Browse Source

dmenu + better layout design

dependabot/npm_and_yarn/webpack-bundle-analyzer-3.6.0
Alexey Velikiy 8 years ago
parent
commit
869e5490d5
  1. 2
      src/d3-components/bubbles-nested-routes/bubbles.vue
  2. 33
      src/d3-components/bubbles-nested-routes/index.vue
  3. 52
      src/d3-components/bubbles-nested-routes/menu.vue
  4. 41
      src/d3-components/bubbles-nested-routes/ph2/index.js
  5. 10
      src/d3-components/bubbles-nested-routes/ph2/layout-contry.js
  6. 5
      src/d3-components/bubbles-nested-routes/ph2/layout-total.js
  7. 15
      src/d3-components/bubbles-nested-routes/ph2/layout-year.js
  8. 2
      src/router/demos.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); that.ph2 = new PH2(bubblesG, data, 'country');
}); });
} }

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

@ -14,19 +14,18 @@ Links:
<template> <template>
<div class="holder"> <div class="holder">
<ul class="menu"> <groupMenu :links="links" :activeLink="activeLink" />
<li v-for="link in links"> {{activeLink.layout}}
<a :href="link.path"> {{link.name}} </a>
</li>
</ul>
{{layout}}
</div> </div>
</template> </template>
<script> <script>
const menu = require('d3-components/bubbles-nested-routes/menu');
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: 'Together',
@ -34,9 +33,9 @@ const LINKS = [
layout: 'together' layout: 'together'
}, },
{ {
name: 'By contry', name: 'By country',
path: '/contry', path: '/country',
layout: 'contry' layout: 'country'
}, },
{ {
name: 'By year', name: 'By year',
@ -45,13 +44,18 @@ const LINKS = [
} }
].map(d => { ].map(d => {
d.path = '#/' + MY_URL_PREFIX + d.path; d.path = '#/' + MY_URL_PREFIX + d.path;
d.active = false;
return d; return d;
}); });
export default { export default {
components: {
groupMenu: menu
},
data: function() { data: function() {
return { return {
layout: this.resolveLayout(), activeLink: this.findActiveLink()
} }
}, },
computed: { computed: {
@ -60,17 +64,20 @@ export default {
} }
}, },
methods: { methods: {
resolveLayout: function() { findActiveLink: function() {
_.each(LINKS, l => {
l.active = false;
})
var link = _.find(LINKS, l => l.path == '#' + this.$route.path); var link = _.find(LINKS, l => l.path == '#' + this.$route.path);
if(!link) { if(!link) {
link = LINKS[0]; link = LINKS[0];
} }
return link.layout; return link;
} }
}, },
watch: { watch: {
'$route' (to, from) { '$route' (to, from) {
this.layout = this.resolveLayout(); this.activeLink = this.findActiveLink();
} }
} }
} }

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

@ -0,0 +1,52 @@
<template>
<div class="holder">
<ul class="menu">
<li>Group by: </li>
<li v-for="link in alinks">
<a :href="link.item.path" :class="{active: link.active}"> {{link.item.name}} </a>
</li>
</ul>
{{activeLink.path}}
</div>
</template>
<script>
const _ = require('lodash');
export default {
props: ['links', 'activeLink'],
computed: {
alinks: function() {
var that = this;
return _.map(this.links, l => ({
item: l,
active: (l.path == that.activeLink.path)
}))
}
}
}
</script>
<style scoped>
.menu{
padding: 0;
margin: 0;
}
.menu li {
text-align: left;
display: inline-block;
text-align: left;
margin: 0px;
margin-right: 10px;
}
.menu li a {
text-decoration: none;
}
.menu li a.active {
text-decoration: underline;
}
</style>

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

