cx 26.1.13 → 26.2.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 (127) hide show
  1. package/build/charts/Marker.d.ts +1 -1
  2. package/build/charts/Marker.d.ts.map +1 -1
  3. package/build/charts/Marker.js +16 -6
  4. package/build/charts/MouseTracker.d.ts +2 -0
  5. package/build/charts/MouseTracker.d.ts.map +1 -1
  6. package/build/charts/helpers/PointReducer.d.ts +2 -2
  7. package/build/charts/helpers/PointReducer.d.ts.map +1 -1
  8. package/build/data/View.d.ts +5 -3
  9. package/build/data/View.d.ts.map +1 -1
  10. package/build/data/View.js +3 -1
  11. package/build/data/ops/findTreeNode.d.ts +20 -1
  12. package/build/data/ops/findTreeNode.d.ts.map +1 -1
  13. package/build/data/ops/findTreeNode.js +19 -0
  14. package/build/data/ops/findTreePath.d.ts +1 -1
  15. package/build/data/ops/findTreePath.d.ts.map +1 -1
  16. package/build/data/ops/findTreePath.js +1 -1
  17. package/build/data/ops/removeTreeNodes.d.ts +14 -1
  18. package/build/data/ops/removeTreeNodes.d.ts.map +1 -1
  19. package/build/data/ops/removeTreeNodes.js +13 -0
  20. package/build/data/ops/updateArray.d.ts +1 -1
  21. package/build/data/ops/updateArray.d.ts.map +1 -1
  22. package/build/data/ops/updateArray.js +1 -1
  23. package/build/data/ops/updateTree.d.ts +20 -1
  24. package/build/data/ops/updateTree.d.ts.map +1 -1
  25. package/build/data/ops/updateTree.js +19 -0
  26. package/build/jsx-runtime.d.ts +1 -0
  27. package/build/jsx-runtime.d.ts.map +1 -1
  28. package/build/jsx-runtime.js +3 -1
  29. package/build/svg/Rectangle.d.ts +6 -4
  30. package/build/svg/Rectangle.d.ts.map +1 -1
  31. package/build/svg/Rectangle.js +9 -7
  32. package/build/ui/Instance.d.ts +1 -1
  33. package/build/ui/Instance.d.ts.map +1 -1
  34. package/build/ui/Instance.js +18 -8
  35. package/build/ui/IsolatedScope.d.ts +2 -1
  36. package/build/ui/IsolatedScope.d.ts.map +1 -1
  37. package/build/ui/Prop.d.ts +1 -1
  38. package/build/ui/Prop.d.ts.map +1 -1
  39. package/build/ui/Widget.d.ts +2 -0
  40. package/build/ui/Widget.d.ts.map +1 -1
  41. package/build/ui/Widget.js +4 -0
  42. package/build/ui/adapter/GroupAdapter.d.ts +4 -4
  43. package/build/ui/adapter/GroupAdapter.d.ts.map +1 -1
  44. package/build/ui/adapter/GroupAdapter.js +4 -4
  45. package/build/ui/adapter/TreeAdapter.d.ts +5 -3
  46. package/build/ui/adapter/TreeAdapter.d.ts.map +1 -1
  47. package/build/ui/adapter/TreeAdapter.js +12 -5
  48. package/build/ui/app/startAppLoop.d.ts +2 -2
  49. package/build/ui/app/startAppLoop.d.ts.map +1 -1
  50. package/build/ui/app/startHotAppLoop.d.ts +4 -4
  51. package/build/ui/app/startHotAppLoop.d.ts.map +1 -1
  52. package/build/ui/app/startHotAppLoop.js +1 -1
  53. package/build/ui/batchUpdates.d.ts.map +1 -1
  54. package/build/ui/batchUpdates.js +3 -4
  55. package/build/widgets/Button.d.ts +0 -7
  56. package/build/widgets/Button.d.ts.map +1 -1
  57. package/build/widgets/HtmlElement.d.ts +2 -2
  58. package/build/widgets/HtmlElement.d.ts.map +1 -1
  59. package/build/widgets/form/Checkbox.d.ts +3 -3
  60. package/build/widgets/form/Checkbox.d.ts.map +1 -1
  61. package/build/widgets/form/Checkbox.js +11 -6
  62. package/build/widgets/form/DateTimeField.d.ts +4 -0
  63. package/build/widgets/form/DateTimeField.d.ts.map +1 -1
  64. package/build/widgets/form/TextField.d.ts +2 -2
  65. package/build/widgets/form/TextField.d.ts.map +1 -1
  66. package/build/widgets/grid/Grid.d.ts +20 -16
  67. package/build/widgets/grid/Grid.d.ts.map +1 -1
  68. package/build/widgets/grid/Grid.js +200 -86
  69. package/build/widgets/nav/Menu.d.ts +2 -0
  70. package/build/widgets/nav/Menu.d.ts.map +1 -1
  71. package/build/widgets/nav/Route.js +1 -1
  72. package/build/widgets/overlay/FlyweightTooltipTracker.d.ts +6 -4
  73. package/build/widgets/overlay/FlyweightTooltipTracker.d.ts.map +1 -1
  74. package/build/widgets/overlay/FlyweightTooltipTracker.js +3 -0
  75. package/build/widgets/overlay/Overlay.d.ts +2 -2
  76. package/build/widgets/overlay/Overlay.d.ts.map +1 -1
  77. package/dist/data.js +52 -1
  78. package/dist/jsx-runtime.js +4 -2
  79. package/dist/manifest.js +910 -904
  80. package/dist/svg.js +3 -0
  81. package/dist/ui.js +1548 -1544
  82. package/dist/widgets.css +1 -1
  83. package/dist/widgets.js +395 -4
  84. package/package.json +2 -2
  85. package/src/charts/Marker.tsx +448 -394
  86. package/src/charts/MouseTracker.tsx +3 -0
  87. package/src/charts/helpers/PointReducer.ts +2 -2
  88. package/src/data/View.ts +76 -19
  89. package/src/data/ops/findTreeNode.ts +20 -1
  90. package/src/data/ops/findTreePath.ts +7 -2
  91. package/src/data/ops/removeTreeNodes.ts +14 -1
  92. package/src/data/ops/updateArray.ts +4 -4
  93. package/src/data/ops/updateTree.ts +32 -6
  94. package/src/index.scss +6 -6
  95. package/src/jsx-runtime.spec.tsx +40 -0
  96. package/src/jsx-runtime.ts +87 -84
  97. package/src/svg/Rectangle.tsx +80 -73
  98. package/src/ui/DataProxy.ts +55 -55
  99. package/src/ui/Instance.ts +142 -45
  100. package/src/ui/IsolatedScope.ts +4 -2
  101. package/src/ui/Prop.ts +141 -141
  102. package/src/ui/Rescope.ts +50 -50
  103. package/src/ui/Widget.tsx +292 -234
  104. package/src/ui/adapter/ArrayAdapter.ts +229 -229
  105. package/src/ui/adapter/GroupAdapter.ts +8 -10
  106. package/src/ui/adapter/TreeAdapter.ts +75 -15
  107. package/src/ui/app/Url.spec.ts +1 -1
  108. package/src/ui/app/startAppLoop.tsx +56 -45
  109. package/src/ui/app/startHotAppLoop.ts +4 -4
  110. package/src/ui/batchUpdates.ts +16 -21
  111. package/src/ui/exprHelpers.ts +96 -96
  112. package/src/widgets/Button.tsx +0 -8
  113. package/src/widgets/HtmlElement.spec.tsx +100 -72
  114. package/src/widgets/HtmlElement.tsx +11 -10
  115. package/src/widgets/Sandbox.ts +104 -104
  116. package/src/widgets/Section.scss +55 -55
  117. package/src/widgets/drag-drop/DropZone.scss +74 -74
  118. package/src/widgets/form/Checkbox.tsx +296 -243
  119. package/src/widgets/form/DateTimeField.tsx +6 -0
  120. package/src/widgets/form/TextField.tsx +2 -2
  121. package/src/widgets/grid/Grid.scss +43 -10
  122. package/src/widgets/grid/Grid.tsx +4401 -3848
  123. package/src/widgets/nav/Menu.tsx +3 -0
  124. package/src/widgets/nav/Route.ts +1 -1
  125. package/src/widgets/overlay/FlyweightTooltipTracker.ts +15 -4
  126. package/src/widgets/overlay/Overlay.tsx +2 -1
  127. package/src/widgets/overlay/index.d.ts +11 -11
