tinybase 8.5.0-beta.2 → 8.5.0-beta.3

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.
@@ -1,14 +1,14 @@
1
1
  /**
2
- * The ui-react-dom-charts module of the TinyBase project provides components
3
- * to make it easy to create web-based reactive charts with Store and Queries
2
+ * The ui-react-dom-charts module of the TinyBase project provides components to
3
+ * make it easy to create web-based reactive charts with Store and Queries
4
4
  * objects.
5
5
  *
6
6
  * The components in this module use the react-dom module and so are not
7
7
  * appropriate for environments like React Native (although those in the
8
8
  * lower-level ui-react module are).
9
9
  *
10
- * For a full list of SVG class names that can be styled with CSS, see the
11
- * Using Charts guide.
10
+ * For a full list of SVG class names that can be styled with CSS, see the Using
11
+ * Charts guide.
12
12
  * @packageDocumentation
13
13
  * @module ui-react-dom-charts
14
14
  * @since v8.5.0
@@ -27,8 +27,8 @@ import type {Id} from '../../common/with-schemas/index.d.ts';
27
27
  import type {OptionalSchemas} from '../../store/with-schemas/index.d.ts';
28
28
 
29
29
  /**
30
- * The ChartProps type describes the props that are used to configure the
31
- * chart element that renders a chart.
30
+ * The ChartProps type describes the props that are used to configure the chart
31
+ * element that renders a chart.
32
32
  * @category Configuration
33
33
  * @since v8.5.0
34
34
  */
@@ -44,12 +44,12 @@ export type ChartProps = {
44
44
  };
45
45
 
46
46
  /**
47
- * The ChartTableSourceProps type describes the props that bind a chart to a
47
+ * The TableSourceProps type describes the props that bind a chart to a
48
48
  * Table in a Store.
49
49
  * @category Configuration
50
50
  * @since v8.5.0
51
51
  */
52
- export type ChartTableSourceProps<
52
+ export type TableSourceProps<
53
53
  Schemas extends OptionalSchemas,
54
54
  TableIds extends TableIdFromSchema<Schemas[0]> = TableIdFromSchema<
55
55
  Schemas[0]
@@ -87,12 +87,12 @@ export type ChartTableSourceProps<
87
87
  : never;
88
88
 
89
89
  /**
90
- * The ChartQuerySourceProps type describes the props that bind a chart to a
90
+ * The QuerySourceProps type describes the props that bind a chart to a
91
91
  * Query in a Queries object.
92
92
  * @category Configuration
93
93
  * @since v8.5.0
94
94
  */
