/* eslint-disable @typescript-eslint/naming-convention */ import Chart from '../core/chart'; import { GraphType, PieGraphOptions, VennGraphOptions, SeriesOptions, LineGraphOptions, BarGraphOptions } from '../models'; import { pluginManager } from '../pluginManager'; import { getId } from '../utils/signature'; import { Renderer } from '../atomComponent'; export default class Graph implements Renderer { public id: string; public name: string; public graphInstance: any; constructor(public chart: Chart, private type: GraphType, private series: Array) { this.id = getId(); this.name = 'graph'; this.type = type; this.series = series; this.graphInstance = this.createGraph(); } createGraph() { const { type } = this; switch (type) { case 'line': return this.createLine(); case 'bar': return this.createBar(); case 'pie': return this.createPie(); case 'venn': return this.createVenn(); } } render() { return this.graphInstance.render(); } /** * 绘制折线图 */ private createLine() { const { chart, series } = this; const Line = pluginManager.getGraph('line'); return new Line(this.id, chart, series as Array); } /** * 绘制条形图(柱状图) */ private createBar() { const { chart, series } = this; const Bar = pluginManager.getGraph('bar'); return new Bar(this.id, chart, series as Array); } /** * 绘制饼图 */ private createPie() { const { chart, series } = this; const Pie = pluginManager.getGraph('pie'); return new Pie(this.id, chart, series[0] as PieGraphOptions); } /** * Venn图 */ private createVenn() { const { chart, series } = this; const Venn = pluginManager.getGraph('venn'); return new Venn(this.id, chart, series[0] as VennGraphOptions); } }