@ -1,11 +1,11 @@
// http://vallandingham.me/bubble_charts_with_d3v4.html // http://vallandingham.me/bubble_charts_with_d3v4.html
const d3 = require('d3'); import layoutTotal from './layout-total';
import layoutCountry from './layout-contry';
const layoutTotal = require('./layout-total'); import layoutYear from './layout-year';
const layoutContry = require('./layout-contry');
const _ = require('lodash'); const d3 = require('d3');
import _ from 'lodash';
// TODO: do it d3-way so I can use selection.call() // TODO: do it d3-way so I can use selection.call()
@ -19,16 +19,25 @@ export default class PH2 {
} }
setLayout(layoutName) { setLayout(layoutName) {
if(layoutName === undefined) {
throw new Error('layoutName is undefined');
}
if(!this.layouts) { if(!this.layouts) {
throw new Error('Layouts are not defined'); throw new Error('Layouts are not defined');
} }
if(!this.layouts[layoutName]) { if(!this.layouts[layoutName]) {
throw new Error('Can`t find layout ' + layoutName); throw new Error('Can`t find layout ' + layoutName);
} }
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) {
this.layout.init();
this.layout.inited = true;
}
this.layout.enter(); this.layout.enter();
} }
@ -39,17 +48,21 @@ export default class PH2 {
r: +d.Magnitude r: +d.Magnitude
})), })),
links:d3.range(0, range).map( links:d3.range(0, range).map(
function(){ return {source:~~d3.randomUniform(range)(), target:~~d3.randomUniform(range)()} 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("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))
this._initLayouts();
var link = this.svg.append("g") var link = this.svg.append("g")
.attr("class", "links") .attr("class", "links")
.selectAll("line") .selectAll("line")
@ -72,7 +85,6 @@ export default class PH2 {
.attr("y1", d => d.source.y) .attr("y1", d => d.source.y)
.attr("x2", d => d.target.x) .attr("x2", d => d.target.x)
.attr("y2", d => d.target.y); .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 );
@ -82,17 +94,20 @@ export default class PH2 {
.nodes(this.data.nodes) .nodes(this.data.nodes)
.on("tick", ticked); .on("tick", ticked);
this.simulation
.force("link")
.links(this.data.links);
} }
_initLayouts() { _initLayouts() {
this.layouts = { this.layouts = {
'total': layoutTotal, 'total': layoutTotal,
'county': layoutContry, 'country': layoutCountry,
'year': layoutYear
}; };
_.this.layouts
for (var k in this.layouts) {
var v = this.layouts[k];
this.layouts[k] = new v(this.svg, this.data, this.simulation);
}
} }
} }

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

@ -1,12 +1,18 @@
export default class { export default class {
constructor(elem, simulation) { constructor(elem, data, simulation) {
this.elem = elem; this.elem = elem;
this.data = data;
this.simulation = simulation; this.simulation = simulation;
} }
init() {
//alert('ебать')
}
enter() { enter() {
} }
exit() { exit() {
this.simulation
.force("link", null)
.links(this.data.links);
} }
} }

5
src/d3-components/bubbles-nested-routes/ph2/layout-total.js vendored

@ -1,7 +1,10 @@
export default class { export default class {
constructor(elem, simulation) { constructor(elem, data, simulation) {
this.elem = elem; this.elem = elem;
this.simulation = simulation; this.simulation = simulation;
}
init() {
} }
enter() { enter() {

15
src/d3-components/bubbles-nested-routes/ph2/layout-year.js vendored

@ -0,0 +1,15 @@
export default class {
constructor(elem, data, simulation) {
this.elem = elem;
this.simulation = simulation;
}
init() {
}
enter() {
}
exit() {
}
}

2
src/router/demos.js

@ -32,7 +32,7 @@ export const routes = [
path: '/bubbles-nested-routes', path: '/bubbles-nested-routes',
alias: '/bubbles-nested-routes/*', alias: '/bubbles-nested-routes/*',
folder: true, folder: true,
component: require('d3-components/bubbles-nested-routes/bubbles') component: require('d3-components/bubbles-nested-routes/index')
} }
].map(r => { ].map(r => {
var res = r; var res = r;

Loading…
Cancel
Save