@perses-dev/components 0.0.0-snapshot-time-chart-rewrite-4667058 → 0.0.0-snapshot-panel-extra-content-3-17f9c42

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 (131) hide show
  1. package/README.md +1 -0
  2. package/dist/BarChart/BarChart.d.ts +16 -0
  3. package/dist/BarChart/BarChart.d.ts.map +1 -0
  4. package/dist/BarChart/BarChart.js +123 -0
  5. package/dist/BarChart/BarChart.js.map +1 -0
  6. package/dist/BarChart/index.d.ts +2 -0
  7. package/dist/BarChart/index.d.ts.map +1 -0
  8. package/dist/BarChart/index.js +15 -0
  9. package/dist/BarChart/index.js.map +1 -0
  10. package/dist/Dialog/DiscardChangesConfirmationDialog.d.ts +10 -0
  11. package/dist/Dialog/DiscardChangesConfirmationDialog.d.ts.map +1 -0
  12. package/dist/Dialog/DiscardChangesConfirmationDialog.js +47 -0
  13. package/dist/Dialog/DiscardChangesConfirmationDialog.js.map +1 -0
  14. package/dist/Dialog/index.d.ts +1 -0
  15. package/dist/Dialog/index.d.ts.map +1 -1
  16. package/dist/Dialog/index.js +1 -0
  17. package/dist/Dialog/index.js.map +1 -1
  18. package/dist/FontSizeSelector/FontSizeSelector.d.ts +8 -0
  19. package/dist/FontSizeSelector/FontSizeSelector.d.ts.map +1 -0
  20. package/dist/FontSizeSelector/FontSizeSelector.js +124 -0
  21. package/dist/FontSizeSelector/FontSizeSelector.js.map +1 -0
  22. package/dist/FontSizeSelector/index.d.ts +2 -0
  23. package/dist/FontSizeSelector/index.d.ts.map +1 -0
  24. package/dist/FontSizeSelector/index.js +15 -0
  25. package/dist/FontSizeSelector/index.js.map +1 -0
  26. package/dist/Legend/ListLegendItem.d.ts +1 -1
  27. package/dist/LineChart/LineChart.d.ts +2 -2
  28. package/dist/LineChart/LineChart.d.ts.map +1 -1
  29. package/dist/LineChart/LineChart.js +8 -8
  30. package/dist/LineChart/LineChart.js.map +1 -1
  31. package/dist/ModeSelector/ModeSelector.d.ts +9 -0
  32. package/dist/ModeSelector/ModeSelector.d.ts.map +1 -0
  33. package/dist/ModeSelector/ModeSelector.js +43 -0
  34. package/dist/ModeSelector/ModeSelector.js.map +1 -0
  35. package/dist/ModeSelector/index.d.ts +2 -0
  36. package/dist/ModeSelector/index.d.ts.map +1 -0
  37. package/dist/ModeSelector/index.js +15 -0
  38. package/dist/ModeSelector/index.js.map +1 -0
  39. package/dist/SortSelector/SortSelector.d.ts +8 -0
  40. package/dist/SortSelector/SortSelector.d.ts.map +1 -0
  41. package/dist/SortSelector/SortSelector.js +42 -0
  42. package/dist/SortSelector/SortSelector.js.map +1 -0
  43. package/dist/SortSelector/index.d.ts +2 -0
  44. package/dist/SortSelector/index.d.ts.map +1 -0
  45. package/dist/SortSelector/index.js +15 -0
  46. package/dist/SortSelector/index.js.map +1 -0
  47. package/dist/StatChart/StatChart.d.ts +2 -0
  48. package/dist/StatChart/StatChart.d.ts.map +1 -1
  49. package/dist/StatChart/StatChart.js +7 -5
  50. package/dist/StatChart/StatChart.js.map +1 -1
  51. package/dist/StatChart/calculateFontSize.d.ts +3 -1
  52. package/dist/StatChart/calculateFontSize.d.ts.map +1 -1
  53. package/dist/StatChart/calculateFontSize.js +5 -1
  54. package/dist/StatChart/calculateFontSize.js.map +1 -1
  55. package/dist/TimeChart/TimeChart.d.ts +3 -2
  56. package/dist/TimeChart/TimeChart.d.ts.map +1 -1
  57. package/dist/TimeChart/TimeChart.js +61 -21
  58. package/dist/TimeChart/TimeChart.js.map +1 -1
  59. package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts +6 -0
  60. package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts.map +1 -1
  61. package/dist/TimeSeriesTooltip/LineChartTooltip.js +14 -6
  62. package/dist/TimeSeriesTooltip/LineChartTooltip.js.map +1 -1
  63. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts +9 -3
  64. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
  65. package/dist/TimeSeriesTooltip/TimeChartTooltip.js +14 -6
  66. package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
  67. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +1 -0
  68. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -1
  69. package/dist/TimeSeriesTooltip/TooltipHeader.js +7 -9
  70. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
  71. package/dist/TimeSeriesTooltip/nearby-series.d.ts +1 -1
  72. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  73. package/dist/TimeSeriesTooltip/nearby-series.js +90 -102
  74. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  75. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +5 -0
  76. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  77. package/dist/TimeSeriesTooltip/tooltip-model.js +7 -0
  78. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  79. package/dist/TimeSeriesTooltip/utils.d.ts +2 -2
  80. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  81. package/dist/TimeSeriesTooltip/utils.js +22 -8
  82. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  83. package/dist/UnitSelector/UnitSelector.d.ts +2 -1
  84. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  85. package/dist/UnitSelector/UnitSelector.js +3 -2
  86. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  87. package/dist/cjs/BarChart/BarChart.js +129 -0
  88. package/dist/cjs/BarChart/index.js +28 -0
  89. package/dist/cjs/Dialog/DiscardChangesConfirmationDialog.js +53 -0
  90. package/dist/cjs/Dialog/index.js +1 -0
  91. package/dist/cjs/FontSizeSelector/FontSizeSelector.js +130 -0
  92. package/dist/cjs/FontSizeSelector/index.js +28 -0
  93. package/dist/cjs/LineChart/LineChart.js +7 -7
  94. package/dist/cjs/ModeSelector/ModeSelector.js +49 -0
  95. package/dist/cjs/ModeSelector/index.js +28 -0
  96. package/dist/cjs/SortSelector/SortSelector.js +48 -0
  97. package/dist/cjs/SortSelector/index.js +28 -0
  98. package/dist/cjs/StatChart/StatChart.js +7 -5
  99. package/dist/cjs/StatChart/calculateFontSize.js +5 -1
  100. package/dist/cjs/TimeChart/TimeChart.js +62 -17
  101. package/dist/cjs/TimeSeriesTooltip/LineChartTooltip.js +13 -5
  102. package/dist/cjs/TimeSeriesTooltip/TimeChartTooltip.js +13 -5
  103. package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +6 -8
  104. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +90 -102
  105. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +12 -1
  106. package/dist/cjs/TimeSeriesTooltip/utils.js +21 -7
  107. package/dist/cjs/UnitSelector/UnitSelector.js +3 -2
  108. package/dist/cjs/index.js +4 -0
  109. package/dist/cjs/model/graph.js +35 -3
  110. package/dist/cjs/utils/chart-actions.js +61 -1
  111. package/dist/cjs/utils/theme-gen.js +39 -7
  112. package/dist/index.d.ts +4 -0
  113. package/dist/index.d.ts.map +1 -1
  114. package/dist/index.js +4 -0
  115. package/dist/index.js.map +1 -1
  116. package/dist/model/graph.d.ts +14 -5
  117. package/dist/model/graph.d.ts.map +1 -1
  118. package/dist/model/graph.js +25 -0
  119. package/dist/model/graph.js.map +1 -1
  120. package/dist/model/theme.d.ts +5 -0
  121. package/dist/model/theme.d.ts.map +1 -1
  122. package/dist/model/theme.js.map +1 -1
  123. package/dist/utils/chart-actions.d.ts +3 -0
  124. package/dist/utils/chart-actions.d.ts.map +1 -1
  125. package/dist/utils/chart-actions.js +66 -0
  126. package/dist/utils/chart-actions.js.map +1 -1
  127. package/dist/utils/theme-gen.d.ts +6 -1
  128. package/dist/utils/theme-gen.d.ts.map +1 -1
  129. package/dist/utils/theme-gen.js +39 -7
  130. package/dist/utils/theme-gen.js.map +1 -1
  131. package/package.json +3 -3
