@torpor/ui 1.3.6 → 1.4.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.
Files changed (128) hide show
  1. package/dist/Accordion/AccordionItem.torp +1 -1
  2. package/dist/Alert/Alert.torp +41 -0
  3. package/dist/Alert/index.d.ts +37 -0
  4. package/dist/Alert/index.js +1 -0
  5. package/dist/Charts/ChartScatter.torp +167 -0
  6. package/dist/Charts/ScatterChart.torp +49 -178
  7. package/dist/Charts/index.d.ts +38 -78
  8. package/dist/Charts/index.js +2 -4
  9. package/dist/ColorPicker/ColorPalette.torp +107 -29
  10. package/dist/ColorPicker/ColorPicker.torp +121 -10
  11. package/dist/ColorPicker/ColorPickerAlpha.torp +58 -0
  12. package/dist/ColorPicker/ColorPickerArea.torp +175 -0
  13. package/dist/ColorPicker/ColorPickerEyedropper.torp +77 -0
  14. package/dist/ColorPicker/ColorPickerHue.torp +59 -0
  15. package/dist/ColorPicker/ColorPickerInput.torp +7 -18
  16. package/dist/ColorPicker/ColorPickerTypes.ts +11 -1
  17. package/dist/ColorPicker/index.d.ts +139 -14
  18. package/dist/ColorPicker/index.js +5 -1
  19. package/dist/ComboBox/ComboBox.torp +40 -5
  20. package/dist/ComboBox/index.d.ts +5 -2
  21. package/dist/ComboBox/index.js +1 -2
  22. package/dist/Contextual/Contextual.torp +25 -77
  23. package/dist/Contextual/ContextualContent.torp +10 -51
  24. package/dist/Contextual/ContextualHover.torp +13 -85
  25. package/dist/Contextual/ContextualTrigger.torp +9 -16
  26. package/dist/Contextual/ContextualTypes.ts +6 -12
  27. package/dist/Contextual/index.d.ts +10 -13
  28. package/dist/DataGrid/DataGrid.torp +2 -2
  29. package/dist/DataGrid/index.d.ts +1 -1
  30. package/dist/DatePicker/DatePicker.torp +6 -4
  31. package/dist/DateRangePicker/DateRangePicker.torp +14 -13
  32. package/dist/DateTimePicker/DateTimePicker.torp +264 -0
  33. package/dist/DateTimePicker/index.d.ts +46 -0
  34. package/dist/DateTimePicker/index.js +1 -0
  35. package/dist/Dialog/Dialog.torp +0 -1
  36. package/dist/Dialog/index.d.ts +0 -1
  37. package/dist/Drawer/Drawer.torp +5 -23
  38. package/dist/Drawer/DrawerContent.torp +1 -0
  39. package/dist/Drawer/DrawerOverlay.torp +9 -16
  40. package/dist/Drawer/DrawerTrigger.torp +9 -24
  41. package/dist/Drawer/DrawerTypes.ts +3 -1
  42. package/dist/Form/CheckBox.torp +10 -18
  43. package/dist/Form/File.torp +10 -18
  44. package/dist/Form/FileDrop.torp +16 -22
  45. package/dist/Form/Input.torp +14 -20
  46. package/dist/Form/Radio.torp +71 -0
  47. package/dist/Form/RadioGroup.torp +221 -0
  48. package/dist/Form/RadioGroupTypes.ts +40 -0
  49. package/dist/Form/Select.torp +10 -18
  50. package/dist/Form/{Toggle.torp → Switch.torp} +17 -21
  51. package/dist/Form/TextArea.torp +10 -18
  52. package/dist/Form/ToggleButton.torp +94 -0
  53. package/dist/Form/ToggleGroup.torp +150 -0
  54. package/dist/Form/ToggleGroupTypes.ts +23 -0
  55. package/dist/Form/index.d.ts +173 -15
  56. package/dist/Form/index.js +6 -2
  57. package/dist/ListBox/ListBox.torp +27 -5
  58. package/dist/ListBox/ListBoxItem.torp +1 -1
  59. package/dist/ListBox/index.d.ts +6 -2
  60. package/dist/MaskedInput/MaskedInput.torp +1 -1
  61. package/dist/Menu/MenuPopoutTrigger.torp +1 -1
  62. package/dist/MenuBar/MenuBar.torp +5 -3
  63. package/dist/MenuBar/MenuBarItemTrigger.torp +2 -2
  64. package/dist/Meter/Meter.torp +126 -0
  65. package/dist/Meter/MeterIndicator.torp +41 -0
  66. package/dist/Meter/MeterTypes.ts +8 -0
  67. package/dist/Meter/index.d.ts +79 -0
  68. package/dist/Meter/index.js +3 -0
  69. package/dist/Modal/Modal.torp +4 -22
  70. package/dist/Modal/ModalOverlay.torp +9 -16
  71. package/dist/NavMenu/NavMenu.torp +5 -3
  72. package/dist/NumberInput/NumberInput.torp +1 -1
  73. package/dist/PinInput/PinInput.torp +220 -0
  74. package/dist/PinInput/index.d.ts +48 -0
  75. package/dist/PinInput/index.js +1 -0
  76. package/dist/Popover/Popover.torp +18 -24
  77. package/dist/Popover/PopoverContent.torp +8 -0
  78. package/dist/Popover/PopoverHover.torp +30 -3
  79. package/dist/Popover/PopoverTypes.ts +2 -0
  80. package/dist/Popover/index.d.ts +8 -1
  81. package/dist/Rating/Rating.torp +1 -1
  82. package/dist/SegmentedControl/SegmentedControl.torp +3 -3
  83. package/dist/SegmentedControl/SegmentedItem.torp +1 -1
  84. package/dist/SelectBox/SelectBox.torp +40 -5
  85. package/dist/SelectBox/index.d.ts +5 -2
  86. package/dist/SelectBox/index.js +1 -2
  87. package/dist/Slider/Slider.torp +1 -1
  88. package/dist/SortableList/SortableList.torp +132 -0
  89. package/dist/SortableList/SortableListItem.torp +117 -0
  90. package/dist/SortableList/SortableListTypes.ts +16 -0
  91. package/dist/SortableList/index.d.ts +81 -0
  92. package/dist/SortableList/index.js +3 -0
  93. package/dist/TabGroup/TabContent.torp +1 -1
  94. package/dist/TabGroup/TabGroup.torp +2 -2
  95. package/dist/TabGroup/TabHeader.torp +1 -1
  96. package/dist/TagInput/TagInput.torp +1 -1
  97. package/dist/TimePicker/TimePicker.torp +1 -1
  98. package/dist/ToolBar/ToolBar.torp +8 -4
  99. package/dist/ToolBar/ToolBarPopoutTrigger.torp +1 -1
  100. package/dist/Tooltip/Tooltip.torp +104 -0
  101. package/dist/Tooltip/TooltipContent.torp +81 -0
  102. package/dist/Tooltip/TooltipTrigger.torp +79 -0
  103. package/dist/Tooltip/TooltipTypes.ts +28 -0
  104. package/dist/Tooltip/index.d.ts +104 -0
  105. package/dist/Tooltip/index.js +4 -0
  106. package/dist/Tree/Tree.torp +1 -1
  107. package/dist/Tree/TreeItem.torp +1 -1
  108. package/dist/VirtualList/VirtualList.torp +149 -0
  109. package/dist/VirtualList/index.d.ts +46 -0
  110. package/dist/VirtualList/index.js +1 -0
  111. package/dist/dnd/index.d.ts +2 -0
  112. package/dist/dnd/index.js +212 -0
  113. package/dist/dnd/index.js.map +1 -0
  114. package/dist/loader/index.d.ts +2 -0
  115. package/dist/{loader-CBGbVpkN.js → loader/index.js} +2 -2
  116. package/dist/loader/index.js.map +1 -0
  117. package/dist/utils/PopoutClickTrigger.torp +1 -0
  118. package/dist/utils/PopoutOverlay.torp +39 -0
  119. package/dist/utils/PopoutTypes.ts +4 -0
  120. package/dist/utils/SubmenuPopoutTrigger.torp +5 -5
  121. package/dist/utils/colorUtils.ts +260 -75
  122. package/dist/utils/formField.ts +4 -3
  123. package/dist/utils/handlePopoutButton.ts +43 -0
  124. package/package.json +41 -5
  125. package/dist/Charts/GridLines.torp +0 -65
  126. package/dist/Charts/XAxis.torp +0 -69
  127. package/dist/Charts/YAxis.torp +0 -49
  128. package/dist/loader-CBGbVpkN.js.map +0 -1
