@perses-dev/components 0.4.0 → 0.5.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 (139) 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 +1 -1
  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}/Tooltip.d.ts +1 -1
  45. package/dist/{tooltip → Tooltip}/Tooltip.d.ts.map +1 -1
  46. package/dist/{tooltip → Tooltip}/Tooltip.js +0 -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 → Tooltip}/focused-series.js +0 -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 +0 -0
  60. package/dist/{tooltip → Tooltip}/tooltip-model.d.ts.map +1 -1
  61. package/dist/{tooltip → Tooltip}/tooltip-model.js +0 -0
  62. package/dist/cjs/EChart.js +3 -3
  63. package/dist/cjs/{GaugeChart.js → GaugeChart/GaugeChart.js} +12 -45
  64. package/dist/cjs/GaugeChart/index.js +29 -0
  65. package/dist/cjs/InfoTooltip/InfoTooltip.js +39 -0
  66. package/dist/cjs/InfoTooltip/InfoTooltip.test.js +33 -0
  67. package/dist/cjs/InfoTooltip/index.js +29 -0
  68. package/dist/cjs/{LineChart.js → LineChart/LineChart.js} +36 -109
  69. package/dist/cjs/LineChart/index.js +29 -0
  70. package/dist/cjs/LineChart/utils.js +72 -0
  71. package/dist/cjs/StatChart/StatChart.js +104 -0
  72. package/dist/cjs/StatChart/StatChart.test.js +45 -0
  73. package/dist/cjs/StatChart/index.js +29 -0
  74. package/dist/cjs/{tooltip → Tooltip}/SeriesInfo.js +2 -1
  75. package/dist/cjs/{tooltip → Tooltip}/SeriesMarker.js +0 -0
  76. package/dist/cjs/{tooltip → Tooltip}/Tooltip.js +0 -0
  77. package/dist/cjs/{tooltip → Tooltip}/TooltipContent.js +0 -0
  78. package/dist/cjs/{tooltip → Tooltip}/focused-series.js +0 -0
  79. package/dist/cjs/Tooltip/focused-series.test.js +57 -0
  80. package/dist/cjs/Tooltip/index.js +30 -0
  81. package/dist/cjs/{tooltip → Tooltip}/tooltip-model.js +0 -0
  82. package/dist/cjs/context/ChartsThemeProvider.js +36 -0
  83. package/dist/cjs/index.js +5 -4
  84. package/dist/cjs/model/{graph-model.js → graph.js} +0 -0
  85. package/dist/cjs/model/index.js +31 -0
  86. package/dist/cjs/model/theme.js +14 -0
  87. package/dist/cjs/model/units.js +58 -85
  88. package/dist/cjs/test/index.js +29 -0
  89. package/dist/cjs/test/render.js +26 -0
  90. package/dist/cjs/test/setup-tests.js +18 -0
  91. package/dist/cjs/utils/index.js +30 -0
  92. package/dist/cjs/utils/theme-gen.js +180 -0
  93. package/dist/cjs/utils/theme-gen.test.js +196 -0
  94. package/dist/context/ChartsThemeProvider.d.ts +11 -0
  95. package/dist/context/ChartsThemeProvider.d.ts.map +1 -0
  96. package/dist/context/ChartsThemeProvider.js +1 -0
  97. package/dist/index.d.ts +5 -4
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +1 -1
  100. package/dist/model/{graph-model.d.ts → graph.d.ts} +7 -1
  101. package/dist/model/graph.d.ts.map +1 -0
  102. package/dist/model/{graph-model.js → graph.js} +0 -0
  103. package/dist/model/index.d.ts +4 -0
  104. package/dist/model/index.d.ts.map +1 -0
  105. package/dist/model/index.js +1 -0
  106. package/dist/model/theme.d.ts +16 -0
  107. package/dist/model/theme.d.ts.map +1 -0
  108. package/dist/model/theme.js +1 -0
  109. package/dist/model/units.d.ts +22 -11
  110. package/dist/model/units.d.ts.map +1 -1
  111. package/dist/model/units.js +1 -1
  112. package/dist/test/index.d.ts +2 -0
  113. package/dist/test/index.d.ts.map +1 -0
  114. package/dist/test/index.js +1 -0
  115. package/dist/test/render.d.ts +7 -0
  116. package/dist/test/render.d.ts.map +1 -0
  117. package/dist/test/render.js +1 -0
  118. package/dist/test/setup-tests.d.ts +2 -0
  119. package/dist/test/setup-tests.d.ts.map +1 -0
  120. package/dist/test/setup-tests.js +1 -0
  121. package/dist/utils/index.d.ts +3 -0
  122. package/dist/utils/index.d.ts.map +1 -0
  123. package/dist/utils/index.js +1 -0
  124. package/dist/utils/theme-gen.d.ts +6 -0
  125. package/dist/utils/theme-gen.d.ts.map +1 -0
  126. package/dist/utils/theme-gen.js +1 -0
  127. package/dist/utils/theme-gen.test.d.ts +2 -0
  128. package/dist/utils/theme-gen.test.d.ts.map +1 -0
  129. package/dist/utils/theme-gen.test.js +1 -0
  130. package/package.json +5 -3
  131. package/dist/GaugeChart.d.ts.map +0 -1
  132. package/dist/GaugeChart.js +0 -1
  133. package/dist/LineChart.d.ts +0 -22
  134. package/dist/LineChart.d.ts.map +0 -1
  135. package/dist/LineChart.js +0 -1
  136. package/dist/StatChart.d.ts.map +0 -1
  137. package/dist/StatChart.js +0 -1
  138. package/dist/cjs/StatChart.js +0 -207
  139. package/dist/model/graph-model.d.ts.map +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.0",
