svelteplot 0.2.8-pr-78.1 → 0.2.9-pr-95.0

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.
@@ -23,6 +23,10 @@
23
23
  | Intl.NumberFormatOptions
24
24
  | ((d: RawValue) => string);
25
25
  tickClass?: ConstantAccessor<string>;
26
+ /** ticks is a shorthand for defining data, tickCount or interval */
27
+ ticks?: number | string | RawValue[];
28
+ /** set to false or null to disable tick labels */
29
+ text: boolean | null;
26
30
  } & XOR<
27
31
  {
28
32
  /** approximate number of ticks to be generated */
@@ -61,12 +65,13 @@
61
65
  };
62
66
 
63
67
  let {
64
- data = [],
68
+ ticks: magicTicks,
69
+ data = Array.isArray(magicTicks) ? magicTicks : [],
65
70
  automatic = false,
66
71
  title,
67
72
  anchor = DEFAULTS.axisXAnchor as 'top' | 'bottom',
68
73
  facetAnchor = 'auto',
69
- interval,
74
+ interval = typeof magicTicks === 'string' ? magicTicks : undefined,
70
75
  tickSize = DEFAULTS.tickSize,
71
76
  tickFontSize = DEFAULTS.tickFontSize,
72
77
  tickPadding = DEFAULTS.tickPadding,
@@ -74,8 +79,9 @@
74
79
  tickFormat,
75
80
  tickClass,
76
81
  class: className,
77
- tickCount,
82
+ tickCount = typeof magicTicks === 'number' ? magicTicks : undefined,
78
83
  tickSpacing,
84
+ text = true,
79
85
  ...options
80
86
  }: AxisXMarkProps = $props();
81
87
 
@@ -217,6 +223,7 @@
217
223
  {tickPadding}
218
224
  {tickFontSize}
219
225
  {tickClass}
226
+ {text}
220
227
  {options}
221
228
  title={useTitle}
222
229
  {plot} />
@@ -12,6 +12,10 @@ export type AxisXMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paint
12
12
  tickPadding?: number;
13
13
  tickFormat?: 'auto' | Intl.DateTimeFormatOptions | Intl.NumberFormatOptions | ((d: RawValue) => string);
14
14
  tickClass?: ConstantAccessor<string>;
15
+ /** ticks is a shorthand for defining data, tickCount or interval */
16
+ ticks?: number | string | RawValue[];
17
+ /** set to false or null to disable tick labels */
18
+ text: boolean | null;
15
19
  } & XOR<{
16
20
  /** approximate number of ticks to be generated */
17
21
  tickCount?: number;
@@ -24,6 +24,10 @@
24
24
  | Intl.NumberFormatOptions
25
25
  | ((d: RawValue) => string);
26
26
  tickClass?: ConstantAccessor<string>;
27
+ /** ticks is a shorthand for defining data, tickCount or interval */
28
+ ticks?: number | string | RawValue[];
29
+ /** set to false or null to disable tick labels */
30
+ text: boolean | null;
27
31
  } & XOR<
28
32
  {
29
33
  /** approximate number of ticks to be generated */
@@ -61,20 +65,22 @@
61
65
  };
62
66
 
63
67
  let {
64
- data = [],
68
+ ticks: magicTicks,
69
+ data = Array.isArray(magicTicks) ? magicTicks : [],
65
70
  automatic = false,
66
71
  title,
67
72
  anchor = DEFAULTS.axisYAnchor as 'left' | 'right',
68
73
  facetAnchor = 'auto',
69
- interval,
74
+ interval = typeof magicTicks === 'string' ? magicTicks : undefined,
70
75
  lineAnchor = 'center',
71
76
  tickSize = DEFAULTS.tickSize,
72
77
  tickFontSize = DEFAULTS.tickFontSize,
73
78
  tickPadding = DEFAULTS.tickPadding,
74
79
  tickFormat,
75
80
  tickClass,
76
- tickCount,
81
+ tickCount = typeof magicTicks === 'number' ? magicTicks : undefined,
77
82
  tickSpacing,
83
+ text = true,
78
84
  ...options
79
85
  }: AxisYMarkProps = $props();
80
86
 
@@ -197,6 +203,7 @@
197
203
  {tickFontSize}
198
204
  {tickClass}
199
205
  {options}
206
+ {text}
200
207
  title={useTitle}
201
208
  {plot} />
202
209
  {/if}
@@ -13,6 +13,10 @@ export type AxisYMarkProps = Omit<BaseMarkProps, 'fill' | 'fillOpacity' | 'paint
13
13
  tickPadding?: number;
14
14
  tickFormat?: 'auto' | Intl.DateTimeFormatOptions | Intl.NumberFormatOptions | ((d: RawValue) => string);
15
15
  tickClass?: ConstantAccessor<string>;
