const DEFAULT_COLORS = [ 'rgb(59, 130, 246)', 'rgb(239, 68, 68)', 'rgb(34, 197, 94)', 'rgb(234, 179, 8)', 'rgb(168, 85, 247)', 'rgb(236, 72, 153)', 'rgb(14, 165, 233)', 'rgb(249, 115, 22)', ] const hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key) export function buildChartDatasets(data, { isTrafficChart, dualAxis, colors = DEFAULT_COLORS }) { return data.datasets.map((dataset, index) => { const color = colors[index % colors.length] const baseConfig = { ...dataset, borderColor: color, backgroundColor: color.replace('rgb', 'rgba').replace(')', ', 0.2)'), borderWidth: 2, tension: 0.4, pointRadius: 0, pointHoverRadius: 4, } if (dualAxis && dataset.yAxisID === 'y1') { baseConfig.stepped = 'before' baseConfig.tension = 0 baseConfig.fill = 'origin' baseConfig.borderWidth = 1 baseConfig.borderColor = 'rgb(34, 197, 94)' baseConfig.backgroundColor = 'rgba(34, 197, 94, 0.1)' return baseConfig } if (hasOwn(dataset, 'fill')) { baseConfig.fill = dataset.fill return baseConfig } baseConfig.fill = isTrafficChart ? 'origin' : false return baseConfig }) }