Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tickFormat typing
  • Loading branch information
gka committed Feb 20, 2026
commit a8a8f223aafe30f774c2731dbda08be430c5b332
12 changes: 9 additions & 3 deletions src/lib/types/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import type { ChannelAccessor, RawValue, ScaledChannelName } from './index.js';
export type AxisXAnchor = 'bottom' | 'top' | 'both';
export type AxisYAnchor = 'left' | 'right' | 'both';

export type TickFormatFunction = (
d: number | Date,
index: number,
ticks: (number | Date)[]
) => string;

export type ScaleName =
| 'x'
| 'y'
Expand Down Expand Up @@ -180,7 +186,7 @@ export type ColorScaleOptions = ScaleOptions & {
/**
* The tick format for the color scale legend.
*/
tickFormat: false | Intl.NumberFormatOptions | ((d: RawValue) => string);
tickFormat: false | Intl.NumberFormatOptions | TickFormatFunction;
};

export type ScaleType =
Expand Down Expand Up @@ -232,7 +238,7 @@ export type XScaleOptions = ScaleOptions & {
* custom tick format; false to hide tick labels, an Intl.NumberFormatOptions
* object, or a function mapping values to strings
*/
tickFormat: false | Intl.NumberFormatOptions | ((d: RawValue) => string);
tickFormat: false | Intl.NumberFormatOptions | TickFormatFunction;
/**
* Enable word wrapping for axis tick labels, default true
*/
Expand Down Expand Up @@ -260,7 +266,7 @@ export type YScaleOptions = ScaleOptions & {
* custom tick format; false to hide tick labels, an Intl.NumberFormatOptions
* object, or a function mapping values to strings
*/
tickFormat: false | Intl.NumberFormatOptions | ((d: RawValue) => string);
tickFormat: false | Intl.NumberFormatOptions | TickFormatFunction;
/**
* rotate the axis ticks
*/
Expand Down
2 changes: 1 addition & 1 deletion src/routes/examples/area/from-numbers.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
</script>

<Plot grid>
<AreaY data={[1, 3, 2, 4, undefined, 6, 8, 7]} />
<AreaY data={[1, 3, 2, 4, NaN, 6, 8, 7]} />
</Plot>
8 changes: 5 additions & 3 deletions src/routes/examples/arrow/metro.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
});

let hl: false | MetrosRow = $state(false);
let hl = $state<MetrosRow | null>(null);
</script>

<Plot
Expand Down Expand Up @@ -53,15 +53,17 @@
value: (d) =>
!hl || hl.Metro === d.Metro ? 1 : 0.1
}}
onmouseenter={(evt, d) => (hl = d)}
onmouseenter={(evt, d) => (hl = d ?? null)}
onmouseleave={() => (hl = null)}
stroke={(d) => d.R90_10_2015 - d.R90_10_1980} />
<Text
data={metros}
x="POP_2015"
y="R90_10_2015"
filter={(d) =>
hl ? hl.Metro === d.Metro : d.highlight}
hl
? hl.Metro === d.Metro
: Boolean(d.highlight)}
text="nyt_display"
fill="currentColor"
stroke="var(--svelteplot-bg)"
Expand Down
7 changes: 4 additions & 3 deletions src/routes/examples/axis/unit-tick.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
'https://svelte.dev/playground/df7b2c9ec47844e686a12926b10b0ac2?version=latest';
</script>

<script>
import { Plot, AxisX, AxisY, Line } from 'svelteplot';
let { aapl } = $props();
<script lang="ts">
import { Plot, Line } from 'svelteplot';
import type { AaplRow } from '../types';
let { aapl }: { aapl: AaplRow[] } = $props();
</script>

<Plot
Expand Down