16
+ /** ticks is a shorthand for defining data, tickCount or interval */
17
+ ticks?: number | string | RawValue[];
18
+ /** set to false or null to disable tick labels */
19
+ text: boolean | null;
16
20
  } & XOR<{
17
21
  /** approximate number of ticks to be generated */
18
22
  tickCount?: number;
@@ -33,6 +33,7 @@
33
33
  dy: ConstantAccessor<number>;
34
34
  filter: ChannelAccessor;
35
35
  };
36
+ text: boolean;
36
37
  plot: PlotState;
37
38
  };
38
39
 
@@ -50,7 +51,8 @@
50
51
  height,
51
52
  options,
52
53
  plot,
53
- title
54
+ title,
55
+ text = true
54
56
  }: BaseAxisXProps = $props();
55
57
 
56
58
  function splitTick(tick: string | string[]) {
@@ -86,15 +88,17 @@
86
88
  })
87
89
  );
88
90
  const T = tickObjects.length;
89
- for (let i = 0; i < T; i++) {
90
- let j = i;
91
- // find the preceding tick that was not hidden
92
- do {
93
- j--;
94
- } while (j >= 0 && tickObjects[j].hidden);
95
- if (j >= 0) {
96
- const tickLabelSpace = Math.abs(tickObjects[i].x - tickObjects[j].x);
97
- tickObjects[i].hidden = tickLabelSpace < 15;
91
+ if (text) {
92
+ for (let i = 0; i < T; i++) {
93
+ let j = i;
94
+ // find the preceding tick that was not hidden
95
+ do {
96
+ j--;
97
+ } while (j >= 0 && tickObjects[j].hidden);
98
+ if (j >= 0) {
99
+ const tickLabelSpace = Math.abs(tickObjects[i].x - tickObjects[j].x);
100
+ tickObjects[i].hidden = tickLabelSpace < 15;
101
+ }
98
102
  }
99
103
  }
100
104
  return tickObjects;
@@ -102,6 +106,7 @@
102
106
 
103
107
  $effect(() => {
104
108
  untrack(() => [$autoMarginTop, $autoMarginBottom]);
109
+ if (!text) return;
105
110
  const outsideTextAnchor = anchor === 'top' ? 'end' : 'start';
106
111
  // measure tick label heights
107
112
  const maxLabelHeight =
@@ -144,26 +149,7 @@
144
149
  <g class="axis-x">
145
150
  {#each positionedTicks as tick, t (t)}
146
151
  {#if testFilter(tick.value, options) && !tick.hidden}
147
- {@const textLines = tick.text}
148
- {@const prevTextLines = t && positionedTicks[t - 1].text}
149
- {@const fontSize = resolveProp(tickFontSize, tick)}
150
152
  {@const tickClass_ = resolveProp(tickClass, tick.value)}
151
- {@const estLabelWidth = max(textLines.map((t) => t.length)) * fontSize * 0.2}
152
- {@const moveDown =
153
- (tickSize + tickPadding + (tickRotate !== 0 ? tickFontSize * 0.35 : 0)) *
154
- (anchor === 'bottom' ? 1 : -1)}
155
- {@const [textStyle, textClass] = resolveStyles(
156
- plot,
157
- tick,
158
- {
159
- fontVariant: isQuantitative ? 'tabular-nums' : 'normal',
160
- ...options,
161
- fontSize: tickFontSize,
162
- stroke: null
163
- },
164
- 'fill',
165
- { x: true }
166
- )}
167
153
  <g
168
154
  class="tick {tickClass_ || ''}"
169
155
  transform="translate({tick.x + tick.dx}, {tickY + tick.dy})"
@@ -182,31 +168,51 @@
182
168
  y2={anchor === 'bottom' ? tickSize : -tickSize} />
183
169
  {/if}
184
170
 
185
- <text
186
- bind:this={tickTextElements[t]}
187
- transform="translate(0, {moveDown}) rotate({tickRotate})"
188
- style={textStyle}
189
- class={textClass}
190
- x={0}
191
- y={0}
192
- dominant-baseline={tickRotate !== 0
193
- ? 'central'
194
- : anchor === 'bottom'
195
- ? 'hanging'
196
- : 'auto'}>
197
- {#if ticks.length > 0 || t === 0 || t === ticks.length - 1}
198
- {#if textLines.length === 1}
199
- {textLines[0]}
200
- {:else}
201
- {#each textLines as line, i (i)}
202
- <tspan x="0" dy={i ? 12 : 0}
203
- >{!prevTextLines || prevTextLines[i] !== line
204
- ? line
205
- : ''}</tspan>
206
- {/each}
171
+ {#if text}
172
+ {@const textLines = tick.text}
173
+ {@const prevTextLines = t && positionedTicks[t - 1].text}
174
+
175
+ {@const moveDown =
176
+ (tickSize + tickPadding + (tickRotate !== 0 ? tickFontSize * 0.35 : 0)) *
177
+ (anchor === 'bottom' ? 1 : -1)}
178
+ {@const [textStyle, textClass] = resolveStyles(
179
+ plot,
180
+ tick,
181
+ {
182
+ fontVariant: isQuantitative ? 'tabular-nums' : 'normal',
183
+ ...options,
184
+ fontSize: tickFontSize,
185
+ stroke: null
186
+ },
187
+ 'fill',
188
+ { x: true }
189
+ )}
190
+ <text
191
+ bind:this={tickTextElements[t]}
192
+ transform="translate(0, {moveDown}) rotate({tickRotate})"
193
+ style={textStyle}
194
+ class={textClass}
195
+ x={0}
196
+ y={0}
197
+ dominant-baseline={tickRotate !== 0
198
+ ? 'central'
199
+ : anchor === 'bottom'
200
+ ? 'hanging'
201
+ : 'auto'}>
202
+ {#if ticks.length > 0 || t === 0 || t === ticks.length - 1}
203
+ {#if textLines.length === 1}
204
+ {textLines[0]}
205
+ {:else}
206
+ {#each textLines as line, i (i)}
207
+ <tspan x="0" dy={i ? 12 : 0}
208
+ >{!prevTextLines || prevTextLines[i] !== line
209
+ ? line
210
+ : ''}</tspan>
211
+ {/each}
212
+ {/if}
207
213
  {/if}
208
- {/if}
209
- </text>
214
+ </text>
215
+ {/if}
210
216
  </g>
211
217
  {/if}
212
218
  {/each}
@@ -17,6 +17,7 @@ type BaseAxisXProps = {
17
17
  dy: ConstantAccessor<number>;
18
18
  filter: ChannelAccessor;
19
19
  };
20
+ text: boolean;
20
21
  plot: PlotState;
21
22
  };
22
23
  declare const BaseAxisX: import("svelte").Component<BaseAxisXProps, {}, "">;
@@ -29,6 +29,7 @@
29
29
  dy: ConstantAccessor<number>;
30
30
  };
31
31
  plot: PlotState;
32
+ text: boolean | null;
32
33
  };
33
34
 
34
35
  let {
@@ -46,7 +47,8 @@
46
47
  width,
47
48
  title,
48
49
  plot,
49
- options
50
+ options,
51
+ text = true
50
52
  }: BaseAxisYProps = $props();
51
53
 
52
54
  const LINE_ANCHOR = {
@@ -67,16 +69,18 @@
67
69
  element: null as SVGTextElement | null
68
70
  };
69
71
  });
70
- const T = tickObjects.length;
71
- for (let i = 0; i < T; i++) {
72
- let j = i;
73
- // find the preceding tick that was not hidden
74
- do {
75
- j--;
76
- } while (j >= 0 && tickObjects[j].hidden);
77
- if (j >= 0) {
78
- const tickLabelSpace = Math.abs(tickObjects[i].y - tickObjects[j].y);
79
- tickObjects[i].hidden = tickLabelSpace < 15;
72
+ if (text) {
73
+ const T = tickObjects.length;
74
+ for (let i = 0; i < T; i++) {
75
+ let j = i;
76
+ // find the preceding tick that was not hidden
77
+ do {
78
+ j--;
79
+ } while (j >= 0 && tickObjects[j].hidden);
80
+ if (j >= 0) {
81
+ const tickLabelSpace = Math.abs(tickObjects[i].y - tickObjects[j].y);
82
+ tickObjects[i].hidden = tickLabelSpace < 15;
83
+ }
80
84
  }
81
85
  }
82
86
  return tickObjects;
@@ -176,13 +180,15 @@
176
180
  class={tickLineClass}
177
181
  x2={anchor === 'left' ? -tickSize : tickSize} />
178
182
  {/if}
179
- <text
180
- bind:this={tickTexts[t]}
181
- class={[textClass, { 'is-left': anchor === 'left' }]}
182
- style={textStyle}
183
- x={(tickSize + tickPadding) * (anchor === 'left' ? -1 : 1)}
184
- dominant-baseline={LINE_ANCHOR[lineAnchor]}
185
- >{Array.isArray(tick.text) ? tick.text.join(' ') : tick.text}</text>
183
+ {#if text}
184
+ <text
185
+ bind:this={tickTexts[t]}
186
+ class={[textClass, { 'is-left': anchor === 'left' }]}
187
+ style={textStyle}
188
+ x={(tickSize + tickPadding) * (anchor === 'left' ? -1 : 1)}
189
+ dominant-baseline={LINE_ANCHOR[lineAnchor]}
190
+ >{Array.isArray(tick.text) ? tick.text.join(' ') : tick.text}</text>
191
+ {/if}
186
192
  </g>
187
193
  {/if}
188
194
  {/each}
@@ -17,6 +17,7 @@ type BaseAxisYProps = {
17
17
  dy: ConstantAccessor<number>;
18
18
  };
19
19
  plot: PlotState;
20
+ text: boolean | null;
20
21
  };
21
22
  declare const BaseAxisY: import("svelte").Component<BaseAxisYProps, {}, "">;
22
23
  type BaseAxisY = ReturnType<typeof BaseAxisY>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.2.8-pr-78.1",
3
+ "version": "0.2.9-pr-95.0",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",