svelteplot 0.0.1-alpha.2 → 0.0.1-alpha.21

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.
Files changed (87) hide show
  1. package/dist/Plot.svelte +56 -42
  2. package/dist/Plot.svelte.d.ts +3 -3
  3. package/dist/classes/Mark.svelte.js +4 -0
  4. package/dist/classes/Plot.svelte.js +50 -24
  5. package/dist/classes/Scale.svelte.js +94 -0
  6. package/dist/contants.d.ts +3 -3
  7. package/dist/contants.js +18 -16
  8. package/dist/helpers/GroupMultiple.svelte.d.ts +3 -3
  9. package/dist/helpers/autoTimeFormat.d.ts +2 -2
  10. package/dist/helpers/autoTimeFormat.js +1 -1
  11. package/dist/helpers/callWithProps.d.ts +4 -0
  12. package/dist/helpers/callWithProps.js +9 -0
  13. package/dist/helpers/colors.d.ts +1 -1
  14. package/dist/helpers/createScale.d.ts +2 -1
  15. package/dist/helpers/createScale.js +37 -16
  16. package/dist/helpers/curves.d.ts +3 -0
  17. package/dist/helpers/curves.js +42 -0
  18. package/dist/helpers/getBaseStyles.d.ts +1 -1
  19. package/dist/helpers/getBaseStyles.js +2 -3
  20. package/dist/helpers/getLogTicks.js +5 -5
  21. package/dist/helpers/isDataRecord.d.ts +1 -1
  22. package/dist/helpers/isRawValue.d.ts +2 -0
  23. package/dist/helpers/isRawValue.js +5 -0
  24. package/dist/helpers/resolveChannel.d.ts +6 -2
  25. package/dist/helpers/resolveChannel.js +16 -6
  26. package/dist/helpers/typeChecks.d.ts +1 -1
  27. package/dist/helpers/typeChecks.js +1 -1
  28. package/dist/helpers/wrapArray.d.ts +2 -2
  29. package/dist/helpers/wrapValueArray.d.ts +6 -0
  30. package/dist/helpers/wrapValueArray.js +5 -0
  31. package/dist/index.d.ts +15 -1
  32. package/dist/index.js +17 -1
  33. package/dist/marks/Area.svelte +95 -0
  34. package/dist/marks/Area.svelte.d.ts +28 -0
  35. package/dist/marks/AreaX.svelte +11 -0
  36. package/dist/marks/AreaX.svelte.d.ts +30 -0
  37. package/dist/marks/AreaY.svelte +12 -0
  38. package/dist/marks/AreaY.svelte.d.ts +30 -0
  39. package/dist/marks/AxisX.svelte +17 -17
  40. package/dist/marks/AxisX.svelte.d.ts +3 -3
  41. package/dist/marks/AxisY.svelte +25 -11
  42. package/dist/marks/AxisY.svelte.d.ts +3 -3
  43. package/dist/marks/BarX.svelte +52 -0
  44. package/dist/marks/BarX.svelte.d.ts +25 -0
  45. package/dist/marks/BarY.svelte +52 -0
  46. package/dist/marks/BarY.svelte.d.ts +25 -0
  47. package/dist/marks/BaseMark.svelte +10 -3
  48. package/dist/marks/BaseMark.svelte.d.ts +5 -4
  49. package/dist/marks/ColorLegend.svelte +26 -24
  50. package/dist/marks/ColorLegend.svelte.d.ts +2 -2
  51. package/dist/marks/Dot.svelte +28 -43
  52. package/dist/marks/Dot.svelte.d.ts +11 -3
  53. package/dist/marks/DotX.svelte.d.ts +3 -3
  54. package/dist/marks/DotY.svelte.d.ts +3 -3
  55. package/dist/marks/Frame.svelte +1 -1
  56. package/dist/marks/Frame.svelte.d.ts +4 -4
  57. package/dist/marks/GridX.svelte +29 -18
  58. package/dist/marks/GridX.svelte.d.ts +6 -6
  59. package/dist/marks/GridY.svelte +17 -7
  60. package/dist/marks/GridY.svelte.d.ts +3 -3
  61. package/dist/marks/Line.svelte +28 -29
  62. package/dist/marks/Line.svelte.d.ts +15 -3
  63. package/dist/marks/LineX.svelte +5 -7
  64. package/dist/marks/LineX.svelte.d.ts +13 -6
  65. package/dist/marks/LineY.svelte +4 -6
  66. package/dist/marks/LineY.svelte.d.ts +14 -6
  67. package/dist/marks/RuleX.svelte +17 -9
  68. package/dist/marks/RuleX.svelte.d.ts +3 -3
  69. package/dist/marks/RuleY.svelte +17 -10
  70. package/dist/marks/RuleY.svelte.d.ts +3 -3
  71. package/dist/marks/SymbolLegend.svelte +17 -17
  72. package/dist/marks/SymbolLegend.svelte.d.ts +2 -2
  73. package/dist/marks/TickX.svelte +30 -0
  74. package/dist/marks/TickX.svelte.d.ts +15 -0
  75. package/dist/marks/TickY.svelte +30 -0
  76. package/dist/marks/TickY.svelte.d.ts +15 -0
  77. package/dist/transforms/normalize.d.ts +18 -0
  78. package/dist/transforms/normalize.js +25 -0
  79. package/dist/transforms/recordize.d.ts +3 -0
  80. package/dist/transforms/recordize.js +36 -0
  81. package/dist/transforms/rename.d.ts +4 -0
  82. package/dist/transforms/rename.js +10 -0
  83. package/dist/transforms/stack.d.ts +11 -0
  84. package/dist/transforms/stack.js +80 -0
  85. package/dist/types.d.ts +60 -23
  86. package/package.json +28 -23
  87. package/dist/classes/Channel.svelte.js +0 -72
