tinybase 8.5.0-beta.2 → 8.5.0-beta.4

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 (151) hide show
  1. package/@types/ui-react-dom-charts/index.d.ts +369 -49
  2. package/@types/ui-react-dom-charts/with-schemas/index.d.ts +396 -70
  3. package/common/index.js +1 -1
  4. package/common/with-schemas/index.js +1 -1
  5. package/index.js +3 -2
  6. package/mergeable-store/index.js +3 -2
  7. package/mergeable-store/with-schemas/index.js +3 -2
  8. package/min/index.js +1 -1
  9. package/min/index.js.gz +0 -0
  10. package/min/mergeable-store/index.js +1 -1
  11. package/min/mergeable-store/index.js.gz +0 -0
  12. package/min/mergeable-store/with-schemas/index.js +1 -1
  13. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  14. package/min/omni/index.js +1 -1
  15. package/min/omni/index.js.gz +0 -0
  16. package/min/omni/with-schemas/index.js +1 -1
  17. package/min/omni/with-schemas/index.js.gz +0 -0
  18. package/min/persisters/index.js +1 -1
  19. package/min/persisters/index.js.gz +0 -0
  20. package/min/persisters/persister-cr-sqlite-wasm/index.js +1 -1
  21. package/min/persisters/persister-cr-sqlite-wasm/index.js.gz +0 -0
  22. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +1 -1
  23. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js.gz +0 -0
  24. package/min/persisters/persister-durable-object-sql-storage/index.js +1 -1
  25. package/min/persisters/persister-durable-object-sql-storage/index.js.gz +0 -0
  26. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js +1 -1
  27. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js.gz +0 -0
  28. package/min/persisters/persister-electric-sql/index.js +1 -1
  29. package/min/persisters/persister-electric-sql/index.js.gz +0 -0
  30. package/min/persisters/persister-electric-sql/with-schemas/index.js +1 -1
  31. package/min/persisters/persister-electric-sql/with-schemas/index.js.gz +0 -0
  32. package/min/persisters/persister-expo-sqlite/index.js +1 -1
  33. package/min/persisters/persister-expo-sqlite/index.js.gz +0 -0
  34. package/min/persisters/persister-expo-sqlite/with-schemas/index.js +1 -1
  35. package/min/persisters/persister-expo-sqlite/with-schemas/index.js.gz +0 -0
  36. package/min/persisters/persister-libsql/index.js +1 -1
  37. package/min/persisters/persister-libsql/index.js.gz +0 -0
  38. package/min/persisters/persister-libsql/with-schemas/index.js +1 -1
  39. package/min/persisters/persister-libsql/with-schemas/index.js.gz +0 -0
  40. package/min/persisters/persister-pglite/index.js +1 -1
  41. package/min/persisters/persister-pglite/index.js.gz +0 -0
  42. package/min/persisters/persister-pglite/with-schemas/index.js +1 -1
  43. package/min/persisters/persister-pglite/with-schemas/index.js.gz +0 -0
  44. package/min/persisters/persister-postgres/index.js +1 -1
  45. package/min/persisters/persister-postgres/index.js.gz +0 -0
  46. package/min/persisters/persister-postgres/with-schemas/index.js +1 -1
  47. package/min/persisters/persister-postgres/with-schemas/index.js.gz +0 -0
  48. package/min/persisters/persister-powersync/index.js +1 -1
  49. package/min/persisters/persister-powersync/index.js.gz +0 -0
  50. package/min/persisters/persister-powersync/with-schemas/index.js +1 -1
  51. package/min/persisters/persister-powersync/with-schemas/index.js.gz +0 -0
  52. package/min/persisters/persister-react-native-sqlite/index.js +1 -1
  53. package/min/persisters/persister-react-native-sqlite/index.js.gz +0 -0
  54. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js +1 -1
  55. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js.gz +0 -0
  56. package/min/persisters/persister-remote/index.js +1 -1
  57. package/min/persisters/persister-remote/index.js.gz +0 -0
  58. package/min/persisters/persister-remote/with-schemas/index.js +1 -1
  59. package/min/persisters/persister-remote/with-schemas/index.js.gz +0 -0
  60. package/min/persisters/persister-sqlite-bun/index.js +1 -1
  61. package/min/persisters/persister-sqlite-bun/index.js.gz +0 -0
  62. package/min/persisters/persister-sqlite-bun/with-schemas/index.js +1 -1
  63. package/min/persisters/persister-sqlite-bun/with-schemas/index.js.gz +0 -0
  64. package/min/persisters/persister-sqlite-wasm/index.js +1 -1
  65. package/min/persisters/persister-sqlite-wasm/index.js.gz +0 -0
  66. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js +1 -1
  67. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js.gz +0 -0
  68. package/min/persisters/persister-sqlite3/index.js +1 -1
  69. package/min/persisters/persister-sqlite3/index.js.gz +0 -0
  70. package/min/persisters/persister-sqlite3/with-schemas/index.js +1 -1
  71. package/min/persisters/persister-sqlite3/with-schemas/index.js.gz +0 -0
  72. package/min/persisters/with-schemas/index.js +1 -1
  73. package/min/persisters/with-schemas/index.js.gz +0 -0
  74. package/min/synchronizers/index.js +1 -1
  75. package/min/synchronizers/index.js.gz +0 -0
  76. package/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -1
  77. package/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
  78. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -1
  79. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
  80. package/min/synchronizers/synchronizer-local/index.js +1 -1
  81. package/min/synchronizers/synchronizer-local/index.js.gz +0 -0
  82. package/min/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
  83. package/min/synchronizers/synchronizer-local/with-schemas/index.js.gz +0 -0
  84. package/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  85. package/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  86. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  87. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  88. package/min/synchronizers/synchronizer-ws-server/index.js +1 -1
  89. package/min/synchronizers/synchronizer-ws-server/index.js.gz +0 -0
  90. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js +1 -1
  91. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js.gz +0 -0
  92. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
  93. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
  94. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
  95. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
  96. package/min/synchronizers/with-schemas/index.js +1 -1
  97. package/min/synchronizers/with-schemas/index.js.gz +0 -0
  98. package/min/ui-react-dom-charts/index.js +1 -1
  99. package/min/ui-react-dom-charts/index.js.gz +0 -0
  100. package/min/ui-react-dom-charts/with-schemas/index.js +1 -1
  101. package/min/ui-react-dom-charts/with-schemas/index.js.gz +0 -0
  102. package/min/with-schemas/index.js +1 -1
  103. package/min/with-schemas/index.js.gz +0 -0
  104. package/omni/index.js +7 -6
  105. package/omni/with-schemas/index.js +7 -6
  106. package/package.json +10 -10
  107. package/persisters/index.js +1 -1
  108. package/persisters/persister-cr-sqlite-wasm/index.js +1 -1
  109. package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +1 -1
  110. package/persisters/persister-durable-object-sql-storage/index.js +1 -1
  111. package/persisters/persister-durable-object-sql-storage/with-schemas/index.js +1 -1
  112. package/persisters/persister-electric-sql/index.js +1 -1
  113. package/persisters/persister-electric-sql/with-schemas/index.js +1 -1
  114. package/persisters/persister-expo-sqlite/index.js +1 -1
  115. package/persisters/persister-expo-sqlite/with-schemas/index.js +1 -1
  116. package/persisters/persister-libsql/index.js +1 -1
  117. package/persisters/persister-libsql/with-schemas/index.js +1 -1
  118. package/persisters/persister-pglite/index.js +1 -1
  119. package/persisters/persister-pglite/with-schemas/index.js +1 -1
  120. package/persisters/persister-postgres/index.js +1 -1
  121. package/persisters/persister-postgres/with-schemas/index.js +1 -1
  122. package/persisters/persister-powersync/index.js +1 -1
  123. package/persisters/persister-powersync/with-schemas/index.js +1 -1
  124. package/persisters/persister-react-native-sqlite/index.js +1 -1
  125. package/persisters/persister-react-native-sqlite/with-schemas/index.js +1 -1
  126. package/persisters/persister-remote/index.js +3 -3
  127. package/persisters/persister-remote/with-schemas/index.js +3 -3
  128. package/persisters/persister-sqlite-bun/index.js +1 -1
  129. package/persisters/persister-sqlite-bun/with-schemas/index.js +1 -1
  130. package/persisters/persister-sqlite-wasm/index.js +1 -1
  131. package/persisters/persister-sqlite-wasm/with-schemas/index.js +1 -1
  132. package/persisters/persister-sqlite3/index.js +1 -1
  133. package/persisters/persister-sqlite3/with-schemas/index.js +1 -1
  134. package/persisters/with-schemas/index.js +1 -1
  135. package/readme.md +13 -13
  136. package/releases.md +57 -57
  137. package/synchronizers/index.js +2 -1
  138. package/synchronizers/synchronizer-broadcast-channel/index.js +2 -1
  139. package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +2 -1
  140. package/synchronizers/synchronizer-local/index.js +2 -1
  141. package/synchronizers/synchronizer-local/with-schemas/index.js +2 -1
  142. package/synchronizers/synchronizer-ws-client/index.js +2 -1
  143. package/synchronizers/synchronizer-ws-client/with-schemas/index.js +2 -1
  144. package/synchronizers/synchronizer-ws-server/index.js +2 -1
  145. package/synchronizers/synchronizer-ws-server/with-schemas/index.js +2 -1
  146. package/synchronizers/synchronizer-ws-server-durable-object/index.js +2 -1
  147. package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +2 -1
  148. package/synchronizers/with-schemas/index.js +2 -1
  149. package/ui-react-dom-charts/index.js +753 -306
  150. package/ui-react-dom-charts/with-schemas/index.js +753 -306
  151. package/with-schemas/index.js +3 -2
@@ -6,6 +6,7 @@ const TINYBASE = 'tinybase';
6
6
  const EMPTY_STRING = '';
7
7
  const STRING = getTypeOf(EMPTY_STRING);
8
8
  const NUMBER = getTypeOf(0);
9
+ const FUNCTION = getTypeOf(getTypeOf);
9
10
  const LISTENER = 'Listener';
