diff --git a/packages/core/demo/demo-data/bar.ts b/packages/core/demo/demo-data/bar.ts index 6d13d32b1d..075dd4ddb7 100644 --- a/packages/core/demo/demo-data/bar.ts +++ b/packages/core/demo/demo-data/bar.ts @@ -1,12 +1,11 @@ import { colors } from "./colors"; -import { getTheme } from "./themes"; export const groupedBarData = { labels: ["Qty", "More", "Sold", "Restocking", "Misc"], datasets: [ { label: "Dataset 1", - backgroundColors: [colors[0]], + fillColors: [colors[0]], data: [ 65000, -29123, @@ -17,7 +16,7 @@ export const groupedBarData = { }, { label: "Dataset 2", - backgroundColors: [colors[1]], + fillColors: [colors[1]], data: [ 32432, -21312, @@ -28,7 +27,7 @@ export const groupedBarData = { }, { label: "Dataset 3", - backgroundColors: [colors[2]], + fillColors: [colors[2]], data: [ -12312, 23232, @@ -39,7 +38,7 @@ export const groupedBarData = { }, { label: "Dataset 4", - backgroundColors: [colors[3]], + fillColors: [colors[3]], data: [ -32423, 21313, @@ -58,14 +57,13 @@ export const groupedBarOptions = { primary: true, }, bottom: { - type: "labels", + scaleType: "labels", secondary: true, }, top: { - type: "labels", + scaleType: "labels", } - }, - theme: getTheme() + } }; // Simple bar @@ -74,7 +72,7 @@ export const simpleBarData = { datasets: [ { label: "Dataset 1", - backgroundColors: colors, + fillColors: colors, data: [ 65000, 29123, @@ -93,11 +91,10 @@ export const simpleBarOptions = { primary: true }, bottom: { - type: "labels", + scaleType: "labels", secondary: true, } - }, - theme: getTheme() + } }; @@ -106,7 +103,7 @@ export const simpleBarTimeSeriesData = { datasets: [ { label: "Dataset 1", - backgroundColors: colors, + fillColors: colors, data: [ { date: new Date(2019, 0, 1), @@ -140,11 +137,10 @@ export const simpleBarTimeSeriesOptions = { primary: true }, bottom: { - type: "time", + scaleType: "time", secondary: true, } - }, - theme: getTheme() + } }; // Stacked bar @@ -153,7 +149,7 @@ export const stackedBarData = { datasets: [ { label: "Dataset 1", - backgroundColors: [colors[0]], + fillColors: [colors[0]], data: [ 65000, 29123, @@ -164,7 +160,7 @@ export const stackedBarData = { }, { label: "Dataset 2", - backgroundColors: [colors[1]], + fillColors: [colors[1]], data: [ 32432, 21312, @@ -175,7 +171,7 @@ export const stackedBarData = { }, { label: "Dataset 3", - backgroundColors: [colors[2]], + fillColors: [colors[2]], data: [ 12312, 23232, @@ -186,7 +182,7 @@ export const stackedBarData = { }, { label: "Dataset 4", - backgroundColors: [colors[3]], + fillColors: [colors[3]], data: [ 32423, 21313, @@ -206,11 +202,10 @@ export const stackedBarOptions = { stacked: true }, bottom: { - type: "labels", + scaleType: "labels", secondary: true, } - }, - theme: getTheme() + } }; @@ -219,7 +214,7 @@ export const stackedBarTimeSeriesData = { datasets: [ { label: "Dataset 1", - backgroundColors: [colors[0]], + fillColors: [colors[0]], data: [ { date: new Date(2019, 0, 1), @@ -245,7 +240,7 @@ export const stackedBarTimeSeriesData = { }, { label: "Dataset 2", - backgroundColors: [colors[1]], + fillColors: [colors[1]], data: [ { date: new Date(2019, 0, 3), @@ -271,7 +266,7 @@ export const stackedBarTimeSeriesData = { }, { label: "Dataset 3", - backgroundColors: [colors[2]], + fillColors: [colors[2]], data: [ { date: new Date(2019, 0, 1), @@ -297,7 +292,7 @@ export const stackedBarTimeSeriesData = { }, { label: "Dataset 4", - backgroundColors: [colors[3]], + fillColors: [colors[3]], data: [ { date: new Date(2019, 0, 2), @@ -332,9 +327,8 @@ export const stackedBarTimeSeriesOptions = { stacked: true }, bottom: { - type: "time", - secondary: true, + scaleType: "time", + secondary: true } - }, - theme: getTheme() + } }; diff --git a/packages/core/demo/demo-data/line.ts b/packages/core/demo/demo-data/line.ts index 9e4c6db6e5..1e6217a7b3 100644 --- a/packages/core/demo/demo-data/line.ts +++ b/packages/core/demo/demo-data/line.ts @@ -1,5 +1,4 @@ import { colors } from "./colors"; -import { getTheme } from "./themes"; import { Tools } from "../../src/tools"; export const lineTimeSeriesData = { @@ -7,7 +6,7 @@ export const lineTimeSeriesData = { datasets: [ { label: "Dataset 1", - backgroundColors: [colors[0]], + fillColors: [colors[0]], data: [ { date: new Date(2019, 0, 1), @@ -33,7 +32,7 @@ export const lineTimeSeriesData = { }, { label: "Dataset 2", - backgroundColors: [colors[1]], + fillColors: [colors[1]], data: [ { date: new Date(2019, 0, 2), @@ -59,7 +58,7 @@ export const lineTimeSeriesData = { }, { label: "Dataset 3", - backgroundColors: [colors[2]], + fillColors: [colors[2]], data: [ { date: new Date(2019, 0, 1), @@ -85,7 +84,7 @@ export const lineTimeSeriesData = { }, { label: "Dataset 4", - backgroundColors: [colors[3]], + fillColors: [colors[3]], data: [ { date: new Date(2019, 0, 2), @@ -119,12 +118,11 @@ export const lineTimeSeriesOptions = { secondary: true }, bottom: { - type: "time", + scaleType: "time", primary: true } }, - curve: "curveMonotoneX", - theme: getTheme() + curve: "curveMonotoneX" }; export const lineData = { @@ -132,7 +130,7 @@ export const lineData = { datasets: [ { label: "Dataset 1", - backgroundColors: [colors[0]], + fillColors: [colors[0]], data: [ 32100, 23500, @@ -143,7 +141,7 @@ export const lineData = { }, { label: "Dataset 2", - backgroundColors: [colors[1]], + fillColors: [colors[1]], data: [ 34200, 53200, @@ -154,7 +152,7 @@ export const lineData = { }, { label: "Dataset 3 long name", - backgroundColors: [colors[2]], + fillColors: [colors[2]], data: [ 41200, 23400, @@ -165,7 +163,7 @@ export const lineData = { }, { label: "Dataset 4 long name", - backgroundColors: [colors[3]], + fillColors: [colors[3]], data: [ 22000, 1200, @@ -176,7 +174,7 @@ export const lineData = { }, { label: "Dataset 5 long name", - backgroundColors: [colors[4]], + fillColors: [colors[4]], data: [ 2412, 30000, @@ -187,7 +185,7 @@ export const lineData = { }, { label: "Dataset 6 long name", - backgroundColors: [colors[5]], + fillColors: [colors[5]], data: [ 0, 20000, @@ -204,14 +202,13 @@ export const lineOptions = { axes: { bottom: { title: "2018 Annual Sales Figures", - type: "labels", + scaleType: "labels", secondary: true }, left: { primary: true } - }, - theme: getTheme() + } }; // Step @@ -235,7 +232,7 @@ export const scatterData = { datasets: [ { label: "Dataset 1", - backgroundColors: [colors[0]], + fillColors: [colors[0]], data: [ 32100, 23500, @@ -246,7 +243,7 @@ export const scatterData = { }, { label: "Dataset 2", - backgroundColors: [colors[1]], + fillColors: [colors[1]], data: [ 34200, 53200, @@ -257,7 +254,7 @@ export const scatterData = { }, { label: "Dataset 3 long name", - backgroundColors: [colors[2]], + fillColors: [colors[2]], data: [ 41200, 23400, @@ -268,7 +265,7 @@ export const scatterData = { }, { label: "Dataset 4 long name", - backgroundColors: [colors[3]], + fillColors: [colors[3]], data: [ 22000, 1200, @@ -279,7 +276,7 @@ export const scatterData = { }, { label: "Dataset 5 long name", - backgroundColors: [colors[4]], + fillColors: [colors[4]], data: [ 2412, 30000, @@ -290,7 +287,7 @@ export const scatterData = { }, { label: "Dataset 6 long name", - backgroundColors: [colors[5]], + fillColors: [colors[5]], data: [ 0, 20000, @@ -307,14 +304,13 @@ export const scatterOptions = { axes: { bottom: { title: "2018 Annual Sales Figures", - type: "labels", + scaleType: "labels", secondary: true }, left: { primary: true } - }, - theme: getTheme() + } }; export const scatterTimeSeriesData = lineTimeSeriesData; @@ -324,12 +320,11 @@ export const scatterTimeSeriesOptions = { axes: { bottom: { title: "2019 Annual Sales Figures", - type: "time", + scaleType: "time", secondary: true }, left: { primary: true } - }, - theme: getTheme() + } }; diff --git a/packages/core/demo/demo-data/pie-donut.ts b/packages/core/demo/demo-data/pie-donut.ts index 053d8ed986..ad95237026 100644 --- a/packages/core/demo/demo-data/pie-donut.ts +++ b/packages/core/demo/demo-data/pie-donut.ts @@ -1,5 +1,4 @@ import { colors } from "./colors"; -import { getTheme } from "./themes"; export const pieData = { labels: ["2V2N 9KYPM version 1", "L22I P66EP L22I P66EP L22I P66EP", "JQAI 2M4L1", "J9DZ F37AP", @@ -7,7 +6,7 @@ export const pieData = { datasets: [ { label: "Dataset 1", - backgroundColors: colors, + fillColors: colors, data: [75000, 65000, 10000, 25000, 1200, 20000] } ] @@ -15,22 +14,14 @@ export const pieData = { export const pieOptions = { title: "Pie", - accessibility: false, - legendClickable: true, - resizable: true, - colors, - theme: getTheme() + resizable: true }; export const donutData = pieData; export const donutOptions = { title: "Donut", - accessibility: false, - legendClickable: true, resizable: true, - theme: getTheme(), - colors, donut: { center: { label: "Browsers" diff --git a/packages/core/demo/demo-data/themes.ts b/packages/core/demo/demo-data/themes.ts deleted file mode 100644 index 2c95c59bea..0000000000 --- a/packages/core/demo/demo-data/themes.ts +++ /dev/null @@ -1,19 +0,0 @@ -const urlParams = new URLSearchParams(window.location.search); -const { ChartTheme } = require("./../../src/interfaces/enums"); - -export const getTheme = () => { - if (urlParams.has("theme")) { - switch (urlParams.get("theme")) { - case "G10": - return ChartTheme.G10; - case "G90": - return ChartTheme.G90; - case "G100": - return ChartTheme.G100; - default: - return ChartTheme.WHITE; - } - } else { - return ChartTheme.WHITE; - } -}; diff --git a/packages/core/src/components/axes/axis.ts b/packages/core/src/components/axes/axis.ts index f28c4e9942..da3dd62f71 100644 --- a/packages/core/src/components/axes/axis.ts +++ b/packages/core/src/components/axes/axis.ts @@ -30,14 +30,15 @@ export class Axis extends Component { createOrGetScale() { const { position } = this.configs; - const scaleOptions = Tools.getProperty(this.model.getOptions(), "axes", position); + const axisOptions = Tools.getProperty(this.model.getOptions(), "axes", position); + this.scaleType = (axisOptions && axisOptions.scaleType) ? axisOptions.scaleType : ScaleTypes.LINEAR; let scaleFunction; - if (scaleOptions && scaleOptions.type === ScaleTypes.TIME) { + if (this.scaleType === ScaleTypes.TIME) { scaleFunction = scaleTime(); - } else if (scaleOptions && scaleOptions.type === ScaleTypes.LOG) { - scaleFunction = scaleLog().base(scaleOptions.base || 10); - } else if (scaleOptions && scaleOptions.type === ScaleTypes.LABELS) { + } else if (this.scaleType === ScaleTypes.LOG) { + scaleFunction = scaleLog().base(axisOptions.base || 10); + } else if (this.scaleType === ScaleTypes.LABELS) { scaleFunction = scaleBand(); } else { scaleFunction = scaleLinear(); @@ -49,12 +50,12 @@ export class Axis extends Component { [position]: this }; - if (scaleOptions) { - if (scaleOptions.primary === true) { + if (axisOptions) { + if (axisOptions.primary === true) { modelUpdates[AxisTypes.PRIMARY] = this; } - if (scaleOptions.secondary === true) { + if (axisOptions.secondary === true) { modelUpdates[AxisTypes.SECONDARY] = this; } } @@ -63,7 +64,6 @@ export class Axis extends Component { } this.scale = scaleFunction; - this.scaleType = (scaleOptions && scaleOptions.type) ? scaleOptions.type : ScaleTypes.LINEAR; return scaleFunction; } @@ -75,12 +75,12 @@ export class Axis extends Component { getScaleDomain() { const options = this.model.getOptions(); const { position } = this.configs; - const scaleOptions = Tools.getProperty(options, "axes", position); + const axisOptions = Tools.getProperty(options, "axes", position); const { datasets, labels } = this.model.getDisplayData(); // If scale is a LABELS scale, return some labels as the domain - if (scaleOptions && scaleOptions.type === ScaleTypes.LABELS) { + if (axisOptions && axisOptions.scaleType === ScaleTypes.LABELS) { if (labels) { return labels; } else { @@ -91,7 +91,7 @@ export class Axis extends Component { // Get the extent of the domain let domain; // If the scale is stacked - if (scaleOptions.stacked) { + if (axisOptions.stacked) { domain = extent( labels.reduce((m, label: any, i) => { const correspondingValues = datasets.map(dataset => { @@ -110,7 +110,7 @@ export class Axis extends Component { // Get all the chart's data values in a flat array let allDataValues = datasets.reduce((dataValues, dataset: any) => { dataset.data.forEach((datum: any) => { - if (scaleOptions.type === ScaleTypes.TIME) { + if (axisOptions.scaleType === ScaleTypes.TIME) { dataValues = dataValues.concat(datum.date); } else { dataValues = dataValues.concat(isNaN(datum) ? datum.value : datum); @@ -120,14 +120,14 @@ export class Axis extends Component { return dataValues; }, []); - if (scaleOptions.type !== ScaleTypes.TIME) { + if (axisOptions.scaleType !== ScaleTypes.TIME) { allDataValues = allDataValues.concat(0); } domain = extent(allDataValues); } - if (scaleOptions.type === ScaleTypes.TIME) { + if (axisOptions.scaleType === ScaleTypes.TIME) { if (Tools.getProperty(options, "timeScale", "addSpaceOnEdges")) { // TODO - Need to account for non-day incrementals as well const [startDate, endDate] = domain; @@ -166,7 +166,7 @@ export class Axis extends Component { // Grab the scale off of the model, and initialize if it doesn't exist const scale = this.createOrGetScale().domain(this.getScaleDomain()); - if (axisOptions && axisOptions.type === ScaleTypes.LABELS) { + if (this.scaleType === ScaleTypes.LABELS) { scale.rangeRound([startPosition, endPosition]); } else { scale.range([startPosition, endPosition]); diff --git a/packages/core/src/components/essentials/tooltip.ts b/packages/core/src/components/essentials/tooltip.ts index 7a85c863d3..b92035295d 100644 --- a/packages/core/src/components/essentials/tooltip.ts +++ b/packages/core/src/components/essentials/tooltip.ts @@ -92,7 +92,7 @@ export class Tooltip extends Component { points.sort((a, b) => b.value - a.value); // tells us which value to use - const scaleType = this.model.getScaleYType(); + const scaleType = this.services.axes.getMainXAxis().scaleType; return "