vap-visual
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -197,3 +197,3 @@ "use strict"; | ||
this.DURATION = this.CONFIG.duration; | ||
if (_.has(this.CONFIG, 'format')) | ||
if (_.has(this.CONFIG, 'valueFormat')) | ||
this.FormatValue = util_1.default.buildFormat(this.CONFIG.valueFormat); | ||
@@ -200,0 +200,0 @@ if (_.has(this.CONFIG, 'labelFormat')) |
{ | ||
"name": "vap-visual", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "vap-visual - A Visual FrameWork base on d3 & lodash", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,14 +8,40 @@ "use strict"; | ||
super(...arguments); | ||
this.id = ''; | ||
this.id = `_v_${_.now()}_${_.random(9999999)}`; | ||
this.visual = null; | ||
this.build_pid = 0; | ||
this.state = { | ||
loaded: false, | ||
}; | ||
} | ||
componentWillUnmount() { | ||
window.clearTimeout(this.build_pid); | ||
} | ||
componentDidMount() { | ||
console.log('222'); | ||
// console.log('mount', this.id, this.state.loaded) | ||
this.build_pid = window.setTimeout(() => { | ||
// console.log('build') | ||
this.setState({ loaded: true }); | ||
this.build(); | ||
}, 3); | ||
} | ||
shouldComponentUpdate() { | ||
return this.state.loaded; | ||
} | ||
componentDidUpdate(old) { | ||
// console.log('update1') | ||
if (!this.state.loaded) { | ||
return; | ||
} | ||
// console.log('update2') | ||
if (!_.isEqual(old.data, this.props.data)) { | ||
// console.log('update3') | ||
this.setData(this.props.data); | ||
return; | ||
} | ||
if (_.isEqualWith(old, this.props)) { | ||
this.setOption(this.props); | ||
return; | ||
} | ||
// if (_.isEqualWith(old, this.props)) { | ||
// // console.log('update4') | ||
// this.setOption(this.props); | ||
// return; | ||
// } | ||
} | ||
@@ -45,15 +71,4 @@ /** | ||
exports.Visual = Visual; | ||
// 地图专用 React 渲染器 | ||
class VisualGEO extends Visual { | ||
componentDidUpdate(old) { | ||
if (!_.isEqual(old.data, this.props.data)) { | ||
this.setData(this.props.data); | ||
return; | ||
} | ||
if (_.isEqualWith(old, this.props)) { | ||
this.setOption(this.props); | ||
return; | ||
} | ||
} | ||
} | ||
exports.VisualGEO = VisualGEO; | ||
// // 地图专用 React 渲染器 | ||
// export abstract class VisualGEO<T extends VisualOpts> extends Visual<T>{ | ||
// } |
@@ -6,3 +6,3 @@ "use strict"; | ||
class Bar extends _Visual_1.Visual { | ||
componentDidMount() { | ||
build() { | ||
this.visual = new index_1.Bar(`#${this.id}`, this.props); | ||
@@ -12,10 +12,10 @@ } | ||
exports.Bar = Bar; | ||
class Hbar extends _Visual_1.Visual { | ||
componentDidMount() { | ||
class HBar extends _Visual_1.Visual { | ||
build() { | ||
this.visual = new index_1.HBar(`#${this.id}`, this.props); | ||
} | ||
} | ||
exports.Hbar = Hbar; | ||
exports.HBar = HBar; | ||
class MultiBar extends _Visual_1.Visual { | ||
componentDidMount() { | ||
build() { | ||
this.visual = new index_1.MultiBar(`#${this.id}`, this.props); | ||
@@ -26,3 +26,3 @@ } | ||
class HMultiBar extends _Visual_1.Visual { | ||
componentDidMount() { | ||
build() { | ||
this.visual = new index_1.HMultiBar(`#${this.id}`, this.props); | ||
@@ -33,3 +33,3 @@ } | ||
class Pie extends _Visual_1.Visual { | ||
componentDidMount() { | ||
build() { | ||
this.visual = new index_1.Pie(`#${this.id}`, this.props); | ||
@@ -40,3 +40,3 @@ } | ||
class Percentile extends _Visual_1.Visual { | ||
componentDidMount() { | ||
build() { | ||
this.visual = new index_1.Percentile(`#${this.id}`, this.props); | ||
@@ -47,3 +47,4 @@ } | ||
class DateTrend extends _Visual_1.Visual { | ||
componentDidMount() { | ||
build() { | ||
console.log(this.props.valueFormat); | ||
this.visual = new index_1.DateTrend(`#${this.id}`, this.props); | ||
@@ -54,3 +55,3 @@ } | ||
class Histogram extends _Visual_1.Visual { | ||
componentDidMount() { | ||
build() { | ||
this.visual = new index_1.Histogram(`#${this.id}`, this.props); | ||
@@ -61,3 +62,3 @@ } | ||
class Hours extends _Visual_1.Visual { | ||
componentDidMount() { | ||
build() { | ||
this.visual = new index_1.Hours(`#${this.id}`, this.props); | ||
@@ -64,0 +65,0 @@ } |
@@ -5,4 +5,20 @@ "use strict"; | ||
const topojson_1 = require("../topojson"); | ||
class SimpleMap extends _Visual_1.VisualGEO { | ||
componentDidMount() { | ||
const _ = require("lodash"); | ||
// export class Bar extends Visual<BarOpts> { | ||
// protected build() { | ||
// this.visual = new _Bar(`#${this.id}`, this.props) | ||
// } | ||
// } | ||
class SimpleMap extends _Visual_1.Visual { | ||
componentDidUpdate(old) { | ||
if (!_.isEqual(old.data, this.props.data)) { | ||
this.setData(this.props.data); | ||
return; | ||
} | ||
if (_.isEqualWith(old, this.props)) { | ||
this.setOption(this.props); | ||
return; | ||
} | ||
} | ||
build() { | ||
this.visual = new topojson_1.SimpleMap(`#${this.id}`, this.props); | ||
@@ -9,0 +25,0 @@ } |
@@ -55,2 +55,3 @@ "use strict"; | ||
this.initClassName = this.CONFIG.fillStyle ? `_item _item_fill_style _item_fill_${this.CONFIG.fillStyle}` : '_item'; | ||
// console.l | ||
let url = this.pathToUrl(this.CONFIG.mapPath); | ||
@@ -57,0 +58,0 @@ let data = null; |
@@ -8,3 +8,3 @@ "use strict"; | ||
*/ | ||
exports.fixMax = (max) => { | ||
exports.fixMax = (max = 0) => { | ||
if (max < 1) { | ||
@@ -30,6 +30,9 @@ return 1; | ||
*/ | ||
exports.extent = (data, fn, fixMax = true) => { | ||
exports.extent = (data, fn, fix = true) => { | ||
let [min, max] = d3.extent(data, fn); | ||
min = (min === undefined ? 0 : min); | ||
max = max === undefined ? 1 : max; | ||
max = max === undefined ? 1 : (fix ? exports.fixMax(max) : max); | ||
if (max == 0 && min == 0) { | ||
max = 1; | ||
} | ||
return [min, max]; | ||
@@ -36,0 +39,0 @@ }; |
@@ -68,2 +68,3 @@ "use strict"; | ||
exports.buildFormat = (format = 'default') => { | ||
// console.log(format) | ||
if (_.isFunction(format)) { | ||
@@ -70,0 +71,0 @@ return format; |
264767
121
6761