@visactor/taro-vchart
Version:
Taro VChart 图表组件
55 lines • 2.36 kB
JavaScript
export class TTCanvas {
constructor(props) {
const {chartConstructor: chartConstructor, dpr: dpr, events: events, spec: spec, options: options, domref: domref, mode: mode, onChartInit: onChartInit, onChartReady: onChartReady, onChartUpdate: onChartUpdate} = props;
this.chartConstructor = chartConstructor, this.domref = domref, this.mode = mode || "miniApp",
this.dpr = dpr, this.spec = spec, this.events = events, this.options = options,
/**
* 三个生命周期函数
*/
this.onChartInit = onChartInit, this.onChartReady = onChartReady, this.onChartUpdate = onChartUpdate,
/**
* 图表初始化以及渲染
*/
this.init(), this.renderAsync();
}
init() {
const domref = this.domref;
return this.chartInstance = new this.chartConstructor(Object.assign({
width: domref.width,
height: domref.height
}, this.spec), Object.assign({
mode: this.mode,
// 跨端参数
modeParams: {
domref: domref,
force: !0,
canvasIdLists: [ `${domref.id}_draw_canvas`, `${domref.id}_tooltip_canvas`, `${domref.id}_hidden_canvas` ],
tooltipCanvasId: `${domref.id}_tooltip_canvas`,
freeCanvasIdx: 2
},
dpr: this.dpr,
renderCanvas: `${domref.id}_draw_canvas`
}, this.options)), this.onChartInit && this.onChartInit(this.chartInstance),
// events
this.events && this.events.forEach((event => {
this.chartInstance.on(event.type, Object.assign(Object.assign({}, event.query), {
source: "chart"
}), event.handler);
})), this.chartInstance;
}
renderAsync() {
var _a;
null === (_a = this.chartInstance) || void 0 === _a || _a.renderAsync().then((chart => (this.onChartReady && this.onChartReady(chart),
chart)));
}
updateSpec(props) {
var _a;
this.onChartUpdate && this.onChartUpdate(this.chartInstance), null === (_a = this.chartInstance) || void 0 === _a || _a.updateSpec(props.spec, !0);
}
release() {
this.chartInstance &&
// 释放: 图表
this.chartInstance.release();
}
}
//# sourceMappingURL=index.js.map