10
11
  const RESULT = 'Result';
11
12
  const GET = 'get';
@@ -16,6 +17,7 @@ const SORTED_ROW_IDS = 'Sorted' + ROW + IDS;
16
17
  const CELL = 'Cell';
17
18
 
18
19
  const math = Math;
20
+ const date = Date;
19
21
  const getIfNotFunction = (predicate) => (value, then, otherwise) =>
20
22
  predicate(value)
21
23
  ? /* istanbul ignore next */
@@ -32,12 +34,21 @@ const mathPow = math.pow;
32
34
  const mathRound = math.round;
33
35
  const mathAbs = math.abs;
34
36
  const mathLog10 = math.log10;
37
+ const dateUtc = date.UTC;
35
38
  const infinity = Infinity;
36
39
  const epsilon = Number.EPSILON;
37
40
  const isFiniteNumber = isFinite;
38
41
  const isInteger = number.isInteger;
39
42
  const isNullish = (thing) => thing == null;
40
43
  const isUndefined = (thing) => thing === void 0;
44
+ const dateNew = (value) => (isUndefined(value) ? new date() : new date(value));
45
+ const dateGetUTCFullYear = (dateObj) => dateObj.getUTCFullYear();
46
+ const dateGetUTCMonth = (dateObj) => dateObj.getUTCMonth();
47
+ const dateGetUTCDate = (dateObj) => dateObj.getUTCDate();
48
+ const dateGetUTCDay = (dateObj) => dateObj.getUTCDay();
49
+ const dateGetUTCHours = (dateObj) => dateObj.getUTCHours();
50
+ const dateGetUTCMinutes = (dateObj) => dateObj.getUTCMinutes();
51
+ const dateGetUTCSeconds = (dateObj) => dateObj.getUTCSeconds();
41
52
  const isNull = (thing) => thing === null;
42
53
  const isTrue = (thing) => thing === true;
43
54
  const isFalse = (thing) => thing === false;
@@ -45,9 +56,34 @@ const ifNotNullish = getIfNotFunction(isNullish);
45
56
  const ifNotUndefined = getIfNotFunction(isUndefined);
46
57
  const isString = (thing) => getTypeOf(thing) == STRING;
47
58
  const isNumber = (thing) => getTypeOf(thing) == NUMBER;
59
+ const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
48
60
  const isArray = (thing) => Array.isArray(thing);
49
61
  const size = (arrayOrString) => arrayOrString.length;
50
62
  const test = (regex, subject) => regex.test(subject);
63
+ const errorNew = (message) => {
64
+ throw new Error(message);
65
+ };
66
+
67
+ const arrayNew = (size2, cb) =>
68
+ arrayMap(new Array(size2).fill(0), (_, index) => cb(index));
69
+ const arrayHas = (array, value) => array.includes(value);
70
+ const arrayIndexOf = (array, value) => array.indexOf(value);
71
+ const arrayEvery = (array, cb) => array.every(cb);
72
+ const arrayIsEqual = (array1, array2) =>
73
+ size(array1) === size(array2) &&
74
+ arrayEvery(array1, (value1, index) => array2[index] === value1);
75
+ const arrayOrValueEqual = (value1, value2) =>
76
+ isArray(value1) && isArray(value2)
77
+ ? arrayIsEqual(value1, value2)
78
+ : value1 === value2;
79
+ const arraySort = (array, sorter) => array.sort(sorter);
80
+ const arrayForEach = (array, cb) => array.forEach(cb);
81
+ const arrayJoin = (array, sep = EMPTY_STRING) => array.join(sep);
82
+ const arrayMap = (array, cb) => array.map(cb);
83
+ const arrayIsEmpty = (array) => size(array) == 0;
84
+ const arrayFilter = (array, cb) => array.filter(cb);
85
+ const arrayPush = (array, ...values) => array.push(...values);
86
+ const arrayShift = (array) => array.shift();
51
87
 
