@pixerate/editor-svelte 0.47.0 → 0.48.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.
@@ -10,6 +10,9 @@
10
10
  import {
11
11
  CHART_COLOR_SCHEMES,
12
12
  CHART_CURVES,
13
+ CHART_ERROR_BAR_DIRECTIONS,
14
+ CHART_ERROR_BAR_LABELS,
15
+ CHART_ERROR_BAR_TYPES,
13
16
  CHART_LABEL_POSITIONS,
14
17
  CHART_LAYOUT_PRESETS,
15
18
  CHART_LEGEND_POSITIONS,
@@ -22,14 +25,21 @@
22
25
  CHART_TYPES,
23
26
  checkChartColors,
24
27
  chartColorInputValue,
28
+ chartErrorBarsOfType,
25
29
  chartFamily,
26
30
  chartSeriesColor,
27
31
  chartSeriesType,
28
32
  chartSupportsTrendlines,
29
33
  chartTrendlineName,
34
+ defaultChartErrorBarValue,
35
+ formatChartAmountList,
30
36
  isCartesianChart,
37
+ parseChartAmountList,
31
38
  type ChartAxis,
32
39
  type ChartController,
40
+ type ChartErrorBars,
41
+ type ChartErrorBarType,
42
+ type ChartSeries,
33
43
  type ChartLabelPosition,
34
44
  type ChartMarker,
35
45
  type ChartNumberFormat,
@@ -66,6 +76,8 @@
66
76
  const currentScheme = $derived(CHART_COLOR_SCHEMES.find((c) => c.palette.join() === spec.palette.join())?.id ?? '');
67
77
  const seriesIndex = $derived(selectedSeries ? spec.series.findIndex((s) => s.id === selectedSeries.id) : -1);
68
78
  const horizontal = $derived(spec.orientation === 'horizontal');
79
+ // Log and reversed axes and error bars are drawn by the bar / line / area / scatter layouts.
80
+ const scales = $derived(family === 'cartesian' || family === 'xy');
69
81
  const cap = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
70
82
  const stackingLabels: Record<string, string> = { none: 'None', stacked: 'Stacked', percent: '100%' };
71
83
 
@@ -85,6 +97,17 @@
85
97
  else delete format.code;
86
98
  return setAxis(axis, { format }).ok;
87
99
  }
100
+ const setBars = (series: ChartSeries, which: 'errorBars' | 'xErrorBars', next: ChartErrorBars | null) => controller.updateSeries(series.id, { [which]: next });
101
+ const patchBars = (series: ChartSeries, which: 'errorBars' | 'xErrorBars', patch: Partial<ChartErrorBars>) => {
102
+ const bars = series[which];
103
+ return bars ? setBars(series, which, { ...bars, ...patch }).ok : false;
104
+ };
105
+ function commitMinus(series: ChartSeries, which: 'errorBars' | 'xErrorBars', text: string) {
106
+ const next = { ...series[which]! };
107
+ if (text.trim()) next.minus = parseChartAmountList(text) as ChartErrorBars['minus'];
108
+ else delete next.minus;
109
+ return setBars(series, which, next).ok;
110
+ }
88
111
  const side = (axis: 'x' | 'y' | 'y2') => (axis === 'x' ? (horizontal ? 'left' : 'bottom') : axis === 'y2' ? (horizontal ? 'top' : 'right') : horizontal ? 'bottom' : 'left');
89
112
  </script>
90
113
 
@@ -95,6 +118,67 @@
95
118
  </label>
96
119
  {/snippet}
97
120
 
