Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { getState, type OriginalScaleLimits, type ScaleRange, type State, type UpdatedScaleLimits } from './state.js'
import { directionEnabled, getEnabledScalesByPoint } from './utils.js'
import type { Chart, Point, Scale, UpdateMode } from 'chart.js'
import type { LimitOptions, ZoomTrigger } from './options.js'
import type { LimitOptions, PanTrigger, ZoomTrigger } from './options.js'
import type { ZoomAmount } from './types.js'

function shouldUpdateScaleLimits(
Expand Down Expand Up @@ -89,7 +89,7 @@

chart.update(transition)

zoomOptions?.onZoom?.({ chart, trigger })
zoomOptions?.onZoom?.({ chart, trigger, amount: { x, y, focalPoint } })
}

export function zoomRect(
Expand Down Expand Up @@ -207,7 +207,7 @@

type PanAmount = number | Partial<Point>

export function pan(chart: Chart, delta: PanAmount, enabledScales?: Scale[], transition: UpdateMode = 'none') {
export function pan(chart: Chart, delta: PanAmount, enabledScales?: Scale[], transition: UpdateMode = 'none', trigger: PanTrigger = "other") {

Check failure on line 210 in src/core.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Strings must use singlequote

Check failure on line 210 in src/core.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Replace `chart:·Chart,·delta:·PanAmount,·enabledScales?:·Scale[],·transition:·UpdateMode·=·'none',·trigger:·PanTrigger·=·"other"` with `⏎··chart:·Chart,⏎··delta:·PanAmount,⏎··enabledScales?:·Scale[],⏎··transition:·UpdateMode·=·'none',⏎··trigger:·PanTrigger·=·'other'⏎`

Check failure on line 210 in src/core.ts

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

Strings must use singlequote

Check failure on line 210 in src/core.ts

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

Replace `chart:·Chart,·delta:·PanAmount,·enabledScales?:·Scale[],·transition:·UpdateMode·=·'none',·trigger:·PanTrigger·=·"other"` with `␍⏎··chart:·Chart,␍⏎··delta:·PanAmount,␍⏎··enabledScales?:·Scale[],␍⏎··transition:·UpdateMode·=·'none',␍⏎··trigger:·PanTrigger·=·'other'␍⏎`
const { x = 0, y = 0 } = typeof delta === 'number' ? { x: delta, y: delta } : delta
const state = getState(chart)
const {
Expand All @@ -232,7 +232,7 @@

chart.update(transition)

onPan?.({ chart })
onPan?.({ chart, trigger, delta: { x, y } })
}

export function getInitialScaleBounds(chart: Chart) {
Expand Down
5 changes: 3 additions & 2 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export type ModifierKey = 'ctrl' | 'alt' | 'shift' | 'meta'
export type DrawTime = 'afterDraw' | 'afterDatasetsDraw' | 'beforeDraw' | 'beforeDatasetsDraw'
export type ZoomTrigger = 'api' | 'drag' | 'wheel' | 'pinch'
export type PanTrigger = 'api' | 'drag' | 'wheel' | 'other'

type RejectableStartEvent<T = Event | HammerInput> = (context: {
chart: Chart
Expand Down Expand Up @@ -120,7 +121,7 @@
/**
* Function called while the user is zooming
*/
onZoom?: (context: { chart: Chart; trigger: ZoomTrigger }) => void
onZoom?: (context: { chart: Chart; trigger: ZoomTrigger; amount?: { x: number, y: number } & { focalPoint: Point } }) => void

Check failure on line 124 in src/options.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Replace `·chart:·Chart;·trigger:·ZoomTrigger;·amount?:·{·x:·number,·y:·number·}·&·{·focalPoint:·Point·}` with `⏎····chart:·Chart⏎····trigger:·ZoomTrigger⏎····amount?:·{·x:·number;·y:·number·}·&·{·focalPoint:·Point·}⏎·`

Check failure on line 124 in src/options.ts

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

Replace `·chart:·Chart;·trigger:·ZoomTrigger;·amount?:·{·x:·number,·y:·number·}·&·{·focalPoint:·Point·}` with `␍⏎····chart:·Chart␍⏎····trigger:·ZoomTrigger␍⏎····amount?:·{·x:·number;·y:·number·}·&·{·focalPoint:·Point·}␍⏎·`

/**
* Function called once zooming is completed
Expand Down Expand Up @@ -172,7 +173,7 @@
/**
* Function called while the user is panning
*/
onPan?: GenericEvent
onPan?: (context: { chart: Chart; trigger: PanTrigger; delta: { x: number, y: number } }) => void

Check failure on line 176 in src/options.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Replace `,` with `;`

Check failure on line 176 in src/options.ts

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

Replace `,` with `;`

/**
* Function called once panning is completed
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}

const bindApi = (chart: Chart) => {
chart.pan = (delta, panScales, transition) => pan(chart, delta, panScales, transition)
chart.pan = (delta, panScales, transition) => pan(chart, delta, panScales, transition, "api")

Check failure on line 53 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Strings must use singlequote

Check failure on line 53 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Replace `"api"` with `'api'`

Check failure on line 53 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

Strings must use singlequote

Check failure on line 53 in src/plugin.ts

View workflow job for this annotation

GitHub Actions / ci (windows-latest)

Replace `"api"` with `'api'`
chart.zoom = (args, transition) => zoom(chart, args, transition)
chart.zoomRect = (p0, p1, transition) => zoomRect(chart, p0, p1, transition)
chart.zoomScale = (id, range, transition) => zoomScale(chart, id, range, transition)
Expand Down
Loading