fix(interaction): keep brushX selection span while dragging #173
Closedandersk(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/173/headopened - packages/charts-core/src/interaction-brush.ts lines 665 to 668OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -644,3 +651,18 @@644651 })645652 }646653654+function translatedSelectionRange<TValue extends ChartValue>(655+ selection: BrushSelection | null,656+ axis: InteractionAxis<TValue>,657+ origin: BrushRange<TValue>,658+): BrushRange<TValue> | null {659+ const snapped = selectionRange(selection, axis)660+ if (!snapped || !axis.values) return snapped661+ // Snapping each edge separately can change the number of selected662+ // values, as when D3 stops the selection at the plot edge between663+ // two values or the values are unevenly spaced. Instead, move the664+ // whole range by the larger of the two edges' snapped offsets.665+ const startIndex = axis.indexOf(origin.start)666+ const endIndex = axis.indexOf(origin.end)667+ const startShift = axis.indexOf(snapped.start) - startIndex668+ const endShift = axis.indexOf(snapped.end) - endIndexpackages/charts-core/src/interaction-brush.ts lines 669 to 674OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -646,0 +654,21 @@654+function translatedSelectionRange<TValue extends ChartValue>(655+ selection: BrushSelection | null,656+ axis: InteractionAxis<TValue>,657+ origin: BrushRange<TValue>,658+): BrushRange<TValue> | null {659+ const snapped = selectionRange(selection, axis)660+ if (!snapped || !axis.values) return snapped661+ // Snapping each edge separately can change the number of selected662+ // values, as when D3 stops the selection at the plot edge between663+ // two values or the values are unevenly spaced. Instead, move the664+ // whole range by the larger of the two edges' snapped offsets.665+ const startIndex = axis.indexOf(origin.start)666+ const endIndex = axis.indexOf(origin.end)667+ const startShift = axis.indexOf(snapped.start) - startIndex668+ const endShift = axis.indexOf(snapped.end) - endIndex669+ const shift = Math.max(670+ -startIndex,671+ Math.min(672+ axis.values.length - 1 - endIndex,673+ Math.abs(startShift) >= Math.abs(endShift) ? startShift : endShift,674+ ),
- packages/charts-core/src/interaction-brush.ts line 674Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -644,3 +655,20 @@644655 })645656 }646657658+function translatedSelectionRange<TValue extends ChartValue>(659+ selection: BrushSelection | null,660+ axis: InteractionAxis<TValue>,661+ originLeft: number,662+): BrushRange<TValue> | null {663+ const snapped = selectionRange(selection, axis)664+ if (!snapped || !axis.values) return snapped665+ // Snapping each edge separately can change the number of selected666+ // values, as when D3 stops the selection at the plot edge between667+ // two values. Instead, snap the edge leading the drag, and place the668+ // other edge the selection's width away from it.669+ const [left, right] = selection as [number, number]670+ const width = right - left671+ if (left > originLeft) {672+ const end = axis.valueAt(right)673+ return normalizeRange(axis, {674+ start: axis.valueAt(axis.position(end) - width),
tannerlinsley closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 73cd72c9f1330bd71e2ff29f3ba80acc124bcf5e
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR