svelteplot 0.4.2-pr-194.0 → 0.4.2-pr-194.2

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.
@@ -13,8 +13,7 @@ export function coalesce(...args) {
13
13
  return null; // Return null if all arguments are null or undefined
14
14
  }
15
15
  export function testFilter(datum, options) {
16
- return (options.filter == null ||
17
- resolveProp(options.filter, isObject(datum) && datum.hasOwnProperty(RAW_VALUE) ? datum[RAW_VALUE] : datum));
16
+ return options.filter == null || resolveProp(options.filter, datum);
18
17
  }
19
18
  export function randomId() {
20
19
  return Math.ceil(1e9 + Math.random() * 1e9).toString(36);
@@ -39,7 +39,7 @@
39
39
  | 'auto'
40
40
  | Intl.DateTimeFormatOptions
41
41
  | Intl.NumberFormatOptions
42
- | ((d: RawValue) => string);
42
+ | ((d: RawValue, i: number) => string);
43
43
  tickClass?: ConstantAccessor<string, Datum>;
44
44
  /** ticks is a shorthand for defining data, tickCount or interval */
45
45
  ticks?: number | string | Datum[];
@@ -71,7 +71,7 @@ declare class __sveltets_Render<Datum extends RawValue> {
71
71
  tickFontSize?: ConstantAccessor<number, Datum>;
72
72
  titleFontSize?: number;
73
73
  tickPadding?: number;
74
- tickFormat?: "auto" | Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | ((d: RawValue) => string) | undefined;
74
+ tickFormat?: "auto" | Intl.NumberFormatOptions | Intl.DateTimeFormatOptions | ((d: RawValue, i: number) => string) | undefined;
75
75
  tickClass?: ConstantAccessor<string, Datum>;
76
76
  /** ticks is a shorthand for defining data, tickCount or interval */
77
77
  ticks?: string | number | Datum[] | undefined;
@@ -9,11 +9,14 @@
9
9
  ConstantAccessor,
10
10
  PlotState,
11
11
  RawValue,
12
+ ScaledDataRecord,
12
13
  ScaleType
13
14
  } from '../../types/index.js';
14
15
  import { resolveProp, resolveStyles } from '../../helpers/resolve.js';
15
16
  import { max } from 'd3-array';
16
17
  import { randomId, testFilter } from '../../helpers/index.js';
18
+ import { INDEX } from '../../constants';
19
+ import { RAW_VALUE } from '../../transforms/recordize';
17
20
 
18
21
  type BaseAxisXProps = {
19
22
  scaleFn: (d: RawValue) => number;
@@ -76,11 +79,12 @@
76
79
  const positionedTicks = $derived.by(() => {
77
80
  let tickObjects = removeIdenticalLines(
78
81
  ticks.map((tick, i) => {
82
+ const datum = { [RAW_VALUE]: tick, [INDEX]: i };
79
83
  return {
80
- value: tick,
84
+ ...datum,
81
85
  hidden: false,
82
- dx: +resolveProp(options.dx, tick, 0),
83
- dy: +resolveProp(options.dy, tick, 0),
86
+ dx: +resolveProp(options.dx, datum, 0),
87
+ dy: +resolveProp(options.dy, datum, 0),
84
88
  x: scaleFn(tick) + (scaleType === 'band' ? scaleFn.bandwidth() * 0.5 : 0),
85
89
  text: splitTick(tickFormat(tick, i)),
86
90
  element: null as SVGTextElement | null
@@ -101,7 +105,7 @@
101
105
  }
102
106
  }
103
107
  }
104
- return tickObjects;
108
+ return tickObjects as ScaledDataRecord[];
105
109
  });
106
110
 
107
111
  $effect(() => {
@@ -114,11 +118,11 @@
114
118
  max(
115
119
  positionedTicks.map((tick, i) => {
116
120
  if (
117
- resolveProp(options.anchor, tick.value, outsideTextAnchor) !==
121
+ resolveProp(options.anchor, tick, outsideTextAnchor) !==
118
122
  outsideTextAnchor
119
123
  )
120
124
  return 0;
121
- if (tick.hidden || !testFilter(tick.value, options)) return 0;
125
+ if (tick.hidden || !testFilter(tick, options)) return 0;
122
126
  if (tickTextElements[i])
123
127
  return tickTextElements[i].getBoundingClientRect().height;
124
128
  return 0;
@@ -148,8 +152,9 @@
148
152
 
149
153
  <g class="axis-x">
150
154
  {#each positionedTicks as tick, t (t)}
151
- {#if testFilter(tick.value, options) && !tick.hidden}
152
- {@const tickClass_ = resolveProp(tickClass, tick.value)}
155
+ {#if testFilter(tick, options) && !tick.hidden}
156
+ {@const tickClass_ = resolveProp(tickClass, tick)}
157
+ {@const tickFontSize_ = +resolveProp(tickFontSize, tick, 10)}
153
158
  <g
154
159
  class="tick {tickClass_ || ''}"
155
160
  transform="translate({tick.x + tick.dx}, {tickY + tick.dy})"
@@ -157,7 +162,7 @@
157
162
  {#if tickSize}
158
163
  {@const [tickLineStyle, tickLineClass] = resolveStyles(
159
164
  plot,
160
- tick,
165
+ { datum: tick },
161
166
  options,
162
167
  'stroke',
163
168
  { x: true },
@@ -174,15 +179,15 @@
174
179
  {@const prevTextLines = t && positionedTicks[t - 1].text}
175
180
 
176
181
  {@const moveDown =
177
- (tickSize + tickPadding + (tickRotate !== 0 ? tickFontSize * 0.35 : 0)) *
182
+ (tickSize + tickPadding + (tickRotate !== 0 ? tickFontSize_ * 0.35 : 0)) *
178
183
  (anchor === 'bottom' ? 1 : -1)}
179
184
  {@const [textStyle, textClass] = resolveStyles(
180
185
  plot,
181
- tick,
186
+ { datum: tick },
182
187
  {
183
188
  fontVariant: isQuantitative ? 'tabular-nums' : 'normal',
184
189
  ...options,
185
- fontSize: tickFontSize,
190
+ fontSize: tickFontSize_,
186
191
  stroke: null
187
192
  },
188
193
  'fill',
@@ -6,10 +6,14 @@
6
6
  import type {
7
7
  AutoMarginStores,
8
8
  ConstantAccessor,
9
+ DataRecord,
9
10
  PlotState,
10
11
  RawValue,
12
+ ScaledDataRecord,
11
13
  ScaleType
12
14
  } from '../../types/index.js';
15
+ import { RAW_VALUE } from '../../transforms/recordize';
16
+ import { INDEX } from '../../constants';
13
17
 
14
18
  type BaseAxisYProps = {
15
19
  scaleFn: (d: RawValue) => number;
@@ -61,13 +65,14 @@
61
65
 
62
66
  const positionedTicks = $derived.by(() => {
63
67
  let tickObjects = ticks.map((tick, i) => {
68
+ const datum = { [RAW_VALUE]: tick, [INDEX]: i };
64
69
  return {
65
- value: tick,
70
+ ...datum,
66
71
  hidden: false,
67
- dx: +resolveProp(options.dx, tick, 0),
68
- dy: +resolveProp(options.dy, tick, 0),
72
+ dx: +resolveProp(options.dx, datum, 0),
73
+ dy: +resolveProp(options.dy, datum, 0),
69
74
  y: scaleFn(tick) + (scaleType === 'band' ? scaleFn.bandwidth() * 0.5 : 0),
70
- text: tickFormat(tick),
75
+ text: tickFormat(tick, i),
71
76
  element: null as SVGTextElement | null
72
77
  };
73
78
  });
@@ -107,11 +112,11 @@
107
112
  max(
108
113
  positionedTicks.map((tick, i) => {
109
114
  if (
110
- resolveProp(options.textAnchor, tick.value, outsideTextAnchor) !==
115
+ resolveProp(options.textAnchor, tick, outsideTextAnchor) !==
111
116
  outsideTextAnchor
112
117
  )
113
118
  return 0;
114
- if (tick.hidden || !testFilter(tick.value, options)) return 0;
119
+ if (tick.hidden || !testFilter(tick, options)) return 0;
115
120
  if (tickTexts[i]) return tickTexts[i].getBoundingClientRect().width;
116
121
  return 0;
117
122
  }) as number[]
@@ -150,11 +155,11 @@
150
155
 
151
156
  <g class="axis-y">
152
157
  {#each positionedTicks as tick, t (t)}
153
- {#if testFilter(tick.value, options) && !tick.hidden}
154
- {@const tickClass_ = resolveProp(tickClass, tick.value)}
158
+ {#if testFilter(tick, options) && !tick.hidden}
159
+ {@const tickClass_ = resolveProp(tickClass, tick)}
155
160
  {@const [textStyle, textClass] = resolveStyles(
156
161
  plot,
157
- tick,
162
+ { datum: tick },
158
163
  {
159
164
  fontVariant: isQuantitative ? 'tabular-nums' : 'normal',
160
165
  ...options,
@@ -173,7 +178,7 @@
173
178
  {#if tickSize}
174
179
  {@const [tickLineStyle, tickLineClass] = resolveStyles(
175
180
  plot,
176
- tick,
181
+ { datum: tick },
177
182
  options,
178
183
  'stroke',
179
184
  { y: true },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelteplot",
3
- "version": "0.4.2-pr-194.0",
3
+ "version": "0.4.2-pr-194.2",
4
4
  "license": "ISC",
5
5
  "author": {
6
6
  "name": "Gregor Aisch",