@@ -1,5 +1,4 @@
1
- import { MARK_PROP_CHANNEL } from '../contants';
2
- import resolveChannel from './resolveChannel';
1
+ import resolveChannel from './resolveChannel.js';
3
2
  const styleProps = {
4
3
  fill: 'fill',
5
4
  stroke: 'stroke',
@@ -13,6 +12,6 @@ const styleProps = {
13
12
  export default function (datum, props) {
14
13
  return Object.entries(styleProps)
15
14
  .filter(([key, cssKey]) => cssKey && props[key] != null)
16
- .map(([key, cssKey]) => `${cssKey}: ${resolveChannel(MARK_PROP_CHANNEL[key], datum, props[key])}`)
15
+ .map(([key, cssKey]) => `${cssKey}: ${resolveChannel(key, datum, props)}`)
17
16
  .join(';');
18
17
  }
@@ -10,7 +10,7 @@ export function getLogTicks(domain, count = 6) {
10
10
  return [];
11
11
  if (domain[0] === 0)
12
12
  return ticksArray(domain[0], domain[1], count - 2);
13
- let mult = Math.pow(10, Math.floor(Math.log10(Math.abs(domain[1] - domain[0]))) - 1);
13
+ let mult = 1; //Math.pow(10, Math.floor(Math.log10(Math.abs(domain[1] - domain[0]))) - 1);
14
14
  count += 2;
15
15
  let candidates = getTickCandidates(domain, mult);
16
16
  if (candidates[0].num > count) {
@@ -46,12 +46,12 @@ function getTickCandidates(domain, mult = 1) {
46
46
  return logSeries.map((factors) => {
47
47
  let i = Math.pow(10, Math.floor(Math.log10(domain[0])));
48
48
  let f = 0;
49
- const r = [i];
50
- while (i < domain[1] && r.length < 50) {
49
+ const ticks = [i];
50
+ while (i < domain[1] && ticks.length < 50) {
51
51
  i *= factors[f] * mult;
52
- r.push(i);
52
+ ticks.push(i);
53
53
  f = (f + 1) % factors.length;
54
54
  }
55
- return { ticks: r, num: r.length };
55
+ return { ticks, num: ticks.length };
56
56
  });
57
57
  }
@@ -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;
@@ -0,0 +1,2 @@
1
+ import type { RawValue } from '../types.js';
2
+ export default function (value: any): value is RawValue;
@@ -0,0 +1,5 @@
1
+ import { isDate } from 'underscore';
2
+ export default function (value) {
3
+ const t = typeof value;
4
+ return t === 'string' || t === 'number' || t === 'boolean' || isDate(value) || t === null;
5
+ }
@@ -1,2 +1,6 @@
1
- import type { ChannelName, ChannelAccessor, DataRow, RawValue } from '../types';
2
- export default function (channel: ChannelName, datum: DataRow, accessor?: ChannelAccessor): RawValue;
1
+ import type { ChannelName, ChannelAccessor, DataRow, RawValue } from '../types.js';
2
+ type ChannelAlias = {
3
+ channel: ChannelName;
4
+ };
5
+ export default function (channel: ChannelName, datum: DataRow, channels: Partial<Record<ChannelName, ChannelAccessor | ChannelAlias>>): RawValue;
6
+ export {};
@@ -1,5 +1,14 @@
1
- import isDataRecord from './isDataRecord';
2
- export default function (channel, datum, accessor = null) {
1
+ import { CHANNEL_SCALE } from '../contants.js';
2
+ import isDataRecord from './isDataRecord.js';
3
+ import isRawValue from './isRawValue.js';
4
+ export default function (channel, datum, channels) {
5
+ const scale = CHANNEL_SCALE[channel];
6
+ const maybeAccessor = channel === 'z' ? channels.z || channels.fill || channels.stroke : channels[channel];
7
+ const accessor = isDataRecord(maybeAccessor) && maybeAccessor?.channel
8
+ ? channels[maybeAccessor?.channel]
9
+ : maybeAccessor;
10
+ if (isDataRecord(accessor) && accessor.channel)
11
+ throw new Error('multiple channel aliases are not allowed');
3
12
  if ((channel === 'x' || channel === 'y') && Array.isArray(datum) && accessor === null) {
4
13
  // special case for [[x0,y0], [x1,y1], ...] format
5
14
  return datum[channel === 'x' ? 0 : 1];
@@ -14,15 +23,16 @@ export default function (channel, datum, accessor = null) {
14
23
  // fallback to channel name as accessor
15
24
  if (accessor === null && datum[channel] !== undefined)
16
25
  return datum[channel];
17
- // interpret accessor as constant
18
- return accessor;
26
+ return isRawValue(accessor) ? accessor : null;
19
27
  }
20
28
  else {
21
29
  // return single value or accessor
22
30
  return typeof accessor === 'function'
23
31
  ? accessor(datum)
24
- : accessor !== null
32
+ : accessor !== null && isRawValue(accessor)
25
33
  ? accessor
26
- : datum;
34
+ : !Array.isArray(datum) && (scale === 'x' || scale === 'y')
35
+ ? datum
36
+ : null;
27
37
  }
28
38
  }
@@ -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;
@@ -14,7 +14,7 @@ export function isStringOrNull(v) {
14
14
  }
15
15
  export function isColorOrNull(v) {
16
16
  // todo: maybe not use chroma.js here to save kb
17
- return v == null || (typeof v === 'string' && chroma.valid(v));
17
+ return v == null || (typeof v === 'string' && (chroma.valid(v) || v === 'currentColor'));
18
18
  }
19
19
  export function isOpacityOrNull(v) {
20
20
  return v == null || (typeof v === 'number' && isFinite(v) && v >= 0 && v <= 1);
@@ -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)[];
@@ -0,0 +1,6 @@
1
+ import type { RawValue } from '../types.js';
2
+ export default function (values: RawValue[]): {
3
+ value: RawValue;
4
+ index: number;
5
+ ___orig___: RawValue;
6
+ }[];
@@ -0,0 +1,5 @@
1
+ export default function (values) {
2
+ const arr = values.map((value, index) => ({ value, index, ___orig___: value }));
3
+ arr.__wrapped__ = true;
4
+ return arr;
5
+ }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,15 @@
1
+ export { default as Plot } from './Plot.svelte';
2
+ export { default as Area } from './marks/Area.svelte';
3
+ export { default as AreaX } from './marks/AreaX.svelte';
4
+ export { default as AreaY } from './marks/AreaY.svelte';
5
+ export { default as AxisX } from './marks/AxisX.svelte';
6
+ export { default as AxisY } from './marks/AxisY.svelte';
7
+ export { default as BarX } from './marks/BarX.svelte';
8
+ export { default as BarY } from './marks/BarY.svelte';
9
+ export { default as ColorLegend } from './marks/ColorLegend.svelte';
1
10
  export { default as Dot } from './marks/Dot.svelte';
2
11
  export { default as DotX } from './marks/DotX.svelte';
3
12
  export { default as DotY } from './marks/DotY.svelte';
4
- export { default as Plot } from './Plot.svelte';
5
13
  export { default as Frame } from './marks/Frame.svelte';
6
14
  export { default as GridX } from './marks/GridX.svelte';
7
15
  export { default as GridY } from './marks/GridY.svelte';
@@ -10,3 +18,9 @@ export { default as LineX } from './marks/LineX.svelte';
10
18
  export { default as LineY } from './marks/LineY.svelte';
11
19
  export { default as RuleX } from './marks/RuleX.svelte';
12
20
  export { default as RuleY } from './marks/RuleY.svelte';
21
+ export { default as SymbolLegend } from './marks/SymbolLegend.svelte';
22
+ export { default as TickX } from './marks/TickX.svelte';
23
+ export { default as TickY } from './marks/TickY.svelte';
24
+ export { stackX, stackY } from './transforms/stack.js';
25
+ export { recordizeX, recordizeY } from './transforms/recordize.js';
26
+ export { renameChannels } from './transforms/rename.js';
package/dist/index.js CHANGED
@@ -1,8 +1,17 @@
1
1
  // Reexport your entry components here
2
+ export { default as Plot } from './Plot.svelte';
3
+ // marks
4
+ export { default as Area } from './marks/Area.svelte';
5
+ export { default as AreaX } from './marks/AreaX.svelte';
6
+ export { default as AreaY } from './marks/AreaY.svelte';
7
+ export { default as AxisX } from './marks/AxisX.svelte';
8
+ export { default as AxisY } from './marks/AxisY.svelte';
9
+ export { default as BarX } from './marks/BarX.svelte';
10
+ export { default as BarY } from './marks/BarY.svelte';
11
+ export { default as ColorLegend } from './marks/ColorLegend.svelte';
2
12
  export { default as Dot } from './marks/Dot.svelte';
3
13
  export { default as DotX } from './marks/DotX.svelte';
4
14
  export { default as DotY } from './marks/DotY.svelte';
5
- export { default as Plot } from './Plot.svelte';
6
15
  export { default as Frame } from './marks/Frame.svelte';
7
16
  export { default as GridX } from './marks/GridX.svelte';
8
17
  export { default as GridY } from './marks/GridY.svelte';
@@ -11,3 +20,10 @@ export { default as LineX } from './marks/LineX.svelte';
11
20
  export { default as LineY } from './marks/LineY.svelte';
12
21
  export { default as RuleX } from './marks/RuleX.svelte';
13
22
  export { default as RuleY } from './marks/RuleY.svelte';
23
+ export { default as SymbolLegend } from './marks/SymbolLegend.svelte';
24
+ export { default as TickX } from './marks/TickX.svelte';
25
+ export { default as TickY } from './marks/TickY.svelte';
26
+ // transforms
27
+ export { stackX, stackY } from './transforms/stack.js';
28
+ export { recordizeX, recordizeY } from './transforms/recordize.js';
29
+ export { renameChannels } from './transforms/rename.js';
@@ -0,0 +1,95 @@
1
+ <script context="module"></script>
2
+
3
+ <script>import resolveChannel from "../helpers/resolveChannel.js";
4
+ import { getContext } from "svelte";
5
+ import BaseMark from "./BaseMark.svelte";
6
+ import getBaseStyles from "../helpers/getBaseStyles.js";
7
+ import { area } from "d3-shape";
8
+ import { groupBy } from "underscore";
9
+ import callWithProps from "../helpers/callWithProps.js";
10
+ import { maybeCurve } from "../helpers/curves.js";
11
+ const BaseMark_Area = BaseMark;
12
+ const plot = getContext("svelteplot");
13
+ let {
14
+ data,
15
+ curve,
16
+ tension,
17
+ x1 = null,
18
+ x2 = null,
19
+ y1 = null,
20
+ y2 = null,
21
+ z = null,
22
+ fill = null,
23
+ stroke = null,
24
+ sort = null,
25
+ ...styleProps
26
+ } = $props();
27
+ let channels = $derived({
28
+ x1,
29
+ x2,
30
+ y1,
31
+ y2,
32
+ fill,
33
+ stroke,
34
+ z,
35
+ sort
36
+ });
37
+ let groups = $derived(
38
+ z || fill || stroke ? Object.values(groupBy(data, (d) => resolveChannel("z", d, channels))) : [data]
39
+ );
40
+ let sortedGroups = $derived(
41
+ sort ? groups.sort(
42
+ (a, b) => resolveChannel("sort", a[0], channels) > resolveChannel("sort", b[0], channels) ? 1 : -1
43
+ ) : groups
44
+ );
45
+ let areaPath = $derived(
46
+ callWithProps(area, [], {
47
+ curve: maybeCurve(curve, tension),
48
+ ...x1 != null && x2 != null ? {
49
+ // "vertical" area
50
+ x0: (d) => plot.xScale(resolveChannel("x1", d, channels)),
51
+ x1: (d) => plot.xScale(resolveChannel("x2", d, channels)),
52
+ y: (d) => plot.yScale(resolveChannel("y1", d, channels))
53
+ } : {
54
+ // "horizontal" area
55
+ x: (d) => plot.xScale(resolveChannel("x1", d, channels)),
56
+ y0: (d) => plot.yScale(resolveChannel("y1", d, channels)),
57
+ y1: (d) => plot.yScale(resolveChannel("y2", d, channels))
58
+ }
59
+ })
60
+ );
61
+ </script>
62
+
63
+ <BaseMark_Area
64
+ type="area"
65
+ {data}
66
+ channels={['x1', 'x2', 'y1', 'y2', 'fill', 'stroke']}
67
+ {x1}
68
+ {x2}
69
+ {y1}
70
+ {y2}
71
+ {fill}
72
+ {stroke}
73
+ {...styleProps}
74
+ >
75
+ <g class="areas">
76
+ {#each sortedGroups as areaData}
77
+ <path
78
+ d={areaPath(areaData)}
79
+ style:stroke={stroke
80
+ ? plot.colorScale(resolveChannel('stroke', areaData[0], channels))
81
+ : 'none'}
82
+ style:fill={fill
83
+ ? plot.colorScale(resolveChannel('fill', areaData[0], channels))
84
+ : 'currentColor'}
85
+ style={getBaseStyles(areaData[0], styleProps)}
86
+ />
87
+ {/each}
88
+ </g>
89
+ </BaseMark_Area>
90
+
91
+ <style>
92
+ .lines path {
93
+ stroke-width: 1.4px;
94
+ }
95
+ </style>
@@ -0,0 +1,28 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, Curve } from '../types.js';
3
+ export type AreaMarkProps = MarkProps & BaseMarkStyleProps & {
4
+ x1?: ChannelAccessor;
5
+ x2?: ChannelAccessor;
6
+ y1?: ChannelAccessor;
7
+ y2?: ChannelAccessor;
8
+ z?: ChannelAccessor;
9
+ sort?: ChannelAccessor | {
10
+ channel: 'stroke' | 'fill';
11
+ };
12
+ curve: Curve | CurveFactory;
13
+ tension: number;
14
+ };
15
+ import { type CurveFactory } from 'd3-shape';
16
+ declare const __propDef: {
17
+ props: AreaMarkProps;
18
+ events: {
19
+ [evt: string]: CustomEvent<any>;
20
+ };
21
+ slots: {};
22
+ };
23
+ export type AreaProps = typeof __propDef.props;
24
+ export type AreaEvents = typeof __propDef.events;
25
+ export type AreaSlots = typeof __propDef.slots;
26
+ export default class Area extends SvelteComponentTyped<AreaProps, AreaEvents, AreaSlots> {
27
+ }
28
+ export {};
@@ -0,0 +1,11 @@
1
+ <script context="module"></script>
2
+
3
+ <script>import Area from "./Area.svelte";
4
+ import { stackX, recordizeX, renameChannels } from "..";
5
+ let { data: rawData, stack, ...rawChannels } = $props();
6
+ let { data, ...channels } = $derived(
7
+ renameChannels(stackX(recordizeX({ data: rawData, ...rawChannels }), stack), { y: "y1" })
8
+ );
9
+ </script>
10
+
11
+ <Area {data} {...channels} />
@@ -0,0 +1,30 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, Curve } from '../types.js';
3
+ import type { CurveFactory } from 'd3-shape';
4
+ import type { StackOptions } from '../transforms/stack.js';
5
+ export type AreaXMarkProps = MarkProps & BaseMarkStyleProps & {
6
+ x?: ChannelAccessor;
7
+ x1?: ChannelAccessor;
8
+ x2?: ChannelAccessor;
9
+ y?: ChannelAccessor;
10
+ z?: ChannelAccessor;
11
+ sort?: ChannelAccessor | {
12
+ channel: 'stroke' | 'fill';
13
+ };
14
+ curve: Curve | CurveFactory;
15
+ tension: number;
16
+ stack?: StackOptions;
17
+ };
18
+ declare const __propDef: {
19
+ props: AreaXMarkProps;
20
+ events: {
21
+ [evt: string]: CustomEvent<any>;
22
+ };
23
+ slots: {};
24
+ };
25
+ export type AreaXProps = typeof __propDef.props;
26
+ export type AreaXEvents = typeof __propDef.events;
27
+ export type AreaXSlots = typeof __propDef.slots;
28
+ export default class AreaX extends SvelteComponentTyped<AreaXProps, AreaXEvents, AreaXSlots> {
29
+ }
30
+ export {};
@@ -0,0 +1,12 @@
1
+ <script context="module"></script>
2
+
3
+ <script>import Area from "./Area.svelte";
4
+ import { stackY, recordizeY, renameChannels } from "..";
5
+ let { data: rawData, stack, ...rawChannels } = $props();
6
+ let { data, ...channels } = $derived(
7
+ renameChannels(stackY(recordizeY({ data: rawData, ...rawChannels }), stack), { x: "x1" })
8
+ );
9
+ $inspect({ data, channels });
10
+ </script>
11
+
12
+ <Area {data} {...channels} />
@@ -0,0 +1,30 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { MarkProps, BaseMarkStyleProps, ChannelAccessor, Curve } from '../types.js';
3
+ import type { CurveFactory } from 'd3-shape';
4
+ import type { StackOptions } from '../transforms/stack.js';
5
+ export type AreaYMarkProps = MarkProps & BaseMarkStyleProps & {
6
+ x?: ChannelAccessor;
7
+ y?: ChannelAccessor;
8
+ y1?: ChannelAccessor;
9
+ y2?: ChannelAccessor;
10
+ z?: ChannelAccessor;
11
+ sort?: ChannelAccessor | {
12
+ channel: 'stroke' | 'fill';
13
+ };
14
+ curve: Curve | CurveFactory;
15
+ tension: number;
16
+ stack?: StackOptions;
17
+ };
18
+ declare const __propDef: {
19
+ props: AreaYMarkProps;
20
+ events: {
21
+ [evt: string]: CustomEvent<any>;
22
+ };
23
+ slots: {};
24
+ };
25
+ export type AreaYProps = typeof __propDef.props;
26
+ export type AreaYEvents = typeof __propDef.events;
27
+ export type AreaYSlots = typeof __propDef.slots;
28
+ export default class AreaY extends SvelteComponentTyped<AreaYProps, AreaYEvents, AreaYSlots> {
29
+ }
30
+ export {};
@@ -1,11 +1,9 @@
1
1
  <script>import { getContext } from "svelte";
2
- import BaseMark from "./BaseMark.svelte";
3
- import resolveChannel from "../helpers/resolveChannel";
4
- import getBaseStyles from "../helpers/getBaseStyles";
5
- import removeIdenticalLines from "../helpers/removeIdenticalLines";
6
- import autoTimeFormat from "../helpers/autoTimeFormat";
7
2
  import dayjs from "dayjs";
8
- import { get } from "underscore";
3
+ import BaseMark from "./BaseMark.svelte";
4
+ import getBaseStyles from "../helpers/getBaseStyles.js";
5
+ import removeIdenticalLines from "../helpers/removeIdenticalLines.js";
6
+ import autoTimeFormat from "../helpers/autoTimeFormat.js";
9
7
  const BaseMark_AxisX = BaseMark;
10
8
  const plot = getContext("svelteplot");
11
9
  let {
@@ -20,12 +18,15 @@ let {
20
18
  fill = null,
21
19
  ...styleProps
22
20
  } = $props();
23
- let autoTickCount = $derived(plot.plotWidth / get(plot, "options.x.tickSpacing", 80));
21
+ let autoTickCount = $derived(
22
+ Math.max(2, Math.round(plot.plotWidth / (plot.options?.x?.tickSpacing || 80)))
23
+ );
24
+ $inspect(autoTickCount);
24
25
  let autoTicks = $derived(
25
- ticks.length > 0 ? ticks : get(plot, "options.x.ticks", plot.xScale.ticks(autoTickCount))
26
+ ticks.length > 0 ? ticks : plot.options?.x?.ticks ?? plot.xScale.ticks(autoTickCount)
26
27
  );
27
28
  let useTickFormat = $derived(
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)
29
+ 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(plot.x.scaleOptions.percent ? +(d * 100).toFixed(5) : d)
29
30
  );
30
31
  let tickTexts = $derived(
31
32
  removeIdenticalLines(
@@ -34,7 +35,7 @@ let tickTexts = $derived(
34
35
  );
35
36
  let optionsLabel = $derived(plot.options?.x?.label);
36
37
  let useTitle = $derived(
37
- title || (optionsLabel === null ? null : optionsLabel === void 0 ? plot.x.autoTitle : optionsLabel)
38
+ title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : plot.x.autoTitle ? plot.options.x?.reverse ? `\u2190 ${plot.x.autoTitle}${plot.x.scaleOptions.percent ? " (%)" : ""}` : `${plot.x.autoTitle}${plot.x.scaleOptions.percent ? " (%)" : ""} \u2192` : "")
38
39
  );
39
40
  </script>
40
41
 
@@ -45,7 +46,7 @@ let useTitle = $derived(
45
46
  x={plot.plotWidth + plot.margins.left}
46
47
  y={plot.height - 10}
47
48
  class="axis-title"
48
- dominant-baseline="hanging">{useTitle} →</text
49
+ dominant-baseline="hanging">{useTitle}</text
49
50
  >
50
51
  {/if}
51
52
  {#each autoTicks as tick, t}
@@ -53,7 +54,9 @@ let useTitle = $derived(
53
54
  {@const prevTextLines = t && tickTexts[t - 1]}
54
55
  <g
55
56
  class="x-tick"
56
- transform="translate({plot.xScale(tick)},{anchor === 'bottom'
57
+ transform="translate({plot.xScale(tick) +
58
+ (plot.xScale.bandwidth ? plot.xScale.bandwidth() * 0.5 : 0)},{anchor ===
59
+ 'bottom'
57
60
  ? plot.margins.top + plot.plotHeight
58
61
  : plot.margins.top})"
59
62
  >
@@ -85,8 +88,8 @@ let useTitle = $derived(
85
88
  text {
86
89
  text-anchor: middle;
87
90
  font-size: 11px;
88
-
89
- fill: #4a4a4a;
91
+ opacity: 0.8;
92
+ fill: currentColor;
90
93
  }
91
94
 
92
95
  text.axis-title {
@@ -95,7 +98,4 @@ let useTitle = $derived(
95
98
  .x-tick line {
96
99
  stroke: currentColor;
97
100
  }
98
- .x-tick line.grid {
99
- stroke: #d9d9d9;
100
- }
101
101
  </style>
@@ -1,5 +1,5 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { AxisMarkOptions } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { AxisMarkOptions } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: AxisMarkOptions & {
5
5
  anchor?: "bottom" | "top" | undefined;
@@ -12,6 +12,6 @@ declare const __propDef: {
12
12
  export type AxisXProps = typeof __propDef.props;
13
13
  export type AxisXEvents = typeof __propDef.events;
14
14
  export type AxisXSlots = typeof __propDef.slots;
15
- export default class AxisX extends SvelteComponent<AxisXProps, AxisXEvents, AxisXSlots> {
15
+ export default class AxisX extends SvelteComponentTyped<AxisXProps, AxisXEvents, AxisXSlots> {
16
16
  }
17
17
  export {};
@@ -1,7 +1,7 @@
1
1
  <script>import { getContext } from "svelte";
2
2
  import BaseMark from "./BaseMark.svelte";
3
- import getBaseStyles from "../helpers/getBaseStyles";
4
- import { get } from "underscore";
3
+ import getBaseStyles from "../helpers/getBaseStyles.js";
4
+ import autoTimeFormat from "../helpers/autoTimeFormat.js";
5
5
  const BaseMark_AxisX = BaseMark;
6
6
  const plot = getContext("svelteplot");
7
7
  let {
@@ -11,37 +11,50 @@ let {
11
11
  tickSize = 6,
12
12
  tickPadding = 3,
13
13
  title = null,
14
- tickFormat = (d) => String(d),
14
+ tickFormat,
15
15
  tickFontSize = null,
16
16
  fill = null,
17
17
  ...styleProps
18
18
  } = $props();
19
- let autoTickCount = $derived(plot.plotHeight / get(plot, "options.y.tickSpacing", 80));
19
+ let autoTickCount = $derived(plot.plotHeight / (plot.options.y?.tickSpacing || 80));
20
20
  let autoTicks = $derived(
21
- ticks.length > 0 ? ticks : get(plot, "options.y.ticks", plot.yScale.ticks(autoTickCount))
21
+ ticks.length > 0 ? ticks : plot.options.y?.ticks || plot.yScale.ticks(autoTickCount)
22
22
  );
23
- let optionsLabel = $derived(get(plot, "options.y.label"));
23
+ let useTickFormat = $derived(
24
+ typeof tickFormat === "function" ? tickFormat : plot.y.scaleType === "time" ? typeof tickFormat === "string" ? (d) => dayjs(d).format(tickFormat).split("\n") : autoTimeFormat(plot.y, plot.plotHeight) : (d) => String(plot.y.scaleOptions.percent ? +(d * 100).toFixed(5) : d)
25
+ );
26
+ let optionsLabel = $derived(plot.options.y?.label);
24
27
  let useTitle = $derived(
25
- title || (optionsLabel === null ? null : optionsLabel === void 0 ? plot.y.autoTitle : optionsLabel)
28
+ title || (optionsLabel === null ? null : optionsLabel !== void 0 ? optionsLabel : plot.y.autoTitle ? `\u2191 ${plot.y.autoTitle}${plot.y.scaleOptions.percent ? " (%)" : ""}` : "")
26
29
  );
30
+ $inspect(plot.y.propNames);
27
31
  </script>
28
32
 
29
33
  <BaseMark_AxisX type="axis-y" data={ticks} channels={['y']} {automatic}>
30
34
  <g class="axis-y">
31
35
  {#if useTitle}
32
- <text x={0} y={5} class="axis-title" dominant-baseline="hanging">↑ {useTitle}</text>
36
+ <text
37
+ style:text-anchor={anchor === 'left' ? 'start' : 'end'}
38
+ x={anchor === 'left' ? 0 : plot.width}
39
+ y={5}
40
+ class="axis-title"
41
+ dominant-baseline="hanging">{useTitle}</text
42
+ >
33
43
  {/if}
34
44
  {#each autoTicks as tick}
45
+ {@const tickText = useTickFormat(tick)}
35
46
  <g
36
47
  class="y-tick"
37
48
  transform="translate({plot.margins.left +
38
- (anchor === 'left' ? 0 : plot.plotWidth)},{plot.yScale(tick)})"
49
+ (anchor === 'left' ? 0 : plot.plotWidth)},{plot.yScale(tick) +
50
+ (plot.yScale.bandwidth ? plot.yScale.bandwidth() * 0.5 : 0)})"
39
51
  >
40
52
  <text
41
53
  class:is-left={anchor === 'left'}
42
54
  style={getBaseStyles(tick, { fill, fontSize: tickFontSize })}
43
55
  x={(tickSize + tickPadding) * (anchor === 'left' ? -1 : 1)}
44
- dominant-baseline="middle">{tickFormat(tick)}</text
56
+ dominant-baseline="middle"
57
+ >{Array.isArray(tickText) ? tickText.join(' ') : tickText}</text
45
58
  >
46
59
  <line
47
60
  style={getBaseStyles(tick, styleProps)}
@@ -55,7 +68,8 @@ let useTitle = $derived(
55
68
  <style>
56
69
  text {
57
70
  font-size: 11px;
58
- fill: #4a4a4a;
71
+ opacity: 0.8;
72
+ fill: currentColor;
59
73
  }
60
74
  text.is-left {
61
75
  text-anchor: end;
@@ -1,5 +1,5 @@
1
- import { SvelteComponent } from "svelte";
2
- import type { AxisYMarkProps } from '../types';
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { AxisYMarkProps } from '../types.js';
3
3
  declare const __propDef: {
4
4
  props: AxisYMarkProps;
5
5
  events: {
@@ -10,6 +10,6 @@ declare const __propDef: {
10
10
  export type AxisYProps = typeof __propDef.props;
11
11
  export type AxisYEvents = typeof __propDef.events;
12
12
  export type AxisYSlots = typeof __propDef.slots;
13
- export default class AxisY extends SvelteComponent<AxisYProps, AxisYEvents, AxisYSlots> {
13
+ export default class AxisY extends SvelteComponentTyped<AxisYProps, AxisYEvents, AxisYSlots> {
14
14
  }
15
15
  export {};