@@ -33,6 +33,7 @@ _export(exports, {
33
33
  });
34
34
  const _core = require("@perses-dev/core");
35
35
  const _model = require("../model");
36
+ const _utils = require("../utils");
36
37
  const INCREASE_NEARBY_SERIES_MULTIPLIER = 5.5; // adjusts how many series show in tooltip (higher == more series shown)
37
38
  const DYNAMIC_NEARBY_SERIES_MULTIPLIER = 30; // used for adjustment after series number divisor
38
39
  const SHOW_FEWER_SERIES_LIMIT = 5;
@@ -43,13 +44,15 @@ function checkforNearbyTimeSeries(data, seriesMapping, pointInGrid, yBuffer, cha
43
44
  var ref1;
44
45
  const cursorY = (ref1 = pointInGrid[1]) !== null && ref1 !== void 0 ? ref1 : null;
45
46
  if (cursorX === null || cursorY === null) return currentNearbySeriesData;
47
+ if (chart.dispatchAction === undefined) return currentNearbySeriesData;
46
48
  if (!Array.isArray(data)) return currentNearbySeriesData;
47
- // TODO: better way to calc xBuffer for longer time ranges
48
- // const xBuffer = cursorX * 0.0000005;
49
49
  const nearbySeriesIndexes = [];
50
50
  const emphasizedSeriesIndexes = [];
51
51
  const nonEmphasizedSeriesIndexes = [];
52
+ const emphasizedDatapoints = [];
53
+ const duplicateDatapoints = [];
52
54
  const totalSeries = data.length;
55
+ const yValueCounts = new Map();
53
56
  let closestTimestamp = null;
54
57
  let closestDistance = Infinity;
55
58
  // find the timestamp with data that is closest to cursorX
@@ -59,6 +62,8 @@ function checkforNearbyTimeSeries(data, seriesMapping, pointInGrid, yBuffer, cha
59
62
  const currentDataset = totalSeries > 0 ? data[seriesIdx] : null;
60
63
  if (currentDataset == null) break;
61
64
  const currentDatasetValues = currentDataset.values;
65
+ // Determine closestTimestamp before checking whether it is equal to xValue. Consolidating
66
+ // with second currentDatasetValues loop below would result in duplicate nearby series
62
67
  for (const [timestamp] of currentDatasetValues){
63
68
  const distance = Math.abs(timestamp - cursorX);
64
69
  if (distance < closestDistance) {
@@ -79,7 +84,6 @@ function checkforNearbyTimeSeries(data, seriesMapping, pointInGrid, yBuffer, cha
79
84
  const yValue = nearbyTimeSeries[1];
80
85
  // TODO: ensure null values not displayed in tooltip
81
86
  if (yValue !== undefined && yValue !== null) {
82
- // if (cursorX < xValue + xBuffer && cursorX > xValue - xBuffer) {
83
87
  if (closestTimestamp === xValue) {
84
88
  if (cursorY <= yValue + yBuffer && cursorY >= yValue - yBuffer) {
85
89
  // show fewer bold series in tooltip when many total series
@@ -91,19 +95,36 @@ function checkforNearbyTimeSeries(data, seriesMapping, pointInGrid, yBuffer, cha
91
95
  percentage: percentRangeToCheck
92
96
  });
93
97
  if (isClosestToCursor) {
98
+ // shows as bold in tooltip, customize 'emphasis' options in getTimeSeries util
94
99
  emphasizedSeriesIndexes.push(seriesIdx);
95
- } else {
96
- nonEmphasizedSeriesIndexes.push(seriesIdx);
97
- // ensure series not close to cursor are not highlighted
98
- if ((chart === null || chart === void 0 ? void 0 : chart.dispatchAction) !== undefined) {
99
- chart.dispatchAction({
100
- type: 'downplay',
101
- seriesIndex: seriesIdx
100
+ var ref2;
101
+ // Used to determine which datapoint to apply select styles to.
102
+ // Accounts for cases where lines may be rendered directly on top of eachother.
103
+ const duplicateValuesCount = (ref2 = yValueCounts.get(yValue)) !== null && ref2 !== void 0 ? ref2 : 0;
104
+ yValueCounts.set(yValue, duplicateValuesCount + 1);
105
+ if (duplicateValuesCount > 0) {
106
+ duplicateDatapoints.push({
107
+ seriesIndex: seriesIdx,
108
+ dataIndex: datumIdx,
109
+ seriesName: currentSeriesName,
110
+ yValue: yValue
102
111
  });
103
112
  }
113
+ // keep track of all bold datapoints in tooltip so that 'select' state only applied to topmost
114
+ emphasizedDatapoints.push({
115
+ seriesIndex: seriesIdx,
116
+ dataIndex: datumIdx,
117
+ seriesName: currentSeriesName,
118
+ yValue: yValue
119
+ });
120
+ } else {
121
+ nonEmphasizedSeriesIndexes.push(seriesIdx);
122
+ // ensure series far away from cursor are not highlighted
123
+ chart.dispatchAction({
124
+ type: 'downplay',
125
+ seriesIndex: seriesIdx
126
+ });
104
127
  }
105
- // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
106
- // const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
107
128
  const formattedY = (0, _core.formatValue)(yValue, unit);
108
129
  currentNearbySeriesData.push({
109
130
  seriesIdx: seriesIdx,
@@ -123,32 +144,7 @@ function checkforNearbyTimeSeries(data, seriesMapping, pointInGrid, yBuffer, cha
123
144
  }
124
145
  }
125
146
  }
126
- if ((chart === null || chart === void 0 ? void 0 : chart.dispatchAction) !== undefined) {
127
- // Clears emphasis state of all lines that are not emphasized.
128
- // Emphasized is a subset of just the nearby series that are closest to cursor.
129
- chart.dispatchAction({
130
- type: 'downplay',
131
- seriesIndex: nonEmphasizedSeriesIndexes
132
- });
133
- // https://echarts.apache.org/en/api.html#action.highlight
134
- if (emphasizedSeriesIndexes.length > 0) {
135
- // Fadeout opacity of all series not closest to cursor.
136
- chart.dispatchAction({
137
- type: 'highlight',
138
- seriesIndex: emphasizedSeriesIndexes,
139
- notBlur: false,
140
- escapeConnect: true
141
- });
142
- } else {
143
- // When no emphasized series with bold text, notBlur allows opacity fadeout to not trigger.
144
- chart.dispatchAction({
145
- type: 'highlight',
146
- seriesIndex: nearbySeriesIndexes,
147
- notBlur: true,
148
- escapeConnect: true
149
- });
150
- }
151
- }
147
+ (0, _utils.batchDispatchNearbySeriesActions)(chart, nearbySeriesIndexes, emphasizedSeriesIndexes, nonEmphasizedSeriesIndexes, emphasizedDatapoints, duplicateDatapoints);
152
148
  return currentNearbySeriesData;
153
149
  }
154
150
  function legacyCheckforNearbySeries(data, pointInGrid, yBuffer, chart, unit) {
@@ -167,55 +163,54 @@ function legacyCheckforNearbySeries(data, pointInGrid, yBuffer, chart, unit) {
167
163
  if (Array.isArray(data.xAxis) && Array.isArray(data.timeSeries)) {
168
164
  for(let seriesIdx = 0; seriesIdx < totalSeries; seriesIdx++){
169
165
  const currentSeries = data.timeSeries[seriesIdx];
166
+ if (currentSeries === undefined) break;
170
167
  if (currentNearbySeriesData.length >= _model.OPTIMIZED_MODE_SERIES_LIMIT) break;
171
- if (currentSeries !== undefined) {
172
- const currentSeriesName = currentSeries.name ? currentSeries.name.toString() : '';
173
- var _color;
174
- const markerColor = (_color = currentSeries.color) !== null && _color !== void 0 ? _color : '#000';
175
- if (Array.isArray(currentSeries.data)) {
176
- for(let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++){
177
- var _datumIdx;
178
- const xValue = (_datumIdx = data.xAxis[datumIdx]) !== null && _datumIdx !== void 0 ? _datumIdx : 0;
179
- const yValue = currentSeries.data[datumIdx];
180
- // ensure null values not displayed in tooltip
181
- if (yValue !== undefined && yValue !== null && cursorX === datumIdx) {
182
- if (yValue !== '-' && cursorY <= yValue + yBuffer && cursorY >= yValue - yBuffer) {
183
- // show fewer bold series in tooltip when many total series
184
- const minPercentRange = totalSeries > SHOW_FEWER_SERIES_LIMIT ? 2 : 5;
185
- const percentRangeToCheck = Math.max(minPercentRange, 100 / totalSeries);
186
- const isClosestToCursor = isWithinPercentageRange({
187
- valueToCheck: cursorY,
188
- baseValue: yValue,
189
- percentage: percentRangeToCheck
190
- });
191
- if (isClosestToCursor) {
192
- emphasizedSeriesIndexes.push(seriesIdx);
193
- } else {
194
- nonEmphasizedSeriesIndexes.push(seriesIdx);
195
- // ensure series not close to cursor are not highlighted
196
- if ((chart === null || chart === void 0 ? void 0 : chart.dispatchAction) !== undefined) {
197
- chart.dispatchAction({
198
- type: 'downplay',
199
- seriesIndex: seriesIdx
200
- });
201
- }
168
+ const currentSeriesName = currentSeries.name ? currentSeries.name.toString() : '';
169
+ var _color;
170
+ const markerColor = (_color = currentSeries.color) !== null && _color !== void 0 ? _color : '#000';
171
+ if (Array.isArray(currentSeries.data)) {
172
+ for(let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++){
173
+ var _datumIdx;
174
+ const xValue = (_datumIdx = data.xAxis[datumIdx]) !== null && _datumIdx !== void 0 ? _datumIdx : 0;
175
+ const yValue = currentSeries.data[datumIdx];
176
+ // ensure null values not displayed in tooltip
177
+ if (yValue !== undefined && yValue !== null && cursorX === datumIdx) {
178
+ if (yValue !== '-' && cursorY <= yValue + yBuffer && cursorY >= yValue - yBuffer) {
179
+ // show fewer bold series in tooltip when many total series
180
+ const minPercentRange = totalSeries > SHOW_FEWER_SERIES_LIMIT ? 2 : 5;
181
+ const percentRangeToCheck = Math.max(minPercentRange, 100 / totalSeries);
182
+ const isClosestToCursor = isWithinPercentageRange({
183
+ valueToCheck: cursorY,
184
+ baseValue: yValue,
185
+ percentage: percentRangeToCheck
186
+ });
187
+ if (isClosestToCursor) {
188
+ emphasizedSeriesIndexes.push(seriesIdx);
189
+ } else {
190
+ nonEmphasizedSeriesIndexes.push(seriesIdx);
191
+ // ensure series not close to cursor are not highlighted
192
+ if ((chart === null || chart === void 0 ? void 0 : chart.dispatchAction) !== undefined) {
193
+ chart.dispatchAction({
194
+ type: 'downplay',
195
+ seriesIndex: seriesIdx
196
+ });
202
197
  }
203
- // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
204
- const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
205
- const formattedY = (0, _core.formatValue)(yValue, unit);
206
- currentNearbySeriesData.push({
207
- seriesIdx: seriesIdx,
208
- datumIdx: datumIdx,
209
- seriesName: currentSeriesName,
210
- date: xValueMilliSeconds,
211
- x: xValue,
212
- y: yValue,
213
- formattedY: formattedY,
214
- markerColor: markerColor.toString(),
215
- isClosestToCursor
216
- });
217
- nearbySeriesIndexes.push(seriesIdx);
218
198
  }
199
+ // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
200
+ const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
201
+ const formattedY = (0, _core.formatValue)(yValue, unit);
202
+ currentNearbySeriesData.push({
203
+ seriesIdx: seriesIdx,
204
+ datumIdx: datumIdx,
205
+ seriesName: currentSeriesName,
206
+ date: xValueMilliSeconds,
207
+ x: xValue,
208
+ y: yValue,
209
+ formattedY: formattedY,
210
+ markerColor: markerColor.toString(),
211
+ isClosestToCursor
212
+ });
213
+ nearbySeriesIndexes.push(seriesIdx);
219
214
  }
220
215
  }
221
216
  }
@@ -273,24 +268,17 @@ function getNearbySeriesData({ mousePos , pinnedPos , data , seriesMapping , cha
273
268
  }
274
269
  if (cursorTargetMatchesChart === false) return [];
275
270
  if (chart['_model'] === undefined || data === null) return [];
276
- const chartModel = chart['_model'];
277
- const yInterval = chartModel.getComponent('yAxis').axis.scale._interval;
278
- const totalSeries = data.length;
279
- const yBuffer = getYBuffer({
280
- yInterval,
281
- totalSeries,
282
- showAllSeries
283
- });
284
- var _x, _y;
285
- const pointInPixel = [
286
- (_x = mousePos.plotCanvas.x) !== null && _x !== void 0 ? _x : 0,
287
- (_y = mousePos.plotCanvas.y) !== null && _y !== void 0 ? _y : 0
288
- ];
289
- if (chart.containPixel('grid', pointInPixel)) {
290
- const pointInGrid = chart.convertFromPixel('grid', pointInPixel);
291
- if (pointInGrid[0] !== undefined && pointInGrid[1] !== undefined) {
292
- return checkforNearbyTimeSeries(data, seriesMapping, pointInGrid, yBuffer, chart, unit);
293
- }
271
+ const pointInGrid = (0, _utils.getPointInGrid)(mousePos.plotCanvas.x, mousePos.plotCanvas.y, chart);
272
+ if (pointInGrid !== null) {
273
+ const chartModel = chart['_model'];
274
+ const yInterval = chartModel.getComponent('yAxis').axis.scale._interval;
275
+ const totalSeries = data.length;
276
+ const yBuffer = getYBuffer({
277
+ yInterval,
278
+ totalSeries,
279
+ showAllSeries
280
+ });
281
+ return checkforNearbyTimeSeries(data, seriesMapping, pointInGrid, yBuffer, chart, unit);
294
282
  }
295
283
  return [];
296
284
  }
@@ -26,6 +26,7 @@ _export(exports, {
26
26
  TOOLTIP_MAX_HEIGHT: ()=>TOOLTIP_MAX_HEIGHT,
27
27
  TOOLTIP_LABELS_MAX_WIDTH: ()=>TOOLTIP_LABELS_MAX_WIDTH,
28
28
  TOOLTIP_ADJUST_Y_POS_MULTIPLIER: ()=>TOOLTIP_ADJUST_Y_POS_MULTIPLIER,
29
+ TOOLTIP_PADDING: ()=>TOOLTIP_PADDING,
29
30
  FALLBACK_CHART_WIDTH: ()=>FALLBACK_CHART_WIDTH,
30
31
  NEARBY_SERIES_DESCRIPTION: ()=>NEARBY_SERIES_DESCRIPTION,
31
32
  EMPHASIZED_SERIES_DESCRIPTION: ()=>EMPHASIZED_SERIES_DESCRIPTION,
@@ -33,7 +34,10 @@ _export(exports, {
33
34
  TOOLTIP_DATE_FORMAT: ()=>TOOLTIP_DATE_FORMAT,
34
35
  defaultCursorData: ()=>defaultCursorData,
35
36
  emptyTooltipData: ()=>emptyTooltipData,
36
- useMousePosition: ()=>useMousePosition
37
+ useMousePosition: ()=>useMousePosition,
38
+ DEFAULT_TOOLTIP_CONFIG: ()=>DEFAULT_TOOLTIP_CONFIG,
39
+ PIN_TOOLTIP_HELP_TEXT: ()=>PIN_TOOLTIP_HELP_TEXT,
40
+ UNPIN_TOOLTIP_HELP_TEXT: ()=>UNPIN_TOOLTIP_HELP_TEXT
37
41
  });
38
42
  const _react = require("react");
39
43
  const TOOLTIP_MIN_WIDTH = 375;
@@ -41,6 +45,7 @@ const TOOLTIP_MAX_WIDTH = 650;
41
45
  const TOOLTIP_MAX_HEIGHT = 650;
42
46
  const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;
43
47
  const TOOLTIP_ADJUST_Y_POS_MULTIPLIER = 0.75;
48
+ const TOOLTIP_PADDING = 8;
44
49
  const FALLBACK_CHART_WIDTH = 750;
45
50
  const NEARBY_SERIES_DESCRIPTION = 'nearby series showing in tooltip';
46
51
  const EMPHASIZED_SERIES_DESCRIPTION = 'emphasized series showing as bold in tooltip';
@@ -106,3 +111,9 @@ const useMousePosition = ()=>{
106
111
  }, []);
107
112
  return coords;
108
113
  };
114
+ const DEFAULT_TOOLTIP_CONFIG = {
115
+ wrapLabels: true,
116
+ enablePinning: true
117
+ };
118
+ const PIN_TOOLTIP_HELP_TEXT = 'Click chart to pin';
119
+ const UNPIN_TOOLTIP_HELP_TEXT = 'Click to unpin';
@@ -25,7 +25,7 @@ _export(exports, {
25
25
  getTooltipStyles: ()=>getTooltipStyles
26
26
  });
27
27
  const _tooltipModel = require("./tooltip-model");
28
- function assembleTransform(mousePos, chartWidth, pinnedPos, tooltipHeight, tooltipWidth) {
28
+ function assembleTransform(mousePos, chartWidth, pinnedPos, tooltipHeight, tooltipWidth, containerElement) {
29
29
  if (mousePos === null) {
30
30
  return 'translate3d(0, 0)';
31
31
  }
@@ -34,28 +34,42 @@ function assembleTransform(mousePos, chartWidth, pinnedPos, tooltipHeight, toolt
34
34
  if (pinnedPos !== null) {
35
35
  mousePos = pinnedPos;
36
36
  }
37
- // Tooltip is located in a Portal attached to the body.
37
+ // By default, tooltip is located in a Portal attached to the body.
38
38
  // Using page coordinates instead of viewport ensures the tooltip is
39
39
  // absolutely positioned correctly as the user scrolls
40
- const x = mousePos.page.x;
40
+ let x = mousePos.page.x;
41
41
  let y = mousePos.page.y + cursorPaddingY;
42
- // adjust so tooltip does not get cut off at bottom of chart
42
+ // If containerElement is defined, tooltip is attached to the containerElement instead.
43
+ let containerRect;
44
+ if (containerElement) {
45
+ // get the container's position relative to viewport
46
+ containerRect = containerElement.getBoundingClientRect();
47
+ // calculate the mouse position relative to container
48
+ x = x - containerRect.left + containerElement.scrollLeft;
49
+ y = y - containerRect.top + containerElement.scrollTop;
50
+ }
43
51
  if (mousePos.client.y + tooltipHeight + cursorPaddingY > window.innerHeight) {
52
+ // adjust so tooltip does not get cut off at bottom of chart
44
53
  // multiplier ensures tooltip isn't overly adjusted and gets cut off at the top of the viewport
45
- y = mousePos.page.y - tooltipHeight * _tooltipModel.TOOLTIP_ADJUST_Y_POS_MULTIPLIER;
54
+ y = y - tooltipHeight * _tooltipModel.TOOLTIP_ADJUST_Y_POS_MULTIPLIER;
55
+ // If y is now above of the top of containerElement, set y close to 0 so tooltip does not get cut off
56
+ if (containerRect && y < containerRect.top) {
57
+ y = _tooltipModel.TOOLTIP_PADDING / 2; // leaves room for some padding around tooltip
58
+ }
46
59
  }
47
60
  // use tooltip width to determine when to repos from right to left
48
61
  const xPosAdjustThreshold = chartWidth - tooltipWidth * 0.9;
49
62
  // reposition so tooltip is never too close to right side of chart or left side of browser window
50
63
  return mousePos.plotCanvas.x > xPosAdjustThreshold && x > _tooltipModel.TOOLTIP_MAX_WIDTH ? `translate3d(${x - cursorPaddingX}px, ${y}px, 0) translateX(-100%)` : `translate3d(${x + cursorPaddingX}px, ${y}px, 0)`;
51
64
  }
52
- function getTooltipStyles(theme, pinnedPos) {
65
+ function getTooltipStyles(theme, pinnedPos, maxHeight) {
53
66
  var ref;
67
+ const adjustedMaxHeight = maxHeight ? maxHeight - _tooltipModel.TOOLTIP_PADDING : undefined;
54
68
  var ref1;
55
69
  return {
56
70
  minWidth: _tooltipModel.TOOLTIP_MIN_WIDTH,
57
71
  maxWidth: _tooltipModel.TOOLTIP_MAX_WIDTH,
58
- maxHeight: _tooltipModel.TOOLTIP_MAX_HEIGHT,
72
+ maxHeight: adjustedMaxHeight !== null && adjustedMaxHeight !== void 0 ? adjustedMaxHeight : _tooltipModel.TOOLTIP_MAX_HEIGHT,
59
73
  padding: 0,
60
74
  position: 'absolute',
61
75
  top: 0,
@@ -64,7 +64,7 @@ const DECIMAL_PLACES_OPTIONS = [
64
64
  function getOptionByDecimalPlaces(decimal_places) {
65
65
  return DECIMAL_PLACES_OPTIONS.find((o)=>o.decimal_places === decimal_places);
66
66
  }
67
- function UnitSelector({ value , onChange }) {
67
+ function UnitSelector({ value , onChange , disabled =false }) {
68
68
  const hasDecimalPlaces = (0, _core.isUnitWithDecimalPlaces)(value);
69
69
  const hasAbbreviate = (0, _core.isUnitWithAbbreviate)(value);
70
70
  const handleKindChange = (_, newValue)=>{
@@ -109,7 +109,8 @@ function UnitSelector({ value , onChange }) {
109
109
  options: KIND_OPTIONS,
110
110
  groupBy: (option)=>option.group,
111
111
  onChange: handleKindChange,
112
- disableClearable: true
112
+ disableClearable: true,
113
+ disabled: disabled
113
114
  })
114
115
  }),
115
116
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
package/dist/cjs/index.js CHANGED
@@ -14,6 +14,7 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
+ _exportStar(require("./BarChart"), exports);
17
18
  _exportStar(require("./ColorPicker"), exports);
18
19
  _exportStar(require("./ContentWithLegend"), exports);
19
20
  _exportStar(require("./DateTimeRangePicker"), exports);
@@ -22,13 +23,16 @@ _exportStar(require("./Drawer"), exports);
22
23
  _exportStar(require("./EChart"), exports);
23
24
  _exportStar(require("./ErrorAlert"), exports);
24
25
  _exportStar(require("./ErrorBoundary"), exports);
26
+ _exportStar(require("./FontSizeSelector"), exports);
25
27
  _exportStar(require("./GaugeChart"), exports);
26
28
  _exportStar(require("./InfoTooltip"), exports);
27
29
  _exportStar(require("./JSONEditor"), exports);
28
30
  _exportStar(require("./Legend"), exports);
29
31
  _exportStar(require("./LineChart"), exports);
32
+ _exportStar(require("./ModeSelector"), exports);
30
33
  _exportStar(require("./OptionsEditorLayout"), exports);
31
34
  _exportStar(require("./SettingsAutocomplete"), exports);
35
+ _exportStar(require("./SortSelector"), exports);
32
36
  _exportStar(require("./StatChart"), exports);
33
37
  _exportStar(require("./Table"), exports);
34
38
  _exportStar(require("./ThresholdsEditor"), exports);
@@ -14,8 +14,40 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "OPTIMIZED_MODE_SERIES_LIMIT", {
18
- enumerable: true,
19
- get: ()=>OPTIMIZED_MODE_SERIES_LIMIT
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ OPTIMIZED_MODE_SERIES_LIMIT: ()=>OPTIMIZED_MODE_SERIES_LIMIT,
25
+ PINNED_CROSSHAIR_SERIES_NAME: ()=>PINNED_CROSSHAIR_SERIES_NAME,
26
+ DEFAULT_PINNED_CROSSHAIR: ()=>DEFAULT_PINNED_CROSSHAIR
20
27
  });
21
28
  const OPTIMIZED_MODE_SERIES_LIMIT = 1000;
29
+ const PINNED_CROSSHAIR_SERIES_NAME = 'Pinned Crosshair';
30
+ const DEFAULT_PINNED_CROSSHAIR = {
31
+ name: PINNED_CROSSHAIR_SERIES_NAME,
32
+ type: 'line',
33
+ // https://echarts.apache.org/en/option.html#series-line.markLine
34
+ markLine: {
35
+ data: [],
36
+ lineStyle: {
37
+ type: 'dashed',
38
+ width: 2
39
+ },
40
+ emphasis: {
41
+ lineStyle: {
42
+ width: 2,
43
+ opacity: 1
44
+ }
45
+ },
46
+ blur: {
47
+ lineStyle: {
48
+ width: 2,
49
+ opacity: 1
50
+ }
51
+ }
52
+ }
53
+ };
@@ -23,7 +23,9 @@ function _export(target, all) {
23
23
  _export(exports, {
24
24
  enableDataZoom: ()=>enableDataZoom,
25
25
  restoreChart: ()=>restoreChart,
26
- clearHighlightedSeries: ()=>clearHighlightedSeries
26
+ clearHighlightedSeries: ()=>clearHighlightedSeries,
27
+ getPointInGrid: ()=>getPointInGrid,
28
+ batchDispatchNearbySeriesActions: ()=>batchDispatchNearbySeriesActions
27
29
  });
28
30
  function enableDataZoom(chart) {
29
31
  const chartModel = chart['_model'];
@@ -55,3 +57,61 @@ function clearHighlightedSeries(chart, totalSeries) {
55
57
  }
56
58
  }
57
59
  }
60
+ function getPointInGrid(cursorCoordX, cursorCoordY, chart) {
61
+ if (chart === undefined) {
62
+ return null;
63
+ }
64
+ const pointInPixel = [
65
+ cursorCoordX,
66
+ cursorCoordY
67
+ ];
68
+ if (!chart.containPixel('grid', pointInPixel)) {
69
+ return null;
70
+ }
71
+ const pointInGrid = chart.convertFromPixel('grid', pointInPixel);
72
+ return pointInGrid;
73
+ }
74
+ function batchDispatchNearbySeriesActions(chart, nearbySeriesIndexes, emphasizedSeriesIndexes, nonEmphasizedSeriesIndexes, emphasizedDatapoints, duplicateDatapoints) {
75
+ // Accounts for multiple series that are rendered direct on top of eachother.
76
+ // Only applies select state to the datapoint that is visible to avoid color mismatch.
77
+ const lastEmphasizedDatapoint = duplicateDatapoints.length > 0 ? duplicateDatapoints[duplicateDatapoints.length - 1] : emphasizedDatapoints[emphasizedDatapoints.length - 1];
78
+ if (lastEmphasizedDatapoint !== undefined) {
79
+ // Corresponds to select options inside getTimeSeries util.
80
+ // https://echarts.apache.org/en/option.html#series-line.select.itemStyle
81
+ chart.dispatchAction({
82
+ type: 'select',
83
+ seriesIndex: lastEmphasizedDatapoint.seriesIndex,
84
+ dataIndex: lastEmphasizedDatapoint.dataIndex,
85
+ // Shared crosshair should not emphasize datapoints on adjacent charts.
86
+ escapeConnect: true
87
+ });
88
+ }
89
+ // Clears emphasis state of all lines that are not emphasized.
90
+ // Emphasized is a subset of just the nearby series that are closest to cursor.
91
+ chart.dispatchAction({
92
+ type: 'downplay',
93
+ seriesIndex: nonEmphasizedSeriesIndexes
94
+ });
95
+ // https://echarts.apache.org/en/api.html#action.highlight
96
+ if (emphasizedSeriesIndexes.length > 0) {
97
+ // Fadeout opacity of all series not closest to cursor.
98
+ chart.dispatchAction({
99
+ type: 'highlight',
100
+ seriesIndex: emphasizedSeriesIndexes,
101
+ notBlur: false,
102
+ escapeConnect: true
103
+ });
104
+ } else {
105
+ // When no emphasized series with bold text, notBlur allows opacity fadeout to not trigger.
106
+ chart.dispatchAction({
107
+ type: 'highlight',
108
+ seriesIndex: nearbySeriesIndexes,
109
+ notBlur: true,
110
+ escapeConnect: true
111
+ });
112
+ // Clears selected datapoints since no bold series in tooltip, restore does not impact highlighting
113
+ chart.dispatchAction({
114
+ type: 'toggleSelect'
115
+ });
116
+ }
117
+ }
@@ -25,10 +25,13 @@ function _interopRequireDefault(obj) {
25
25
  };
26
26
  }
27
27
  const DEFAULT_TEXT_COLOR = '#222';
28
- function generateChartsTheme(muiTheme, echartsTheme) {
29
- var ref, ref1, ref2, ref3, ref4;
30
- var ref5;
31
- const primaryTextColor = (ref5 = (ref = muiTheme.palette.text) === null || ref === void 0 ? void 0 : ref.primary) !== null && ref5 !== void 0 ? ref5 : DEFAULT_TEXT_COLOR;
28
+ function generateChartsTheme(muiTheme, echartsTheme, /**
29
+ * The id of the container that will have the chart tooltip appended to it.
30
+ * By default, chart tooltip uses the body of the top-level document object.
31
+ */ tooltipPortalContainerId) {
32
+ var ref, ref1, ref2, ref3, ref4, ref5, ref6;
33
+ var ref7;
34
+ const primaryTextColor = (ref7 = (ref = muiTheme.palette.text) === null || ref === void 0 ? void 0 : ref.primary) !== null && ref7 !== void 0 ? ref7 : DEFAULT_TEXT_COLOR;
32
35
  const muiConvertedTheme = {
33
36
  title: {
34
37
  show: false
@@ -80,7 +83,7 @@ function generateChartsTheme(muiTheme, echartsTheme) {
80
83
  lineStyle: {
81
84
  width: 0.5,
82
85
  color: muiTheme.palette.grey[300],
83
- opacity: 0.6
86
+ opacity: 0.4
84
87
  }
85
88
  },
86
89
  splitArea: {
@@ -117,7 +120,7 @@ function generateChartsTheme(muiTheme, echartsTheme) {
117
120
  lineStyle: {
118
121
  width: 0.5,
119
122
  color: muiTheme.palette.grey[300],
120
- opacity: 0.6
123
+ opacity: 0.4
121
124
  }
122
125
  },
123
126
  splitArea: {
@@ -166,7 +169,30 @@ function generateChartsTheme(muiTheme, echartsTheme) {
166
169
  borderColor: primaryTextColor
167
170
  }
168
171
  },
169
- tooltip: {},
172
+ tooltip: {
173
+ backgroundColor: (ref5 = muiTheme.palette.designSystem) === null || ref5 === void 0 ? void 0 : ref5.grey[800],
174
+ borderColor: (ref6 = muiTheme.palette.designSystem) === null || ref6 === void 0 ? void 0 : ref6.grey[800],
175
+ textStyle: {
176
+ color: '#fff',
177
+ fontSize: 11
178
+ }
179
+ },
180
+ axisPointer: {
181
+ lineStyle: {
182
+ color: muiTheme.palette.grey[500]
183
+ }
184
+ },
185
+ markLine: {
186
+ symbol: 'none',
187
+ symbolSize: 0,
188
+ itemStyle: {
189
+ color: muiTheme.palette.grey[500]
190
+ },
191
+ lineStyle: {
192
+ type: 'dashed',
193
+ width: 1
194
+ }
195
+ },
170
196
  line: {
171
197
  showSymbol: false,
172
198
  symbol: 'circle',
@@ -185,7 +211,12 @@ function generateChartsTheme(muiTheme, echartsTheme) {
185
211
  barMaxWidth: 150,
186
212
  itemStyle: {
187
213
  borderWidth: 0,
214
+ borderRadius: 0,
188
215
  borderColor: muiTheme.palette.grey[300]
216
+ },
217
+ label: {
218
+ show: false,
219
+ color: primaryTextColor
189
220
  }
190
221
  },
191
222
  gauge: {
@@ -205,6 +236,7 @@ function generateChartsTheme(muiTheme, echartsTheme) {
205
236
  }
206
237
  };
207
238
  return {
239
+ tooltipPortalContainerId,
208
240
  echartsTheme: (0, _merge.default)(muiConvertedTheme, echartsTheme),
209
241
  noDataOption: {
210
242
  title: {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './BarChart';
1
2
  export * from './ColorPicker';
2
3
  export * from './ContentWithLegend';
3
4
  export * from './DateTimeRangePicker';
@@ -6,13 +7,16 @@ export * from './Drawer';
6
7
  export * from './EChart';
7
8
  export * from './ErrorAlert';
8
9
  export * from './ErrorBoundary';
10
+ export * from './FontSizeSelector';
9
11
  export * from './GaugeChart';
10
12
  export * from './InfoTooltip';
11
13
  export * from './JSONEditor';
12
14
  export * from './Legend';
13
15
  export * from './LineChart';
16
+ export * from './ModeSelector';
14
17
  export * from './OptionsEditorLayout';
15
18
  export * from './SettingsAutocomplete';
19
+ export * from './SortSelector';
16
20
  export * from './StatChart';
17
21
  export * from './Table';
18
22
  export * from './ThresholdsEditor';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC"}