Merge pull request #10 from moklick/patch-1
refactor(charts.js): use switch instead of multiple if else
This commit is contained in:
commit
678fc55c20
@ -14,20 +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 {
|
export default class Chart {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
if(args.type === 'line') {
|
return getChartByType(args.type, arguments[0]);
|
||||||
return new LineChart(arguments[0]);
|
|
||||||
} else if(args.type === 'bar') {
|
|
||||||
return new BarChart(arguments[0]);
|
|
||||||
} else if(args.type === 'scatter') {
|
|
||||||
return new ScatterChart(arguments[0]);
|
|
||||||
} else if(args.type === 'percentage') {
|
|
||||||
return new PercentageChart(arguments[0]);
|
|
||||||
} else if(args.type === 'heatmap') {
|
|
||||||
return new Heatmap(arguments[0]);
|
|
||||||
} else {
|
|
||||||
return new LineChart(arguments[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user