95
- export type ChartQuerySourceProps<Schemas extends OptionalSchemas> = {
95
+ export type QuerySourceProps<Schemas extends OptionalSchemas> = {
96
96
  /**
97
97
  * The Id of the query in the Queries object to chart.
98
98
  * @category Prop
@@ -121,13 +121,14 @@ export type ChartQuerySourceProps<Schemas extends OptionalSchemas> = {
121
121
  };
122
122
 
123
123
  /**
124
- * The ChartBindingProps type describes the props that bind a LineChart or
125
- * BarChart component to Cell values in TinyBase data. An x Cell value can be a
126
- * finite number, string, or boolean. A y Cell value must be a finite number.
124
+ * The BindingProps type describes the props that bind a LineChart
125
+ * component or BarChart component to Cell values in TinyBase data. An x Cell
126
+ * value can be a finite number, string, or boolean. A y Cell value must be a
127
+ * finite number.
127
128
  * @category Configuration
128
129
  * @since v8.5.0
129
130
  */
130
- export type ChartBindingProps<
131
+ export type BindingProps<
131
132
  XCellId extends Id = Id,
132
133
  YCellId extends Id = Id,
133
134
  SortCellId extends Id = XCellId,
@@ -176,13 +177,13 @@ export type ChartBindingProps<
176
177
  };
177
178
 
178
179
  /**
179
- * The ChartSeriesProps type describes the props that bind a chart series to
180
- * Cell values in TinyBase data. An x Cell value can be a finite number,
181
- * string, or boolean. A y Cell value must be a finite number.
180
+ * The SeriesProps type describes the props that bind a chart series to Cell
181
+ * values in TinyBase data. An x Cell value can be a finite number, string, or
182
+ * boolean. A y Cell value must be a finite number.
182
183
  * @category Configuration
183
184
  * @since v8.5.0
184
185
  */
185
- export type ChartSeriesProps<CellId extends Id = Id> = {
186
+ export type SeriesProps<CellId extends Id = Id> = {
186
187
  /**
187
188
  * An optional string that will be added to the class attribute of the series'
188
189
  * SVG group element.
@@ -240,6 +241,136 @@ export type ChartSeriesProps<CellId extends Id = Id> = {
240
241
  readonly limit?: number;
241
242
  };
242
243
 
244
+ /**
245
+ * The XAxisProps type describes the props that configure the x axis of a
246
+ * CartesianChart component.
247
+ *
248
+ * The x axis is inferred by default. Use an XAxis component child when you want
249
+ * to override its title, numeric bounds, tick values, tick count, tick labels,
250
+ * or SVG class name.
251
+ * @category Configuration
252
+ * @since v8.5.0
253
+ */
254
+ export type XAxisProps = {
255
+ /**
256
+ * An optional string that will be added to the class attribute of the x-axis
257
+ * SVG group element.
258
+ * @category Prop
259
+ * @since v8.5.0
260
+ */
261
+ readonly className?: string;
262
+ /**
263
+ * An optional title to use for the x axis, defaulting to the x Cell Id, or to
264
+ * a combined title when multiple series use different x Cell Ids.
265
+ * @category Prop
266
+ * @since v8.5.0
267
+ */
268
+ readonly title?: string;
269
+ /**
270
+ * An optional minimum x-axis bound for continuous numeric x values.
271
+ *
272
+ * This prop is ignored when the x axis is categorical.
273
+ * @category Prop
274
+ * @since v8.5.0
275
+ */
276
+ readonly min?: number;
277
+ /**
278
+ * An optional maximum x-axis bound for continuous numeric x values.
279
+ *
280
+ * This prop is ignored when the x axis is categorical.
281
+ * @category Prop
282
+ * @since v8.5.0
283
+ */
284
+ readonly max?: number;
285
+ /**
286
+ * Optional numeric tick values to use for a continuous x axis.
287
+ *
288
+ * This prop is ignored when the x axis is categorical.
289
+ * @category Prop
290
+ * @since v8.5.0
291
+ */
292
+ readonly ticks?: readonly number[];
293
+ /**
294
+ * An optional preferred number of ticks to render on a continuous x axis.
295
+ *
296
+ * The actual number of ticks may vary so that labels remain readable.
297
+ * @category Prop
298
+ * @since v8.5.0
299
+ */
300
+ readonly tickCount?: number;
301
+ /**
302
+ * An optional function for formatting x-axis tick labels.
303
+ *
304
+ * It receives the original tick value, which can be a finite number, string,
305
+ * or boolean.
306
+ * @category Prop
307
+ * @since v8.5.0
308
+ */
309
+ readonly tickFormatter?: (tick: boolean | number | string) => string;
310
+ };
311
+
312
+ /**
313
+ * The YAxisProps type describes the props that configure the y axis of a
314
+ * CartesianChart component.
315
+ *
316
+ * The y axis is inferred by default. Use a YAxis component child when you want
317
+ * to override its title, numeric bounds, tick values, tick count, tick labels,
318
+ * or SVG class name.
319
+ * @category Configuration
320
+ * @since v8.5.0
321
+ */
322
+ export type YAxisProps = {
323
+ /**
324
+ * An optional string that will be added to the class attribute of the y-axis
325
+ * SVG group element.
326
+ * @category Prop
327
+ * @since v8.5.0
328
+ */
329
+ readonly className?: string;
330
+ /**
331
+ * An optional title to use for the y axis, defaulting to the y Cell Id, y
332
+ * series label, or a combined title when multiple series use different y Cell
333
+ * Ids or labels.
334
+ * @category Prop
335
+ * @since v8.5.0
336
+ */
337
+ readonly title?: string;
338
+ /**
339
+ * An optional minimum y-axis bound.
340
+ * @category Prop
341
+ * @since v8.5.0
342
+ */
343
+ readonly min?: number;
344
+ /**
345
+ * An optional maximum y-axis bound.
346
+ * @category Prop
347
+ * @since v8.5.0
348
+ */
349
+ readonly max?: number;
350
+ /**
351
+ * Optional numeric tick values to use for the y axis.
352
+ * @category Prop
353
+ * @since v8.5.0
354
+ */
355
+ readonly ticks?: readonly number[];
356
+ /**
357
+ * An optional preferred number of ticks to render on the y axis.
358
+ *
359
+ * The actual number of ticks may vary so that labels remain readable.
360
+ * @category Prop
361
+ * @since v8.5.0
362
+ */
363
+ readonly tickCount?: number;
364
+ /**
365
+ * An optional function for formatting y-axis tick labels.
366
+ *
367
+ * It receives the numeric tick value.
368
+ * @category Prop
369
+ * @since v8.5.0
370
+ */
371
+ readonly tickFormatter?: (tick: number) => string;
372
+ };
373
+
243
374
  type NumericCellIdFromSchema<
244
375
  Schemas extends OptionalSchemas,
245
376
  TableId extends TableIdFromSchema<Schemas[0]>,
@@ -252,15 +383,15 @@ type NumericCellIdFromSchema<
252
383
  : never;
253
384
  }[CellIdFromSchema<Schemas[0], TableId>];
254
385
 
255
- type ChartTableBindingProps<
386
+ type TableBindingProps<
256
387
  Schemas extends OptionalSchemas,
257
388
  TableIds extends TableIdFromSchema<Schemas[0]> = TableIdFromSchema<
258
389
  Schemas[0]
259
390
  >,
260
391
  > = TableIds extends infer TableId
261
392
  ? TableId extends TableIdFromSchema<Schemas[0]>
262
- ? ChartTableSourceProps<Schemas, TableId> &
263
- ChartBindingProps<
393
+ ? TableSourceProps<Schemas, TableId> &
394
+ BindingProps<
264
395
  CellIdFromSchema<Schemas[0], TableId>,
265
396
  NumericCellIdFromSchema<Schemas, TableId>,
266
397
  CellIdFromSchema<Schemas[0], TableId>
@@ -277,23 +408,31 @@ type ChartTableBindingProps<
277
408
  export type WithSchemas<Schemas extends OptionalSchemas> = {
278
409
  /**
279
410
  * The CartesianChart component renders a chart frame and provides TinyBase
280
- * source and layout context to child LineSeries and BarSeries components.
411
+ * source and layout context to LineSeries component and BarSeries component
412
+ * children.
281
413
  *
282
414
  * This has schema-based typing. The following is a simplified representation:
283
415
  *
284
416
  * ```ts override
285
417
  * CartesianChart(
286
- * props: (ChartTableSourceProps | ChartQuerySourceProps) &
418
+ * props: (TableSourceProps | QuerySourceProps) &
287
419
  * ChartProps & {readonly children?: ReactNode},
288
420
  * ): ComponentReturnType;
289
421
  * ```
290
422
  *
291
- * The series children declare their own xCellId and yCellId bindings.
423
+ * See the Composing Charts (React) demo for this component in action:
424
+ *
425
+ * ![CartesianChart component example](https://beta.tinybase.org/shots/composing-charts-react-demo.png
426
+ * "CartesianChart component example")
427
+ *
428
+ * The series children declare their own xCellId and yCellId bindings. The
429
+ * optional XAxis component and YAxis component children can be used to
430
+ * configure axis titles, bounds, ticks, and tick formatting.
292
431
  * @category Store components
293
432
  * @since v8.5.0
294
433
  * @example
295
- * This example creates a Store and renders two LineSeries components in a
296
- * CartesianChart.
434
+ * This example creates a Store and renders two LineSeries component children
435
+ * in a CartesianChart component.
297
436
  *
298
437
  * ```jsx
299
438
  * import React from 'react';
@@ -329,57 +468,102 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
329
468
  */
330
469
  CartesianChart: {
331
470
  (
332
- props: ChartTableSourceProps<Schemas> &
471
+ props: TableSourceProps<Schemas> &
333
472
  ChartProps & {readonly children?: ReactNode},
334
473
  ): ComponentReturnType;
335
474
  (
336
- props: ChartQuerySourceProps<Schemas> &
475
+ props: QuerySourceProps<Schemas> &
337
476
  ChartProps & {readonly children?: ReactNode},
338
477
  ): ComponentReturnType;
339
478
  };
340
479
 
341
480
  /**
342
- * The LineSeries component renders a line series in a CartesianChart
343
- * component. If every x value in every series is a finite number, the x axis is
344
- * rendered as a continuous numeric scale. If any x value is a string or
345
- * boolean, the x axis is rendered categorically. When sortCellId is omitted,
346
- * rows are sorted by xCellId.
481
+ * The XAxis component configures the x axis of a CartesianChart component.
482
+ *
483
+ * It is a configuration child rather than a separately rendered SVG element:
484
+ * include zero or one XAxis component in a CartesianChart component's children.
485
+ * If omitted, the x axis is inferred from the chart's series.
486
+ *
487
+ * See the Axis Overrides (React) demo for this component in action:
488
+ *
489
+ * ![XAxis component example](https://beta.tinybase.org/shots/axis-overrides-react-demo.png
490
+ * "XAxis component example")
491
+ * @category Store components
492
+ * @since v8.5.0
493
+ */
494
+ XAxis: (props: XAxisProps) => ComponentReturnType;
495
+
496
+ /**
497
+ * The YAxis component configures the y axis of a CartesianChart component.
498
+ *
499
+ * It is a configuration child rather than a separately rendered SVG element:
500
+ * include zero or one YAxis component in a CartesianChart component's children.
501
+ * If omitted, the y axis is inferred from the chart's series.
502
+ *
503
+ * See the Axis Overrides (React) demo for this component in action:
504
+ *
505
+ * ![YAxis component example](https://beta.tinybase.org/shots/axis-overrides-react-demo.png
506
+ * "YAxis component example")
507
+ * @category Store components
508
+ * @since v8.5.0
509
+ */
510
+ YAxis: (props: YAxisProps) => ComponentReturnType;
511
+
512
+ /**
513
+ * The LineSeries component renders a line series in a CartesianChart component.
514
+ * If every x value in every series is a finite number, the x axis is rendered
515
+ * as a continuous numeric scale. If any x value is a string or boolean, the x
516
+ * axis is rendered categorically. When sortCellId is omitted, rows are sorted
517
+ * by xCellId.
518
+ *
519
+ * See the Composing Charts (React) demo for this component in action:
520
+ *
521
+ * ![LineSeries component example](https://beta.tinybase.org/shots/composing-charts-react-demo.png
522
+ * "LineSeries component example")
347
523
  * @category Store components
348
524
  * @since v8.5.0
349
525
  */
350
- LineSeries: (props: ChartSeriesProps) => ComponentReturnType;
526
+ LineSeries: (props: SeriesProps) => ComponentReturnType;
351
527
 
352
528
  /**
353
529
  * The BarSeries component renders a bar series in a CartesianChart component.
354
530
  * Its x values are always rendered categorically, even when they are finite
355
531
  * numbers. Boolean category labels are rendered as `true` and `false`.
532
+ *
533
+ * See the Composing Charts (React) demo for this component in action:
534
+ *
535
+ * ![BarSeries component example](https://beta.tinybase.org/shots/composing-charts-react-demo.png
536
+ * "BarSeries component example")
356
537
  * @category Store components
357
538
  * @since v8.5.0
358
539
  */
359
- BarSeries: (props: ChartSeriesProps) => ComponentReturnType;
540
+ BarSeries: (props: SeriesProps) => ComponentReturnType;
360
541
 
361
542
  /**
362
543
  * The LineChart component renders a line chart from TinyBase data. If every x
363
544
  * value is a finite number, the x axis is rendered as a continuous numeric
364
545
  * scale. If any x value is a string or boolean, the x axis is rendered
365
546
  * categorically. When sortCellId is omitted, rows are sorted by xCellId.
366
- * @category Store components
367
- * @since v8.5.0
368
- * @example
369
- * This example creates a Provider context into which a default Store is
370
- * provided. The LineChart component then renders an SVG chart from Cells in the
371
- * `pets` Table.
372
547
  *
373
548
  * This has schema-based typing. The following is a simplified representation:
374
549
  *
375
550
  * ```ts override
376
551
  * LineChart(
377
- * props: (ChartTableSourceProps | ChartQuerySourceProps) &
378
- * ChartBindingProps &
379
- * ChartProps,
552
+ * props: (TableSourceProps | QuerySourceProps) & BindingProps & ChartProps,
380
553
  * ): ComponentReturnType;
381
554
  * ```
382
555
  *
556
+ * See the <LineChart /> (React) demo for this component in action:
557
+ *
558
+ * ![LineChart component example](https://beta.tinybase.org/shots/basic-chart-react-demo.png "LineChart
559
+ * component example")
560
+ * @category Store components
561
+ * @since v8.5.0
562
+ * @example
563
+ * This example creates a Provider context into which a default Store is
564
+ * provided. The LineChart component then renders an SVG chart from Cells in the
565
+ * `pets` Table.
566
+ *
383
567
  * ```jsx
384
568
  * import React from 'react';
385
569
  * import {createRoot} from 'react-dom/client';
@@ -412,31 +596,34 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
412
596
  */
413
597
  LineChart: (
414
598
  props:
415
- | (ChartTableBindingProps<Schemas> & ChartProps)
416
- | (ChartQuerySourceProps<Schemas> & ChartBindingProps & ChartProps),
599
+ | (TableBindingProps<Schemas> & ChartProps)
600
+ | (QuerySourceProps<Schemas> & BindingProps & ChartProps),
417
601
  ) => ComponentReturnType;
418
602
 
419
603
  /**
420
604
  * The BarChart component renders a bar chart from TinyBase data. Its x values
421
605
  * are always rendered categorically, even when they are finite numbers. Boolean
422
606
  * category labels are rendered as `true` and `false`.
423
- * @category Store components
424
- * @since v8.5.0
425
- * @example
426
- * This example creates a Queries object and provides it through Provider
427
- * context. The BarChart component then renders an SVG chart from Cells in the
428
- * `bySpecies` query.
429
607
  *
430
608
  * This has schema-based typing. The following is a simplified representation:
431
609
  *
432
610
  * ```ts override
433
611
  * BarChart(
434
- * props: (ChartTableSourceProps | ChartQuerySourceProps) &
435
- * ChartBindingProps &
436
- * ChartProps,
612
+ * props: (TableSourceProps | QuerySourceProps) & BindingProps & ChartProps,
437
613
  * ): ComponentReturnType;
438
614
  * ```
439
615
  *
616
+ * See the Sorting And Types (React) demo for this component in action:
617
+ *
618
+ * ![BarChart component example](https://beta.tinybase.org/shots/sorting-and-types-react-demo.png
619
+ * "BarChart component example")
620
+ * @category Store components
621
+ * @since v8.5.0
622
+ * @example
623
+ * This example creates a Queries object and provides it through Provider
624
+ * context. The BarChart component then renders an SVG chart from Cells in the
625
+ * `bySpecies` query.
626
+ *
440
627
  * ```jsx
441
628
  * import React from 'react';
442
629
  * import {createRoot} from 'react-dom/client';
@@ -470,7 +657,7 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
470
657
  */
471
658
  BarChart: (
472
659
  props:
473
- | (ChartTableBindingProps<Schemas> & ChartProps)
474
- | (ChartQuerySourceProps<Schemas> & ChartBindingProps & ChartProps),
660
+ | (TableBindingProps<Schemas> & ChartProps)
661
+ | (QuerySourceProps<Schemas> & BindingProps & ChartProps),
475
662
  ) => ComponentReturnType;
476
663
  };
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import n from"react";const l=e=>typeof e,s=l(""),i=l(0),o="Result",a="SortedRowIds",u="Cell",c=Math,d=e=>(t,r,n)=>e(t)?n?.():r(t),x=globalThis,y=String,m=c.max,p=c.min,h=c.ceil,f=c.floor,b=c.pow,I=c.round,g=c.abs,S=c.log10,C=1/0,M=Number.EPSILON,k=isFinite,N=Number.isInteger,$=e=>null==e,T=e=>void 0===e,v=d($),F=d(T),q=e=>l(e)==s,O=e=>l(e)==i,V=e=>Array.isArray(e),w=e=>e.length,{Children:z,Fragment:P,PureComponent:E,createContext:R,isValidElement:X,useCallback:A,useContext:L,useEffect:B,useLayoutEffect:W,useMemo:Q,useRef:G,useState:j,useSyncExternalStore:H}=n;var _=(e=>(e[e.None=0]="None",e[e.Query=1]="Query",e[e.Table=2]="Table",e))(_||{});const D="_tinybaseChartSeries",J=R(null),Z=()=>{const e=L(J);if(null==e)throw Error("Series components must be used inside a CartesianChart");return e},K=(e,t)=>se(Array(e).fill(0),(e,r)=>t(r)),U=(e,t)=>e.includes(t),Y=(e,t)=>e.indexOf(t),ee=(e,t)=>e.every(t),te=(e,t)=>w(e)===w(t)&&ee(e,(e,r)=>t[r]===e),re=(e,t)=>V(e)&&V(t)?te(e,t):e===t,ne=(e,t)=>e.forEach(t),le=(e,t="")=>e.join(t),se=(e,t)=>e.map(t),ie=e=>0==w(e),oe=(e,t)=>e.filter(t),ae=(e,...t)=>e.push(...t),ue=e=>e?.size??0,ce=[1,5,2,2.5,4,3],de=(e,t,r,n,l,s)=>{let i=[e,t],o=-2;const a=t-e;for(let u=1;u<C;u++)for(const c of ce){const d=1-Y(ce,c)/m(w(ce)-1,1)-u+1;if(.25*d+.2+.5+.05<o)return i;for(let x=2;x<C;x++){const y=x>=r?2-(x-1)/(r-1):1;if(.25*d+.2+.5*y+.05<o)break;for(let k=h(S(a/(x+1)/u/c));k<C;k++){const a=u*c*b(10,k);if(.25*d+.2*(a*(x-1)<=t-e?1:1-b((a*(x-1)-(t-e))/2,2)/b(.1*(t-e),2))+.5*y+.05<o)break;const S=f(t/a)*u-(x-1)*u,C=h(e/a)*u;S<=C&&ne(K(C-S+1,e=>S+e),d=>{const y=d*(a/u),h=y+a*(x-1),S=(x-1)/(h-y),C=(r-1)/(m(h,t)-p(e,y)),k=l/(x-1),N=.25*(1-Y(ce,c)/m(w(ce)-1,1)-u+(g(y/a-I(y/a))<100*M&&y<=0&&h>=0?1:0))+.2*(1-(b(t-h,2)+b(e-y,2))/(2*b(.1*(t-e),2)))+.5*(2-m(S/C,C/S))+.05*(k<1.2*n?-1/0:p(k,1))+(s&&(g(a-I(a))>100*M||g(y-I(y))>100*M)?-1:0);N>o&&(i=K(f((h-y)/a+.5)+1,e=>I(1e6*(y+e*a))/1e6),o=N)})}}}return i},xe=(e,t)=>oe(se(e,t),e=>!T(e)),ye=(e,t,r)=>{const n=Me(t),l=ke(r);return T(n)||T(l)?void 0:[e,n,l]},me=(e,t,[r,n,l,s],[i,o],a,u,c)=>{const d="line"==e&&ie(oe(t,([,e])=>!O(e))),x=d?[r,n]:[0,0],y=[l??0,s??0],m=new Map;return ne(null==a||ie(a)?se(t,([,e])=>e):a,e=>{m.has(e)||m.set(e,ue(m))}),se(t,([t,r,n])=>[t,r,n,pe(r,d,x,m,i,e),he(n,y,o),u,c])},pe=(e,t,[r,n],l,s,i)=>t?fe(e,r,n,s):"bar"==i?s*((l.get(e)??0)+.5)/ue(l):fe(l.get(e)??0,0,ue(l)-1,s),he=(e,[t,r],n)=>n-fe(e,t,r,n),fe=(e,t,r,n)=>t==r?n/2:Ce(n*(e-t)/(r-t)),be=(e,t,r,n,l)=>{const[s,i,o,a]=((e,t)=>{if(ie(t))return[];const[r,n]=ge(t,e);if(ie(oe(t,([,e])=>!O(e)))){const[e,l]=Se(se(t,([,e])=>e));return[e,l,r,n]}return[t[0]?.[1],t[w(t)-1]?.[1],r,n]})(e,t),u=[],c="line"==e&&ie(oe(t,([,e])=>!O(e)));return ne(t,([,e])=>{U(u,e)||ae(u,e)}),{continuousX:c,xCellId:r,xMin:s,xMax:i,yMin:o,yMax:a,yCellId:n,yLabel:l,xValues:u}},Ie=e=>{const t=[],r=[],n=[],l=[],s=[];let i,o,a=!0;return ne(e,e=>{a&&=e.continuousX,ne(e.xValues,e=>{U(t,e)||ae(t,e)}),O(e.xMin)&&O(e.xMax)?(r.push(e.xMin),n.push(e.xMax)):(i??=e.xMin,o=e.xMax??o),T(e.yMin)||l.push(e.yMin),T(e.yMax)||s.push(e.yMax)}),{bounds:[ie(r)?i:p(...r),ie(n)?o:m(...n),ie(l)?void 0:p(...l),ie(s)?void 0:m(...s)],continuousX:!ie(e)&&a,xValues:t}},ge=(e,t="bar")=>Se([..."bar"==t?[0]:[],...se(e,([,,e])=>e)]),Se=e=>{const t=p(...e);return t==C?[0,0]:[t,m(...e)]},Ce=e=>I(1e6*e)/1e6,Me=e=>O(e)?k(e)?e:void 0:q(e)||!0===e||!1===e?e:void 0,ke=e=>O(e)&&k(e)?e:void 0,Ne="currentColor",$e=({points:t,plotFrame:r,barGap:n,barSeriesCount:l,barSeriesIndex:s,setTooltipPoint:i,yMin:o=0,yMax:a=0})=>{const[u,c,d,x]=r,y=x-fe(0,o,a,x),h=w(t),f=ie(t)?0:d/h,b=m(l,1),I=m(s,0),S=m(f-n,0),C=m((S-n*(b-1))/b,0);return se(t,t=>{const[r,,,l,s]=t,o=p(s,y);return e("rect",{className:"bar",height:g(y-s),onPointerEnter:()=>i(t),onPointerLeave:()=>i(void 0),width:C,x:u+l-S/2+(C+n)*I,y:c+o},r)})},Te=Object,ve=e=>Te.getPrototypeOf(e),Fe=Te.entries,qe=e=>!$(e)&&v(ve(e),e=>e==Te.prototype||$(ve(e)),()=>!0),Oe=Te.keys,Ve=e=>Te.values(e),we=(e,t,r=(e,t)=>e===t)=>{const n=Fe(e);return w(n)===w(Oe(t))&&ee(n,([e,n])=>qe(n)?!!qe(t[e])&&we(t[e],n,r):r(n,t[e]))},ze=JSON.stringify,Pe="tinybase_uirc",Ee=x[Pe]?x[Pe]:x[Pe]=R([]),Re=(e,t)=>{const r=((e,t)=>{const r=L(Ee);return T(e)?r[2*t]:q(e)?((e,t)=>F(e,e=>e[t]))(r[2*t+1],e):e})(e,t);return T(e)||q(e)?r:e},Xe=[],Ae=[{},[],[Xe,void 0,Xe],{},void 0,void 0,!1,0],Le=(e,t)=>e===t||(qe(e)||V(e))&&ze(e)===ze(t),Be=[(e,t)=>we(e,t,Le),te,([e,t,r],[n,l,s])=>t===l&&te(e,n)&&te(r,s),(e,t)=>we(e,t,re),re,Le],We=(e,t)=>e===t,Qe=(e,t,...r)=>{const n=e?.["add"+t+"Listener"]?.(...r);return()=>e?.delListener?.(n)},Ge=(e,t,r,n=Xe)=>{const l=G(Ae[r]),s=A(()=>{const s=t?.["get"+e]?.(...n)??Ae[r];return(Be[r]??We)(s,l.current)?l.current:l.current=s},[t,r,e,...n]),i=A(r=>Qe(t,""+e,...n,r),[t,r,e,...n]);return H(i,s,s)},je=(e,t,r,n=Xe,l=Xe,...s)=>W(()=>Qe(t,e,...l,r,...s),[t,e,...l,...n,...s]),He=e=>Re(e,0),_e=(e,t,r,n,l,s,i)=>je(u,He(i),n,l,[e,t,r],s),De=e=>Re(e,4),Je=(e,t,r,n,l,s)=>je(o+u,De(s),n,l,[e,t,r]),Ze=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>{const[,i]=j(),u=Z(),{getSeriesId:c,queries:d,queriesOrQueriesId:x,queryId:y,releaseSeriesId:m,sourceType:p,store:h,storeOrStoreId:f,tableId:b}=u,[I]=j(c),g=A(()=>i([]),[i]),S=((e,t,r,n,l,s)=>((e,t,r,n,l,s)=>Ge(a,He(s),1,[e,t,r,n,l]))(...qe(e)?[e.tableId,e.cellId,e.descending??!1,e.offset??0,e.limit,t]:[e,t,r,n,l,s]))(b??"",n??l,e,r,t,f),C=((e,t,r,n=0,l,s)=>Ge(o+a,De(s),1,[e,t,r,n,l]))(y??"",n??l,e,r,t,x),M=p==_.Table?S:C,k=null==s?[]:xe(M,e=>ye(e,Ue(p,h,d,b,y,e,l),Ue(p,h,d,b,y,e,s)));return _e(p==_.Table?b??null:null,null,l,g,[g],!1,f),_e(p==_.Table?b??null:null,null,s??null,g,[g],!1,f),Je(p==_.Query?y??null:null,null,l,g,[g],x),Je(p==_.Query?y??null:null,null,s??null,g,[g],x),W(()=>()=>m(I),[m,I]),[I,k]},Ke=(e,t)=>null==t?e:`${e} ${t}`,Ue=(e,t,r,n,l,s,i)=>e==_.Table?t?.getCell(n,s,i):r?.getResultCell(l,s,i),Ye=t=>{const{barSeriesCount:r,bounds:n,getBarSeriesIndex:l,layout:[,,[,,s]],plotFrame:i,plotSize:o,registerBarSeries:a,releaseBarSeries:u,setSeriesSummary:c,setTooltipPoint:d,xValues:x}=Z(),{className:y,label:m,xCellId:p,yCellId:h}=t,[f,b]=Ze(t),I=l(f),[,,g,S]=n,C=me("bar",b,n,o,x,p,m??h);return W(()=>{c(f,be("bar",b,p,h,m))}),W(()=>(a(f),()=>u(f)),[a,u,f]),e("g",{className:Ke("bar-series",y),fill:Ne,children:e($e,{barGap:s,barSeriesCount:r,barSeriesIndex:I,plotFrame:i,points:C,setTooltipPoint:d,yMax:S,yMin:g})})};Ye[D]=!0;const et=/^\d+$/,tt=[1e3,1e3],rt=[.5,.5,.25,3.5,4,1,1],nt=([e,t],[,,,r,n,l,s])=>{const i=l+m(p(n,e/2-2*l),0),o=l+s/2,a=l+s/2,u=m(t-o-m(p(r,t/2-o-l),0)-l,0);return[i,o,m(e-i-a,0),u]},lt=e=>se(rt,t=>t*e),st=e=>{const t=parseFloat(e?.fontSize??"");return lt(k(t)?t:12)},it=({width:e,height:t})=>[I(e)||tt[0],I(t)||tt[1]],ot=({points:r,xTicks:n,xMin:l,xMax:s,xTitle:i,plotFrame:o,tickSize:a,tickGap:u,axisHeight:c,fontSize:d})=>{const[x,p,h,f]=o,b=m(c-a-u-2*d,0);return t("g",{className:"x",dominantBaseline:"hanging",textAnchor:"middle",children:[e("path",{className:"line",d:`M${x},${p+f}h${h}`,fill:"none",stroke:Ne,strokeOpacity:.5,strokeWidth:1}),e("g",{className:"ticks",children:!ie(n)&&O(l)&&O(s)?se(n,t=>{const r=fe(t,l,s,h);return e("text",{x:x+r,y:p+f+a+u,children:t},t)}):se(r,([t,r,,n])=>e("text",{x:x+n,y:p+f+a+u,children:y(r)},t))}),e("text",{className:"title",x:x+h/2,y:p+f+a+u+d+b,children:i})]})},at=({yTicks:r,yMin:n,yMax:l,yTitle:s,plotFrame:i,tickSize:o,tickGap:a,axisWidth:u})=>{const[c,d,,x]=i;return $(n)||$(l)?null:t("g",{className:"y",children:[e("path",{className:"line",d:`M${c},${d}v${x}`,fill:"none",stroke:Ne,strokeOpacity:.5,strokeWidth:1}),e("g",{className:"ticks",dominantBaseline:"middle",textAnchor:"end",children:se(r,t=>{const r=x-fe(t,n,l,x);return e("text",{x:c-o-a,y:d+r,children:t},t)})}),e("text",{className:"title",dominantBaseline:"text-before-edge",textAnchor:"middle",transform:`translate(${c-u} ${i[1]+i[3]/2}) rotate(-90)`,children:s})]})},ut=({points:r,xTicks:n,yTicks:l,bounds:[s,i,o,a],titles:[u,c],xAxisHeight:d,yAxisWidth:x,fontSize:y,...m})=>t("g",{className:"axes",fill:Ne,fillOpacity:.75,children:[e(at,{...m,yTicks:l,yMin:o,yMax:a,yTitle:c,axisWidth:x}),e(ot,{...m,points:r,xTicks:n,xMin:s,xMax:i,xTitle:u,axisHeight:d,fontSize:y})]}),ct=({points:r,xTicks:n,yTicks:l,bounds:[s,i,o,a],plotFrame:u,tickSize:c})=>{const[d,x,y,m]=u;return t("g",{className:"grid",stroke:Ne,strokeOpacity:.75,strokeWidth:.5,children:[$(o)||$(a)?null:e("path",{className:"y",d:le(se(oe(l,e=>0!=fe(e,o,a,m)),e=>`M${d-c},${x+m-fe(e,o,a,m)}h${y+c}`)," ")}),!ie(n)&&O(s)&&O(i)?e("path",{className:"x",d:le(se(oe(n,e=>0!=fe(e,s,i,y)),e=>`M${d+fe(e,s,i,y)},${x}v${m+c}`)," ")}):e("path",{className:"x",d:le(se(oe(r,([,,,e])=>0!=e),([,,,e])=>`M${d+e},${x}v${m+c}`)," ")})]})},dt="#fff",xt=({point:n,width:l,height:s,plotFrame:i,titles:[o,a]})=>{if($(n))return null;const[,u,c,d,x,h,f]=n,[b,I]=i,g=d+12+160>l?d-12-160:d+12,S=m(p(x-12-60,s-60),0);return t(r,{children:[e("path",{className:"tooltip-lines",pointerEvents:"none",stroke:Ne,strokeOpacity:.25,strokeWidth:1,d:`M${b+d},${I}v${s}M${b},${I+x}h${l}`}),t("g",{className:"tooltip",transform:`translate(${b+g} ${I+S})`,fontFamily:"sans-serif",fontWeight:600,pointerEvents:"none",children:[e("rect",{fill:"#111827",fillOpacity:.9,width:160,height:60,rx:6}),t("text",{fill:dt,x:12,y:22,children:[h??o,": ",y(u)]}),t("text",{fill:dt,x:12,y:46,children:[f??a,": ",c]})]})]})},yt={bounds:[],continuousX:!1,xValues:[]},mt=({children:r,className:n,initialSummary:l,queries:s,queryId:i,store:o,tableId:a})=>{const u=(()=>{const e=G(null),t=G([tt,lt(12)]),[r,n]=j([tt,lt(12)]);return W(()=>{const r=e.current;if(null===r)return;const l=new ResizeObserver(([e])=>(({contentRect:e})=>{const l=r.ownerDocument.defaultView?.getComputedStyle(r),s=[it(e),st(l)];(([e,t],[r,n])=>te(e,r)&&te(t,n))(t.current,s)||(t.current=s,n(s))})(e));return l.observe(r),()=>l.disconnect()},[]),[e,...r]})(),[c,d,x]=u,[y,h,,f,b,,I]=x,g=nt(d,x),S=(([,e,t])=>{const[,,r,n]=nt(e,t);return[r,n]})(u),M=(([,,e])=>e[6])(u),k=He(o),$=De(s),v=null==a?null==i?_.None:_.Query:_.Table,F=null==l?{}:{0:l},q=null==l?yt:Ie(Ve(F)),V=Ct(F,"xCellId"),z=Ct(F,"yCellId"),P=G(F),E=G(q.bounds),R=G(q),X=G(V),L=G(z),B=G((()=>{const e=[];let t=0;return[r=>(r?e.shift():null)??""+t++,t=>{et.test(t)&&w(e)<1e3&&ae(e,t)}]})()),[H,D]=j(q),[Z,K]=j(V),[ee,re]=j(z),ne=G([]),[le,se]=j([]),[ue,ce]=j(),xe=H.xValues,ye=H.bounds,pe=H.continuousX||ie(le)?"line":"bar",he=((e,[t,r],[n],l)=>"line"==e&&O(t)&&O(r)&&t!=r?de(t,r,10,l,n,N(t)&&N(r)):[])(pe,ye,S,M),fe=(([,,e,t],[,r],n)=>T(e)||T(t)?[]:e==t?[e]:de(e,t,10,n,r,N(e)&&N(t)))(ye,S,M),be=(([e,t,r,n],l,s)=>[ie(l)?e:p(e,l[0]),ie(l)?t:m(t,l[w(l)-1]),ie(s)?r:p(r??C,s[0]),ie(s)?n:m(n??-1/0,s[w(s)-1])])(ye,he,fe),ge=me(pe,xe.map((e,t)=>[""+t,e,0]),be,S,xe),Se=A(e=>{const t=Ie(Ve(e)),r=t.bounds;pt(E.current,r)&&te(R.current.xValues,t.xValues)||(E.current=r,R.current=t,D(t))},[]),Ce=A(e=>{const t=Ct(e,"xCellId"),r=Ct(e,"yCellId");X.current!=t&&(X.current=t,K(t)),L.current!=r&&(L.current=r,re(r))},[]),Me=A(e=>{const t=E.current,r=[bt(t[0],e.xMin),It(t[1],e.xMax),gt(t[2],e.yMin),St(t[3],e.yMax)];pt(t,r)||(E.current=r,R.current={bounds:r,continuousX:R.current.continuousX,xValues:R.current.xValues},D(R.current))},[]),ke=A((e,t)=>{const r=P.current,n=r[e];if(null==t){if(null==n)return;return delete r[e],Ce(r),void Se(r)}r[e]=t,Ce(r),(null==n?ft(t.xValues,R.current.xValues)||t.continuousX!=R.current.continuousX:ht(n,E.current)||n.continuousX!=t.continuousX||!te(n.xValues,t.xValues))?Se(r):Me(t)},[Me,Se,Ce]),[Ne,$e]=B.current,Te=A(()=>Ne(1),[Ne]),ve=A(e=>{ke(e,void 0),$e(e)},[$e,ke]),Fe=A(e=>{if(!U(ne.current,e)){const t=[...ne.current];ae(t,e),ne.current=t,se(t)}},[]),qe=A(e=>{if(U(ne.current,e)){const t=oe(ne.current,t=>t!=e);ne.current=t,se(t)}},[]),Oe=A(e=>Y(ne.current,e),[]),we=Q(()=>({bounds:be,barSeriesCount:w(le),domainState:H,getBarSeriesIndex:Oe,getSeriesId:Te,layout:u,plotFrame:g,plotSize:S,queries:$,queriesOrQueriesId:s,queryId:i,registerBarSeries:Fe,releaseBarSeries:qe,releaseSeriesId:ve,setSeriesSummary:ke,setTooltipPoint:ce,sourceType:v,store:k,storeOrStoreId:o,tableId:a,xTicks:he,xValues:xe,yTicks:fe}),[le,H,Oe,Te,u,g,S,s,$,i,Fe,qe,ve,ke,v,o,k,a,be,he,xe,fe]);return e(J.Provider,{value:we,children:t("svg",{className:n,preserveAspectRatio:"none",ref:c,viewBox:`0 0 ${d[0]} ${d[1]}`,children:[e(ct,{bounds:be,points:ge,plotFrame:g,tickSize:y,xTicks:he,yTicks:fe}),e(ut,{bounds:be,fontSize:I,points:ge,plotFrame:g,tickGap:h,tickSize:y,titles:[Z,ee],xAxisHeight:f,xTicks:he,yAxisWidth:b,yTicks:fe}),e("g",{className:"plot",children:Mt(r)}),e(xt,{height:S[1],point:ue,plotFrame:g,titles:[Z,ee],width:S[0]})]})})},pt=(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3],ht=({xMin:e,xMax:t,yMin:r,yMax:n},[l,s,i,o])=>e===l||t===s||r===i||n===o,ft=(e,t)=>{let r=!1;return ne(e,e=>{U(t,e)||(r=!0)}),r},bt=(e,t)=>O(e)&&O(t)?p(e,t):e??t,It=(e,t)=>O(e)&&O(t)?m(e,t):e??t,gt=(e,t)=>null==e||null==t?e??t:p(e,t),St=(e,t)=>null==e||null==t?e??t:m(e,t),Ct=(e,t)=>{const r=[];return ne(Ve(e),e=>{const n="yCellId"==t?e.yLabel??e.yCellId:e.xCellId;null==n||U(r,n)||ae(r,n)}),ie(r)?"":r.join(" & ")},Mt=e=>{const t=[];return z.forEach(e,e=>{var r;X(e)&&(e.type===P?ne(Mt(e.props.children),e=>ae(t,e)):"function"==typeof(r=e.type)&&!0===r[D]&&ae(t,e))}),t},kt=(e,{descending:t,limit:r,offset:n,queries:l,queryId:s,sortCellId:i,store:o,tableId:a,xCellId:u,yCellId:c})=>{const d=He(o),x=De(l);return Q(()=>{const l=null==a?xe(x?.getResultSortedRowIds(s??"",i??u,t,n,r)??[],e=>ye(e,x?.getResultCell(s??"",e,u),x?.getResultCell(s??"",e,c))):xe(d?.getSortedRowIds(a,i??u,t,n,r)??[],e=>ye(e,d?.getCell(a,e,u),d?.getCell(a,e,c)));return be(e,l,u,c)},[t,e,r,n,x,s,i,d,a,u,c])},Nt=t=>{const r=kt("bar",t);return e(mt,{...$t(t),initialSummary:r,children:e(Ye,{...Tt(t)})})},$t=e=>null==e.tableId?{className:e.className,queries:e.queries,queryId:e.queryId}:{className:e.className,store:e.store,tableId:e.tableId},Tt=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s}),vt=({plotFrame:n,points:l,setTooltipPoint:s})=>{const[i,o,,a]=n;return t(r,{children:[e("path",{className:"area",d:qt(l,i,o,a),fill:Ne,fillOpacity:.25,stroke:"none"}),e("path",{className:"line",d:Ft(l,i,o),fill:"none",stroke:Ne,strokeOpacity:.75,strokeWidth:2}),e("g",{className:"points",fill:Ne,children:se(l,t=>{const[r,,,n,l]=t;return e("circle",{cx:i+n,cy:o+l,onPointerEnter:()=>s(t),onPointerLeave:()=>s(void 0),r:5},r)})})]})},Ft=(e,t,r)=>le(se(e,([,,,e,n],l)=>`${0==l?"M":"L"}${t+e},${r+n}`)," "),qt=(e,t,r,n)=>ie(e)?"":`${Ft(e,t,r)} L${t+e[w(e)-1][3]},${r+n} L${t+e[0][3]},${r+n} Z`,Ot=t=>{const{barSeriesCount:r,bounds:n,domainState:l,plotFrame:s,plotSize:i,setSeriesSummary:o,setTooltipPoint:a,xValues:u}=Z(),{className:c,label:d,xCellId:x,yCellId:y}=t,[m,p]=Ze(t),h=me(l.continuousX||0==r?"line":"bar",p,n,i,u,x,d??y);return W(()=>{o(m,be("line",p,x,y,d))}),e("g",{className:Ke("line-series",c),children:e(vt,{plotFrame:s,points:h,setTooltipPoint:a})})};Ot[D]=!0;const Vt=t=>{const r=kt("line",t);return e(mt,{...wt(t),initialSummary:r,children:e(Ot,{...zt(t)})})},wt=e=>null==e.tableId?{className:e.className,queries:e.queries,queryId:e.queryId}:{className:e.className,store:e.store,tableId:e.tableId},zt=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s});export{Nt as BarChart,Ye as BarSeries,mt as CartesianChart,Vt as LineChart,Ot as LineSeries};
1
+ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import n from"react";const l=e=>typeof e,s=l(""),i=l(0),o="Result",a="SortedRowIds",u="Cell",c=Math,d=e=>(t,r,n)=>e(t)?n?.():r(t),x=globalThis,m=String,y=c.max,p=c.min,h=c.ceil,f=c.floor,b=c.pow,I=c.round,g=c.abs,k=c.log10,C=1/0,S=Number.EPSILON,N=isFinite,M=Number.isInteger,$=e=>null==e,v=e=>void 0===e,T=d($),F=d(v),q=e=>l(e)==s,O=e=>l(e)==i,V=e=>Array.isArray(e),A=e=>e.length,{Children:w,Fragment:z,PureComponent:P,createContext:X,isValidElement:E,useCallback:R,useContext:L,useEffect:B,useLayoutEffect:W,useMemo:Q,useRef:G,useState:j,useSyncExternalStore:H}=n;var _=(e=>(e[e.None=0]="None",e[e.Query=1]="Query",e[e.Table=2]="Table",e))(_||{});const D="_tinybaseChartSeries",J="_tinybaseChartXAxis",Y="_tinybaseChartYAxis",Z=X(null),K=()=>{const e=L(Z);if(null==e)throw Error("Series components must be used inside a CartesianChart");return e},U=(e,t)=>oe(Array(e).fill(0),(e,r)=>t(r)),ee=(e,t)=>e.includes(t),te=(e,t)=>e.indexOf(t),re=(e,t)=>e.every(t),ne=(e,t)=>A(e)===A(t)&&re(e,(e,r)=>t[r]===e),le=(e,t)=>V(e)&&V(t)?ne(e,t):e===t,se=(e,t)=>e.forEach(t),ie=(e,t="")=>e.join(t),oe=(e,t)=>e.map(t),ae=e=>0==A(e),ue=(e,t)=>e.filter(t),ce=(e,...t)=>e.push(...t),de=e=>e?.size??0,xe=[1,5,2,2.5,4,3],me=(e,t,r,n,l,s)=>{let i=[e,t],o=-2;const a=t-e;for(let u=1;u<C;u++)for(const c of xe){const d=1-te(xe,c)/y(A(xe)-1,1)-u+1;if(.25*d+.2+.5+.05<o)return i;for(let x=2;x<C;x++){const m=x>=r?2-(x-1)/(r-1):1;if(.25*d+.2+.5*m+.05<o)break;for(let N=h(k(a/(x+1)/u/c));N<C;N++){const a=u*c*b(10,N);if(.25*d+.2*(a*(x-1)<=t-e?1:1-b((a*(x-1)-(t-e))/2,2)/b(.1*(t-e),2))+.5*m+.05<o)break;const k=f(t/a)*u-(x-1)*u,C=h(e/a)*u;k<=C&&se(U(C-k+1,e=>k+e),d=>{const m=d*(a/u),h=m+a*(x-1),k=(x-1)/(h-m),C=(r-1)/(y(h,t)-p(e,m)),N=l/(x-1),M=.25*(1-te(xe,c)/y(A(xe)-1,1)-u+(g(m/a-I(m/a))<100*S&&m<=0&&h>=0?1:0))+.2*(1-(b(t-h,2)+b(e-m,2))/(2*b(.1*(t-e),2)))+.5*(2-y(k/C,C/k))+.05*(N<1.2*n?-1/0:p(N,1))+(s&&(g(a-I(a))>100*S||g(m-I(m))>100*S)?-1:0);M>o&&(i=U(f((h-m)/a+.5)+1,e=>I(1e6*(m+e*a))/1e6),o=M)})}}}return i},ye=(e,t)=>ue(oe(e,t),e=>!v(e)),pe=(e,t,r)=>{const n=ve(t),l=Te(r);return v(n)||v(l)?void 0:[e,n,l]},he=(e,t,[r,n,l,s],[i,o],a,u,c)=>{const d="line"==e&&ae(ue(t,([,e])=>!O(e))),x=d?[r,n]:[0,0],m=[l??0,s??0],y=new Map;return se(null==a||ae(a)?oe(t,([,e])=>e):a,e=>{y.has(e)||y.set(e,de(y))}),oe(t,([t,r,n])=>[t,r,n,fe(r,d,x,y,i,e),be(n,m,o),u,c])},fe=(e,t,[r,n],l,s,i)=>t?Ie(e,r,n,s):"bar"==i?s*((l.get(e)??0)+.5)/de(l):Ie(l.get(e)??0,0,de(l)-1,s),be=(e,[t,r],n)=>n-Ie(e,t,r,n),Ie=(e,t,r,n)=>t==r?n/2:$e(n*(e-t)/(r-t)),ge=(e,t,r,n,l)=>{const[s,i,o,a]=((e,t)=>{if(ae(t))return[];const[r,n]=Ce(t,e);if(ae(ue(t,([,e])=>!O(e)))){const[e,l]=Se(oe(t,([,e])=>e));return[e,l,r,n]}return[t[0]?.[1],t[A(t)-1]?.[1],r,n]})(e,t),u=[],c="line"==e&&ae(ue(t,([,e])=>!O(e)));return se(t,([,e])=>{ee(u,e)||ce(u,e)}),{continuousX:c,xCellId:r,xMin:s,xMax:i,yMin:o,yMax:a,yCellId:n,yLabel:l,xValues:u}},ke=e=>{const t=[],r=[],n=[],l=[],s=[];let i,o,a=!0;return se(e,e=>{a&&=e.continuousX,se(e.xValues,e=>{ee(t,e)||ce(t,e)}),O(e.xMin)&&O(e.xMax)?(r.push(e.xMin),n.push(e.xMax)):(i??=e.xMin,o=e.xMax??o),v(e.yMin)||l.push(e.yMin),v(e.yMax)||s.push(e.yMax)}),{bounds:[ae(r)?i:p(...r),ae(n)?o:y(...n),ae(l)?void 0:p(...l),ae(s)?void 0:y(...s)],continuousX:!ae(e)&&a,xValues:t}},Ce=(e,t="bar")=>Se([..."bar"==t?[0]:[],...oe(e,([,,e])=>e)]),Se=e=>{const t=p(...e);return t==C?[0,0]:[t,y(...e)]},Ne=(e,t)=>O(e)?y(e,t):t,Me=(e=10)=>N(e)?y(I(e),1):10,$e=e=>I(1e6*e)/1e6,ve=e=>O(e)?N(e)?e:void 0:q(e)||!0===e||!1===e?e:void 0,Te=e=>O(e)&&N(e)?e:void 0,Fe="currentColor",qe=({points:t,plotFrame:r,barGap:n,barSeriesCount:l,barSeriesIndex:s,setTooltipPoint:i,yMin:o=0,yMax:a=0})=>{const[u,c,d,x]=r,m=x-Ie(0,o,a,x),h=A(t),f=ae(t)?0:d/h,b=y(l,1),I=y(s,0),k=y(f-n,0),C=y((k-n*(b-1))/b,0);return oe(t,t=>{const[r,,,l,s]=t,o=p(s,m);return e("rect",{className:"bar",height:g(m-s),onPointerEnter:()=>i(t),onPointerLeave:()=>i(void 0),width:C,x:u+l-k/2+(C+n)*I,y:c+o},r)})},Oe=Object,Ve=e=>Oe.getPrototypeOf(e),Ae=Oe.entries,we=e=>!$(e)&&T(Ve(e),e=>e==Oe.prototype||$(Ve(e)),()=>!0),ze=Oe.keys,Pe=e=>Oe.values(e),Xe=(e,t,r=(e,t)=>e===t)=>{const n=Ae(e);return A(n)===A(ze(t))&&re(n,([e,n])=>we(n)?!!we(t[e])&&Xe(t[e],n,r):r(n,t[e]))},Ee=JSON.stringify,Re="tinybase_uirc",Le=x[Re]?x[Re]:x[Re]=X([]),Be=(e,t)=>{const r=((e,t)=>{const r=L(Le);return v(e)?r[2*t]:q(e)?((e,t)=>F(e,e=>e[t]))(r[2*t+1],e):e})(e,t);return v(e)||q(e)?r:e},We=[],Qe=[{},[],[We,void 0,We],{},void 0,void 0,!1,0],Ge=(e,t)=>e===t||(we(e)||V(e))&&Ee(e)===Ee(t),je=[(e,t)=>Xe(e,t,Ge),ne,([e,t,r],[n,l,s])=>t===l&&ne(e,n)&&ne(r,s),(e,t)=>Xe(e,t,le),le,Ge],He=(e,t)=>e===t,_e=(e,t,...r)=>{const n=e?.["add"+t+"Listener"]?.(...r);return()=>e?.delListener?.(n)},De=(e,t,r,n=We)=>{const l=G(Qe[r]),s=R(()=>{const s=t?.["get"+e]?.(...n)??Qe[r];return(je[r]??He)(s,l.current)?l.current:l.current=s},[t,r,e,...n]),i=R(r=>_e(t,""+e,...n,r),[t,r,e,...n]);return H(i,s,s)},Je=(e,t,r,n=We,l=We,...s)=>W(()=>_e(t,e,...l,r,...s),[t,e,...l,...n,...s]),Ye=e=>Be(e,0),Ze=(e,t,r,n,l,s,i)=>Je(u,Ye(i),n,l,[e,t,r],s),Ke=e=>Be(e,4),Ue=(e,t,r,n,l,s)=>Je(o+u,Ke(s),n,l,[e,t,r]),et=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>{const[,i]=j(),u=K(),{getSeriesId:c,queries:d,queriesOrQueriesId:x,queryId:m,releaseSeriesId:y,sourceType:p,store:h,storeOrStoreId:f,tableId:b}=u,[I]=j(c),g=R(()=>i([]),[i]),k=((e,t,r,n,l,s)=>((e,t,r,n,l,s)=>De(a,Ye(s),1,[e,t,r,n,l]))(...we(e)?[e.tableId,e.cellId,e.descending??!1,e.offset??0,e.limit,t]:[e,t,r,n,l,s]))(b??"",n??l,e,r,t,f),C=((e,t,r,n=0,l,s)=>De(o+a,Ke(s),1,[e,t,r,n,l]))(m??"",n??l,e,r,t,x),S=p==_.Table?k:C,N=null==s?[]:ye(S,e=>pe(e,rt(p,h,d,b,m,e,l),rt(p,h,d,b,m,e,s)));return Ze(p==_.Table?b??null:null,null,l,g,[g],!1,f),Ze(p==_.Table?b??null:null,null,s??null,g,[g],!1,f),Ue(p==_.Query?m??null:null,null,l,g,[g],x),Ue(p==_.Query?m??null:null,null,s??null,g,[g],x),W(()=>()=>y(I),[y,I]),[I,N]},tt=(e,t)=>null==t?e:`${e} ${t}`,rt=(e,t,r,n,l,s,i)=>e==_.Table?t?.getCell(n,s,i):r?.getResultCell(l,s,i),nt=t=>{const{barSeriesCount:r,bounds:n,getBarSeriesIndex:l,layout:[,,[,,s]],plotFrame:i,plotSize:o,registerBarSeries:a,releaseBarSeries:u,setSeriesSummary:c,setTooltipPoint:d,xValues:x}=K(),{className:m,label:y,xCellId:p,yCellId:h}=t,[f,b]=et(t),I=l(f),[,,g,k]=n,C=he("bar",b,n,o,x,p,y??h);return W(()=>{c(f,ge("bar",b,p,h,y))}),W(()=>(a(f),()=>u(f)),[a,u,f]),e("g",{className:tt("bar-series",m),fill:Fe,children:e(qe,{barGap:s,barSeriesCount:r,barSeriesIndex:I,plotFrame:i,points:C,setTooltipPoint:d,yMax:k,yMin:g})})};nt[D]=!0;const lt=/^\d+$/,st=[1e3,1e3],it=[.5,.5,.25,3.5,4,1,1],ot=([e,t],[,,,r,n,l,s])=>{const i=l+y(p(n,e/2-2*l),0),o=l+s/2,a=l+s/2,u=y(t-o-y(p(r,t/2-o-l),0)-l,0);return[i,o,y(e-i-a,0),u]},at=e=>oe(it,t=>t*e),ut=e=>{const t=parseFloat(e?.fontSize??"");return at(N(t)?t:12)},ct=({width:e,height:t})=>[I(e)||st[0],I(t)||st[1]],dt=({className:r,points:n,tickFormatter:l,xTicks:s,xMin:i,xMax:o,xTitle:a,plotFrame:u,tickSize:c,tickGap:d,axisHeight:x,fontSize:m})=>{const[p,h,f,b]=u,I=y(x-c-d-2*m,0);return t("g",{className:xt("x",r),dominantBaseline:"hanging",textAnchor:"middle",children:[e("path",{className:"line",d:`M${p},${h+b}h${f}`,fill:"none",stroke:Fe,strokeOpacity:.5,strokeWidth:1}),e("g",{className:"ticks",children:!ae(s)&&O(i)&&O(o)?oe(s,t=>{const r=Ie(t,i,o,f);return e("text",{x:p+r,y:h+b+c+d,children:mt(t,l)},t)}):oe(n,([t,r,,n])=>e("text",{x:p+n,y:h+b+c+d,children:mt(r,l)},t))}),e("text",{className:"title",x:p+f/2,y:h+b+c+d+m+I,children:a})]})},xt=(e,t)=>null==t?e:`${e} ${t}`,mt=(e,t)=>t?.(e)??m(e),yt=({className:r,tickFormatter:n,yTicks:l,yMin:s,yMax:i,yTitle:o,plotFrame:a,tickSize:u,tickGap:c,axisWidth:d})=>{const[x,y,,p]=a;return $(s)||$(i)?null:t("g",{className:pt("y",r),children:[e("path",{className:"line",d:`M${x},${y}v${p}`,fill:"none",stroke:Fe,strokeOpacity:.5,strokeWidth:1}),e("g",{className:"ticks",dominantBaseline:"middle",textAnchor:"end",children:oe(l,t=>{const r=p-Ie(t,s,i,p);return e("text",{x:x-u-c,y:y+r,children:n?.(t)??m(t)},t)})}),e("text",{className:"title",dominantBaseline:"text-before-edge",textAnchor:"middle",transform:`translate(${x-d} ${a[1]+a[3]/2}) rotate(-90)`,children:o})]})},pt=(e,t)=>null==t?e:`${e} ${t}`,ht=({xAxis:r,yAxis:n,points:l,xTicks:s,yTicks:i,bounds:[o,a,u,c],titles:[d,x],xAxisHeight:m,yAxisWidth:y,fontSize:p,...h})=>t("g",{className:"axes",fill:Fe,fillOpacity:.75,children:[e(yt,{...h,className:n?.className,tickFormatter:n?.tickFormatter,yTicks:i,yMin:u,yMax:c,yTitle:x,axisWidth:y}),e(dt,{...h,className:r?.className,points:l,tickFormatter:r?.tickFormatter,xTicks:s,xMin:o,xMax:a,xTitle:d,axisHeight:m,fontSize:p})]}),ft=({points:r,xTicks:n,yTicks:l,bounds:[s,i,o,a],plotFrame:u,tickSize:c})=>{const[d,x,m,y]=u;return t("g",{className:"grid",stroke:Fe,strokeOpacity:.75,strokeWidth:.5,children:[$(o)||$(a)?null:e("path",{className:"y",d:ie(oe(ue(l,e=>0!=Ie(e,o,a,y)),e=>`M${d-c},${x+y-Ie(e,o,a,y)}h${m+c}`)," ")}),!ae(n)&&O(s)&&O(i)?e("path",{className:"x",d:ie(oe(ue(n,e=>0!=Ie(e,s,i,m)),e=>`M${d+Ie(e,s,i,m)},${x}v${y+c}`)," ")}):e("path",{className:"x",d:ie(oe(ue(r,([,,,e])=>0!=e),([,,,e])=>`M${d+e},${x}v${y+c}`)," ")})]})},bt="#fff",It=({point:n,width:l,height:s,plotFrame:i,titles:[o,a]})=>{if($(n))return null;const[,u,c,d,x,h,f]=n,[b,I]=i,g=d+12+160>l?d-12-160:d+12,k=y(p(x-12-60,s-60),0);return t(r,{children:[e("path",{className:"tooltip-lines",pointerEvents:"none",stroke:Fe,strokeOpacity:.25,strokeWidth:1,d:`M${b+d},${I}v${s}M${b},${I+x}h${l}`}),t("g",{className:"tooltip",transform:`translate(${b+g} ${I+k})`,fontFamily:"sans-serif",fontWeight:600,pointerEvents:"none",children:[e("rect",{fill:"#111827",fillOpacity:.9,width:160,height:60,rx:6}),t("text",{fill:bt,x:12,y:22,children:[h??o,": ",m(u)]}),t("text",{fill:bt,x:12,y:46,children:[f??a,": ",c]})]})]})},gt={bounds:[],continuousX:!1,xValues:[]},kt=({children:r,className:n,initialSummary:l,queries:s,queryId:i,store:o,tableId:a})=>{const u=(()=>{const e=G(null),t=G([st,at(12)]),[r,n]=j([st,at(12)]);return W(()=>{const r=e.current;if(null===r)return;const l=new ResizeObserver(([e])=>(({contentRect:e})=>{const l=r.ownerDocument.defaultView?.getComputedStyle(r),s=[ct(e),ut(l)];(([e,t],[r,n])=>ne(e,r)&&ne(t,n))(t.current,s)||(t.current=s,n(s))})(e));return l.observe(r),()=>l.disconnect()},[]),[e,...r]})(),[c,d,x]=u,[m,h,,f,b,,I]=x,g=ot(d,x),k=(([,e,t])=>{const[,,r,n]=ot(e,t);return[r,n]})(u),S=(([,,e])=>e[6])(u),N=Ye(o),$=Ke(s),T=null==a?null==i?_.None:_.Query:_.Table,F=null==l?{}:{0:l},q=null==l?gt:ke(Pe(F)),V=Ft(F,"xCellId"),w=Ft(F,"yCellId"),z=G(F),P=G(q.bounds),X=G(q),E=G(V),L=G(w),B=G((()=>{const e=[];let t=0;return[r=>(r?e.shift():null)??""+t++,t=>{lt.test(t)&&A(e)<1e3&&ce(e,t)}]})()),[H,D]=j(q),[J,Y]=j(V),[K,U]=j(w),re=G([]),[le,se]=j([]),[ie,oe]=j(),[de,xe,ye]=zt(r),pe=H.xValues,fe=H.continuousX||ae(pe)&&wt(xe),be=qt(H.bounds,fe,xe,ye),Ie=fe||ae(le)?"line":"bar",ge=fe&&null!=xe?.ticks?At(xe.ticks):((e,[t,r],[n],l,s)=>"line"==e&&O(t)&&O(r)&&t!=r?me(t,r,Me(s),l,n,M(t)&&M(r)):[])(Ie,be,k,S,xe?.tickCount),Ce=null==ye?.ticks?(([,,e,t],[,r],n,l)=>v(e)||v(t)?[]:e==t?[e]:me(e,t,Me(l),n,r,M(e)&&M(t)))(be,k,S,ye?.tickCount):At(ye.ticks),Se=(([e,t,r,n],l,s)=>{return[ae(l)?e:(i=e,o=l[0],O(i)?p(i,o):o),ae(l)?t:Ne(t,l[A(l)-1]),ae(s)?r:p(r??C,s[0]),ae(s)?n:y(n??-1/0,s[A(s)-1])];var i,o})(be,ge,Ce),$e=he(Ie,pe.map((e,t)=>[""+t,e,0]),Se,k,pe),ve=R(e=>{const t=ke(Pe(e)),r=t.bounds;Ct(P.current,r)&&ne(X.current.xValues,t.xValues)||(P.current=r,X.current=t,D(t))},[]),Te=R(e=>{const t=Ft(e,"xCellId"),r=Ft(e,"yCellId");E.current!=t&&(E.current=t,Y(t)),L.current!=r&&(L.current=r,U(r))},[]),Fe=R(e=>{const t=P.current,r=[Mt(t[0],e.xMin),$t(t[1],e.xMax),vt(t[2],e.yMin),Tt(t[3],e.yMax)];Ct(t,r)||(P.current=r,X.current={bounds:r,continuousX:X.current.continuousX,xValues:X.current.xValues},D(X.current))},[]),qe=R((e,t)=>{const r=z.current,n=r[e];if(null==t){if(null==n)return;return delete r[e],Te(r),void ve(r)}r[e]=t,Te(r),(null==n?Nt(t.xValues,X.current.xValues)||t.continuousX!=X.current.continuousX:St(n,P.current)||n.continuousX!=t.continuousX||!ne(n.xValues,t.xValues))?ve(r):Fe(t)},[Fe,ve,Te]),[Oe,Ve]=B.current,Ae=R(()=>Oe(1),[Oe]),we=R(e=>{qe(e,void 0),Ve(e)},[Ve,qe]),ze=R(e=>{if(!ee(re.current,e)){const t=[...re.current];ce(t,e),re.current=t,se(t)}},[]),Xe=R(e=>{if(ee(re.current,e)){const t=ue(re.current,t=>t!=e);re.current=t,se(t)}},[]),Ee=R(e=>te(re.current,e),[]),Re=Q(()=>({bounds:Se,barSeriesCount:A(le),domainState:H,getBarSeriesIndex:Ee,getSeriesId:Ae,layout:u,plotFrame:g,plotSize:k,queries:$,queriesOrQueriesId:s,queryId:i,registerBarSeries:ze,releaseBarSeries:Xe,releaseSeriesId:we,setSeriesSummary:qe,setTooltipPoint:oe,sourceType:T,store:N,storeOrStoreId:o,tableId:a,xTicks:ge,xValues:pe,yTicks:Ce}),[le,H,Ee,Ae,u,g,k,s,$,i,ze,Xe,we,qe,T,o,N,a,Se,ge,pe,Ce]);return e(Z.Provider,{value:Re,children:t("svg",{className:n,preserveAspectRatio:"none",ref:c,viewBox:`0 0 ${d[0]} ${d[1]}`,children:[e(ft,{bounds:Se,points:$e,plotFrame:g,tickSize:m,xTicks:ge,yTicks:Ce}),e(ht,{bounds:Se,fontSize:I,points:$e,plotFrame:g,tickGap:h,tickSize:m,titles:[xe?.title??J,ye?.title??K],xAxis:xe,xAxisHeight:f,xTicks:ge,yAxis:ye,yAxisWidth:b,yTicks:Ce}),e("g",{className:"plot",children:de}),e(It,{height:k[1],point:ie,plotFrame:g,titles:[xe?.title??J,ye?.title??K],width:k[0]})]})})},Ct=(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3],St=({xMin:e,xMax:t,yMin:r,yMax:n},[l,s,i,o])=>e===l||t===s||r===i||n===o,Nt=(e,t)=>{let r=!1;return se(e,e=>{ee(t,e)||(r=!0)}),r},Mt=(e,t)=>O(e)&&O(t)?p(e,t):e??t,$t=(e,t)=>O(e)&&O(t)?y(e,t):e??t,vt=(e,t)=>null==e||null==t?e??t:p(e,t),Tt=(e,t)=>null==e||null==t?e??t:y(e,t),Ft=(e,t)=>{const r=[];return se(Pe(e),e=>{const n="yCellId"==t?e.yLabel??e.yCellId:e.xCellId;null==n||ee(r,n)||ce(r,n)}),ae(r)?"":r.join(" & ")},qt=([e,t,r,n],l,s,i)=>[l?Ot(s?.min,e):e,l?Ot(s?.max,t):t,Vt(i?.min,r),Vt(i?.max,n)],Ot=(e,t)=>N(e)?e:t,Vt=(e,t)=>N(e)?e:t,At=e=>{return t=(e,t)=>e-t,ue([...e],N).sort(t);var t},wt=e=>N(e?.min)||N(e?.max)||null!=e?.ticks,zt=e=>{const t=[];let r,n;return w.forEach(e,e=>{if(E(e))if(e.type===z){const[l,s,i]=zt(e.props.children);se(l,e=>ce(t,e)),r??=s,n??=i}else"function"==typeof(l=e.type)&&!0===l[D]?ce(t,e):null==r&&(e=>"function"==typeof e&&!0===e[J])(e.type)?r=e.props:null==n&&(e=>"function"==typeof e&&!0===e[Y])(e.type)&&(n=e.props);var l}),[t,r,n]},Pt=(e,{descending:t,limit:r,offset:n,queries:l,queryId:s,sortCellId:i,store:o,tableId:a,xCellId:u,yCellId:c})=>{const d=Ye(o),x=Ke(l);return Q(()=>{const l=null==a?ye(x?.getResultSortedRowIds(s??"",i??u,t,n,r)??[],e=>pe(e,x?.getResultCell(s??"",e,u),x?.getResultCell(s??"",e,c))):ye(d?.getSortedRowIds(a,i??u,t,n,r)??[],e=>pe(e,d?.getCell(a,e,u),d?.getCell(a,e,c)));return ge(e,l,u,c)},[t,e,r,n,x,s,i,d,a,u,c])},Xt=t=>{const r=Pt("bar",t);return e(kt,{...Et(t),initialSummary:r,children:e(nt,{...Rt(t)})})},Et=e=>null==e.tableId?{className:e.className,queries:e.queries,queryId:e.queryId}:{className:e.className,store:e.store,tableId:e.tableId},Rt=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s}),Lt=({plotFrame:n,points:l,setTooltipPoint:s})=>{const[i,o,,a]=n;return t(r,{children:[e("path",{className:"area",d:Wt(l,i,o,a),fill:Fe,fillOpacity:.25,stroke:"none"}),e("path",{className:"line",d:Bt(l,i,o),fill:"none",stroke:Fe,strokeOpacity:.75,strokeWidth:2}),e("g",{className:"points",fill:Fe,children:oe(l,t=>{const[r,,,n,l]=t;return e("circle",{cx:i+n,cy:o+l,onPointerEnter:()=>s(t),onPointerLeave:()=>s(void 0),r:5},r)})})]})},Bt=(e,t,r)=>ie(oe(e,([,,,e,n],l)=>`${0==l?"M":"L"}${t+e},${r+n}`)," "),Wt=(e,t,r,n)=>ae(e)?"":`${Bt(e,t,r)} L${t+e[A(e)-1][3]},${r+n} L${t+e[0][3]},${r+n} Z`,Qt=t=>{const{barSeriesCount:r,bounds:n,domainState:l,plotFrame:s,plotSize:i,setSeriesSummary:o,setTooltipPoint:a,xValues:u}=K(),{className:c,label:d,xCellId:x,yCellId:m}=t,[y,p]=et(t),h=he(l.continuousX||0==r?"line":"bar",p,n,i,u,x,d??m);return W(()=>{o(y,ge("line",p,x,m,d))}),e("g",{className:tt("line-series",c),children:e(Lt,{plotFrame:s,points:h,setTooltipPoint:a})})};Qt[D]=!0;const Gt=t=>{const r=Pt("line",t);return e(kt,{...jt(t),initialSummary:r,children:e(Qt,{...Ht(t)})})},jt=e=>null==e.tableId?{className:e.className,queries:e.queries,queryId:e.queryId}:{className:e.className,store:e.store,tableId:e.tableId},Ht=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s}),_t=()=>null;_t[J]=!0;const Dt=()=>null;Dt[Y]=!0;export{Xt as BarChart,nt as BarSeries,kt as CartesianChart,Gt as LineChart,Qt as LineSeries,_t as XAxis,Dt as YAxis};
Binary file
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import n from"react";const l=e=>typeof e,s=l(""),i=l(0),o="Result",a="SortedRowIds",u="Cell",c=Math,d=e=>(t,r,n)=>e(t)?n?.():r(t),x=globalThis,y=String,m=c.max,p=c.min,h=c.ceil,f=c.floor,b=c.pow,I=c.round,g=c.abs,S=c.log10,C=1/0,M=Number.EPSILON,k=isFinite,N=Number.isInteger,$=e=>null==e,T=e=>void 0===e,v=d($),F=d(T),q=e=>l(e)==s,O=e=>l(e)==i,V=e=>Array.isArray(e),w=e=>e.length,{Children:z,Fragment:P,PureComponent:E,createContext:R,isValidElement:X,useCallback:A,useContext:L,useEffect:B,useLayoutEffect:W,useMemo:Q,useRef:G,useState:j,useSyncExternalStore:H}=n;var _=(e=>(e[e.None=0]="None",e[e.Query=1]="Query",e[e.Table=2]="Table",e))(_||{});const D="_tinybaseChartSeries",J=R(null),Z=()=>{const e=L(J);if(null==e)throw Error("Series components must be used inside a CartesianChart");return e},K=(e,t)=>se(Array(e).fill(0),(e,r)=>t(r)),U=(e,t)=>e.includes(t),Y=(e,t)=>e.indexOf(t),ee=(e,t)=>e.every(t),te=(e,t)=>w(e)===w(t)&&ee(e,(e,r)=>t[r]===e),re=(e,t)=>V(e)&&V(t)?te(e,t):e===t,ne=(e,t)=>e.forEach(t),le=(e,t="")=>e.join(t),se=(e,t)=>e.map(t),ie=e=>0==w(e),oe=(e,t)=>e.filter(t),ae=(e,...t)=>e.push(...t),ue=e=>e?.size??0,ce=[1,5,2,2.5,4,3],de=(e,t,r,n,l,s)=>{let i=[e,t],o=-2;const a=t-e;for(let u=1;u<C;u++)for(const c of ce){const d=1-Y(ce,c)/m(w(ce)-1,1)-u+1;if(.25*d+.2+.5+.05<o)return i;for(let x=2;x<C;x++){const y=x>=r?2-(x-1)/(r-1):1;if(.25*d+.2+.5*y+.05<o)break;for(let k=h(S(a/(x+1)/u/c));k<C;k++){const a=u*c*b(10,k);if(.25*d+.2*(a*(x-1)<=t-e?1:1-b((a*(x-1)-(t-e))/2,2)/b(.1*(t-e),2))+.5*y+.05<o)break;const S=f(t/a)*u-(x-1)*u,C=h(e/a)*u;S<=C&&ne(K(C-S+1,e=>S+e),d=>{const y=d*(a/u),h=y+a*(x-1),S=(x-1)/(h-y),C=(r-1)/(m(h,t)-p(e,y)),k=l/(x-1),N=.25*(1-Y(ce,c)/m(w(ce)-1,1)-u+(g(y/a-I(y/a))<100*M&&y<=0&&h>=0?1:0))+.2*(1-(b(t-h,2)+b(e-y,2))/(2*b(.1*(t-e),2)))+.5*(2-m(S/C,C/S))+.05*(k<1.2*n?-1/0:p(k,1))+(s&&(g(a-I(a))>100*M||g(y-I(y))>100*M)?-1:0);N>o&&(i=K(f((h-y)/a+.5)+1,e=>I(1e6*(y+e*a))/1e6),o=N)})}}}return i},xe=(e,t)=>oe(se(e,t),e=>!T(e)),ye=(e,t,r)=>{const n=Me(t),l=ke(r);return T(n)||T(l)?void 0:[e,n,l]},me=(e,t,[r,n,l,s],[i,o],a,u,c)=>{const d="line"==e&&ie(oe(t,([,e])=>!O(e))),x=d?[r,n]:[0,0],y=[l??0,s??0],m=new Map;return ne(null==a||ie(a)?se(t,([,e])=>e):a,e=>{m.has(e)||m.set(e,ue(m))}),se(t,([t,r,n])=>[t,r,n,pe(r,d,x,m,i,e),he(n,y,o),u,c])},pe=(e,t,[r,n],l,s,i)=>t?fe(e,r,n,s):"bar"==i?s*((l.get(e)??0)+.5)/ue(l):fe(l.get(e)??0,0,ue(l)-1,s),he=(e,[t,r],n)=>n-fe(e,t,r,n),fe=(e,t,r,n)=>t==r?n/2:Ce(n*(e-t)/(r-t)),be=(e,t,r,n,l)=>{const[s,i,o,a]=((e,t)=>{if(ie(t))return[];const[r,n]=ge(t,e);if(ie(oe(t,([,e])=>!O(e)))){const[e,l]=Se(se(t,([,e])=>e));return[e,l,r,n]}return[t[0]?.[1],t[w(t)-1]?.[1],r,n]})(e,t),u=[],c="line"==e&&ie(oe(t,([,e])=>!O(e)));return ne(t,([,e])=>{U(u,e)||ae(u,e)}),{continuousX:c,xCellId:r,xMin:s,xMax:i,yMin:o,yMax:a,yCellId:n,yLabel:l,xValues:u}},Ie=e=>{const t=[],r=[],n=[],l=[],s=[];let i,o,a=!0;return ne(e,e=>{a&&=e.continuousX,ne(e.xValues,e=>{U(t,e)||ae(t,e)}),O(e.xMin)&&O(e.xMax)?(r.push(e.xMin),n.push(e.xMax)):(i??=e.xMin,o=e.xMax??o),T(e.yMin)||l.push(e.yMin),T(e.yMax)||s.push(e.yMax)}),{bounds:[ie(r)?i:p(...r),ie(n)?o:m(...n),ie(l)?void 0:p(...l),ie(s)?void 0:m(...s)],continuousX:!ie(e)&&a,xValues:t}},ge=(e,t="bar")=>Se([..."bar"==t?[0]:[],...se(e,([,,e])=>e)]),Se=e=>{const t=p(...e);return t==C?[0,0]:[t,m(...e)]},Ce=e=>I(1e6*e)/1e6,Me=e=>O(e)?k(e)?e:void 0:q(e)||!0===e||!1===e?e:void 0,ke=e=>O(e)&&k(e)?e:void 0,Ne="currentColor",$e=({points:t,plotFrame:r,barGap:n,barSeriesCount:l,barSeriesIndex:s,setTooltipPoint:i,yMin:o=0,yMax:a=0})=>{const[u,c,d,x]=r,y=x-fe(0,o,a,x),h=w(t),f=ie(t)?0:d/h,b=m(l,1),I=m(s,0),S=m(f-n,0),C=m((S-n*(b-1))/b,0);return se(t,t=>{const[r,,,l,s]=t,o=p(s,y);return e("rect",{className:"bar",height:g(y-s),onPointerEnter:()=>i(t),onPointerLeave:()=>i(void 0),width:C,x:u+l-S/2+(C+n)*I,y:c+o},r)})},Te=Object,ve=e=>Te.getPrototypeOf(e),Fe=Te.entries,qe=e=>!$(e)&&v(ve(e),e=>e==Te.prototype||$(ve(e)),()=>!0),Oe=Te.keys,Ve=e=>Te.values(e),we=(e,t,r=(e,t)=>e===t)=>{const n=Fe(e);return w(n)===w(Oe(t))&&ee(n,([e,n])=>qe(n)?!!qe(t[e])&&we(t[e],n,r):r(n,t[e]))},ze=JSON.stringify,Pe="tinybase_uirc",Ee=x[Pe]?x[Pe]:x[Pe]=R([]),Re=(e,t)=>{const r=((e,t)=>{const r=L(Ee);return T(e)?r[2*t]:q(e)?((e,t)=>F(e,e=>e[t]))(r[2*t+1],e):e})(e,t);return T(e)||q(e)?r:e},Xe=[],Ae=[{},[],[Xe,void 0,Xe],{},void 0,void 0,!1,0],Le=(e,t)=>e===t||(qe(e)||V(e))&&ze(e)===ze(t),Be=[(e,t)=>we(e,t,Le),te,([e,t,r],[n,l,s])=>t===l&&te(e,n)&&te(r,s),(e,t)=>we(e,t,re),re,Le],We=(e,t)=>e===t,Qe=(e,t,...r)=>{const n=e?.["add"+t+"Listener"]?.(...r);return()=>e?.delListener?.(n)},Ge=(e,t,r,n=Xe)=>{const l=G(Ae[r]),s=A(()=>{const s=t?.["get"+e]?.(...n)??Ae[r];return(Be[r]??We)(s,l.current)?l.current:l.current=s},[t,r,e,...n]),i=A(r=>Qe(t,""+e,...n,r),[t,r,e,...n]);return H(i,s,s)},je=(e,t,r,n=Xe,l=Xe,...s)=>W(()=>Qe(t,e,...l,r,...s),[t,e,...l,...n,...s]),He=e=>Re(e,0),_e=(e,t,r,n,l,s,i)=>je(u,He(i),n,l,[e,t,r],s),De=e=>Re(e,4),Je=(e,t,r,n,l,s)=>je(o+u,De(s),n,l,[e,t,r]),Ze=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>{const[,i]=j(),u=Z(),{getSeriesId:c,queries:d,queriesOrQueriesId:x,queryId:y,releaseSeriesId:m,sourceType:p,store:h,storeOrStoreId:f,tableId:b}=u,[I]=j(c),g=A(()=>i([]),[i]),S=((e,t,r,n,l,s)=>((e,t,r,n,l,s)=>Ge(a,He(s),1,[e,t,r,n,l]))(...qe(e)?[e.tableId,e.cellId,e.descending??!1,e.offset??0,e.limit,t]:[e,t,r,n,l,s]))(b??"",n??l,e,r,t,f),C=((e,t,r,n=0,l,s)=>Ge(o+a,De(s),1,[e,t,r,n,l]))(y??"",n??l,e,r,t,x),M=p==_.Table?S:C,k=null==s?[]:xe(M,e=>ye(e,Ue(p,h,d,b,y,e,l),Ue(p,h,d,b,y,e,s)));return _e(p==_.Table?b??null:null,null,l,g,[g],!1,f),_e(p==_.Table?b??null:null,null,s??null,g,[g],!1,f),Je(p==_.Query?y??null:null,null,l,g,[g],x),Je(p==_.Query?y??null:null,null,s??null,g,[g],x),W(()=>()=>m(I),[m,I]),[I,k]},Ke=(e,t)=>null==t?e:`${e} ${t}`,Ue=(e,t,r,n,l,s,i)=>e==_.Table?t?.getCell(n,s,i):r?.getResultCell(l,s,i),Ye=t=>{const{barSeriesCount:r,bounds:n,getBarSeriesIndex:l,layout:[,,[,,s]],plotFrame:i,plotSize:o,registerBarSeries:a,releaseBarSeries:u,setSeriesSummary:c,setTooltipPoint:d,xValues:x}=Z(),{className:y,label:m,xCellId:p,yCellId:h}=t,[f,b]=Ze(t),I=l(f),[,,g,S]=n,C=me("bar",b,n,o,x,p,m??h);return W(()=>{c(f,be("bar",b,p,h,m))}),W(()=>(a(f),()=>u(f)),[a,u,f]),e("g",{className:Ke("bar-series",y),fill:Ne,children:e($e,{barGap:s,barSeriesCount:r,barSeriesIndex:I,plotFrame:i,points:C,setTooltipPoint:d,yMax:S,yMin:g})})};Ye[D]=!0;const et=/^\d+$/,tt=[1e3,1e3],rt=[.5,.5,.25,3.5,4,1,1],nt=([e,t],[,,,r,n,l,s])=>{const i=l+m(p(n,e/2-2*l),0),o=l+s/2,a=l+s/2,u=m(t-o-m(p(r,t/2-o-l),0)-l,0);return[i,o,m(e-i-a,0),u]},lt=e=>se(rt,t=>t*e),st=e=>{const t=parseFloat(e?.fontSize??"");return lt(k(t)?t:12)},it=({width:e,height:t})=>[I(e)||tt[0],I(t)||tt[1]],ot=({points:r,xTicks:n,xMin:l,xMax:s,xTitle:i,plotFrame:o,tickSize:a,tickGap:u,axisHeight:c,fontSize:d})=>{const[x,p,h,f]=o,b=m(c-a-u-2*d,0);return t("g",{className:"x",dominantBaseline:"hanging",textAnchor:"middle",children:[e("path",{className:"line",d:`M${x},${p+f}h${h}`,fill:"none",stroke:Ne,strokeOpacity:.5,strokeWidth:1}),e("g",{className:"ticks",children:!ie(n)&&O(l)&&O(s)?se(n,t=>{const r=fe(t,l,s,h);return e("text",{x:x+r,y:p+f+a+u,children:t},t)}):se(r,([t,r,,n])=>e("text",{x:x+n,y:p+f+a+u,children:y(r)},t))}),e("text",{className:"title",x:x+h/2,y:p+f+a+u+d+b,children:i})]})},at=({yTicks:r,yMin:n,yMax:l,yTitle:s,plotFrame:i,tickSize:o,tickGap:a,axisWidth:u})=>{const[c,d,,x]=i;return $(n)||$(l)?null:t("g",{className:"y",children:[e("path",{className:"line",d:`M${c},${d}v${x}`,fill:"none",stroke:Ne,strokeOpacity:.5,strokeWidth:1}),e("g",{className:"ticks",dominantBaseline:"middle",textAnchor:"end",children:se(r,t=>{const r=x-fe(t,n,l,x);return e("text",{x:c-o-a,y:d+r,children:t},t)})}),e("text",{className:"title",dominantBaseline:"text-before-edge",textAnchor:"middle",transform:`translate(${c-u} ${i[1]+i[3]/2}) rotate(-90)`,children:s})]})},ut=({points:r,xTicks:n,yTicks:l,bounds:[s,i,o,a],titles:[u,c],xAxisHeight:d,yAxisWidth:x,fontSize:y,...m})=>t("g",{className:"axes",fill:Ne,fillOpacity:.75,children:[e(at,{...m,yTicks:l,yMin:o,yMax:a,yTitle:c,axisWidth:x}),e(ot,{...m,points:r,xTicks:n,xMin:s,xMax:i,xTitle:u,axisHeight:d,fontSize:y})]}),ct=({points:r,xTicks:n,yTicks:l,bounds:[s,i,o,a],plotFrame:u,tickSize:c})=>{const[d,x,y,m]=u;return t("g",{className:"grid",stroke:Ne,strokeOpacity:.75,strokeWidth:.5,children:[$(o)||$(a)?null:e("path",{className:"y",d:le(se(oe(l,e=>0!=fe(e,o,a,m)),e=>`M${d-c},${x+m-fe(e,o,a,m)}h${y+c}`)," ")}),!ie(n)&&O(s)&&O(i)?e("path",{className:"x",d:le(se(oe(n,e=>0!=fe(e,s,i,y)),e=>`M${d+fe(e,s,i,y)},${x}v${m+c}`)," ")}):e("path",{className:"x",d:le(se(oe(r,([,,,e])=>0!=e),([,,,e])=>`M${d+e},${x}v${m+c}`)," ")})]})},dt="#fff",xt=({point:n,width:l,height:s,plotFrame:i,titles:[o,a]})=>{if($(n))return null;const[,u,c,d,x,h,f]=n,[b,I]=i,g=d+12+160>l?d-12-160:d+12,S=m(p(x-12-60,s-60),0);return t(r,{children:[e("path",{className:"tooltip-lines",pointerEvents:"none",stroke:Ne,strokeOpacity:.25,strokeWidth:1,d:`M${b+d},${I}v${s}M${b},${I+x}h${l}`}),t("g",{className:"tooltip",transform:`translate(${b+g} ${I+S})`,fontFamily:"sans-serif",fontWeight:600,pointerEvents:"none",children:[e("rect",{fill:"#111827",fillOpacity:.9,width:160,height:60,rx:6}),t("text",{fill:dt,x:12,y:22,children:[h??o,": ",y(u)]}),t("text",{fill:dt,x:12,y:46,children:[f??a,": ",c]})]})]})},yt={bounds:[],continuousX:!1,xValues:[]},mt=({children:r,className:n,initialSummary:l,queries:s,queryId:i,store:o,tableId:a})=>{const u=(()=>{const e=G(null),t=G([tt,lt(12)]),[r,n]=j([tt,lt(12)]);return W(()=>{const r=e.current;if(null===r)return;const l=new ResizeObserver(([e])=>(({contentRect:e})=>{const l=r.ownerDocument.defaultView?.getComputedStyle(r),s=[it(e),st(l)];(([e,t],[r,n])=>te(e,r)&&te(t,n))(t.current,s)||(t.current=s,n(s))})(e));return l.observe(r),()=>l.disconnect()},[]),[e,...r]})(),[c,d,x]=u,[y,h,,f,b,,I]=x,g=nt(d,x),S=(([,e,t])=>{const[,,r,n]=nt(e,t);return[r,n]})(u),M=(([,,e])=>e[6])(u),k=He(o),$=De(s),v=null==a?null==i?_.None:_.Query:_.Table,F=null==l?{}:{0:l},q=null==l?yt:Ie(Ve(F)),V=Ct(F,"xCellId"),z=Ct(F,"yCellId"),P=G(F),E=G(q.bounds),R=G(q),X=G(V),L=G(z),B=G((()=>{const e=[];let t=0;return[r=>(r?e.shift():null)??""+t++,t=>{et.test(t)&&w(e)<1e3&&ae(e,t)}]})()),[H,D]=j(q),[Z,K]=j(V),[ee,re]=j(z),ne=G([]),[le,se]=j([]),[ue,ce]=j(),xe=H.xValues,ye=H.bounds,pe=H.continuousX||ie(le)?"line":"bar",he=((e,[t,r],[n],l)=>"line"==e&&O(t)&&O(r)&&t!=r?de(t,r,10,l,n,N(t)&&N(r)):[])(pe,ye,S,M),fe=(([,,e,t],[,r],n)=>T(e)||T(t)?[]:e==t?[e]:de(e,t,10,n,r,N(e)&&N(t)))(ye,S,M),be=(([e,t,r,n],l,s)=>[ie(l)?e:p(e,l[0]),ie(l)?t:m(t,l[w(l)-1]),ie(s)?r:p(r??C,s[0]),ie(s)?n:m(n??-1/0,s[w(s)-1])])(ye,he,fe),ge=me(pe,xe.map((e,t)=>[""+t,e,0]),be,S,xe),Se=A(e=>{const t=Ie(Ve(e)),r=t.bounds;pt(E.current,r)&&te(R.current.xValues,t.xValues)||(E.current=r,R.current=t,D(t))},[]),Ce=A(e=>{const t=Ct(e,"xCellId"),r=Ct(e,"yCellId");X.current!=t&&(X.current=t,K(t)),L.current!=r&&(L.current=r,re(r))},[]),Me=A(e=>{const t=E.current,r=[bt(t[0],e.xMin),It(t[1],e.xMax),gt(t[2],e.yMin),St(t[3],e.yMax)];pt(t,r)||(E.current=r,R.current={bounds:r,continuousX:R.current.continuousX,xValues:R.current.xValues},D(R.current))},[]),ke=A((e,t)=>{const r=P.current,n=r[e];if(null==t){if(null==n)return;return delete r[e],Ce(r),void Se(r)}r[e]=t,Ce(r),(null==n?ft(t.xValues,R.current.xValues)||t.continuousX!=R.current.continuousX:ht(n,E.current)||n.continuousX!=t.continuousX||!te(n.xValues,t.xValues))?Se(r):Me(t)},[Me,Se,Ce]),[Ne,$e]=B.current,Te=A(()=>Ne(1),[Ne]),ve=A(e=>{ke(e,void 0),$e(e)},[$e,ke]),Fe=A(e=>{if(!U(ne.current,e)){const t=[...ne.current];ae(t,e),ne.current=t,se(t)}},[]),qe=A(e=>{if(U(ne.current,e)){const t=oe(ne.current,t=>t!=e);ne.current=t,se(t)}},[]),Oe=A(e=>Y(ne.current,e),[]),we=Q(()=>({bounds:be,barSeriesCount:w(le),domainState:H,getBarSeriesIndex:Oe,getSeriesId:Te,layout:u,plotFrame:g,plotSize:S,queries:$,queriesOrQueriesId:s,queryId:i,registerBarSeries:Fe,releaseBarSeries:qe,releaseSeriesId:ve,setSeriesSummary:ke,setTooltipPoint:ce,sourceType:v,store:k,storeOrStoreId:o,tableId:a,xTicks:he,xValues:xe,yTicks:fe}),[le,H,Oe,Te,u,g,S,s,$,i,Fe,qe,ve,ke,v,o,k,a,be,he,xe,fe]);return e(J.Provider,{value:we,children:t("svg",{className:n,preserveAspectRatio:"none",ref:c,viewBox:`0 0 ${d[0]} ${d[1]}`,children:[e(ct,{bounds:be,points:ge,plotFrame:g,tickSize:y,xTicks:he,yTicks:fe}),e(ut,{bounds:be,fontSize:I,points:ge,plotFrame:g,tickGap:h,tickSize:y,titles:[Z,ee],xAxisHeight:f,xTicks:he,yAxisWidth:b,yTicks:fe}),e("g",{className:"plot",children:Mt(r)}),e(xt,{height:S[1],point:ue,plotFrame:g,titles:[Z,ee],width:S[0]})]})})},pt=(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3],ht=({xMin:e,xMax:t,yMin:r,yMax:n},[l,s,i,o])=>e===l||t===s||r===i||n===o,ft=(e,t)=>{let r=!1;return ne(e,e=>{U(t,e)||(r=!0)}),r},bt=(e,t)=>O(e)&&O(t)?p(e,t):e??t,It=(e,t)=>O(e)&&O(t)?m(e,t):e??t,gt=(e,t)=>null==e||null==t?e??t:p(e,t),St=(e,t)=>null==e||null==t?e??t:m(e,t),Ct=(e,t)=>{const r=[];return ne(Ve(e),e=>{const n="yCellId"==t?e.yLabel??e.yCellId:e.xCellId;null==n||U(r,n)||ae(r,n)}),ie(r)?"":r.join(" & ")},Mt=e=>{const t=[];return z.forEach(e,e=>{var r;X(e)&&(e.type===P?ne(Mt(e.props.children),e=>ae(t,e)):"function"==typeof(r=e.type)&&!0===r[D]&&ae(t,e))}),t},kt=(e,{descending:t,limit:r,offset:n,queries:l,queryId:s,sortCellId:i,store:o,tableId:a,xCellId:u,yCellId:c})=>{const d=He(o),x=De(l);return Q(()=>{const l=null==a?xe(x?.getResultSortedRowIds(s??"",i??u,t,n,r)??[],e=>ye(e,x?.getResultCell(s??"",e,u),x?.getResultCell(s??"",e,c))):xe(d?.getSortedRowIds(a,i??u,t,n,r)??[],e=>ye(e,d?.getCell(a,e,u),d?.getCell(a,e,c)));return be(e,l,u,c)},[t,e,r,n,x,s,i,d,a,u,c])},Nt=t=>{const r=kt("bar",t);return e(mt,{...$t(t),initialSummary:r,children:e(Ye,{...Tt(t)})})},$t=e=>null==e.tableId?{className:e.className,queries:e.queries,queryId:e.queryId}:{className:e.className,store:e.store,tableId:e.tableId},Tt=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s}),vt=({plotFrame:n,points:l,setTooltipPoint:s})=>{const[i,o,,a]=n;return t(r,{children:[e("path",{className:"area",d:qt(l,i,o,a),fill:Ne,fillOpacity:.25,stroke:"none"}),e("path",{className:"line",d:Ft(l,i,o),fill:"none",stroke:Ne,strokeOpacity:.75,strokeWidth:2}),e("g",{className:"points",fill:Ne,children:se(l,t=>{const[r,,,n,l]=t;return e("circle",{cx:i+n,cy:o+l,onPointerEnter:()=>s(t),onPointerLeave:()=>s(void 0),r:5},r)})})]})},Ft=(e,t,r)=>le(se(e,([,,,e,n],l)=>`${0==l?"M":"L"}${t+e},${r+n}`)," "),qt=(e,t,r,n)=>ie(e)?"":`${Ft(e,t,r)} L${t+e[w(e)-1][3]},${r+n} L${t+e[0][3]},${r+n} Z`,Ot=t=>{const{barSeriesCount:r,bounds:n,domainState:l,plotFrame:s,plotSize:i,setSeriesSummary:o,setTooltipPoint:a,xValues:u}=Z(),{className:c,label:d,xCellId:x,yCellId:y}=t,[m,p]=Ze(t),h=me(l.continuousX||0==r?"line":"bar",p,n,i,u,x,d??y);return W(()=>{o(m,be("line",p,x,y,d))}),e("g",{className:Ke("line-series",c),children:e(vt,{plotFrame:s,points:h,setTooltipPoint:a})})};Ot[D]=!0;const Vt=t=>{const r=kt("line",t);return e(mt,{...wt(t),initialSummary:r,children:e(Ot,{...zt(t)})})},wt=e=>null==e.tableId?{className:e.className,queries:e.queries,queryId:e.queryId}:{className:e.className,store:e.store,tableId:e.tableId},zt=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s});export{Nt as BarChart,Ye as BarSeries,mt as CartesianChart,Vt as LineChart,Ot as LineSeries};
1
+ import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import n from"react";const l=e=>typeof e,s=l(""),i=l(0),o="Result",a="SortedRowIds",u="Cell",c=Math,d=e=>(t,r,n)=>e(t)?n?.():r(t),x=globalThis,m=String,y=c.max,p=c.min,h=c.ceil,f=c.floor,b=c.pow,I=c.round,g=c.abs,k=c.log10,C=1/0,S=Number.EPSILON,N=isFinite,M=Number.isInteger,$=e=>null==e,v=e=>void 0===e,T=d($),F=d(v),q=e=>l(e)==s,O=e=>l(e)==i,V=e=>Array.isArray(e),A=e=>e.length,{Children:w,Fragment:z,PureComponent:P,createContext:X,isValidElement:E,useCallback:R,useContext:L,useEffect:B,useLayoutEffect:W,useMemo:Q,useRef:G,useState:j,useSyncExternalStore:H}=n;var _=(e=>(e[e.None=0]="None",e[e.Query=1]="Query",e[e.Table=2]="Table",e))(_||{});const D="_tinybaseChartSeries",J="_tinybaseChartXAxis",Y="_tinybaseChartYAxis",Z=X(null),K=()=>{const e=L(Z);if(null==e)throw Error("Series components must be used inside a CartesianChart");return e},U=(e,t)=>oe(Array(e).fill(0),(e,r)=>t(r)),ee=(e,t)=>e.includes(t),te=(e,t)=>e.indexOf(t),re=(e,t)=>e.every(t),ne=(e,t)=>A(e)===A(t)&&re(e,(e,r)=>t[r]===e),le=(e,t)=>V(e)&&V(t)?ne(e,t):e===t,se=(e,t)=>e.forEach(t),ie=(e,t="")=>e.join(t),oe=(e,t)=>e.map(t),ae=e=>0==A(e),ue=(e,t)=>e.filter(t),ce=(e,...t)=>e.push(...t),de=e=>e?.size??0,xe=[1,5,2,2.5,4,3],me=(e,t,r,n,l,s)=>{let i=[e,t],o=-2;const a=t-e;for(let u=1;u<C;u++)for(const c of xe){const d=1-te(xe,c)/y(A(xe)-1,1)-u+1;if(.25*d+.2+.5+.05<o)return i;for(let x=2;x<C;x++){const m=x>=r?2-(x-1)/(r-1):1;if(.25*d+.2+.5*m+.05<o)break;for(let N=h(k(a/(x+1)/u/c));N<C;N++){const a=u*c*b(10,N);if(.25*d+.2*(a*(x-1)<=t-e?1:1-b((a*(x-1)-(t-e))/2,2)/b(.1*(t-e),2))+.5*m+.05<o)break;const k=f(t/a)*u-(x-1)*u,C=h(e/a)*u;k<=C&&se(U(C-k+1,e=>k+e),d=>{const m=d*(a/u),h=m+a*(x-1),k=(x-1)/(h-m),C=(r-1)/(y(h,t)-p(e,m)),N=l/(x-1),M=.25*(1-te(xe,c)/y(A(xe)-1,1)-u+(g(m/a-I(m/a))<100*S&&m<=0&&h>=0?1:0))+.2*(1-(b(t-h,2)+b(e-m,2))/(2*b(.1*(t-e),2)))+.5*(2-y(k/C,C/k))+.05*(N<1.2*n?-1/0:p(N,1))+(s&&(g(a-I(a))>100*S||g(m-I(m))>100*S)?-1:0);M>o&&(i=U(f((h-m)/a+.5)+1,e=>I(1e6*(m+e*a))/1e6),o=M)})}}}return i},ye=(e,t)=>ue(oe(e,t),e=>!v(e)),pe=(e,t,r)=>{const n=ve(t),l=Te(r);return v(n)||v(l)?void 0:[e,n,l]},he=(e,t,[r,n,l,s],[i,o],a,u,c)=>{const d="line"==e&&ae(ue(t,([,e])=>!O(e))),x=d?[r,n]:[0,0],m=[l??0,s??0],y=new Map;return se(null==a||ae(a)?oe(t,([,e])=>e):a,e=>{y.has(e)||y.set(e,de(y))}),oe(t,([t,r,n])=>[t,r,n,fe(r,d,x,y,i,e),be(n,m,o),u,c])},fe=(e,t,[r,n],l,s,i)=>t?Ie(e,r,n,s):"bar"==i?s*((l.get(e)??0)+.5)/de(l):Ie(l.get(e)??0,0,de(l)-1,s),be=(e,[t,r],n)=>n-Ie(e,t,r,n),Ie=(e,t,r,n)=>t==r?n/2:$e(n*(e-t)/(r-t)),ge=(e,t,r,n,l)=>{const[s,i,o,a]=((e,t)=>{if(ae(t))return[];const[r,n]=Ce(t,e);if(ae(ue(t,([,e])=>!O(e)))){const[e,l]=Se(oe(t,([,e])=>e));return[e,l,r,n]}return[t[0]?.[1],t[A(t)-1]?.[1],r,n]})(e,t),u=[],c="line"==e&&ae(ue(t,([,e])=>!O(e)));return se(t,([,e])=>{ee(u,e)||ce(u,e)}),{continuousX:c,xCellId:r,xMin:s,xMax:i,yMin:o,yMax:a,yCellId:n,yLabel:l,xValues:u}},ke=e=>{const t=[],r=[],n=[],l=[],s=[];let i,o,a=!0;return se(e,e=>{a&&=e.continuousX,se(e.xValues,e=>{ee(t,e)||ce(t,e)}),O(e.xMin)&&O(e.xMax)?(r.push(e.xMin),n.push(e.xMax)):(i??=e.xMin,o=e.xMax??o),v(e.yMin)||l.push(e.yMin),v(e.yMax)||s.push(e.yMax)}),{bounds:[ae(r)?i:p(...r),ae(n)?o:y(...n),ae(l)?void 0:p(...l),ae(s)?void 0:y(...s)],continuousX:!ae(e)&&a,xValues:t}},Ce=(e,t="bar")=>Se([..."bar"==t?[0]:[],...oe(e,([,,e])=>e)]),Se=e=>{const t=p(...e);return t==C?[0,0]:[t,y(...e)]},Ne=(e,t)=>O(e)?y(e,t):t,Me=(e=10)=>N(e)?y(I(e),1):10,$e=e=>I(1e6*e)/1e6,ve=e=>O(e)?N(e)?e:void 0:q(e)||!0===e||!1===e?e:void 0,Te=e=>O(e)&&N(e)?e:void 0,Fe="currentColor",qe=({points:t,plotFrame:r,barGap:n,barSeriesCount:l,barSeriesIndex:s,setTooltipPoint:i,yMin:o=0,yMax:a=0})=>{const[u,c,d,x]=r,m=x-Ie(0,o,a,x),h=A(t),f=ae(t)?0:d/h,b=y(l,1),I=y(s,0),k=y(f-n,0),C=y((k-n*(b-1))/b,0);return oe(t,t=>{const[r,,,l,s]=t,o=p(s,m);return e("rect",{className:"bar",height:g(m-s),onPointerEnter:()=>i(t),onPointerLeave:()=>i(void 0),width:C,x:u+l-k/2+(C+n)*I,y:c+o},r)})},Oe=Object,Ve=e=>Oe.getPrototypeOf(e),Ae=Oe.entries,we=e=>!$(e)&&T(Ve(e),e=>e==Oe.prototype||$(Ve(e)),()=>!0),ze=Oe.keys,Pe=e=>Oe.values(e),Xe=(e,t,r=(e,t)=>e===t)=>{const n=Ae(e);return A(n)===A(ze(t))&&re(n,([e,n])=>we(n)?!!we(t[e])&&Xe(t[e],n,r):r(n,t[e]))},Ee=JSON.stringify,Re="tinybase_uirc",Le=x[Re]?x[Re]:x[Re]=X([]),Be=(e,t)=>{const r=((e,t)=>{const r=L(Le);return v(e)?r[2*t]:q(e)?((e,t)=>F(e,e=>e[t]))(r[2*t+1],e):e})(e,t);return v(e)||q(e)?r:e},We=[],Qe=[{},[],[We,void 0,We],{},void 0,void 0,!1,0],Ge=(e,t)=>e===t||(we(e)||V(e))&&Ee(e)===Ee(t),je=[(e,t)=>Xe(e,t,Ge),ne,([e,t,r],[n,l,s])=>t===l&&ne(e,n)&&ne(r,s),(e,t)=>Xe(e,t,le),le,Ge],He=(e,t)=>e===t,_e=(e,t,...r)=>{const n=e?.["add"+t+"Listener"]?.(...r);return()=>e?.delListener?.(n)},De=(e,t,r,n=We)=>{const l=G(Qe[r]),s=R(()=>{const s=t?.["get"+e]?.(...n)??Qe[r];return(je[r]??He)(s,l.current)?l.current:l.current=s},[t,r,e,...n]),i=R(r=>_e(t,""+e,...n,r),[t,r,e,...n]);return H(i,s,s)},Je=(e,t,r,n=We,l=We,...s)=>W(()=>_e(t,e,...l,r,...s),[t,e,...l,...n,...s]),Ye=e=>Be(e,0),Ze=(e,t,r,n,l,s,i)=>Je(u,Ye(i),n,l,[e,t,r],s),Ke=e=>Be(e,4),Ue=(e,t,r,n,l,s)=>Je(o+u,Ke(s),n,l,[e,t,r]),et=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>{const[,i]=j(),u=K(),{getSeriesId:c,queries:d,queriesOrQueriesId:x,queryId:m,releaseSeriesId:y,sourceType:p,store:h,storeOrStoreId:f,tableId:b}=u,[I]=j(c),g=R(()=>i([]),[i]),k=((e,t,r,n,l,s)=>((e,t,r,n,l,s)=>De(a,Ye(s),1,[e,t,r,n,l]))(...we(e)?[e.tableId,e.cellId,e.descending??!1,e.offset??0,e.limit,t]:[e,t,r,n,l,s]))(b??"",n??l,e,r,t,f),C=((e,t,r,n=0,l,s)=>De(o+a,Ke(s),1,[e,t,r,n,l]))(m??"",n??l,e,r,t,x),S=p==_.Table?k:C,N=null==s?[]:ye(S,e=>pe(e,rt(p,h,d,b,m,e,l),rt(p,h,d,b,m,e,s)));return Ze(p==_.Table?b??null:null,null,l,g,[g],!1,f),Ze(p==_.Table?b??null:null,null,s??null,g,[g],!1,f),Ue(p==_.Query?m??null:null,null,l,g,[g],x),Ue(p==_.Query?m??null:null,null,s??null,g,[g],x),W(()=>()=>y(I),[y,I]),[I,N]},tt=(e,t)=>null==t?e:`${e} ${t}`,rt=(e,t,r,n,l,s,i)=>e==_.Table?t?.getCell(n,s,i):r?.getResultCell(l,s,i),nt=t=>{const{barSeriesCount:r,bounds:n,getBarSeriesIndex:l,layout:[,,[,,s]],plotFrame:i,plotSize:o,registerBarSeries:a,releaseBarSeries:u,setSeriesSummary:c,setTooltipPoint:d,xValues:x}=K(),{className:m,label:y,xCellId:p,yCellId:h}=t,[f,b]=et(t),I=l(f),[,,g,k]=n,C=he("bar",b,n,o,x,p,y??h);return W(()=>{c(f,ge("bar",b,p,h,y))}),W(()=>(a(f),()=>u(f)),[a,u,f]),e("g",{className:tt("bar-series",m),fill:Fe,children:e(qe,{barGap:s,barSeriesCount:r,barSeriesIndex:I,plotFrame:i,points:C,setTooltipPoint:d,yMax:k,yMin:g})})};nt[D]=!0;const lt=/^\d+$/,st=[1e3,1e3],it=[.5,.5,.25,3.5,4,1,1],ot=([e,t],[,,,r,n,l,s])=>{const i=l+y(p(n,e/2-2*l),0),o=l+s/2,a=l+s/2,u=y(t-o-y(p(r,t/2-o-l),0)-l,0);return[i,o,y(e-i-a,0),u]},at=e=>oe(it,t=>t*e),ut=e=>{const t=parseFloat(e?.fontSize??"");return at(N(t)?t:12)},ct=({width:e,height:t})=>[I(e)||st[0],I(t)||st[1]],dt=({className:r,points:n,tickFormatter:l,xTicks:s,xMin:i,xMax:o,xTitle:a,plotFrame:u,tickSize:c,tickGap:d,axisHeight:x,fontSize:m})=>{const[p,h,f,b]=u,I=y(x-c-d-2*m,0);return t("g",{className:xt("x",r),dominantBaseline:"hanging",textAnchor:"middle",children:[e("path",{className:"line",d:`M${p},${h+b}h${f}`,fill:"none",stroke:Fe,strokeOpacity:.5,strokeWidth:1}),e("g",{className:"ticks",children:!ae(s)&&O(i)&&O(o)?oe(s,t=>{const r=Ie(t,i,o,f);return e("text",{x:p+r,y:h+b+c+d,children:mt(t,l)},t)}):oe(n,([t,r,,n])=>e("text",{x:p+n,y:h+b+c+d,children:mt(r,l)},t))}),e("text",{className:"title",x:p+f/2,y:h+b+c+d+m+I,children:a})]})},xt=(e,t)=>null==t?e:`${e} ${t}`,mt=(e,t)=>t?.(e)??m(e),yt=({className:r,tickFormatter:n,yTicks:l,yMin:s,yMax:i,yTitle:o,plotFrame:a,tickSize:u,tickGap:c,axisWidth:d})=>{const[x,y,,p]=a;return $(s)||$(i)?null:t("g",{className:pt("y",r),children:[e("path",{className:"line",d:`M${x},${y}v${p}`,fill:"none",stroke:Fe,strokeOpacity:.5,strokeWidth:1}),e("g",{className:"ticks",dominantBaseline:"middle",textAnchor:"end",children:oe(l,t=>{const r=p-Ie(t,s,i,p);return e("text",{x:x-u-c,y:y+r,children:n?.(t)??m(t)},t)})}),e("text",{className:"title",dominantBaseline:"text-before-edge",textAnchor:"middle",transform:`translate(${x-d} ${a[1]+a[3]/2}) rotate(-90)`,children:o})]})},pt=(e,t)=>null==t?e:`${e} ${t}`,ht=({xAxis:r,yAxis:n,points:l,xTicks:s,yTicks:i,bounds:[o,a,u,c],titles:[d,x],xAxisHeight:m,yAxisWidth:y,fontSize:p,...h})=>t("g",{className:"axes",fill:Fe,fillOpacity:.75,children:[e(yt,{...h,className:n?.className,tickFormatter:n?.tickFormatter,yTicks:i,yMin:u,yMax:c,yTitle:x,axisWidth:y}),e(dt,{...h,className:r?.className,points:l,tickFormatter:r?.tickFormatter,xTicks:s,xMin:o,xMax:a,xTitle:d,axisHeight:m,fontSize:p})]}),ft=({points:r,xTicks:n,yTicks:l,bounds:[s,i,o,a],plotFrame:u,tickSize:c})=>{const[d,x,m,y]=u;return t("g",{className:"grid",stroke:Fe,strokeOpacity:.75,strokeWidth:.5,children:[$(o)||$(a)?null:e("path",{className:"y",d:ie(oe(ue(l,e=>0!=Ie(e,o,a,y)),e=>`M${d-c},${x+y-Ie(e,o,a,y)}h${m+c}`)," ")}),!ae(n)&&O(s)&&O(i)?e("path",{className:"x",d:ie(oe(ue(n,e=>0!=Ie(e,s,i,m)),e=>`M${d+Ie(e,s,i,m)},${x}v${y+c}`)," ")}):e("path",{className:"x",d:ie(oe(ue(r,([,,,e])=>0!=e),([,,,e])=>`M${d+e},${x}v${y+c}`)," ")})]})},bt="#fff",It=({point:n,width:l,height:s,plotFrame:i,titles:[o,a]})=>{if($(n))return null;const[,u,c,d,x,h,f]=n,[b,I]=i,g=d+12+160>l?d-12-160:d+12,k=y(p(x-12-60,s-60),0);return t(r,{children:[e("path",{className:"tooltip-lines",pointerEvents:"none",stroke:Fe,strokeOpacity:.25,strokeWidth:1,d:`M${b+d},${I}v${s}M${b},${I+x}h${l}`}),t("g",{className:"tooltip",transform:`translate(${b+g} ${I+k})`,fontFamily:"sans-serif",fontWeight:600,pointerEvents:"none",children:[e("rect",{fill:"#111827",fillOpacity:.9,width:160,height:60,rx:6}),t("text",{fill:bt,x:12,y:22,children:[h??o,": ",m(u)]}),t("text",{fill:bt,x:12,y:46,children:[f??a,": ",c]})]})]})},gt={bounds:[],continuousX:!1,xValues:[]},kt=({children:r,className:n,initialSummary:l,queries:s,queryId:i,store:o,tableId:a})=>{const u=(()=>{const e=G(null),t=G([st,at(12)]),[r,n]=j([st,at(12)]);return W(()=>{const r=e.current;if(null===r)return;const l=new ResizeObserver(([e])=>(({contentRect:e})=>{const l=r.ownerDocument.defaultView?.getComputedStyle(r),s=[ct(e),ut(l)];(([e,t],[r,n])=>ne(e,r)&&ne(t,n))(t.current,s)||(t.current=s,n(s))})(e));return l.observe(r),()=>l.disconnect()},[]),[e,...r]})(),[c,d,x]=u,[m,h,,f,b,,I]=x,g=ot(d,x),k=(([,e,t])=>{const[,,r,n]=ot(e,t);return[r,n]})(u),S=(([,,e])=>e[6])(u),N=Ye(o),$=Ke(s),T=null==a?null==i?_.None:_.Query:_.Table,F=null==l?{}:{0:l},q=null==l?gt:ke(Pe(F)),V=Ft(F,"xCellId"),w=Ft(F,"yCellId"),z=G(F),P=G(q.bounds),X=G(q),E=G(V),L=G(w),B=G((()=>{const e=[];let t=0;return[r=>(r?e.shift():null)??""+t++,t=>{lt.test(t)&&A(e)<1e3&&ce(e,t)}]})()),[H,D]=j(q),[J,Y]=j(V),[K,U]=j(w),re=G([]),[le,se]=j([]),[ie,oe]=j(),[de,xe,ye]=zt(r),pe=H.xValues,fe=H.continuousX||ae(pe)&&wt(xe),be=qt(H.bounds,fe,xe,ye),Ie=fe||ae(le)?"line":"bar",ge=fe&&null!=xe?.ticks?At(xe.ticks):((e,[t,r],[n],l,s)=>"line"==e&&O(t)&&O(r)&&t!=r?me(t,r,Me(s),l,n,M(t)&&M(r)):[])(Ie,be,k,S,xe?.tickCount),Ce=null==ye?.ticks?(([,,e,t],[,r],n,l)=>v(e)||v(t)?[]:e==t?[e]:me(e,t,Me(l),n,r,M(e)&&M(t)))(be,k,S,ye?.tickCount):At(ye.ticks),Se=(([e,t,r,n],l,s)=>{return[ae(l)?e:(i=e,o=l[0],O(i)?p(i,o):o),ae(l)?t:Ne(t,l[A(l)-1]),ae(s)?r:p(r??C,s[0]),ae(s)?n:y(n??-1/0,s[A(s)-1])];var i,o})(be,ge,Ce),$e=he(Ie,pe.map((e,t)=>[""+t,e,0]),Se,k,pe),ve=R(e=>{const t=ke(Pe(e)),r=t.bounds;Ct(P.current,r)&&ne(X.current.xValues,t.xValues)||(P.current=r,X.current=t,D(t))},[]),Te=R(e=>{const t=Ft(e,"xCellId"),r=Ft(e,"yCellId");E.current!=t&&(E.current=t,Y(t)),L.current!=r&&(L.current=r,U(r))},[]),Fe=R(e=>{const t=P.current,r=[Mt(t[0],e.xMin),$t(t[1],e.xMax),vt(t[2],e.yMin),Tt(t[3],e.yMax)];Ct(t,r)||(P.current=r,X.current={bounds:r,continuousX:X.current.continuousX,xValues:X.current.xValues},D(X.current))},[]),qe=R((e,t)=>{const r=z.current,n=r[e];if(null==t){if(null==n)return;return delete r[e],Te(r),void ve(r)}r[e]=t,Te(r),(null==n?Nt(t.xValues,X.current.xValues)||t.continuousX!=X.current.continuousX:St(n,P.current)||n.continuousX!=t.continuousX||!ne(n.xValues,t.xValues))?ve(r):Fe(t)},[Fe,ve,Te]),[Oe,Ve]=B.current,Ae=R(()=>Oe(1),[Oe]),we=R(e=>{qe(e,void 0),Ve(e)},[Ve,qe]),ze=R(e=>{if(!ee(re.current,e)){const t=[...re.current];ce(t,e),re.current=t,se(t)}},[]),Xe=R(e=>{if(ee(re.current,e)){const t=ue(re.current,t=>t!=e);re.current=t,se(t)}},[]),Ee=R(e=>te(re.current,e),[]),Re=Q(()=>({bounds:Se,barSeriesCount:A(le),domainState:H,getBarSeriesIndex:Ee,getSeriesId:Ae,layout:u,plotFrame:g,plotSize:k,queries:$,queriesOrQueriesId:s,queryId:i,registerBarSeries:ze,releaseBarSeries:Xe,releaseSeriesId:we,setSeriesSummary:qe,setTooltipPoint:oe,sourceType:T,store:N,storeOrStoreId:o,tableId:a,xTicks:ge,xValues:pe,yTicks:Ce}),[le,H,Ee,Ae,u,g,k,s,$,i,ze,Xe,we,qe,T,o,N,a,Se,ge,pe,Ce]);return e(Z.Provider,{value:Re,children:t("svg",{className:n,preserveAspectRatio:"none",ref:c,viewBox:`0 0 ${d[0]} ${d[1]}`,children:[e(ft,{bounds:Se,points:$e,plotFrame:g,tickSize:m,xTicks:ge,yTicks:Ce}),e(ht,{bounds:Se,fontSize:I,points:$e,plotFrame:g,tickGap:h,tickSize:m,titles:[xe?.title??J,ye?.title??K],xAxis:xe,xAxisHeight:f,xTicks:ge,yAxis:ye,yAxisWidth:b,yTicks:Ce}),e("g",{className:"plot",children:de}),e(It,{height:k[1],point:ie,plotFrame:g,titles:[xe?.title??J,ye?.title??K],width:k[0]})]})})},Ct=(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3],St=({xMin:e,xMax:t,yMin:r,yMax:n},[l,s,i,o])=>e===l||t===s||r===i||n===o,Nt=(e,t)=>{let r=!1;return se(e,e=>{ee(t,e)||(r=!0)}),r},Mt=(e,t)=>O(e)&&O(t)?p(e,t):e??t,$t=(e,t)=>O(e)&&O(t)?y(e,t):e??t,vt=(e,t)=>null==e||null==t?e??t:p(e,t),Tt=(e,t)=>null==e||null==t?e??t:y(e,t),Ft=(e,t)=>{const r=[];return se(Pe(e),e=>{const n="yCellId"==t?e.yLabel??e.yCellId:e.xCellId;null==n||ee(r,n)||ce(r,n)}),ae(r)?"":r.join(" & ")},qt=([e,t,r,n],l,s,i)=>[l?Ot(s?.min,e):e,l?Ot(s?.max,t):t,Vt(i?.min,r),Vt(i?.max,n)],Ot=(e,t)=>N(e)?e:t,Vt=(e,t)=>N(e)?e:t,At=e=>{return t=(e,t)=>e-t,ue([...e],N).sort(t);var t},wt=e=>N(e?.min)||N(e?.max)||null!=e?.ticks,zt=e=>{const t=[];let r,n;return w.forEach(e,e=>{if(E(e))if(e.type===z){const[l,s,i]=zt(e.props.children);se(l,e=>ce(t,e)),r??=s,n??=i}else"function"==typeof(l=e.type)&&!0===l[D]?ce(t,e):null==r&&(e=>"function"==typeof e&&!0===e[J])(e.type)?r=e.props:null==n&&(e=>"function"==typeof e&&!0===e[Y])(e.type)&&(n=e.props);var l}),[t,r,n]},Pt=(e,{descending:t,limit:r,offset:n,queries:l,queryId:s,sortCellId:i,store:o,tableId:a,xCellId:u,yCellId:c})=>{const d=Ye(o),x=Ke(l);return Q(()=>{const l=null==a?ye(x?.getResultSortedRowIds(s??"",i??u,t,n,r)??[],e=>pe(e,x?.getResultCell(s??"",e,u),x?.getResultCell(s??"",e,c))):ye(d?.getSortedRowIds(a,i??u,t,n,r)??[],e=>pe(e,d?.getCell(a,e,u),d?.getCell(a,e,c)));return ge(e,l,u,c)},[t,e,r,n,x,s,i,d,a,u,c])},Xt=t=>{const r=Pt("bar",t);return e(kt,{...Et(t),initialSummary:r,children:e(nt,{...Rt(t)})})},Et=e=>null==e.tableId?{className:e.className,queries:e.queries,queryId:e.queryId}:{className:e.className,store:e.store,tableId:e.tableId},Rt=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s}),Lt=({plotFrame:n,points:l,setTooltipPoint:s})=>{const[i,o,,a]=n;return t(r,{children:[e("path",{className:"area",d:Wt(l,i,o,a),fill:Fe,fillOpacity:.25,stroke:"none"}),e("path",{className:"line",d:Bt(l,i,o),fill:"none",stroke:Fe,strokeOpacity:.75,strokeWidth:2}),e("g",{className:"points",fill:Fe,children:oe(l,t=>{const[r,,,n,l]=t;return e("circle",{cx:i+n,cy:o+l,onPointerEnter:()=>s(t),onPointerLeave:()=>s(void 0),r:5},r)})})]})},Bt=(e,t,r)=>ie(oe(e,([,,,e,n],l)=>`${0==l?"M":"L"}${t+e},${r+n}`)," "),Wt=(e,t,r,n)=>ae(e)?"":`${Bt(e,t,r)} L${t+e[A(e)-1][3]},${r+n} L${t+e[0][3]},${r+n} Z`,Qt=t=>{const{barSeriesCount:r,bounds:n,domainState:l,plotFrame:s,plotSize:i,setSeriesSummary:o,setTooltipPoint:a,xValues:u}=K(),{className:c,label:d,xCellId:x,yCellId:m}=t,[y,p]=et(t),h=he(l.continuousX||0==r?"line":"bar",p,n,i,u,x,d??m);return W(()=>{o(y,ge("line",p,x,m,d))}),e("g",{className:tt("line-series",c),children:e(Lt,{plotFrame:s,points:h,setTooltipPoint:a})})};Qt[D]=!0;const Gt=t=>{const r=Pt("line",t);return e(kt,{...jt(t),initialSummary:r,children:e(Qt,{...Ht(t)})})},jt=e=>null==e.tableId?{className:e.className,queries:e.queries,queryId:e.queryId}:{className:e.className,store:e.store,tableId:e.tableId},Ht=({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s})=>({descending:e,limit:t,offset:r,sortCellId:n,xCellId:l,yCellId:s}),_t=()=>null;_t[J]=!0;const Dt=()=>null;Dt[Y]=!0;export{Xt as BarChart,nt as BarSeries,kt as CartesianChart,Gt as LineChart,Qt as LineSeries,_t as XAxis,Dt as YAxis};