Skip to content

Commit 121a8fb

Browse files
feat: set tooltip to follow when single value scale
1 parent c2c13bd commit 121a8fb

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/lib/utils/interactions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export function isCrosshairTooltipType(type: TooltipType) {
7272
export function isFollowTooltipType(type: TooltipType) {
7373
return type === TooltipType.Follow;
7474
}
75+
export function isNoneTooltipType(type: TooltipType) {
76+
return type === TooltipType.None;
77+
}
7578

7679
export function areIndexedGeometryArraysEquals(arr1: IndexedGeometry[], arr2: IndexedGeometry[]) {
7780
if (arr1.length !== arr2.length) {

src/state/chart_state.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,4 +866,22 @@ describe('Chart Store', () => {
866866
expect(store.isCrosshairCursorVisible.get()).toBe(false);
867867
});
868868
});
869+
test('should set tooltip type to follow when single value x scale', () => {
870+
const singleValueSpec: BarSeriesSpec = {
871+
id: SPEC_ID,
872+
groupId: GROUP_ID,
873+
seriesType: 'bar',
874+
yScaleToDataExtent: false,
875+
data: [{ x: 1, y: 1, g: 0 }],
876+
xAccessor: 'x',
877+
yAccessors: ['y'],
878+
xScaleType: ScaleType.Linear,
879+
yScaleType: ScaleType.Linear,
880+
hideInLegend: false,
881+
};
882+
883+
store.addSeriesSpec(singleValueSpec);
884+
store.computeChart();
885+
expect(store.tooltipType.get()).toBe(TooltipType.Follow);
886+
});
869887
});

src/state/chart_state.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
getValidYPosition,
5757
isCrosshairTooltipType,
5858
isFollowTooltipType,
59+
isNoneTooltipType,
5960
TooltipType,
6061
TooltipValue,
6162
TooltipValueFormatter,
@@ -876,6 +877,12 @@ export class ChartStore {
876877
// console.log({ seriesGeometries });
877878
this.geometries = seriesGeometries.geometries;
878879
this.xScale = seriesGeometries.scales.xScale;
880+
881+
const isSingleValueXScale = this.xScale.isSingleValue();
882+
if (isSingleValueXScale && !isNoneTooltipType(this.tooltipType.get())) {
883+
this.tooltipType.set(TooltipType.Follow);
884+
}
885+
879886
this.yScales = seriesGeometries.scales.yScales;
880887
this.geometriesIndex = seriesGeometries.geometriesIndex;
881888
this.geometriesIndexKeys = [...this.geometriesIndex.keys()].sort(compareByValueAsc);

0 commit comments

Comments
 (0)