@perses-dev/components 0.8.1 → 0.9.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 (131) hide show
  1. package/dist/Drawer/Drawer.d.ts +3 -4
  2. package/dist/Drawer/Drawer.d.ts.map +1 -1
  3. package/dist/Drawer/Drawer.js +35 -1
  4. package/dist/Drawer/Drawer.js.map +1 -0
  5. package/dist/Drawer/index.js +15 -1
  6. package/dist/Drawer/index.js.map +1 -0
  7. package/dist/EChart.d.ts.map +1 -1
  8. package/dist/EChart.js +142 -1
  9. package/dist/EChart.js.map +1 -0
  10. package/dist/ErrorAlert.js +25 -1
  11. package/dist/ErrorAlert.js.map +1 -0
  12. package/dist/ErrorBoundary.js +16 -1
  13. package/dist/ErrorBoundary.js.map +1 -0
  14. package/dist/GaugeChart/GaugeChart.js +172 -1
  15. package/dist/GaugeChart/GaugeChart.js.map +1 -0
  16. package/dist/GaugeChart/index.js +15 -1
  17. package/dist/GaugeChart/index.js.map +1 -0
  18. package/dist/InfoTooltip/InfoTooltip.js +79 -1
  19. package/dist/InfoTooltip/InfoTooltip.js.map +1 -0
  20. package/dist/InfoTooltip/InfoTooltip.test.js +36 -1
  21. package/dist/InfoTooltip/InfoTooltip.test.js.map +1 -0
  22. package/dist/InfoTooltip/index.js +15 -1
  23. package/dist/InfoTooltip/index.js.map +1 -0
  24. package/dist/LineChart/LineChart.js +198 -1
  25. package/dist/LineChart/LineChart.js.map +1 -0
  26. package/dist/LineChart/index.js +15 -1
  27. package/dist/LineChart/index.js.map +1 -0
  28. package/dist/LineChart/utils.js +63 -1
  29. package/dist/LineChart/utils.js.map +1 -0
  30. package/dist/StatChart/StatChart.js +121 -1
  31. package/dist/StatChart/StatChart.js.map +1 -0
  32. package/dist/StatChart/StatChart.test.js +82 -1
  33. package/dist/StatChart/StatChart.test.js.map +1 -0
  34. package/dist/StatChart/index.js +15 -1
  35. package/dist/StatChart/index.js.map +1 -0
  36. package/dist/TimeRangeSelector/AbsoluteTimePicker.js +175 -1
  37. package/dist/TimeRangeSelector/AbsoluteTimePicker.js.map +1 -0
  38. package/dist/TimeRangeSelector/TimeRangeSelector.js +52 -1
  39. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -0
  40. package/dist/TimeRangeSelector/index.js +16 -1
  41. package/dist/TimeRangeSelector/index.js.map +1 -0
  42. package/dist/TimeRangeSelector/utils.js +36 -1
  43. package/dist/TimeRangeSelector/utils.js.map +1 -0
  44. package/dist/Tooltip/SeriesInfo.js +143 -1
  45. package/dist/Tooltip/SeriesInfo.js.map +1 -0
  46. package/dist/Tooltip/SeriesMarker.js +33 -1
  47. package/dist/Tooltip/SeriesMarker.js.map +1 -0
  48. package/dist/Tooltip/Tooltip.js +72 -1
  49. package/dist/Tooltip/Tooltip.js.map +1 -0
  50. package/dist/Tooltip/TooltipContent.js +89 -1
  51. package/dist/Tooltip/TooltipContent.js.map +1 -0
  52. package/dist/Tooltip/focused-series.js +108 -1
  53. package/dist/Tooltip/focused-series.js.map +1 -0
  54. package/dist/Tooltip/focused-series.test.js +75 -1
  55. package/dist/Tooltip/focused-series.test.js.map +1 -0
  56. package/dist/Tooltip/index.js +16 -1
  57. package/dist/Tooltip/index.js.map +1 -0
  58. package/dist/Tooltip/tooltip-model.js +80 -1
  59. package/dist/Tooltip/tooltip-model.js.map +1 -0
  60. package/dist/Tooltip/utils.js +46 -1
  61. package/dist/Tooltip/utils.js.map +1 -0
  62. package/dist/cjs/Drawer/Drawer.js +26 -13
  63. package/dist/cjs/Drawer/index.js +16 -17
  64. package/dist/cjs/EChart.js +114 -89
  65. package/dist/cjs/ErrorAlert.js +16 -12
  66. package/dist/cjs/ErrorBoundary.js +10 -6
  67. package/dist/cjs/GaugeChart/GaugeChart.js +90 -57
  68. package/dist/cjs/GaugeChart/index.js +16 -17
  69. package/dist/cjs/InfoTooltip/InfoTooltip.js +90 -33
  70. package/dist/cjs/InfoTooltip/InfoTooltip.test.js +27 -17
  71. package/dist/cjs/InfoTooltip/index.js +16 -17
  72. package/dist/cjs/LineChart/LineChart.js +122 -87
  73. package/dist/cjs/LineChart/index.js +16 -17
  74. package/dist/cjs/LineChart/utils.js +23 -23
  75. package/dist/cjs/StatChart/StatChart.js +107 -46
  76. package/dist/cjs/StatChart/StatChart.test.js +65 -21
  77. package/dist/cjs/StatChart/index.js +16 -17
  78. package/dist/cjs/TimeRangeSelector/AbsoluteTimePicker.js +144 -64
  79. package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +45 -22
  80. package/dist/cjs/TimeRangeSelector/index.js +17 -18
  81. package/dist/cjs/TimeRangeSelector/utils.js +19 -16
  82. package/dist/cjs/Tooltip/SeriesInfo.js +120 -48
  83. package/dist/cjs/Tooltip/SeriesMarker.js +20 -11
  84. package/dist/cjs/Tooltip/Tooltip.js +95 -67
  85. package/dist/cjs/Tooltip/TooltipContent.js +76 -31
  86. package/dist/cjs/Tooltip/focused-series.js +40 -36
  87. package/dist/cjs/Tooltip/focused-series.test.js +36 -16
  88. package/dist/cjs/Tooltip/index.js +17 -18
  89. package/dist/cjs/Tooltip/tooltip-model.js +46 -30
  90. package/dist/cjs/Tooltip/utils.js +13 -16
  91. package/dist/cjs/context/ChartsThemeProvider.js +65 -13
  92. package/dist/cjs/index.js +27 -28
  93. package/dist/cjs/model/graph.js +10 -5
  94. package/dist/cjs/model/index.js +18 -19
  95. package/dist/cjs/model/theme.js +4 -2
  96. package/dist/cjs/model/units.js +68 -51
  97. package/dist/cjs/test/index.js +16 -17
  98. package/dist/cjs/test/render.js +22 -12
  99. package/dist/cjs/test/setup-tests.js +4 -2
  100. package/dist/cjs/utils/combine-sx.js +15 -16
  101. package/dist/cjs/utils/index.js +17 -18
  102. package/dist/cjs/utils/theme-gen.js +64 -55
  103. package/dist/cjs/utils/theme-gen.test.js +14 -12
  104. package/dist/context/ChartsThemeProvider.js +36 -1
  105. package/dist/context/ChartsThemeProvider.js.map +1 -0
  106. package/dist/index.js +26 -1
  107. package/dist/index.js.map +1 -0
  108. package/dist/model/graph.js +15 -1
  109. package/dist/model/graph.js.map +1 -0
  110. package/dist/model/index.js +17 -1
  111. package/dist/model/index.js.map +1 -0
  112. package/dist/model/theme.js +15 -1
  113. package/dist/model/theme.js.map +1 -0
  114. package/dist/model/units.d.ts.map +1 -1
  115. package/dist/model/units.js +196 -1
  116. package/dist/model/units.js.map +1 -0
  117. package/dist/test/index.js +15 -1
  118. package/dist/test/index.js.map +1 -0
  119. package/dist/test/render.js +32 -1
  120. package/dist/test/render.js.map +1 -0
  121. package/dist/test/setup-tests.js +18 -1
  122. package/dist/test/setup-tests.js.map +1 -0
  123. package/dist/utils/combine-sx.js +27 -1
  124. package/dist/utils/combine-sx.js.map +1 -0
  125. package/dist/utils/index.js +16 -1
  126. package/dist/utils/index.js.map +1 -0
  127. package/dist/utils/theme-gen.js +183 -1
  128. package/dist/utils/theme-gen.js.map +1 -0
  129. package/dist/utils/theme-gen.test.js +196 -1
  130. package/dist/utils/theme-gen.test.js.map +1 -0
  131. package/package.json +8 -4
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/InfoTooltip/InfoTooltip.tsx"],"sourcesContent":["// Copyright 2022 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 React from 'react';\nimport {\n styled,\n TooltipProps as MuiTooltipProps,\n Tooltip as MuiTooltip,\n tooltipClasses,\n Typography,\n} from '@mui/material';\n\nexport enum TooltipPlacement {\n Top = 'top',\n Left = 'left',\n Right = 'right',\n Bottom = 'bottom',\n}\n\ninterface InfoTooltipProps {\n description: string;\n children: React.ReactNode;\n id?: string;\n title?: string;\n placement?: TooltipPlacement;\n}\n\nexport const InfoTooltip = ({ id, title, description, placement, children }: InfoTooltipProps) => {\n return (\n <StyledTooltip\n arrow\n id={id}\n placement={placement}\n title={<TooltipContent title={title} description={description} />}\n >\n <div>{children}</div>\n </StyledTooltip>\n );\n};\n\nconst TooltipContent = ({ title, description }: Pick<InfoTooltipProps, 'title' | 'description'>) => {\n return (\n <>\n {title && (\n <Typography\n variant=\"body2\"\n sx={(theme) => ({\n color: theme.palette.text.primary,\n fontWeight: theme.typography.fontWeightMedium,\n })}\n >\n {title}\n </Typography>\n )}\n <Typography\n variant=\"caption\"\n sx={(theme) => ({\n color: theme.palette.text.primary,\n })}\n >\n {description}\n </Typography>\n </>\n );\n};\n\nconst StyledTooltip = styled(({ className, ...props }: MuiTooltipProps) => (\n <MuiTooltip {...props} classes={{ popper: className }} />\n))(({ theme }) => ({\n [`& .${tooltipClasses.tooltip}`]: {\n backgroundColor: theme.palette.secondary.main,\n color: theme.palette.grey[900],\n maxWidth: '300px',\n padding: theme.spacing(1),\n boxShadow: theme.shadows[1],\n },\n [`& .${tooltipClasses.arrow}`]: {\n color: theme.palette.background.paper,\n '&::before': {\n backgroundColor: theme.palette.secondary.main,\n },\n },\n}));\n"],"names":["React","styled","Tooltip","MuiTooltip","tooltipClasses","Typography","TooltipPlacement","Top","Left","Right","Bottom","InfoTooltip","id","title","description","placement","children","StyledTooltip","arrow","TooltipContent","div","variant","sx","theme","color","palette","text","primary","fontWeight","typography","fontWeightMedium","className","props","classes","popper","tooltip","backgroundColor","secondary","main","grey","maxWidth","padding","spacing","boxShadow","shadows","background","paper"],"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;AAAA,OAAOA,KAAK,MAAM,OAAO,CAAC;AAC1B,SACEC,MA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AC;0BAEDb,WAAW;cACD;;MACZ,CACH;AACJ,CAAC,AAAC;AAEF,MAAMG,aAAa,GAAGhB,MAAM,CAAC,CAAC,EAAE8B,SAAS,CAAA,EAAE,GAAGC,KAAK,EAAmB,iBACpE,KAAC7B,UAAU;QAAE,GAAG6B,KAAK;QAAEC,OAAO,EAAE;YAAEC,MAAM,EAAEH,SAAS;SAAE;MAAI,AAC1D,CAAC,CAAC,CAAC,EAAER,KAAK,CAAA,EAAE,GAAM,CAAA;QACjB,CAAC,CAAC,GAAG,EAAEnB,cAAc,CAAC+B,OAAO,CAAC,CAAC,CAAC,EAAE;YAChCC,eAAe,EAAEb,KAAK,CAACE,OAAO,CAACY,SAAS,CAACC,IAAI;YAC7Cd,KAAK,EAAED,KAAK,CAACE,OAAO,CAACc,IAAI,CAAC,GAAG,CAAC;YAC9BC,QAAQ,EAAE,OAAO;YACjBC,OAAO,EAAElB,KAAK,CAACmB,OAAO,CAAC,CAAC,CAAC;YACzBC,SAAS,EAAEpB,KAAK,CAACqB,OAAO,CAAC,CAAC,CAAC;SAC5B;QACD,CAAC,CAAC,GAAG,EAAExC,cAAc,CAACc,KAAK,CAAC,CAAC,CAAC,EAAE;YAC9BM,KAAK,EAAED,KAAK,CAACE,OAAO,CAACoB,UAAU,CAACC,KAAK;YACrC,WAAW,EAAE;gBACXV,eAAe,EAAEb,KAAK,CAACE,OAAO,CAACY,SAAS,CAACC,IAAI;aAC9C;SACF;KACF,CAAA,AAAC,CAAC,AAAC"}
@@ -1 +1,36 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{render}from"@testing-library/react";import userEvent from"@testing-library/user-event";import{screen}from"@testing-library/dom";import{InfoTooltip}from"./InfoTooltip";describe("InfoTooltip",(()=>{const t="Tooltip Title",e="this is a tooltip";it("should render title and description",(async()=>{render(_jsx(InfoTooltip,{title:t,description:e,children:_jsx("div",{children:"tooltipAnchor"})}));const r=screen.getByText("tooltipAnchor");userEvent.hover(r),await screen.findByText(t),screen.findByText(e)}))}));
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { render } from '@testing-library/react';
15
+ import userEvent from '@testing-library/user-event';
16
+ import { screen } from '@testing-library/dom';
17
+ import { InfoTooltip } from './InfoTooltip';
18
+ describe('InfoTooltip', ()=>{
19
+ const title = 'Tooltip Title';
20
+ const description = 'this is a tooltip';
21
+ it('should render title and description', async ()=>{
22
+ render(/*#__PURE__*/ _jsx(InfoTooltip, {
23
+ title: title,
24
+ description: description,
25
+ children: /*#__PURE__*/ _jsx("div", {
26
+ children: "tooltipAnchor"
27
+ })
28
+ }));
29
+ const tooltipAnchor = screen.getByText('tooltipAnchor');
30
+ userEvent.hover(tooltipAnchor);
31
+ await screen.findByText(title);
32
+ screen.findByText(description);
33
+ });
34
+ });
35
+
36
+ //# sourceMappingURL=InfoTooltip.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/InfoTooltip/InfoTooltip.test.tsx"],"sourcesContent":["// Copyright 2022 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 { render } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { screen } from '@testing-library/dom';\nimport { InfoTooltip } from './InfoTooltip';\n\ndescribe('InfoTooltip', () => {\n const title = 'Tooltip Title';\n const description = 'this is a tooltip';\n it('should render title and description', async () => {\n render(\n <InfoTooltip title={title} description={description}>\n <div>tooltipAnchor</div>\n </InfoTooltip>\n );\n const tooltipAnchor = screen.getByText('tooltipAnchor');\n userEvent.hover(tooltipAnchor);\n await screen.findByText(title);\n screen.findByText(description);\n });\n});\n"],"names":["render","userEvent","screen","InfoTooltip","describe","title","description","it","div","tooltipAnchor","getByText","hover","findByText"],"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;AAAA,SAASA,MAAM,QAAQ,wBAAwB,CAAC;AAChD,OAAOC,SAAS,MAAM,6BAA6B,CAAC;AACpD,SAASC,MAAM,QAAQ,sBAAsB,CAAC;AAC9C,SAASC,WAAW,QAAQ,eAAe,CAAC;AAE5CC,QAAQ,CAAC,aAAa,EAAE,IAAM;IAC5B,MAAMC,KAAK,GAAG,eAAe,AAAC;IAC9B,MAAMC,WAAW,GAAG,mBAAmB,AAAC;IACxCC,EAAE,CAAC,qCAAqC,EAAE,UAAY;QACpDP,MAAM,eACJ,KAACG,WAAW;YAACE,KAAK,EAAEA,KAAK;YAAEC,WAAW,EAAEA,WAAW;sBACjD,cAAA,KAACE,KAAG;0BAAC,eAAa;cAAM;UACZ,CACf,CAAC;QACF,MAAMC,aAAa,GAAGP,MAAM,CAACQ,SAAS,CAAC,eAAe,CAAC,AAAC;QACxDT,SAAS,CAACU,KAAK,CAACF,aAAa,CAAC,CAAC;QAC/B,MAAMP,MAAM,CAACU,UAAU,CAACP,KAAK,CAAC,CAAC;QAC/BH,MAAM,CAACU,UAAU,CAACN,WAAW,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1 +1,15 @@
1
- export*from"./InfoTooltip";
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './InfoTooltip';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/InfoTooltip/index.ts"],"sourcesContent":["// Copyright 2022 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\nexport * from './InfoTooltip';\n"],"names":[],"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,cAAc,eAAe,CAAC"}
@@ -1 +1,198 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useMemo,useRef,useState}from"react";import{useDeepMemo}from"@perses-dev/core";import{Box}from"@mui/material";import{use}from"echarts/core";import{LineChart as EChartsLineChart}from"echarts/charts";import{GridComponent,DataZoomComponent,MarkAreaComponent,MarkLineComponent,MarkPointComponent,TitleComponent,ToolboxComponent,TooltipComponent,LegendComponent,VisualMapComponent}from"echarts/components";import{CanvasRenderer}from"echarts/renderers";import{EChart}from"../EChart";import{PROGRESSIVE_MODE_SERIES_LIMIT}from"../model/graph";import{formatValue}from"../model/units";import{useChartsTheme}from"../context/ChartsThemeProvider";import{Tooltip}from"../Tooltip/Tooltip";import{enableDataZoom,restoreChart,getDateRange,getFormattedDate}from"./utils";use([EChartsLineChart,GridComponent,DataZoomComponent,MarkAreaComponent,MarkLineComponent,MarkPointComponent,TitleComponent,ToolboxComponent,TooltipComponent,LegendComponent,VisualMapComponent,CanvasRenderer]);export function LineChart({height:e,data:o,unit:t,grid:n,legend:r,visualMap:a,onDataZoom:i,onDoubleClick:s}){const m=useChartsTheme(),p=useRef(),[l,u]=useState(!0),[h,d]=useState(!1),x=useMemo((()=>({datazoom:e=>{var t,n;if(void 0===i&&setTimeout((()=>{d(!1)}),10),void 0===i||void 0===e.batch[0])return;const r=null!==(t=e.batch[0].startValue)&&void 0!==t?t:0,a=null!==(n=e.batch[0].endValue)&&void 0!==n?n:o.xAxis.length-1,s=o.xAxis[r],m=o.xAxis[a];void 0!==s&&void 0!==m&&i({start:s,end:m,startIndex:r,endIndex:a})}})),[o,i,d]);void 0!==p.current&&enableDataZoom(p.current);const C=useDeepMemo((()=>{var e;if(void 0===o.timeSeries)return{};if(null===o.timeSeries||0===o.timeSeries.length)return m.noDataOption;const i=o.timeSeries.length<PROGRESSIVE_MODE_SERIES_LIMIT,s=null!==(e=o.rangeMs)&&void 0!==e?e:getDateRange(o.xAxis);return{series:o.timeSeries,xAxis:{type:"category",data:o.xAxis,max:o.xAxisMax,axisLabel:{formatter:e=>getFormattedDate(e,s)}},yAxis:{type:"value",boundaryGap:[0,"10%"],axisLabel:{formatter:e=>formatValue(e,t)}},animation:!1,tooltip:{show:i,trigger:"axis",showContent:!1,axisPointer:{type:"none"}},toolbox:{feature:{dataZoom:{icon:null,yAxisIndex:"none"}}},grid:n,legend:r,visualMap:a}}),[o,n,r,a]);return _jsxs(Box,{sx:{height:e},onClick:()=>d((e=>!e)),onDoubleClick:e=>{d(!1),void 0===s?void 0!==p.current&&restoreChart(p.current):s(e)},onMouseDown:e=>{e.target instanceof HTMLCanvasElement&&u(!1)},onMouseUp:()=>{u(!0)},onMouseLeave:()=>{u(!1),d(!1)},onMouseEnter:()=>{u(!0)},children:[!0===l&&_jsx(Tooltip,{chartRef:p,chartData:o,wrapLabels:!0,pinTooltip:h}),_jsx(EChart,{sx:{width:"100%",height:"100%"},option:C,theme:m.themeName,onEvents:x,_instance:p})]})}
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { useMemo, useRef, useState } from 'react';
15
+ import { useDeepMemo } from '@perses-dev/core';
16
+ import { Box } from '@mui/material';
17
+ import { use } from 'echarts/core';
18
+ import { LineChart as EChartsLineChart } from 'echarts/charts';
19
+ import { GridComponent, DataZoomComponent, MarkAreaComponent, MarkLineComponent, MarkPointComponent, TitleComponent, ToolboxComponent, TooltipComponent, LegendComponent, VisualMapComponent } from 'echarts/components';
20
+ import { CanvasRenderer } from 'echarts/renderers';
21
+ import { EChart } from '../EChart';
22
+ import { PROGRESSIVE_MODE_SERIES_LIMIT } from '../model/graph';
23
+ import { formatValue } from '../model/units';
24
+ import { useChartsTheme } from '../context/ChartsThemeProvider';
25
+ import { Tooltip } from '../Tooltip/Tooltip';
26
+ import { enableDataZoom, restoreChart, getDateRange, getFormattedDate } from './utils';
27
+ use([
28
+ EChartsLineChart,
29
+ GridComponent,
30
+ DataZoomComponent,
31
+ MarkAreaComponent,
32
+ MarkLineComponent,
33
+ MarkPointComponent,
34
+ TitleComponent,
35
+ ToolboxComponent,
36
+ TooltipComponent,
37
+ LegendComponent,
38
+ VisualMapComponent,
39
+ CanvasRenderer
40
+ ]);
41
+ export function LineChart({ height , data , unit , grid , legend , visualMap , onDataZoom , onDoubleClick }) {
42
+ const chartsTheme = useChartsTheme();
43
+ const chartRef = useRef();
44
+ const [showTooltip, setShowTooltip] = useState(true);
45
+ const [pinTooltip, setPinTooltip] = useState(false);
46
+ const handleEvents = useMemo(()=>{
47
+ return {
48
+ datazoom: (params)=>{
49
+ if (onDataZoom === undefined) {
50
+ setTimeout(()=>{
51
+ // workaround so unpin happens after click event
52
+ setPinTooltip(false);
53
+ }, 10);
54
+ }
55
+ if (onDataZoom === undefined || params.batch[0] === undefined) return;
56
+ var _startValue;
57
+ const startIndex = (_startValue = params.batch[0].startValue) !== null && _startValue !== void 0 ? _startValue : 0;
58
+ var _endValue;
59
+ const endIndex = (_endValue = params.batch[0].endValue) !== null && _endValue !== void 0 ? _endValue : data.xAxis.length - 1;
60
+ const xAxisStartValue = data.xAxis[startIndex];
61
+ const xAxisEndValue = data.xAxis[endIndex];
62
+ if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {
63
+ const zoomEvent = {
64
+ start: xAxisStartValue,
65
+ end: xAxisEndValue,
66
+ startIndex,
67
+ endIndex
68
+ };
69
+ onDataZoom(zoomEvent);
70
+ }
71
+ }
72
+ };
73
+ }, [
74
+ data,
75
+ onDataZoom,
76
+ setPinTooltip
77
+ ]);
78
+ if (chartRef.current !== undefined) {
79
+ enableDataZoom(chartRef.current);
80
+ }
81
+ const handleOnClick = ()=>setPinTooltip((current)=>!current);
82
+ const handleOnDoubleClick = (e)=>{
83
+ setPinTooltip(false);
84
+ // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
85
+ if (onDoubleClick === undefined) {
86
+ if (chartRef.current !== undefined) {
87
+ restoreChart(chartRef.current);
88
+ }
89
+ } else {
90
+ onDoubleClick(e);
91
+ }
92
+ };
93
+ const handleOnMouseDown = (e)=>{
94
+ // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
95
+ if (e.target instanceof HTMLCanvasElement) {
96
+ setShowTooltip(false);
97
+ }
98
+ };
99
+ const handleOnMouseUp = ()=>{
100
+ setShowTooltip(true);
101
+ };
102
+ const handleOnMouseEnter = ()=>{
103
+ setShowTooltip(true);
104
+ };
105
+ const handleOnMouseLeave = ()=>{
106
+ setShowTooltip(false);
107
+ setPinTooltip(false);
108
+ };
109
+ const option = useDeepMemo(()=>{
110
+ if (data.timeSeries === undefined) return {};
111
+ if (data.timeSeries === null || data.timeSeries.length === 0) return chartsTheme.noDataOption;
112
+ const showPointsOnHover = data.timeSeries.length < PROGRESSIVE_MODE_SERIES_LIMIT;
113
+ var _rangeMs;
114
+ const rangeMs = (_rangeMs = data.rangeMs) !== null && _rangeMs !== void 0 ? _rangeMs : getDateRange(data.xAxis);
115
+ const option = {
116
+ series: data.timeSeries,
117
+ xAxis: {
118
+ type: 'category',
119
+ data: data.xAxis,
120
+ max: data.xAxisMax,
121
+ axisLabel: {
122
+ formatter: (value)=>{
123
+ return getFormattedDate(value, rangeMs);
124
+ }
125
+ }
126
+ },
127
+ yAxis: {
128
+ type: 'value',
129
+ boundaryGap: [
130
+ 0,
131
+ '10%'
132
+ ],
133
+ axisLabel: {
134
+ formatter: (value)=>{
135
+ return formatValue(value, unit);
136
+ }
137
+ }
138
+ },
139
+ animation: false,
140
+ tooltip: {
141
+ show: showPointsOnHover,
142
+ trigger: 'axis',
143
+ showContent: false,
144
+ axisPointer: {
145
+ type: 'none'
146
+ }
147
+ },
148
+ toolbox: {
149
+ feature: {
150
+ dataZoom: {
151
+ icon: null,
152
+ yAxisIndex: 'none'
153
+ }
154
+ }
155
+ },
156
+ grid,
157
+ legend,
158
+ visualMap
159
+ };
160
+ return option;
161
+ }, [
162
+ data,
163
+ grid,
164
+ legend,
165
+ visualMap
166
+ ]);
167
+ return /*#__PURE__*/ _jsxs(Box, {
168
+ sx: {
169
+ height
170
+ },
171
+ onClick: handleOnClick,
172
+ onDoubleClick: handleOnDoubleClick,
173
+ onMouseDown: handleOnMouseDown,
174
+ onMouseUp: handleOnMouseUp,
175
+ onMouseLeave: handleOnMouseLeave,
176
+ onMouseEnter: handleOnMouseEnter,
177
+ children: [
178
+ showTooltip === true && /*#__PURE__*/ _jsx(Tooltip, {
179
+ chartRef: chartRef,
180
+ chartData: data,
181
+ wrapLabels: true,
182
+ pinTooltip: pinTooltip
183
+ }),
184
+ /*#__PURE__*/ _jsx(EChart, {
185
+ sx: {
186
+ width: '100%',
187
+ height: '100%'
188
+ },
189
+ option: option,
190
+ theme: chartsTheme.themeName,
191
+ onEvents: handleEvents,
192
+ _instance: chartRef
193
+ })
194
+ ]
195
+ });
196
+ }
197
+
198
+ //# sourceMappingURL=LineChart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/LineChart/LineChart.tsx"],"sourcesContent":["// Copyright 2022 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 { MouseEvent, useMemo, useRef, useState } from 'react';\nimport { useDeepMemo } from '@perses-dev/core';\nimport { Box } from '@mui/material';\nimport type {\n EChartsCoreOption,\n GridComponentOption,\n LineSeriesOption,\n LegendComponentOption,\n VisualMapComponentOption,\n} from 'echarts';\nimport { ECharts as EChartsInstance, use } from 'echarts/core';\nimport { LineChart as EChartsLineChart } from 'echarts/charts';\nimport {\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n VisualMapComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, OnEventsType } from '../EChart';\nimport { PROGRESSIVE_MODE_SERIES_LIMIT, EChartsDataFormat } from '../model/graph';\nimport { formatValue, UnitOptions } from '../model/units';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { Tooltip } from '../Tooltip/Tooltip';\nimport { enableDataZoom, restoreChart, getDateRange, getFormattedDate, ZoomEventData } from './utils';\n\nuse([\n EChartsLineChart,\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n VisualMapComponent,\n CanvasRenderer,\n]);\n\ninterface LineChartProps {\n height: number;\n data: EChartsDataFormat;\n unit?: UnitOptions;\n grid?: GridComponentOption;\n legend?: LegendComponentOption;\n visualMap?: VisualMapComponentOption[];\n onDataZoom?: (e: ZoomEventData) => void;\n onDoubleClick?: (e: MouseEvent) => void;\n}\n\nexport function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom, onDoubleClick }: LineChartProps) {\n const chartsTheme = useChartsTheme();\n const chartRef = useRef<EChartsInstance>();\n const [showTooltip, setShowTooltip] = useState<boolean>(true);\n const [pinTooltip, setPinTooltip] = useState<boolean>(false);\n\n const handleEvents: OnEventsType<LineSeriesOption['data'] | unknown> = useMemo(() => {\n return {\n datazoom: (params) => {\n if (onDataZoom === undefined) {\n setTimeout(() => {\n // workaround so unpin happens after click event\n setPinTooltip(false);\n }, 10);\n }\n if (onDataZoom === undefined || params.batch[0] === undefined) return;\n const startIndex = params.batch[0].startValue ?? 0;\n const endIndex = params.batch[0].endValue ?? data.xAxis.length - 1;\n const xAxisStartValue = data.xAxis[startIndex];\n const xAxisEndValue = data.xAxis[endIndex];\n\n if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {\n const zoomEvent: ZoomEventData = {\n start: xAxisStartValue,\n end: xAxisEndValue,\n startIndex,\n endIndex,\n };\n onDataZoom(zoomEvent);\n }\n },\n // TODO: use legendselectchanged event to fix tooltip when legend selected\n };\n }, [data, onDataZoom, setPinTooltip]);\n\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n\n const handleOnClick = () => setPinTooltip((current) => !current);\n\n const handleOnDoubleClick = (e: MouseEvent) => {\n setPinTooltip(false);\n // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior\n if (onDoubleClick === undefined) {\n if (chartRef.current !== undefined) {\n restoreChart(chartRef.current);\n }\n } else {\n onDoubleClick(e);\n }\n };\n\n const handleOnMouseDown = (e: MouseEvent) => {\n // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels\n if (e.target instanceof HTMLCanvasElement) {\n setShowTooltip(false);\n }\n };\n\n const handleOnMouseUp = () => {\n setShowTooltip(true);\n };\n\n const handleOnMouseEnter = () => {\n setShowTooltip(true);\n };\n\n const handleOnMouseLeave = () => {\n setShowTooltip(false);\n setPinTooltip(false);\n };\n\n const option: EChartsCoreOption = useDeepMemo(() => {\n if (data.timeSeries === undefined) return {};\n if (data.timeSeries === null || data.timeSeries.length === 0) return chartsTheme.noDataOption;\n\n const showPointsOnHover = data.timeSeries.length < PROGRESSIVE_MODE_SERIES_LIMIT;\n\n const rangeMs = data.rangeMs ?? getDateRange(data.xAxis);\n\n const option: EChartsCoreOption = {\n series: data.timeSeries,\n xAxis: {\n type: 'category',\n data: data.xAxis,\n max: data.xAxisMax,\n axisLabel: {\n formatter: (value: number) => {\n return getFormattedDate(value, rangeMs);\n },\n },\n },\n yAxis: {\n type: 'value',\n boundaryGap: [0, '10%'],\n axisLabel: {\n formatter: (value: number) => {\n return formatValue(value, unit);\n },\n },\n },\n animation: false,\n tooltip: {\n show: showPointsOnHover,\n trigger: 'axis',\n showContent: false,\n axisPointer: {\n type: 'none',\n },\n },\n toolbox: {\n feature: {\n dataZoom: {\n icon: null, // https://stackoverflow.com/a/67684076/17575201\n yAxisIndex: 'none',\n },\n },\n },\n grid,\n legend,\n visualMap,\n };\n\n return option;\n }, [data, grid, legend, visualMap]);\n\n return (\n <Box\n sx={{\n height,\n }}\n onClick={handleOnClick}\n onDoubleClick={handleOnDoubleClick}\n onMouseDown={handleOnMouseDown}\n onMouseUp={handleOnMouseUp}\n onMouseLeave={handleOnMouseLeave}\n onMouseEnter={handleOnMouseEnter}\n >\n {showTooltip === true && (\n <Tooltip chartRef={chartRef} chartData={data} wrapLabels={true} pinTooltip={pinTooltip}></Tooltip>\n )}\n\n <EChart\n sx={{\n width: '100%',\n height: '100%',\n }}\n option={option}\n theme={chartsTheme.themeName}\n onEvents={handleEvents}\n _instance={chartRef}\n />\n </Box>\n );\n}\n"],"names":["useMemo","useRef","useState","useDeepMemo","Box","use","LineChart","EChartsLineChart","GridComponent","DataZoomComponent","MarkAreaComponent","MarkLineComponent","MarkPointComponent","TitleComponent","ToolboxComponent","TooltipComponent","LegendComponent","VisualMapComponent","CanvasRenderer","EChart","PROGRESSIVE_MODE_SERIES_LIMIT","formatValue","useChartsTheme","Tooltip","enableDataZoom","restoreChart","getDateRange","getFormattedDate","height","data","unit","grid","legend","visualMap","onDataZoom","onDoubleClick","chartsTheme","chartRef","showTooltip","setShowTooltip","pinTooltip","setPinTooltip","handleEvents","datazoom","params","undefined","setTimeout","batch","startIndex","startValue","endIndex","endValue","xAxis","length","xAxisStartValue","xAxisEndValue","zoomEvent","start","end","current","handleOnClick","handleOnDoubleClick","e","handleOnMouseDown","target","HTMLCanvasElement","handleOnMouseUp","handleOnMouseEnter","handleOnMouseLeave","option","timeSeries","noDataOption","showPointsOnHover","rangeMs","series","type","max","xAxisMax","axisLabel","formatter","value","yAxis","boundaryGap","animation","tooltip","show","trigger","showContent","axisPointer","toolbox","feature","dataZoom","icon","yAxisIndex","sx","onClick","onMouseDown","onMouseUp","onMouseLeave","onMouseEnter","chartData","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
@@ -1 +1,15 @@
1
- export*from"./LineChart";
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './LineChart';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/LineChart/index.ts"],"sourcesContent":["// Copyright 2022 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\nexport * from './LineChart';\nexport type { ZoomEventData } from './utils';\n"],"names":[],"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,cAAc,aAAa,CAAC"}
@@ -1 +1,63 @@
1
- export function enableDataZoom(o){const t=o._model;void 0!==t&&void 0!==t.option.toolbox&&t.option.toolbox.length>0&&"normal"===t.option.toolbox[0].feature.dataZoom.iconStatus.zoom&&o.dispatchAction({type:"takeGlobalCursor",key:"dataZoomSelect",dataZoomSelectActive:!0})}export function restoreChart(o){o.dispatchAction({type:"restore"})}export function getDateRange(o){const t=36e5;if(0===o.length)return t;const e=o[o.length-1];return void 0===o[0]||void 0===e?t:e-o[0]}export function getFormattedDate(o,t){const e={hour:"numeric",minute:"numeric",hourCycle:"h23"};return t<=18e5?e.second="numeric":t>=864e5&&(e.month="numeric",e.day="numeric"),new Intl.DateTimeFormat(void 0,e).format(o).replace(/, /g," ")}
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ // enable dataZoom without requring user to click toolbox icon
14
+ export function enableDataZoom(chart) {
15
+ const chartModel = chart['_model'];
16
+ if (chartModel === undefined) return;
17
+ if (chartModel.option.toolbox !== undefined && chartModel.option.toolbox.length > 0) {
18
+ // check if hidden data zoom icon is unselected (if selected it would be 'emphasis' instead of 'normal')
19
+ if (chartModel.option.toolbox[0].feature.dataZoom.iconStatus.zoom === 'normal') {
20
+ chart.dispatchAction({
21
+ type: 'takeGlobalCursor',
22
+ key: 'dataZoomSelect',
23
+ dataZoomSelectActive: true
24
+ });
25
+ }
26
+ }
27
+ }
28
+ // restore chart to original state before zoom or other actions were dispatched
29
+ // TODO: support incremental unzoom instead of restore to original state
30
+ export function restoreChart(chart) {
31
+ chart.dispatchAction({
32
+ type: 'restore'
33
+ });
34
+ }
35
+ // fallback when xAxis time range not passed as prop
36
+ export function getDateRange(data) {
37
+ const defaultRange = 3600000; // hour in ms
38
+ if (data.length === 0) return defaultRange;
39
+ const lastDatum = data[data.length - 1];
40
+ if (data[0] === undefined || lastDatum === undefined) return defaultRange;
41
+ return lastDatum - data[0];
42
+ }
43
+ // determines time granularity for axis labels, defaults to hh:mm
44
+ export function getFormattedDate(value, rangeMs) {
45
+ const dateFormatOptions = {
46
+ hour: 'numeric',
47
+ minute: 'numeric',
48
+ hourCycle: 'h23'
49
+ };
50
+ const thirtyMinMs = 1800000;
51
+ const dayMs = 86400000;
52
+ if (rangeMs <= thirtyMinMs) {
53
+ dateFormatOptions.second = 'numeric';
54
+ } else if (rangeMs >= dayMs) {
55
+ dateFormatOptions.month = 'numeric';
56
+ dateFormatOptions.day = 'numeric';
57
+ }
58
+ const DATE_FORMAT = new Intl.DateTimeFormat(undefined, dateFormatOptions);
59
+ // remove comma when month / day present
60
+ return DATE_FORMAT.format(value).replace(/, /g, ' ');
61
+ }
62
+
63
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/LineChart/utils.ts"],"sourcesContent":["// Copyright 2022 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 { ECharts as EChartsInstance } from 'echarts/core';\n\nexport interface ZoomEventData {\n start: number;\n end: number;\n startIndex: number;\n endIndex: number;\n}\n\n// enable dataZoom without requring user to click toolbox icon\nexport function enableDataZoom(chart: EChartsInstance) {\n const chartModel = chart['_model'];\n if (chartModel === undefined) return;\n if (chartModel.option.toolbox !== undefined && chartModel.option.toolbox.length > 0) {\n // check if hidden data zoom icon is unselected (if selected it would be 'emphasis' instead of 'normal')\n if (chartModel.option.toolbox[0].feature.dataZoom.iconStatus.zoom === 'normal') {\n chart.dispatchAction({\n type: 'takeGlobalCursor',\n key: 'dataZoomSelect',\n dataZoomSelectActive: true,\n });\n }\n }\n}\n\n// restore chart to original state before zoom or other actions were dispatched\n// TODO: support incremental unzoom instead of restore to original state\nexport function restoreChart(chart: EChartsInstance) {\n chart.dispatchAction({\n type: 'restore', // https://echarts.apache.org/en/api.html#events.restore\n });\n}\n\n// fallback when xAxis time range not passed as prop\nexport function getDateRange(data: number[]) {\n const defaultRange = 3600000; // hour in ms\n if (data.length === 0) return defaultRange;\n const lastDatum = data[data.length - 1];\n if (data[0] === undefined || lastDatum === undefined) return defaultRange;\n return lastDatum - data[0];\n}\n\n// determines time granularity for axis labels, defaults to hh:mm\nexport function getFormattedDate(value: number, rangeMs: number) {\n const dateFormatOptions: Intl.DateTimeFormatOptions = {\n hour: 'numeric',\n minute: 'numeric',\n hourCycle: 'h23',\n };\n const thirtyMinMs = 1800000;\n const dayMs = 86400000;\n if (rangeMs <= thirtyMinMs) {\n dateFormatOptions.second = 'numeric';\n } else if (rangeMs >= dayMs) {\n dateFormatOptions.month = 'numeric';\n dateFormatOptions.day = 'numeric';\n }\n const DATE_FORMAT = new Intl.DateTimeFormat(undefined, dateFormatOptions);\n // remove comma when month / day present\n return DATE_FORMAT.format(value).replace(/, /g, ' ');\n}\n"],"names":["enableDataZoom","chart","chartModel","undefined","option","toolbox","length","feature","dataZoom","iconStatus","zoom","dispatchAction","type","key","dataZoomSelectActive","restoreChart","getDateRange","data","defaultRange","lastDatum","getFormattedDate","value","rangeMs","dateFormatOptions","hour","minute","hourCycle","thirtyMinMs","dayMs","second","month","day","DATE_FORMAT","Intl","DateTimeFormat","format","replace"],"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;AAWjC,8DAA8D;AAC9D,OAAO,SAASA,cAAc,CAACC,KAAsB,EAAE;IACrD,MAAMC,UAAU,GAAGD,KAAK,CAAC,QAAQ,CAAC,AAAC;IACnC,IAAIC,UAAU,KAAKC,SAAS,EA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AMC,WAAW,GAAG,OAAO,AAAC;IAC5B,MAAMC,KAAK,GAAG,QAAQ,AAAC;IACvB,IAAIN,OAAO,IAAIK,WAAW,EAAE;QAC1BJ,iBAAiB,CAACM,MAAM,GAAG,SAAS,CAAC;IACvC,OAAO,IAAIP,OAAO,IAAIM,KAAK,EAAE;QAC3BL,iBAAiB,CAACO,KAAK,GAAG,SAAS,CAAC;QACpCP,iBAAiB,CAACQ,GAAG,GAAG,SAAS,CAAC;IACpC,CAAC;IACD,MAAMC,WAAW,GAAG,IAAIC,IAAI,CAACC,cAAc,CAAC/B,SAAS,EAAEoB,iBAAiB,CAAC,AAAC;IAC1E,wCAAwC;IACxC,OAAOS,WAAW,CAACG,MAAM,CAACd,KAAK,CAAC,CAACe,OAAO,QAAQ,GAAG,CAAC,CAAC;AACvD,CAAC"}
@@ -1 +1,121 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useMemo}from"react";import{Box,Typography}from"@mui/material";import{merge}from"lodash-es";import{use}from"echarts/core";import{GaugeChart as EChartsGaugeChart}from"echarts/charts";import{LineChart as EChartsLineChart}from"echarts/charts";import{GridComponent,DatasetComponent,TitleComponent,TooltipComponent}from"echarts/components";import{CanvasRenderer}from"echarts/renderers";import{useChartsTheme}from"../context/ChartsThemeProvider";import{formatValue}from"../model/units";import{EChart}from"../EChart";use([EChartsGaugeChart,EChartsLineChart,GridComponent,DatasetComponent,TitleComponent,TooltipComponent,CanvasRenderer]);const PANEL_PADDING=32,MIN_VALUE_SIZE=12,MAX_VALUE_SIZE=36;export function StatChart(t){const{width:e,height:o,data:r,unit:a,sparkline:s}=t,i=useChartsTheme(),n=void 0===r.calculatedValue?"No data":formatValue(r.calculatedValue,a),m=useMemo((()=>{if(void 0===r.seriesData)return i.noDataOption;const t=r.seriesData,e=[];if(void 0!==s){const o={type:"line",data:[...t.values],zlevel:1,symbol:"none",animation:!1,silent:!0},r=merge(o,s);e.push(r)}return{title:{show:!1},grid:{show:!1,top:"35%",right:0,bottom:0,left:0,containLabel:!1},xAxis:{type:"time",show:!1,boundaryGap:!1},yAxis:{type:"value",show:!1},tooltip:{show:!1},series:e}}),[r,i,s]),h=e>250&&o>180,p=n.length,l=!0===h?36:Math.min(e,o)/p;return _jsxs(Box,{children:[_jsx(Typography,{variant:"h3",sx:t=>({color:t.palette.text.primary,fontSize:`clamp(12px, ${l}px, 36px)`}),children:n}),void 0!==s&&_jsx(EChart,{sx:{width:e+32,height:o,position:"absolute",bottom:0,left:0},option:m,theme:i.themeName,renderer:"svg"})]})}
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import React, { useMemo } from 'react';
15
+ import { Box, Typography } from '@mui/material';
16
+ import { merge } from 'lodash-es';
17
+ import { use } from 'echarts/core';
18
+ import { GaugeChart as EChartsGaugeChart } from 'echarts/charts';
19
+ import { LineChart as EChartsLineChart } from 'echarts/charts';
20
+ import { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';
21
+ import { CanvasRenderer } from 'echarts/renderers';
22
+ import { useChartsTheme } from '../context/ChartsThemeProvider';
23
+ import { formatValue } from '../model/units';
24
+ import { EChart } from '../EChart';
25
+ use([
26
+ EChartsGaugeChart,
27
+ EChartsLineChart,
28
+ GridComponent,
29
+ DatasetComponent,
30
+ TitleComponent,
31
+ TooltipComponent,
32
+ CanvasRenderer
33
+ ]);
34
+ const PANEL_PADDING = 32;
35
+ const MIN_VALUE_SIZE = 12;
36
+ const MAX_VALUE_SIZE = 36;
37
+ export function StatChart(props) {
38
+ const { width , height , data , unit , sparkline } = props;
39
+ const chartsTheme = useChartsTheme();
40
+ const formattedValue = data.calculatedValue === undefined ? 'No data' : formatValue(data.calculatedValue, unit);
41
+ const option = useMemo(()=>{
42
+ if (data.seriesData === undefined) return chartsTheme.noDataOption;
43
+ const series = data.seriesData;
44
+ const statSeries = [];
45
+ if (sparkline !== undefined) {
46
+ const lineSeries = {
47
+ type: 'line',
48
+ data: [
49
+ ...series.values
50
+ ],
51
+ zlevel: 1,
52
+ symbol: 'none',
53
+ animation: false,
54
+ silent: true
55
+ };
56
+ const mergedSeries = merge(lineSeries, sparkline);
57
+ statSeries.push(mergedSeries);
58
+ }
59
+ const option = {
60
+ title: {
61
+ show: false
62
+ },
63
+ grid: {
64
+ show: false,
65
+ top: '35%',
66
+ right: 0,
67
+ bottom: 0,
68
+ left: 0,
69
+ containLabel: false
70
+ },
71
+ xAxis: {
72
+ type: 'time',
73
+ show: false,
74
+ boundaryGap: false
75
+ },
76
+ yAxis: {
77
+ type: 'value',
78
+ show: false
79
+ },
80
+ tooltip: {
81
+ show: false
82
+ },
83
+ series: statSeries
84
+ };
85
+ return option;
86
+ }, [
87
+ data,
88
+ chartsTheme,
89
+ sparkline
90
+ ]);
91
+ const isLargePanel = width > 250 && height > 180;
92
+ // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute
93
+ const charactersAdjust = formattedValue.length;
94
+ const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
95
+ return /*#__PURE__*/ _jsxs(Box, {
96
+ children: [
97
+ /*#__PURE__*/ _jsx(Typography, {
98
+ variant: "h3",
99
+ sx: (theme)=>({
100
+ color: theme.palette.text.primary,
101
+ fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`
102
+ }),
103
+ children: formattedValue
104
+ }),
105
+ sparkline !== undefined && /*#__PURE__*/ _jsx(EChart, {
106
+ sx: {
107
+ width: width + PANEL_PADDING,
108
+ height: height,
109
+ position: 'absolute',
110
+ bottom: 0,
111
+ left: 0
112
+ },
113
+ option: option,
114
+ theme: chartsTheme.themeName,
115
+ renderer: "svg"
116
+ })
117
+ ]
118
+ });
119
+ }
120
+
121
+ //# sourceMappingURL=StatChart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/StatChart/StatChart.tsx"],"sourcesContent":["// Copyright 2022 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 React, { useMemo } from 'react';\nimport { Box, Typography } from '@mui/material';\nimport { merge } from 'lodash-es';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { GaugeChart as EChartsGaugeChart, GaugeSeriesOption } from 'echarts/charts';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { formatValue, UnitOptions } from '../model/units';\nimport { EChart } from '../EChart';\nimport { GraphSeries } from '../model/graph';\n\nuse([\n EChartsGaugeChart,\n EChartsLineChart,\n GridComponent,\n DatasetComponent,\n TitleComponent,\n TooltipComponent,\n CanvasRenderer,\n]);\n\nconst PANEL_PADDING = 32;\nconst MIN_VALUE_SIZE = 12;\nconst MAX_VALUE_SIZE = 36;\n\nexport interface StatChartData {\n calculatedValue?: number;\n seriesData?: GraphSeries;\n name?: string;\n}\n\ninterface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n unit: UnitOptions;\n sparkline?: LineSeriesOption;\n}\n\nexport function StatChart(props: StatChartProps) {\n const { width, height, data, unit, sparkline } = props;\n const chartsTheme = useChartsTheme();\n\n const formattedValue = data.calculatedValue === undefined ? 'No data' : formatValue(data.calculatedValue, unit);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.seriesData === undefined) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n\n const statSeries: Array<GaugeSeriesOption | LineSeriesOption> = [];\n\n if (sparkline !== undefined) {\n const lineSeries: LineSeriesOption = {\n type: 'line',\n data: [...series.values],\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n const mergedSeries = merge(lineSeries, sparkline);\n statSeries.push(mergedSeries);\n }\n\n const option = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline]);\n\n const isLargePanel = width > 250 && height > 180;\n // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute\n const charactersAdjust = formattedValue.length;\n const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;\n\n return (\n <Box>\n <Typography\n variant=\"h3\"\n sx={(theme) => ({\n color: theme.palette.text.primary,\n fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,\n })}\n >\n {formattedValue}\n </Typography>\n {sparkline !== undefined && (\n <EChart\n sx={{\n width: width + PANEL_PADDING, // allows sparkline to extend to edge of panel\n height: height,\n position: 'absolute',\n bottom: 0,\n left: 0,\n }}\n option={option}\n theme={chartsTheme.themeName}\n renderer=\"svg\"\n />\n )}\n </Box>\n );\n}\n"],"names":["React","useMemo","Box","Typography","merge","use","GaugeChart","EChartsGaugeChart","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","formatValue","EChart","PANEL_PADDING","MIN_VALUE_SIZE","MAX_VALUE_SIZE","StatChart","props","width","height","data","unit","sparkline","chartsTheme","formattedValue","calculatedValue","undefined","option","seriesData","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","tooltip","isLargePanel","charactersAdjust","length","valueSize","Math","min","variant","sx","theme","color","palette","text","primary","fontSize","position","themeName","renderer"],"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;AAAA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO,CAAC;AACvC,SAASC,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAChD,SAASC,KAAK,QAAQ,WAAW,CAAC;AAClC,SAASC,GAAG,QAA2B,cAAc,CAAC;AACtD,SAASC,UAAU,IAAIC,iBAAiB,QAA2B,gBAAgB,CAAC;AACpF,SAASC,SAAS,IAAIC,gBAAgB,QAA0B,gBAAgB,CAAC;AACjF,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,oBAAoB,CAAC;AACvG,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,cAAc,QAAQ,gCAAgC,CAAC;AAChE,SAASC,WAAW,QAAqB,gBAAgB,CAAC;AAC1D,SAASC,MAAM,QAAQ,WAAW,CAAC;AAGnCZ,GAAG,CAAC;IACFE,iBAAiB;IACjBE,gBAAgB;IAChBC,aAAa;IACbC,gBAAgB;IAChBC,cAAc;IACdC,gBAAgB;IAChBC,cAAc;CACf,CAAC,CAAC;AAEH,MAAMI,aA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