svelteplot 0.0.1-alpha.6 → 0.0.1-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Plot.svelte CHANGED
@@ -1,11 +1,7 @@
1
1
  <script>import { setContext } from "svelte";
2
- import { Frame, GridX, GridY } from "./";
2
+ import { Frame, GridX, GridY, AxisX, AxisY, ColorLegend, SymbolLegend } from "./index.js";
3
3
  import { DEFAULT_PLOT_OPTIONS, Plot } from "./classes/Plot.svelte";
4
4
  import mergeDeep from "./helpers/mergeDeep.js";
5
- import AxisX from "./marks/AxisX.svelte";
6
- import AxisY from "./marks/AxisY.svelte";
7
- import ColorLegend from "./marks/ColorLegend.svelte";
8
- import SymbolLegend from "./marks/SymbolLegend.svelte";
9
5
  let {
10
6
  // snippets
11
7
  header,
@@ -74,6 +70,7 @@ function onMouseMove(evt) {
74
70
  if (onmousemove)
75
71
  onmousemove({ ...evt, plot });
76
72
  }
73
+ $inspect(plot.x.domain);
77
74
  let hasLegend = $derived(color?.legend || symbol?.legend);
78
75
  </script>
79
76
 
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { PlotProps } from './types';
2
+ import type { PlotProps } from './types.js';
3
3
  declare const __propDef: {
4
4
  props: PlotProps;
5
5
  events: {
@@ -1,6 +1,6 @@
1
1
  import resolveChannel from '../helpers/resolveChannel.js';
2
2
  import { extent } from 'd3-array';
3
- import { MARK_PROP_CHANNEL, CHANNEL_TYPES } from '../contants';
3
+ import { MARK_PROP_CHANNEL } from '../contants.js';
4
4
  import { isBooleanOrNull, isColorOrNull, isDateOrNull, isNumberOrNull, isStringOrNull } from '../helpers/typeChecks.js';
5
5
  import { uniq } from 'underscore';
6
6
  export class Channel {
@@ -67,6 +67,8 @@ export class Channel {
67
67
  ? 'linear'
68
68
  : this.valueType === 'text'
69
69
  ? 'band'
70
- : 'linear');
70
+ : this.valueType === 'color'
71
+ ? 'identity'
72
+ : 'linear');
71
73
  }
72
74
  // opacity: typeof === 'number' && between [0,1]
@@ -1,6 +1,7 @@
1
1
  import { createScale, createColorScale } from '../helpers/createScale.js';
2
2
  import mergeDeep from '../helpers/mergeDeep.js';
3
3
  import { Channel } from './Channel.svelte';
4
+ import { get } from 'underscore';
4
5
  export const DEFAULT_PLOT_OPTIONS = {
5
6
  title: '',
6
7
  subtitle: '',
@@ -76,7 +77,7 @@ export class Plot {
76
77
  symbolScale = $derived(createScale('ordinal', this.symbol.domain, this.options.symbol?.range || this.hasFilledDotMarks
77
78
  ? ['circle', 'cross', 'diamond', 'square', 'star', 'triangle', 'wye']
78
79
  : ['circle', 'plus', 'times', 'triangle2', 'asterisk', 'square2', 'diamond2']));
79
- colorScale = $derived(createColorScale(this.color.scaleType, this.color.domain, this.options.color.scheme));
80
+ colorScale = $derived(createColorScale(this.color.scaleType, this.color.domain, this.options.color?.range || null, this.options.color?.scheme));
80
81
  hasAxisXMark = $derived(!!this.marks.find((mark) => mark.type === 'axis-x' && !mark.automatic));
81
82
  hasAxisYMark = $derived(!!this.marks.find((mark) => mark.type === 'axis-y' && !mark.automatic));
82
83
  constructor(width, height, options) {
@@ -89,8 +90,7 @@ export class Plot {
89
90
  // console.log('addMark: ' + mark);
90
91
  this.marks = [...this.marks, mark];
91
92
  // add mark to respective channels
92
- if (mark.channels.has('color'))
93
- console.log(this.color.uniqueMarkProps);
93
+ // console.log(this.x.domain);
94
94
  }
95
95
  removeMark(removeMark) {
96
96
  this.marks = this.marks.filter((mark) => mark.id !== removeMark.id);
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { DataRow } from '../types';
2
+ import type { DataRow } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  data: DataRow[];
@@ -1,5 +1,5 @@
1
1
  import { interpolateBrBG } from 'd3-scale-chromatic';
2
- import type { ColorScheme } from '../types';
2
+ import type { ColorScheme } from '../types.js';
3
3
  export declare const categoricalSchemes: Map<string, readonly string[]>;
4
4
  export declare function isCategoricalScheme(scheme: string): boolean;
5
5
  type SchemeGetter = (n: number) => readonly string[];
@@ -1,4 +1,5 @@
1
+ import type { ColorScheme, RawValue } from '../types.js';
1
2
  declare const Scales: Record<string, (domain: number[], range: [number, number]) => (val: any) => any>;
2
3
  export declare function createScale(type: keyof typeof Scales, domain: any, range: any, options?: {}): (val: any) => any;
3
- export declare function createColorScale(type: any, domain: string[] | [number, number] | [Date, Date] | [boolean | boolean], scheme: any): ((d: any) => any) | (unknown[] & string[] & import("d3-scale").ScaleOrdinal<string, unknown, never>);
4
+ export declare function createColorScale(type: any, domain: string[] | [number, number] | [Date, Date] | [boolean | boolean], range: RawValue[] | null, scheme: ColorScheme | null): ((d: any) => any) | (unknown[] & string[] & import("d3-scale").ScaleOrdinal<string, unknown, never>) | import("d3-scale").ScaleSequential<string, never>;
4
5
  export {};
@@ -1,6 +1,7 @@
1
1
  import { scaleBand, scaleLinear, scaleTime, scaleSqrt, scaleLog, scaleOrdinal } from 'd3-scale';
2
+ import { scaleSequential, scaleDiverging } from 'd3-scale';
2
3
  import { getLogTicks } from './getLogTicks.js';
3
- import { categoricalSchemes, isCategoricalScheme, ordinalScheme } from './colors.js';
4
+ import { categoricalSchemes, isCategoricalScheme, isQuantitativeScheme, ordinalScheme, quantitativeScheme } from './colors.js';
4
5
  import { isColorOrNull } from './typeChecks.js';
5
6
  const Scales = {
6
7
  band: scaleBand,
@@ -8,7 +9,9 @@ const Scales = {
8
9
  time: scaleTime,
9
10
  sqrt: scaleSqrt,
10
11
  log: scaleLog,
11
- ordinal: scaleOrdinal
12
+ ordinal: scaleOrdinal,
13
+ sequential: scaleSequential,
14
+ diverging: scaleDiverging
12
15
  };
13
16
  export function createScale(type, domain, range, options = {}) {
14
17
  const scale = Scales[type](domain, range);
@@ -28,20 +31,27 @@ export function createScale(type, domain, range, options = {}) {
28
31
  return scale;
29
32
  }
30
33
  const identity = (d) => d;
31
- export function createColorScale(type, domain, scheme) {
34
+ export function createColorScale(type, domain, range, scheme) {
35
+ if (type === 'identity')
36
+ return identity;
32
37
  if (type === 'band') {
33
38
  if (domain.every(isColorOrNull)) {
34
- console.log('domain is colors', domain);
35
39
  return identity;
36
40
  }
37
- const colorRange = !scheme
38
- ? categoricalSchemes.get('tableau10')
39
- : Array.isArray(scheme)
40
- ? scheme
41
+ const colorRange = Array.isArray(range)
42
+ ? range
43
+ : !scheme
44
+ ? categoricalSchemes.get('tableau10')
41
45
  : isCategoricalScheme(scheme)
42
46
  ? categoricalSchemes.get(scheme)
43
47
  : ordinalScheme(scheme)(domain.length);
44
48
  return scaleOrdinal().domain(domain).range(colorRange);
45
49
  }
50
+ else if (type === 'linear') {
51
+ const colorInterpolator = isQuantitativeScheme(scheme)
52
+ ? quantitativeScheme(scheme)
53
+ : quantitativeScheme('blues');
54
+ return scaleSequential(domain, colorInterpolator);
55
+ }
46
56
  return (d) => d;
47
57
  }
@@ -1,2 +1,2 @@
1
- import type { ChannelAccessor, MarkStyleProps, DataRow } from '../types';
1
+ import type { ChannelAccessor, MarkStyleProps, DataRow } from '../types.js';
2
2
  export default function (datum: DataRow, props: Partial<Record<MarkStyleProps, ChannelAccessor>>): string;
@@ -1,2 +1,2 @@
1
- import type { DataRecord } from '../types';
1
+ import type { DataRecord } from '../types.js';
2
2
  export default function (value: any): value is DataRecord;
@@ -1,4 +1,4 @@
1
- import type { RawValue } from '../types';
1
+ import type { RawValue } from '../types.js';
2
2
  export declare function isBooleanOrNull(v: RawValue): boolean;
3
3
  export declare function isDateOrNull(v: RawValue): boolean;
4
4
  export declare function isNumberOrNull(v: RawValue): boolean;
@@ -1,2 +1,2 @@
1
- import type { DataRow } from '../types';
2
- export default function (data: DataRow[]): (Date | [number, number] | import("../types").DataRecord)[];
1
+ import type { DataRow } from '../types.js';
2
+ export default function (data: DataRow[]): (Date | [number, number] | import("../types.js").DataRecord)[];
@@ -1,6 +1,5 @@
1
1
  <script>import { getContext } from "svelte";
2
2
  import dayjs from "dayjs";
3
- import { get } from "underscore";
4
3
  import BaseMark from "./BaseMark.svelte";
5
4
  import getBaseStyles from "../helpers/getBaseStyles.js";
6
5
  import removeIdenticalLines from "../helpers/removeIdenticalLines.js";
@@ -19,9 +18,11 @@ let {
19
18
  fill = null,
20
19
  ...styleProps
21
20
  } = $props();
22
- let autoTickCount = $derived(plot.plotWidth / get(plot, "options.x.tickSpacing", 80));
21
+ let autoTickCount = $derived(Math.max(2, Math.round(plot.plotWidth / (plot.options?.x?.tickSpacing || 80))));
22
+ $inspect(autoTickCount);
23
+ $inspect(ticks.length);
23
24
  let autoTicks = $derived(
24
- ticks.length > 0 ? ticks : get(plot, "options.x.ticks", plot.xScale.ticks(autoTickCount))
25
+ ticks.length > 0 ? ticks : plot.options?.x?.ticks ?? plot.xScale.ticks(autoTickCount)
25
26
  );
26
27
  let useTickFormat = $derived(
27
28
  typeof tickFormat === "function" ? tickFormat : plot.x.scaleType === "time" ? typeof tickFormat === "string" ? (d) => dayjs(d).format(tickFormat).split("\n") : autoTimeFormat(plot.x, plot.plotWidth) : (d) => String(d)
@@ -33,7 +34,7 @@ let tickTexts = $derived(
33
34
  );
34
35
  let optionsLabel = $derived(plot.options?.x?.label);
35
36
  let useTitle = $derived(
36
- title || (optionsLabel === null ? null : optionsLabel === void 0 ? plot.x.autoTitle : optionsLabel)
37
+ title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : `${plot.x.autoTitle} \u2192`)
37
38
  );
38
39
  </script>
39
40
 
@@ -44,7 +45,7 @@ let useTitle = $derived(
44
45
  x={plot.plotWidth + plot.margins.left}
45
46
  y={plot.height - 10}
46
47
  class="axis-title"
47
- dominant-baseline="hanging">{useTitle} →</text
48
+ dominant-baseline="hanging">{useTitle}</text
48
49
  >
49
50
  {/if}
50
51
  {#each autoTicks as tick, t}
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { AxisMarkOptions } from '../types';
2
+ import type { AxisMarkOptions } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: AxisMarkOptions & {
5
5
  anchor?: "bottom" | "top" | undefined;
@@ -20,16 +20,17 @@ let autoTickCount = $derived(plot.plotHeight / get(plot, "options.y.tickSpacing"
20
20
  let autoTicks = $derived(
21
21
  ticks.length > 0 ? ticks : get(plot, "options.y.ticks", plot.yScale.ticks(autoTickCount))
22
22
  );
23
- let optionsLabel = $derived(get(plot, "options.y.label"));
23
+ let optionsLabel = $derived(plot.options.y?.label);
24
24
  let useTitle = $derived(
25
- title || (optionsLabel === null ? null : optionsLabel === void 0 ? plot.y.autoTitle : optionsLabel)
25
+ title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : `\u2191 ${plot.y.autoTitle}`)
26
26
  );
27
+ $inspect(optionsLabel);
27
28
  </script>
28
29
 
29
30
  <BaseMark_AxisX type="axis-y" data={ticks} channels={['y']} {automatic}>
30
31
  <g class="axis-y">
31
32
  {#if useTitle}
32
- <text x={0} y={5} class="axis-title" dominant-baseline="hanging">↑ {useTitle}</text>
33
+ <text x={0} y={5} class="axis-title" dominant-baseline="hanging">{useTitle}</text>
33
34
  {/if}
34
35
  {#each autoTicks as tick}
35
36
  <g
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { AxisYMarkProps } from '../types';
2
+ import type { AxisYMarkProps } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: AxisYMarkProps;
5
5
  events: {
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { BaseMarkProps } from '../types';
2
+ import type { BaseMarkProps } from '../types.js';
3
3
  declare class __sveltets_Render<T extends BaseMarkProps> {
4
4
  props(): T & {
5
5
  children?: Function | undefined;
@@ -5,29 +5,29 @@ const plot = getContext("svelteplot");
5
5
  </script>
6
6
 
7
7
  {#if plot.color.manualActiveMarks.length > 0}
8
- <div class="color-legend">
9
- {#each plot.colorScale.domain() as value}
10
- {@const symbolV = plot.symbolScale(value)}
11
- {@const symbolType = maybeSymbol(symbolV)}
12
- <div class="item">
13
- <div class="swatch">
14
- <svg width="15" height="15"
15
- >{#if plot.colorSymbolRedundant}
16
- <path
17
- transform="translate(7.5,7.5)"
18
- fill={plot.hasFilledDotMarks ? plot.colorScale(value) : 'none'}
19
- stroke={plot.hasFilledDotMarks ? null : plot.colorScale(value)}
20
- d={d3Symbol(symbolType, 40)()}
21
- />
22
- {:else}
23
- <rect fill={plot.colorScale(value)} width="15" height="15" />
24
- {/if}</svg
25
- >
8
+ <div class="color-legend">
9
+ {#each plot.colorScale.domain() as value}
10
+ {@const symbolV = plot.symbolScale(value)}
11
+ {@const symbolType = maybeSymbol(symbolV)}
12
+ <div class="item">
13
+ <div class="swatch">
14
+ <svg width="15" height="15"
15
+ >{#if plot.colorSymbolRedundant}
16
+ <path
17
+ transform="translate(7.5,7.5)"
18
+ fill={plot.hasFilledDotMarks ? plot.colorScale(value) : 'none'}
19
+ stroke={plot.hasFilledDotMarks ? null : plot.colorScale(value)}
20
+ d={d3Symbol(symbolType, 40)()}
21
+ />
22
+ {:else}
23
+ <rect fill={plot.colorScale(value)} width="15" height="15" />
24
+ {/if}</svg
25
+ >
26
+ </div>
27
+ <span class="item-label">{value}</span>
26
28
  </div>
27
- <span class="item-label">{value}</span>
28
- </div>
29
- {/each}
30
- </div>
29
+ {/each}
30
+ </div>
31
31
  {/if}
32
32
 
33
33
  <style>
@@ -40,7 +40,9 @@ const plot = getContext("svelteplot");
40
40
  .item {
41
41
  margin: 0 1em 0.5ex 0;
42
42
  }
43
- path { stroke-width: 1.5;}
43
+ path {
44
+ stroke-width: 1.5;
45
+ }
44
46
  .item,
45
47
  .item-label,
46
48
  .swatch {
@@ -30,10 +30,10 @@ function isValid(value) {
30
30
  {data}
31
31
  channels={[
32
32
  ...(x ? ['x'] : []),
33
- ...(y ? ['y'] : []),
34
- ...(r ? ['radius'] : []),
35
- ...(symbol ? ['symbol'] : []),
36
- ...(fill || stroke ? ['color']: [])
33
+ ...(y ? ['y'] : []),
34
+ ...(r ? ['radius'] : []),
35
+ ...(symbol ? ['symbol'] : []),
36
+ ...(fill || stroke ? ['color'] : [])
37
37
  ]}
38
38
  {x}
39
39
  {y}
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { DotMarkProps } from '../types';
2
+ import type { DotMarkProps } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: DotMarkProps;
5
5
  events: {
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { RawValue } from '../types';
2
+ import type { RawValue } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  data: RawValue[];
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { RawValue } from '../types';
2
+ import type { RawValue } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  data: RawValue[];
@@ -1,7 +1,7 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { FrameProps } from '../types';
2
+ import type { FrameProps } from '../types.js';
3
3
  declare const __propDef: {
4
- props: import("../types").BaseMarkStyleProps;
4
+ props: import("../types.js").BaseMarkStyleProps;
5
5
  events: {
6
6
  [evt: string]: CustomEvent<any>;
7
7
  };
@@ -1,8 +1,8 @@
1
1
  <script>import { getContext } from "svelte";
2
+ import { get } from "underscore";
2
3
  import BaseMark from "./BaseMark.svelte";
3
4
  import resolveChannel from "../helpers/resolveChannel.js";
4
5
  import getBaseStyles from "../helpers/getBaseStyles.js";
5
- import { get } from "underscore";
6
6
  const BaseMark_GridX = BaseMark;
7
7
  const plot = getContext("svelteplot");
8
8
  let {
@@ -1,9 +1,9 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { GridOptions } from '../types';
2
+ import type { GridOptions } from '../types.js';
3
3
  declare const __propDef: {
4
- props: Partial<import("../types").MarkProps> & GridOptions & {
5
- y1?: import("../types").ChannelAccessor | undefined;
6
- y2?: import("../types").ChannelAccessor | undefined;
4
+ props: Partial<import("../types.js").MarkProps> & GridOptions & {
5
+ y1?: import("../types.js").ChannelAccessor | undefined;
6
+ y2?: import("../types.js").ChannelAccessor | undefined;
7
7
  automatic?: boolean | undefined;
8
8
  };
9
9
  events: {
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { GridYMarkProps } from '../types';
2
+ import type { GridYMarkProps } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: GridYMarkProps;
5
5
  events: {
@@ -4,6 +4,7 @@ import BaseMark from "./BaseMark.svelte";
4
4
  import getBaseStyles from "../helpers/getBaseStyles.js";
5
5
  import { line } from "d3-shape";
6
6
  import { groupBy } from "underscore";
7
+ import isDataRecord from "../helpers/isDataRecord.js";
7
8
  const BaseMark_Line = BaseMark;
8
9
  const plot = getContext("svelteplot");
9
10
  let {
@@ -14,10 +15,16 @@ let {
14
15
  fill,
15
16
  stroke,
16
17
  r = 5,
18
+ sort,
17
19
  ...styleProps
18
20
  } = $props();
19
21
  let groups = $derived(
20
- z ? Object.values(groupBy(data, (d) => resolveChannel("z", d, z))) : [data]
22
+ z || fill || stroke ? Object.values(groupBy(data, (d) => resolveChannel("z", d, z || fill || stroke))) : [data]
23
+ );
24
+ let sortedGroups = $derived(
25
+ sort ? groups.sort(
26
+ (a, b) => resolveChannel("sort", a[0], sort) > resolveChannel("sort", b[0], sort) ? 1 : -1
27
+ ) : groups
21
28
  );
22
29
  let linePath = line().x((d) => plot.xScale(resolveChannel("x", d, x))).y((d) => plot.yScale(resolveChannel("y", d, y)));
23
30
  </script>
@@ -34,16 +41,21 @@ let linePath = line().x((d) => plot.xScale(resolveChannel("x", d, x))).y((d) =>
34
41
  {...styleProps}
35
42
  >
36
43
  <g class="lines">
37
- {#each groups as lineData}
38
- <path d={linePath(lineData)} style={getBaseStyles(lineData[0], styleProps)} />
44
+ {#each sortedGroups as lineData}
45
+ <path
46
+ d={linePath(lineData)}
47
+ stroke={stroke
48
+ ? plot.colorScale(resolveChannel('color', lineData[0], stroke))
49
+ : 'currentColor'}
50
+ fill={fill ? plot.colorScale(resolveChannel('color', lineData[0], fill)) : 'none'}
51
+ style={getBaseStyles(lineData[0], styleProps)}
52
+ />
39
53
  {/each}
40
54
  </g>
41
55
  </BaseMark_Line>
42
56
 
43
57
  <style>
44
58
  .lines path {
45
- stroke: currentColor;
46
- fill: none;
47
59
  stroke-width: 1.4px;
48
60
  }
49
61
  </style>
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { LineMarkProps } from '../types';
2
+ import type { LineMarkProps } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: LineMarkProps;
5
5
  events: {
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { RawValue } from '../types';
2
+ import type { RawValue } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  data: RawValue[];
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { RawValue } from '../types';
2
+ import type { RawValue } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  data: RawValue[];
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { RuleXMarkProps } from '../types';
2
+ import type { RuleXMarkProps } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: RuleXMarkProps;
5
5
  events: {
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
- import type { RuleYMarkProps } from '../types';
2
+ import type { RuleYMarkProps } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: RuleYMarkProps;
5
5
  events: {
@@ -5,28 +5,26 @@ const plot = getContext("svelteplot");
5
5
  </script>
6
6
 
7
7
  {#if plot.color.manualActiveMarks.length > 0 && !(plot.options.color?.legend && plot.colorSymbolRedundant)}
8
- <div class="symbol-legend">
9
- {#each plot.symbolScale.domain() as value}
10
- {@const symbolV = plot.symbolScale(value)}
11
- {@const symbolType = maybeSymbol(symbolV)}
12
- {@const color = plot.colorSymbolRedundant ? plot.colorScale(value) : 'currentColor'}
13
- <div class="item">
14
- <div class="swatch">
15
- <svg width="15" height="15"
16
- >
8
+ <div class="symbol-legend">
9
+ {#each plot.symbolScale.domain() as value}
10
+ {@const symbolV = plot.symbolScale(value)}
11
+ {@const symbolType = maybeSymbol(symbolV)}
12
+ {@const color = plot.colorSymbolRedundant ? plot.colorScale(value) : 'currentColor'}
13
+ <div class="item">
14
+ <div class="swatch">
15
+ <svg width="15" height="15">
17
16
  <path
18
17
  transform="translate(7.5,7.5)"
19
18
  fill={plot.hasFilledDotMarks ? color : 'none'}
20
19
  stroke={plot.hasFilledDotMarks ? null : color}
21
20
  d={d3Symbol(symbolType, 40)()}
22
21
  />
23
- </svg
24
- >
22
+ </svg>
23
+ </div>
24
+ <span class="item-label">{value}</span>
25
25
  </div>
26
- <span class="item-label">{value}</span>
27
- </div>
28
- {/each}
29
- </div>
26
+ {/each}
27
+ </div>
30
28
  {/if}
31
29
 
32
30
  <style>
@@ -38,7 +36,9 @@ const plot = getContext("svelteplot");
38
36
  .item {
39
37
  margin: 0 1em 0.5ex 0;
40
38
  }
41
- path { stroke-width: 1.5;}
39
+ path {
40
+ stroke-width: 1.5;
41
+ }
42
42
  .item,
43
43
  .item-label,
44
44
  .swatch {
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { CHANNEL_TYPES } from './contants';
2
+ import type { CHANNEL_TYPES } from './contants.js';
3
3
  import type { Plot } from './classes/Plot.svelte';
4
4
  import type { MouseEventHandler } from 'svelte/elements';
5
5
  export type Datasets = {
@@ -30,6 +30,11 @@ export type Datasets = {
30
30
  body_mass_g: number;
31
31
  sex: string;
32
32
  }[];
33
+ bls: {
34
+ division: string;
35
+ date: Date;
36
+ unemployment: number;
37
+ }[];
33
38
  };
34
39
  export type AxisXAnchor = 'bottom' | 'top' | 'both';
35
40
  export type AxisYAnchor = 'left' | 'right' | 'both';
@@ -80,7 +85,9 @@ export type PlotProps = {
80
85
  legend?: boolean;
81
86
  } | null;
82
87
  color?: {
83
- scheme?: ColorScheme | string[];
88
+ range?: string[];
89
+ domain: RawValue[];
90
+ scheme?: ColorScheme;
84
91
  legend?: boolean;
85
92
  } | null;
86
93
  };
@@ -133,6 +140,9 @@ export type LineMarkProps = MarkProps & BaseMarkStyleProps & {
133
140
  x?: ChannelAccessor;
134
141
  y?: ChannelAccessor;
135
142
  z?: ChannelAccessor;
143
+ sort?: ChannelAccessor | {
144
+ channel: 'stroke' | 'fill';
145
+ };
136
146
  };
137
147
  export type GridOptions = {
138
148
  ticks?: RawValue[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.0.1-alpha.6",
3
+ "version": "0.0.1-alpha.8",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build",
@@ -49,7 +49,7 @@
49
49
  "prettier": "^3.1.0",
50
50
  "prettier-plugin-svelte": "^3.1.2",
51
51
  "sass": "^1.69.5",
52
- "svelte": "5.0.0-next.20",
52
+ "svelte": "5.0.0-next.22",
53
53
  "svelte-check": "^3.6.2",
54
54
  "svelte-highlight": "^7.4.2",
55
55
  "tslib": "^2.6.2",