@@ -1,372 +1,416 @@
1
1
  /** @jsxImportSource react */
2
2
 
3
3
  import { Widget, VDOM } from "../ui/Widget";
4
- import { BoundedObject, BoundedObjectConfig, BoundedObjectInstance } from "../svg/BoundedObject";
4
+ import {
5
+ BoundedObject,
6
+ BoundedObjectConfig,
7
+ BoundedObjectInstance,
8
+ } from "../svg/BoundedObject";
5
9
  import { Rect } from "../svg/util/Rect";
6
10
  import {
7
- tooltipMouseMove,
8
- tooltipMouseLeave,
9
- tooltipParentWillUnmount,
10
- tooltipParentWillReceiveProps,
11
- tooltipParentDidMount,
12
- tooltipParentDidUpdate,
13
- TooltipParentInstance,
14
- TooltipConfig,
11
+ tooltipMouseMove,
12
+ tooltipMouseLeave,
13
+ tooltipParentWillUnmount,
14
+ tooltipParentWillReceiveProps,
15
+ tooltipParentDidMount,
16
+ tooltipParentDidUpdate,
17
+ TooltipParentInstance,
18
+ TooltipConfig,
15
19
  } from "../widgets/overlay/tooltip-ops";
16
- import { captureMouseOrTouch, getCursorPos } from "../widgets/overlay/captureMouse";
20
+ import {
21
+ captureMouseOrTouch,
22
+ getCursorPos,
23
+ } from "../widgets/overlay/captureMouse";
17
24
  import { closest } from "../util/DOM";
18
25
  import { Selection } from "../ui/selection/Selection";
19
26
  import { getShape } from "./shapes";
20
27
  import { getTopLevelBoundingClientRect } from "../util/getTopLevelBoundingClientRect";
21
28
  import { RenderingContext } from "../ui/RenderingContext";
22
- import { NumberProp, BooleanProp, StringProp, StructuredProp } from "../ui/Prop";
29
+ import {
30
+ NumberProp,
31
+ BooleanProp,
32
+ StringProp,
33
+ StructuredProp,
34
+ } from "../ui/Prop";
23
35
  import { Instance } from "../ui/Instance";
24
36
  import type { ChartRenderingContext } from "./Chart";
25
37
 
