[frontend] Refactored bar, time and line chart to use the common basic chart builder
}
};
- ko.bindingHandlers.barChart = {
- init: function (element, valueAccessor) {
- resizeHandlers(element);
- },
- update: function (element, valueAccessor) {
+ function basicChartBuilder(element, valueAccessor, chartType) {
var options = valueAccessor();
window.clearTimeout(element.plotterTimeout);
element.plotterTimeout = window.setTimeout(function () {
x: [],
y: [],
name: el.key,
- type: 'bar'
+ type: options.chartType || chartType
}
el.values.forEach(function (serie) {
chartSerie.x.push(serie.x);
Plotly.newPlot(element, chartData, PLOTLY_COMMON_LAYOUT, PLOTLY_COMMON_OPTIONS);
}, 200);
}
+
+ ko.bindingHandlers.basicChart = {
+ init: function (element, valueAccessor) {
+ resizeHandlers(element);
+ },
+ update: function (element, valueAccessor) {
+ basicChartBuilder(element, valueAccessor);
+ }
+ }
+
+ ko.bindingHandlers.barChart = {
+ init: function (element, valueAccessor) {
+ resizeHandlers(element);
+ },
+ update: function (element, valueAccessor) {
+ basicChartBuilder(element, valueAccessor, 'bar');
+ }
};
ko.bindingHandlers.timelineChart = {
resizeHandlers(element);
},
update: function (element, valueAccessor) {
- var options = valueAccessor();
- window.clearTimeout(element.plotterTimeout);
- element.plotterTimeout = window.setTimeout(function () {
- var data = options.transformer(options.datum);
- var chartData = [];
- data.forEach(function (el) {
- var chartSerie = {
- x: [],
- y: [],
- name: el.key,
- type: 'scatter'
- }
- el.values.forEach(function (serie) {
- chartSerie.x.push(serie.x);
- chartSerie.y.push(serie.y);
- });
- chartData.push(chartSerie)
- });
- Plotly.newPlot(element, chartData, PLOTLY_COMMON_LAYOUT, PLOTLY_COMMON_OPTIONS);
- }, 200);
+ basicChartBuilder(element, valueAccessor, 'scatter');
}
};
resizeHandlers(element);
},
update: function (element, valueAccessor) {
- var options = valueAccessor();
- window.clearTimeout(element.plotterTimeout);
- element.plotterTimeout = window.setTimeout(function () {
- var data = options.transformer(options.datum);
- var chartData = [];
- data.forEach(function (el) {
- var chartSerie = {
- x: [],
- y: [],
- name: el.key,
- type: 'scatter'
- }
- el.values.forEach(function (serie) {
- chartSerie.x.push(serie.x);
- chartSerie.y.push(serie.y);
- });
- chartData.push(chartSerie)
- });
- Plotly.newPlot(element, chartData, PLOTLY_COMMON_LAYOUT, PLOTLY_COMMON_OPTIONS);
- }, 200);
+ basicChartBuilder(element, valueAccessor, 'scatter');
}
};
