@perses-dev/components 0.2.0 → 0.3.1
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.
- package/dist/ECharts.d.ts +59 -0
- package/dist/ECharts.d.ts.map +1 -0
- package/dist/ECharts.js +1 -0
- package/dist/GaugeChart.d.ts +14 -0
- package/dist/GaugeChart.d.ts.map +1 -0
- package/dist/GaugeChart.js +1 -0
- package/dist/LineChart.d.ts +22 -0
- package/dist/LineChart.d.ts.map +1 -0
- package/dist/LineChart.js +1 -0
- package/dist/StatChart.d.ts +24 -0
- package/dist/StatChart.d.ts.map +1 -0
- package/dist/StatChart.js +1 -0
- package/dist/cjs/ECharts.js +103 -0
- package/dist/cjs/ErrorAlert.js +25 -0
- package/dist/cjs/ErrorBoundary.js +18 -0
- package/dist/cjs/GaugeChart.js +178 -0
- package/dist/cjs/LineChart.js +227 -0
- package/dist/cjs/StatChart.js +205 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/model/graph-model.js +16 -0
- package/dist/cjs/model/units.js +211 -0
- package/dist/cjs/tooltip/SeriesInfo.js +76 -0
- package/dist/cjs/tooltip/SeriesMarker.js +30 -0
- package/dist/cjs/tooltip/Tooltip.js +99 -0
- package/dist/cjs/tooltip/TooltipContent.js +50 -0
- package/dist/cjs/tooltip/focused-series.js +108 -0
- package/dist/cjs/tooltip/tooltip-model.js +82 -0
- package/dist/cjs/utils/combine-sx.js +30 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/model/graph-model.d.ts +13 -0
- package/dist/model/graph-model.d.ts.map +1 -0
- package/dist/model/graph-model.js +1 -0
- package/dist/model/units.d.ts +25 -0
- package/dist/model/units.d.ts.map +1 -0
- package/dist/model/units.js +1 -0
- package/dist/tooltip/SeriesInfo.d.ts +11 -0
- package/dist/tooltip/SeriesInfo.d.ts.map +1 -0
- package/dist/tooltip/SeriesInfo.js +1 -0
- package/dist/tooltip/SeriesMarker.d.ts +7 -0
- package/dist/tooltip/SeriesMarker.d.ts.map +1 -0
- package/dist/tooltip/SeriesMarker.js +1 -0
- package/dist/tooltip/Tooltip.d.ts +13 -0
- package/dist/tooltip/Tooltip.d.ts.map +1 -0
- package/dist/tooltip/Tooltip.js +1 -0
- package/dist/tooltip/TooltipContent.d.ts +9 -0
- package/dist/tooltip/TooltipContent.d.ts.map +1 -0
- package/dist/tooltip/TooltipContent.js +1 -0
- package/dist/tooltip/focused-series.d.ts +24 -0
- package/dist/tooltip/focused-series.d.ts.map +1 -0
- package/dist/tooltip/focused-series.js +1 -0
- package/dist/tooltip/tooltip-model.d.ts +79 -0
- package/dist/tooltip/tooltip-model.d.ts.map +1 -0
- package/dist/tooltip/tooltip-model.js +1 -0
- package/package.json +7 -3
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ECharts, EChartsCoreOption } from 'echarts/core';
|
|
3
|
+
import { SxProps, Theme } from '@mui/material';
|
|
4
|
+
export interface MouseEventsParameters<T> {
|
|
5
|
+
componentType: string;
|
|
6
|
+
seriesType: string;
|
|
7
|
+
seriesIndex: number;
|
|
8
|
+
seriesName: string;
|
|
9
|
+
name: string;
|
|
10
|
+
dataIndex: number;
|
|
11
|
+
data: Record<string, unknown> & T;
|
|
12
|
+
dataType: string;
|
|
13
|
+
value: number | number[];
|
|
14
|
+
color: string;
|
|
15
|
+
info: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
declare type OnEventFunction<T> = (params: MouseEventsParameters<T>, instance?: ECharts) => void;
|
|
18
|
+
declare const mouseEvents: readonly ["click", "dblclick", "mousedown", "mousemove", "mouseup", "mouseover", "mouseout", "globalout", "contextmenu"];
|
|
19
|
+
export declare type MouseEventName = typeof mouseEvents[number];
|
|
20
|
+
export interface DataZoomPayloadBatchItem {
|
|
21
|
+
dataZoomId: string;
|
|
22
|
+
start?: number;
|
|
23
|
+
end?: number;
|
|
24
|
+
startValue?: number;
|
|
25
|
+
endValue?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface HighlightPayloadBatchItem {
|
|
28
|
+
dataIndex: number;
|
|
29
|
+
dataIndexInside: number;
|
|
30
|
+
seriesIndex: number;
|
|
31
|
+
escapeConnect?: boolean;
|
|
32
|
+
notBlur?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface BatchEventsParameters {
|
|
35
|
+
type: BatchEventName;
|
|
36
|
+
batch: DataZoomPayloadBatchItem[] & HighlightPayloadBatchItem[];
|
|
37
|
+
}
|
|
38
|
+
declare type OnBatchEventFunction = (params: BatchEventsParameters) => void;
|
|
39
|
+
declare const batchEvents: readonly ["datazoom", "downplay", "highlight"];
|
|
40
|
+
export declare type BatchEventName = typeof batchEvents[number];
|
|
41
|
+
declare type ChartEventName = 'finished';
|
|
42
|
+
export declare type OnEventsType<T> = {
|
|
43
|
+
[mouseEventName in MouseEventName]?: OnEventFunction<T>;
|
|
44
|
+
} & {
|
|
45
|
+
[batchEventName in BatchEventName]?: OnBatchEventFunction;
|
|
46
|
+
} & {
|
|
47
|
+
[eventName in ChartEventName]?: () => void;
|
|
48
|
+
};
|
|
49
|
+
export interface EChartsProps<T> {
|
|
50
|
+
option: EChartsCoreOption;
|
|
51
|
+
sx?: SxProps<Theme>;
|
|
52
|
+
onChartInitialized?: (instance: ECharts) => void;
|
|
53
|
+
onEvents?: OnEventsType<T>;
|
|
54
|
+
_instance?: React.MutableRefObject<ECharts | undefined>;
|
|
55
|
+
parentContainer?: HTMLDivElement | null;
|
|
56
|
+
}
|
|
57
|
+
export declare function ECharts<T>({ sx, _instance, onChartInitialized, option, onEvents }: EChartsProps<T>): JSX.Element;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=ECharts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ECharts.d.ts","sourceRoot":"","sources":["../src/ECharts.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAoC,MAAM,OAAO,CA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/debounce";import{init}from"echarts/core";import{Box}from"@mui/material";const mouseEvents=["click","dblclick","mousedown","mousemove","mouseup","mouseover","mouseout","globalout","contextmenu"],batchEvents=["datazoom","downplay","highlight"];export function ECharts({sx:e,_instance:t,onChartInitialized:n,option:o,onEvents:s}){const[i,u]=useState(null),[r,c]=useState(void 0);return useLayoutEffect((()=>{if(null===i)return;const e=init(i);return c(e),void 0!==t&&(t.current=e),bindEvents(e,s),null==n||n(e),()=>{e.dispose()}}),[i,t,n,s]),useLayoutEffect((()=>{void 0!==r&&r.setOption(o)}),[r,o]),useLayoutEffect((()=>{const e=debounce((()=>{null==r||r.resize()}),200);return window.addEventListener("resize",e),e(),()=>window.removeEventListener("resize",e)}),[r]),_jsx(Box,{ref:u,sx:e})}function bindEvents(e,t){var n;if(void 0!==t)for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)){const s=null!==(n=t[e])&&void 0!==n?n:null;s&&o(e,s)}function o(t,n){"function"==typeof n&&(isMouseEvent(t)?e.on(t,(t=>n(t,e))):isBatchEvent(t)?e.on(t,(e=>n(e))):e.on(t,(()=>n(null,e))))}}function isMouseEvent(e){return mouseEvents.includes(e)}function isBatchEvent(e){return batchEvents.includes(e)}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { GaugeSeriesOption } from 'echarts/charts';
|
|
3
|
+
import { UnitOptions } from './model/units';
|
|
4
|
+
export declare type GaugeChartData = number | null | undefined;
|
|
5
|
+
interface GaugeChartProps {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
data: GaugeChartData;
|
|
9
|
+
unit: UnitOptions;
|
|
10
|
+
axisLine: GaugeSeriesOption['axisLine'];
|
|
11
|
+
}
|
|
12
|
+
export declare function GaugeChart(props: GaugeChartProps): JSX.Element;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=GaugeChart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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{ECharts}from"./ECharts";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:s}=t,a=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:s,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,s]);return _jsx(ECharts,{sx:{width:e,height:o},option:a})}
|
|
@@ -0,0 +1,22 @@
|
|
|
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(props: LineChartProps): JSX.Element;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=LineChart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../src/LineChart.tsx"],"names":[],"mappings":";AAgBA,OAAO,KAAK,EAEV,mBAAmB,EACnB,qBAAqB,EAErB,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,KAAK,EAAE,cAAc,eAsL9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useMemo,useRef,useState}from"react";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{ECharts}from"./ECharts";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(e){const{height:t,data:o,grid:r,legend:a,toolbox:n,dataZoomEnabled:i,onDataZoom:s}=e,m=useTheme(),l=useRef(),[p,d]=useState(!0),h=useMemo((()=>({datazoom:e=>{var t,r;if(void 0===s||void 0===e.batch[0])return;const a=null!==(t=e.batch[0].startValue)&&void 0!==t?t:0,n=null!==(r=e.batch[0].endValue)&&void 0!==r?r:o.xAxis.length-1,i=o.xAxis[a],m=o.xAxis[n];void 0!==i&&void 0!==m&&s({start:i,end:m,startIndex:a,endIndex:n})}})),[o,s]);void 0!==l.current&&!0===i&&l.current.dispatchAction({type:"takeGlobalCursor",key:"dataZoomSelect",dataZoomSelectActive:!0});const u=useMemo((()=>{if(void 0===o.timeSeries)return{};if(null===o.timeSeries||0===o.timeSeries.length)return noDataOption;const e=o.timeSeries.length<PROGRESSIVE_MODE_SERIES_LIMIT,t={show:!0,backgroundColor:"dark"===m.palette.mode?m.palette.grey[100]:m.palette.background.paper,borderColor:m.palette.grey[300],top:10,right:20,bottom:0,left:20,containLabel:!0},s={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}}};return!1===i&&delete s.feature.dataZoom.icon,{title:{show:!1},grid:merge(t,r),toolbox:merge(s,n),series:o.timeSeries,xAxis:{type:"category",data:o.xAxis,axisLabel:{color:m.palette.text.primary,margin:12,formatter:e=>getFormattedDate(e)},axisTick:{show:!0,length:6},axisLine:{lineStyle:{color:m.palette.grey[600]}}},yAxis:{type:"value",boundaryGap:["10%","10%"],axisLabel:{showMinLabel:!1,showMaxLabel:!0,color:m.palette.text.primary,formatter:e=>abbreviateLargeNumber(e)},splitLine:{lineStyle:{color:m.palette.grey[300]}}},animation:!1,tooltip:{show:e,trigger:"axis",showContent:!1,axisPointer:{type:"none"}},legend:a}}),[o,m,r,a,n,i]);return _jsxs(Box,{sx:{height:t},onMouseDown:e=>{e.target instanceof HTMLCanvasElement&&d(!1)},onMouseUp:()=>{d(!0)},onMouseLeave:()=>{d(!1)},onMouseEnter:()=>{d(!0)},children:[!0===p&&_jsx(Tooltip,{chartRef:l,tooltipData:emptyTooltipData,chartData:o,wrapLabels:!0}),_jsx(ECharts,{sx:{width:"100%",height:"100%"},option:u,onEvents:h,_instance:l})]})}function getFormattedDate(e){return new Intl.DateTimeFormat(void 0,{hour:"numeric",minute:"numeric",hour12:!1}).format(1e3*e)}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LineSeriesOption } from 'echarts/charts';
|
|
3
|
+
import { UnitOptions } from './model/units';
|
|
4
|
+
import { GraphSeriesValueTuple } from './model/graph-model';
|
|
5
|
+
export interface GraphSeries {
|
|
6
|
+
name: string;
|
|
7
|
+
values: Iterable<GraphSeriesValueTuple>;
|
|
8
|
+
}
|
|
9
|
+
export interface StatChartData {
|
|
10
|
+
calculatedValue: number | null | undefined;
|
|
11
|
+
seriesData: GraphSeries | null | undefined;
|
|
12
|
+
name?: string;
|
|
13
|
+
}
|
|
14
|
+
interface StatChartProps {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
data: StatChartData;
|
|
18
|
+
unit: UnitOptions;
|
|
19
|
+
backgroundColor?: string;
|
|
20
|
+
sparkline?: LineSeriesOption;
|
|
21
|
+
}
|
|
22
|
+
export declare function StatChart(props: StatChartProps): JSX.Element;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=StatChart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatChart.d.ts","sourceRoot":"","sources":["../src/StatChart.tsx"],"names":[],"mappings":";AAkBA,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,eA8J9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useMemo}from"react";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{ECharts}from"./ECharts";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=useMemo((()=>{var t;if(void 0===a.seriesData)return{};if(null===a.seriesData||void 0===a.calculatedValue)return noDataOption;const s=a.seriesData,h=null!==(t=a.calculatedValue)&&void 0!==t?t:0,l=e>250,m=!0===l?a.name:"",p=Math.min(e,1.2*o),c=Math.min(p/4*.65,72),d=.5*c,u=[{type:"gauge",data:[{value:h,name:m}],detail:{show:!0,offsetCenter:["0%","-65%"],formatter:[`{name|${m}}`,`{value|${formatValue(h,r)}}`].join("\n"),rich:{name:{padding:!0===l?[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:[...s.values],zlevel:1,symbol:"none",animation:!1,lineStyle:{color:"#FFFFFF",opacity:.6},areaStyle:{color:"#FFFFFF",opacity:.3},silent:!0},e=merge(t,n);u.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:u,textStyle:{color:"transparent"===i?"#000000":"#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,r,e,n,i]);return _jsx(ECharts,{sx:{width:e,height:o},option:s})}
|
|
@@ -0,0 +1,103 @@
|
|
|
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.ECharts = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
// Copyright 2021 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 debounce_1 = __importDefault(require("lodash/debounce"));
|
|
22
|
+
const core_1 = require("echarts/core");
|
|
23
|
+
const material_1 = require("@mui/material");
|
|
24
|
+
const mouseEvents = [
|
|
25
|
+
'click',
|
|
26
|
+
'dblclick',
|
|
27
|
+
'mousedown',
|
|
28
|
+
'mousemove',
|
|
29
|
+
'mouseup',
|
|
30
|
+
'mouseover',
|
|
31
|
+
'mouseout',
|
|
32
|
+
'globalout',
|
|
33
|
+
'contextmenu',
|
|
34
|
+
];
|
|
35
|
+
const batchEvents = ['datazoom', 'downplay', 'highlight'];
|
|
36
|
+
function ECharts({ sx, _instance, onChartInitialized, option, onEvents }) {
|
|
37
|
+
const [containerRef, setContainerRef] = (0, react_1.useState)(null);
|
|
38
|
+
const [echart, setChart] = (0, react_1.useState)(undefined);
|
|
39
|
+
// Create a chart instance in the container
|
|
40
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
41
|
+
if (containerRef === null)
|
|
42
|
+
return;
|
|
43
|
+
const chart = (0, core_1.init)(containerRef);
|
|
44
|
+
setChart(chart);
|
|
45
|
+
if (_instance !== undefined) {
|
|
46
|
+
_instance.current = chart;
|
|
47
|
+
}
|
|
48
|
+
bindEvents(chart, onEvents);
|
|
49
|
+
onChartInitialized === null || onChartInitialized === void 0 ? void 0 : onChartInitialized(chart);
|
|
50
|
+
return () => {
|
|
51
|
+
chart.dispose();
|
|
52
|
+
};
|
|
53
|
+
}, [containerRef, _instance, onChartInitialized, onEvents]);
|
|
54
|
+
// Sync options with chart instance
|
|
55
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
56
|
+
if (echart === undefined)
|
|
57
|
+
return;
|
|
58
|
+
echart.setOption(option);
|
|
59
|
+
}, [echart, option]);
|
|
60
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
61
|
+
const updateSize = (0, debounce_1.default)(() => {
|
|
62
|
+
echart === null || echart === void 0 ? void 0 : echart.resize();
|
|
63
|
+
}, 200);
|
|
64
|
+
window.addEventListener('resize', updateSize);
|
|
65
|
+
updateSize();
|
|
66
|
+
return () => window.removeEventListener('resize', updateSize);
|
|
67
|
+
}, [echart]);
|
|
68
|
+
return (0, jsx_runtime_1.jsx)(material_1.Box, { ref: setContainerRef, sx: sx });
|
|
69
|
+
}
|
|
70
|
+
exports.ECharts = ECharts;
|
|
71
|
+
// Validate event config and bind custom events
|
|
72
|
+
function bindEvents(instance, events) {
|
|
73
|
+
var _a;
|
|
74
|
+
if (events === undefined)
|
|
75
|
+
return;
|
|
76
|
+
function bindEvent(eventName, onEventFunction) {
|
|
77
|
+
if (typeof onEventFunction === 'function') {
|
|
78
|
+
if (isMouseEvent(eventName)) {
|
|
79
|
+
instance.on(eventName, (param) => onEventFunction(param, instance));
|
|
80
|
+
}
|
|
81
|
+
else if (isBatchEvent(eventName)) {
|
|
82
|
+
instance.on(eventName, (param) => onEventFunction(param));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
instance.on(eventName, () => onEventFunction(null, instance));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
for (const eventName in events) {
|
|
90
|
+
if (Object.prototype.hasOwnProperty.call(events, eventName)) {
|
|
91
|
+
const customEvent = (_a = events[eventName]) !== null && _a !== void 0 ? _a : null;
|
|
92
|
+
if (customEvent) {
|
|
93
|
+
bindEvent(eventName, customEvent);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function isMouseEvent(eventName) {
|
|
99
|
+
return mouseEvents.includes(eventName);
|
|
100
|
+
}
|
|
101
|
+
function isBatchEvent(eventName) {
|
|
102
|
+
return batchEvents.includes(eventName);
|
|
103
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorAlert = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
// Copyright 2021 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 material_1 = require("@mui/material");
|
|
18
|
+
/**
|
|
19
|
+
* Shows an MUI Alert with the `Error.message` as its contents.
|
|
20
|
+
*/
|
|
21
|
+
function ErrorAlert(props) {
|
|
22
|
+
const { error } = props;
|
|
23
|
+
return (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", children: error.message });
|
|
24
|
+
}
|
|
25
|
+
exports.ErrorAlert = ErrorAlert;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ErrorBoundary = void 0;
|
|
16
|
+
// Just use react-error-boundary as-is for now
|
|
17
|
+
var react_error_boundary_1 = require("react-error-boundary");
|
|
18
|
+
Object.defineProperty(exports, "ErrorBoundary", { enumerable: true, get: function () { return react_error_boundary_1.ErrorBoundary; } });
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GaugeChart = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
// Copyright 2021 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 core_1 = require("echarts/core");
|
|
19
|
+
const charts_1 = require("echarts/charts");
|
|
20
|
+
const components_1 = require("echarts/components");
|
|
21
|
+
const renderers_1 = require("echarts/renderers");
|
|
22
|
+
const units_1 = require("./model/units");
|
|
23
|
+
const ECharts_1 = require("./ECharts");
|
|
24
|
+
(0, core_1.use)([charts_1.GaugeChart, components_1.GridComponent, components_1.TitleComponent, components_1.TooltipComponent, renderers_1.CanvasRenderer]);
|
|
25
|
+
const noDataOption = {
|
|
26
|
+
title: {
|
|
27
|
+
show: true,
|
|
28
|
+
textStyle: {
|
|
29
|
+
color: 'grey',
|
|
30
|
+
fontSize: 16,
|
|
31
|
+
fontWeight: 400,
|
|
32
|
+
},
|
|
33
|
+
text: 'No data',
|
|
34
|
+
left: 'center',
|
|
35
|
+
top: 'center',
|
|
36
|
+
},
|
|
37
|
+
xAxis: {
|
|
38
|
+
show: false,
|
|
39
|
+
},
|
|
40
|
+
yAxis: {
|
|
41
|
+
show: false,
|
|
42
|
+
},
|
|
43
|
+
series: [],
|
|
44
|
+
};
|
|
45
|
+
function GaugeChart(props) {
|
|
46
|
+
const { width, height, data, unit, axisLine } = props;
|
|
47
|
+
const option = (0, react_1.useMemo)(() => {
|
|
48
|
+
if (data === null || data === undefined)
|
|
49
|
+
return noDataOption;
|
|
50
|
+
const calculatedValue = data;
|
|
51
|
+
return {
|
|
52
|
+
title: {
|
|
53
|
+
show: false,
|
|
54
|
+
},
|
|
55
|
+
tooltip: {
|
|
56
|
+
show: false,
|
|
57
|
+
},
|
|
58
|
+
series: [
|
|
59
|
+
{
|
|
60
|
+
type: 'gauge',
|
|
61
|
+
center: ['50%', '65%'],
|
|
62
|
+
radius: '100%',
|
|
63
|
+
startAngle: 200,
|
|
64
|
+
endAngle: -20,
|
|
65
|
+
min: 0,
|
|
66
|
+
max: 100,
|
|
67
|
+
splitNumber: 12,
|
|
68
|
+
silent: true,
|
|
69
|
+
progress: {
|
|
70
|
+
show: true,
|
|
71
|
+
width: 22,
|
|
72
|
+
itemStyle: {
|
|
73
|
+
color: 'auto',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
pointer: {
|
|
77
|
+
show: false,
|
|
78
|
+
},
|
|
79
|
+
axisLine: {
|
|
80
|
+
lineStyle: {
|
|
81
|
+
color: [[1, '#e1e5e9']],
|
|
82
|
+
width: 22,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
axisTick: {
|
|
86
|
+
show: false,
|
|
87
|
+
distance: -28,
|
|
88
|
+
splitNumber: 5,
|
|
89
|
+
lineStyle: {
|
|
90
|
+
width: 2,
|
|
91
|
+
color: '#999',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
splitLine: {
|
|
95
|
+
show: false,
|
|
96
|
+
distance: -32,
|
|
97
|
+
length: 6,
|
|
98
|
+
lineStyle: {
|
|
99
|
+
width: 2,
|
|
100
|
+
color: '#999',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
axisLabel: {
|
|
104
|
+
show: false,
|
|
105
|
+
distance: -18,
|
|
106
|
+
color: '#999',
|
|
107
|
+
fontSize: 12,
|
|
108
|
+
},
|
|
109
|
+
anchor: {
|
|
110
|
+
show: false,
|
|
111
|
+
},
|
|
112
|
+
title: {
|
|
113
|
+
show: false,
|
|
114
|
+
},
|
|
115
|
+
detail: {
|
|
116
|
+
show: false,
|
|
117
|
+
},
|
|
118
|
+
data: [
|
|
119
|
+
{
|
|
120
|
+
value: calculatedValue,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
type: 'gauge',
|
|
126
|
+
center: ['50%', '65%'],
|
|
127
|
+
radius: '114%',
|
|
128
|
+
startAngle: 200,
|
|
129
|
+
endAngle: -20,
|
|
130
|
+
min: 0,
|
|
131
|
+
max: 100,
|
|
132
|
+
pointer: {
|
|
133
|
+
show: false,
|
|
134
|
+
itemStyle: {
|
|
135
|
+
color: 'auto',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
axisLine,
|
|
139
|
+
axisTick: {
|
|
140
|
+
show: false,
|
|
141
|
+
},
|
|
142
|
+
splitLine: {
|
|
143
|
+
show: false,
|
|
144
|
+
},
|
|
145
|
+
axisLabel: {
|
|
146
|
+
show: false,
|
|
147
|
+
},
|
|
148
|
+
detail: {
|
|
149
|
+
show: true,
|
|
150
|
+
valueAnimation: false,
|
|
151
|
+
width: '60%',
|
|
152
|
+
borderRadius: 8,
|
|
153
|
+
offsetCenter: [0, '-9%'],
|
|
154
|
+
fontSize: 20,
|
|
155
|
+
fontWeight: 'bolder',
|
|
156
|
+
color: 'inherit',
|
|
157
|
+
formatter: (value) => {
|
|
158
|
+
return (0, units_1.formatValue)(value, {
|
|
159
|
+
kind: unit.kind,
|
|
160
|
+
decimal_places: 0,
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
data: [
|
|
165
|
+
{
|
|
166
|
+
value: calculatedValue,
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
};
|
|
172
|
+
}, [data, unit, axisLine]);
|
|
173
|
+
return ((0, jsx_runtime_1.jsx)(ECharts_1.ECharts, { sx: {
|
|
174
|
+
width: width,
|
|
175
|
+
height: height,
|
|
176
|
+
}, option: option }));
|
|
177
|
+
}
|
|
178
|
+
exports.GaugeChart = GaugeChart;
|