From ae16d348b4c7f063d14b0a7e2eb1422a1177cca2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 8 Jun 2024 22:11:35 +0000 Subject: [PATCH 1/9] build(deps): bump release-drafter/release-drafter from 5 to 6 Bumps [release-drafter/release-drafter](https://github.com/release-drafter/release-drafter) from 5 to 6. - [Release notes](https://github.com/release-drafter/release-drafter/releases) - [Commits](https://github.com/release-drafter/release-drafter/compare/v5...v6) --- updated-dependencies: - dependency-name: release-drafter/release-drafter dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/release_helper.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release_helper.yml b/.github/workflows/release_helper.yml index 25c09b3..84d8433 100644 --- a/.github/workflows/release_helper.yml +++ b/.github/workflows/release_helper.yml @@ -31,7 +31,7 @@ jobs: echo "releasing ${{ steps.extract_version.outputs.version }} with tag ${{ steps.extract_version.outputs.npm_tag }}" - name: Create Release id: create_release - uses: release-drafter/release-drafter@v5 + uses: release-drafter/release-drafter@v6 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: From 6e49baa234ef454ed8ec344dd4615830e2081387 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 8 Jun 2024 22:11:37 +0000 Subject: [PATCH 2/9] build(deps): bump actions/configure-pages from 4 to 5 Bumps [actions/configure-pages](https://github.com/actions/configure-pages) from 4 to 5. - [Release notes](https://github.com/actions/configure-pages/releases) - [Commits](https://github.com/actions/configure-pages/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/configure-pages dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/deploy_website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy_website.yml b/.github/workflows/deploy_website.yml index 3cc2762..17ffb86 100644 --- a/.github/workflows/deploy_website.yml +++ b/.github/workflows/deploy_website.yml @@ -34,7 +34,7 @@ jobs: ${{ runner.os }}-yarn2-v5 - run: yarn install - run: yarn docs:build - - uses: actions/configure-pages@v4 + - uses: actions/configure-pages@v5 - uses: actions/upload-pages-artifact@v3 with: path: docs/.vitepress/dist From 99b5533fe8ebc0c95536faa291fc03d65902b8bb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 8 Jun 2024 22:11:41 +0000 Subject: [PATCH 3/9] build(deps): bump peter-evans/create-pull-request from 4 to 6 Bumps [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) from 4 to 6. - [Release notes](https://github.com/peter-evans/create-pull-request/releases) - [Commits](https://github.com/peter-evans/create-pull-request/compare/v4...v6) --- updated-dependencies: - dependency-name: peter-evans/create-pull-request dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/create_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 060db06..e9294f4 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -28,7 +28,7 @@ jobs: run: | echo "next_tag=$(npm version --no-git-tag-version ${{ github.event.inputs.versionName }} --preid ${{ github.event.inputs.preid }})" >> $GITHUB_OUTPUT - name: Create pull request into main - uses: peter-evans/create-pull-request@v4 + uses: peter-evans/create-pull-request@v6 with: branch: release/${{ steps.version.outputs.next_tag }} commit-message: 'chore: release ${{ steps.version.outputs.next_tag }}' From 2f39fb85944212965a4b8d310c132d4f0d1c5ef9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 8 Jun 2024 22:11:43 +0000 Subject: [PATCH 4/9] build(deps): bump AButler/upload-release-assets from 2.0.2 to 3.0 Bumps [AButler/upload-release-assets](https://github.com/abutler/upload-release-assets) from 2.0.2 to 3.0. - [Release notes](https://github.com/abutler/upload-release-assets/releases) - [Commits](https://github.com/abutler/upload-release-assets/compare/v2.0.2...v3.0) --- updated-dependencies: - dependency-name: AButler/upload-release-assets dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/release_helper.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release_helper.yml b/.github/workflows/release_helper.yml index 25c09b3..bb37944 100644 --- a/.github/workflows/release_helper.yml +++ b/.github/workflows/release_helper.yml @@ -70,7 +70,7 @@ jobs: - run: yarn build - run: yarn pack - name: Upload Release Asset - uses: AButler/upload-release-assets@v2.0.2 + uses: AButler/upload-release-assets@v3.0 with: files: 'package.tgz' repo-token: ${{ secrets.GITHUB_TOKEN }} From 77daed862419d699e6c442b25e5b1d8b6da085a3 Mon Sep 17 00:00:00 2001 From: Samuel Gratzl Date: Sat, 8 Jun 2024 18:14:47 -0400 Subject: [PATCH 5/9] ci: fix dependabot target branch --- .github/dependabot.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c56a672..dda67f9 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,7 +5,15 @@ updates: directory: '/' schedule: interval: 'monthly' + target-branch: 'dev' + labels: + - 'dependencies' + - 'chore' - package-ecosystem: 'npm' directory: '/' schedule: interval: 'monthly' + target-branch: 'dev' + labels: + - 'dependencies' + - 'chore' From 6227a3e70f0ad0b74ed3768adb3276bb00533b61 Mon Sep 17 00:00:00 2001 From: Samuel Gratzl Date: Sat, 8 Jun 2024 22:13:38 -0400 Subject: [PATCH 6/9] feat: item tooltip --- docs/examples/items.ts | 3 +- src/controllers/StatsBase.ts | 10 ++- src/elements/BoxAndWiskers.ts | 2 +- src/elements/base.ts | 117 +++++++++++++++++++++++++++------- src/tooltip.ts | 7 ++ 5 files changed, 114 insertions(+), 25 deletions(-) diff --git a/docs/examples/items.ts b/docs/examples/items.ts index c21a204..428e50b 100644 --- a/docs/examples/items.ts +++ b/docs/examples/items.ts @@ -8,8 +8,9 @@ export const config: ChartConfiguration<'boxplot'> = { data, options: { elements: { - boxplot: { + boxandwhiskers: { itemRadius: 2, + itemHitRadius: 4, }, }, }, diff --git a/src/controllers/StatsBase.ts b/src/controllers/StatsBase.ts index 0a63b7f..2351fc0 100644 --- a/src/controllers/StatsBase.ts +++ b/src/controllers/StatsBase.ts @@ -147,7 +147,10 @@ export abstract class StatsBase vScale.getLabelForValue(v)); const s = this._toStringStats(r.value.raw); @@ -166,6 +170,10 @@ export abstract class StatsBase= 0) { + // TODO formatter + return `(item: ${this.items[this.hoveredItemIndex]})`; + } return s; }; return r; diff --git a/src/elements/BoxAndWiskers.ts b/src/elements/BoxAndWiskers.ts index c8b32c2..6a44535 100644 --- a/src/elements/BoxAndWiskers.ts +++ b/src/elements/BoxAndWiskers.ts @@ -259,6 +259,6 @@ export class BoxAndWiskers extends StatsBase { - boxplot: ScriptableAndArrayOptions>; + boxandwhiskers: ScriptableAndArrayOptions>; } } diff --git a/src/elements/base.ts b/src/elements/base.ts index 72dcec4..a8e343f 100644 --- a/src/elements/base.ts +++ b/src/elements/base.ts @@ -116,6 +116,13 @@ export interface IStatsBaseOptions { * @indexable */ itemBorderWidth: number; + /** + * hit radius for hit test of items + * @default 0 + * @scriptable + * @indexable + */ + itemHitRadius: number; /** * padding that is added around the bounding box when computing a mouse hit @@ -195,6 +202,7 @@ export const baseDefaults = { itemStyle: 'circle', itemRadius: 0, itemBorderWidth: 0, + itemHitRadius: 0, meanStyle: 'circle', meanRadius: 3, @@ -399,7 +407,8 @@ export class StatsBase= 0 + this._outlierIndexInRange(mouseX, mouseY, useFinalPosition) != null || + this._itemIndexInRange(mouseX, mouseY, useFinalPosition) != null ); } @@ -422,7 +431,11 @@ export class StatsBase hitRadius) || (!vertical && Math.abs(mouseY - props.y) > hitRadius)) { - return -1; + return null; } const toCompare = vertical ? mouseY : mouseX; for (let i = 0; i < outliers.length; i += 1) { if (Math.abs(outliers[i] - toCompare) <= hitRadius) { - return i; + return vertical ? { index: i, x: props.x, y: outliers[i] } : { index: i, x: outliers[i], y: props.y }; + } + } + return null; + } + + /** + * @hidden + */ + protected _itemIndexInRange( + mouseX: number, + mouseY: number, + useFinalPosition?: boolean + ): { index: number; x: number; y: number } | null { + const hitRadius = this.options.itemHitRadius; + if (hitRadius <= 0) { + return null; + } + const props = this.getProps(['x', 'y', 'items', 'width', 'height', 'outliers'], useFinalPosition); + const vert = this.isVertical(); + const { options } = this; + + if (options.itemRadius <= 0 || !props.items || props.items.length <= 0) { + return null; + } + // jitter based on random data + // use the dataset index and index to initialize the random number generator + const random = rnd(this._datasetIndex * 1000 + this._index); + const outliers = new Set(props.outliers || []); + + if (vert) { + for (let i = 0; i < props.items.length; i++) { + const y = props.items[i]; + if (!outliers.has(y)) { + const x = props.x - props.width / 2 + random() * props.width; + if (Math.abs(x - mouseX) <= hitRadius && Math.abs(y - mouseY) <= hitRadius) { + return { index: i, x, y }; + } + } + } + } else { + for (let i = 0; i < props.items.length; i++) { + const x = props.items[i]; + if (!outliers.has(x)) { + const y = props.y - props.height / 2 + random() * props.height; + if (Math.abs(x - mouseX) <= hitRadius && Math.abs(y - mouseY) <= hitRadius) { + return { index: i, x, y }; + } + } } } - return -1; + return null; } /** @@ -482,28 +543,40 @@ export class StatsBase { index: number; datasetIndex: number; }; + _tooltipItem?: { + index: number; + datasetIndex: number; + }; } /** @@ -19,6 +23,9 @@ export function patchInHoveredOutlier( if (value && that._tooltipOutlier != null && item.datasetIndex === that._tooltipOutlier.datasetIndex) { value.hoveredOutlierIndex = that._tooltipOutlier.index; } + if (value && that._tooltipItem != null && item.datasetIndex === that._tooltipItem.datasetIndex) { + value.hoveredItemIndex = that._tooltipItem.index; + } } /** From 31f64e93f2497458bb0e00d10372004939174536 Mon Sep 17 00:00:00 2001 From: Samuel Gratzl Date: Sat, 8 Jun 2024 22:29:00 -0400 Subject: [PATCH 7/9] fix: tune interfaces --- src/controllers/BoxPlotController.ts | 2 ++ src/controllers/ViolinController.ts | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/controllers/BoxPlotController.ts b/src/controllers/BoxPlotController.ts index f0cc08c..545ca8e 100644 --- a/src/controllers/BoxPlotController.ts +++ b/src/controllers/BoxPlotController.ts @@ -11,6 +11,7 @@ import { AnimationOptions, ScriptableContext, CartesianScaleTypeRegistry, + BarControllerDatasetOptions, } from 'chart.js'; import { merge } from 'chart.js/helpers'; import { asBoxPlotStats, IBoxPlot, IBoxplotOptions } from '../data'; @@ -70,6 +71,7 @@ export class BoxPlotController extends StatsBase, IBoxplotOptions, ScriptableAndArrayOptions>, ScriptableAndArrayOptions>, diff --git a/src/controllers/ViolinController.ts b/src/controllers/ViolinController.ts index 1433863..35e5bc0 100644 --- a/src/controllers/ViolinController.ts +++ b/src/controllers/ViolinController.ts @@ -11,6 +11,7 @@ import { AnimationOptions, ScriptableContext, CartesianScaleTypeRegistry, + BarControllerDatasetOptions, } from 'chart.js'; import { merge } from 'chart.js/helpers'; import { asViolinStats, IViolin, IViolinOptions } from '../data'; @@ -79,6 +80,10 @@ export type ViolinDataPoint = number[] | (Partial & Pick, IViolinOptions, ScriptableAndArrayOptions>, ScriptableAndArrayOptions>, From 0d8789ef758a324e6c032e11d5f053eb0949ceb3 Mon Sep 17 00:00:00 2001 From: Samuel Gratzl Date: Sat, 8 Jun 2024 22:31:14 -0400 Subject: [PATCH 8/9] fix: linting --- src/controllers/BoxPlotController.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/BoxPlotController.ts b/src/controllers/BoxPlotController.ts index 545ca8e..09a7455 100644 --- a/src/controllers/BoxPlotController.ts +++ b/src/controllers/BoxPlotController.ts @@ -71,7 +71,10 @@ export class BoxPlotController extends StatsBase, + Pick< + BarControllerDatasetOptions, + 'barPercentage' | 'barThickness' | 'categoryPercentage' | 'maxBarThickness' | 'minBarLength' + >, IBoxplotOptions, ScriptableAndArrayOptions>, ScriptableAndArrayOptions>, From 75decf461b7fdac772d573701d5a73902d4ce5b5 Mon Sep 17 00:00:00 2001 From: sgratzl <4129778+sgratzl@users.noreply.github.com> Date: Sun, 9 Jun 2024 02:33:08 +0000 Subject: [PATCH 9/9] chore: release v4.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9ea66d2..36c34cf 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": "4.3.3", + "version": "4.4.0", "publishConfig": { "access": "public" },