@perses-dev/components 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
  2. package/dist/DateTimeRangePicker/TimeRangeSelector.js +7 -1
  3. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
  4. package/dist/EChart/EChart.d.ts.map +1 -1
  5. package/dist/EChart/EChart.js +1 -7
  6. package/dist/EChart/EChart.js.map +1 -1
  7. package/dist/LineChart/LineChart.d.ts.map +1 -1
  8. package/dist/LineChart/LineChart.js +4 -0
  9. package/dist/LineChart/LineChart.js.map +1 -1
  10. package/dist/StatChart/StatChart.d.ts.map +1 -1
  11. package/dist/StatChart/StatChart.js +5 -1
  12. package/dist/StatChart/StatChart.js.map +1 -1
  13. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +1 -1
  14. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  15. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +6 -5
  16. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  17. package/dist/TimeSeriesTooltip/TooltipContent.js +2 -2
  18. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  19. package/dist/TimeSeriesTooltip/focused-series.d.ts +1 -1
  20. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +1 -1
  21. package/dist/TimeSeriesTooltip/focused-series.js +2 -3
  22. package/dist/TimeSeriesTooltip/focused-series.js.map +1 -1
  23. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +4 -0
  24. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  25. package/dist/TimeSeriesTooltip/tooltip-model.js +4 -0
  26. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  27. package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
  28. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  29. package/dist/TimeSeriesTooltip/utils.js +5 -14
  30. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  31. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  32. package/dist/UnitSelector/UnitSelector.js +40 -17
  33. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  34. package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +7 -1
  35. package/dist/cjs/EChart/EChart.js +1 -7
  36. package/dist/cjs/LineChart/LineChart.js +4 -0
  37. package/dist/cjs/StatChart/StatChart.js +5 -1
  38. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +11 -5
  39. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +2 -2
  40. package/dist/cjs/TimeSeriesTooltip/focused-series.js +1 -2
  41. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +4 -0
  42. package/dist/cjs/TimeSeriesTooltip/utils.js +5 -14
  43. package/dist/cjs/UnitSelector/UnitSelector.js +39 -16
  44. package/dist/cjs/model/units/bytes.js +25 -21
  45. package/dist/cjs/model/units/constants.js +3 -3
  46. package/dist/cjs/model/units/decimal.js +22 -19
  47. package/dist/cjs/model/units/percent.js +15 -22
  48. package/dist/cjs/model/units/time.js +24 -20
  49. package/dist/cjs/model/units/units.js +2 -2
  50. package/dist/cjs/model/units/utils.js +42 -0
  51. package/dist/model/units/bytes.d.ts +1 -1
  52. package/dist/model/units/bytes.d.ts.map +1 -1
  53. package/dist/model/units/bytes.js +26 -22
  54. package/dist/model/units/bytes.js.map +1 -1
  55. package/dist/model/units/constants.d.ts +1 -1
  56. package/dist/model/units/constants.js +1 -1
  57. package/dist/model/units/constants.js.map +1 -1
  58. package/dist/model/units/decimal.d.ts +2 -2
  59. package/dist/model/units/decimal.d.ts.map +1 -1
  60. package/dist/model/units/decimal.js +22 -19
  61. package/dist/model/units/decimal.js.map +1 -1
  62. package/dist/model/units/percent.d.ts +1 -1
  63. package/dist/model/units/percent.d.ts.map +1 -1
  64. package/dist/model/units/percent.js +14 -21
  65. package/dist/model/units/percent.js.map +1 -1
  66. package/dist/model/units/time.d.ts +1 -1
  67. package/dist/model/units/time.d.ts.map +1 -1
  68. package/dist/model/units/time.js +24 -20
  69. package/dist/model/units/time.js.map +1 -1
  70. package/dist/model/units/units.js +2 -2
  71. package/dist/model/units/units.js.map +1 -1
  72. package/dist/model/units/utils.d.ts +4 -0
  73. package/dist/model/units/utils.d.ts.map +1 -0
  74. package/dist/model/units/utils.js +32 -0
  75. package/dist/model/units/utils.js.map +1 -0
  76. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip-model.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/tooltip-model.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,wBAAwB,QAA0B,CAAC;AAEhE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,eAAO,MAAM,mBAAmB,qBAQ9B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAa7B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;CAG5B,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE;QACJ,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;IACF,UAAU,EAAE;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;IACF,OAAO,EAAE;QACP,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;KACZ,CAAC;IACF,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,iBAA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C,EAAE,MAAM,CAAC;KACX,CAAC;IACF,OAAO,EAAE;QACP,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;KACZ,CAAC;IACF,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACzC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,aAAK,iBAAiB,GAAG;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,cAAc,GAAG,gBAAgB,CAAC;IACnD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,oBAAY,eAAe,GAAG,UAAU,GAAG,iBAAiB,CAAC;AAE7D,eAAO,MAAM,gBAAgB,QAAO,UAAU,CAAC,QAAQ,CAoCtD,CAAC"}
@@ -51,6 +51,10 @@ export const useMousePosition = ()=>{
51
51
  x: e.pageX,
52
52
  y: e.pageY
53
53
  },