26
38
  export interface MarkerConfig extends BoundedObjectConfig {
27
- /** The `x` value binding or expression. */
28
- x?: NumberProp | StringProp;
39
+ /** The `x` value binding or expression. */
40
+ x?: NumberProp | StringProp;
29
41
 
30
- /** The `y` value binding or expression. */
31
- y?: NumberProp;
42
+ /** The `y` value binding or expression. */
43
+ y?: NumberProp | StringProp;
32
44
 
33
- /** Used to indicate if the data should affect axis span. */
34
- affectsAxes?: boolean;
45
+ /** Used to indicate if the data should affect axis span. */
46
+ affectsAxes?: boolean;
35
47
 
36
- /** Shape kind. `circle`, `square`, `triangle`, etc. */
37
- shape?: StringProp;
48
+ /** Shape kind. `circle`, `square`, `triangle`, etc. */
49
+ shape?: StringProp;
38
50
 
39
- /** Disabled state. */
40
- disabled?: BooleanProp;
51
+ /** Disabled state. */
52
+ disabled?: BooleanProp;
41
53
 
42
- /** Index of a color from the standard palette of colors. 0-15. */
43
- colorIndex?: NumberProp | StringProp;
54
+ /** Index of a color from the standard palette of colors. 0-15. */
55
+ colorIndex?: NumberProp | StringProp;
44
56
 
45
- /** Used to automatically assign a color based on the `name` and the contextual `ColorMap` widget. */
46
- colorMap?: StringProp;
57
+ /** Used to automatically assign a color based on the `name` and the contextual `ColorMap` widget. */
58
+ colorMap?: StringProp;
47
59
 
48
- /** Name used to resolve the color. If not provided, `name` is used instead. */
49
- colorName?: StringProp;
60
+ /** Name used to resolve the color. If not provided, `name` is used instead. */
61
+ colorName?: StringProp;
50
62
 
51
- /** Color index to use for the legend entry. */
52
- legendColorIndex?: NumberProp;
63
+ /** Color index to use for the legend entry. */
64
+ legendColorIndex?: NumberProp;
53
65
 
54
- /** Name of the item as it will appear in the legend. */
55
- name?: StringProp;
66
+ /** Name of the item as it will appear in the legend. */
67
+ name?: StringProp;
56
68
 
57
- /** Used to indicate if an item is active or not. Inactive items are shown only in the legend. */
58
- active?: BooleanProp;
69
+ /** Used to indicate if an item is active or not. Inactive items are shown only in the legend. */
70
+ active?: BooleanProp;
59
71
 
60
- /** X offset. */
61
- xOffset?: number;
72
+ /** X offset. */
73
+ xOffset?: number;
62
74
 
63
- /** Y offset. */
64
- yOffset?: number;
75
+ /** Y offset. */
76
+ yOffset?: number;
65
77
 
66
- /** Size of the shape in pixels. */
67
- size?: NumberProp;
78
+ /** Size of the shape in pixels. */
79
+ size?: NumberProp;
68
80
 
69
- /**
70
- * Name of the horizontal axis. The value should match one of the horizontal axes set
71
- * in the `axes` configuration of the parent `Chart` component. Default value is `x`.
72
- */
73
- xAxis?: string;
81
+ /**
82
+ * Name of the horizontal axis. The value should match one of the horizontal axes set
83
+ * in the `axes` configuration of the parent `Chart` component. Default value is `x`.
84
+ */
85
+ xAxis?: string;
74
86
 
75
- /**
76
- * Name of the vertical axis. The value should match one of the vertical axes set
77
- * in the `axes` configuration if the parent `Chart` component. Default value is `y`.
78
- */
79
- yAxis?: string;
87
+ /**
88
+ * Name of the vertical axis. The value should match one of the vertical axes set
89
+ * in the `axes` configuration if the parent `Chart` component. Default value is `y`.
90
+ */
91
+ yAxis?: string;
80
92
 
81
- /** Set to `true` to make the shape draggable along the X axis. */
82
- draggableX?: boolean;
93
+ /** Set to `true` to make the shape draggable along the X axis. */
94
+ draggableX?: boolean;
83
95
 
84
- /** Set to `true` to make the shape draggable along the Y axis. */
85
- draggableY?: boolean;
96
+ /** Set to `true` to make the shape draggable along the Y axis. */
97
+ draggableY?: boolean;
86
98
 
87
- /** Set to `true` to make the shape draggable along the X and Y axis. */
88
- draggable?: boolean;
99
+ /** Set to `true` to make the shape draggable along the X and Y axis. */
100
+ draggable?: boolean;
89
101
 
90
- /** Constrain the marker position to min/max values of the X axis during drag operations. */
91
- constrainX?: boolean;
102
+ /** Constrain the marker position to min/max values of the X axis during drag operations. */
103
+ constrainX?: boolean;
92
104
 
93
- /** Constrain the marker position to min/max values of the Y axis during drag operations. */
94
- constrainY?: boolean;
105
+ /** Constrain the marker position to min/max values of the Y axis during drag operations. */
106
+ constrainY?: boolean;
95
107
 
96
- /** When set to `true`, it is equivalent to setting `constrainX` and `constrainY` to true. */
97
- constrain?: boolean;
108
+ /** When set to `true`, it is equivalent to setting `constrainX` and `constrainY` to true. */
109
+ constrain?: boolean;
98
110
 
99
- /** Name of the legend to be used. Default is `legend`. */
100
- legend?: string;
111
+ /** Name of the legend to be used. Default is `legend`. */
112
+ legend?: string;
101
113
 
102
- /** Action to perform on legend item click. Default is `auto`. */
103
- legendAction?: string;
114
+ /** Action to perform on legend item click. Default is `auto`. */
115
+ legendAction?: string;
104
116
 
105
- /** Tooltip configuration. For more info see Tooltips. */
106
- tooltip?: StringProp | StructuredProp;
117
+ /** Tooltip configuration. For more info see Tooltips. */
118
+ tooltip?: StringProp | StructuredProp;
107
119
 
108
- /** Set to true to hide the marker. The marker will still participate in axis range calculations. */
109
- hidden?: boolean;
120
+ /** Set to true to hide the marker. The marker will still participate in axis range calculations. */
121
+ hidden?: boolean;
110
122
 
111
- /** Indicate that markers should be stacked horizontally. Default value is `false`. */
112
- stackedX?: BooleanProp;
123
+ /** Indicate that markers should be stacked horizontally. Default value is `false`. */
124
+ stackedX?: BooleanProp;
113
125
 
114
- /** Indicate that markers should be stacked vertically. Default value is `false`. */
115
- stackedY?: BooleanProp;
126
+ /** Indicate that markers should be stacked vertically. Default value is `false`. */
127
+ stackedY?: BooleanProp;
116
128
 
117
- /** Name of the stack. If multiple stacks are used, each should have a unique name. Default value is `stack`. */
118
- stack?: StringProp;
129
+ /** Name of the stack. If multiple stacks are used, each should have a unique name. Default value is `stack`. */
130
+ stack?: StringProp;
119
131
 
120
- /**
121
- * Applies to rectangular shapes. The horizontal corner radius of the rect. Defaults to ry if ry is specified.
122
- * Value type: <length>|<percentage>;
123
- * If unit is not specified, it defaults to `px`.
124
- */
125
- rx?: StringProp | NumberProp;
132
+ /**
133
+ * Applies to rectangular shapes. The horizontal corner radius of the rect. Defaults to ry if ry is specified.
134
+ * Value type: <length>|<percentage>;
135
+ * If unit is not specified, it defaults to `px`.
136
+ */
137
+ rx?: StringProp | NumberProp;
126
138
 
127
- /**
128
- * Applies to rectangular shapes. The vertical corner radius of the rect. Defaults to rx if rx is specified.
129
- * Value type: <length>|<percentage>;
130
- * If unit is not specified, it defaults to `px`.
131
- */
132
- ry?: StringProp | NumberProp;
139
+ /**
140
+ * Applies to rectangular shapes. The vertical corner radius of the rect. Defaults to rx if rx is specified.
141
+ * Value type: <length>|<percentage>;
142
+ * If unit is not specified, it defaults to `px`.
143
+ */
144
+ ry?: StringProp | NumberProp;
133
145
 
134
- /** Selection configuration. */
135
- selection?: any;
146
+ /** Selection configuration. */
147
+ selection?: any;
136
148
 
137
- /** Click event handler. */
138
- onClick?: (e: React.MouseEvent, instance: Instance) => void;
149
+ /** Click event handler. */
150
+ onClick?: (e: React.MouseEvent, instance: Instance) => void;
139
151
  }