121
+ {#snippet errorBarFields(series: ChartSeries, which: 'errorBars' | 'xErrorBars')}
122
+ {@const bars = series[which]}
123
+ {@const key = `series.${which}`}
124
+ {@const id = `${idPrefix}-${which}`}
125
+ <div class="space-y-1.5" data-section={which === 'errorBars' ? 'error-bars' : 'x-error-bars'}>
126
+ <div class="flex items-center gap-2">
127
+ <label for="{id}-type" class="{chartLabelClass} w-20 shrink-0">{which === 'errorBars' ? 'Error bars' : 'X error bars'}</label>
128
+ <select
129
+ id="{id}-type"
130
+ class={chartInputClass}
131
+ value={bars?.type ?? ''}
132
+ data-option="{key}.type"
133
+ onchange={(e) => setBars(series, which, chartErrorBarsOfType(e.currentTarget.value as ChartErrorBarType | '', bars, which === 'xErrorBars' ? (series.x ?? []) : series.values))}
134
+ >
135
+ <option value="">None</option>
136
+ {#each CHART_ERROR_BAR_TYPES as t (t)}
137
+ <option value={t}>{CHART_ERROR_BAR_LABELS[t]}</option>
138
+ {/each}
139
+ </select>
140
+ </div>
141
+ {#if bars && (bars.type === 'fixed' || bars.type === 'percent' || bars.type === 'stddev')}
142
+ <div class="flex items-center gap-2">
143
+ <label for="{id}-value" class="{chartLabelClass} w-20 shrink-0">{bars.type === 'percent' ? 'Percent' : bars.type === 'stddev' ? 'Deviations' : 'Amount'}</label>
144
+ <div class="min-w-0 flex-1">
145
+ <ChartCommitInput id="{id}-value" value={String(bars.value ?? defaultChartErrorBarValue(bars.type))} inputmode="decimal" data-option="{key}.value" oncommit={(text) => patchBars(series, which, { value: text.trim() === '' ? undefined : Number(text) })} />
146
+ </div>
147
+ </div>
148
+ {/if}
149
+ {#if bars?.type === 'custom'}
150
+ <div class="flex items-center gap-2">
151
+ <label for="{id}-plus" class="{chartLabelClass} w-20 shrink-0">Plus</label>
152
+ <div class="min-w-0 flex-1">
153
+ <ChartCommitInput id="{id}-plus" value={formatChartAmountList(bars.plus)} placeholder="1, 2, -, 0.5" data-option="{key}.plus" oncommit={(text) => patchBars(series, which, { plus: parseChartAmountList(text) as ChartErrorBars['plus'] })} />
154
+ </div>
155
+ </div>
156
+ <div class="flex items-center gap-2">
157
+ <label for="{id}-minus" class="{chartLabelClass} w-20 shrink-0">Minus</label>
158
+ <div class="min-w-0 flex-1">
159
+ <ChartCommitInput id="{id}-minus" value={formatChartAmountList(bars.minus)} placeholder="Same as plus" data-option="{key}.minus" oncommit={(text) => commitMinus(series, which, text)} />
160
+ </div>
161
+ </div>
162
+ {/if}
163
+ {#if bars}
164
+ <div class="flex items-center gap-2">
165
+ <select
166
+ class="{chartInputClass} flex-1"
167
+ aria-label="Error bar direction"
168
+ value={bars.direction ?? 'both'}
169
+ data-option="{key}.direction"
170
+ onchange={(e) => patchBars(series, which, { direction: e.currentTarget.value as ChartErrorBars['direction'] })}
171
+ >
172
+ {#each CHART_ERROR_BAR_DIRECTIONS as d (d)}
173
+ <option value={d}>{d === 'both' ? 'Both ways' : d === 'plus' ? 'Plus only' : 'Minus only'}</option>
174
+ {/each}
175
+ </select>
176
+ {@render toggle('Caps', `${key}.cap`, bars.cap !== false, (cap) => patchBars(series, which, { cap }))}
177
+ </div>
178
+ {/if}
179
+ </div>
180
+ {/snippet}
181
+
98
182
  {#snippet axisSection(axis: 'x' | 'y' | 'y2', value: ChartAxis, numeric: boolean)}
99
183
  {@const key = keyOf(axis)}
100
184
  {@const valueAxis = axis !== 'x' || numeric}
@@ -117,14 +201,30 @@
117
201
  {#if axis === 'x' && !numeric}
118
202
  {@render toggle('Dates', 'xAxis.kind', value.kind === 'date', (dates) => setAxis('x', { kind: dates ? 'date' : undefined } as Partial<ChartAxis>))}
119
203
  {/if}
204
+ {#if scales}
205
+ {@render toggle('Reverse', `${key}.reverse`, !!value.reverse, (reverse) => setAxis(axis, { reverse }))}
206
+ {/if}
207
+ {#if scales && valueAxis}
208
+ {@render toggle('Log scale', `${key}.scale`, value.scale === 'log', (log) => setAxis(axis, { scale: log ? 'log' : 'linear' }))}
209
+ {/if}
120
210
  </div>
121
- {#if valueAxis}
211
+ {#if scales && valueAxis && value.scale === 'log'}
212
+ <div class="flex items-center gap-2">
213
+ <label for="{idPrefix}-{axis}-log-base" class="{chartLabelClass} w-20 shrink-0">Log base</label>
214
+ <div class="min-w-0 flex-1">
215
+ <ChartCommitInput id="{idPrefix}-{axis}-log-base" value={String(value.logBase ?? 10)} inputmode="decimal" data-option="{key}.logBase" oncommit={(text) => setAxis(axis, { logBase: text.trim() === '' ? undefined : Number(text) }).ok} />
216
+ </div>
217
+ </div>
218
+ {/if}
219
+ {#if valueAxis && value.scale !== 'log'}
122
220
  <div class="flex items-center gap-2">
123
221
  <label for="{idPrefix}-{axis}-step" class="{chartLabelClass} w-20 shrink-0">Step</label>
124
222
  <div class="min-w-0 flex-1">
125
223
  <ChartCommitInput id="{idPrefix}-{axis}-step" value={value.step === null ? '' : String(value.step)} placeholder="Auto" inputmode="decimal" data-option="{key}.step" oncommit={commitNumber(axis, 'step')} />
126
224
  </div>
127
225
  </div>
226
+ {/if}
227
+ {#if valueAxis}
128
228
  <div class="flex items-center gap-2">
129
229
  <span class="{chartLabelClass} w-20 shrink-0">Min / max</span>
130
230
  <div class="flex min-w-0 flex-1 gap-1">
@@ -428,6 +528,12 @@
428
528
  </select>
429
529
  </div>
430
530
  {/if}
531
+ {#if scales}
532
+ {@render errorBarFields(series, 'errorBars')}
533
+ {/if}
534
+ {#if family === 'xy'}
535
+ {@render errorBarFields(series, 'xErrorBars')}
536
+ {/if}
431
537
  {#if chartSupportsTrendlines(spec.type, spec.stacking)}
432
538
  <div class="space-y-1" data-section="trendlines">
433
539
  {#each series.trendlines ?? [] as t, i (i)}
@@ -1 +1 @@
1
- {"version":3,"file":"ChartInspector.svelte.d.ts","sourceRoot":"","sources":["../../src/chart/ChartInspector.svelte.ts"],"names":[],"mappings":"AAOE,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;AAG7G,OAAO,EAsBH,KAAK,eAAe,EAMrB,MAAM,wBAAwB,CAAC;AAMhC,UAAU,KAAK;IACb,UAAU,EAAE,eAAe,CAAC;IAC5B,qEAAqE;IACrE,QAAQ,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAC5C,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAoWH,QAAA,MAAM,cAAc,2CAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"ChartInspector.svelte.d.ts","sourceRoot":"","sources":["../../src/chart/ChartInspector.svelte.ts"],"names":[],"mappings":"AAOE,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;AAG7G,OAAO,EA6BH,KAAK,eAAe,EASrB,MAAM,wBAAwB,CAAC;AAMhC,UAAU,KAAK;IACb,UAAU,EAAE,eAAe,CAAC;IAC5B,qEAAqE;IACrE,QAAQ,CAAC,EAAE,SAAS,qBAAqB,EAAE,CAAC;IAC5C,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAwbH,QAAA,MAAM,cAAc,2CAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-svelte",
3
- "version": "0.47.0",
3
+ "version": "0.48.0",
4
4
  "description": "Svelte bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -115,7 +115,7 @@
115
115
  "@tiptap/extension-bubble-menu": "^2.11.5",
116
116
  "@tiptap/extension-placeholder": "^2.11.5",
117
117
  "@tiptap/starter-kit": "^2.11.5",
118
- "@pixerate/editor": "0.52.0"
118
+ "@pixerate/editor": "0.53.0"
119
119
  },
120
120
  "peerDependencies": {
121
121
  "@dagrejs/dagre": "^1.1.4",