@perses-dev/components 0.4.2 → 0.5.2

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 (148) hide show
  1. package/README.md +18 -0
  2. package/dist/EChart.d.ts +4 -1
  3. package/dist/EChart.d.ts.map +1 -1
  4. package/dist/EChart.js +1 -1
  5. package/dist/{GaugeChart.d.ts → GaugeChart/GaugeChart.d.ts} +2 -1
  6. package/dist/GaugeChart/GaugeChart.d.ts.map +1 -0
  7. package/dist/GaugeChart/GaugeChart.js +1 -0
  8. package/dist/GaugeChart/index.d.ts +2 -0
  9. package/dist/GaugeChart/index.d.ts.map +1 -0
  10. package/dist/GaugeChart/index.js +1 -0
  11. package/dist/InfoTooltip/InfoTooltip.d.ts +17 -0
  12. package/dist/InfoTooltip/InfoTooltip.d.ts.map +1 -0
  13. package/dist/InfoTooltip/InfoTooltip.js +1 -0
  14. package/dist/InfoTooltip/InfoTooltip.test.d.ts +2 -0
  15. package/dist/InfoTooltip/InfoTooltip.test.d.ts.map +1 -0
  16. package/dist/InfoTooltip/InfoTooltip.test.js +1 -0
  17. package/dist/InfoTooltip/index.d.ts +2 -0
  18. package/dist/InfoTooltip/index.d.ts.map +1 -0
  19. package/dist/InfoTooltip/index.js +1 -0
  20. package/dist/LineChart/LineChart.d.ts +17 -0
  21. package/dist/LineChart/LineChart.d.ts.map +1 -0
  22. package/dist/LineChart/LineChart.js +1 -0
  23. package/dist/LineChart/index.d.ts +3 -0
  24. package/dist/LineChart/index.d.ts.map +1 -0
  25. package/dist/LineChart/index.js +1 -0
  26. package/dist/LineChart/utils.d.ts +12 -0
  27. package/dist/LineChart/utils.d.ts.map +1 -0
  28. package/dist/LineChart/utils.js +1 -0
  29. package/dist/{StatChart.d.ts → StatChart/StatChart.d.ts} +4 -9
  30. package/dist/StatChart/StatChart.d.ts.map +1 -0
  31. package/dist/StatChart/StatChart.js +1 -0
  32. package/dist/StatChart/StatChart.test.d.ts +2 -0
  33. package/dist/StatChart/StatChart.test.d.ts.map +1 -0
  34. package/dist/StatChart/StatChart.test.js +1 -0
  35. package/dist/StatChart/index.d.ts +2 -0
  36. package/dist/StatChart/index.d.ts.map +1 -0
  37. package/dist/StatChart/index.js +1 -0
  38. package/dist/{tooltip → Tooltip}/SeriesInfo.d.ts +0 -0
  39. package/dist/{tooltip → Tooltip}/SeriesInfo.d.ts.map +1 -1
  40. package/dist/{tooltip → Tooltip}/SeriesInfo.js +0 -0
  41. package/dist/{tooltip → Tooltip}/SeriesMarker.d.ts +0 -0
  42. package/dist/{tooltip → Tooltip}/SeriesMarker.d.ts.map +1 -1
  43. package/dist/{tooltip → Tooltip}/SeriesMarker.js +0 -0
  44. package/dist/Tooltip/Tooltip.d.ts +11 -0
  45. package/dist/Tooltip/Tooltip.d.ts.map +1 -0
  46. package/dist/Tooltip/Tooltip.js +1 -0
  47. package/dist/{tooltip → Tooltip}/TooltipContent.d.ts +0 -0
  48. package/dist/{tooltip → Tooltip}/TooltipContent.d.ts.map +1 -1
  49. package/dist/{tooltip → Tooltip}/TooltipContent.js +0 -0
  50. package/dist/{tooltip → Tooltip}/focused-series.d.ts +1 -1
  51. package/dist/{tooltip → Tooltip}/focused-series.d.ts.map +1 -1
  52. package/dist/Tooltip/focused-series.js +1 -0
  53. package/dist/Tooltip/focused-series.test.d.ts +2 -0
  54. package/dist/Tooltip/focused-series.test.d.ts.map +1 -0
  55. package/dist/Tooltip/focused-series.test.js +1 -0
  56. package/dist/Tooltip/index.d.ts +3 -0
  57. package/dist/Tooltip/index.d.ts.map +1 -0
  58. package/dist/Tooltip/index.js +1 -0
  59. package/dist/{tooltip → Tooltip}/tooltip-model.d.ts +1 -1
  60. package/dist/{tooltip → Tooltip}/tooltip-model.d.ts.map +1 -1
  61. package/dist/{tooltip → Tooltip}/tooltip-model.js +1 -1
  62. package/dist/Tooltip/utils.d.ts +6 -0
  63. package/dist/Tooltip/utils.d.ts.map +1 -0
  64. package/dist/Tooltip/utils.js +1 -0
  65. package/dist/cjs/EChart.js +3 -3
  66. package/dist/cjs/{GaugeChart.js → GaugeChart/GaugeChart.js} +12 -45
  67. package/dist/cjs/GaugeChart/index.js +29 -0
  68. package/dist/cjs/InfoTooltip/InfoTooltip.js +39 -0
  69. package/dist/cjs/InfoTooltip/InfoTooltip.test.js +33 -0
  70. package/dist/cjs/InfoTooltip/index.js +29 -0
  71. package/dist/cjs/LineChart/LineChart.js +153 -0
  72. package/dist/cjs/LineChart/index.js +29 -0
  73. package/dist/cjs/LineChart/utils.js +72 -0
  74. package/dist/cjs/StatChart/StatChart.js +104 -0
  75. package/dist/cjs/StatChart/StatChart.test.js +45 -0
  76. package/dist/cjs/StatChart/index.js +29 -0
  77. package/dist/cjs/{tooltip → Tooltip}/SeriesInfo.js +0 -0
  78. package/dist/cjs/{tooltip → Tooltip}/SeriesMarker.js +0 -0
  79. package/dist/cjs/{tooltip → Tooltip}/Tooltip.js +33 -40
  80. package/dist/cjs/{tooltip → Tooltip}/TooltipContent.js +0 -0
  81. package/dist/cjs/{tooltip → Tooltip}/focused-series.js +1 -1
  82. package/dist/cjs/Tooltip/focused-series.test.js +57 -0
  83. package/dist/cjs/Tooltip/index.js +30 -0
  84. package/dist/cjs/{tooltip → Tooltip}/tooltip-model.js +1 -1
  85. package/dist/cjs/Tooltip/utils.js +53 -0
  86. package/dist/cjs/context/ChartsThemeProvider.js +36 -0
  87. package/dist/cjs/index.js +5 -4
  88. package/dist/cjs/model/{graph-model.js → graph.js} +0 -0
  89. package/dist/cjs/model/index.js +31 -0
  90. package/dist/cjs/model/theme.js +14 -0
  91. package/dist/cjs/model/units.js +58 -85
  92. package/dist/cjs/test/index.js +29 -0
  93. package/dist/cjs/test/render.js +26 -0
  94. package/dist/cjs/test/setup-tests.js +18 -0
  95. package/dist/cjs/utils/index.js +30 -0
  96. package/dist/cjs/utils/theme-gen.js +180 -0
  97. package/dist/cjs/utils/theme-gen.test.js +196 -0
  98. package/dist/context/ChartsThemeProvider.d.ts +11 -0
  99. package/dist/context/ChartsThemeProvider.d.ts.map +1 -0
  100. package/dist/context/ChartsThemeProvider.js +1 -0
  101. package/dist/index.d.ts +5 -4
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +1 -1
  104. package/dist/model/{graph-model.d.ts → graph.d.ts} +6 -2
  105. package/dist/model/graph.d.ts.map +1 -0
  106. package/dist/model/{graph-model.js → graph.js} +0 -0
  107. package/dist/model/index.d.ts +4 -0
  108. package/dist/model/index.d.ts.map +1 -0
  109. package/dist/model/index.js +1 -0
  110. package/dist/model/theme.d.ts +16 -0
  111. package/dist/model/theme.d.ts.map +1 -0
  112. package/dist/model/theme.js +1 -0
  113. package/dist/model/units.d.ts +22 -11
  114. package/dist/model/units.d.ts.map +1 -1
  115. package/dist/model/units.js +1 -1
  116. package/dist/test/index.d.ts +2 -0
  117. package/dist/test/index.d.ts.map +1 -0
  118. package/dist/test/index.js +1 -0
  119. package/dist/test/render.d.ts +7 -0
  120. package/dist/test/render.d.ts.map +1 -0
  121. package/dist/test/render.js +1 -0
  122. package/dist/test/setup-tests.d.ts +2 -0
  123. package/dist/test/setup-tests.d.ts.map +1 -0
  124. package/dist/test/setup-tests.js +1 -0
  125. package/dist/utils/index.d.ts +3 -0
  126. package/dist/utils/index.d.ts.map +1 -0
  127. package/dist/utils/index.js +1 -0
  128. package/dist/utils/theme-gen.d.ts +6 -0
  129. package/dist/utils/theme-gen.d.ts.map +1 -0
  130. package/dist/utils/theme-gen.js +1 -0
  131. package/dist/utils/theme-gen.test.d.ts +2 -0
  132. package/dist/utils/theme-gen.test.d.ts.map +1 -0
  133. package/dist/utils/theme-gen.test.js +1 -0
  134. package/package.json +5 -4
  135. package/dist/GaugeChart.d.ts.map +0 -1
  136. package/dist/GaugeChart.js +0 -1
  137. package/dist/LineChart.d.ts +0 -22
  138. package/dist/LineChart.d.ts.map +0 -1
  139. package/dist/LineChart.js +0 -1
  140. package/dist/StatChart.d.ts.map +0 -1
  141. package/dist/StatChart.js +0 -1
  142. package/dist/cjs/LineChart.js +0 -252
  143. package/dist/cjs/StatChart.js +0 -207
  144. package/dist/model/graph-model.d.ts.map +0 -1
  145. package/dist/tooltip/Tooltip.d.ts +0 -13
  146. package/dist/tooltip/Tooltip.d.ts.map +0 -1
  147. package/dist/tooltip/Tooltip.js +0 -1
  148. package/dist/tooltip/focused-series.js +0 -1
