Merge branch 'master' into theme-mods
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { mergedOptionsWithJsonConfig } from './helpers'
|
||||
|
||||
const columnChart = () => {
|
||||
return {
|
||||
@@ -14,6 +15,7 @@ const columnChart = () => {
|
||||
this.chart.destroy()
|
||||
}
|
||||
|
||||
const title = component.get('columnChartModel.title')
|
||||
const animated = component.get('columnChartModel.animated') || false;
|
||||
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
||||
const dataLabels = component.get('columnChartModel.dataLabels') || {};
|
||||
@@ -22,9 +24,13 @@ const columnChart = () => {
|
||||
const grid = component.get('columnChartModel.grid');
|
||||
const columnWidth = component.get('columnChartModel.columnWidth');
|
||||
const horizontal = component.get('columnChartModel.horizontal');
|
||||
const jsonConfig = component.get('columnChartModel.jsonConfig');
|
||||
|
||||
const data = component.get('columnChartModel.data');
|
||||
const series = [{ data: data.map(item => item.value)}]
|
||||
const series = [{
|
||||
name: title,
|
||||
data: data.map(item => item.value)
|
||||
}]
|
||||
|
||||
const options = {
|
||||
series: series,
|
||||
@@ -80,7 +86,7 @@ const columnChart = () => {
|
||||
|
||||
yaxis: {
|
||||
title: {
|
||||
text: component.get('columnChartModel.title'),
|
||||
text: title,
|
||||
}
|
||||
},
|
||||
|
||||
@@ -90,6 +96,14 @@ const columnChart = () => {
|
||||
|
||||
theme: component.get('columnChartModel.theme') || {},
|
||||
|
||||
tooltip: {
|
||||
y: {
|
||||
formatter: function(value, series) {
|
||||
return data[series.dataPointIndex].extras.tooltip || value;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
const colors = component.get('columnChartModel.colors');
|
||||
@@ -98,7 +112,7 @@ const columnChart = () => {
|
||||
options['colors'] = colors
|
||||
}
|
||||
|
||||
this.chart = new ApexCharts(this.$refs.container, options);
|
||||
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||
this.chart.render();
|
||||
}
|
||||
}
|
||||
|
||||
27
resources/js/helpers.js
Normal file
27
resources/js/helpers.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import deepmerge from 'deepmerge'
|
||||
|
||||
export const addPathToObjectWithValue = (obj, path, value) => {
|
||||
const pList = path.split('.');
|
||||
const key = pList.pop();
|
||||
const pointer = pList.reduce((accumulator, currentValue) => {
|
||||
if (accumulator[currentValue] === undefined) accumulator[currentValue] = {};
|
||||
return accumulator[currentValue];
|
||||
}, obj);
|
||||
pointer[key] = value;
|
||||
return obj;
|
||||
}
|
||||
|
||||
export const mergedOptionsWithJsonConfig = (options, jsonConfig) => {
|
||||
const customOptions = Object.keys(jsonConfig)
|
||||
.reduce(function (obj, key) {
|
||||
const value = jsonConfig[key]
|
||||
|
||||
if (typeof value === 'string' && value.includes('function')) {
|
||||
return addPathToObjectWithValue(obj, key, eval('(' + value + ')'))
|
||||
}
|
||||
|
||||
return addPathToObjectWithValue(obj, key, eval(value))
|
||||
}, {})
|
||||
|
||||
return deepmerge(options, customOptions)
|
||||
}
|
||||
@@ -98,6 +98,14 @@ const lineChart = () => {
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
tooltip: {
|
||||
y: {
|
||||
formatter: function(value, series) {
|
||||
return data[series.dataPointIndex].extras.tooltip || value;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
this.chart = new ApexCharts(this.$refs.container, options);
|
||||
|
||||
@@ -14,6 +14,7 @@ const multiColumnChart = () => {
|
||||
this.chart.destroy()
|
||||
}
|
||||
|
||||
const title = component.get('columnChartModel.title')
|
||||
const stacked = component.get('columnChartModel.isStacked');
|
||||
const animated = component.get('columnChartModel.animated');
|
||||
const onColumnClickEventName = component.get('columnChartModel.onColumnClickEventName')
|
||||
@@ -81,7 +82,7 @@ const multiColumnChart = () => {
|
||||
|
||||
yaxis: {
|
||||
title: {
|
||||
text: component.get('columnChartModel.title'),
|
||||
text: title,
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import {mergedOptionsWithJsonConfig} from './helpers'
|
||||
|
||||
const pieChart = () => {
|
||||
return {
|
||||
@@ -21,6 +22,7 @@ const pieChart = () => {
|
||||
const data = component.get('pieChartModel.data')
|
||||
const sparkline = component.get('pieChartModel.sparkline')
|
||||
const type = component.get('pieChartModel.type')
|
||||
const jsonConfig = component.get('pieChartModel.jsonConfig');
|
||||
|
||||
const options = {
|
||||
series: data.map(item => item.value),
|
||||
@@ -76,6 +78,13 @@ const pieChart = () => {
|
||||
|
||||
theme: component.get('pieChartModel.theme') || {},
|
||||
|
||||
tooltip: {
|
||||
y: {
|
||||
formatter: function(value, series) {
|
||||
return data[series.dataPointIndex].extras.tooltip || value;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const colors = component.get('pieChartModel.colors');
|
||||
@@ -84,7 +93,7 @@ const pieChart = () => {
|
||||
options['colors'] = colors
|
||||
}
|
||||
|
||||
this.chart = new ApexCharts(this.$refs.container, options);
|
||||
this.chart = new ApexCharts(this.$refs.container, mergedOptionsWithJsonConfig(options, jsonConfig));
|
||||
this.chart.render();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user