3
+ "version": "0.5.0",
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,12 +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
- "echarts": "^5.3.2",
27
+ "@perses-dev/core": "^0.5.0",
28
+ "echarts": "^5.3.3",
27
29
  "lodash-es": "^4.17.21",
28
30
  "react-error-boundary": "^3.1.4"
29
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,eAqLhB"}
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:a,visualMap:n,dataZoomEnabled:i,onDataZoom:m}){const s=useTheme(),p=useRef(),[l,d]=useState(!0),h=useMemo((()=>({datazoom:e=>{var o,r;if(void 0===m||void 0===e.batch[0])return;const a=null!==(o=e.batch[0].startValue)&&void 0!==o?o:0,n=null!==(r=e.batch[0].endValue)&&void 0!==r?r:t.xAxis.length-1,i=t.xAxis[a],s=t.xAxis[n];void 0!==i&&void 0!==s&&m({start:i,end:s,startIndex:a,endIndex:n})}})),[t,m]);void 0!==p.current&&!0===i&&p.current.dispatchAction({type:"takeGlobalCursor",key:"dataZoomSelect",dataZoomSelectActive:!0});const u=useDeepMemo((()=>{if(void 0===t.timeSeries)return{};if(null===t.timeSeries||0===t.timeSeries.length)return noDataOption;const e=t.timeSeries.length<PROGRESSIVE_MODE_SERIES_LIMIT,m={show:!0,top:10,right:10,iconStyle:{borderColor:s.palette.text.primary},feature:{dataZoom:{icon:i?null:void 0,yAxisIndex:"none"},restore:{}},emphasis:{iconStyle:{textFill:s.palette.text.primary}}};return!1===i&&delete m.feature.dataZoom.icon,{title:{show:!1},grid:merge({top:10,right:20,bottom:5,left:20,containLabel:!0},o),toolbox:merge(m,a),series:t.timeSeries,xAxis:{type:"category",data:t.xAxis,max:e=>e.max,axisLabel:{margin:15,color:s.palette.text.primary,formatter:e=>getFormattedDate(e)},axisTick:{show:!1},axisLine:{lineStyle:{color:s.palette.grey[600]}}},yAxis:{type:"value",boundaryGap:[0,"10%"],axisLabel:{margin:12,color:s.palette.text.primary,formatter:e=>abbreviateLargeNumber(e)},splitLine:{show:!0,lineStyle:{width:.5,color:s.palette.grey[300],opacity:.95}}},animation:!1,tooltip:{show:e,trigger:"axis",showContent:!1,axisPointer:{type:"none"}},legend:r,visualMap:n}}),[t,s,o,r,a,i,n]);return _jsxs(Box,{sx:{height:e},onMouseDown:e=>{e.target instanceof HTMLCanvasElement&&d(!1)},onMouseUp:()=>{d(!0)},onMouseLeave:()=>{d(!1)},onMouseEnter:()=>{d(!0)},children:[!0===l&&_jsx(Tooltip,{chartRef:p,tooltipData:emptyTooltipData,chartData:t,wrapLabels:!0}),_jsx(EChart,{sx:{width:"100%",height:"100%"},option:u,onEvents:h,_instance:p})]})}function getFormattedDate(e){return new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"numeric",hour12:!1}).format(1e3*e)}
@@ -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,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;CACjB,CAAC"}