@@ -0,0 +1 @@
1
+ import{createTheme}from"@mui/material";import{generateChartsTheme}from"./theme-gen";describe("generateChartsTheme",(()=>{const n=createTheme({}),e=generateChartsTheme("perses",n,{legend:{textStyle:{color:"yellow"}},line:{showSymbol:!0,smooth:!0}});it("should return perses specific charts theme from converted MUI theme",(()=>{expect(e).toMatchInlineSnapshot('\n Object {\n "echartsTheme": Object {\n "bar": Object {\n "barMaxWidth": 150,\n "itemStyle": Object {\n "borderColor": "#e0e0e0",\n "borderWidth": 0,\n },\n },\n "categoryAxis": Object {\n "axisLabel": Object {\n "color": "rgba(0, 0, 0, 0.87)",\n "margin": 15,\n "show": true,\n },\n "axisLine": Object {\n "lineStyle": Object {\n "color": "#757575",\n },\n "show": true,\n },\n "axisTick": Object {\n "length": 6,\n "lineStyle": Object {\n "color": "#757575",\n },\n "show": false,\n },\n "show": true,\n "splitArea": Object {\n "areaStyle": Object {\n "color": Array [\n "#e0e0e0",\n ],\n },\n "show": false,\n },\n "splitLine": Object {\n "lineStyle": Object {\n "color": "#e0e0e0",\n "opacity": 0.6,\n "width": 0.5,\n },\n "show": true,\n },\n },\n "color": Array [\n "#8dd3c7",\n "#bebada",\n "#fb8072",\n "#80b1d3",\n "#fdb462",\n ],\n "gauge": Object {\n "detail": Object {\n "fontSize": 18,\n "fontWeight": 600,\n "valueAnimation": false,\n },\n "splitLine": Object {\n "distance": 0,\n "length": 4,\n "lineStyle": Object {\n "width": 1,\n },\n },\n "splitNumber": 12,\n },\n "grid": Object {\n "bottom": 0,\n "containLabel": true,\n "left": 20,\n "right": 20,\n "top": 5,\n },\n "legend": Object {\n "orient": "horizontal",\n "pageIconColor": "rgba(0, 0, 0, 0.54)",\n "pageIconInactiveColor": "rgba(0, 0, 0, 0.26)",\n "pageTextStyle": Object {\n "color": "#757575",\n },\n "textStyle": Object {\n "color": "yellow",\n },\n },\n "line": Object {\n "emphasis": Object {\n "lineStyle": Object {\n "width": 1.5,\n },\n },\n "lineStyle": Object {\n "width": 1,\n },\n "showSymbol": true,\n "smooth": true,\n "symbol": "circle",\n "symbolSize": 4,\n },\n "textStyle": Object {\n "color": "rgba(0, 0, 0, 0.87)",\n "fontFamily": "\\"Roboto\\", \\"Helvetica\\", \\"Arial\\", sans-serif",\n "fontSize": 12,\n },\n "title": Object {\n "show": false,\n },\n "toolbox": Object {\n "iconStyle": Object {\n "borderColor": "rgba(0, 0, 0, 0.87)",\n },\n "right": 10,\n "show": true,\n "top": 10,\n },\n "tooltip": Object {},\n "valueAxis": Object {\n "axisLabel": Object {\n "color": "rgba(0, 0, 0, 0.87)",\n "margin": 12,\n },\n "axisLine": Object {\n "show": false,\n },\n "show": true,\n "splitLine": Object {\n "lineStyle": Object {\n "color": "#e0e0e0",\n "opacity": 0.6,\n "width": 0.5,\n },\n "show": true,\n },\n },\n },\n "noDataOption": Object {\n "title": Object {\n "left": "center",\n "show": true,\n "text": "No data",\n "textStyle": Object {\n "color": "rgba(0, 0, 0, 0.87)",\n "fontSize": 16,\n "fontWeight": 400,\n },\n "top": "center",\n },\n "xAxis": Object {\n "show": false,\n },\n "yAxis": Object {\n "show": false,\n },\n },\n "sparkline": Object {\n "color": "#1976d2",\n "width": 2,\n },\n "themeName": "perses",\n }\n ')}))}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/components",
3
- "version": "0.4.2",
3
+ "version": "0.5.2",
4
4
  "description": "Common UI components used across Perses features",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -18,13 +18,14 @@
18
18
  "clean": "rimraf dist/",
19
19
  "build": "tsc --build",
20
20
  "build:cjs": "tsc --project ./tsconfig.cjs.json",
21
- "test": "echo 'no test to run' && exit 0",
21
+ "test": "TZ=UTC jest",
22
+ "test:watch": "TZ=UTC jest --watch",
22
23
  "lint": "eslint src --ext .ts,.tsx",
23
24
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
24
25
  },
25
26
  "dependencies": {
26
- "@perses-dev/core": "^0.4.2",
27
- "echarts": "^5.3.2",
27
+ "@perses-dev/core": "^0.5.2",
28
+ "echarts": "^5.3.3",
28
29
  "lodash-es": "^4.17.21",
29
30
  "react-error-boundary": "^3.1.4"
30
31
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"GaugeChart.d.ts","sourceRoot":"","sources":["../src/GaugeChart.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAmC,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGpF,OAAO,EAAe,WAAW,EAAE,MAAM,eAAe,CAAC;AA0BzD,oBAAY,cAAc,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAEvD,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;CACzC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eA2IhD"}
@@ -1 +0,0 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useMemo}from"react";import{use}from"echarts/core";import{GaugeChart as EChartsGaugeChart}from"echarts/charts";import{GridComponent,TitleComponent,TooltipComponent}from"echarts/components";import{CanvasRenderer}from"echarts/renderers";import{formatValue}from"./model/units";import{EChart}from"./EChart";use([EChartsGaugeChart,GridComponent,TitleComponent,TooltipComponent,CanvasRenderer]);const noDataOption={title:{show:!0,textStyle:{color:"grey",fontSize:16,fontWeight:400},text:"No data",left:"center",top:"center"},xAxis:{show:!1},yAxis:{show:!1},series:[]};export function GaugeChart(t){const{width:e,height:o,data:i,unit:r,axisLine:a}=t,s=useMemo((()=>null==i?noDataOption:{title:{show:!1},tooltip:{show:!1},series:[{type:"gauge",center:["50%","65%"],radius:"100%",startAngle:200,endAngle:-20,min:0,max:100,splitNumber:12,silent:!0,progress:{show:!0,width:22,itemStyle:{color:"auto"}},pointer:{show:!1},axisLine:{lineStyle:{color:[[1,"#e1e5e9"]],width:22}},axisTick:{show:!1,distance:-28,splitNumber:5,lineStyle:{width:2,color:"#999"}},splitLine:{show:!1,distance:-32,length:6,lineStyle:{width:2,color:"#999"}},axisLabel:{show:!1,distance:-18,color:"#999",fontSize:12},anchor:{show:!1},title:{show:!1},detail:{show:!1},data:[{value:i}]},{type:"gauge",center:["50%","65%"],radius:"114%",startAngle:200,endAngle:-20,min:0,max:100,pointer:{show:!1,itemStyle:{color:"auto"}},axisLine:a,axisTick:{show:!1},splitLine:{show:!1},axisLabel:{show:!1},detail:{show:!0,valueAnimation:!1,width:"60%",borderRadius:8,offsetCenter:[0,"-9%"],fontSize:20,fontWeight:"bolder",color:"inherit",formatter:t=>formatValue(t,{kind:r.kind,decimal_places:0})},data:[{value:i}]}]}),[i,r,a]);return _jsx(EChart,{sx:{width:e,height:o},option:s})}
@@ -1,22 +0,0 @@
1
- /// <reference types="react" />
2
- import type { GridComponentOption, LegendComponentOption, ToolboxComponentOption, VisualMapComponentOption } from 'echarts';
3
- import { EChartsDataFormat } from './model/graph-model';
4
- export interface ZoomEventData {
5
- start: number;
6
- end: number;
7
- startIndex: number;
8
- endIndex: number;
9
- }
10
- interface LineChartProps {
11
- height: number;
12
- data: EChartsDataFormat;
13
- grid?: GridComponentOption;
14
- legend?: LegendComponentOption;
15
- toolbox?: ToolboxComponentOption;
16
- visualMap?: VisualMapComponentOption[];
17
- dataZoomEnabled?: boolean;
18
- onDataZoom?: (e: ZoomEventData) => void;
19
- }
20
- export declare function LineChart({ height, data, grid, legend, toolbox, visualMap, dataZoomEnabled, onDataZoom, }: LineChartProps): JSX.Element;
21
- export {};
22
- //# sourceMappingURL=LineChart.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../src/LineChart.tsx"],"names":[],"mappings":";AAiBA,OAAO,KAAK,EAEV,mBAAmB,EAEnB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAiBjB,OAAO,EAAiC,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAyCvF,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC;IACxB,IAAI,CAAC,EAAE,mBAAmB,CAAC;IAC3B,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,SAAS,CAAC,EAAE,wBAAwB,EAAE,CAAC;IACvC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CACzC;AAED,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,OAAO,EACP,SAAS,EACT,eAAe,EACf,UAAU,GACX,EAAE,cAAc,eAwLhB"}
package/dist/LineChart.js DELETED
@@ -1 +0,0 @@
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,useTheme}from"@mui/material";import merge from"lodash/merge";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-model";import{abbreviateLargeNumber}from"./model/units";import{emptyTooltipData}from"./tooltip/tooltip-model";import{Tooltip}from"./tooltip/Tooltip";use([EChartsLineChart,GridComponent,DataZoomComponent,MarkAreaComponent,MarkLineComponent,MarkPointComponent,TitleComponent,ToolboxComponent,TooltipComponent,LegendComponent,VisualMapComponent,CanvasRenderer]);const noDataOption={title:{show:!0,textStyle:{color:"grey",fontSize:16,fontWeight:400},text:"No data",left:"center",top:"center"},xAxis:{show:!1},yAxis:{show:!1},series:[]};export function LineChart({height:e,data:t,grid:o,legend:r,toolbox:n,visualMap:a,dataZoomEnabled:i,onDataZoom:s}){const m=useTheme(),l=useRef(),[p,c]=useState(!0),u=useMemo((()=>({datazoom:e=>{var o,r;if(void 0===s||void 0===e.batch[0])return;const n=null!==(o=e.batch[0].startValue)&&void 0!==o?o:0,a=null!==(r=e.batch[0].endValue)&&void 0!==r?r:t.xAxis.length-1,i=t.xAxis[n],m=t.xAxis[a];void 0!==i&&void 0!==m&&s({start:i,end:m,startIndex:n,endIndex:a})}})),[t,s]);void 0!==l.current&&!0===i&&l.current.dispatchAction({type:"takeGlobalCursor",key:"dataZoomSelect",dataZoomSelectActive:!0});const d=useDeepMemo((()=>{var e;if(void 0===t.timeSeries)return{};if(null===t.timeSeries||0===t.timeSeries.length)return noDataOption;const s=t.timeSeries.length<PROGRESSIVE_MODE_SERIES_LIMIT,l={show:!0,top:10,right:10,iconStyle:{borderColor:m.palette.text.primary},feature:{dataZoom:{icon:i?null:void 0,yAxisIndex:"none"},restore:{}},emphasis:{iconStyle:{textFill:m.palette.text.primary}}};!1===i&&delete l.feature.dataZoom.icon;const p=null!==(e=t.rangeMs)&&void 0!==e?e:getDateRange(t.xAxis);return{title:{show:!1},grid:merge({top:10,right:20,bottom:5,left:20,containLabel:!0},o),toolbox:merge(l,n),series:t.timeSeries,xAxis:{type:"category",data:t.xAxis,max:t.xAxisMax,axisLabel:{margin:15,color:m.palette.text.primary,formatter:e=>getFormattedDate(e,p)},axisTick:{show:!1},axisLine:{lineStyle:{color:m.palette.grey[600]}}},yAxis:{type:"value",boundaryGap:[0,"10%"],axisLabel:{margin:12,color:m.palette.text.primary,formatter:e=>abbreviateLargeNumber(e)},splitLine:{show:!0,lineStyle:{width:.5,color:m.palette.grey[300],opacity:.95}}},animation:!1,tooltip:{show:s,trigger:"axis",showContent:!1,axisPointer:{type:"none"}},legend:r,visualMap:a}}),[t,m,o,r,n,i,a]);return _jsxs(Box,{sx:{height:e},onMouseDown:e=>{e.target instanceof HTMLCanvasElement&&c(!1)},onMouseUp:()=>{c(!0)},onMouseLeave:()=>{c(!1)},onMouseEnter:()=>{c(!0)},children:[!0===p&&_jsx(Tooltip,{chartRef:l,tooltipData:emptyTooltipData,chartData:t,wrapLabels:!0}),_jsx(EChart,{sx:{width:"100%",height:"100%"},option:d,onEvents:u,_instance:l})]})}function getDateRange(e){const t=36e5;if(0===e.length)return t;const o=e[e.length-1];return void 0===e[0]||void 0===o?t:o-e[0]}function getFormattedDate(e,t){const o={hour:"numeric",minute:"numeric",hourCycle:"h23"};return t<=18e5?o.second="numeric":t>=864e5&&(o.month="numeric",o.day="numeric"),new Intl.DateTimeFormat(void 0,o).format(e).replace(/, /g," ")}
@@ -1 +0,0 @@
1
- {"version":3,"file":"StatChart.d.ts","sourceRoot":"","sources":["../src/StatChart.tsx"],"names":[],"mappings":";AAmBA,OAAO,EAAiC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGjF,OAAO,EAAe,WAAW,EAAE,MAAM,eAAe,CAAC;AAEzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAiC5D,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC3C,UAAU,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,UAAU,cAAc;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eA+J9C"}
package/dist/StatChart.js DELETED
@@ -1 +0,0 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useMemo}from"react";import{useTheme}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{formatValue}from"./model/units";import{EChart}from"./EChart";use([EChartsGaugeChart,EChartsLineChart,GridComponent,DatasetComponent,TitleComponent,TooltipComponent,CanvasRenderer]);const noDataOption={title:{show:!0,textStyle:{color:"grey",fontSize:16,fontWeight:400},text:"No data",left:"center",top:"center"},xAxis:{show:!1},yAxis:{show:!1},series:[]};export function StatChart(t){const{width:e,height:o,data:a,unit:r,backgroundColor:i,sparkline:n}=t,s=useTheme(),h=useMemo((()=>{var t;if(void 0===a.seriesData)return{};if(null===a.seriesData||void 0===a.calculatedValue)return noDataOption;const h=a.seriesData,l=null!==(t=a.calculatedValue)&&void 0!==t?t:0,m=e>250,p=!0===m?a.name:"",u=Math.min(e,1.2*o),c=Math.min(u/4*.65,72),d=.5*c,f=[{type:"gauge",data:[{value:l,name:p}],detail:{show:!0,offsetCenter:["0%","-65%"],formatter:[`{name|${p}}`,`{value|${formatValue(l,r)}}`].join("\n"),rich:{name:{padding:!0===m?[0,0,5,0]:0,fontSize:d,lineHeight:2.5*d,fontWeight:500},value:{}}},center:["50%","60%"],animation:!1,silent:!0,title:{show:!1},progress:{show:!1},pointer:{show:!1},axisLine:{show:!1},axisTick:{show:!1},splitLine:{show:!1},axisLabel:{show:!1},anchor:{show:!1},zlevel:2}];if(void 0!==n){const t={type:"line",data:[...h.values],zlevel:1,symbol:"none",animation:!1,lineStyle:{color:"#FFFFFF",opacity:.6},areaStyle:{color:"#FFFFFF",opacity:.3},silent:!0},e=merge(t,n);f.push(e)}return{title:{show:!1},grid:[{show:!0,backgroundColor:i,top:0,right:0,bottom:0,left:0,containLabel:!1,borderWidth:0},{show:!1,top:"45%",right:0,bottom:0,left:0,containLabel:!1}],xAxis:{type:"time",show:!1,boundaryGap:!1,gridIndex:1},yAxis:{type:"value",show:!1,gridIndex:1},tooltip:{show:!1},series:f,textStyle:{color:"transparent"===i?s.palette.text.primary:"#FFFFFF",fontSize:25,lineHeight:18,fontFamily:'"Lato", sans-serif',fontWeight:"bold"},media:[{query:{maxWidth:150},option:{textStyle:{fontSize:12}}},{query:{minWidth:150},option:{textStyle:{fontSize:`max(14px, ${c}px)`,lineHeight:Math.min(16,1.2*c)}}}]}}),[a,o,s,r,e,n,i]);return _jsx(EChart,{sx:{width:e,height:o},option:h})}
@@ -1,252 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LineChart = void 0;
7
- const jsx_runtime_1 = require("react/jsx-runtime");
8
- // Copyright 2022 The Perses Authors
9
- // Licensed under the Apache License, Version 2.0 (the "License");
10
- // you may not use this file except in compliance with the License.
11
- // You may obtain a copy of the License at
12
- //
13
- // http://www.apache.org/licenses/LICENSE-2.0
14
- //
15
- // Unless required by applicable law or agreed to in writing, software
16
- // distributed under the License is distributed on an "AS IS" BASIS,
17
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- // See the License for the specific language governing permissions and
19
- // limitations under the License.
20
- const react_1 = require("react");
21
- const core_1 = require("@perses-dev/core");
22
- const material_1 = require("@mui/material");
23
- const merge_1 = __importDefault(require("lodash/merge"));
24
- const core_2 = require("echarts/core");
25
- const charts_1 = require("echarts/charts");
26
- const components_1 = require("echarts/components");
27
- const renderers_1 = require("echarts/renderers");
28
- const EChart_1 = require("./EChart");
29
- const graph_model_1 = require("./model/graph-model");
30
- const units_1 = require("./model/units");
31
- const tooltip_model_1 = require("./tooltip/tooltip-model");
32
- const Tooltip_1 = require("./tooltip/Tooltip");
33
- (0, core_2.use)([
34
- charts_1.LineChart,
35
- components_1.GridComponent,
36
- components_1.DataZoomComponent,
37
- components_1.MarkAreaComponent,
38
- components_1.MarkLineComponent,
39
- components_1.MarkPointComponent,
40
- components_1.TitleComponent,
41
- components_1.ToolboxComponent,
42
- components_1.TooltipComponent,
43
- components_1.LegendComponent,
44
- components_1.VisualMapComponent,
45
- renderers_1.CanvasRenderer,
46
- ]);
47
- const noDataOption = {
48
- title: {
49
- show: true,
50
- textStyle: {
51
- color: 'grey',
52
- fontSize: 16,
53
- fontWeight: 400,
54
- },
55
- text: 'No data',
56
- left: 'center',
57
- top: 'center',
58
- },
59
- xAxis: {
60
- show: false,
61
- },
62
- yAxis: {
63
- show: false,
64
- },
65
- series: [],
66
- };
67
- function LineChart({ height, data, grid, legend, toolbox, visualMap, dataZoomEnabled, onDataZoom, }) {
68
- const theme = (0, material_1.useTheme)();
69
- const chartRef = (0, react_1.useRef)();
70
- const [showTooltip, setShowTooltip] = (0, react_1.useState)(true);
71
- const handleEvents = (0, react_1.useMemo)(() => {
72
- return {
73
- datazoom: (params) => {
74
- var _a, _b;
75
- if (onDataZoom === undefined || params.batch[0] === undefined)
76
- return;
77
- const startIndex = (_a = params.batch[0].startValue) !== null && _a !== void 0 ? _a : 0;
78
- const endIndex = (_b = params.batch[0].endValue) !== null && _b !== void 0 ? _b : data.xAxis.length - 1;
79
- const xAxisStartValue = data.xAxis[startIndex];
80
- const xAxisEndValue = data.xAxis[endIndex];
81
- if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {
82
- const zoomEvent = {
83
- start: xAxisStartValue,
84
- end: xAxisEndValue,
85
- startIndex,
86
- endIndex,
87
- };
88
- onDataZoom(zoomEvent);
89
- }
90
- },
91
- };
92
- }, [data, onDataZoom]);
93
- if (chartRef.current !== undefined && dataZoomEnabled === true) {
94
- const chart = chartRef.current;
95
- chart.dispatchAction({
96
- type: 'takeGlobalCursor',
97
- key: 'dataZoomSelect',
98
- dataZoomSelectActive: true,
99
- });
100
- }
101
- const handleOnMouseDown = (event) => {
102
- // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
103
- if (event.target instanceof HTMLCanvasElement) {
104
- setShowTooltip(false);
105
- }
106
- };
107
- const handleOnMouseUp = () => {
108
- setShowTooltip(true);
109
- };
110
- const handleOnMouseEnter = () => {
111
- setShowTooltip(true);
112
- };
113
- const handleOnMouseLeave = () => {
114
- setShowTooltip(false);
115
- };
116
- const option = (0, core_1.useDeepMemo)(() => {
117
- var _a;
118
- if (data.timeSeries === undefined)
119
- return {};
120
- if (data.timeSeries === null || data.timeSeries.length === 0)
121
- return noDataOption;
122
- const showPointsOnHover = data.timeSeries.length < graph_model_1.PROGRESSIVE_MODE_SERIES_LIMIT;
123
- const defaultGrid = {
124
- top: 10,
125
- right: 20,
126
- bottom: 5,
127
- left: 20,
128
- containLabel: true,
129
- };
130
- const defaultToolbox = {
131
- show: true,
132
- top: 10,
133
- right: 10,
134
- iconStyle: {
135
- borderColor: theme.palette.text.primary,
136
- },
137
- feature: {
138
- dataZoom: {
139
- icon: dataZoomEnabled ? null : undefined,
140
- yAxisIndex: 'none',
141
- },
142
- restore: {},
143
- },
144
- emphasis: {
145
- iconStyle: {
146
- textFill: theme.palette.text.primary,
147
- },
148
- },
149
- };
150
- if (dataZoomEnabled === false) {
151
- delete defaultToolbox.feature.dataZoom.icon;
152
- }
153
- const rangeMs = (_a = data.rangeMs) !== null && _a !== void 0 ? _a : getDateRange(data.xAxis);
154
- const option = {
155
- title: {
156
- show: false,
157
- },
158
- grid: (0, merge_1.default)(defaultGrid, grid),
159
- toolbox: (0, merge_1.default)(defaultToolbox, toolbox),
160
- series: data.timeSeries,
161
- xAxis: {
162
- type: 'category',
163
- data: data.xAxis,
164
- max: data.xAxisMax,
165
- axisLabel: {
166
- margin: 15,
167
- color: theme.palette.text.primary,
168
- formatter: (value) => {
169
- return getFormattedDate(value, rangeMs);
170
- },
171
- },
172
- axisTick: {
173
- show: false,
174
- },
175
- axisLine: {
176
- lineStyle: {
177
- color: theme.palette.grey['600'],
178
- },
179
- },
180
- },
181
- yAxis: {
182
- type: 'value',
183
- boundaryGap: [0, '10%'],
184
- axisLabel: {
185
- margin: 12,
186
- color: theme.palette.text.primary,
187
- formatter: (value) => {
188
- return (0, units_1.abbreviateLargeNumber)(value);
189
- },
190
- },
191
- splitLine: {
192
- show: true,
193
- lineStyle: {
194
- width: 0.5,
195
- color: theme.palette.grey['300'],
196
- opacity: 0.95,
197
- },
198
- },
199
- },
200
- animation: false,
201
- tooltip: {
202
- show: showPointsOnHover,
203
- trigger: 'axis',
204
- showContent: false,
205
- axisPointer: {
206
- type: 'none',
207
- },
208
- },
209
- legend,
210
- visualMap,
211
- };
212
- return option;
213
- // TODO (sjcobb): consolidate option props using echarts theme to reduce num of items in dep array
214
- }, [data, theme, grid, legend, toolbox, dataZoomEnabled, visualMap]);
215
- return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
216
- height,
217
- }, onMouseDown: handleOnMouseDown, onMouseUp: handleOnMouseUp, onMouseLeave: handleOnMouseLeave, onMouseEnter: handleOnMouseEnter, children: [showTooltip === true && ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { chartRef: chartRef, tooltipData: tooltip_model_1.emptyTooltipData, chartData: data, wrapLabels: true })), (0, jsx_runtime_1.jsx)(EChart_1.EChart, { sx: {
218
- width: '100%',
219
- height: '100%',
220
- }, option: option, onEvents: handleEvents, _instance: chartRef })] }));
221
- }
222
- exports.LineChart = LineChart;
223
- // fallback when xAxis time range not passed as prop
224
- function getDateRange(data) {
225
- const defaultRange = 3600000; // hour in ms
226
- if (data.length === 0)
227
- return defaultRange;
228
- const lastDatum = data[data.length - 1];
229
- if (data[0] === undefined || lastDatum === undefined)
230
- return defaultRange;
231
- return lastDatum - data[0];
232
- }
233
- // determines time granularity for axis labels, defaults to hh:mm
234
- function getFormattedDate(value, rangeMs) {
235
- const dateFormatOptions = {
236
- hour: 'numeric',
237
- minute: 'numeric',
238
- hourCycle: 'h23',
239
- };
240
- const thirtyMinMs = 1800000;
241
- const dayMs = 86400000;
242
- if (rangeMs <= thirtyMinMs) {
243
- dateFormatOptions.second = 'numeric';
244
- }
245
- else if (rangeMs >= dayMs) {
246
- dateFormatOptions.month = 'numeric';
247
- dateFormatOptions.day = 'numeric';
248
- }
249
- const DATE_FORMAT = new Intl.DateTimeFormat(undefined, dateFormatOptions);
250
- // remove comma when month / day present
251
- return DATE_FORMAT.format(value).replace(/, /g, ' ');
252
- }
@@ -1,207 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StatChart = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- // Copyright 2022 The Perses Authors
6
- // Licensed under the Apache License, Version 2.0 (the "License");
7
- // you may not use this file except in compliance with the License.
8
- // You may obtain a copy of the License at
9
- //
10
- // http://www.apache.org/licenses/LICENSE-2.0
11
- //
12
- // Unless required by applicable law or agreed to in writing, software
13
- // distributed under the License is distributed on an "AS IS" BASIS,
14
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- // See the License for the specific language governing permissions and
16
- // limitations under the License.
17
- const react_1 = require("react");
18
- const material_1 = require("@mui/material");
19
- const lodash_es_1 = require("lodash-es");
20
- const core_1 = require("echarts/core");
21
- const charts_1 = require("echarts/charts");
22
- const charts_2 = require("echarts/charts");
23
- const components_1 = require("echarts/components");
24
- const renderers_1 = require("echarts/renderers");
25
- const units_1 = require("./model/units");
26
- const EChart_1 = require("./EChart");
27
- (0, core_1.use)([
28
- charts_1.GaugeChart,
29
- charts_2.LineChart,
30
- components_1.GridComponent,
31
- components_1.DatasetComponent,
32
- components_1.TitleComponent,
33
- components_1.TooltipComponent,
34
- renderers_1.CanvasRenderer,
35
- ]);
36
- const noDataOption = {
37
- title: {
38
- show: true,
39
- textStyle: {
40
- color: 'grey',
41
- fontSize: 16,
42
- fontWeight: 400,
43
- },
44
- text: 'No data',
45
- left: 'center',
46
- top: 'center',
47
- },
48
- xAxis: {
49
- show: false,
50
- },
51
- yAxis: {
52
- show: false,
53
- },
54
- series: [],
55
- };
56
- function StatChart(props) {
57
- const { width, height, data, unit, backgroundColor, sparkline } = props;
58
- const theme = (0, material_1.useTheme)();
59
- const option = (0, react_1.useMemo)(() => {
60
- var _a;
61
- if (data.seriesData === undefined)
62
- return {};
63
- if (data.seriesData === null || data.calculatedValue === undefined)
64
- return noDataOption;
65
- const series = data.seriesData;
66
- const calculatedValue = (_a = data.calculatedValue) !== null && _a !== void 0 ? _a : 0;
67
- const isLargePanel = width > 250 ? true : false;
68
- const showName = isLargePanel;
69
- const name = showName === true ? data.name : '';
70
- const smallestSide = Math.min(width, height * 1.2);
71
- const baseFontSize = Math.min((smallestSide / 4) * 0.65, 72);
72
- const nameFontSize = baseFontSize * 0.5;
73
- const statSeries = [
74
- {
75
- type: 'gauge',
76
- data: [
77
- {
78
- value: calculatedValue,
79
- name: name,
80
- },
81
- ],
82
- detail: {
83
- show: true,
84
- offsetCenter: ['0%', '-65%'],
85
- formatter: [`{name|${name}}`, `{value|${(0, units_1.formatValue)(calculatedValue, unit)}}`].join('\n'),
86
- rich: {
87
- name: {
88
- padding: showName === true ? [0, 0, 5, 0] : 0,
89
- fontSize: nameFontSize,
90
- lineHeight: nameFontSize * 2.5,
91
- fontWeight: 500,
92
- },
93
- value: {},
94
- },
95
- },
96
- center: ['50%', '60%'],
97
- animation: false,
98
- silent: true,
99
- title: { show: false },
100
- progress: { show: false },
101
- pointer: { show: false },
102
- axisLine: { show: false },
103
- axisTick: { show: false },
104
- splitLine: { show: false },
105
- axisLabel: { show: false },
106
- anchor: { show: false },
107
- zlevel: 2,
108
- },
109
- ];
110
- if (sparkline !== undefined) {
111
- const lineSeries = {
112
- type: 'line',
113
- data: [...series.values],
114
- zlevel: 1,
115
- symbol: 'none',
116
- animation: false,
117
- lineStyle: {
118
- color: '#FFFFFF',
119
- opacity: 0.6,
120
- },
121
- areaStyle: {
122
- color: '#FFFFFF',
123
- opacity: 0.3,
124
- },
125
- silent: true,
126
- };
127
- const mergedSeries = (0, lodash_es_1.merge)(lineSeries, sparkline);
128
- statSeries.push(mergedSeries);
129
- }
130
- const option = {
131
- title: {
132
- show: false,
133
- },
134
- grid: [
135
- {
136
- show: true,
137
- backgroundColor: backgroundColor,
138
- top: 0,
139
- right: 0,
140
- bottom: 0,
141
- left: 0,
142
- containLabel: false,
143
- borderWidth: 0,
144
- },
145
- {
146
- show: false,
147
- top: '45%',
148
- right: 0,
149
- bottom: 0,
150
- left: 0,
151
- containLabel: false,
152
- },
153
- ],
154
- xAxis: {
155
- type: 'time',
156
- show: false,
157
- boundaryGap: false,
158
- gridIndex: 1, // sparkline grid
159
- },
160
- yAxis: {
161
- type: 'value',
162
- show: false,
163
- gridIndex: 1,
164
- },
165
- tooltip: {
166
- show: false,
167
- },
168
- series: statSeries,
169
- textStyle: {
170
- color: backgroundColor === 'transparent' ? theme.palette.text.primary : '#FFFFFF',
171
- fontSize: 25,
172
- lineHeight: 18,
173
- fontFamily: '"Lato", sans-serif',
174
- fontWeight: 'bold',
175
- },
176
- media: [
177
- {
178
- query: {
179
- maxWidth: 150,
180
- },
181
- option: {
182
- textStyle: {
183
- fontSize: 12,
184
- },
185
- },
186
- },
187
- {
188
- query: {
189
- minWidth: 150,
190
- },
191
- option: {
192
- textStyle: {
193
- fontSize: `max(14px, ${baseFontSize}px)`,
194
- lineHeight: Math.min(16, baseFontSize * 1.2),
195
- },
196
- },
197
- },
198
- ],
199
- };
200
- return option;
201
- }, [data, height, theme, unit, width, sparkline, backgroundColor]);
202
- return ((0, jsx_runtime_1.jsx)(EChart_1.EChart, { sx: {
203
- width: width,
204
- height: height,
205
- }, option: option }));
206
- }
207
- exports.StatChart = StatChart;
@@ -1 +0,0 @@
1
- {"version":3,"file":"graph-model.d.ts","sourceRoot":"","sources":["../../src/model/graph-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,eAAO,MAAM,6BAA6B,MAAM,CAAC;AAEjD,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC,oBAAY,qBAAqB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAE3E,oBAAY,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;AAEhD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAEvE,IAAI,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,aAAa,EAAE,CAAC;CACzD;AAED,oBAAY,iBAAiB,GAAG;IAC9B,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
@@ -1,13 +0,0 @@
1
- import React from 'react';
2
- import { ECharts as EChartsInstance } from 'echarts/core';
3
- import { EChartsDataFormat } from '../model/graph-model';
4
- import { TooltipData } from './tooltip-model';
5
- interface TooltipProps {
6
- chartRef: React.MutableRefObject<EChartsInstance | undefined>;
7
- tooltipData: TooltipData;
8
- chartData: EChartsDataFormat;
9
- wrapLabels?: boolean;
10
- }
11
- export declare function Tooltip(props: TooltipProps): JSX.Element | null;
12
- export {};
13
- //# sourceMappingURL=Tooltip.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/tooltip/Tooltip.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAGL,WAAW,EAIZ,MAAM,iBAAiB,CAAC;AAGzB,UAAU,YAAY;IACpB,QAAQ,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IAC9D,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,sBA4D1C"}
@@ -1 +0,0 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useState}from"react";import{Box,Portal}from"@mui/material";import{getFocusedSeriesData}from"./focused-series";import{TOOLTIP_MAX_HEIGHT,TOOLTIP_MAX_WIDTH,useMousePosition}from"./tooltip-model";import{TooltipContent}from"./TooltipContent";export function Tooltip(t){var o,e;const{chartRef:r,chartData:n}=t,[l,i]=useState(null),s=useMousePosition();if(null===s)return null;const a=r.current,u=getFocusedSeriesData(s,n,l,a),p=null!==(o=null==a?void 0:a.getWidth())&&void 0!==o?o:750,T=null!==(e=null==a?void 0:a.getHeight())&&void 0!==e?e:230,d=assembleTransform(s,u.length,p,T,l);return 0===u.length?null:_jsx(Portal,{children:_jsx(Box,{sx:t=>({maxWidth:TOOLTIP_MAX_WIDTH,maxHeight:TOOLTIP_MAX_HEIGHT,position:"absolute",top:0,left:0,backgroundColor:"#2E313E",borderRadius:"6px",color:"#fff",fontSize:"11px",visibility:"visible",opacity:1,transition:"all 0.1s ease-out",zIndex:t.zIndex.tooltip,overflow:"hidden","&:hover":{overflowY:"auto"}}),style:{transform:d},onMouseEnter:()=>{null!==s&&i(s)},onMouseLeave:()=>{null!==l&&i(null)},children:_jsx(TooltipContent,{focusedSeries:u,wrapLabels:t.wrapLabels})})})}function assembleTransform(t,o,e,r,n){if(null===t)return"translate3d(0, 0)";null!==n&&(t=n);const l=t.viewport.x;let i=t.viewport.y+16;const s=.75*r;!0==t.viewport.y>.8*window.innerHeight?i=o>6?.65*t.viewport.y:.75*t.viewport.y:t.plotCanvas.y>s&&(i=.85*t.viewport.y);const a=e-.9*(o>1?TOOLTIP_MAX_WIDTH:TOOLTIP_MAX_WIDTH/2);return t.plotCanvas.x>a&&l>TOOLTIP_MAX_WIDTH?`translate3d(${l-32}px, ${i}px, 0) translateX(-100%)`:`translate3d(${l+32}px, ${i}px, 0)`}
@@ -1 +0,0 @@
1
- import{TOOLTIP_DATE_FORMAT,TOOLTIP_MAX_ITEMS}from"./tooltip-model";export function getNearbySeries(e,t,r){var i,n,l,o,a;const s=[],u=null!==(i=t[0])&&void 0!==i?i:null,d=null!==(n=t[1])&&void 0!==n?n:null;if(null===u||null===d)return s;if(Array.isArray(e.xAxis)&&Array.isArray(e.timeSeries))for(let t=0;t<e.timeSeries.length;t++){const i=e.timeSeries[t];if(s.length>TOOLTIP_MAX_ITEMS)break;if(void 0!==i){const n=i.name?i.name.toString():"",m=null!==(l=i.color)&&void 0!==l?l:"#000";if(Array.isArray(i.data))for(let l=0;l<i.data.length;l++){const f=null!==(o=e.xAxis[l])&&void 0!==o?o:0,v=null!==(a=i.data[l])&&void 0!==a?a:0;if(u===l&&"-"!==v&&d<=v+r&&d>=v-r){const e=f>99999999999?f:1e3*f,r=TOOLTIP_DATE_FORMAT.format(e);s.push({seriesIdx:t,datumIdx:l,seriesName:n,date:r,x:f,y:v,markerColor:m.toString()})}}}}return s}export function getFocusedSeriesData(e,t,r,i){var n,l;if(void 0===i||null===e)return[];let o=!1;if(null!==e.target){const t=e.target.parentElement;if(null!==t){const e=t.parentElement;null!==e&&i.getDom()===e&&(o=!0)}}if(null!==r&&(e=r,o=!0),!1===o)return[];if(void 0===i._model)return[];const a=i._model.getComponent("yAxis").axis.scale._interval,s=t.timeSeries.length>TOOLTIP_MAX_ITEMS?.5*a:2*a,u=[null!==(n=e.plotCanvas.x)&&void 0!==n?n:0,null!==(l=e.plotCanvas.y)&&void 0!==l?l:0];if(i.containPixel("grid",u)){const e=i.convertFromPixel("grid",u);if(void 0!==e[0]&&void 0!==e[1])return getNearbySeries(t,e,s)}return[]}