54
+ client: {
55
+ x: e.clientX,
56
+ y: e.clientY
57
+ },
54
58
  plotCanvas: {
55
59
  x: e.offsetX,
56
60
  y: e.offsetY
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/TimeSeriesTooltip/tooltip-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useEffect, useState } from 'react';\nimport { FocusedSeriesArray } from './focused-series';\n\nexport const TOOLTIP_MAX_WIDTH = 650;\nexport const TOOLTIP_MAX_HEIGHT = 400;\nexport const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;\n\nexport const TOOLTIP_MAX_ITEMS = 50;\n\nexport const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n hour12: true,\n});\n\nexport const defaultCursorData = {\n coords: {\n plotCanvas: {\n x: 0,\n y: 0,\n },\n zrender: {\n x: 0,\n y: 0,\n },\n target: null,\n },\n chartWidth: 0,\n};\n\nexport const emptyTooltipData = {\n cursor: defaultCursorData,\n focusedSeries: null,\n};\n\nexport interface CursorCoordinates {\n page: {\n x: number;\n y: number;\n };\n plotCanvas: {\n x: number;\n y: number;\n };\n zrender: {\n x?: number;\n y?: number;\n };\n target: EventTarget | null;\n}\n\nexport interface CursorData {\n coords: CursorCoordinates | null;\n chartWidth?: number;\n}\n\nexport interface TooltipData {\n focusedSeries: FocusedSeriesArray | null;\n cursor: CursorData;\n}\n\ntype ZREventProperties = {\n zrX?: number;\n zrY?: number;\n zrDelta?: number;\n zrEventControl?: 'no_globalout' | 'only_globalout';\n zrByTouch?: boolean;\n};\n\nexport type ZRRawMouseEvent = MouseEvent & ZREventProperties;\n\nexport const useMousePosition = (): CursorData['coords'] => {\n const [coords, setCoords] = useState<CursorData['coords']>(null);\n\n useEffect(() => {\n const setFromEvent = (e: ZRRawMouseEvent) => {\n return setCoords({\n page: {\n x: e.pageX,\n y: e.pageY,\n },\n plotCanvas: {\n x: e.offsetX,\n y: e.offsetY,\n },\n zrender: {\n // echarts canvas coordinates added automatically by zrender\n // zrX and zrY are similar to offsetX and offsetY but they return undefined when not hovering over a chart canvas\n x: e.zrX,\n y: e.zrY,\n },\n // necessary to check whether cursor target matches correct chart canvas (since each chart has its own mousemove listener)\n target: e.target,\n });\n };\n window.addEventListener('mousemove', setFromEvent);\n\n return () => {\n window.removeEventListener('mousemove', setFromEvent);\n };\n }, []);\n\n return coords;\n};\n"],"names":["useEffect","useState","TOOLTIP_MAX_WIDTH","TOOLTIP_MAX_HEIGHT","TOOLTIP_LABELS_MAX_WIDTH","TOOLTIP_MAX_ITEMS","TOOLTIP_DATE_FORMAT","Intl","DateTimeFormat","undefined","year","month","day","hour","minute","second","hour12","defaultCursorData","coords","plotCanvas","x","y","zrender","target","chartWidth","emptyTooltipData","cursor","focusedSeries","useMousePosition","setCoords","setFromEvent","e","page","pageX","pageY","offsetX","offsetY","zrX","zrY","window","addEventListener","removeEventListener"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAG5C,OAAO,MAAMC,iBAAiB,GAAG,GAAG,CAAC;AACrC,OAAO,MAAMC,kBAAkB,GAAG,GAAG,CAAC;AACtC,OAAO,MAAMC,wBAAwB,GAAGF,iBAAiB,GAAG,GAAG,CAAC;AAEhE,OAAO,MAAMG,iBAAiB,GAAG,EAAE,CAAC;AAEpC,OAAO,MAAMC,mBAAmB,GAAG,IAAIC,IAAI,CAACC,cAAc,CAACC,SAAS,EAAE;IACpEC,IAAI,EAAE,SAAS;IACfC,KAAK,EAAE,OAAO;IACdC,GAAG,EAAE,SAAS;IACdC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE,SAAS;IACjBC,MAAM,EAAE,SAAS;IACjBC,MAAM,EAAE,IAAI;CACb,CAAC,CAAC;AAEH,OAAO,MAAMC,iBAAiB,GAAG;IAC/BC,MAAM,EAAE;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../../src/TimeSeriesTooltip/tooltip-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useEffect, useState } from 'react';\nimport { FocusedSeriesArray } from './focused-series';\n\nexport const TOOLTIP_MAX_WIDTH = 650;\nexport const TOOLTIP_MAX_HEIGHT = 400;\nexport const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;\n\nexport const TOOLTIP_MAX_ITEMS = 50;\n\nexport const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n hour12: true,\n});\n\nexport const defaultCursorData = {\n coords: {\n plotCanvas: {\n x: 0,\n y: 0,\n },\n zrender: {\n x: 0,\n y: 0,\n },\n target: null,\n },\n chartWidth: 0,\n};\n\nexport const emptyTooltipData = {\n cursor: defaultCursorData,\n focusedSeries: null,\n};\n\nexport interface CursorCoordinates {\n page: {\n x: number;\n y: number;\n };\n client: {\n x: number;\n y: number;\n };\n plotCanvas: {\n x: number;\n y: number;\n };\n zrender: {\n x?: number;\n y?: number;\n };\n target: EventTarget | null;\n}\n\nexport interface CursorData {\n coords: CursorCoordinates | null;\n chartWidth?: number;\n}\n\nexport interface TooltipData {\n focusedSeries: FocusedSeriesArray | null;\n cursor: CursorData;\n}\n\ntype ZREventProperties = {\n zrX?: number;\n zrY?: number;\n zrDelta?: number;\n zrEventControl?: 'no_globalout' | 'only_globalout';\n zrByTouch?: boolean;\n};\n\nexport type ZRRawMouseEvent = MouseEvent & ZREventProperties;\n\nexport const useMousePosition = (): CursorData['coords'] => {\n const [coords, setCoords] = useState<CursorData['coords']>(null);\n\n useEffect(() => {\n const setFromEvent = (e: ZRRawMouseEvent) => {\n return setCoords({\n page: {\n x: e.pageX,\n y: e.pageY,\n },\n client: {\n x: e.clientX,\n y: e.clientY,\n },\n plotCanvas: {\n x: e.offsetX,\n y: e.offsetY,\n },\n zrender: {\n // echarts canvas coordinates added automatically by zrender\n // zrX and zrY are similar to offsetX and offsetY but they return undefined when not hovering over a chart canvas\n x: e.zrX,\n y: e.zrY,\n },\n // necessary to check whether cursor target matches correct chart canvas (since each chart has its own mousemove listener)\n target: e.target,\n });\n };\n window.addEventListener('mousemove', setFromEvent);\n\n return () => {\n window.removeEventListener('mousemove', setFromEvent);\n };\n }, []);\n\n return coords;\n};\n"],"names":["useEffect","useState","TOOLTIP_MAX_WIDTH","TOOLTIP_MAX_HEIGHT","TOOLTIP_LABELS_MAX_WIDTH","TOOLTIP_MAX_ITEMS","TOOLTIP_DATE_FORMAT","Intl","DateTimeFormat","undefined","year","month","day","hour","minute","second","hour12","defaultCursorData","coords","plotCanvas","x","y","zrender","target","chartWidth","emptyTooltipData","cursor","focusedSeries","useMousePosition","setCoords","setFromEvent","e","page","pageX","pageY","client","clientX","clientY","offsetX","offsetY","zrX","zrY","window","addEventListener","removeEventListener"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAG5C,OAAO,MAAMC,iBAAiB,GAAG,GAAG,CAAC;AACrC,OAAO,MAAMC,kBAAkB,GAAG,GAAG,CAAC;AACtC,OAAO,MAAMC,wBAAwB,GAAGF,iBAAiB,GAAG,GAAG,CAAC;AAEhE,OAAO,MAAM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5D,iHAAiH;oBACjHF,CAAC,EAAEW,CAAC,CAACS,GAAG;oBACRnB,CAAC,EAAEU,CAAC,CAACU,GAAG;iBACT;gBACD,0HAA0H;gBAC1HlB,MAAM,EAAEQ,CAAC,CAACR,MAAM;aACjB,CAAC,CAAC;QACL,CAAC,AAAC;QACFmB,MAAM,CAACC,gBAAgB,CAAC,WAAW,EAAEb,YAAY,CAAC,CAAC;QAEnD,OAAO,IAAM;YACXY,MAAM,CAACE,mBAAmB,CAAC,WAAW,EAAEd,YAAY,CAAC,CAAC;QACxD,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAOZ,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -2,5 +2,5 @@ import { CursorCoordinates, CursorData } from './tooltip-model';
2
2
  /**
3
3
  * Determine position of tooltip depending on chart dimensions and the number of focused series
4
4
  */
5
- export declare function assembleTransform(mousePos: CursorData['coords'], seriesNum: number, chartWidth: number, chartHeight: number, pinnedPos: CursorCoordinates | null): string;
5
+ export declare function assembleTransform(mousePos: CursorData['coords'], seriesNum: number, chartWidth: number, pinnedPos: CursorCoordinates | null, tooltipHeight: number, tooltipWidth: number): string;
6
6
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAqB,MAAM,iBAAiB,CAAC;AAEnF;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,iBAAiB,GAAG,IAAI,UAwCpC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAqB,MAAM,iBAAiB,CAAC;AAEnF;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,iBAAiB,GAAG,IAAI,EACnC,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,UA+BrB"}
@@ -13,7 +13,7 @@
13
13
  import { TOOLTIP_MAX_WIDTH } from './tooltip-model';
14
14
  /**
15
15
  * Determine position of tooltip depending on chart dimensions and the number of focused series
16
- */ export function assembleTransform(mousePos, seriesNum, chartWidth, chartHeight, pinnedPos) {
16
+ */ export function assembleTransform(mousePos, seriesNum, chartWidth, pinnedPos, tooltipHeight, tooltipWidth) {
17
17
  if (mousePos === null) {
18
18
  return 'translate3d(0, 0)';
19
19
  }
@@ -27,20 +27,11 @@ import { TOOLTIP_MAX_WIDTH } from './tooltip-model';
27
27
  // absolutely positioned correctly as the user scrolls
28
28
  const x = mousePos.page.x;
29
29
  let y = mousePos.page.y + cursorPaddingY;
30
- const isCloseToBottom = mousePos.page.y > window.innerHeight * 0.8;
31
- const yPosAdjustThreshold = chartHeight * 0.75;
32
- // adjust so tooltip does not get cut off at bottom of chart, reduce multiplier to move up
33
- if (isCloseToBottom === true) {
34
- if (seriesNum > 6) {
35
- y = mousePos.page.y * 0.75;
36
- } else {
37
- y = mousePos.page.y * 0.9;
38
- }
39
- } else if (mousePos.plotCanvas.y > yPosAdjustThreshold) {
40
- y = mousePos.page.y * 0.95;
30
+ // adjust so tooltip does not get cut off at bottom of chart
31
+ if (mousePos.client.y + tooltipHeight + cursorPaddingY > window.innerHeight) {
32
+ y = mousePos.page.y - tooltipHeight;
41
33
  }
42
- // use tooltip width to determine when to repos from right to left (width is narrower when only 1 focused series since labels wrap)
43
- const tooltipWidth = seriesNum > 1 ? TOOLTIP_MAX_WIDTH : TOOLTIP_MAX_WIDTH / 2;
34
+ // use tooltip width to determine when to repos from right to left
44
35
  const xPosAdjustThreshold = chartWidth - tooltipWidth * 0.9;
45
36
  // reposition so tooltip is never too close to right side of chart or left side of browser window
46
37
  return mousePos.plotCanvas.x > xPosAdjustThreshold && x > TOOLTIP_MAX_WIDTH ? `translate3d(${x - cursorPaddingX}px, ${y}px, 0) translateX(-100%)` : `translate3d(${x + cursorPaddingX}px, ${y}px, 0)`;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/TimeSeriesTooltip/utils.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { CursorCoordinates, CursorData, TOOLTIP_MAX_WIDTH } from './tooltip-model';\n\n/**\n * Determine position of tooltip depending on chart dimensions and the number of focused series\n */\nexport function assembleTransform(\n mousePos: CursorData['coords'],\n seriesNum: number,\n chartWidth: number,\n chartHeight: number,\n pinnedPos: CursorCoordinates | null\n) {\n if (mousePos === null) {\n return 'translate3d(0, 0)';\n }\n\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n }\n\n const cursorPaddingX = 32;\n const cursorPaddingY = 16;\n\n // Tooltip is located in a Portal attached to the body.\n // Using page coordinates instead of viewport ensures the tooltip is\n // absolutely positioned correctly as the user scrolls\n const x = mousePos.page.x;\n let y = mousePos.page.y + cursorPaddingY;\n\n const isCloseToBottom = mousePos.page.y > window.innerHeight * 0.8;\n const yPosAdjustThreshold = chartHeight * 0.75;\n // adjust so tooltip does not get cut off at bottom of chart, reduce multiplier to move up\n if (isCloseToBottom === true) {\n if (seriesNum > 6) {\n y = mousePos.page.y * 0.75;\n } else {\n y = mousePos.page.y * 0.9;\n }\n } else if (mousePos.plotCanvas.y > yPosAdjustThreshold) {\n y = mousePos.page.y * 0.95;\n }\n\n // use tooltip width to determine when to repos from right to left (width is narrower when only 1 focused series since labels wrap)\n const tooltipWidth = seriesNum > 1 ? TOOLTIP_MAX_WIDTH : TOOLTIP_MAX_WIDTH / 2;\n const xPosAdjustThreshold = chartWidth - tooltipWidth * 0.9;\n\n // reposition so tooltip is never too close to right side of chart or left side of browser window\n return mousePos.plotCanvas.x > xPosAdjustThreshold && x > TOOLTIP_MAX_WIDTH\n ? `translate3d(${x - cursorPaddingX}px, ${y}px, 0) translateX(-100%)`\n : `translate3d(${x + cursorPaddingX}px, ${y}px, 0)`;\n}\n"],"names":["TOOLTIP_MAX_WIDTH","assembleTransform","mousePos","seriesNum","chartWidth","chartHeight","pinnedPos","cursorPaddingX","cursorPaddingY","x","page","y","isCloseToBottom","window","innerHeight","yPosAdjustThreshold","plotCanvas","tooltipWidth","xPosAdjustThreshold"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAwCA,iBAAiB,QAAQ,iBAAiB,CAAC;AAEnF;;CAEC,GACD,OAAO,SAASC,iBAAiB,CAC/BC,QAA8B,EAC9BC,SAAiB,EACjBC,UAAkB,EAClBC,WAAmB,EACnBC,SAAmC,EACnC;IACA,IAAIJ,QAAQ,KAAK,IAAI,EAAE;QACrB,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED,IAAII,SAAS,KAAK,IAAI,EAAE;QACtBJ,QAAQ,GAAGI,SAAS,CAAC;IACvB,CAAC;IAED,MAAMC,cAAc,GAAG,EAAE,AAAC;IAC1B,MAAMC,cAAc,GAAG,EAAE,AAAC;IAE1B,uDAAuD;IACvD,oEAAoE;I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TimeSeriesTooltip/utils.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { CursorCoordinates, CursorData, TOOLTIP_MAX_WIDTH } from './tooltip-model';\n\n/**\n * Determine position of tooltip depending on chart dimensions and the number of focused series\n */\nexport function assembleTransform(\n mousePos: CursorData['coords'],\n seriesNum: number,\n chartWidth: number,\n pinnedPos: CursorCoordinates | null,\n tooltipHeight: number,\n tooltipWidth: number\n) {\n if (mousePos === null) {\n return 'translate3d(0, 0)';\n }\n\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n }\n\n const cursorPaddingX = 32;\n const cursorPaddingY = 16;\n\n // Tooltip is located in a Portal attached to the body.\n // Using page coordinates instead of viewport ensures the tooltip is\n // absolutely positioned correctly as the user scrolls\n const x = mousePos.page.x;\n let y = mousePos.page.y + cursorPaddingY;\n\n // adjust so tooltip does not get cut off at bottom of chart\n if (mousePos.client.y + tooltipHeight + cursorPaddingY > window.innerHeight) {\n y = mousePos.page.y - tooltipHeight;\n }\n\n // use tooltip width to determine when to repos from right to left\n const xPosAdjustThreshold = chartWidth - tooltipWidth * 0.9;\n\n // reposition so tooltip is never too close to right side of chart or left side of browser window\n return mousePos.plotCanvas.x > xPosAdjustThreshold && x > TOOLTIP_MAX_WIDTH\n ? `translate3d(${x - cursorPaddingX}px, ${y}px, 0) translateX(-100%)`\n : `translate3d(${x + cursorPaddingX}px, ${y}px, 0)`;\n}\n"],"names":["TOOLTIP_MAX_WIDTH","assembleTransform","mousePos","seriesNum","chartWidth","pinnedPos","tooltipHeight","tooltipWidth","cursorPaddingX","cursorPa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EAAEU,CAAC,GAAGF,cAAc,CAAC,IAAI,EAAEI,CAAC,CAAC,wBAAwB,CAAC,GACnE,CAAC,YAAY,EAAEF,CAAC,GAAGF,cAAc,CAAC,IAAI,EAAEI,CAAC,CAAC,MAAM,CAAC,CAAC;AACxD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"UnitSelector.d.ts","sourceRoot":"","sources":["../../src/UnitSelector/UnitSelector.tsx"],"names":[],"mappings":";AAaA,OAAO,EACL,WAAW,EAMZ,MAAM,UAAU,CAAC;AAGlB,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;CACvC;AAeD,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,iBAAiB,eAiFlE"}
1
+ {"version":3,"file":"UnitSelector.d.ts","sourceRoot":"","sources":["../../src/UnitSelector/UnitSelector.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,WAAW,EAA0E,MAAM,UAAU,CAAC;AAI/G,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;CACvC;AA0BD,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,iBAAiB,eAkFlE"}
@@ -12,7 +12,8 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
14
  import { Box, Switch, TextField, Autocomplete } from '@mui/material';
15
- import { UNIT_CONFIG, DEFAULT_DECIMAL_PLACES, isUnitWithDecimalPlaces, isUnitWithAbbreviate } from '../model';
15
+ import { UNIT_CONFIG, isUnitWithDecimalPlaces, isUnitWithAbbreviate } from '../model';
16
+ import { shouldAbbreviate } from '../model/units/utils';
16
17
  import { OptionsEditorControl } from '../OptionsEditorLayout';
17
18
  const KIND_OPTIONS = Object.entries(UNIT_CONFIG).map(([id, config])=>{
18
19
  return {
@@ -20,13 +21,35 @@ const KIND_OPTIONS = Object.entries(UNIT_CONFIG).map(([id, config])=>{
20
21
  ...config
21
22
  };
22
23
  }).filter((config)=>!config.disableSelectorOption);
23
- const DECIMAL_OPTIONS = [
24
- 0,
25
- 1,
26
- 2,
27
- 3,
28
- 4
24
+ const DECIMAL_PLACES_OPTIONS = [
25
+ {
26
+ label: 'Default',
27
+ decimal_places: undefined
28
+ },
29
+ {
30
+ label: '0',
31
+ decimal_places: 0
32
+ },
33
+ {
34
+ label: '1',
35
+ decimal_places: 1
36
+ },
37
+ {
38
+ label: '2',
39
+ decimal_places: 2
40
+ },
41
+ {
42
+ label: '3',
43
+ decimal_places: 3
44
+ },
45
+ {
46
+ label: '4',
47
+ decimal_places: 4
48
+ }
29
49
  ];
50
+ function getOptionByDecimalPlaces(decimal_places) {
51
+ return DECIMAL_PLACES_OPTIONS.find((o)=>o.decimal_places === decimal_places);
52
+ }
30
53
  export function UnitSelector({ value , onChange }) {
31
54
  const hasDecimalPlaces = isUnitWithDecimalPlaces(value);
32
55
  const hasAbbreviate = isUnitWithAbbreviate(value);
@@ -35,11 +58,11 @@ export function UnitSelector({ value , onChange }) {
35
58
  kind: newValue.id
36
59
  });
37
60
  };
38
- const handleDecimalChange = (_, newValue)=>{
61
+ const handleDecimalPlacesChange = (_, { decimal_places })=>{
39
62
  if (hasDecimalPlaces) {
40
63
  onChange({
41
64
  ...value,
42
- decimal_places: newValue
65
+ decimal_places: decimal_places
43
66
  });
44
67
  }
45
68
  };
@@ -52,19 +75,18 @@ export function UnitSelector({ value , onChange }) {
52
75
  }
53
76
  };
54
77
  const kindConfig = UNIT_CONFIG[value.kind];
55
- var _decimal_places;
56
78
  return /*#__PURE__*/ _jsxs(_Fragment, {
57
79
  children: [
58
80
  /*#__PURE__*/ _jsx(OptionsEditorControl, {
59
81
  label: "Abbreviate",
60
82
  control: /*#__PURE__*/ _jsx(Switch, {
61
- checked: hasAbbreviate ? !!value.abbreviate : false,
83
+ checked: hasAbbreviate ? shouldAbbreviate(value.abbreviate) : false,
62
84
  onChange: handleAbbreviateChange,
63
85
  disabled: !hasAbbreviate
64
86
  })
65
87
  }),
66
88
  /*#__PURE__*/ _jsx(OptionsEditorControl, {
67
- label: "Units",
89
+ label: "Unit",
68
90
  control: /*#__PURE__*/ _jsx(Autocomplete, {
69
91
  value: {
70
92
  id: value.kind,
@@ -92,15 +114,16 @@ export function UnitSelector({ value , onChange }) {
92
114
  })
93
115
  }),
94
116
  /*#__PURE__*/ _jsx(OptionsEditorControl, {
95
- label: "Decimal",
117
+ label: "Decimals",
96
118
  control: /*#__PURE__*/ _jsx(Autocomplete, {
97
- value: hasDecimalPlaces ? (_decimal_places = value.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES : 0,
98
- options: DECIMAL_OPTIONS,
99
- getOptionLabel: (option)=>`${option}`,
119
+ value: getOptionByDecimalPlaces(value.decimal_places),
120
+ options: DECIMAL_PLACES_OPTIONS,
121
+ getOptionLabel: (o)=>o.label,
122
+ isOptionEqualToValue: (option, value)=>option.label === value.label,
100
123
  renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
101
124
  ...params
102
125
  }),
103
- onChange: handleDecimalChange,
126
+ onChange: handleDecimalPlacesChange,
104
127
  disabled: !hasDecimalPlaces,
105
128
  disableClearable: true
106
129
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/UnitSelector/UnitSelector.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport { Box, Switch, TextField, Autocomplete, SwitchProps } from '@mui/material';\nimport {\n UnitOptions,\n UNIT_CONFIG,\n DEFAULT_DECIMAL_PLACES,\n UnitConfig,\n isUnitWithDecimalPlaces,\n isUnitWithAbbreviate,\n} from '../model';\nimport { OptionsEditorControl } from '../OptionsEditorLayout';\n\nexport interface UnitSelectorProps {\n value: UnitOptions;\n onChange: (unit: UnitOptions) => void;\n}\n\ntype AutocompleteKindOption = UnitConfig & { id: UnitOptions['kind'] };\n\nconst KIND_OPTIONS: AutocompleteKindOption[] = Object.entries(UNIT_CONFIG)\n .map(([id, config]) => {\n return {\n id: id as UnitOptions['kind'],\n ...config,\n };\n })\n .filter((config) => !config.disableSelectorOption);\n\nconst DECIMAL_OPTIONS = [0, 1, 2, 3, 4];\n\nexport function UnitSelector({ value, onChange }: UnitSelectorProps) {\n const hasDecimalPlaces = isUnitWithDecimalPlaces(value);\n const hasAbbreviate = isUnitWithAbbreviate(value);\n\n const handleKindChange = (_: unknown, newValue: AutocompleteKindOption) => {\n onChange({\n kind: newValue.id,\n });\n };\n\n const handleDecimalChange = (_: unknown, newValue: number) => {\n if (hasDecimalPlaces) {\n onChange({\n ...value,\n decimal_places: newValue,\n });\n }\n };\n\n const handleAbbreviateChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n if (hasAbbreviate) {\n onChange({\n ...value,\n abbreviate: checked,\n });\n }\n };\n\n const kindConfig = UNIT_CONFIG[value.kind];\n\n return (\n <>\n <OptionsEditorControl\n label=\"Abbreviate\"\n control={\n <Switch\n checked={hasAbbreviate ? !!value.abbreviate : false}\n onChange={handleAbbreviateChange}\n disabled={!hasAbbreviate}\n />\n }\n />\n <OptionsEditorControl\n label=\"Units\"\n control={\n <Autocomplete\n value={{ id: value.kind, ...kindConfig }}\n options={KIND_OPTIONS}\n isOptionEqualToValue={(option, value) => option.id === value.id}\n groupBy={(option) => option.group}\n renderInput={(params) => <TextField {...params} />}\n renderOption={(renderOptsProps, option) => {\n // Custom option needed to get some increased left padding to make\n // the items more distinct from the group label.\n return (\n <li {...renderOptsProps}>\n <Box paddingLeft={(theme) => theme.spacing(1)}>{option.label}</Box>\n </li>\n );\n }}\n onChange={handleKindChange}\n disableClearable\n ></Autocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Decimal\"\n control={\n <Autocomplete\n value={hasDecimalPlaces ? value.decimal_places ?? DEFAULT_DECIMAL_PLACES : 0}\n options={DECIMAL_OPTIONS}\n getOptionLabel={(option) => `${option}`}\n renderInput={(params) => <TextField {...params} />}\n onChange={handleDecimalChange}\n disabled={!hasDecimalPlaces}\n disableClearable\n ></Autocomplete>\n }\n />\n </>\n );\n}\n"],"names":["Box","Switch","TextField","Autocomplete","UNIT_CONFIG","DEFAULT_DECIMAL_PLACES","isUnitWithDecimalPlaces","isUnitWithAbbreviate","OptionsEditorControl","KIND_OPTIONS","Object","entries","map","id","config","filter","disableSelectorOption","DECIMAL_OPTIONS","UnitSelector","value","onChange","hasDecimalPlaces","hasAbbreviate","handleKindChange","_","newValue","kind","handleDecimalChange","decimal_places","handleAbbreviateChange","checked","abbreviate","kindConfig","label","control","disabled","options","isOptionEqualToValue","option","groupBy","group","renderInput","params","renderOption","renderOptsProps","li","paddingLeft","theme","spacing","disableClearable","getOptionLabel"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC;AAAA,SAASA,GAAG,EAAEC,MAAM,EAAEC,SAAS,EAAEC,YAAY,QAAqB,eAAe,CAAC;AAClF,SAEEC,WAAW,EACXC,sBAAsB,EAEtBC,uBAAuB,EACvBC,oBAAoB,QACf,UAAU,CAAC;AAClB,SAASC,oBAAoB,QAAQ,wBAAwB,CAAC;AAS9D,MAAMC,YAAY,GAA6BC,MAAM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OAAO,EAAEnB,eAAe;oBACxBiC,cAAc,EAAE,CAACZ,MAAM,GAAK,CAAC,EAAEA,MAAM,CAAC,CAAC;oBACvCG,WAAW,EAAE,CAACC,MAAM,iBAAK,KAACxC,SAAS;4BAAE,GAAGwC,MAAM;0BAAI;oBAClDtB,QAAQ,EAAEO,mBAAmB;oBAC7BQ,QAAQ,EAAE,CAACd,gBAAgB;oBAC3B4B,gBAAgB;kBACF;cAElB;;MACD,CACH;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../src/UnitSelector/UnitSelector.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport { Box, Switch, TextField, Autocomplete, SwitchProps } from '@mui/material';\nimport { UnitOptions, UNIT_CONFIG, UnitConfig, isUnitWithDecimalPlaces, isUnitWithAbbreviate } from '../model';\nimport { shouldAbbreviate } from '../model/units/utils';\nimport { OptionsEditorControl } from '../OptionsEditorLayout';\n\nexport interface UnitSelectorProps {\n value: UnitOptions;\n onChange: (unit: UnitOptions) => void;\n}\n\ntype AutocompleteKindOption = UnitConfig & { id: UnitOptions['kind'] };\n\nconst KIND_OPTIONS: AutocompleteKindOption[] = Object.entries(UNIT_CONFIG)\n .map(([id, config]) => {\n return {\n id: id as UnitOptions['kind'],\n ...config,\n };\n })\n .filter((config) => !config.disableSelectorOption);\n\nconst DECIMAL_PLACES_OPTIONS = [\n { label: 'Default', decimal_places: undefined },\n { label: '0', decimal_places: 0 },\n { label: '1', decimal_places: 1 },\n { label: '2', decimal_places: 2 },\n { label: '3', decimal_places: 3 },\n { label: '4', decimal_places: 4 },\n];\n\nfunction getOptionByDecimalPlaces(decimal_places?: number) {\n return DECIMAL_PLACES_OPTIONS.find((o) => o.decimal_places === decimal_places);\n}\n\nexport function UnitSelector({ value, onChange }: UnitSelectorProps) {\n const hasDecimalPlaces = isUnitWithDecimalPlaces(value);\n const hasAbbreviate = isUnitWithAbbreviate(value);\n\n const handleKindChange = (_: unknown, newValue: AutocompleteKindOption) => {\n onChange({\n kind: newValue.id,\n });\n };\n\n const handleDecimalPlacesChange = (_: unknown, { decimal_places }: { decimal_places: number | undefined }) => {\n if (hasDecimalPlaces) {\n onChange({\n ...value,\n decimal_places: decimal_places,\n });\n }\n };\n\n const handleAbbreviateChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n if (hasAbbreviate) {\n onChange({\n ...value,\n abbreviate: checked,\n });\n }\n };\n\n const kindConfig = UNIT_CONFIG[value.kind];\n\n return (\n <>\n <OptionsEditorControl\n label=\"Abbreviate\"\n control={\n <Switch\n checked={hasAbbreviate ? shouldAbbreviate(value.abbreviate) : false}\n onChange={handleAbbreviateChange}\n disabled={!hasAbbreviate}\n />\n }\n />\n <OptionsEditorControl\n label=\"Unit\"\n control={\n <Autocomplete\n value={{ id: value.kind, ...kindConfig }}\n options={KIND_OPTIONS}\n isOptionEqualToValue={(option, value) => option.id === value.id}\n groupBy={(option) => option.group}\n renderInput={(params) => <TextField {...params} />}\n renderOption={(renderOptsProps, option) => {\n // Custom option needed to get some increased left padding to make\n // the items more distinct from the group label.\n return (\n <li {...renderOptsProps}>\n <Box paddingLeft={(theme) => theme.spacing(1)}>{option.label}</Box>\n </li>\n );\n }}\n onChange={handleKindChange}\n disableClearable\n ></Autocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Decimals\"\n control={\n <Autocomplete\n value={getOptionByDecimalPlaces(value.decimal_places)}\n options={DECIMAL_PLACES_OPTIONS}\n getOptionLabel={(o) => o.label}\n isOptionEqualToValue={(option, value) => option.label === value.label}\n renderInput={(params) => <TextField {...params} />}\n onChange={handleDecimalPlacesChange}\n disabled={!hasDecimalPlaces}\n disableClearable\n />\n }\n />\n </>\n );\n}\n"],"names":["Box","Switch","TextField","Autocomplete","UNIT_CONFIG","isUnitWithDecimalPlaces","isUnitWithAbbreviate","shouldAbbreviate","OptionsEditorControl","KIND_OPTIONS","Object","entries","map","id","config","filter","disableSelectorOption","DECIMAL_PLACES_OPTIONS","label","decimal_places","undefined","getOptionByDecimalPlaces","find","o","UnitSelector","value","onChange","hasDecimalPlaces","hasAbbreviate","handleKindChange","_","newValue","kind","handleDecimalPlacesChange","handleAbbreviateChange","checked","abbreviate","kindConfig","control","disabled","options","isOptionEqualToValue","option","groupBy","group","renderInput","params","renderOption","renderOptsProps","li","paddingLeft","theme","spacing","disableClearable","getOptionLabel"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC;AAAA,SAASA,GAAG,EAAEC,MAAM,EAAEC,SAAS,EAAEC,YAAY,QAAqB,eAAe,CAAC;AAClF,SAAsBC,WAAW,EAAcC,uBAAuB,EAAEC,oBAAoB,QAAQ,UAAU,CAAC;AAC/G,SAASC,gBAAgB,QAAQ,sBAAsB,CAAC;AACxD,SAASC,oBAAoB,QAAQ,wBAAwB,CAAC;AAS9D,MAAMC,YAAY,GAA6BC,MAAM,CAACC,OAAO,CAACP,WAAW,CAAC,CACvEQ,GAAG,CAAC,CAAC,CAACC,EAAE,EAAEC,MAAM,CAAC,GAAK;IACrB,OAAO;QACLD,EAAE,EAAEA,EAAE;QACN,GAAGC,MAAM;KACV,CAAC;AACJ,CAAC,CAAC,CACDC,MAAM,CAAC,CAACD,MAAM,GAAK,CAACA,MAAM,CAACE,qBAAqB,CAAC,AAAC;AAErD,MAAMC,sBAAsB,GAAG;IAC7B;QAAEC,KAAK,EAAE,SAAS;QA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EAAC,UAAU;gBAChBoB,OAAO,gBACL,KAACnC,YAAY;oBACXsB,KAAK,EAAEJ,wBAAwB,CAACI,KAAK,CAACN,cAAc,CAAC;oBACrDqB,OAAO,EAAEvB,sBAAsB;oBAC/BqC,cAAc,EAAE,CAAC/B,CAAC,GAAKA,CAAC,CAACL,KAAK;oBAC9BuB,oBAAoB,EAAE,CAACC,MAAM,EAAEjB,KAAK,GAAKiB,MAAM,CAACxB,KAAK,KAAKO,KAAK,CAACP,KAAK;oBACrE2B,WAAW,EAAE,CAACC,MAAM,iBAAK,KAAC5C,SAAS;4BAAE,GAAG4C,MAAM;0BAAI;oBAClDpB,QAAQ,EAAEO,yBAAyB;oBACnCM,QAAQ,EAAE,CAACZ,gBAAgB;oBAC3B0B,gBAAgB;kBAChB;cAEJ;;MACD,CACH;AACJ,CAAC"}
@@ -42,8 +42,14 @@ function TimeRangeSelector(props) {
42
42
  'aria-label': `Select time range. Currently set to ${formattedValue}`
43
43
  },
44
44
  sx: {
45
+ // `transform: none` prevents calendar icon from flipping over when menu is open
45
46
  '.MuiSelect-icon': {
46
- marginTop: '1px'
47
+ marginTop: '1px',
48
+ transform: 'none'
49
+ },
50
+ // paddingRight creates more space for the calendar icon (it's a bigger icon)
51
+ '.MuiSelect-select.MuiSelect-outlined.MuiInputBase-input': {
52
+ paddingRight: '36px'
47
53
  },
48
54
  '.MuiSelect-select': height ? {
49
55
  lineHeight: height,
@@ -23,7 +23,6 @@ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
23
23
  const _core = require("echarts/core");
24
24
  const _material = require("@mui/material");
25
25
  const _lodashEs = require("lodash-es");
26
- const _utils = require("../utils");
27
26
  function _getRequireWildcardCache(nodeInterop) {
28
27
  if (typeof WeakMap !== "function") return null;
29
28
  var cacheBabelInterop = new WeakMap();
@@ -154,12 +153,7 @@ const EChart = /*#__PURE__*/ _react.default.memo(function EChart({ option , them
154
153
  ]);
155
154
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
156
155
  ref: containerRef,
157
- sx: (0, _utils.combineSx)({
158
- // Ensures chart fills container and updates size correctly when resizing,
159
- // combineSx allows this default behavior to be overriden from parent component
160
- width: '100%',
161
- height: '100%'
162
- }, sx)
156
+ sx: sx
163
157
  });
164
158
  });
165
159
  // Validate event config and bind custom events
@@ -230,6 +230,10 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
230
230
  unit: unit
231
231
  }),
232
232
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
233
+ sx: {
234
+ width: '100%',
235
+ height: '100%'
236
+ },
233
237
  option: option,
234
238
  theme: chartsTheme.echartsTheme,
235
239
  onEvents: handleEvents,
@@ -117,11 +117,15 @@ function StatChart(props) {
117
117
  sx: (theme)=>({
118
118
  color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
119
119
  fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
120
- padding: `${containerPadding} ${containerPadding} 0 ${containerPadding}`
120
+ padding: sparkline ? `${containerPadding} ${containerPadding} 0 ${containerPadding}` : ` 0 ${containerPadding}`
121
121
  }),
122
122
  children: formattedValue
123
123
  }),
124
124
  sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
125
+ sx: {
126
+ width: '100%',
127
+ height: '100%'
128
+ },
125
129
  option: option,
126
130
  theme: chartsTheme.echartsTheme,
127
131
  renderer: "svg"
@@ -19,12 +19,18 @@ Object.defineProperty(exports, "TimeSeriesTooltip", {
19
19
  get: ()=>TimeSeriesTooltip
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
- const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
23
22
  const _material = require("@mui/material");
23
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
24
+ const _useResizeObserver = /*#__PURE__*/ _interopRequireDefault(require("use-resize-observer"));
25
+ const _tooltipContent = require("./TooltipContent");
24
26
  const _focusedSeries = require("./focused-series");
25
27
  const _tooltipModel = require("./tooltip-model");
26
- const _tooltipContent = require("./TooltipContent");
27
28
  const _utils = require("./utils");
29
+ function _interopRequireDefault(obj) {
30
+ return obj && obj.__esModule ? obj : {
31
+ default: obj
32
+ };
33
+ }
28
34
  function _getRequireWildcardCache(nodeInterop) {
29
35
  if (typeof WeakMap !== "function") return null;
30
36
  var cacheBabelInterop = new WeakMap();
@@ -67,6 +73,7 @@ function _interopRequireWildcard(obj, nodeInterop) {
67
73
  const TimeSeriesTooltip = /*#__PURE__*/ _react.default.memo(function TimeSeriesTooltip({ chartRef , chartData , wrapLabels , pinTooltip , unit }) {
68
74
  const [pinnedPos, setPinnedPos] = (0, _react.useState)(null);
69
75
  const mousePos = (0, _tooltipModel.useMousePosition)();
76
+ const { height , width , ref: tooltipRef } = (0, _useResizeObserver.default)();
70
77
  if (mousePos === null || mousePos.target === null) return null;
71
78
  // ensure user is hovering over a chart before checking for nearby series
72
79
  if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS') return null;
@@ -74,9 +81,7 @@ const TimeSeriesTooltip = /*#__PURE__*/ _react.default.memo(function TimeSeriesT
74
81
  const focusedSeries = (0, _focusedSeries.getFocusedSeriesData)(mousePos, chartData, pinnedPos, chart, unit);
75
82
  var ref;
76
83
  const chartWidth = (ref = chart === null || chart === void 0 ? void 0 : chart.getWidth()) !== null && ref !== void 0 ? ref : 750;
77
- var ref1;
78
- const chartHeight = (ref1 = chart === null || chart === void 0 ? void 0 : chart.getHeight()) !== null && ref1 !== void 0 ? ref1 : 230;
79
- const cursorTransform = (0, _utils.assembleTransform)(mousePos, focusedSeries.length, chartWidth, chartHeight, pinnedPos);
84
+ const cursorTransform = (0, _utils.assembleTransform)(mousePos, focusedSeries.length, chartWidth, pinnedPos, height !== null && height !== void 0 ? height : 0, width !== null && width !== void 0 ? width : 0);
80
85
  if (focusedSeries.length === 0) {
81
86
  return null;
82
87
  }
@@ -85,6 +90,7 @@ const TimeSeriesTooltip = /*#__PURE__*/ _react.default.memo(function TimeSeriesT
85
90
  }
86
91
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Portal, {
87
92
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
93
+ ref: tooltipRef,
88
94
  sx: (theme)=>({
89
95
  maxWidth: _tooltipModel.TOOLTIP_MAX_WIDTH,
90
96
  maxHeight: _tooltipModel.TOOLTIP_MAX_HEIGHT,
@@ -27,8 +27,8 @@ function TooltipContent(props) {
27
27
  const { focusedSeries , wrapLabels } = props;
28
28
  const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
29
29
  const seriesTime = focusedSeries && focusedSeries[0] && focusedSeries[0].date ? focusedSeries[0].date : null;
30
- const formatTimeSeriesHeader = (timeString)=>{
31
- const date = new Date(timeString);
30
+ const formatTimeSeriesHeader = (timeMs)=>{
31
+ const date = new Date(timeMs);
32
32
  const formattedDate = formatWithUserTimeZone(date, 'MMM dd, yyyy - ');
33
33
  const formattedTime = formatWithUserTimeZone(date, 'HH:mm:ss');
34
34
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
@@ -53,13 +53,12 @@ function getNearbySeries(data, pointInGrid, yBuffer, unit) {
53
53
  if (yValue !== '-' && focusedY <= yValue + yBuffer && focusedY >= yValue - yBuffer) {
54
54
  // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
55
55
  const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
56
- const formattedDate = _tooltipModel.TOOLTIP_DATE_FORMAT.format(xValueMilliSeconds);
57
56
  const formattedY = (0, _model.formatValue)(yValue, unit);
58
57
  currentFocusedData.push({
59
58
  seriesIdx: seriesIdx,
60
59
  datumIdx: datumIdx,
61
60
  seriesName: currentSeriesName,
62
- date: formattedDate,
61
+ date: xValueMilliSeconds,
63
62
  x: xValue,
64
63
  y: yValue,
65
64
  formattedY: formattedY,
@@ -71,6 +71,10 @@ const useMousePosition = ()=>{
71
71
  x: e.pageX,
72
72
  y: e.pageY
73
73
  },
74
+ client: {
75
+ x: e.clientX,
76
+ y: e.clientY
77
+ },
74
78
  plotCanvas: {
75
79
  x: e.offsetX,
76
80
  y: e.offsetY
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "assembleTransform", {
19
19
  get: ()=>assembleTransform
20
20
  });
21
21
  const _tooltipModel = require("./tooltip-model");
22
- function assembleTransform(mousePos, seriesNum, chartWidth, chartHeight, pinnedPos) {
22
+ function assembleTransform(mousePos, seriesNum, chartWidth, pinnedPos, tooltipHeight, tooltipWidth) {
23
23
  if (mousePos === null) {
24
24
  return 'translate3d(0, 0)';
25
25
  }
@@ -33,20 +33,11 @@ function assembleTransform(mousePos, seriesNum, chartWidth, chartHeight, pinnedP
33
33
  // absolutely positioned correctly as the user scrolls
34
34
  const x = mousePos.page.x;
35
35
  let y = mousePos.page.y + cursorPaddingY;
36
- const isCloseToBottom = mousePos.page.y > window.innerHeight * 0.8;
37
- const yPosAdjustThreshold = chartHeight * 0.75;
38
- // adjust so tooltip does not get cut off at bottom of chart, reduce multiplier to move up
39
- if (isCloseToBottom === true) {
40
- if (seriesNum > 6) {
41
- y = mousePos.page.y * 0.75;
42
- } else {
43
- y = mousePos.page.y * 0.9;
44
- }
45
- } else if (mousePos.plotCanvas.y > yPosAdjustThreshold) {
46
- y = mousePos.page.y * 0.95;
36
+ // adjust so tooltip does not get cut off at bottom of chart
37
+ if (mousePos.client.y + tooltipHeight + cursorPaddingY > window.innerHeight) {
38
+ y = mousePos.page.y - tooltipHeight;
47
39
  }
48
- // use tooltip width to determine when to repos from right to left (width is narrower when only 1 focused series since labels wrap)
49
- const tooltipWidth = seriesNum > 1 ? _tooltipModel.TOOLTIP_MAX_WIDTH : _tooltipModel.TOOLTIP_MAX_WIDTH / 2;
40
+ // use tooltip width to determine when to repos from right to left
50
41
  const xPosAdjustThreshold = chartWidth - tooltipWidth * 0.9;
51
42
  // reposition so tooltip is never too close to right side of chart or left side of browser window
52
43
  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)`;
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "UnitSelector", {
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
23
  const _model = require("../model");
24
+ const _utils = require("../model/units/utils");
24
25
  const _optionsEditorLayout = require("../OptionsEditorLayout");
25
26
  const KIND_OPTIONS = Object.entries(_model.UNIT_CONFIG).map(([id, config])=>{
26
27
  return {
@@ -28,13 +29,35 @@ const KIND_OPTIONS = Object.entries(_model.UNIT_CONFIG).map(([id, config])=>{
28
29
  ...config
29
30
  };
30
31
  }).filter((config)=>!config.disableSelectorOption);
31
- const DECIMAL_OPTIONS = [
32
- 0,
33
- 1,
34
- 2,
35
- 3,
36
- 4
32
+ const DECIMAL_PLACES_OPTIONS = [
33
+ {
34
+ label: 'Default',
35
+ decimal_places: undefined
36
+ },
37
+ {
38
+ label: '0',
39
+ decimal_places: 0
40
+ },
41
+ {
42
+ label: '1',
43
+ decimal_places: 1
44
+ },
45
+ {
46
+ label: '2',
47
+ decimal_places: 2
48
+ },
49
+ {
50
+ label: '3',
51
+ decimal_places: 3
52
+ },
53
+ {
54
+ label: '4',
55
+ decimal_places: 4
56
+ }
37
57
  ];
58
+ function getOptionByDecimalPlaces(decimal_places) {
59
+ return DECIMAL_PLACES_OPTIONS.find((o)=>o.decimal_places === decimal_places);
60
+ }
38
61
  function UnitSelector({ value , onChange }) {
39
62
  const hasDecimalPlaces = (0, _model.isUnitWithDecimalPlaces)(value);
40
63
  const hasAbbreviate = (0, _model.isUnitWithAbbreviate)(value);
@@ -43,11 +66,11 @@ function UnitSelector({ value , onChange }) {
43
66
  kind: newValue.id
44
67
  });
45
68
  };
46
- const handleDecimalChange = (_, newValue)=>{
69
+ const handleDecimalPlacesChange = (_, { decimal_places })=>{
47
70
  if (hasDecimalPlaces) {
48
71
  onChange({
49
72
  ...value,
50
- decimal_places: newValue
73
+ decimal_places: decimal_places
51
74
  });
52
75
  }
53
76
  };
@@ -60,19 +83,18 @@ function UnitSelector({ value , onChange }) {
60
83
  }
61
84
  };
62
85
  const kindConfig = _model.UNIT_CONFIG[value.kind];
63
- var _decimal_places;
64
86
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
65
87
  children: [
66
88
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
67
89
  label: "Abbreviate",
68
90
  control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
69
- checked: hasAbbreviate ? !!value.abbreviate : false,
91
+ checked: hasAbbreviate ? (0, _utils.shouldAbbreviate)(value.abbreviate) : false,
70
92
  onChange: handleAbbreviateChange,
71
93
  disabled: !hasAbbreviate
72
94
  })
73
95
  }),
74
96
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
75
- label: "Units",
97
+ label: "Unit",
76
98
  control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
77
99
  value: {
78
100
  id: value.kind,
@@ -100,15 +122,16 @@ function UnitSelector({ value , onChange }) {
100
122
  })
101
123
  }),
102
124
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
103
- label: "Decimal",
125
+ label: "Decimals",
104
126
  control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
105
- value: hasDecimalPlaces ? (_decimal_places = value.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _model.DEFAULT_DECIMAL_PLACES : 0,
106
- options: DECIMAL_OPTIONS,
107
- getOptionLabel: (option)=>`${option}`,
127
+ value: getOptionByDecimalPlaces(value.decimal_places),
128
+ options: DECIMAL_PLACES_OPTIONS,
129
+ getOptionLabel: (o)=>o.label,
130
+ isOptionEqualToValue: (option, value)=>option.label === value.label,
108
131
  renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
109
132
  ...params
110
133
  }),
111
- onChange: handleDecimalChange,
134
+ onChange: handleDecimalPlacesChange,
112
135
  disabled: !hasDecimalPlaces,
113
136
  disableClearable: true
114
137
  })