52
88
  const {
53
89
  Children,
@@ -65,48 +101,136 @@ const {
65
101
  useSyncExternalStore,
66
102
  } = React;
67
103
 
104
+ const CATEGORY = 'category';
105
+ const LINEAR = 'linear';
106
+ const TIME = 'time';
107
+ const MILLISECOND = 'millisecond';
108
+ const SECOND_UNIT = 'second';
109
+ const BAR = 'bar';
110
+ const LINE = 'line';
111
+ const CURRENT_COLOR = 'currentColor';
112
+ const SERIES = '_tinybaseChartSeries';
113
+ const X_AXIS = '_tinybaseChartXAxis';
114
+ const Y_AXIS = '_tinybaseChartYAxis';
115
+
68
116
  var SourceType = /* @__PURE__ */ ((SourceType2) => {
69
117
  SourceType2[(SourceType2['None'] = 0)] = 'None';
70
118
  SourceType2[(SourceType2['Query'] = 1)] = 'Query';
71
119
  SourceType2[(SourceType2['Table'] = 2)] = 'Table';
72
120
  return SourceType2;
73
121
  })(SourceType || {});
74
- const CHART_SERIES = '_tinybaseChartSeries';
75
- const isChartSeriesComponent = (component) =>
76
- typeof component == 'function' && component[CHART_SERIES] === true;
122
+ const isSeriesComponent = (component) =>
123
+ isFunction(component) && component[SERIES] === true;
124
+ const isXAxisComponent = (component) =>
125
+ isFunction(component) && component[X_AXIS] === true;
126
+ const isYAxisComponent = (component) =>
127
+ isFunction(component) && component[Y_AXIS] === true;
77
128
  const CartesianChartContext = createContext(null);
78
129
  const useCartesianChartContext = () => {
79
130
  const context = useContext(CartesianChartContext);
80
- if (context == null) {
81
- throw new Error('Series components must be used inside a CartesianChart');
131
+ if (isNullish(context)) {
132
+ errorNew('Series components must be used inside a CartesianChart');
82
133
  }
83
134
  return context;
84
135
  };
85
136
 
86
- const arrayNew = (size2, cb) =>
87
- arrayMap(new Array(size2).fill(0), (_, index) => cb(index));
88
- const arrayHas = (array, value) => array.includes(value);
89
- const arrayIndexOf = (array, value) => array.indexOf(value);
90
- const arrayEvery = (array, cb) => array.every(cb);
91
- const arrayIsEqual = (array1, array2) =>
92
- size(array1) === size(array2) &&
93
- arrayEvery(array1, (value1, index) => array2[index] === value1);
94
- const arrayOrValueEqual = (value1, value2) =>
95
- isArray(value1) && isArray(value2)
96
- ? arrayIsEqual(value1, value2)
97
- : value1 === value2;
98
- const arrayForEach = (array, cb) => array.forEach(cb);
99
- const arrayJoin = (array, sep = EMPTY_STRING) => array.join(sep);
100
- const arrayMap = (array, cb) => array.map(cb);
101
- const arrayIsEmpty = (array) => size(array) == 0;
102
- const arrayFilter = (array, cb) => array.filter(cb);
103
- const arrayPush = (array, ...values) => array.push(...values);
104
- const arrayShift = (array) => array.shift();
105
-
106
137
  const collSize = (coll) => coll?.size ?? 0;
138
+ const collHas = (coll, keyOrValue) => coll?.has(keyOrValue) ?? false;
139
+ const collDel = (coll, keyOrValue) => coll?.delete(keyOrValue);
140
+
141
+ const object = Object;
142
+ const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
143
+ const objEntries = object.entries;
144
+ const isObject = (obj) =>
145
+ !isNullish(obj) &&
146
+ ifNotNullish(
147
+ getPrototypeOf(obj),
148
+ (objPrototype) =>
149
+ objPrototype == object.prototype ||
150
+ isNullish(getPrototypeOf(objPrototype)),
151
+
152
+ /* istanbul ignore next */
153
+ () => true,
154
+ );
155
+ const objIds = object.keys;
156
+ const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
157
+ const objValues = (obj) => object.values(obj);
158
+ const objSize = (obj) => size(objIds(obj));
107
159
 
160
+ /* istanbul ignore next */
161
+ const objIsEqual = (
162
+ obj1,
163
+ obj2,
164
+ isEqual = (value1, value2) => value1 === value2,
165
+ ) => {
166
+ const entries1 = objEntries(obj1);
167
+ return (
168
+ size(entries1) === objSize(obj2) &&
169
+ arrayEvery(entries1, ([index, value1]) =>
170
+ isObject(value1)
171
+ ? /* istanbul ignore next */
172
+ isObject(obj2[index])
173
+ ? objIsEqual(obj2[index], value1, isEqual)
174
+ : false
175
+ : isEqual(value1, obj2[index]),
176
+ )
177
+ );
178
+ };
179
+
180
+ const map = Map;
181
+ const mapNew = (entries) => new map(entries);
182
+ const mapGet = (map2, key) => map2?.get(key);
183
+ const mapSet = (map2, key, value) =>
184
+ isUndefined(value) ? (collDel(map2, key), map2) : map2?.set(key, value);
185
+
186
+ const TARGET_TICKS = 10;
108
187
  const NICE_NUMBERS = [1, 5, 2, 2.5, 4, 3];
109
188
  const WEIGHTS = [0.25, 0.2, 0.5, 0.05];
189
+ const SECOND = 1e3;
190
+ const MINUTE = 60 * SECOND;
191
+ const HOUR = 60 * MINUTE;
192
+ const DAY = 24 * HOUR;
193
+ const MONTH = 30 * DAY;
194
+ const YEAR = 365 * DAY;
195
+ const MINUTE_UNIT = 'minute';
196
+ const HOUR_UNIT = 'hour';
197
+ const DAY_UNIT = 'day';
198
+ const WEEK_UNIT = 'week';
199
+ const MONTH_UNIT = 'month';
200
+ const QUARTER_UNIT = 'quarter';
201
+ const YEAR_UNIT = 'year';
202
+ const TIME_INTERVALS = [
203
+ [SECOND_UNIT, 1],
204
+ [SECOND_UNIT, 5],
205
+ [SECOND_UNIT, 10],
206
+ [SECOND_UNIT, 15],
207
+ [SECOND_UNIT, 30],
208
+ [MINUTE_UNIT, 1],
209
+ [MINUTE_UNIT, 5],
210
+ [MINUTE_UNIT, 10],
211
+ [MINUTE_UNIT, 15],
212
+ [MINUTE_UNIT, 30],
213
+ [HOUR_UNIT, 1],
214
+ [HOUR_UNIT, 3],
215
+ [HOUR_UNIT, 6],
216
+ [HOUR_UNIT, 12],
217
+ [DAY_UNIT, 1],
218
+ [DAY_UNIT, 2],
219
+ [WEEK_UNIT, 1],
220
+ [MONTH_UNIT, 1],
221
+ [MONTH_UNIT, 2],
222
+ [QUARTER_UNIT, 1],
223
+ [MONTH_UNIT, 6],
224
+ [YEAR_UNIT, 1],
225
+ [YEAR_UNIT, 2],
226
+ [YEAR_UNIT, 5],
227
+ [YEAR_UNIT, 10],
228
+ [YEAR_UNIT, 25],
229
+ [YEAR_UNIT, 50],
230
+ [YEAR_UNIT, 100],
231
+ ];
232
+ const getTickCount = (tickCount = TARGET_TICKS) =>
233
+ isFiniteNumber(tickCount) ? mathMax(mathRound(tickCount), 1) : TARGET_TICKS;
110
234
  const getTicks = (
111
235
  min,
112
236
  max,
@@ -228,8 +352,129 @@ const getTicks = (
228
352
  }
229
353
  return bestTicks;
230
354
  };
355
+ const getTimeTicks = (
356
+ minTimestamp,
357
+ maxTimestamp,
358
+ targetTickCount,
359
+ labelSize,
360
+ axisSize,
361
+ ) => {
362
+ const min = mathMin(minTimestamp, maxTimestamp);
363
+ const max = mathMax(minTimestamp, maxTimestamp);
364
+ let bestTicks = [min, max];
365
+ let bestScore = -infinity;
366
+ arrayForEach(TIME_INTERVALS, (interval, index) => {
367
+ const ticks = [];
368
+ for (
369
+ let tick = floorTime(min, interval), count = 0;
370
+ tick <= max && count < 1e3;
371
+ tick = addTime(tick, interval), count++
372
+ ) {
373
+ arrayPush(ticks, tick);
374
+ }
375
+ const lastTick = ticks[size(ticks) - 1];
376
+ if (!isFiniteNumber(lastTick) || lastTick < max) {
377
+ arrayPush(ticks, addTime(lastTick ?? floorTime(min, interval), interval));
378
+ }
379
+ const tickCount = size(ticks);
380
+ const tickMin = ticks[0];
381
+ const tickMax = ticks[tickCount - 1];
382
+ const range = max - min;
383
+ const target = mathMax(targetTickCount, 2);
384
+ const spacing = axisSize / (tickCount - 1);
385
+ const score =
386
+ tickCount < 2
387
+ ? -infinity
388
+ : WEIGHTS[0] * (1 - index / mathMax(size(TIME_INTERVALS) - 1, 1)) +
389
+ WEIGHTS[1] *
390
+ (1 - (mathAbs(min - tickMin) + mathAbs(tickMax - max)) / range) +
391
+ WEIGHTS[2] * (2 - mathMax(tickCount / target, target / tickCount)) +
392
+ WEIGHTS[3] *
393
+ (spacing < labelSize * 1.2
394
+ ? -infinity
395
+ : mathMin(spacing / labelSize, 1));
396
+ if (score > bestScore) {
397
+ bestTicks = ticks;
398
+ bestScore = score;
399
+ }
400
+ });
401
+ return bestTicks;
402
+ };
403
+ const getTimeTickLabel = (timestamp, ticks) => {
404
+ const date = dateNew(timestamp);
405
+ const year = dateGetUTCFullYear(date) + EMPTY_STRING;
406
+ const month = getPadded(dateGetUTCMonth(date) + 1);
407
+ const day = getPadded(dateGetUTCDate(date));
408
+ const hour = getPadded(dateGetUTCHours(date));
409
+ const minute = getPadded(dateGetUTCMinutes(date));
410
+ const second = getPadded(dateGetUTCSeconds(date));
411
+ const dateLabel = `${year}-${month}-${day}`;
412
+ let minDiff = infinity;
413
+ arrayForEach(ticks, (tick, index) => {
414
+ if (index > 0) {
415
+ minDiff = mathMin(minDiff, tick - ticks[index - 1]);
416
+ }
417
+ });
418
+ minDiff =
419
+ minDiff == infinity
420
+ ? dateGetUTCHours(date) == 0 &&
421
+ dateGetUTCMinutes(date) == 0 &&
422
+ dateGetUTCSeconds(date) == 0
423
+ ? DAY
424
+ : dateGetUTCSeconds(date) == 0
425
+ ? HOUR
426
+ : SECOND
427
+ : minDiff;
428
+ return minDiff < MINUTE
429
+ ? `${dateLabel} ${hour}:${minute}:${second}`
430
+ : minDiff < DAY
431
+ ? `${dateLabel} ${hour}:${minute}`
432
+ : minDiff < MONTH
433
+ ? dateLabel
434
+ : minDiff < YEAR
435
+ ? `${year}-${month}`
436
+ : year;
437
+ };
438
+ const floorTime = (timestamp, [unit, step]) => {
439
+ const date = dateNew(timestamp);
440
+ const year = dateGetUTCFullYear(date);
441
+ const month = dateGetUTCMonth(date);
442
+ const monthStep = unit == QUARTER_UNIT ? step * 3 : step;
443
+ const monthIndex = year * 12 + month;
444
+ const flooredMonthIndex = mathFloor(monthIndex / monthStep) * monthStep;
445
+ const fixedInterval = getFixedInterval(unit, step);
446
+ return unit == YEAR_UNIT
447
+ ? dateUtc(mathFloor(year / step) * step, 0, 1)
448
+ : unit == QUARTER_UNIT || unit == MONTH_UNIT
449
+ ? dateUtc(mathFloor(flooredMonthIndex / 12), flooredMonthIndex % 12, 1)
450
+ : unit == WEEK_UNIT
451
+ ? dateUtc(year, month, dateGetUTCDate(date)) -
452
+ ((dateGetUTCDay(date) + 6) % 7) * DAY
453
+ : mathFloor(timestamp / fixedInterval) * fixedInterval;
454
+ };
455
+ const addTime = (timestamp, [unit, step]) => {
456
+ const date = dateNew(timestamp);
457
+ return unit == YEAR_UNIT
458
+ ? dateUtc(dateGetUTCFullYear(date) + step, 0, 1)
459
+ : unit == QUARTER_UNIT
460
+ ? dateUtc(dateGetUTCFullYear(date), dateGetUTCMonth(date) + step * 3, 1)
461
+ : unit == MONTH_UNIT
462
+ ? dateUtc(dateGetUTCFullYear(date), dateGetUTCMonth(date) + step, 1)
463
+ : timestamp + getFixedInterval(unit, step);
464
+ };
465
+ const getFixedInterval = (unit, step) =>
466
+ unit == WEEK_UNIT
467
+ ? step * 7 * DAY
468
+ : unit == DAY_UNIT
469
+ ? step * DAY
470
+ : unit == HOUR_UNIT
471
+ ? step * HOUR
472
+ : unit == MINUTE_UNIT
473
+ ? step * MINUTE
474
+ : step * SECOND;
475
+ const getPadded = (value) => (value < 10 ? `0${value}` : value + EMPTY_STRING);
231
476
 
232
- const TARGET_TICKS = 10;
477
+ const ISO_DATE = /^\d{4}-\d{2}-\d{2}(?:$|T)/;
233
478
  const getDataPoints = (rowIds, getPoint) =>
234
479
  arrayFilter(arrayMap(rowIds, getPoint), (point) => !isUndefined(point));
235
480
  const getDataPoint = (rowId, xCell, yCell) => {
@@ -245,50 +490,78 @@ const getScaledPoints = (
245
490
  [xMin, xMax, yMin, yMax],
246
491
  [width, height],
247
492
  xValues,
493
+ xScale = CATEGORY,
494
+ timestampUnit = MILLISECOND,
248
495
  xTitle,
249
496
  yTitle,
250
497
  ) => {
251
- const numericX =
252
- kind == 'line' &&
253
- arrayIsEmpty(arrayFilter(points, ([, xValue]) => !isNumber(xValue)));
254
- const xDomain = numericX ? [xMin, xMax] : [0, 0];
498
+ const continuousX = xScale != CATEGORY;
499
+ const xDomain = continuousX ? [xMin, xMax] : [0, 0];
255
500
  const yDomain = [yMin ?? 0, yMax ?? 0];
256
- const xCategories = /* @__PURE__ */ new Map();
501
+ const xCategories = mapNew();
257
502
  arrayForEach(
258
- xValues == null || arrayIsEmpty(xValues)
503
+ isNullish(xValues) || arrayIsEmpty(xValues)
259
504
  ? arrayMap(points, ([, xValue]) => xValue)
260
505
  : xValues,
261
- (xValue) => {
262
- if (!xCategories.has(xValue)) {
263
- xCategories.set(xValue, collSize(xCategories));
264
- }
265
- },
506
+ (xValue) =>
507
+ collHas(xCategories, xValue)
508
+ ? 0
509
+ : mapSet(xCategories, xValue, collSize(xCategories)),
510
+ );
511
+ return arrayFilter(
512
+ arrayMap(points, ([rowId, xValue, yValue]) => {
513
+ const x = getX(
514
+ xValue,
515
+ xScale,
516
+ timestampUnit,
517
+ xDomain,
518
+ xCategories,
519
+ width,
520
+ kind,
521
+ );
522
+ return isUndefined(x)
523
+ ? void 0
524
+ : [
525
+ rowId,
526
+ xValue,
527
+ yValue,
528
+ x,
529
+ height - getScale(yValue, yDomain[0], yDomain[1], height),
530
+ xTitle,
531
+ yTitle,
532
+ ];
533
+ }),
534
+ (point) => !isUndefined(point),
266
535
  );
267
- return arrayMap(points, ([rowId, xValue, yValue]) => [
268
- rowId,
269
- xValue,
270
- yValue,
271
- getX(xValue, numericX, xDomain, xCategories, width, kind),
272
- getY(yValue, yDomain, height),
273
- xTitle,
274
- yTitle,
275
- ]);
276
536
  };
277
- const getX = (xValue, numericX, [xMin, xMax], xCategories, width, kind) =>
278
- numericX
279
- ? getScale(xValue, xMin, xMax, width)
280
- : kind == 'bar'
281
- ? (width * ((xCategories.get(xValue) ?? 0) + 0.5)) / collSize(xCategories)
537
+ const getX = (
538
+ xValue,
539
+ xScale,
540
+ timestampUnit,
541
+ [xMin, xMax],
542
+ xCategories,
543
+ width,
544
+ kind,
545
+ ) => {
546
+ const continuousValue = getContinuousXValue(xValue, xScale, timestampUnit);
547
+ return xScale != CATEGORY
548
+ ? isUndefined(continuousValue)
549
+ ? void 0
550
+ : getScale(continuousValue, xMin, xMax, width)
551
+ : kind == BAR
552
+ ? (width * ((mapGet(xCategories, xValue) ?? 0) + 0.5)) /
553
+ collSize(xCategories)
282
554
  : getScale(
283
- xCategories.get(xValue) ?? 0,
555
+ mapGet(xCategories, xValue) ?? 0,
284
556
  0,
285
557
  collSize(xCategories) - 1,
286
558
  width,
287
559
  );
288
- const getY = (yValue, [yMin, yMax], height) =>
289
- height - getScale(yValue, yMin, yMax, height);
560
+ };
290
561
  const getScale = (value, min, max, size2) =>
291
- min == max ? size2 / 2 : getRounded((size2 * (value - min)) / (max - min));
562
+ min == max
563
+ ? size2 / 2
564
+ : mathRound(((size2 * (value - min)) / (max - min)) * 1e6) / 1e6;
292
565
  const getBounds = (kind, points) => {
293
566
  if (arrayIsEmpty(points)) {
294
567
  return [];
@@ -300,7 +573,7 @@ const getBounds = (kind, points) => {
300
573
  }
301
574
  return [points[0]?.[1], points[size(points) - 1]?.[1], yMin, yMax];
302
575
  };
303
- const getYTicks = ([, , yMin, yMax], [, height], labelSize) => {
576
+ const getYTicks = ([, , yMin, yMax], [, height], labelSize, tickCount) => {
304
577
  if (isUndefined(yMin) || isUndefined(yMax)) {
305
578
  return [];
306
579
  }
@@ -310,26 +583,78 @@ const getYTicks = ([, , yMin, yMax], [, height], labelSize) => {
310
583
  return getTicks(
311
584
  yMin,
312
585
  yMax,
313
- TARGET_TICKS,
586
+ getTickCount(tickCount),
314
587
  labelSize,
315
588
  height,
316
589
  isInteger(yMin) && isInteger(yMax),
317
590
  );
318
591
  };
319
- const getXTicks = (kind, [xMin, xMax], [width], labelSize) =>
320
- kind == 'line' && isNumber(xMin) && isNumber(xMax) && xMin != xMax
592
+ const getXTicks = (kind, [xMin, xMax], [width], labelSize, tickCount) =>
593
+ kind == LINE && isNumber(xMin) && isNumber(xMax) && xMin != xMax
321
594
  ? getTicks(
322
595
  xMin,
323
596
  xMax,
324
- TARGET_TICKS,
597
+ getTickCount(tickCount),
325
598
  labelSize,
326
599
  width,
327
600
  isInteger(xMin) && isInteger(xMax),
328
601
  )
329
602
  : [];
603
+ const getResolvedXScale = (
604
+ xAxisScale,
605
+ {continuousX, xValues},
606
+ hasLinearAxisDefinition,
607
+ ) =>
608
+ xAxisScale == CATEGORY || xAxisScale == LINEAR || xAxisScale == TIME
609
+ ? xAxisScale
610
+ : continuousX || (arrayIsEmpty(xValues) && hasLinearAxisDefinition)
611
+ ? LINEAR
612
+ : !arrayIsEmpty(xValues) &&
613
+ arrayEvery(
614
+ xValues,
615
+ (xValue) =>
616
+ isString(xValue) &&
617
+ isFiniteNumber(normalizeTimeValue(xValue, MILLISECOND)),
618
+ )
619
+ ? TIME
620
+ : CATEGORY;
621
+ const getXScaleDomain = ([xMin, xMax], xValues, xScale, timestampUnit) => {
622
+ const timestamps = [];
623
+ return xScale == LINEAR
624
+ ? [isNumber(xMin) ? xMin : void 0, isNumber(xMax) ? xMax : void 0]
625
+ : xScale == TIME
626
+ ? (arrayForEach(xValues, (xValue) => {
627
+ const timestamp = normalizeTimeValue(xValue, timestampUnit);
628
+ if (isFiniteNumber(timestamp)) {
629
+ arrayPush(timestamps, timestamp);
630
+ }
631
+ }),
632
+ arrayIsEmpty(timestamps) ? [] : getDomain(timestamps))
633
+ : [xMin, xMax];
634
+ };
635
+ const normalizeTimeValue = (value, timestampUnit) => {
636
+ const timestamp = isNumber(value)
637
+ ? timestampUnit == SECOND_UNIT
638
+ ? value * 1e3
639
+ : value
640
+ : isString(value) && ISO_DATE.test(value)
641
+ ? getTime(value)
642
+ : value instanceof Date
643
+ ? getTime(value)
644
+ : void 0;
645
+ return isFiniteNumber(timestamp) ? timestamp : void 0;
646
+ };
330
647
  const getTickBounds = ([xMin, xMax, yMin, yMax], xTicks, yTicks) => [
331
- arrayIsEmpty(xTicks) ? xMin : mathMin(xMin, xTicks[0]),
332
- arrayIsEmpty(xTicks) ? xMax : mathMax(xMax, xTicks[size(xTicks) - 1]),
648
+ arrayIsEmpty(xTicks)
649
+ ? xMin
650
+ : isNumber(xMin)
651
+ ? mathMin(xMin, xTicks[0])
652
+ : xTicks[0],
653
+ arrayIsEmpty(xTicks)
654
+ ? xMax
655
+ : isNumber(xMax)
656
+ ? mathMax(xMax, xTicks[size(xTicks) - 1])
657
+ : xTicks[size(xTicks) - 1],
333
658
  arrayIsEmpty(yTicks) ? yMin : mathMin(yMin ?? infinity, yTicks[0]),
334
659
  arrayIsEmpty(yTicks)
335
660
  ? yMax
@@ -339,7 +664,7 @@ const getSeriesSummary = (kind, points, xCellId, yCellId, yLabel) => {
339
664
  const [xMin, xMax, yMin, yMax] = getBounds(kind, points);
340
665
  const xValues = [];
341
666
  const continuousX =
342
- kind == 'line' &&
667
+ kind == LINE &&
343
668
  arrayIsEmpty(arrayFilter(points, ([, xValue]) => !isNumber(xValue)));
344
669
  arrayForEach(points, ([, xValue]) => {
345
670
  if (!arrayHas(xValues, xValue)) {
@@ -375,17 +700,17 @@ const getDomainState = (summaries) => {
375
700
  }
376
701
  });
377
702
  if (isNumber(summary.xMin) && isNumber(summary.xMax)) {
378
- xMins.push(summary.xMin);
379
- xMaxes.push(summary.xMax);
703
+ arrayPush(xMins, summary.xMin);
704
+ arrayPush(xMaxes, summary.xMax);
380
705
  } else {
381
706
  xMin ??= summary.xMin;
382
707
  xMax = summary.xMax ?? xMax;
383
708
  }
384
709
  if (!isUndefined(summary.yMin)) {
385
- yMins.push(summary.yMin);
710
+ arrayPush(yMins, summary.yMin);
386
711
  }
387
712
  if (!isUndefined(summary.yMax)) {
388
- yMaxes.push(summary.yMax);
713
+ arrayPush(yMaxes, summary.yMax);
389
714
  }
390
715
  });
391
716
  return {
@@ -399,16 +724,27 @@ const getDomainState = (summaries) => {
399
724
  xValues,
400
725
  };
401
726
  };
402
- const getYDomain = (points, kind = 'bar') =>
727
+ const getYDomain = (points, kind = BAR) =>
403
728
  getDomain([
404
- ...(kind == 'bar' ? [0] : []),
729
+ ...(kind == BAR ? [0] : []),
405
730
  ...arrayMap(points, ([, , yValue]) => yValue),
406
731
  ]);
407
732
  const getDomain = (values) => {
408
733
  const min = mathMin(...values);
409
734
  return min == infinity ? [0, 0] : [min, mathMax(...values)];
410
735
  };
411
- const getRounded = (value) => mathRound(value * 1e6) / 1e6;
736
+ const getContinuousXValue = (xValue, xScale, timestampUnit) =>
737
+ xScale == LINEAR
738
+ ? isNumber(xValue)
739
+ ? xValue
740
+ : void 0
741
+ : xScale == TIME
742
+ ? normalizeTimeValue(xValue, timestampUnit)
743
+ : void 0;
744
+ const getTime = (value) => {
745
+ const time = +dateNew(value);
746
+ return isFiniteNumber(time) ? mathFloor(time) : void 0;
747
+ };
412
748
  const getXValue = (cell) =>
413
749
  isNumber(cell)
414
750
  ? isFiniteNumber(cell)
@@ -422,14 +758,13 @@ const getXValue = (cell) =>
422
758
  const getYValue = (cell) =>
423
759
  isNumber(cell) && isFiniteNumber(cell) ? cell : void 0;
424
760
 
425
- const CURRENT_COLOR = 'currentColor';
426
-
427
761
  const Bars = ({
428
762
  points,
429
763
  plotFrame,
430
764
  barGap,
431
765
  barSeriesCount,
432
766
  barSeriesIndex,
767
+ fullBarWidth,
433
768
  setTooltipPoint,
434
769
  yMin = 0,
435
770
  yMax = 0,
@@ -437,10 +772,11 @@ const Bars = ({
437
772
  const [plotX, plotY, width, height] = plotFrame;
438
773
  const baselineY = height - getScale(0, yMin, yMax, height);
439
774
  const pointsSize = size(points);
440
- const fullBarWidth = arrayIsEmpty(points) ? 0 : width / pointsSize;
775
+ const resolvedFullBarWidth =
776
+ fullBarWidth ?? (arrayIsEmpty(points) ? 0 : width / pointsSize);
441
777
  const barCount = mathMax(barSeriesCount, 1);
442
778
  const barIndex = mathMax(barSeriesIndex, 0);
443
- const barGroupWidth = mathMax(fullBarWidth - barGap, 0);
779
+ const barGroupWidth = mathMax(resolvedFullBarWidth - barGap, 0);
444
780
  const barWidth = mathMax(
445
781
  (barGroupWidth - barGap * (barCount - 1)) / barCount,
446
782
  0,
@@ -463,44 +799,18 @@ const Bars = ({
463
799
  );
464
800
  });
465
801
  };
466
-
467
- const object = Object;
468
- const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
469
- const objEntries = object.entries;
470
- const isObject = (obj) =>
471
- !isNullish(obj) &&
472
- ifNotNullish(
473
- getPrototypeOf(obj),
474
- (objPrototype) =>
475
- objPrototype == object.prototype ||
476
- isNullish(getPrototypeOf(objPrototype)),
477
-
478
- /* istanbul ignore next */
479
- () => true,
480
- );
481
- const objIds = object.keys;
482
- const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
483
- const objValues = (obj) => object.values(obj);
484
- const objSize = (obj) => size(objIds(obj));
485
-
486
- /* istanbul ignore next */
487
- const objIsEqual = (
488
- obj1,
489
- obj2,
490
- isEqual = (value1, value2) => value1 === value2,
491
- ) => {
492
- const entries1 = objEntries(obj1);
493
- return (
494
- size(entries1) === objSize(obj2) &&
495
- arrayEvery(entries1, ([index, value1]) =>
496
- isObject(value1)
497
- ? /* istanbul ignore next */
498
- isObject(obj2[index])
499
- ? objIsEqual(obj2[index], value1, isEqual)
500
- : false
501
- : isEqual(value1, obj2[index]),
502
- )
802
+ const getContinuousBarWidth = (points, fallbackWidth) => {
803
+ const xs = arraySort(
804
+ arrayMap(points, ([, , , x]) => x),
805
+ (x1, x2) => x1 - x2,
503
806
  );
807
+ let barWidth = infinity;
808
+ arrayForEach(xs, (x, index) => {
809
+ if (index > 0 && x > xs[index - 1]) {
810
+ barWidth = mathMin(barWidth, x - xs[index - 1]);
811
+ }
812
+ });
813
+ return barWidth == infinity ? fallbackWidth : barWidth;
504
814
  };
505
815
 
506
816
  const jsonString = JSON.stringify;
@@ -693,7 +1003,6 @@ const useResultCellListener = (
693
1003
  [queryId, rowId, cellId],
694
1004
  );
695
1005
 
696
- const EMPTY_ID = '';
697
1006
  const useSeriesData = ({
698
1007
  descending,
699
1008
  limit,
@@ -718,7 +1027,7 @@ const useSeriesData = ({
718
1027
  const [seriesId] = useState(getSeriesId);
719
1028
  const handleChange = useCallback(() => rerender([]), [rerender]);
720
1029
  const tableRowIds = useSortedRowIds(
721
- tableId ?? EMPTY_ID,
1030
+ tableId ?? EMPTY_STRING,
722
1031
  sortCellId ?? xCellId,
723
1032
  descending,
724
1033
  offset,
@@ -726,7 +1035,7 @@ const useSeriesData = ({
726
1035
  storeOrStoreId,
727
1036
  );
728
1037
  const queryRowIds = useResultSortedRowIds(
729
- queryId ?? EMPTY_ID,
1038
+ queryId ?? EMPTY_STRING,
730
1039
  sortCellId ?? xCellId,
731
1040
  descending,
732
1041
  offset,
@@ -734,32 +1043,15 @@ const useSeriesData = ({
734
1043
  queriesOrQueriesId,
735
1044
  );
736
1045
  const rowIds = sourceType == SourceType.Table ? tableRowIds : queryRowIds;
737
- const points =
738
- yCellId == null
739
- ? []
740
- : getDataPoints(rowIds, (rowId) =>
741
- getDataPoint(
742
- rowId,
743
- getCell(
744
- sourceType,
745
- store,
746
- queries,
747
- tableId,
748
- queryId,
749
- rowId,
750
- xCellId,
751
- ),
752
- getCell(
753
- sourceType,
754
- store,
755
- queries,
756
- tableId,
757
- queryId,
758
- rowId,
759
- yCellId,
760
- ),
761
- ),
762
- );
1046
+ const points = isNullish(yCellId)
1047
+ ? []
1048
+ : getDataPoints(rowIds, (rowId) =>
1049
+ getDataPoint(
1050
+ rowId,
1051
+ getCell(sourceType, store, queries, tableId, queryId, rowId, xCellId),
1052
+ getCell(sourceType, store, queries, tableId, queryId, rowId, yCellId),
1053
+ ),
1054
+ );
763
1055
  useCellListener(
764
1056
  sourceType == SourceType.Table ? (tableId ?? null) : null,
765
1057
  null,
@@ -801,7 +1093,7 @@ const useSeriesData = ({
801
1093
  return [seriesId, points];
802
1094
  };
803
1095
  const getSeriesClassName = (baseClassName, className) =>
804
- className == null ? baseClassName : `${baseClassName} ${className}`;
1096
+ isNullish(className) ? baseClassName : `${baseClassName} ${className}`;
805
1097
  const getCell = (
806
1098
  sourceType,
807
1099
  store,
@@ -827,25 +1119,41 @@ const BarSeries = (props) => {
827
1119
  releaseBarSeries,
828
1120
  setSeriesSummary,
829
1121
  setTooltipPoint,
1122
+ timestampUnit,
1123
+ xScale,
830
1124
  xValues,
831
1125
  } = useCartesianChartContext();
832
1126
  const {className, label, xCellId, yCellId} = props;
833
1127
  const [seriesId, rawPoints] = useSeriesData(props);
834
1128
  const barSeriesIndex = getBarSeriesIndex(seriesId);
835
1129
  const [, , yMin, yMax] = bounds;
1130
+ const axisPoints =
1131
+ xScale == CATEGORY
1132
+ ? void 0
1133
+ : getScaledPoints(
1134
+ LINE,
1135
+ arrayMap(xValues, (xValue, index) => [`${index}`, xValue, 0]),
1136
+ bounds,
1137
+ plotSize,
1138
+ xValues,
1139
+ xScale,
1140
+ timestampUnit,
1141
+ );
836
1142
  const points = getScaledPoints(
837
- 'bar',
1143
+ BAR,
838
1144
  rawPoints,
839
1145
  bounds,
840
1146
  plotSize,
841
1147
  xValues,
1148
+ xScale,
1149
+ timestampUnit,
842
1150
  xCellId,
843
1151
  label ?? yCellId,
844
1152
  );
845
1153
  useLayoutEffect(() => {
846
1154
  setSeriesSummary(
847
1155
  seriesId,
848
- getSeriesSummary('bar', rawPoints, xCellId, yCellId, label),
1156
+ getSeriesSummary(BAR, rawPoints, xCellId, yCellId, label),
849
1157
  );
850
1158
  });
851
1159
  useLayoutEffect(() => {
@@ -859,6 +1167,9 @@ const BarSeries = (props) => {
859
1167
  barGap,
860
1168
  barSeriesCount,
861
1169
  barSeriesIndex,
1170
+ fullBarWidth: isNullish(axisPoints)
1171
+ ? void 0
1172
+ : getContinuousBarWidth(axisPoints, plotSize[0]),
862
1173
  plotFrame,
863
1174
  points,
864
1175
  setTooltipPoint,
@@ -867,7 +1178,29 @@ const BarSeries = (props) => {
867
1178
  }),
868
1179
  });
869
1180
  };
870
- BarSeries[CHART_SERIES] = true;
1181
+ BarSeries[SERIES] = true;
1182
+
1183
+ const getConvenienceChartProps = (props) => [
1184
+ isNullish(props.tableId)
1185
+ ? {
1186
+ className: props.className,
1187
+ queries: props.queries,
1188
+ queryId: props.queryId,
1189
+ }
1190
+ : {
1191
+ className: props.className,
1192
+ store: props.store,
1193
+ tableId: props.tableId,
1194
+ },
1195
+ {
1196
+ descending: props.descending,
1197
+ limit: props.limit,
1198
+ offset: props.offset,
1199
+ sortCellId: props.sortCellId,
1200
+ xCellId: props.xCellId,
1201
+ yCellId: props.yCellId,
1202
+ },
1203
+ ];
871
1204
 
872
1205
  const INTEGER = /^\d+$/;
873
1206
  const getPoolFunctions = () => {
@@ -939,7 +1272,7 @@ const getPlotFrame = (
939
1272
  const getDefaultStyle = (fontSize) =>
940
1273
  arrayMap(DEFAULT_STYLE, (value) => value * fontSize);
941
1274
  const getStyle = (style) => {
942
- const fontSize = parseFloat(style?.fontSize ?? '');
1275
+ const fontSize = parseFloat(style?.fontSize ?? EMPTY_STRING);
943
1276
  return getDefaultStyle(
944
1277
  isFiniteNumber(fontSize) ? fontSize : DEFAULT_FONT_SIZE,
945
1278
  );
@@ -952,8 +1285,10 @@ const isLayoutEqual = ([chartSize1, chartStyle1], [chartSize2, chartStyle2]) =>
952
1285
  arrayIsEqual(chartSize1, chartSize2) &&
953
1286
  arrayIsEqual(chartStyle1, chartStyle2);
954
1287
 
955
- const XAxis = ({
1288
+ const XAxis$1 = ({
1289
+ className,
956
1290
  points,
1291
+ tickFormatter,
957
1292
  xTicks,
958
1293
  xMin,
959
1294
  xMax,
@@ -963,11 +1298,13 @@ const XAxis = ({
963
1298
  tickGap,
964
1299
  axisHeight,
965
1300
  fontSize,
1301
+ timestampUnit,
1302
+ xScale,
966
1303
  }) => {
967
1304
  const [plotX, plotY, plotWidth, plotHeight] = plotFrame;
968
1305
  const titleGap = mathMax(axisHeight - tickSize - tickGap - 2 * fontSize, 0);
969
1306
  return /* @__PURE__ */ jsxs('g', {
970
- className: 'x',
1307
+ className: isNullish(className) ? 'x' : `x ${className}`,
971
1308
  dominantBaseline: 'hanging',
972
1309
  textAnchor: 'middle',
973
1310
  children: [
@@ -989,7 +1326,12 @@ const XAxis = ({
989
1326
  {
990
1327
  x: plotX + x,
991
1328
  y: plotY + plotHeight + tickSize + tickGap,
992
- children: string(xValue),
1329
+ children: getTickLabel(
1330
+ xValue,
1331
+ tickFormatter,
1332
+ xScale,
1333
+ timestampUnit,
1334
+ ),
993
1335
  },
994
1336
  rowId,
995
1337
  ),
@@ -1001,7 +1343,13 @@ const XAxis = ({
1001
1343
  {
1002
1344
  x: plotX + x,
1003
1345
  y: plotY + plotHeight + tickSize + tickGap,
1004
- children: tick,
1346
+ children: getTickLabel(
1347
+ tick,
1348
+ tickFormatter,
1349
+ xScale,
1350
+ MILLISECOND,
1351
+ xTicks,
1352
+ ),
1005
1353
  },
1006
1354
  tick,
1007
1355
  );
@@ -1016,8 +1364,24 @@ const XAxis = ({
1016
1364
  ],
1017
1365
  });
1018
1366
  };
1367
+ const getTickLabel = (
1368
+ tick,
1369
+ tickFormatter,
1370
+ xScale,
1371
+ timestampUnit,
1372
+ ticks = [],
1373
+ ) => {
1374
+ const timestamp =
1375
+ xScale == TIME ? normalizeTimeValue(tick, timestampUnit) : void 0;
1376
+ return isNumber(timestamp)
1377
+ ? (tickFormatter?.(dateNew(timestamp), timestamp) ??
1378
+ getTimeTickLabel(timestamp, ticks))
1379
+ : (tickFormatter?.(tick, void 0) ?? string(tick));
1380
+ };
1019
1381
 
1020
- const YAxis = ({
1382
+ const YAxis$1 = ({
1383
+ className,
1384
+ tickFormatter,
1021
1385
  yTicks,
1022
1386
  yMin,
1023
1387
  yMax,
@@ -1031,7 +1395,7 @@ const YAxis = ({
1031
1395
  return isNullish(yMin) || isNullish(yMax)
1032
1396
  ? null
1033
1397
  : /* @__PURE__ */ jsxs('g', {
1034
- className: 'y',
1398
+ className: isNullish(className) ? 'y' : `y ${className}`,
1035
1399
  children: [
1036
1400
  /* @__PURE__ */ jsx('path', {
1037
1401
  className: 'line',
@@ -1049,7 +1413,11 @@ const YAxis = ({
1049
1413
  const y = plotHeight - getScale(tick, yMin, yMax, plotHeight);
1050
1414
  return /* @__PURE__ */ jsx(
1051
1415
  'text',
1052
- {x: plotX - tickSize - tickGap, y: plotY + y, children: tick},
1416
+ {
1417
+ x: plotX - tickSize - tickGap,
1418
+ y: plotY + y,
1419
+ children: tickFormatter?.(tick) ?? string(tick),
1420
+ },
1053
1421
  tick,
1054
1422
  );
1055
1423
  }),
@@ -1066,6 +1434,8 @@ const YAxis = ({
1066
1434
  };
1067
1435
 
1068
1436
  const Axes = ({
1437
+ xAxis,
1438
+ yAxis,
1069
1439
  points,
1070
1440
  xTicks,
1071
1441
  yTicks,
@@ -1074,6 +1444,8 @@ const Axes = ({
1074
1444
  xAxisHeight,
1075
1445
  yAxisWidth,
1076
1446
  fontSize,
1447
+ timestampUnit,
1448
+ xScale,
1077
1449
  ...sharedProps
1078
1450
  }) => {
1079
1451
  return /* @__PURE__ */ jsxs('g', {
@@ -1081,23 +1453,29 @@ const Axes = ({
1081
1453
  fill: CURRENT_COLOR,
1082
1454
  fillOpacity: 0.75,
1083
1455
  children: [
1084
- /* @__PURE__ */ jsx(YAxis, {
1456
+ /* @__PURE__ */ jsx(YAxis$1, {
1085
1457
  ...sharedProps,
1458
+ className: yAxis?.className,
1459
+ tickFormatter: yAxis?.tickFormatter,
1086
1460
  yTicks,
1087
1461
  yMin,
1088
1462
  yMax,
1089
1463
  yTitle,
1090
1464
  axisWidth: yAxisWidth,
1091
1465
  }),
1092
- /* @__PURE__ */ jsx(XAxis, {
1466
+ /* @__PURE__ */ jsx(XAxis$1, {
1093
1467
  ...sharedProps,
1468
+ className: xAxis?.className,
1094
1469
  points,
1470
+ tickFormatter: xAxis?.tickFormatter,
1095
1471
  xTicks,
1096
1472
  xMin,
1097
1473
  xMax,
1098
1474
  xTitle,
1099
1475
  axisHeight: xAxisHeight,
1100
1476
  fontSize,
1477
+ timestampUnit,
1478
+ xScale,
1101
1479
  }),
1102
1480
  ],
1103
1481
  });
@@ -1236,6 +1614,7 @@ const EMPTY_DOMAIN_STATE = {
1236
1614
  continuousX: false,
1237
1615
  xValues: [],
1238
1616
  };
1617
+ const TITLE_SEPARATOR = ' & ';
1239
1618
  const CartesianChart = ({
1240
1619
  children,
1241
1620
  className,
@@ -1253,17 +1632,15 @@ const CartesianChart = ({
1253
1632
  const labelSize = getLabelSize(layout);
1254
1633
  const storeObject = useStoreOrStoreById(store);
1255
1634
  const queriesObject = useQueriesOrQueriesById(queries);
1256
- const sourceType =
1257
- tableId == null
1258
- ? queryId == null
1259
- ? SourceType.None
1260
- : SourceType.Query
1261
- : SourceType.Table;
1262
- const initialSummaries = initialSummary == null ? {} : {0: initialSummary};
1263
- const initialDomainState =
1264
- initialSummary == null
1265
- ? EMPTY_DOMAIN_STATE
1266
- : getDomainState(objValues(initialSummaries));
1635
+ const sourceType = isNullish(tableId)
1636
+ ? isNullish(queryId)
1637
+ ? SourceType.None
1638
+ : SourceType.Query
1639
+ : SourceType.Table;
1640
+ const initialSummaries = isNullish(initialSummary) ? {} : {0: initialSummary};
1641
+ const initialDomainState = isNullish(initialSummary)
1642
+ ? EMPTY_DOMAIN_STATE
1643
+ : getDomainState(objValues(initialSummaries));
1267
1644
  const initialXTitle = getTitle(initialSummaries, 'xCellId');
1268
1645
  const initialYTitle = getTitle(initialSummaries, 'yCellId');
1269
1646
  const summariesRef = useRef(initialSummaries);
@@ -1278,19 +1655,63 @@ const CartesianChart = ({
1278
1655
  const barSeriesIdsRef = useRef([]);
1279
1656
  const [barSeriesIds, setBarSeriesIds] = useState([]);
1280
1657
  const [tooltipPoint, setTooltipPoint] = useState();
1658
+ const [chartChildren, xAxis, yAxis] = getParsedChildren(children);
1281
1659
  const xValues = domainState.xValues;
1282
- const dataBounds = domainState.bounds;
1283
- const axisKind =
1284
- domainState.continuousX || arrayIsEmpty(barSeriesIds) ? 'line' : 'bar';
1285
- const xTicks = getXTicks(axisKind, dataBounds, plotSize, labelSize);
1286
- const yTicks = getYTicks(dataBounds, plotSize, labelSize);
1660
+ const timestampUnit =
1661
+ xAxis?.scale == TIME && xAxis.timestampUnit == SECOND_UNIT
1662
+ ? SECOND_UNIT
1663
+ : MILLISECOND;
1664
+ const xScale = getResolvedXScale(
1665
+ xAxis?.scale,
1666
+ domainState,
1667
+ isFiniteNumber(xAxis?.min) ||
1668
+ isFiniteNumber(xAxis?.max) ||
1669
+ !isNullish(xAxis?.ticks),
1670
+ );
1671
+ const continuousX = xScale != CATEGORY;
1672
+ const dataBounds = getAxisBounds(
1673
+ domainState.bounds,
1674
+ xValues,
1675
+ xScale,
1676
+ timestampUnit,
1677
+ xAxis,
1678
+ yAxis,
1679
+ );
1680
+ const [dataXMin, dataXMax] = dataBounds;
1681
+ const axisKind = continuousX || arrayIsEmpty(barSeriesIds) ? LINE : BAR;
1682
+ const xTicks =
1683
+ continuousX && !isNullish(xAxis?.ticks)
1684
+ ? getAxisTicks(xAxis.ticks, xScale, timestampUnit)
1685
+ : xScale == TIME &&
1686
+ isNumber(dataXMin) &&
1687
+ isNumber(dataXMax) &&
1688
+ dataXMin != dataXMax
1689
+ ? getTimeTicks(
1690
+ dataXMin,
1691
+ dataXMax,
1692
+ getTickCount(xAxis?.tickCount),
1693
+ labelSize,
1694
+ plotSize[0],
1695
+ )
1696
+ : getXTicks(
1697
+ axisKind,
1698
+ dataBounds,
1699
+ plotSize,
1700
+ labelSize,
1701
+ xAxis?.tickCount,
1702
+ );
1703
+ const yTicks = isNullish(yAxis?.ticks)
1704
+ ? getYTicks(dataBounds, plotSize, labelSize, yAxis?.tickCount)
1705
+ : getAxisTicks(yAxis.ticks);
1287
1706
  const tickBounds = getTickBounds(dataBounds, xTicks, yTicks);
1288
1707
  const axisPoints = getScaledPoints(
1289
1708
  axisKind,
1290
- xValues.map((xValue, index) => [`${index}`, xValue, 0]),
1709
+ arrayMap(xValues, (xValue, index) => [`${index}`, xValue, 0]),
1291
1710
  tickBounds,
1292
1711
  plotSize,
1293
1712
  xValues,
1713
+ xScale,
1714
+ timestampUnit,
1294
1715
  );
1295
1716
  const setNextDomainState = useCallback((summaryById) => {
1296
1717
  const nextDomainState = getDomainState(objValues(summaryById));
@@ -1318,11 +1739,21 @@ const CartesianChart = ({
1318
1739
  }, []);
1319
1740
  const setIncrementalDomainState = useCallback((summary) => {
1320
1741
  const currentBounds = boundsRef.current;
1742
+ const [currentXMin, currentXMax, currentYMin, currentYMax] = currentBounds;
1743
+ const {xMin, xMax, yMin, yMax} = summary;
1321
1744
  const nextBounds = [
1322
- getMin(currentBounds[0], summary.xMin),
1323
- getMax(currentBounds[1], summary.xMax),
1324
- getNumberMin(currentBounds[2], summary.yMin),
1325
- getNumberMax(currentBounds[3], summary.yMax),
1745
+ isNumber(currentXMin) && isNumber(xMin)
1746
+ ? mathMin(currentXMin, xMin)
1747
+ : (currentXMin ?? xMin),
1748
+ isNumber(currentXMax) && isNumber(xMax)
1749
+ ? mathMax(currentXMax, xMax)
1750
+ : (currentXMax ?? xMax),
1751
+ isNullish(currentYMin) || isNullish(yMin)
1752
+ ? (currentYMin ?? yMin)
1753
+ : mathMin(currentYMin, yMin),
1754
+ isNullish(currentYMax) || isNullish(yMax)
1755
+ ? (currentYMax ?? yMax)
1756
+ : mathMax(currentYMax, yMax),
1326
1757
  ];
1327
1758
  if (!boundsAreEqual(currentBounds, nextBounds)) {
1328
1759
  boundsRef.current = nextBounds;
@@ -1338,8 +1769,8 @@ const CartesianChart = ({
1338
1769
  (seriesId, summary) => {
1339
1770
  const currentSummaries = summariesRef.current;
1340
1771
  const currentSummary = currentSummaries[seriesId];
1341
- if (summary == null) {
1342
- if (currentSummary == null) {
1772
+ if (isNullish(summary)) {
1773
+ if (isNullish(currentSummary)) {
1343
1774
  return;
1344
1775
  }
1345
1776
  delete currentSummaries[seriesId];
@@ -1350,9 +1781,10 @@ const CartesianChart = ({
1350
1781
  currentSummaries[seriesId] = summary;
1351
1782
  setNextTitles(currentSummaries);
1352
1783
  if (
1353
- currentSummary == null
1354
- ? addsXValues(summary.xValues, domainStateRef.current.xValues) ||
1355
- summary.continuousX != domainStateRef.current.continuousX
1784
+ isNullish(currentSummary)
1785
+ ? !arrayEvery(summary.xValues, (xValue) =>
1786
+ arrayHas(domainStateRef.current.xValues, xValue),
1787
+ ) || summary.continuousX != domainStateRef.current.continuousX
1356
1788
  : ownsBound(currentSummary, boundsRef.current) ||
1357
1789
  currentSummary.continuousX != summary.continuousX ||
1358
1790
  !arrayIsEqual(currentSummary.xValues, summary.xValues)
@@ -1417,7 +1849,9 @@ const CartesianChart = ({
1417
1849
  store: storeObject,
1418
1850
  storeOrStoreId: store,
1419
1851
  tableId,
1852
+ timestampUnit,
1420
1853
  xTicks,
1854
+ xScale,
1421
1855
  xValues,
1422
1856
  yTicks,
1423
1857
  }),
@@ -1440,8 +1874,10 @@ const CartesianChart = ({
1440
1874
  store,
1441
1875
  storeObject,
1442
1876
  tableId,
1877
+ timestampUnit,
1443
1878
  tickBounds,
1444
1879
  xTicks,
1880
+ xScale,
1445
1881
  xValues,
1446
1882
  yTicks,
1447
1883
  ],
@@ -1469,21 +1905,22 @@ const CartesianChart = ({
1469
1905
  plotFrame,
1470
1906
  tickGap,
1471
1907
  tickSize,
1472
- titles: [xTitle, yTitle],
1908
+ titles: [xAxis?.title ?? xTitle, yAxis?.title ?? yTitle],
1909
+ timestampUnit,
1910
+ xAxis,
1473
1911
  xAxisHeight,
1912
+ xScale,
1474
1913
  xTicks,
1914
+ yAxis,
1475
1915
  yAxisWidth,
1476
1916
  yTicks,
1477
1917
  }),
1478
- /* @__PURE__ */ jsx('g', {
1479
- className: 'plot',
1480
- children: getChartChildren(children),
1481
- }),
1918
+ /* @__PURE__ */ jsx('g', {className: 'plot', children: chartChildren}),
1482
1919
  /* @__PURE__ */ jsx(Tooltip, {
1483
1920
  height: plotSize[1],
1484
1921
  point: tooltipPoint,
1485
1922
  plotFrame,
1486
- titles: [xTitle, yTitle],
1923
+ titles: [xAxis?.title ?? xTitle, yAxis?.title ?? yTitle],
1487
1924
  width: plotSize[0],
1488
1925
  }),
1489
1926
  ],
@@ -1503,31 +1940,6 @@ const ownsBound = (
1503
1940
  xMax === boundXMax ||
1504
1941
  yMin === boundYMin ||
1505
1942
  yMax === boundYMax;
1506
- const addsXValues = (xValues, currentXValues) => {
1507
- let adds = false;
1508
- arrayForEach(xValues, (xValue) => {
1509
- if (!arrayHas(currentXValues, xValue)) {
1510
- adds = true;
1511
- }
1512
- });
1513
- return adds;
1514
- };
1515
- const getMin = (value1, value2) =>
1516
- isNumber(value1) && isNumber(value2)
1517
- ? mathMin(value1, value2)
1518
- : (value1 ?? value2);
1519
- const getMax = (value1, value2) =>
1520
- isNumber(value1) && isNumber(value2)
1521
- ? mathMax(value1, value2)
1522
- : (value1 ?? value2);
1523
- const getNumberMin = (value1, value2) =>
1524
- value1 == null || value2 == null
1525
- ? (value1 ?? value2)
1526
- : mathMin(value1, value2);
1527
- const getNumberMax = (value1, value2) =>
1528
- value1 == null || value2 == null
1529
- ? (value1 ?? value2)
1530
- : mathMax(value1, value2);
1531
1943
  const getTitle = (summaryById, cellIdType) => {
1532
1944
  const titles = [];
1533
1945
  arrayForEach(objValues(summaryById), (summary) => {
@@ -1535,26 +1947,81 @@ const getTitle = (summaryById, cellIdType) => {
1535
1947
  cellIdType == 'yCellId'
1536
1948
  ? (summary.yLabel ?? summary.yCellId)
1537
1949
  : summary.xCellId;
1538
- if (title != null && !arrayHas(titles, title)) {
1950
+ if (!isNullish(title) && !arrayHas(titles, title)) {
1539
1951
  arrayPush(titles, title);
1540
1952
  }
1541
1953
  });
1542
- return arrayIsEmpty(titles) ? '' : titles.join(' & ');
1954
+ return arrayIsEmpty(titles) ? '' : arrayJoin(titles, TITLE_SEPARATOR);
1955
+ };
1956
+ const getAxisBounds = (
1957
+ [xMin, xMax, yMin, yMax],
1958
+ xValues,
1959
+ xScale,
1960
+ timestampUnit,
1961
+ xAxis,
1962
+ yAxis,
1963
+ ) => {
1964
+ const [xDomainMin, xDomainMax] = getXScaleDomain(
1965
+ [xMin, xMax],
1966
+ xValues,
1967
+ xScale,
1968
+ timestampUnit,
1969
+ );
1970
+ return [
1971
+ xScale == CATEGORY
1972
+ ? xDomainMin
1973
+ : getAxisBound(xAxis?.min, xDomainMin, xScale, timestampUnit),
1974
+ xScale == CATEGORY
1975
+ ? xDomainMax
1976
+ : getAxisBound(xAxis?.max, xDomainMax, xScale, timestampUnit),
1977
+ getNumberAxisBound(yAxis?.min, yMin),
1978
+ getNumberAxisBound(yAxis?.max, yMax),
1979
+ ];
1543
1980
  };
1544
- const getChartChildren = (children) => {
1981
+ const getAxisBound = (value, bound, xScale, timestampUnit) => {
1982
+ const axisBound =
1983
+ xScale == TIME ? normalizeTimeValue(value, timestampUnit) : value;
1984
+ return isFiniteNumber(axisBound) ? axisBound : bound;
1985
+ };
1986
+ const getNumberAxisBound = (value, bound) =>
1987
+ isFiniteNumber(value) ? value : bound;
1988
+ const getAxisTicks = (ticks, xScale = LINEAR, timestampUnit = MILLISECOND) =>
1989
+ arraySort(
1990
+ arrayFilter(
1991
+ arrayMap([...ticks], (tick) =>
1992
+ xScale == TIME ? normalizeTimeValue(tick, timestampUnit) : tick,
1993
+ ),
1994
+ (tick) => isFiniteNumber(tick),
1995
+ ),
1996
+ (tick1, tick2) => {
1997
+ return tick1 - tick2;
1998
+ },
1999
+ );
2000
+ const getParsedChildren = (children) => {
1545
2001
  const chartChildren = [];
2002
+ let xAxis;
2003
+ let yAxis;
1546
2004
  Children.forEach(children, (child) => {
1547
2005
  if (isValidElement(child)) {
1548
2006
  if (child.type === Fragment) {
1549
- arrayForEach(getChartChildren(child.props.children), (chartChild) =>
2007
+ const [childChildren, childXAxis, childYAxis] = getParsedChildren(
2008
+ child.props.children,
2009
+ );
2010
+ arrayForEach(childChildren, (chartChild) =>
1550
2011
  arrayPush(chartChildren, chartChild),
1551
2012
  );
1552
- } else if (isChartSeriesComponent(child.type)) {
2013
+ xAxis ??= childXAxis;
2014
+ yAxis ??= childYAxis;
2015
+ } else if (isSeriesComponent(child.type)) {
1553
2016
  arrayPush(chartChildren, child);
2017
+ } else if (isNullish(xAxis) && isXAxisComponent(child.type)) {
2018
+ xAxis = child.props;
2019
+ } else if (isNullish(yAxis) && isYAxisComponent(child.type)) {
2020
+ yAxis = child.props;
1554
2021
  }
1555
2022
  }
1556
2023
  });
1557
- return chartChildren;
2024
+ return [chartChildren, xAxis, yAxis];
1558
2025
  };
1559
2026
 
1560
2027
  const useInitialSeriesSummary = (
@@ -1575,38 +2042,45 @@ const useInitialSeriesSummary = (
1575
2042
  const storeObject = useStoreOrStoreById(store);
1576
2043
  const queriesObject = useQueriesOrQueriesById(queries);
1577
2044
  return useMemo(() => {
1578
- const points =
1579
- tableId == null
1580
- ? getDataPoints(
1581
- queriesObject?.getResultSortedRowIds(
1582
- queryId ?? '',
1583
- sortCellId ?? xCellId,
1584
- descending,
1585
- offset,
1586
- limit,
1587
- ) ?? [],
1588
- (rowId) =>
1589
- getDataPoint(
2045
+ const points = isNullish(tableId)
2046
+ ? getDataPoints(
2047
+ queriesObject?.getResultSortedRowIds(
2048
+ queryId ?? EMPTY_STRING,
2049
+ sortCellId ?? xCellId,
2050
+ descending,
2051
+ offset,
2052
+ limit,
2053
+ ) ?? [],
2054
+ (rowId) =>
2055
+ getDataPoint(
2056
+ rowId,
2057
+ queriesObject?.getResultCell(
2058
+ queryId ?? EMPTY_STRING,
1590
2059
  rowId,
1591
- queriesObject?.getResultCell(queryId ?? '', rowId, xCellId),
1592
- queriesObject?.getResultCell(queryId ?? '', rowId, yCellId),
2060
+ xCellId,
1593
2061
  ),
1594
- )
1595
- : getDataPoints(
1596
- storeObject?.getSortedRowIds(
1597
- tableId,
1598
- sortCellId ?? xCellId,
1599
- descending,
1600
- offset,
1601
- limit,
1602
- ) ?? [],
1603
- (rowId) =>
1604
- getDataPoint(
2062
+ queriesObject?.getResultCell(
2063
+ queryId ?? EMPTY_STRING,
1605
2064
  rowId,
1606
- storeObject?.getCell(tableId, rowId, xCellId),
1607
- storeObject?.getCell(tableId, rowId, yCellId),
2065
+ yCellId,
1608
2066
  ),
1609
- );
2067
+ ),
2068
+ )
2069
+ : getDataPoints(
2070
+ storeObject?.getSortedRowIds(
2071
+ tableId,
2072
+ sortCellId ?? xCellId,
2073
+ descending,
2074
+ offset,
2075
+ limit,
2076
+ ) ?? [],
2077
+ (rowId) =>
2078
+ getDataPoint(
2079
+ rowId,
2080
+ storeObject?.getCell(tableId, rowId, xCellId),
2081
+ storeObject?.getCell(tableId, rowId, yCellId),
2082
+ ),
2083
+ );
1610
2084
  return getSeriesSummary(kind, points, xCellId, yCellId);
1611
2085
  }, [
1612
2086
  descending,
@@ -1623,37 +2097,15 @@ const useInitialSeriesSummary = (
1623
2097
  ]);
1624
2098
  };
1625
2099
 
1626
- const BarChart = (props) => {
1627
- const initialSummary = useInitialSeriesSummary('bar', props);
1628
- return /* @__PURE__ */ jsx(CartesianChart, {
1629
- ...getSourceProps$1(props),
2100
+ const BarChart = ({children, ...props}) => {
2101
+ const initialSummary = useInitialSeriesSummary(BAR, props);
2102
+ const [sourceProps, seriesProps] = getConvenienceChartProps(props);
2103
+ return /* @__PURE__ */ jsxs(CartesianChart, {
2104
+ ...sourceProps,
1630
2105
  initialSummary,
1631
- children: /* @__PURE__ */ jsx(BarSeries, {...getSeriesProps$1(props)}),
2106
+ children: [/* @__PURE__ */ jsx(BarSeries, {...seriesProps}), children],
1632
2107
  });
1633
2108
  };
1634
- const getSourceProps$1 = (props) =>
1635
- props.tableId == null
1636
- ? {
1637
- className: props.className,
1638
- queries: props.queries,
1639
- queryId: props.queryId,
1640
- }
1641
- : {className: props.className, store: props.store, tableId: props.tableId};
1642
- const getSeriesProps$1 = ({
1643
- descending,
1644
- limit,
1645
- offset,
1646
- sortCellId,
1647
- xCellId,
1648
- yCellId,
1649
- }) => ({
1650
- descending,
1651
- limit,
1652
- offset,
1653
- sortCellId,
1654
- xCellId,
1655
- yCellId,
1656
- });
1657
2109
 
1658
2110
  const Line = ({plotFrame, points, setTooltipPoint}) => {
1659
2111
  const [plotX, plotY, , height] = plotFrame;
@@ -1713,28 +2165,31 @@ const LineSeries = (props) => {
1713
2165
  const {
1714
2166
  barSeriesCount,
1715
2167
  bounds,
1716
- domainState,
1717
2168
  plotFrame,
1718
2169
  plotSize,
1719
2170
  setSeriesSummary,
1720
2171
  setTooltipPoint,
2172
+ timestampUnit,
2173
+ xScale,
1721
2174
  xValues,
1722
2175
  } = useCartesianChartContext();
1723
2176
  const {className, label, xCellId, yCellId} = props;
1724
2177
  const [seriesId, rawPoints] = useSeriesData(props);
1725
2178
  const points = getScaledPoints(
1726
- domainState.continuousX || barSeriesCount == 0 ? 'line' : 'bar',
2179
+ xScale != CATEGORY || !barSeriesCount ? LINE : BAR,
1727
2180
  rawPoints,
1728
2181
  bounds,
1729
2182
  plotSize,
1730
2183
  xValues,
2184
+ xScale,
2185
+ timestampUnit,
1731
2186
  xCellId,
1732
2187
  label ?? yCellId,
1733
2188
  );
1734
2189
  useLayoutEffect(() => {
1735
2190
  setSeriesSummary(
1736
2191
  seriesId,
1737
- getSeriesSummary('line', rawPoints, xCellId, yCellId, label),
2192
+ getSeriesSummary(LINE, rawPoints, xCellId, yCellId, label),
1738
2193
  );
1739
2194
  });
1740
2195
  return /* @__PURE__ */ jsx('g', {
@@ -1746,38 +2201,30 @@ const LineSeries = (props) => {
1746
2201
  }),
1747
2202
  });
1748
2203
  };
1749
- LineSeries[CHART_SERIES] = true;
2204
+ LineSeries[SERIES] = true;
1750
2205
 
1751
- const LineChart = (props) => {
1752
- const initialSummary = useInitialSeriesSummary('line', props);
1753
- return /* @__PURE__ */ jsx(CartesianChart, {
1754
- ...getSourceProps(props),
2206
+ const LineChart = ({children, ...props}) => {
2207
+ const initialSummary = useInitialSeriesSummary(LINE, props);
2208
+ const [sourceProps, seriesProps] = getConvenienceChartProps(props);
2209
+ return /* @__PURE__ */ jsxs(CartesianChart, {
2210
+ ...sourceProps,
1755
2211
  initialSummary,
1756
- children: /* @__PURE__ */ jsx(LineSeries, {...getSeriesProps(props)}),
2212
+ children: [/* @__PURE__ */ jsx(LineSeries, {...seriesProps}), children],
1757
2213
  });
1758
2214
  };
1759
- const getSourceProps = (props) =>
1760
- props.tableId == null
1761
- ? {
1762
- className: props.className,
1763
- queries: props.queries,
1764
- queryId: props.queryId,
1765
- }
1766
- : {className: props.className, store: props.store, tableId: props.tableId};
1767
- const getSeriesProps = ({
1768
- descending,
1769
- limit,
1770
- offset,
1771
- sortCellId,
1772
- xCellId,
1773
- yCellId,
1774
- }) => ({
1775
- descending,
1776
- limit,
1777
- offset,
1778
- sortCellId,
1779
- xCellId,
1780
- yCellId,
1781
- });
1782
2215
 
1783
- export {BarChart, BarSeries, CartesianChart, LineChart, LineSeries};
2216
+ const XAxis = () => null;
2217
+ XAxis[X_AXIS] = true;
2218
+
2219
+ const YAxis = () => null;
2220
+ YAxis[Y_AXIS] = true;
2221
+
2222
+ export {
2223
+ BarChart,
2224
+ BarSeries,
2225
+ CartesianChart,
2226
+ LineChart,
2227
+ LineSeries,
2228
+ XAxis,
2229
+ YAxis,
2230
+ };