Skip to content

Commit

Permalink
AG-13306 Use relative coordinates for focus indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
olegat committed Nov 14, 2024
1 parent 1ff1c3f commit a1b8965
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,6 @@ export class BarSeries extends AbstractBarSeries<Rect, BarSeriesProperties, BarN

protected computeFocusBounds({ datumIndex, seriesRect }: PickFocusInputs): BBox | undefined {
const datumBox = this.contextNodeData?.nodeData[datumIndex].clipBBox;
return computeBarFocusBounds(datumBox, this.contentGroup, seriesRect);
return computeBarFocusBounds(datumBox, seriesRect);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { ContinuousScale } from '../../../scale/continuousScale';
import type { Scale } from '../../../scale/scale';
import { BBox } from '../../../scene/bbox';
import type { DropShadow } from '../../../scene/dropShadow';
import type { Group } from '../../../scene/group';
import type { Rect } from '../../../scene/shape/rect';
import { Transformable } from '../../../scene/transformable';
import { isNegative } from '../../../util/number';
import { mergeDefaults } from '../../../util/object';
import type { ChartAxis } from '../../chartAxis';
Expand Down Expand Up @@ -297,11 +295,10 @@ export function resetBarSelectionsFn(_node: Rect, { x, y, width, height, clipBBo

export function computeBarFocusBounds(
datum: { x: number; y: number; width: number; height: number } | undefined,
barGroup: Group,
seriesRect: BBox | undefined
): BBox | undefined {
if (datum === undefined) return undefined;

const { x, y, width, height } = datum;
return Transformable.toCanvas(barGroup, new BBox(x, y, width, height)).clip(seriesRect);
return new BBox(x, y, width, height).clip(seriesRect);
}
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,6 @@ export class HistogramSeries extends CartesianSeries<Rect, HistogramSeriesProper
}

protected computeFocusBounds({ datumIndex, seriesRect }: PickFocusInputs): BBox | undefined {
return computeBarFocusBounds(this.contextNodeData?.nodeData[datumIndex], this.contentGroup, seriesRect);
return computeBarFocusBounds(this.contextNodeData?.nodeData[datumIndex], seriesRect);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { QUICK_TRANSITION } from '../../../motion/animation';
import type { NodeUpdateState } from '../../../motion/fromToMotion';
import { NODE_UPDATE_STATE_TO_PHASE_MAPPING, fromToMotion, staticFromToMotion } from '../../../motion/fromToMotion';
import { BBox } from '../../../scene/bbox';
import type { Group } from '../../../scene/group';
import type { Node } from '../../../scene/node';
import type { Point, SizedPoint } from '../../../scene/point';
import type { Selection } from '../../../scene/selection';
import { Transformable } from '../../../scene/transformable';
import { clamp } from '../../../util/number';
import type { AnimationManager } from '../../interaction/animationManager';
import type { Marker } from '../../marker/marker';
Expand Down Expand Up @@ -157,7 +155,6 @@ export function prepareMarkerAnimation(pairMap: PathPointMap<any>, parentStatus:
type MarkerSeries<TDatum> = {
getNodeData(): TDatum[] | undefined;
getFormattedMarkerStyle(datum: TDatum): { size: number };
contentGroup: Group;
};

export function computeMarkerFocusBounds<TDatum extends { point: Point & SizedPoint }>(
Expand All @@ -175,5 +172,5 @@ export function computeMarkerFocusBounds<TDatum extends { point: Point & SizedPo
const radius = size / 2;
const x = datum.point.x - radius;
const y = datum.point.y - radius;
return Transformable.toCanvas(series.contentGroup, new BBox(x, y, size, size));
return new BBox(x, y, size, size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,6 @@ export class BoxPlotSeries extends _ModuleSupport.AbstractBarSeries<
datumIndex,
seriesRect,
}: _ModuleSupport.PickFocusInputs): _ModuleSupport.BBox | undefined {
return computeBarFocusBounds(
this.contextNodeData?.nodeData[datumIndex].focusRect,
this.contentGroup,
seriesRect
);
return computeBarFocusBounds(this.contextNodeData?.nodeData[datumIndex].focusRect, seriesRect);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ function getCoordinates(datum: CandlestickNodeDatum) {

type AbstractCandlestickSeries = {
getNodeData(): CandlestickNodeBaseDatum[] | undefined;
contentGroup: _ModuleSupport.Group;
};

export function computeCandleFocusBounds(
Expand All @@ -121,5 +120,5 @@ export function computeCandleFocusBounds(
width: candleDatum.bandwidth,
height: candleDatum.scaledValues.lowValue - candleDatum.scaledValues.highValue,
};
return computeBarFocusBounds(datum, series.contentGroup, opts.seriesRect);
return computeBarFocusBounds(datum, opts.seriesRect);
}
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export abstract class BaseFunnelSeries<
datumIndex,
seriesRect,
}: _ModuleSupport.PickFocusInputs): _ModuleSupport.BBox | undefined {
return computeBarFocusBounds(this.contextNodeData?.nodeData[datumIndex], this.contentGroup, seriesRect);
return computeBarFocusBounds(this.contextNodeData?.nodeData[datumIndex], seriesRect);
}

getLegendData(legendType: _ModuleSupport.ChartLegendType): _ModuleSupport.CategoryLegendDatum[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,6 @@ export class HeatmapSeries extends _ModuleSupport.CartesianSeries<
if (datum === undefined) return undefined;
const { width, height, midPoint } = datum;
const focusRect = { x: midPoint.x - width / 2, y: midPoint.y - height / 2, width, height };
return computeBarFocusBounds(focusRect, this.contentGroup, seriesRect);
return computeBarFocusBounds(focusRect, seriesRect);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,6 @@ export class MapLineSeries

protected override computeFocusBounds(opts: _ModuleSupport.PickFocusInputs): _ModuleSupport.BBox | undefined {
const geometry = findFocusedGeoGeometry(this, opts);
return geometry ? _ModuleSupport.Transformable.toCanvas(geometry) : undefined;
return geometry ? geometry.getBBox() : undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,6 @@ export class RangeBarSeries extends _ModuleSupport.AbstractBarSeries<
datumIndex,
seriesRect,
}: _ModuleSupport.PickFocusInputs): _ModuleSupport.BBox | undefined {
return computeBarFocusBounds(this.contextNodeData?.nodeData[datumIndex], this.contentGroup, seriesRect);
return computeBarFocusBounds(this.contextNodeData?.nodeData[datumIndex], seriesRect);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const {
Logger,
Rect,
BBox,
Transformable,
} = _ModuleSupport;

export interface SankeyNodeDataContext
Expand Down Expand Up @@ -634,7 +633,7 @@ export class SankeySeries extends FlowProportionSeries<
if (datum?.type === FlowProportionDatumType.Node) {
const { x, y, width, height } = datum;
const bbox = new BBox(x, y, width, height);
return Transformable.toCanvas(this.contentGroup, bbox).clip(seriesRect);
return bbox.clip(seriesRect);
} else if (datum?.type === FlowProportionDatumType.Link) {
for (const link of this.linkSelection) {
if (link.datum === datum) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const {
clamp,
isNumberEqual,
sanitizeHtml,
Transformable,
Rect,
Group,
BBox,
Expand Down Expand Up @@ -827,6 +826,6 @@ export class TreemapSeries<
node: _ModuleSupport.HierarchyNode<_ModuleSupport.SeriesNodeDatum>
): _ModuleSupport.BBox | undefined {
const rects = this.groupSelection.selectByClass(Rect);
return Transformable.toCanvas(rects[node.index]);
return rects[node.index].getBBox();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,6 @@ export class WaterfallSeries extends _ModuleSupport.AbstractBarSeries<
datumIndex,
seriesRect,
}: _ModuleSupport.PickFocusInputs): _ModuleSupport.BBox | undefined {
return computeBarFocusBounds(this.contextNodeData?.nodeData[datumIndex], this.contentGroup, seriesRect);
return computeBarFocusBounds(this.contextNodeData?.nodeData[datumIndex], seriesRect);
}
}

0 comments on commit a1b8965

Please sign in to comment.