ソースを参照

refactor(charts.js): use key value map for handling chart types

tags/1.2.0
Moritz 7年前
committed by GitHub
コミット
3a41cd071f
この署名に対応する既知のキーがデータベースに存在しません GPGキーID: 4AEE18F83AFDEB23
1個のファイルの変更17行の追加8行の削除
  1. +17
    -8
      src/scripts/charts.js

+ 17
- 8
src/scripts/charts.js ファイルの表示

@@ -14,15 +14,24 @@ import Heatmap from './charts/Heatmap';
// );
// }

const chartTypes = {
line: LineChart,
bar: BarChart,
scatter: ScatterChart,
percentage: PercentageChart,
heatmap: Heatmap
};

function getChartByType(chartType = 'line', options) {
if (!chartTypes[chartType]) {
return new LineChart(options);
}

return new chartTypes[chartType](options);
}

export default class Chart {
constructor(args) {
switch (args.type) {
case 'line': return new LineChart(arguments[0]);
case 'bar': return new BarChart(arguments[0]);
case 'scatter': return new ScatterChart(arguments[0]);
case 'percentage': return new PercentageChart(arguments[0]);
case 'heatmap': return new Heatmap(arguments[0]);
default: return new LineChart(arguments[0]);
}
return getChartByType(args.type, arguments[0]);
}
}

読み込み中…
キャンセル
保存