From a4a10bf3e155a84b0e9ee7b96d1c63e4470734b7 Mon Sep 17 00:00:00 2001 From: Samuel Gratzl Date: Fri, 18 Feb 2022 09:01:35 -0500 Subject: [PATCH 1/5] feat: add element options --- src/controllers/BoxPlotController.ts | 4 +++- src/controllers/ViolinController.ts | 4 +++- src/elements/BoxAndWiskers.ts | 7 +++++++ src/elements/Violin.ts | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/controllers/BoxPlotController.ts b/src/controllers/BoxPlotController.ts index 61bcf0e..37959f4 100644 --- a/src/controllers/BoxPlotController.ts +++ b/src/controllers/BoxPlotController.ts @@ -8,6 +8,7 @@ ChartConfiguration, LinearScale, CategoryScale, + AnimationOptions, } from 'chart.js'; import { merge } from 'chart.js/helpers'; import { asBoxPlotStats, IBaseStats, IBoxPlot, IBoxplotOptions } from '../data'; @@ -57,7 +58,8 @@ export interface BoxPlotControllerDatasetOptions extends ControllerDatasetOptions, IBoxplotOptions, ScriptableAndArrayOptions, - ScriptableAndArrayOptions {} + ScriptableAndArrayOptions, + AnimationOptions<'boxplot'> {} export type BoxPlotDataPoint = number[] | (Partial & IBaseStats); diff --git a/src/controllers/ViolinController.ts b/src/controllers/ViolinController.ts index 0329dc8..b36b049 100644 --- a/src/controllers/ViolinController.ts +++ b/src/controllers/ViolinController.ts @@ -8,6 +8,7 @@ ChartConfiguration, LinearScale, CategoryScale, + AnimationOptions, } from 'chart.js'; import { merge } from 'chart.js/helpers'; import { asViolinStats, IBaseStats, IViolin, IViolinOptions } from '../data'; @@ -66,7 +67,8 @@ export interface ViolinControllerDatasetOptions extends ControllerDatasetOptions, IViolinOptions, ScriptableAndArrayOptions, - ScriptableAndArrayOptions {} + ScriptableAndArrayOptions, + AnimationOptions<'violin'> {} // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface IViolinChartOptions {} diff --git a/src/elements/BoxAndWiskers.ts b/src/elements/BoxAndWiskers.ts index 2d9ce12..ca695be 100644 --- a/src/elements/BoxAndWiskers.ts +++ b/src/elements/BoxAndWiskers.ts @@ -226,3 +226,10 @@ export class BoxAndWiskers extends StatsBase { + boxplot: ScriptableAndArrayOptions>; + } +} diff --git a/src/elements/Violin.ts b/src/elements/Violin.ts index 3860969..35eccd0 100644 --- a/src/elements/Violin.ts +++ b/src/elements/Violin.ts @@ -108,3 +108,9 @@ export class Violin extends StatsBase { + violin: ScriptableAndArrayOptions>; + } +} From 4c01f5f02bade09ca3b7ece27537dddf9ddde614 Mon Sep 17 00:00:00 2001 From: Samuel Gratzl Date: Fri, 18 Feb 2022 09:16:31 -0500 Subject: [PATCH 2/5] test: add type test --- .github/workflows/ci.yml | 1 + .gitignore | 4 +++- .prettierignore | 3 ++- README.md | 4 ++-- package.json | 1 + samples/type_test.ts | 37 +++++++++++++++++++++++++++++++++++ src/elements/BoxAndWiskers.ts | 1 - 7 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 samples/type_test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70d49de..1131910 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,7 @@ jobs: - run: yarn build - run: yarn lint - run: yarn test + - run: yarn samples - uses: actions/upload-artifact@v2 if: failure() with: diff --git a/.gitignore b/.gitignore index e65b98d..cbbfefc 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,6 @@ npm-debug.log* /.vscode/extensions.json /docs *.tsbuildinfo -__diff_output__ \ No newline at end of file +__diff_output__ + +/samples/type_test.js \ No newline at end of file diff --git a/.prettierignore b/.prettierignore index 7b78f87..648c305 100644 --- a/.prettierignore +++ b/.prettierignore @@ -12,4 +12,5 @@ /.vscode *.png *.tgz -*.tsbuildinfo \ No newline at end of file +*.tsbuildinfo +/samples/type_test.js \ No newline at end of file diff --git a/README.md b/README.md index b8016c1..fdfa630 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ The ESM build of the library supports tree shaking thus having no side effects. Variant A: ```js -import Chart, { LinearScale, CategoryScale } from 'chart.js'; +import { Chart, LinearScale, CategoryScale } from 'chart.js'; import { BoxPlotController, BoxAndWiskers } from '@sgratzl/chartjs-chart-boxplot'; // register controller in chart.js and ensure the defaults are set @@ -91,7 +91,7 @@ Chart.register(BoxPlotController, BoxAndWiskers, LinearScale, CategoryScale); ... new Chart(ctx, { - type: BoxPlotController.id, + type: 'boxplot', data: [...], }); ``` diff --git a/package.json b/package.json index 9586b6c..35b6243 100644 --- a/package.json +++ b/package.json @@ -106,6 +106,7 @@ "test": "jest --passWithNoTests", "test:watch": "jest --passWithNoTests --watch", "test:coverage": "jest --passWithNoTests --coverage", + "samples": "yarn tsc samples/type_test.ts", "lint": "yarn run eslint && yarn run prettier", "fix": "yarn run eslint:fix && yarn run prettier:write", "prettier:write": "prettier \"*\" \"*/**\" --write", diff --git a/samples/type_test.ts b/samples/type_test.ts new file mode 100644 index 0000000..53a553d --- /dev/null +++ b/samples/type_test.ts @@ -0,0 +1,37 @@ +import { Chart, LinearScale, CategoryScale } from 'chart.js'; +import { BoxPlotController, BoxAndWiskers } from '../build'; + +// register controller in chart.js and ensure the defaults are set +Chart.register(BoxPlotController, BoxAndWiskers, LinearScale, CategoryScale); + +const ctx = document.querySelector('canvas').getContext('2d'); + +const myBar = new Chart(ctx, { + type: 'boxplot', + data: { + labels: ['vs'], + datasets: [ + { + label: 'Dataset 1', + outlierRadius: 10, + data: [ + [1, 2, 3, 4, 5], + { + min: 1, + q1: 2, + median: 3, + q3: 4, + max: 5, + }, + ], + }, + ], + }, + options: { + elements: { + boxplot: { + outlierRadius: 10, + }, + }, + }, +}); diff --git a/src/elements/BoxAndWiskers.ts b/src/elements/BoxAndWiskers.ts index ca695be..195a91d 100644 --- a/src/elements/BoxAndWiskers.ts +++ b/src/elements/BoxAndWiskers.ts @@ -227,7 +227,6 @@ export class BoxAndWiskers extends StatsBase { boxplot: ScriptableAndArrayOptions>; From 014278562081aeed93b0bd24ccc748d6434f7370 Mon Sep 17 00:00:00 2001 From: Samuel Gratzl Date: Fri, 18 Feb 2022 09:18:07 -0500 Subject: [PATCH 3/5] feat: add violin example --- samples/type_test.ts | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/samples/type_test.ts b/samples/type_test.ts index 53a553d..70a0c7d 100644 --- a/samples/type_test.ts +++ b/samples/type_test.ts @@ -1,5 +1,5 @@ import { Chart, LinearScale, CategoryScale } from 'chart.js'; -import { BoxPlotController, BoxAndWiskers } from '../build'; +import { BoxPlotController, BoxAndWiskers, Violin, ViolinController } from '../build'; // register controller in chart.js and ensure the defaults are set Chart.register(BoxPlotController, BoxAndWiskers, LinearScale, CategoryScale); @@ -35,3 +35,33 @@ const myBar = new Chart(ctx, { }, }, }); + +const myViolin = new Chart(ctx, { + type: 'violin', + data: { + labels: ['vs'], + datasets: [ + { + label: 'Dataset 1', + outlierRadius: 10, + data: [ + [1, 2, 3, 4, 5], + { + min: 1, + q1: 2, + median: 3, + q3: 4, + max: 5, + }, + ], + }, + ], + }, + options: { + elements: { + violin: { + outlierRadius: 10, + }, + }, + }, +}); From b4170a08fb6eac942ddc7f7ebfef8a58af4cadbf Mon Sep 17 00:00:00 2001 From: Samuel Gratzl Date: Fri, 18 Feb 2022 09:18:50 -0500 Subject: [PATCH 4/5] fix: register violin --- samples/type_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/type_test.ts b/samples/type_test.ts index 70a0c7d..cb7df9c 100644 --- a/samples/type_test.ts +++ b/samples/type_test.ts @@ -2,7 +2,7 @@ import { Chart, LinearScale, CategoryScale } from 'chart.js'; import { BoxPlotController, BoxAndWiskers, Violin, ViolinController } from '../build'; // register controller in chart.js and ensure the defaults are set -Chart.register(BoxPlotController, BoxAndWiskers, LinearScale, CategoryScale); +Chart.register(BoxPlotController, BoxAndWiskers, Violin, ViolinController, LinearScale, CategoryScale); const ctx = document.querySelector('canvas').getContext('2d'); From 851f74699572270e8d0dd244bf272114eb1bc813 Mon Sep 17 00:00:00 2001 From: sgratzl Date: Mon, 21 Feb 2022 02:03:54 +0000 Subject: [PATCH 5/5] chore: release v3.7.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 35b6243..c10e536 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@sgratzl/chartjs-chart-boxplot", "description": "Chart.js module for charting boxplots and violin charts", - "version": "3.7.0", + "version": "3.7.1", "publishConfig": { "access": "public" },