@@ -46,7 +46,7 @@ export default function AccordionItem($props: AccordionItemProps | undefined) {
46
46
  expanded: false,
47
47
  headerId: "",
48
48
  contentId: "",
49
- disabled: $props?.disabled ?? false,
49
+ disabled: $props?.disabled === true,
50
50
  parentDisabled: false,
51
51
  setFocused,
52
52
  });
@@ -0,0 +1,41 @@
1
+ import type { ClassValue, StyleValue } from "@torpor/view";
2
+
3
+ interface AlertProps {
4
+ /** An ID for the root element */
5
+ id?: string;
6
+ /** Classes for the root element */
7
+ class?: ClassValue;
8
+ /** Styles for the root element */
9
+ style?: StyleValue;
10
+ /** The kind of message, for theming (default "info") */
11
+ variant?: "info" | "success" | "warning" | "error";
12
+ /** An accessible name for the alert */
13
+ ariaLabel?: string;
14
+ }
15
+
16
+ /**
17
+ * An inline message that is announced by assistive tech as soon as it is
18
+ * shown, for errors, warnings and other important status updates.
19
+ *
20
+ * See [the WAI ARIA alert pattern](https://www.w3.org/WAI/ARIA/apg/patterns/alert/).
21
+ *
22
+ * Unlike Notification (a toast), an Alert sits in the flow of the page:
23
+ *
24
+ * ```
25
+ * <Alert variant="error">Your changes could not be saved.</Alert>
26
+ * ```
27
+ */
28
+ export default function Alert($props: AlertProps | undefined) {
29
+ @render {
30
+ <div
31
+ {$props?.id}
32
+ class={["torp-alert", $props?.class]}
33
+ {$props?.style}
34
+ role="alert"
35
+ aria-label={$props?.ariaLabel}
36
+ data-variant={$props?.variant ?? "info"}
37
+ >
38
+ <slot />
39
+ </div>
40
+ }
41
+ }
@@ -0,0 +1,37 @@
1
+ import { type SlotRender } from "@torpor/view";
2
+
3
+
4
+ interface AlertProps {
5
+ /** An ID for the root element */
6
+ id?: string;
7
+ /** Classes for the root element */
8
+ class?: ClassValue;
9
+ /** Styles for the root element */
10
+ style?: StyleValue;
11
+ /** The kind of message, for theming (default "info") */
12
+ variant?: "info" | "success" | "warning" | "error";
13
+ /** An accessible name for the alert */
14
+ ariaLabel?: string;
15
+ }
16
+
17
+ /**
18
+ * An inline message that is announced by assistive tech as soon as it is
19
+ * shown, for errors, warnings and other important status updates.
20
+ *
21
+ * See [the WAI ARIA alert pattern](https://www.w3.org/WAI/ARIA/apg/patterns/alert/).
22
+ *
23
+ * Unlike Notification (a toast), an Alert sits in the flow of the page:
24
+ *
25
+ * ```
26
+ * <Alert variant="error">Your changes could not be saved.</Alert>
27
+ * ```
28
+ */
29
+ declare function Alert(
30
+ $parent: ParentNode,
31
+ $anchor: Node | null,
32
+ $props: AlertProps | undefined,
33
+ $context?: Record<PropertyKey, any>,
34
+ $slots?: Record<string, SlotRender>,
35
+ ): void;
36
+
37
+ export { Alert };
@@ -0,0 +1 @@
1
+ export { default as Alert } from "./Alert.torp";
@@ -0,0 +1,167 @@
1
+ import { chartColors } from "../utils/chartColors";
2
+ import {
3
+ calculateStepLabels,
4
+ calculateStepValue,
5
+ } from "../utils/chartUtils";
6
+ import { type ChartContext, ChartContextName } from "./ChartTypes";
7
+
8
+ interface Pair {
9
+ x: number;
10
+ y: number;
11
+ /** An extra label for the point's tooltip */
12
+ label?: string;
13
+ }
14
+
15
+ interface ScatterSeries {
16
+ name: string;
17
+ color?: string;
18
+ data: Pair[];
19
+ }
20
+
21
+ interface ChartScatterProps {
22
+ /** The point series to draw */
23
+ series: ScatterSeries[];
24
+ /** The largest x value, for scaling the horizontal axis */
25
+ maxX: number;
26
+ /** The number of x axis steps (default 2) */
27
+ stepCount?: number;
28
+ /** The size of each x axis step, instead of being calculated */
29
+ stepValue?: number;
30
+ /** Whether to draw the x axis and its labels (default true) */
31
+ showAxis?: boolean;
32
+ /** Whether to draw vertical grid lines at each x step (default false) */
33
+ showVLines?: boolean;
34
+ /** An axis title drawn under the x ticks */
35
+ xLabel?: string;
36
+ }
37
+
38
+ /**
39
+ * Scatter marks for a Chart: one circle per `{ x, y }` pair, positioned
40
+ * against a numeric x scale and the Chart's value scale. Also draws the
41
+ * numeric x axis and its vertical grid lines, since the standard axes
42
+ * assume category labels.
43
+ */
44
+ export default function ChartScatter($props: ChartScatterProps | undefined) {
45
+ const context = $context[ChartContextName] as ChartContext;
46
+ if (!context) {
47
+ throw new Error("ChartScatter must be contained within a Chart");
48
+ }
49
+ const { layout } = context;
50
+
51
+ function stepCount(): number {
52
+ return $props?.stepCount ?? 2;
53
+ }
54
+
55
+ function stepValue(): number {
56
+ return $props?.stepValue || calculateStepValue($props?.maxX || 1, stepCount());
57
+ }
58
+
59
+ function stepLabels(): number[] {
60
+ return calculateStepLabels(stepCount(), stepValue());
61
+ }
62
+
63
+ // The domain top the x ticks span; the marks scale against the same
64
+ // range so they line up with the ticks even when maxX falls between them
65
+ function domainTop(): number {
66
+ return Math.max(stepValue() * stepCount(), $props?.maxX || 1);
67
+ }
68
+
69
+ function xFor(value: number): number {
70
+ return +(layout.plotX + (value / domainTop()) * layout.plotWidth).toFixed(2);
71
+ }
72
+
73
+ function yFor(value: number): number {
74
+ return +(layout.plotY + layout.plotHeight - value * layout.valueHeight).toFixed(2);
75
+ }
76
+
77
+ function showAxis(): boolean {
78
+ return $props?.showAxis !== false;
79
+ }
80
+
81
+ function title(): string {
82
+ return $props?.xLabel ?? "";
83
+ }
84
+
85
+ // Reserve a strip along the bottom for the ticks and title
86
+ $run(() => {
87
+ if (!showAxis() && !title()) {
88
+ layout.release("scatter-xaxis");
89
+ return;
90
+ }
91
+ layout.reserve("scatter-xaxis", "bottom", layout.textHeight * (title() ? 2 : 1));
92
+ return () => layout.release("scatter-xaxis");
93
+ });
94
+
95
+ function tickY(): number {
96
+ return layout.plotY + layout.plotHeight + layout.textHeight * (2 / 3) + 4;
97
+ }
98
+
99
+ function titleY(): number {
100
+ return layout.plotY + layout.plotHeight + layout.textHeight * 2;
101
+ }
102
+
103
+ function tickAnchor(i: number, count: number): string {
104
+ if (i === 0) return "start";
105
+ if (i === count - 1) return "end";
106
+ return "middle";
107
+ }
108
+
109
+ @render {
110
+ <svg>
111
+ @if (showAxis()) {
112
+ <line
113
+ x1={layout.plotX}
114
+ y1={layout.plotY + layout.plotHeight + 0.5}
115
+ x2={layout.plotX + layout.plotWidth}
116
+ y2={layout.plotY + layout.plotHeight + 0.5}
117
+ stroke="currentcolor"
118
+ />
119
+ }
120
+ @if ($props?.showVLines) {
121
+ @for (let label of stepLabels()) {
122
+ <line
123
+ x1={xFor(label)}
124
+ y1={layout.plotY}
125
+ x2={xFor(label)}
126
+ y2={layout.plotY + layout.plotHeight}
127
+ stroke="currentcolor"
128
+ />
129
+ }
130
+ }
131
+ @if (title()) {
132
+ <text
133
+ fill="currentcolor"
134
+ text-anchor="middle"
135
+ dominant-baseline="text-after-edge"
136
+ x={layout.plotX + layout.plotWidth / 2}
137
+ y={titleY()}
138
+ >
139
+ {title()}
140
+ </text>
141
+ }
142
+ @for (let [i, label] of stepLabels().entries()) {
143
+ <text
144
+ fill="currentcolor"
145
+ text-anchor={tickAnchor(i, stepLabels().length)}
146
+ dominant-baseline="text-after-edge"
147
+ x={xFor(label)}
148
+ y={tickY()}
149
+ >
150
+ {label}
151
+ </text>
152
+ }
153
+ @for (let [i, series] of ($props?.series ?? []).entries()) {
154
+ @for (let point of series.data) {
155
+ <circle
156
+ cx={xFor(point.x)}
157
+ cy={yFor(point.y)}
158
+ r="4"
159
+ fill={series.color || chartColors[i % chartColors.length]}
160
+ >
161
+ <title>{`${[series.name, point.label, point.x].filter(Boolean).join("\n")}, ${point.y}`}</title>
162
+ </circle>
163
+ }
164
+ }
165
+ </svg>
166
+ }
167
+ }
@@ -1,15 +1,8 @@
1
1
  import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { chartColors } from "../utils/chartColors";
