|
|
@ -2,6 +2,11 @@ |
|
|
|
|
|
|
|
|
|
|
|
const d3 = require('d3'); |
|
|
|
const d3 = require('d3'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const layoutTotal = require('./layout-total'); |
|
|
|
|
|
|
|
const layoutContry = require('./layout-contry'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const _ = require('lodash'); |
|
|
|
|
|
|
|
|
|
|
|
// TODO: do it d3-way so I can use selection.call()
|
|
|
|
// TODO: do it d3-way so I can use selection.call()
|
|
|
|
|
|
|
|
|
|
|
|
export default class PH2 { |
|
|
|
export default class PH2 { |
|
|
@ -9,21 +14,33 @@ export default class PH2 { |
|
|
|
this.svg = elem; |
|
|
|
this.svg = elem; |
|
|
|
this.setData(data); |
|
|
|
this.setData(data); |
|
|
|
this._init(); |
|
|
|
this._init(); |
|
|
|
|
|
|
|
this.layout = undefined; |
|
|
|
this.setLayout(layoutName); |
|
|
|
this.setLayout(layoutName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setLayout(layoutName) { |
|
|
|
setLayout(layoutName) { |
|
|
|
// TODO: something special
|
|
|
|
if(!this.layouts) { |
|
|
|
this.simulation.alpha(1).restart(); |
|
|
|
throw new Error('Layouts are not defined'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(!this.layouts[layoutName]) { |
|
|
|
|
|
|
|
throw new Error('Can`t find layout ' + layoutName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(this.layout) { |
|
|
|
|
|
|
|
this.layout.exit(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.layout = this.layouts[layoutName]; |
|
|
|
|
|
|
|
this.layout.enter(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setData(data) { |
|
|
|
setData(data) { |
|
|
|
var range = data.length; |
|
|
|
var range = data.length; |
|
|
|
this.data = { |
|
|
|
this.data = { |
|
|
|
nodes:data.map(d => ({ |
|
|
|
nodes:data.map(d => ({ |
|
|
|
label: "l"+d ,r:+d.Magnitude |
|
|
|
r: +d.Magnitude |
|
|
|
})), |
|
|
|
})), |
|
|
|
links:d3.range(0, range).map(function(){ return {source:~~d3.randomUniform(range)(), target:~~d3.randomUniform(range)()} }) |
|
|
|
links:d3.range(0, range).map( |
|
|
|
|
|
|
|
function(){ return {source:~~d3.randomUniform(range)(), target:~~d3.randomUniform(range)()} |
|
|
|
|
|
|
|
}) |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -65,12 +82,17 @@ export default class PH2 { |
|
|
|
.nodes(this.data.nodes) |
|
|
|
.nodes(this.data.nodes) |
|
|
|
.on("tick", ticked); |
|
|
|
.on("tick", ticked); |
|
|
|
|
|
|
|
|
|
|
|
this.simulation.force("link") |
|
|
|
this.simulation |
|
|
|
|
|
|
|
.force("link") |
|
|
|
.links(this.data.links); |
|
|
|
.links(this.data.links); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_initNodeYearPos() { |
|
|
|
_initLayouts() { |
|
|
|
// TODO: fill
|
|
|
|
this.layouts = { |
|
|
|
|
|
|
|
'total': layoutTotal, |
|
|
|
|
|
|
|
'county': layoutContry, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
_.this.layouts |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |