Browse Source

layout contry continu

dependabot/npm_and_yarn/webpack-bundle-analyzer-3.6.0
Alexey Velikiy 8 years ago
parent
commit
929389597e
  1. 2
      src/d3-components/bubbles-nested-routes/bubbles.vue
  2. 10
      src/d3-components/bubbles-nested-routes/index.vue
  3. 6
      src/d3-components/bubbles-nested-routes/menu.vue
  4. 40
      src/d3-components/bubbles-nested-routes/ph2/index.js
  5. 38
      src/d3-components/bubbles-nested-routes/ph2/layout-contry.js

2
src/d3-components/bubbles-nested-routes/bubbles.vue

@ -35,7 +35,7 @@ export default {
// TODO: remove it later // TODO: remove it later
d3.csv('static/data/earthquakes.csv', function(data) { d3.csv('static/data/earthquakes.csv', function(data) {
that.ph2 = new PH2(bubblesG, data, 'country'); that.ph2 = new PH2(bubblesG, data, that.groupBy);
}); });
} }

10
src/d3-components/bubbles-nested-routes/index.vue

@ -15,22 +15,23 @@ Links:
<template> <template>
<div class="holder"> <div class="holder">
<groupMenu :links="links" :activeLink="activeLink" /> <groupMenu :links="links" :activeLink="activeLink" />
{{activeLink.layout}} <bubbles :groupBy="activeLink.layout" />
</div> </div>
</template> </template>
<script> <script>
const menu = require('d3-components/bubbles-nested-routes/menu'); const menu = require('d3-components/bubbles-nested-routes/menu');
const bubbles = require('d3-components/bubbles-nested-routes/bubbles');
const MY_URL_PREFIX = 'bubbles-nested-routes'; const MY_URL_PREFIX = 'bubbles-nested-routes';
const _ = require('lodash'); const _ = require('lodash');
const LINKS = [ const LINKS = [
{ {
name: 'Together', name: 'None',
path: '', path: '',
layout: 'together' layout: 'total'
}, },
{ {
name: 'By country', name: 'By country',
@ -51,7 +52,8 @@ const LINKS = [
export default { export default {
components: { components: {
groupMenu: menu groupMenu: menu,
bubbles: bubbles
}, },
data: function() { data: function() {
return { return {

6
src/d3-components/bubbles-nested-routes/menu.vue

@ -1,15 +1,11 @@
<template> <template>
<div class="holder"> <div class="holder">
<ul class="menu"> <ul class="menu">
<li>Group by: </li> <li>Group by: </li>
<li v-for="link in alinks"> <li v-for="link in alinks">
<a :href="link.item.path" :class="{active: link.active}"> {{link.item.name}} </a> <a :href="link.item.path" :class="{active: link.active}"> {{link.item.name}} </a>
</li> </li>
</ul> </ul>
{{activeLink.path}}
</div> </div>
</template> </template>
@ -32,7 +28,7 @@ export default {
</script> </script>
<style scoped> <style scoped>
.menu{ .menu {
padding: 0; padding: 0;
margin: 0; margin: 0;
} }

40
src/d3-components/bubbles-nested-routes/ph2/index.js vendored

@ -12,6 +12,7 @@ import _ from 'lodash';
export default class PH2 { export default class PH2 {
constructor(elem, data, layoutName) { constructor(elem, data, layoutName) {
this.svg = elem; this.svg = elem;
this.data = data;
this.setData(data); this.setData(data);
this._init(); this._init();
this.layout = undefined; this.layout = undefined;
@ -32,6 +33,7 @@ export default class PH2 {
if(this.layout) { if(this.layout) {
this.layout.exit(); this.layout.exit();
} }
this.layout = this.layouts[layoutName]; this.layout = this.layouts[layoutName];
if(!this.layout.inited) { if(!this.layout.inited) {
@ -39,62 +41,46 @@ export default class PH2 {
this.layout.inited = true; this.layout.inited = true;
} }
this.layout.enter(); this.layout.enter();
this.simulation.alpha(1);
this.simulation.restart();
} }
setData(data) { setData(data) {
var range = data.length; this.nodes = data.map(d => ({
this.data = {
nodes:data.map(d => ({
r: +d.Magnitude r: +d.Magnitude
})), }))
links:d3.range(0, range).map(
function(){ return {
source:~~d3.randomUniform(range)(),
target:~~d3.randomUniform(range)()
}
})
};
} }
_init() { _init() {
this.simulation = d3.forceSimulation() this.simulation = d3.forceSimulation()
//.force("link", d3.forceLink().id(d => d.index))
.force("collide", d3.forceCollide(d => d.r + 5).iterations(16)) .force("collide", d3.forceCollide(d => d.r + 5).iterations(16))
.force("center", d3.forceCenter(0, 0)) .force("center", d3.forceCenter(0, 0))
.force("charge", d3.forceManyBody().strength(-1))
this._initLayouts(); this._initLayouts();
var link = this.svg.append("g")
.attr("class", "links")
.selectAll("line")
.data(this.data.links)
.enter()
.append("line")
.attr("stroke", "black")
var node = this.svg.append("g") var node = this.svg.append("g")
.attr("class", "nodes") .attr("class", "nodes")
.selectAll("circle") .selectAll("circle")
.data(this.data.nodes) .data(this.nodes)
.enter() .enter()
.append("circle") .append("circle")
.attr("r", d => d.r ) .attr("r", d => d.r )
var that = this;
var ticked = function() { var ticked = function() {
link
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
node node
.attr("cx", d => d.x ) .attr("cx", d => d.x )
.attr("cy", d => d.y ); .attr("cy", d => d.y );
if(that.layout.ticked) {
that.layout.ticked();
}
} }
this.simulation this.simulation
.nodes(this.data.nodes) .nodes(this.nodes)
.on("tick", ticked); .on("tick", ticked);
} }
_initLayouts() { _initLayouts() {

38
src/d3-components/bubbles-nested-routes/ph2/layout-contry.js vendored

@ -1,18 +1,52 @@
const d3 = require('d3');
export default class { export default class {
constructor(elem, data, simulation) { constructor(elem, data, simulation) {
this.elem = elem; this.elem = elem;
this.data = data; this.data = data;
this.simulation = simulation; this.simulation = simulation;
} }
init() { init() {
//alert('ебать') var range = this.data.length / 20;
this.links = d3.range(0, range).map(
() => ({
source:~~d3.randomUniform(range)(),
target:~~d3.randomUniform(range)()
})
);
} }
enter() { enter() {
this.simulation
.force("link", d3.forceLink().id(d => d.index))
this.linesG = this.elem.insert("g", ":first-child");
this.lines = this.linesG
.attr("class", "links")
.selectAll("line")
.data(this.links)
.enter()
.append("line")
.attr("stroke", "black")
this.simulation
.force("link")
.links(this.links);
} }
ticked() {
this.lines
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
}
exit() { exit() {
this.simulation this.simulation
.force("link", null) .force("link", null)
.links(this.data.links); this.linesG.remove();
} }
} }

Loading…
Cancel
Save