Skip to content

Commit c4bc8b4

Browse files
committed
fix grid styles
1 parent 24b50fb commit c4bc8b4

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

src/lib/marks/GridX.svelte

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import { getContext } from 'svelte';
33
import Mark from '../Mark.svelte';
44
import type { PlotContext, BaseMarkProps, RawValue } from '../types.js';
5-
import { resolveChannel, resolveScaledStyles } from '../helpers/resolve.js';
5+
import { resolveChannel, resolveStyles } from '../helpers/resolve.js';
66
import { autoTicks } from '$lib/helpers/autoTicks.js';
77
import { testFilter } from '$lib/helpers/index.js';
8+
import { RAW_VALUE } from '$lib/transforms/recordize.js';
89
910
type GrixXMarkProps = BaseMarkProps & {
1011
data?: RawValue[];
@@ -14,13 +15,13 @@
1415
let { data = [], automatic = false, ...options }: GrixXMarkProps = $props();
1516
1617
const { getPlotState } = getContext<PlotContext>('svelteplot');
17-
let plot = $derived(getPlotState());
18+
const plot = $derived(getPlotState());
1819
19-
let autoTickCount = $derived(
20+
const autoTickCount = $derived(
2021
Math.max(3, Math.round(plot.facetWidth / plot.options.x.tickSpacing))
2122
);
2223
23-
let ticks: RawValue[] = $derived(
24+
const ticks: RawValue[] = $derived(
2425
data.length > 0
2526
? // use custom tick values if user passed any as prop
2627
data
@@ -53,9 +54,18 @@
5354
{@const y2_ = resolveChannel('y2', tick, options)}
5455
{@const y1 = options.y1 != null ? plot.scales.y.fn(y1_) : 0}
5556
{@const y2 = options.y2 != null ? plot.scales.y.fn(y2_) : plot.facetHeight}
57+
{@const [style, styleClass] = resolveStyles(
58+
plot,
59+
{ datum: { [RAW_VALUE]: tick } },
60+
options,
61+
'stroke',
62+
usedScales,
63+
true
64+
)}
5665
<line
66+
class={styleClass}
5767
transform="translate({x},{plot.options.marginTop})"
58-
style={resolveScaledStyles(tick, options, usedScales, plot, 'stroke')}
68+
{style}
5969
{y1}
6070
{y2} />
6171
{/if}

src/lib/marks/GridY.svelte

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
import { getContext } from 'svelte';
33
import Mark from '../Mark.svelte';
44
import type { PlotContext, BaseMarkProps, RawValue, DataRecord } from '../types.js';
5-
import { resolveChannel, resolveScaledStyles } from '../helpers/resolve.js';
5+
import { resolveChannel, resolveStyles } from '../helpers/resolve.js';
66
import { autoTicks } from '$lib/helpers/autoTicks.js';
7-
import { getUsedScales } from '$lib/helpers/scales.js';
87
import { testFilter } from '$lib/helpers/index.js';
8+
import { RAW_VALUE } from '$lib/transforms/recordize.js';
99
1010
type GridYMarkProps = BaseMarkProps & { data?: RawValue[]; automatic?: boolean };
1111
1212
let { data = [], automatic = false, ...options }: GridYMarkProps = $props();
1313
1414
const { getPlotState } = getContext<PlotContext>('svelteplot');
15-
let plot = $derived(getPlotState());
15+
const plot = $derived(getPlotState());
1616
17-
let autoTickCount = $derived(
17+
const autoTickCount = $derived(
1818
Math.max(2, Math.round(plot.facetHeight / plot.options.y.tickSpacing))
1919
);
2020
21-
let ticks: RawValue[] = $derived(
21+
const ticks: RawValue[] = $derived(
2222
data.length > 0
2323
? // use custom tick values if user passed any as prop
2424
data
@@ -51,9 +51,18 @@
5151
{@const x2_ = resolveChannel('x2', tick, options)}
5252
{@const x1 = options.x1 != null ? plot.scales.x.fn(x1_) : 0}
5353
{@const x2 = options.x2 != null ? plot.scales.x.fn(x2_) : plot.facetWidth}
54+
{@const [style, styleClass] = resolveStyles(
55+
plot,
56+
{ datum: { [RAW_VALUE]: tick } },
57+
options,
58+
'stroke',
59+
usedScales,
60+
true
61+
)}
5462
<line
63+
{style}
64+
class={styleClass}
5565
transform="translate({plot.options.marginLeft},{y})"
56-
style={resolveScaledStyles(tick, options, usedScales, plot, 'stroke')}
5766
{x1}
5867
{x2} />
5968
{/if}

src/tests/gridX.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('GridX mark', () => {
1717
stroke: '#008000',
1818
strokeOpacity: 0.5,
1919
strokeDasharray: '5, 5',
20-
ticks: [0, 5, 10],
20+
data: [0, 5, 10],
2121
},
2222
},
2323
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy