Skip to content

Commit 4702510

Browse files
committed
merge PlotDefaults and DefaultOptions types
1 parent 88ab15d commit 4702510

File tree

12 files changed

+135
-126
lines changed

12 files changed

+135
-126
lines changed

src/lib/core/Plot.svelte

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,24 @@
5454
// default settings in the plot and marks can be overwritten by
5555
// defining the svelteplot/defaults context outside of Plot
5656
const DEFAULTS: PlotDefaults = {
57-
axisXAnchor: 'bottom',
58-
axisYAnchor: 'left',
59-
xTickSpacing: 80,
60-
yTickSpacing: 50,
6157
height: 350,
6258
initialWidth: 500,
6359
inset: 0,
6460
colorScheme: 'turbo',
6561
unknown: '#cccccc99',
66-
dotRadius: 3,
67-
frame: false,
68-
axes: true,
69-
grid: false,
62+
implicitMarks: {
63+
frame: false,
64+
grid: false,
65+
axes: true
66+
},
67+
axisX: {
68+
anchor: 'bottom',
69+
tickSpacing: 80
70+
},
71+
axisY: {
72+
anchor: 'left',
73+
tickSpacing: 50
74+
},
7075
categoricalColorScheme: 'observable10',
7176
pointScaleHeight: 18,
7277
bandScaleHeight: 30,
@@ -390,16 +395,16 @@
390395
? margins
391396
: Math.max(5, maxMarginBottom),
392397
inset: isOneDimensional ? 10 : DEFAULTS.inset,
393-
grid: DEFAULTS.grid,
394-
axes: DEFAULTS.axes,
395-
frame: DEFAULTS.frame,
398+
grid: DEFAULTS.implicitMarks.grid,
399+
axes: DEFAULTS.implicitMarks.axes,
400+
frame: DEFAULTS.implicitMarks.frame,
396401
projection: null,
397402
aspectRatio: null,
398403
facet: {},
399404
padding: 0.1,
400405
x: {
401406
type: 'auto',
402-
axis: autoXAxis ? DEFAULTS.axisXAnchor : false,
407+
axis: autoXAxis ? DEFAULTS.axisX.anchor : false,
403408
labelAnchor: 'auto',
404409
reverse: false,
405410
clamp: false,
@@ -408,13 +413,13 @@
408413
round: false,
409414
percent: false,
410415
align: 0.5,
411-
tickSpacing: DEFAULTS.xTickSpacing,
416+
tickSpacing: DEFAULTS.axisX.tickSpacing,
412417
tickFormat: 'auto',
413418
grid: false
414419
},
415420
y: {
416421
type: 'auto',
417-
axis: autoYAxis ? DEFAULTS.axisYAnchor : false,
422+
axis: autoYAxis ? DEFAULTS.axisY.anchor : false,
418423
labelAnchor: 'auto',
419424
reverse: false,
420425
clamp: false,
@@ -423,7 +428,7 @@
423428
round: false,
424429
percent: false,
425430
align: 0.5,
426-
tickSpacing: DEFAULTS.yTickSpacing,
431+
tickSpacing: DEFAULTS.axisY.tickSpacing,
427432
tickFormat: 'auto',
428433
grid: false
429434
},

src/lib/marks/Area.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
ChannelAccessor,
4141
ScaledDataRecord,
4242
LinkableMarkProps,
43-
DefaultOptions
43+
PlotDefaults
4444
} from '../types.js';
4545
import type { RawValue } from '$lib/types.js';
4646
import type { StackOptions } from '$lib/transforms/stack.js';
@@ -51,7 +51,7 @@
5151
fill: 'currentColor',
5252
curve: 'linear',
5353
tension: 0,
54-
...getContext<DefaultOptions>('svelteplot/_defaults').area
54+
...getContext<PlotDefaults>('svelteplot/_defaults').area
5555
};
5656
5757
const {

src/lib/marks/AreaX.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { renameChannels } from '$lib/transforms/rename.js';
88
import { stackX } from '$lib/transforms/stack.js';
99
import { recordizeX } from '$lib/transforms/recordize.js';
10-
import type { ChannelAccessor, DefaultOptions } from '../types.js';
10+
import type { ChannelAccessor, PlotDefaults } from '../types.js';
1111
import { getContext } from 'svelte';
1212
1313
type AreaXProps = Omit<AreaMarkProps, 'y1' | 'y2'> & {
@@ -17,7 +17,7 @@
1717
1818
let markProps: AreaMarkProps = $props();
1919
20-
const DEFAULTS = getContext<DefaultOptions>('svelteplot/_defaults').areaX;
20+
const DEFAULTS = getContext<PlotDefaults>('svelteplot/_defaults').areaX;
2121
2222
const { data, stack, ...options }: AreaMarkProps = $derived({ ...DEFAULTS, ...markProps });
2323

src/lib/marks/AreaY.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { renameChannels } from '$lib/transforms/rename.js';
88
import { stackY } from '$lib/transforms/stack.js';
99
import { recordizeY } from '$lib/transforms/recordize.js';
10-
import type { ChannelAccessor, DefaultOptions } from '../types.js';
10+
import type { ChannelAccessor, PlotDefaults } from '../types.js';
1111
import { getContext } from 'svelte';
1212
1313
/**
@@ -20,7 +20,7 @@
2020
2121
let markProps: AreaMarkProps = $props();
2222
23-
const DEFAULTS = getContext<DefaultOptions>('svelteplot/_defaults').areaY;
23+
const DEFAULTS = getContext<PlotDefaults>('svelteplot/_defaults').areaY;
2424
2525
const { data, stack, ...options }: AreaMarkProps = $derived({ ...DEFAULTS, ...markProps });
2626

src/lib/marks/Arrow.svelte

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@
3838
</script>
3939

4040
<script lang="ts">
41-
import { getContext, type Snippet } from 'svelte';
41+
import { getContext } from 'svelte';
4242
import type {
4343
PlotContext,
4444
DataRecord,
4545
BaseMarkProps,
4646
ConstantAccessor,
4747
ChannelAccessor,
48-
RawValue
48+
RawValue,
49+
PlotDefaults
4950
} from '../types.js';
5051
import { resolveChannel, resolveProp, resolveStyles } from '../helpers/resolve.js';
5152
import { coalesce, maybeData, maybeNumber } from '../helpers/index.js';
@@ -55,7 +56,20 @@
5556
import { addEventHandlers } from './helpers/events.js';
5657
import GroupMultiple from './helpers/GroupMultiple.svelte';
5758
58-
let { data = [{}], class: className = null, ...options }: ArrowMarkProps = $props();
59+
let markProps: ArrowMarkProps = $props();
60+
61+
const DEFAULTS = {
62+
headAngle: 60,
63+
headLength: 8,
64+
inset: 0,
65+
...getContext<PlotDefaults>('svelteplot/_defaults').arrow
66+
};
67+
68+
const {
69+
data = [{}],
70+
class: className = null,
71+
...options
72+
}: ArrowMarkProps = $derived({ ...DEFAULTS, ...markProps });
5973
6074
const { getPlotState } = getContext<PlotContext>('svelteplot');
6175
const plot = $derived(getPlotState());
@@ -68,7 +82,7 @@
6882
: maybeData(data)
6983
);
7084
71-
const args: ArrowProps = $derived(
85+
const args: ArrowMarkProps = $derived(
7286
replaceChannels({ data: sorted, ...options }, { y: ['y1', 'y2'], x: ['x1', 'x2'] })
7387
);
7488
</script>
@@ -78,16 +92,16 @@
7892
required={['x1', 'x2', 'y1', 'y2']}
7993
channels={['x1', 'y1', 'x2', 'y2', 'opacity', 'stroke', 'strokeOpacity']}
8094
{...args}>
81-
{#snippet children({ mark, usedScales, scaledData })}
95+
{#snippet children({ usedScales, scaledData })}
8296
{@const sweep = maybeSweep(args.sweep)}
8397
<GroupMultiple class="arrow" length={scaledData.length}>
8498
{#each scaledData as d, i (i)}
8599
{#if d.valid}
86100
{@const inset = resolveProp(args.inset, d.datum, 0)}
87101
{@const insetStart = resolveProp(args.insetStart, d.datum)}
88102
{@const insetEnd = resolveProp(args.insetEnd, d.datum)}
89-
{@const headAngle = resolveProp(args.headAngle, d.datum, 60)}
90-
{@const headLength = resolveProp(args.headLength, d.datum, 8)}
103+
{@const headAngle = resolveProp(args.headAngle, d.datum)}
104+
{@const headLength = resolveProp(args.headLength, d.datum)}
91105
{@const bend = resolveProp(args.bend, d.datum, 0)}
92106
{@const strokeWidth = resolveProp(args.strokeWidth, d.datum, 1)}
93107
{@const arrPath = arrowPath(

src/lib/marks/AxisX.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
RawValue,
5050
ConstantAccessor,
5151
FacetContext,
52-
DefaultOptions
52+
PlotDefaults
5353
} from '../types.js';
5454
import autoTimeFormat from '$lib/helpers/autoTimeFormat.js';
5555
import { derived } from 'svelte/store';
@@ -61,7 +61,7 @@
6161
tickPadding: 3,
6262
tickFontSize: 11,
6363
axisXAnchor: 'bottom',
64-
...getContext<Partial<DefaultOptions>>('svelteplot/_defaults')
64+
...getContext<Partial<PlotDefaults>>('svelteplot/_defaults')
6565
};
6666
6767
let {

src/lib/marks/AxisY.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
BaseMarkProps,
5050
RawValue,
5151
FacetContext,
52-
DefaultOptions
52+
PlotDefaults
5353
} from '../types.js';
5454
import autoTimeFormat from '$lib/helpers/autoTimeFormat.js';
5555
import type { ConstantAccessor } from '$lib/types.js';
@@ -61,7 +61,7 @@
6161
tickPadding: 3,
6262
tickFontSize: 11,
6363
axisYAnchor: 'left',
64-
...getContext<Partial<DefaultOptions>>('svelteplot/_defaults')
64+
...getContext<Partial<PlotDefaults>>('svelteplot/_defaults')
6565
};
6666
6767
let {

src/lib/marks/BarX.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
BaseRectMarkProps,
1010
ChannelAccessor,
1111
LinkableMarkProps,
12-
PlotDefaults,
13-
DefaultOptions
12+
PlotDefaults
1413
} from '../types.js';
1514
1615
export type BarXMarkProps = BaseMarkProps &
@@ -42,8 +41,8 @@
4241
4342
const DEFAULTS = {
4443
fill: 'currentColor',
45-
...getContext<DefaultOptions>('svelteplot/_defaults').bar,
46-
...getContext<DefaultOptions>('svelteplot/_defaults').barX
44+
...getContext<PlotDefaults>('svelteplot/_defaults').bar,
45+
...getContext<PlotDefaults>('svelteplot/_defaults').barX
4746
};
4847
4948
let markProps: BarXMarkProps = $props();

src/lib/marks/BarY.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
BaseRectMarkProps,
1010
ChannelAccessor,
1111
DataRow,
12-
DefaultOptions
12+
PlotDefaults
1313
} from '../types.js';
1414
1515
export type BarYMarkProps = BaseMarkProps &
@@ -43,8 +43,8 @@
4343
4444
const DEFAULTS = {
4545
fill: 'currentColor',
46-
...getContext<DefaultOptions>('svelteplot/_defaults').bar,
47-
...getContext<DefaultOptions>('svelteplot/_defaults').barY
46+
...getContext<PlotDefaults>('svelteplot/_defaults').bar,
47+
...getContext<PlotDefaults>('svelteplot/_defaults').barY
4848
};
4949
5050
let markProps: BarYMarkProps = $props();

src/lib/marks/ColorLegend.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import { range as d3Range, extent } from 'd3-array';
1212
import { maybeSymbol } from '$lib/helpers/symbols.js';
1313
14-
import type { DefaultOptions, PlotContext } from '../types.js';
14+
import type { PlotDefaults, PlotContext } from '../types.js';
1515
1616
let { class: className = null }: ColorLegendMarkProps = $props();
1717
1818
const { getPlotState } = getContext<PlotContext>('svelteplot');
1919
const plot = $derived(getPlotState());
2020
21-
const DEFAULTS = getContext<Partial<DefaultOptions>>('svelteplot/_defaults');
21+
const DEFAULTS = getContext<Partial<PlotDefaults>>('svelteplot/_defaults');
2222
2323
const legendTitle = $derived(plot.options.color.label);
2424
const scaleType = $derived(plot.scales.color.type);

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