Skip to content

Commit 5a29e36

Browse files
committed
fix(Highlight|TooltipContext): Support xInterval / yInterval (#681)
* Fix icon imports * fix(Highlight|TooltipContext): Support xInterval / yInterval
1 parent e9eac2b commit 5a29e36

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

.changeset/cozy-moments-work.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'layerchart': patch
3+
---
4+
5+
fix(Highlight|TooltipContext): Support xInterval / yInterval

packages/layerchart/src/lib/components/Highlight.svelte

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@
264264
tmpArea.width = max(xCoord) - min(xCoord); // Use first/last values for width
265265
} else if (isScaleBand(ctx.xScale)) {
266266
tmpArea.width = ctx.xScale.step();
267+
} else if (ctx.xInterval) {
268+
// x-axis time scale with interval
269+
const start = ctx.xInterval.floor(xValue);
270+
const end = ctx.xInterval.offset(start);
271+
tmpArea.width = ctx.xScale(end) - ctx.xScale(start);
267272
} else {
268273
// Find width to next data point
269274
const index = ctx.flatData.findIndex((d) => Number(x(d)) === Number(x(highlightData)));
@@ -290,6 +295,11 @@
290295
tmpArea.height = max(yCoord) - min(yCoord); // Use first/last values for width
291296
} else if (isScaleBand(ctx.yScale)) {
292297
tmpArea.height = ctx.yScale.step();
298+
} else if (ctx.yInterval) {
299+
// y-axis time scale with interval
300+
const start = ctx.yInterval.floor(yValue);
301+
const end = ctx.yInterval.offset(start);
302+
tmpArea.height = ctx.yScale(end) - ctx.yScale(start);
293303
} else {
294304
// Find width to next data point
295305
const index = ctx.flatData.findIndex((d) => Number(y(d)) === Number(y(highlightData)));

packages/layerchart/src/lib/components/tooltip/TooltipContext.svelte

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,32 @@
518518
height: ctx.yScale.step(),
519519
data: d,
520520
};
521+
} else if (ctx.xInterval) {
522+
// x-axis time scale with interval
523+
const xVal = ctx.x(d);
524+
const start = ctx.xInterval.floor(xVal);
525+
const end = ctx.xInterval.offset(start);
526+
527+
return {
528+
x: ctx.xScale(start),
529+
y: isScaleBand(ctx.yScale) ? y - yOffset : min(ctx.yRange),
530+
width: ctx.xScale(end) - ctx.xScale(start),
531+
height: isScaleBand(ctx.yScale) ? ctx.yScale.step() : fullHeight,
532+
data: d,
533+
};
534+
} else if (ctx.yInterval) {
535+
// y-axis time scale with interval
536+
const yVal = ctx.y(d);
537+
const start = ctx.yInterval.floor(yVal);
538+
const end = ctx.yInterval.offset(start);
539+
540+
return {
541+
x: isScaleBand(ctx.xScale) ? x - xOffset : min(ctx.xRange),
542+
y: ctx.yScale(start),
543+
width: isScaleBand(ctx.xScale) ? ctx.xScale.step() : fullWidth,
544+
height: ctx.yScale(end) - ctx.yScale(start),
545+
data: d,
546+
};
521547
} else if (isScaleTime(ctx.xScale)) {
522548
// Find width to next data point
523549
const index = ctx.flatData.findIndex(

0 commit comments

Comments
 (0)