140
152
 
141
- export interface MarkerInstance extends BoundedObjectInstance, TooltipParentInstance {
142
- axes: Record<string, any>;
143
- xAxis: any;
144
- yAxis: any;
145
- colorMap: any;
153
+ export interface MarkerInstance
154
+ extends BoundedObjectInstance,
155
+ TooltipParentInstance {
156
+ axes: Record<string, any>;
157
+ xAxis: any;
158
+ yAxis: any;
159
+ colorMap: any;
146
160
  }
147
161
 
148
162
  export class Marker extends BoundedObject {
149
- declare baseClass: string;
150
- declare xAxis: string;
151
- declare yAxis: string;
152
- declare xOffset: number;
153
- declare yOffset: number;
154
- declare size: number;
155
- declare draggableX: boolean;
156
- declare draggableY: boolean;
157
- declare draggable: boolean;
158
- declare constrainX: boolean;
159
- declare constrainY: boolean;
160
- declare constrain: boolean;
161
- declare legend: string;
162
- declare legendAction: string;
163
- declare shape: string;
164
- declare hidden: boolean;
165
- declare affectsAxes: boolean;
166
- declare stackedY: boolean;
167
- declare stackedX: boolean;
168
- declare stack: string;
169
- declare selection: Selection;
170
- declare tooltip: TooltipConfig;
171
- declare onClick: MarkerConfig["onClick"];
172
-
173
- constructor(config: MarkerConfig) {
174
- super(config);
175
- }
176
-
177
- init(): void {
178
- this.selection = Selection.create(this.selection);
179
-
180
- if (this.draggable) {
181
- this.draggableX = true;
182
- this.draggableY = true;
183
- }
184
-
185
- if (this.constrain) {
186
- this.constrainX = true;
187
- this.constrainY = true;
188
- }
189
-
190
- super.init();
191
- }
192
-
193
- declareData(...args: any[]): void {
194
- var selection = this.selection.configureWidget(this);
195
-
196
- super.declareData(...args, selection, {
197
- x: undefined,
198
- y: undefined,
199
- size: undefined,
200
- shape: undefined,
201
- disabled: undefined,
202
- colorMap: undefined,
203
- colorIndex: undefined,
204
- colorName: undefined,
205
- legendColorIndex: undefined,
206
- name: undefined,
207
- active: true,
208
- stack: undefined,
209
- stackedX: undefined,
210
- stackedY: undefined,
211
- rx: undefined,
212
- ry: undefined,
213
- });
214
- }
215
-
216
- prepareData(context: RenderingContext, instance: MarkerInstance): void {
217
- instance.axes = context.axes;
218
- instance.xAxis = context.axes[this.xAxis];
219
- instance.yAxis = context.axes[this.yAxis];
220
- let { data } = instance;
221
- data.selected = this.selection.isInstanceSelected(instance);
222
- data.stateMods = {
223
- selected: data.selected,
224
- disabled: data.disabled,
225
- selectable: !this.selection.isDummy,
226
- "draggable-x": this.draggableX && !this.draggableY,
227
- "draggable-y": this.draggableY && !this.draggableX,
228
- "draggable-xy": this.draggableY && this.draggableX,
229
- };
230
- if (data.name && !data.colorName) data.colorName = data.name;
231
- super.prepareData(context, instance);
232
- }
233
-
234
- calculateBounds(context: RenderingContext, instance: MarkerInstance): Rect {
235
- let { data, xAxis, yAxis } = instance;
236
-
237
- let x!: number, y!: number;
238
-
239
- if (data.x == null || data.y == null) {
240
- let bounds = super.calculateBounds(context, instance);
241
- x = (bounds.l + bounds.r) / 2;
242
- y = (bounds.t + bounds.b) / 2;
163
+ declare baseClass: string;
164
+ declare xAxis: string;
165
+ declare yAxis: string;
166
+ declare xOffset: number;
167
+ declare yOffset: number;
168
+ declare size: number;
169
+ declare draggableX: boolean;
170
+ declare draggableY: boolean;
171
+ declare draggable: boolean;
172
+ declare constrainX: boolean;
173
+ declare constrainY: boolean;
174
+ declare constrain: boolean;
175
+ declare legend: string;
176
+ declare legendAction: string;
177
+ declare shape: string;
178
+ declare hidden: boolean;
179
+ declare affectsAxes: boolean;
180
+ declare stackedY: boolean;
181
+ declare stackedX: boolean;
182
+ declare stack: string;
183
+ declare selection: Selection;
184
+ declare tooltip: TooltipConfig;
185
+ declare onClick: MarkerConfig["onClick"];
186
+
187
+ constructor(config: MarkerConfig) {
188
+ super(config);
189
+ }
190
+
191
+ init(): void {
192
+ this.selection = Selection.create(this.selection);
193
+
194
+ if (this.draggable) {
195
+ this.draggableX = true;
196
+ this.draggableY = true;
197
+ }
198
+
199
+ if (this.constrain) {
200
+ this.constrainX = true;
201
+ this.constrainY = true;
202
+ }
203
+
204
+ super.init();
205
+ }
206
+
207
+ declareData(...args: any[]): void {
208
+ var selection = this.selection.configureWidget(this);
209
+
210
+ super.declareData(...args, selection, {
211
+ x: undefined,
212
+ y: undefined,
213
+ size: undefined,
214
+ shape: undefined,
215
+ disabled: undefined,
216
+ colorMap: undefined,
217
+ colorIndex: undefined,
218
+ colorName: undefined,
219
+ legendColorIndex: undefined,
220
+ name: undefined,
221
+ active: true,
222
+ stack: undefined,
223
+ stackedX: undefined,
224
+ stackedY: undefined,
225
+ rx: undefined,
226
+ ry: undefined,
227
+ });
228
+ }
229
+
230
+ prepareData(context: RenderingContext, instance: MarkerInstance): void {
231
+ instance.axes = context.axes;
232
+ instance.xAxis = context.axes[this.xAxis];
233
+ instance.yAxis = context.axes[this.yAxis];
234
+ let { data } = instance;
235
+ data.selected = this.selection.isInstanceSelected(instance);
236
+ data.stateMods = {
237
+ selected: data.selected,
238
+ disabled: data.disabled,
239
+ selectable: !this.selection.isDummy,
240
+ "draggable-x": this.draggableX && !this.draggableY,
241
+ "draggable-y": this.draggableY && !this.draggableX,
242
+ "draggable-xy": this.draggableY && this.draggableX,
243
+ };
244
+ if (data.name && !data.colorName) data.colorName = data.name;
245
+ super.prepareData(context, instance);
246
+ }
247
+
248
+ calculateBounds(context: RenderingContext, instance: MarkerInstance): Rect {
249
+ let { data, xAxis, yAxis } = instance;
250
+
251
+ let x!: number, y!: number;
252
+
253
+ if (data.x == null || data.y == null) {
254
+ let bounds = super.calculateBounds(context, instance);
255
+ x = (bounds.l + bounds.r) / 2;
256
+ y = (bounds.t + bounds.b) / 2;
257
+ }
258
+
259
+ if (data.x != null)
260
+ x = data.stackedX
261
+ ? xAxis.stack(data.stack, data.y, data.x)
262
+ : xAxis.map(data.x);
263
+
264
+ if (data.y != null)
265
+ y = data.stackedY
266
+ ? yAxis.stack(data.stack, data.x, data.y)
267
+ : yAxis.map(data.y);
268
+
269
+ return new Rect({
270
+ l: x - data.size / 2,
271
+ r: x + data.size / 2,
272
+ t: y - data.size / 2,
273
+ b: y + data.size / 2,
274
+ });
275
+ }
276
+
277
+ explore(context: RenderingContext, instance: MarkerInstance): void {
278
+ let { data, xAxis, yAxis } = instance;
279
+
280
+ instance.colorMap =
281
+ data.colorMap &&
282
+ context.getColorMap &&
283
+ context.getColorMap(data.colorMap);
284
+ if (instance.colorMap && data.colorName)
285
+ instance.colorMap.acknowledge(data.colorName);
286
+
287
+ if (data.active) {
288
+ if (this.affectsAxes) {
289
+ if (xAxis && data.x != null) {
290
+ if (data.stackedX) xAxis.stacknowledge(data.stack, data.y, data.x);
291
+ else xAxis.acknowledge(data.x, 0, this.xOffset);
292
+ }
293
+
294
+ if (yAxis && data.y != null) {
295
+ if (data.stackedY) yAxis.stacknowledge(data.stack, data.x, data.y);
296
+ else yAxis.acknowledge(data.y, 0, this.yOffset);
297
+ }
243
298
  }
244
-
245
- if (data.x != null) x = data.stackedX ? xAxis.stack(data.stack, data.y, data.x) : xAxis.map(data.x);
246
-
247
- if (data.y != null) y = data.stackedY ? yAxis.stack(data.stack, data.x, data.y) : yAxis.map(data.y);
248
-
249
- return new Rect({
250
- l: x - data.size / 2,
251
- r: x + data.size / 2,
252
- t: y - data.size / 2,
253
- b: y + data.size / 2,
299
+ super.explore(context, instance);
300
+ }
301
+ }
302
+
303
+ prepare(context: RenderingContext, instance: MarkerInstance): void {
304
+ let { data, xAxis, yAxis, colorMap } = instance;
305
+
306
+ if (colorMap && data.colorName) {
307
+ data.colorIndex = colorMap.map(data.colorName);
308
+ if (instance.cache("colorIndex", data.colorIndex))
309
+ instance.markShouldUpdate(context);
310
+ }
311
+
312
+ if (data.active) {
313
+ if (xAxis && xAxis.shouldUpdate) instance.markShouldUpdate(context);
314
+
315
+ if (yAxis && yAxis.shouldUpdate) instance.markShouldUpdate(context);
316
+
317
+ if (context.pointReducer)
318
+ context.pointReducer(data.x, data.y, data.name, data);
319
+ }
320
+
321
+ super.prepare(context, instance);
322
+
323
+ if (data.name && context.addLegendEntry)
324
+ context.addLegendEntry(this.legend, {
325
+ name: data.name,
326
+ active: data.active,
327
+ colorIndex: data.legendColorIndex || data.colorIndex,
328
+ disabled: data.disabled,
329
+ selected: data.selected,
330
+ style: data.style,
331
+ shape: data.shape,
332
+ onClick: (e: MouseEvent) => {
333
+ this.onLegendClick(e, instance);
334
+ },
254
335
  });
255
- }
256
-
257
- explore(context: RenderingContext, instance: MarkerInstance): void {
258
- let { data, xAxis, yAxis } = instance;
259
-
260
- instance.colorMap = data.colorMap && context.getColorMap && context.getColorMap(data.colorMap);
261
- if (instance.colorMap && data.colorName) instance.colorMap.acknowledge(data.colorName);
262
-
263
- if (data.active) {
264
- if (this.affectsAxes) {
265
- if (xAxis && data.x != null) {
266
- if (data.stackedX) xAxis.stacknowledge(data.stack, data.y, data.x);
267
- else xAxis.acknowledge(data.x, 0, this.xOffset);
268
- }
269
-
270
- if (yAxis && data.y != null) {
271
- if (data.stackedY) yAxis.stacknowledge(data.stack, data.x, data.y);
272
- else yAxis.acknowledge(data.y, 0, this.yOffset);
273
- }
274
- }
275
- super.explore(context, instance);
276
- }
277
- }
278
-
279
- prepare(context: RenderingContext, instance: MarkerInstance): void {
280
- let { data, xAxis, yAxis, colorMap } = instance;
281
-
282
- if (colorMap && data.colorName) {
283
- data.colorIndex = colorMap.map(data.colorName);
284
- if (instance.cache("colorIndex", data.colorIndex)) instance.markShouldUpdate(context);
285
- }
286
-
287
- if (data.active) {
288
- if (xAxis && xAxis.shouldUpdate) instance.markShouldUpdate(context);
289
-
290
- if (yAxis && yAxis.shouldUpdate) instance.markShouldUpdate(context);
291
-
292
- if (context.pointReducer) context.pointReducer(data.x, data.y, data.name, data);
293
- }
294
-
295
- super.prepare(context, instance);
296
-
297
- if (data.name && context.addLegendEntry)
298
- context.addLegendEntry(this.legend, {
299
- name: data.name,
300
- active: data.active,
301
- colorIndex: data.legendColorIndex || data.colorIndex,
302
- disabled: data.disabled,
303
- selected: data.selected,
304
- style: data.style,
305
- shape: data.shape,
306
- onClick: (e: MouseEvent) => {
307
- this.onLegendClick(e, instance);
308
- },
309
- });
310
- }
311
-
312
- onLegendClick(e: MouseEvent, instance: MarkerInstance): void {
313
- let allActions = this.legendAction == "auto";
314
- let { data } = instance;
315
- if (allActions || this.legendAction == "toggle") if (instance.set("active", !data.active)) return;
316
-
317
- if (allActions || this.legendAction == "select") this.handleClick(e as unknown as React.MouseEvent, instance);
318
- }
319
-
320
- render(context: RenderingContext, instance: MarkerInstance, key: string): React.ReactNode {
321
- let { data } = instance;
322
-
323
- if (!data.active || data.x === null || data.y === null) return null;
324
-
325
- return (
326
- <MarkerComponent key={key} instance={instance} data={instance.data} shouldUpdate={instance.shouldUpdate}>
327
- {this.renderChildren(context, instance)}
328
- </MarkerComponent>
329
- );
330
- }
331
-
332
- handleMouseDown(e: React.MouseEvent | React.TouchEvent, instance: MarkerInstance): void {
333
- if (this.draggableX || this.draggableY) {
334
- let svgEl = closest(e.target as Element, (el) => el.tagName == "svg");
335
- if (svgEl)
336
- captureMouseOrTouch(
337
- e,
338
- (e, captureData) => {
339
- this.handleDragMove(e, instance, captureData);
340
- },
341
- undefined,
342
- { svgEl, el: e.target },
343
- (e.target as HTMLElement).style.cursor
344
- );
345
- } else {
346
- if (!this.selection.isDummy) this.selection.selectInstance(instance);
347
- }
348
- }
349
-
350
- handleClick(e: React.MouseEvent, instance: MarkerInstance): void {
351
- if (this.onClick) instance.invoke("onClick", e, instance);
352
- }
353
-
354
- handleDragMove(e: MouseEvent | TouchEvent, instance: MarkerInstance, captureData: any): void {
355
- let cursor = getCursorPos(e);
356
- let svgBounds = getTopLevelBoundingClientRect(captureData.svgEl);
357
- let { xAxis, yAxis } = instance;
358
- if (this.draggableX && xAxis) {
359
- let x = xAxis.trackValue(cursor.clientX - svgBounds.left, this.xOffset);
360
- if (this.constrainX) x = xAxis.constrainValue(x);
361
- instance.set("x", xAxis.encodeValue(x));
362
- }
363
- if (this.draggableY && yAxis) {
364
- let y = yAxis.trackValue(cursor.clientY - svgBounds.top, this.yOffset);
365
- if (this.constrainY) y = yAxis.constrainValue(y);
366
- instance.set("y", yAxis.encodeValue(y));
367
- }
368
- tooltipMouseMove(e, instance, this.tooltip, { target: captureData.el });
369
- }
336
+ }
337
+
338
+ onLegendClick(e: MouseEvent, instance: MarkerInstance): void {
339
+ let allActions = this.legendAction == "auto";
340
+ let { data } = instance;
341
+ if (allActions || this.legendAction == "toggle")
342
+ if (instance.set("active", !data.active)) return;
343
+
344
+ if (allActions || this.legendAction == "select")
345
+ this.handleClick(e as unknown as React.MouseEvent, instance);
346
+ }
347
+
348
+ render(
349
+ context: RenderingContext,
350
+ instance: MarkerInstance,
351
+ key: string,
352
+ ): React.ReactNode {
353
+ let { data } = instance;
354
+
355
+ if (!data.active || data.x === null || data.y === null) return null;
356
+
357
+ return (
358
+ <MarkerComponent
359
+ key={key}
360
+ instance={instance}
361
+ data={instance.data}
362
+ shouldUpdate={instance.shouldUpdate}
363
+ >
364
+ {this.renderChildren(context, instance)}
365
+ </MarkerComponent>
366
+ );
367
+ }
368
+
369
+ handleMouseDown(
370
+ e: React.MouseEvent | React.TouchEvent,
371
+ instance: MarkerInstance,
372
+ ): void {
373
+ if (this.draggableX || this.draggableY) {
374
+ let svgEl = closest(e.target as Element, (el) => el.tagName == "svg");
375
+ if (svgEl)
376
+ captureMouseOrTouch(
377
+ e,
378
+ (e, captureData) => {
379
+ this.handleDragMove(e, instance, captureData);
380
+ },
381
+ undefined,
382
+ { svgEl, el: e.target },
383
+ (e.target as HTMLElement).style.cursor,
384
+ );
385
+ } else {
386
+ if (!this.selection.isDummy) this.selection.selectInstance(instance);
387
+ }
388
+ }
389
+
390
+ handleClick(e: React.MouseEvent, instance: MarkerInstance): void {
391
+ if (this.onClick) instance.invoke("onClick", e, instance);
392
+ }
393
+
394
+ handleDragMove(
395
+ e: MouseEvent | TouchEvent,
396
+ instance: MarkerInstance,
397
+ captureData: any,
398
+ ): void {
399
+ let cursor = getCursorPos(e);
400
+ let svgBounds = getTopLevelBoundingClientRect(captureData.svgEl);
401
+ let { xAxis, yAxis } = instance;
402
+ if (this.draggableX && xAxis) {
403
+ let x = xAxis.trackValue(cursor.clientX - svgBounds.left, this.xOffset);
404
+ if (this.constrainX) x = xAxis.constrainValue(x);
405
+ instance.set("x", xAxis.encodeValue(x));
406
+ }
407
+ if (this.draggableY && yAxis) {
408
+ let y = yAxis.trackValue(cursor.clientY - svgBounds.top, this.yOffset);
409
+ if (this.constrainY) y = yAxis.constrainValue(y);
410
+ instance.set("y", yAxis.encodeValue(y));
411
+ }
412
+ tooltipMouseMove(e, instance, this.tooltip, { target: captureData.el });
413
+ }
370
414
  }
371
415
 
372
416
  Marker.prototype.xOffset = 0;
@@ -397,87 +441,97 @@ Marker.prototype.stack = "stack";
397
441
  BoundedObject.alias("marker", Marker);
398
442
 
399
443
  interface MarkerComponentProps {
400
- instance: MarkerInstance;
401
- data: any;
402
- shouldUpdate?: boolean;
403
- children?: React.ReactNode;
444
+ instance: MarkerInstance;
445
+ data: any;
446
+ shouldUpdate?: boolean;
447
+ children?: React.ReactNode;
404
448
  }
405
449
 
406
450
  class MarkerComponent extends VDOM.Component<MarkerComponentProps> {
407
- declare el: SVGElement | null;
408
-
409
- shouldComponentUpdate(props: MarkerComponentProps): boolean {
410
- return props.shouldUpdate ?? true;
411
- }
412
-
413
- render(): React.ReactNode {
414
- let { instance, children, data } = this.props;
415
- let widget = instance.widget as Marker;
416
- let { CSS, baseClass } = widget;
417
- let { bounds, shape } = data;
418
- let shapeRenderer = getShape(shape);
419
- let shapeProps: Record<string, any> = {
420
- className: CSS.element(baseClass, "shape", {
421
- ["color-" + data.colorIndex]: data.colorIndex != null,
422
- selected: data.selected,
423
- }),
424
- style: data.style,
425
- cx: (bounds.l + bounds.r) / 2,
426
- cy: (bounds.t + bounds.b) / 2,
427
- r: data.size / 2,
428
- onMouseMove: (e: React.MouseEvent) => {
429
- tooltipMouseMove(e, instance, widget.tooltip);
430
- },
431
- onMouseLeave: (e: React.MouseEvent) => {
432
- tooltipMouseLeave(e, instance, widget.tooltip);
433
- },
434
- onMouseDown: (e: React.MouseEvent) => {
435
- widget.handleMouseDown(e, instance);
436
- },
437
- onTouchStart: (e: React.TouchEvent) => {
438
- widget.handleMouseDown(e, instance);
439
- },
440
- onClick: (e: React.MouseEvent) => {
441
- widget.handleClick(e, instance);
442
- },
451
+ declare el: SVGElement | null;
452
+
453
+ shouldComponentUpdate(props: MarkerComponentProps): boolean {
454
+ return props.shouldUpdate ?? true;
455
+ }
456
+
457
+ render(): React.ReactNode {
458
+ let { instance, children, data } = this.props;
459
+ let widget = instance.widget as Marker;
460
+ let { CSS, baseClass } = widget;
461
+ let { bounds, shape } = data;
462
+ let shapeRenderer = getShape(shape);
463
+ let shapeProps: Record<string, any> = {
464
+ className: CSS.element(baseClass, "shape", {
465
+ ["color-" + data.colorIndex]: data.colorIndex != null,
466
+ selected: data.selected,
467
+ }),
468
+ style: data.style,
469
+ cx: (bounds.l + bounds.r) / 2,
470
+ cy: (bounds.t + bounds.b) / 2,
471
+ r: data.size / 2,
472
+ onMouseMove: (e: React.MouseEvent) => {
473
+ tooltipMouseMove(e, instance, widget.tooltip);
474
+ },
475
+ onMouseLeave: (e: React.MouseEvent) => {
476
+ tooltipMouseLeave(e, instance, widget.tooltip);
477
+ },
478
+ onMouseDown: (e: React.MouseEvent) => {
479
+ widget.handleMouseDown(e, instance);
480
+ },
481
+ onTouchStart: (e: React.TouchEvent) => {
482
+ widget.handleMouseDown(e, instance);
483
+ },
484
+ onClick: (e: React.MouseEvent) => {
485
+ widget.handleClick(e, instance);
486
+ },
487
+ };
488
+
489
+ if (
490
+ shape == "rect" ||
491
+ shape == "square" ||
492
+ shape == "bar" ||
493
+ shape == "column"
494
+ ) {
495
+ shapeProps.rx = data.rx;
496
+ shapeProps.ry = data.ry;
497
+ }
498
+
499
+ if (widget.tooltip) {
500
+ shapeProps.ref = (c: SVGElement | null) => {
501
+ this.el = c;
443
502
  };
444
-
445
- if (shape == "rect" || shape == "square" || shape == "bar" || shape == "column") {
446
- shapeProps.rx = data.rx;
447
- shapeProps.ry = data.ry;
448
- }
449
-
450
- if (widget.tooltip) {
451
- shapeProps.ref = (c: SVGElement | null) => {
452
- this.el = c;
453
- };
454
- }
455
-
456
- return (
457
- <g className={data.classNames}>
458
- {!widget.hidden &&
459
- shapeRenderer((bounds.l + bounds.r) / 2, (bounds.t + bounds.b) / 2, data.size, shapeProps)}
460
- {children}
461
- </g>
462
- );
463
- }
464
-
465
- componentWillUnmount(): void {
466
- tooltipParentWillUnmount(this.props.instance);
467
- }
468
-
469
- UNSAFE_componentWillReceiveProps(props: MarkerComponentProps): void {
470
- let widget = props.instance.widget as Marker;
471
- tooltipParentWillReceiveProps(this.el!, props.instance, widget.tooltip);
472
- }
473
-
474
- componentDidMount(): void {
475
- let widget = this.props.instance.widget as Marker;
476
- tooltipParentDidMount(this.el!, this.props.instance, widget.tooltip);
477
- }
478
-
479
- componentDidUpdate(): void {
480
- let widget = this.props.instance.widget as Marker;
481
- tooltipParentDidUpdate(this.el!, this.props.instance, widget.tooltip);
482
- }
503
+ }
504
+
505
+ return (
506
+ <g className={data.classNames}>
507
+ {!widget.hidden &&
508
+ shapeRenderer(
509
+ (bounds.l + bounds.r) / 2,
510
+ (bounds.t + bounds.b) / 2,
511
+ data.size,
512
+ shapeProps,
513
+ )}
514
+ {children}
515
+ </g>
516
+ );
517
+ }
518
+
519
+ componentWillUnmount(): void {
520
+ tooltipParentWillUnmount(this.props.instance);
521
+ }
522
+
523
+ UNSAFE_componentWillReceiveProps(props: MarkerComponentProps): void {
524
+ let widget = props.instance.widget as Marker;
525
+ tooltipParentWillReceiveProps(this.el!, props.instance, widget.tooltip);
526
+ }
527
+
528
+ componentDidMount(): void {
529
+ let widget = this.props.instance.widget as Marker;
530
+ tooltipParentDidMount(this.el!, this.props.instance, widget.tooltip);
531
+ }
532
+
533
+ componentDidUpdate(): void {
534
+ let widget = this.props.instance.widget as Marker;
535
+ tooltipParentDidUpdate(this.el!, this.props.instance, widget.tooltip);
536
+ }
483
537
  }