Skip to content

Commit 613e974

Browse files
authored
fix(Highlight|TooltipContext): Support xInterval / yInterval (#681)
* Fix icon imports * fix(Highlight|TooltipContext): Support xInterval / yInterval
1 parent eda1f16 commit 613e974

File tree

6 files changed

+49
-8
lines changed

6 files changed

+49
-8
lines changed

.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
@@ -482,6 +482,32 @@
482482
height: ctx.yScale.step(),
483483
data: d,
484484
};
485+
} else if (ctx.xInterval) {
486+
// x-axis time scale with interval
487+
const xVal = ctx.x(d);
488+
const start = ctx.xInterval.floor(xVal);
489+
const end = ctx.xInterval.offset(start);
490+
491+
return {
492+
x: ctx.xScale(start),
493+
y: isScaleBand(ctx.yScale) ? y - yOffset : min(ctx.yRange),
494+
width: ctx.xScale(end) - ctx.xScale(start),
495+
height: isScaleBand(ctx.yScale) ? ctx.yScale.step() : fullHeight,
496+
data: d,
497+
};
498+
} else if (ctx.yInterval) {
499+
// y-axis time scale with interval
500+
const yVal = ctx.y(d);
501+
const start = ctx.yInterval.floor(yVal);
502+
const end = ctx.yInterval.offset(start);
503+
504+
return {
505+
x: isScaleBand(ctx.xScale) ? x - xOffset : min(ctx.xRange),
506+
y: ctx.yScale(start),
507+
width: isScaleBand(ctx.xScale) ? ctx.xScale.step() : fullWidth,
508+
height: ctx.yScale(end) - ctx.yScale(start),
509+
data: d,
510+
};
485511
} else if (isScaleTime(ctx.xScale)) {
486512
// Find width to next data point
487513
const index = ctx.flatData.findIndex(

packages/layerchart/src/lib/docs/ViewSourceButton.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import type { ComponentProps } from 'svelte';
33
import { Button, Dialog, Toggle, Tooltip } from 'svelte-ux';
4-
import LucideGithub from '~icons/lucide/github.svelte';
4+
import LucideGithub from '~icons/lucide/github';
55
66
import Code from './Code.svelte';
77

packages/layerchart/src/routes/docs/+layout.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import { onMount } from 'svelte';
33
import { flatGroup } from 'd3-array';
44
5-
import LucideAlignLeft from '~icons/lucide/align-left.svelte';
6-
import LucideChevronRight from '~icons/lucide/chevron-right.svelte';
7-
import LucideChevronDown from '~icons/lucide/chevron-down.svelte';
8-
import LucideCircleCheck from '~icons/lucide/circle-check.svelte';
5+
import LucideAlignLeft from '~icons/lucide/align-left';
6+
import LucideChevronRight from '~icons/lucide/chevron-right';
7+
import LucideChevronDown from '~icons/lucide/chevron-down';
8+
import LucideCircleCheck from '~icons/lucide/circle-check';
99
import LucideCode from '~icons/lucide/code';
1010
import LucideBraces from '~icons/lucide/braces';
1111
import LucideDatabase from '~icons/lucide/database';
1212
import LucideFilePenLine from '~icons/lucide/file-pen-line';
13-
import LucideGithub from '~icons/lucide/github.svelte';
13+
import LucideGithub from '~icons/lucide/github';
1414
import LucideLink2 from '~icons/lucide/link-2';
1515
import IconSettings from '~icons/lucide/settings';
1616
import LucideX from '~icons/lucide/x';

packages/layerchart/src/routes/docs/components/BrushContext/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
type DomainType,
2424
} from 'layerchart';
2525
26-
import LucideChevronLeft from '~icons/lucide/chevron-left.svelte';
27-
import LucideChevronRight from '~icons/lucide/chevron-right.svelte';
26+
import LucideChevronLeft from '~icons/lucide/chevron-left';
27+
import LucideChevronRight from '~icons/lucide/chevron-right';
2828
2929
import Preview from '$lib/docs/Preview.svelte';
3030
import { createDateSeries, randomWalk } from '$lib/utils/genData.js';

0 commit comments

Comments
 (0)