3
- import {
4
- calculateChartBottom,
5
- calculateChartLeft,
6
- calculateStepLabels,
7
- calculateStepValue,
8
- calculateValueHeight,
9
- } from "../utils/chartUtils";
10
- import GridLines from "./GridLines.torp";
11
- import XAxis from "./XAxis.torp";
12
- import YAxis from "./YAxis.torp";
2
+ import Chart from "./Chart.torp";
3
+ import ChartGrid from "./ChartGrid.torp";
4
+ import ChartScatter from "./ChartScatter.torp";
5
+ import ChartYAxis from "./ChartYAxis.torp";
13
6
 
14
7
  interface Pair {
15
8
  x: number;
@@ -48,176 +41,54 @@ interface ScatterChartProps {
48
41
  showVLines?: boolean;
49
42
  }
50
43
 
51
- export default function ScatterChart($props: ScatterChartProps) {
52
- const defaultHeight = 200;
53
- const defaultWidth = 400;
54
-
55
- let container: HTMLElement;
56
- let measurer: SVGTextElement;
57
-
58
- let $state = $watch({
59
- textWidth: 0,
60
- textHeight: 0,
61
- get calculatedHeight() {
62
- return $props.height || defaultHeight;
63
- },
64
- get calculatedWidth() {
65
- return $props.width || container?.clientWidth || defaultWidth;
66
- },
67
- get maxXValue() {
68
- return calculateMaxValue($props.series, "x");
69
- },
70
- get calculatedXStepValue() {
71
- return $props.xStepValue || calculateStepValue($state.maxXValue, $props.xStepCount);
72
- },
73
- get xStepLabels() {
74
- return calculateStepLabels($props.xStepCount || 2, $state.calculatedXStepValue);
75
- },
76
- get maxYValue() {
77
- return calculateMaxValue($props.series, "y");
78
- },
79
- get calculatedYStepValue() {
80
- return $props.yStepValue || calculateStepValue($state.maxYValue, $props.yStepCount);
81
- },
82
- get yStepLabels() {
83
- return calculateStepLabels($props.yStepCount || 2, $state.calculatedYStepValue);
84
- },
85
- get itemWidth() {
86
- return calculateValueHeight(
87
- $state.calculatedWidth - $state.chartLeft,
88
- $state.textHeight,
89
- $state.calculatedXStepValue,
90
- $props.xStepCount || 2,
91
- );
92
- },
93
- get valueHeight() {
94
- return calculateValueHeight(
95
- $state.chartBottom,
96
- $state.textHeight,
97
- $state.calculatedYStepValue,
98
- $props.yStepCount || 2,
99
- );
100
- },
101
- get chartBottom() {
102
- return calculateChartBottom($props.xLabel ?? "", $state.calculatedHeight, $state.textHeight);
103
- },
104
- get chartLeft() {
105
- return calculateChartLeft(
106
- $state.yStepLabels,
107
- $props.yLabel ?? "",
108
- $state.textHeight,
109
- $state.textWidth,
110
- );
111
- },
112
- get pointSeries() {
113
- return buildPointSeries(
114
- $props.series,
115
- $state.chartLeft,
116
- $state.chartBottom,
117
- $state.itemWidth,
118
- $state.valueHeight,
119
- );
120
- },
121
- });
122
-
123
- $onmount(() => {
124
- // HACK: Wait until the measurer is really available
125
- setTimeout(() => {
126
- const bbox = measurer.getBBox();
127
- $state.textWidth = bbox.width;
128
- $state.textHeight = bbox.height * 1.5;
129
- measurer.remove();
130
- }, 1);
131
- });
132
-
133
- function calculateMaxValue(series: DataSeries[], field: "x" | "y") {
134
- // HACK: Yeah, nested reduces
135
- return series.reduce((a, b) => {
136
- return Math.max(
137
- a,
138
- b.data.reduce((c, d) => Math.max(c, field === "x" ? d.x : d.y), 0),
139
- );
140
- }, 0);
141
- }
44
+ function maxOf(series: DataSeries[], field: "x" | "y"): number {
45
+ return series.reduce(
46
+ (max, s) => Math.max(max, ...s.data.map((point) => point[field])),
47
+ 0,
48
+ );
49
+ }
142
50
 
143
- function buildPointSeries(
144
- theSeries: DataSeries[],
145
- theChartLeft: number,
146
- theChartBottom: number,
147
- theItemWidth: number,
148
- theValueHeight: number,
149
- ) {
150
- return theSeries.map((series) => {
151
- return series.data.map((item) => {
152
- const x = +(theChartLeft + item.x * theItemWidth).toFixed(2);
153
- const y = +(theChartBottom - item.y * theValueHeight).toFixed(2);
154
- return { x, y };
155
- });
156
- });
51
+ /**
52
+ * A scatter chart preset: one point per `{ x, y }` pair, with a numeric x
53
+ * axis and the standard value axis, laid out by Chart.
54
+ */
55
+ export default function ScatterChart($props: ScatterChartProps) {
56
+ // Chart's value scale works on plain numbers, so the points become the
57
+ // y values and ChartScatter positions them by their x values
58
+ function chartSeries() {
59
+ return $props.series.map((series) => ({
60
+ name: series.name,
61
+ color: series.color,
62
+ data: series.data.map((point) => point.y),
63
+ }));
157
64
  }
158
65
 
159
66
  @render {
160
- <div {$props?.id} class={["torp-scatter-chart", $props?.class]} {$props?.style} &ref={container}>
161
- <svg role={$props?.ariaLabel ? "img" : undefined} aria-label={$props?.ariaLabel} version="1.1" width={$state.calculatedWidth} height={$state.calculatedHeight}>
162
- <g>
163
- <text &ref={measurer} x="-999" y="-999">8</text>
164
-
165
- @if ($state.textWidth && $state.textHeight) {
166
- <XAxis
167
- showAxis={!$props.hideXAxis}
168
- height={$state.calculatedHeight}
169
- width={$state.calculatedWidth}
170
- {$state.itemWidth}
171
- {$state.textHeight}
172
- xLabel={$props.xLabel ?? ""}
173
- labels={[]}
174
- stepLabels={$state.xStepLabels}
175
- stepValue={$state.calculatedXStepValue}
176
- {$state.chartLeft}
177
- {$state.chartBottom}
178
- />
179
- <YAxis
180
- showAxis={!$props.hideYAxis}
181
- {$state.valueHeight}
182
- {$state.textHeight}
183
- yLabel={$props.yLabel ?? ""}
184
- stepLabels={$state.yStepLabels}
185
- stepValue={$state.calculatedYStepValue}
186
- {$state.chartLeft}
187
- {$state.chartBottom}
188
- />
189
- <GridLines
190
- {$props.showHLines}
191
- {$props.showVLines}
192
- width={$state.calculatedWidth}
193
- labels={[]}
194
- xStepValue={$state.calculatedXStepValue}
195
- {$state.xStepLabels}
196
- yStepValue={$state.calculatedYStepValue}
197
- {$state.yStepLabels}
198
- {$state.itemWidth}
199
- {$state.valueHeight}
200
- {$state.chartLeft}
201
- {$state.chartBottom}
202
- type="line"
203
- />
204
- @for (let [i, series] of $props.series.entries()) {
205
- @for (let [j, point] of $state.pointSeries[i].entries()) {
206
- <circle
207
- cx={point.x}
208
- cy={point.y}
209
- r="4"
210
- fill={series.color || chartColors[i % chartColors.length]}
211
- >
212
- <title>{
213
- `${[series.name, series.data[j].label, series.data[j].x].filter(Boolean).join("\n")}, ${series.data[j].y}`
214
- }</title>
215
- </circle>
216
- }
217
- }
218
- }
219
- </g>
220
- </svg>
221
- </div>
67
+ <Chart
68
+ {$props?.id}
69
+ class={["torp-scatter-chart", $props?.class]}
70
+ {$props?.style}
71
+ ariaLabel={$props?.ariaLabel}
72
+ series={chartSeries()}
73
+ height={$props?.height}
74
+ width={$props?.width}
75
+ xLabel={$props?.xLabel}
76
+ yLabel={$props?.yLabel}
77
+ maxValue={maxOf($props.series, "y")}
78
+ stepCount={$props?.yStepCount}
79
+ stepValue={$props?.yStepValue}
80
+ >
81
+ <ChartYAxis showAxis={!$props?.hideYAxis} />
82
+ <ChartGrid hLines={$props?.showHLines} />
83
+ <ChartScatter
84
+ series={$props.series}
85
+ maxX={maxOf($props.series, "x")}
86
+ stepCount={$props?.xStepCount}
87
+ stepValue={$props?.xStepValue}
88
+ showAxis={!$props?.hideXAxis}
89
+ showVLines={$props?.showVLines}
90
+ xLabel={$props?.xLabel}
91
+ />
92
+ </Chart>
222
93
  }
223
94
  }
@@ -301,6 +301,39 @@ declare function ChartPoints(
301
301
 
302
302
 
303
303
 
304
+ interface ChartScatterProps {
305
+ /** The point series to draw */
306
+ series: ScatterSeries[];
307
+ /** The largest x value, for scaling the horizontal axis */
308
+ maxX: number;
309
+ /** The number of x axis steps (default 2) */
310
+ stepCount?: number;
311
+ /** The size of each x axis step, instead of being calculated */
312
+ stepValue?: number;
313
+ /** Whether to draw the x axis and its labels (default true) */
314
+ showAxis?: boolean;
315
+ /** Whether to draw vertical grid lines at each x step (default false) */
316
+ showVLines?: boolean;
317
+ /** An axis title drawn under the x ticks */
318
+ xLabel?: string;
319
+ }
320
+
321
+ /**
322
+ * Scatter marks for a Chart: one circle per `{ x, y }` pair, positioned
323
+ * against a numeric x scale and the Chart's value scale. Also draws the
324
+ * numeric x axis and its vertical grid lines, since the standard axes
325
+ * assume category labels.
326
+ */
327
+ declare function ChartScatter(
328
+ $parent: ParentNode,
329
+ $anchor: Node | null,
330
+ $props: ChartScatterProps | undefined,
331
+ $context?: Record<PropertyKey, any>,
332
+ $slots?: Record<string, SlotRender>,
333
+ ): void;
334
+
335
+
336
+
304
337
  /**
305
338
  * The x axis for a chart. For vertical marks (columns, lines) it runs along
306
339
  * the bottom with each series' label centered under its slot; for
@@ -392,38 +425,6 @@ declare function ColumnChart(
392
425
 
393
426
 
394
427
 
395
- interface GridLinesProps {
396
- /** An ID for the root element */
397
- id?: string;
398
- /** Classes for the root element */
399
- class?: ClassValue;
400
- /** Styles for the root element */
401
- style?: StyleValue;
402
- showHLines?: boolean;
403
- showVLines?: boolean;
404
- width: number;
405
- labels: string[];
406
- xStepValue: number;
407
- xStepLabels: number[];
408
- yStepValue: number;
409
- yStepLabels: number[];
410
- itemWidth: number;
411
- valueHeight: number;
412
- chartLeft: number;
413
- chartBottom: number;
414
- type: string;
415
- }
416
-
417
- declare function GridLines(
418
- $parent: ParentNode,
419
- $anchor: Node | null,
420
- $props: GridLinesProps,
421
- $context?: Record<PropertyKey, any>,
422
- $slots?: Record<string, SlotRender>,
423
- ): void;
424
-
425
-
426
-
427
428
  interface LineChartProps {
428
429
  /** An ID for the root element */
429
430
  id?: string;
@@ -529,6 +530,10 @@ interface ScatterChartProps {
529
530
  showVLines?: boolean;
530
531
  }
531
532
 
533
+ /**
534
+ * A scatter chart preset: one point per `{ x, y }` pair, with a numeric x
535
+ * axis and the standard value axis, laid out by Chart.
536
+ */
532
537
  declare function ScatterChart(
533
538
  $parent: ParentNode,
534
539
  $anchor: Node | null,
@@ -562,49 +567,4 @@ declare function SparkLine(
562
567
  $slots?: Record<string, SlotRender>,
563
568
  ): void;
564
569
 
565
-
566
-
567
- interface XAxisProps {
568
- showAxis: boolean;
569
- height: number;
570
- width: number;
571
- itemWidth: number;
572
- textHeight: number;
573
- xLabel: string;
574
- labels: string[];
575
- stepLabels: number[];
576
- stepValue: number;
577
- chartLeft: number;
578
- chartBottom: number;
579
- }
580
-
581
- declare function XAxis(
582
- $parent: ParentNode,
583
- $anchor: Node | null,
584
- $props: XAxisProps,
585
- $context?: Record<PropertyKey, any>,
586
- $slots?: Record<string, SlotRender>,
587
- ): void;
588
-
589
-
590
-
591
- interface YAxisProps {
592
- showAxis: boolean;
593
- valueHeight: number;
594
- textHeight: number;
595
- yLabel: string;
596
- stepLabels: number[];
597
- stepValue: number;
598
- chartLeft: number;
599
- chartBottom: number;
600
- }
601
-
602
- declare function YAxis(
603
- $parent: ParentNode,
604
- $anchor: Node | null,
605
- $props: YAxisProps,
606
- $context?: Record<PropertyKey, any>,
607
- $slots?: Record<string, SlotRender>,
608
- ): void;
609
-
610
- export { AreaChart, BarChart, Chart, ChartArea, ChartBars, ChartColumns, ChartGrid, ChartLegend, ChartLines, ChartPoints, ChartXAxis, ChartYAxis, ColumnChart, GridLines, LineChart, PieChart, ScatterChart, SparkLine, XAxis, YAxis };
570
+ export { AreaChart, BarChart, Chart, ChartArea, ChartBars, ChartColumns, ChartGrid, ChartLegend, ChartLines, ChartPoints, ChartScatter, ChartXAxis, ChartYAxis, ColumnChart, LineChart, PieChart, ScatterChart, SparkLine };
@@ -8,14 +8,12 @@ import ChartGrid from "./ChartGrid.torp";
8
8
  import ChartLegend from "./ChartLegend.torp";
9
9
  import ChartLines from "./ChartLines.torp";
10
10
  import ChartPoints from "./ChartPoints.torp";
11
+ import ChartScatter from "./ChartScatter.torp";
11
12
  import ChartXAxis from "./ChartXAxis.torp";
12
13
  import ChartYAxis from "./ChartYAxis.torp";
13
14
  import ColumnChart from "./ColumnChart.torp";
14
- import GridLines from "./GridLines.torp";
15
15
  import LineChart from "./LineChart.torp";
16
16
  import PieChart from "./PieChart.torp";
17
17
  import ScatterChart from "./ScatterChart.torp";
18
18
  import SparkLine from "./SparkLine.torp";
19
- import XAxis from "./XAxis.torp";
20
- import YAxis from "./YAxis.torp";
21
- export { AreaChart, BarChart, Chart, ChartArea, ChartBars, ChartColumns, ChartGrid, ChartLegend, ChartLines, ChartPoints, ChartXAxis, ChartYAxis, ColumnChart, GridLines, LineChart, PieChart, ScatterChart, SparkLine, XAxis, YAxis };
19
+ export { AreaChart, BarChart, Chart, ChartArea, ChartBars, ChartColumns, ChartGrid, ChartLegend, ChartLines, ChartPoints, ChartScatter, ChartXAxis, ChartYAxis, ColumnChart, LineChart, PieChart, ScatterChart, SparkLine };