@perses-dev/components 0.3.1 → 0.4.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.
@@ -49,11 +49,10 @@ export declare type OnEventsType<T> = {
49
49
  export interface EChartsProps<T> {
50
50
  option: EChartsCoreOption;
51
51
  sx?: SxProps<Theme>;
52
- onChartInitialized?: (instance: ECharts) => void;
53
52
  onEvents?: OnEventsType<T>;
54
53
  _instance?: React.MutableRefObject<ECharts | undefined>;
55
- parentContainer?: HTMLDivElement | null;
54
+ onChartInitialized?: (instance: ECharts) => void;
56
55
  }
57
- export declare function ECharts<T>({ sx, _instance, onChartInitialized, option, onEvents }: EChartsProps<T>): JSX.Element;
56
+ export declare const EChart: React.MemoExoticComponent<(<T>({ option, sx, onEvents, _instance, onChartInitialized, }: EChartsProps<T>) => JSX.Element)>;
58
57
  export {};
59
- //# sourceMappingURL=ECharts.d.ts.map
58
+ //# sourceMappingURL=EChart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EChart.d.ts","sourceRoot":"","sources":["../src/EChart.tsx"],"names":[],"mappings":"AAaA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAElE,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAQ,MAAM,cAAc,CAAC;AAChE,OAAO,EAAO,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAIpD,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,aAAK,eAAe,CAAC,CAAC,IAAI,CACxB,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAEhC,QAAQ,CAAC,EAAE,OAAO,KACf,IAAI,CAAC;AAEV,QAAA,MAAM,WAAW,0HAUP,CAAC;AAEX,oBAAY,cAAc,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAGxD,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,MAAM,CAAC;IAGnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IAGb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,yBAAyB;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IAEpB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,wBAAwB,EAAE,GAAG,yBAAyB,EAAE,CAAC;CACjE;AAED,aAAK,oBAAoB,GAAG,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;AAEpE,QAAA,MAAM,WAAW,gDAAiD,CAAC;AAEnE,oBAAY,cAAc,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAExD,aAAK,cAAc,GAAG,UAAU,CAAC;AAIjC,oBAAY,YAAY,CAAC,CAAC,IAAI;KAC3B,cAAc,IAAI,cAAc,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;CACxD,GAAG;KACD,cAAc,IAAI,cAAc,CAAC,CAAC,EAAE,oBAAoB;CAC1D,GAAG;KACD,SAAS,IAAI,cAAc,CAAC,CAAC,EAAE,MAAM,IAAI;CAC3C,CAAC;AAEF,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IACxD,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,MAAM,4HAgEjB,CAAC"}
package/dist/EChart.js ADDED
@@ -0,0 +1 @@
1
+ import{jsx as _jsx}from"react/jsx-runtime";import React,{useEffect,useLayoutEffect,useRef}from"react";import debounce from"lodash/debounce";import{init}from"echarts/core";import{Box}from"@mui/material";import{isEqual}from"lodash-es";const mouseEvents=["click","dblclick","mousedown","mousemove","mouseup","mouseover","mouseout","globalout","contextmenu"],batchEvents=["datazoom","downplay","highlight"];export const EChart=React.memo((function({option:e,sx:n,onEvents:t,_instance:r,onChartInitialized:o}){const u=useRef(e),s=useRef(e),c=useRef(null),i=useRef(null);return useLayoutEffect((()=>{if(null!==c.current&&null===i.current)return i.current=init(c.current),i.current.setOption(u.current,!0),null==o||o(i.current),void 0!==r&&(r.current=i.current),()=>{null!==i.current&&(i.current.dispose(),i.current=null)}}),[r,o]),useEffect((()=>{void 0===s.current||isEqual(s.current,e)||null!==i.current&&(i.current.setOption(e,!0),s.current=e)}),[e]),useLayoutEffect((()=>{const e=debounce((()=>{null!==i.current&&i.current.resize()}),200);return window.addEventListener("resize",e),e(),()=>{window.removeEventListener("resize",e)}}),[]),useEffect((()=>{const e=i.current;if(null!==e&&void 0!==t)return bindEvents(e,t),()=>{if(void 0!==e&&!0!==e.isDisposed())for(const n in t)e.off(n)}}),[t]),_jsx(Box,{ref:c,sx:n})}));function bindEvents(e,n){var t;if(void 0!==n)for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const o=null!==(t=n[e])&&void 0!==t?t:null;o&&r(e,o)}function r(n,t){"function"==typeof t&&(isMouseEvent(n)?e.on(n,(n=>t(n,e))):isBatchEvent(n)?e.on(n,(e=>t(e))):e.on(n,(()=>t(null,e))))}}function isMouseEvent(e){return mouseEvents.includes(e)}function isBatchEvent(e){return batchEvents.includes(e)}
@@ -1 +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})}
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})}
@@ -17,6 +17,6 @@ interface LineChartProps {
17
17
  dataZoomEnabled?: boolean;
18
18
  onDataZoom?: (e: ZoomEventData) => void;
19
19
  }
20
- export declare function LineChart(props: LineChartProps): JSX.Element;
20
+ export declare function LineChart({ height, data, grid, legend, toolbox, visualMap, dataZoomEnabled, onDataZoom, }: LineChartProps): JSX.Element;
21
21
  export {};
22
22
  //# sourceMappingURL=LineChart.d.ts.map
@@ -1 +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"}
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 CHANGED
@@ -1 +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)}
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 +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"}
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 CHANGED
@@ -1 +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})}
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})}
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.EChart = void 0;
30
+ const jsx_runtime_1 = require("react/jsx-runtime");
31
+ // Copyright 2022 The Perses Authors
32
+ // Licensed under the Apache License, Version 2.0 (the "License");
33
+ // you may not use this file except in compliance with the License.
34
+ // You may obtain a copy of the License at
35
+ //
36
+ // http://www.apache.org/licenses/LICENSE-2.0
37
+ //
38
+ // Unless required by applicable law or agreed to in writing, software
39
+ // distributed under the License is distributed on an "AS IS" BASIS,
40
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41
+ // See the License for the specific language governing permissions and
42
+ // limitations under the License.
43
+ const react_1 = __importStar(require("react"));
44
+ const debounce_1 = __importDefault(require("lodash/debounce"));
45
+ const core_1 = require("echarts/core");
46
+ const material_1 = require("@mui/material");
47
+ const lodash_es_1 = require("lodash-es");
48
+ const mouseEvents = [
49
+ 'click',
50
+ 'dblclick',
51
+ 'mousedown',
52
+ 'mousemove',
53
+ 'mouseup',
54
+ 'mouseover',
55
+ 'mouseout',
56
+ 'globalout',
57
+ 'contextmenu',
58
+ ];
59
+ const batchEvents = ['datazoom', 'downplay', 'highlight'];
60
+ exports.EChart = react_1.default.memo(function EChart({ option, sx, onEvents, _instance, onChartInitialized, }) {
61
+ const initialOption = (0, react_1.useRef)(option);
62
+ const prevOption = (0, react_1.useRef)(option);
63
+ const containerRef = (0, react_1.useRef)(null);
64
+ const chartElement = (0, react_1.useRef)(null);
65
+ // Initialize chart, dispose on unmount
66
+ (0, react_1.useLayoutEffect)(() => {
67
+ if (containerRef.current === null || chartElement.current !== null)
68
+ return;
69
+ chartElement.current = (0, core_1.init)(containerRef.current);
70
+ chartElement.current.setOption(initialOption.current, true);
71
+ onChartInitialized === null || onChartInitialized === void 0 ? void 0 : onChartInitialized(chartElement.current);
72
+ if (_instance !== undefined) {
73
+ _instance.current = chartElement.current;
74
+ }
75
+ return () => {
76
+ if (chartElement.current === null)
77
+ return;
78
+ chartElement.current.dispose();
79
+ chartElement.current = null;
80
+ };
81
+ }, [_instance, onChartInitialized]);
82
+ // Update chart data when option changes
83
+ (0, react_1.useEffect)(() => {
84
+ if (prevOption.current === undefined || (0, lodash_es_1.isEqual)(prevOption.current, option))
85
+ return;
86
+ if (chartElement.current === null)
87
+ return;
88
+ chartElement.current.setOption(option, true);
89
+ prevOption.current = option;
90
+ }, [option]);
91
+ // Resize chart, cleanup listener on unmount
92
+ (0, react_1.useLayoutEffect)(() => {
93
+ const updateSize = (0, debounce_1.default)(() => {
94
+ if (chartElement.current === null)
95
+ return;
96
+ chartElement.current.resize();
97
+ }, 200);
98
+ window.addEventListener('resize', updateSize);
99
+ updateSize();
100
+ return () => {
101
+ window.removeEventListener('resize', updateSize);
102
+ };
103
+ }, []);
104
+ // Bind and unbind chart events passed as prop
105
+ (0, react_1.useEffect)(() => {
106
+ const chart = chartElement.current;
107
+ if (chart === null || onEvents === undefined)
108
+ return;
109
+ bindEvents(chart, onEvents);
110
+ return () => {
111
+ if (chart === undefined)
112
+ return;
113
+ if (chart.isDisposed() === true)
114
+ return;
115
+ for (const event in onEvents) {
116
+ chart.off(event);
117
+ }
118
+ };
119
+ }, [onEvents]);
120
+ return (0, jsx_runtime_1.jsx)(material_1.Box, { ref: containerRef, sx: sx });
121
+ });
122
+ // Validate event config and bind custom events
123
+ function bindEvents(instance, events) {
124
+ var _a;
125
+ if (events === undefined)
126
+ return;
127
+ function bindEvent(eventName, OnEventFunction) {
128
+ if (typeof OnEventFunction === 'function') {
129
+ if (isMouseEvent(eventName)) {
130
+ instance.on(eventName, (params) => OnEventFunction(params, instance));
131
+ }
132
+ else if (isBatchEvent(eventName)) {
133
+ instance.on(eventName, (params) => OnEventFunction(params));
134
+ }
135
+ else {
136
+ instance.on(eventName, () => OnEventFunction(null, instance));
137
+ }
138
+ }
139
+ }
140
+ for (const eventName in events) {
141
+ if (Object.prototype.hasOwnProperty.call(events, eventName)) {
142
+ const customEvent = (_a = events[eventName]) !== null && _a !== void 0 ? _a : null;
143
+ if (customEvent) {
144
+ bindEvent(eventName, customEvent);
145
+ }
146
+ }
147
+ }
148
+ }
149
+ function isMouseEvent(eventName) {
150
+ return mouseEvents.includes(eventName);
151
+ }
152
+ function isBatchEvent(eventName) {
153
+ return batchEvents.includes(eventName);
154
+ }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GaugeChart = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- // Copyright 2021 The Perses Authors
5
+ // Copyright 2022 The Perses Authors
6
6
  // Licensed under the Apache License, Version 2.0 (the "License");
7
7
  // you may not use this file except in compliance with the License.
8
8
  // You may obtain a copy of the License at
@@ -20,7 +20,7 @@ const charts_1 = require("echarts/charts");
20
20
  const components_1 = require("echarts/components");
21
21
  const renderers_1 = require("echarts/renderers");
22
22
  const units_1 = require("./model/units");
23
- const ECharts_1 = require("./ECharts");
23
+ const EChart_1 = require("./EChart");
24
24
  (0, core_1.use)([charts_1.GaugeChart, components_1.GridComponent, components_1.TitleComponent, components_1.TooltipComponent, renderers_1.CanvasRenderer]);
25
25
  const noDataOption = {
26
26
  title: {
@@ -170,7 +170,7 @@ function GaugeChart(props) {
170
170
  ],
171
171
  };
172
172
  }, [data, unit, axisLine]);
173
- return ((0, jsx_runtime_1.jsx)(ECharts_1.ECharts, { sx: {
173
+ return ((0, jsx_runtime_1.jsx)(EChart_1.EChart, { sx: {
174
174
  width: width,
175
175
  height: height,
176
176
  }, option: option }));
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LineChart = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
- // Copyright 2021 The Perses Authors
8
+ // Copyright 2022 The Perses Authors
9
9
  // Licensed under the Apache License, Version 2.0 (the "License");
10
10
  // you may not use this file except in compliance with the License.
11
11
  // You may obtain a copy of the License at
@@ -18,18 +18,19 @@ const jsx_runtime_1 = require("react/jsx-runtime");
18
18
  // See the License for the specific language governing permissions and
19
19
  // limitations under the License.
20
20
  const react_1 = require("react");
21
+ const core_1 = require("@perses-dev/core");
21
22
  const material_1 = require("@mui/material");
22
23
  const merge_1 = __importDefault(require("lodash/merge"));
23
- const core_1 = require("echarts/core");
24
+ const core_2 = require("echarts/core");
24
25
  const charts_1 = require("echarts/charts");
25
26
  const components_1 = require("echarts/components");
26
27
  const renderers_1 = require("echarts/renderers");
27
- const ECharts_1 = require("./ECharts");
28
+ const EChart_1 = require("./EChart");
28
29
  const graph_model_1 = require("./model/graph-model");
29
30
  const units_1 = require("./model/units");
30
31
  const tooltip_model_1 = require("./tooltip/tooltip-model");
31
32
  const Tooltip_1 = require("./tooltip/Tooltip");
32
- (0, core_1.use)([
33
+ (0, core_2.use)([
33
34
  charts_1.LineChart,
34
35
  components_1.GridComponent,
35
36
  components_1.DataZoomComponent,
@@ -63,8 +64,7 @@ const noDataOption = {
63
64
  },
64
65
  series: [],
65
66
  };
66
- function LineChart(props) {
67
- const { height, data, grid, legend, toolbox, dataZoomEnabled, onDataZoom } = props;
67
+ function LineChart({ height, data, grid, legend, toolbox, visualMap, dataZoomEnabled, onDataZoom, }) {
68
68
  const theme = (0, material_1.useTheme)();
69
69
  const chartRef = (0, react_1.useRef)();
70
70
  const [showTooltip, setShowTooltip] = (0, react_1.useState)(true);
@@ -113,19 +113,17 @@ function LineChart(props) {
113
113
  const handleOnMouseLeave = () => {
114
114
  setShowTooltip(false);
115
115
  };
116
- const option = (0, react_1.useMemo)(() => {
116
+ const option = (0, core_1.useDeepMemo)(() => {
117
+ var _a;
117
118
  if (data.timeSeries === undefined)
118
119
  return {};
119
120
  if (data.timeSeries === null || data.timeSeries.length === 0)
120
121
  return noDataOption;
121
122
  const showPointsOnHover = data.timeSeries.length < graph_model_1.PROGRESSIVE_MODE_SERIES_LIMIT;
122
123
  const defaultGrid = {
123
- show: true,
124
- backgroundColor: theme.palette.mode === 'dark' ? theme.palette.grey[100] : theme.palette.background.paper,
125
- borderColor: theme.palette.grey['300'],
126
124
  top: 10,
127
125
  right: 20,
128
- bottom: 0,
126
+ bottom: 5,
129
127
  left: 20,
130
128
  containLabel: true,
131
129
  };
@@ -152,6 +150,7 @@ function LineChart(props) {
152
150
  if (dataZoomEnabled === false) {
153
151
  delete defaultToolbox.feature.dataZoom.icon;
154
152
  }
153
+ const rangeMs = (_a = data.rangeMs) !== null && _a !== void 0 ? _a : getDateRange(data.xAxis);
155
154
  const option = {
156
155
  title: {
157
156
  show: false,
@@ -162,16 +161,16 @@ function LineChart(props) {
162
161
  xAxis: {
163
162
  type: 'category',
164
163
  data: data.xAxis,
164
+ max: data.xAxisMax,
165
165
  axisLabel: {
166
+ margin: 15,
166
167
  color: theme.palette.text.primary,
167
- margin: 12,
168
168
  formatter: (value) => {
169
- return getFormattedDate(value);
169
+ return getFormattedDate(value, rangeMs);
170
170
  },
171
171
  },
172
172
  axisTick: {
173
- show: true,
174
- length: 6,
173
+ show: false,
175
174
  },
176
175
  axisLine: {
177
176
  lineStyle: {
@@ -181,18 +180,20 @@ function LineChart(props) {
181
180
  },
182
181
  yAxis: {
183
182
  type: 'value',
184
- boundaryGap: ['10%', '10%'],
183
+ boundaryGap: [0, '10%'],
185
184
  axisLabel: {
186
- showMinLabel: false,
187
- showMaxLabel: true,
185
+ margin: 12,
188
186
  color: theme.palette.text.primary,
189
187
  formatter: (value) => {
190
188
  return (0, units_1.abbreviateLargeNumber)(value);
191
189
  },
192
190
  },
193
191
  splitLine: {
192
+ show: true,
194
193
  lineStyle: {
194
+ width: 0.5,
195
195
  color: theme.palette.grey['300'],
196
+ opacity: 0.95,
196
197
  },
197
198
  },
198
199
  },
@@ -206,22 +207,46 @@ function LineChart(props) {
206
207
  },
207
208
  },
208
209
  legend,
210
+ visualMap,
209
211
  };
210
212
  return option;
211
- }, [data, theme, grid, legend, toolbox, dataZoomEnabled]);
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]);
212
215
  return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
213
216
  height,
214
- }, 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)(ECharts_1.ECharts, { sx: {
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: {
215
218
  width: '100%',
216
219
  height: '100%',
217
220
  }, option: option, onEvents: handleEvents, _instance: chartRef })] }));
218
221
  }
219
222
  exports.LineChart = LineChart;
220
- function getFormattedDate(value) {
221
- const XAXIS_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
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 = {
222
236
  hour: 'numeric',
223
237
  minute: 'numeric',
224
- hour12: false,
225
- });
226
- return XAXIS_DATE_FORMAT.format(value * 1000);
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, ' ');
227
252
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StatChart = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- // Copyright 2021 The Perses Authors
5
+ // Copyright 2022 The Perses Authors
6
6
  // Licensed under the Apache License, Version 2.0 (the "License");
7
7
  // you may not use this file except in compliance with the License.
8
8
  // You may obtain a copy of the License at
@@ -15,6 +15,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
15
15
  // See the License for the specific language governing permissions and
16
16
  // limitations under the License.
17
17
  const react_1 = require("react");
18
+ const material_1 = require("@mui/material");
18
19
  const lodash_es_1 = require("lodash-es");
19
20
  const core_1 = require("echarts/core");
20
21
  const charts_1 = require("echarts/charts");
@@ -22,7 +23,7 @@ const charts_2 = require("echarts/charts");
22
23
  const components_1 = require("echarts/components");
23
24
  const renderers_1 = require("echarts/renderers");
24
25
  const units_1 = require("./model/units");
25
- const ECharts_1 = require("./ECharts");
26
+ const EChart_1 = require("./EChart");
26
27
  (0, core_1.use)([
27
28
  charts_1.GaugeChart,
28
29
  charts_2.LineChart,
@@ -54,6 +55,7 @@ const noDataOption = {
54
55
  };
55
56
  function StatChart(props) {
56
57
  const { width, height, data, unit, backgroundColor, sparkline } = props;
58
+ const theme = (0, material_1.useTheme)();
57
59
  const option = (0, react_1.useMemo)(() => {
58
60
  var _a;
59
61
  if (data.seriesData === undefined)
@@ -165,7 +167,7 @@ function StatChart(props) {
165
167
  },
166
168
  series: statSeries,
167
169
  textStyle: {
168
- color: backgroundColor === 'transparent' ? '#000000' : '#FFFFFF',
170
+ color: backgroundColor === 'transparent' ? theme.palette.text.primary : '#FFFFFF',
169
171
  fontSize: 25,
170
172
  lineHeight: 18,
171
173
  fontFamily: '"Lato", sans-serif',
@@ -196,8 +198,8 @@ function StatChart(props) {
196
198
  ],
197
199
  };
198
200
  return option;
199
- }, [data, height, unit, width, sparkline, backgroundColor]);
200
- return ((0, jsx_runtime_1.jsx)(ECharts_1.ECharts, { sx: {
201
+ }, [data, height, theme, unit, width, sparkline, backgroundColor]);
202
+ return ((0, jsx_runtime_1.jsx)(EChart_1.EChart, { sx: {
201
203
  width: width,
202
204
  height: height,
203
205
  }, option: option }));
package/dist/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021 The Perses Authors
2
+ // Copyright 2022 The Perses Authors
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
5
5
  // You may obtain a copy of the License at
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- __exportStar(require("./ECharts"), exports);
29
+ __exportStar(require("./EChart"), exports);
30
30
  __exportStar(require("./ErrorAlert"), exports);
31
31
  __exportStar(require("./ErrorBoundary"), exports);
32
32
  __exportStar(require("./GaugeChart"), exports);
@@ -42,7 +42,8 @@ function SeriesInfo(props) {
42
42
  }), children: formattedSeriesLabels.split(',').map((name) => {
43
43
  if (name) {
44
44
  const [key, value] = jsonFormattedSeries ? name.split(':') : name.split('=');
45
- return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: 'flex', gap: '4px' }, children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { sx: { fontSize: '11px' }, children: [key, ":"] }), (0, jsx_runtime_1.jsx)(material_1.Typography, { sx: (theme) => ({
45
+ const formattedKey = value !== undefined ? `${key}: ` : key;
46
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: 'flex', gap: '4px' }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { sx: { fontSize: '11px' }, children: formattedKey }), (0, jsx_runtime_1.jsx)(material_1.Typography, { sx: (theme) => ({
46
47
  color: theme.palette.common.white,
47
48
  fontWeight: 700,
48
49
  fontSize: '11px',
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Tooltip = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- // Copyright 2021 The Perses Authors
5
+ // Copyright 2022 The Perses Authors
6
6
  // Licensed under the Apache License, Version 2.0 (the "License");
7
7
  // you may not use this file except in compliance with the License.
8
8
  // You may obtain a copy of the License at
@@ -50,8 +50,7 @@ function Tooltip(props) {
50
50
  position: 'absolute',
51
51
  top: 0,
52
52
  left: 0,
53
- overflowY: 'scroll',
54
- backgroundColor: '#000',
53
+ backgroundColor: '#2E313E',
55
54
  borderRadius: '6px',
56
55
  color: '#fff',
57
56
  fontSize: '11px',
@@ -59,6 +58,10 @@ function Tooltip(props) {
59
58
  opacity: 1,
60
59
  transition: 'all 0.1s ease-out',
61
60
  zIndex: theme.zIndex.tooltip,
61
+ overflow: 'hidden',
62
+ '&:hover': {
63
+ overflowY: 'auto',
64
+ },
62
65
  }), style: {
63
66
  transform: cursorTransform,
64
67
  }, onMouseEnter: () => handleMouseEnter(), onMouseLeave: () => handleMouseLeave(), children: (0, jsx_runtime_1.jsx)(TooltipContent_1.TooltipContent, { focusedSeries: focusedSeries, wrapLabels: props.wrapLabels }) }) }));
@@ -40,7 +40,9 @@ function getNearbySeries(data, pointInGrid, yBuffer) {
40
40
  const yValue = (_e = currentSeries.data[datumIdx]) !== null && _e !== void 0 ? _e : 0;
41
41
  if (focusedX === datumIdx) {
42
42
  if (yValue !== '-' && focusedY <= yValue + yBuffer && focusedY >= yValue - yBuffer) {
43
- const formattedDate = tooltip_model_1.TOOLTIP_DATE_FORMAT.format(xValue * 1000);
43
+ // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
44
+ const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
45
+ const formattedDate = tooltip_model_1.TOOLTIP_DATE_FORMAT.format(xValueMilliSeconds);
44
46
  currentFocusedData.push({
45
47
  seriesIdx: seriesIdx,
46
48
  datumIdx: datumIdx,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './ECharts';
1
+ export * from './EChart';
2
2
  export * from './ErrorAlert';
3
3
  export * from './ErrorBoundary';
4
4
  export * from './GaugeChart';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export*from"./ECharts";export*from"./ErrorAlert";export*from"./ErrorBoundary";export*from"./GaugeChart";export*from"./LineChart";export*from"./StatChart";export*from"./utils/combine-sx";export*from"./model/graph-model";export*from"./model/units";
1
+ export*from"./EChart";export*from"./ErrorAlert";export*from"./ErrorBoundary";export*from"./GaugeChart";export*from"./LineChart";export*from"./StatChart";export*from"./utils/combine-sx";export*from"./model/graph-model";export*from"./model/units";
@@ -9,5 +9,7 @@ export interface EChartsTimeSeries extends Omit<LineSeriesOption, 'data'> {
9
9
  export declare type EChartsDataFormat = {
10
10
  timeSeries: EChartsTimeSeries[];
11
11
  xAxis: number[];
12
+ xAxisMax?: number | 'dataMax';
13
+ rangeMs?: number;
12
14
  };
13
15
  //# sourceMappingURL=graph-model.d.ts.map
@@ -1 +1 @@
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"}
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 +1 @@
1
- {"version":3,"file":"SeriesInfo.d.ts","sourceRoot":"","sources":["../../src/tooltip/SeriesInfo.tsx"],"names":[],"mappings":";AAiBA,UAAU,eAAe;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eAiHhD"}
1
+ {"version":3,"file":"SeriesInfo.d.ts","sourceRoot":"","sources":["../../src/tooltip/SeriesInfo.tsx"],"names":[],"mappings":";AAiBA,UAAU,eAAe;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eAkHhD"}
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Box,Divider,Stack,Typography}from"@mui/material";import{SeriesMarker}from"./SeriesMarker";import{TOOLTIP_LABELS_MAX_WIDTH}from"./tooltip-model";export function SeriesInfo(e){const{seriesName:o,y:r,markerColor:t,totalSeries:i,wrapLabels:s}=e,l=o.replace(/[{}"]/g,"");if(1===i){const e="{"===o[0];return _jsxs(Stack,{spacing:.5,children:[_jsxs(Box,{sx:e=>({height:"16px",display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"left",color:e.palette.common.white,fontSize:"11px"}),children:[_jsx(SeriesMarker,{markerColor:t}),_jsxs(Box,{component:"span",children:["value:",_jsx(Box,{component:"span",sx:e=>({color:e.palette.common.white,fontWeight:700,paddingLeft:"2px"}),children:r})]})]}),_jsx(Divider,{sx:e=>({borderColor:e.palette.grey[500]})}),_jsx(Box,{sx:e=>({color:e.palette.common.white}),children:l.split(",").map((o=>{if(o){const[r,t]=e?o.split(":"):o.split("=");return _jsxs(Box,{sx:{display:"flex",gap:"4px"},children:[_jsxs(Typography,{sx:{fontSize:"11px"},children:[r,":"]}),_jsx(Typography,{sx:e=>({color:e.palette.common.white,fontWeight:700,fontSize:"11px"}),children:t})]},o)}}))})]})}const n=l.replace(/[,]/g,", ").replace(/[:=]/g,": ");return _jsxs(Box,{sx:{display:"table-row",paddingTop:.5},children:[_jsxs(Box,{sx:{display:"table-cell",maxWidth:"520px"},children:[_jsx(SeriesMarker,{markerColor:t}),_jsx(Box,{component:"span",sx:e=>({color:e.palette.common.white,display:"inline-block",maxWidth:TOOLTIP_LABELS_MAX_WIDTH,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:s?"normal":"nowrap",width:"calc(100% - 20px)"}),children:n})]}),_jsx(Box,{sx:{display:"table-cell",fontWeight:"700",paddingLeft:1.5,textAlign:"right",verticalAlign:"top"},children:r})]})}
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Box,Divider,Stack,Typography}from"@mui/material";import{SeriesMarker}from"./SeriesMarker";import{TOOLTIP_LABELS_MAX_WIDTH}from"./tooltip-model";export function SeriesInfo(e){const{seriesName:o,y:r,markerColor:t,totalSeries:i,wrapLabels:s}=e,l=o.replace(/[{}"]/g,"");if(1===i){const e="{"===o[0];return _jsxs(Stack,{spacing:.5,children:[_jsxs(Box,{sx:e=>({height:"16px",display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"left",color:e.palette.common.white,fontSize:"11px"}),children:[_jsx(SeriesMarker,{markerColor:t}),_jsxs(Box,{component:"span",children:["value:",_jsx(Box,{component:"span",sx:e=>({color:e.palette.common.white,fontWeight:700,paddingLeft:"2px"}),children:r})]})]}),_jsx(Divider,{sx:e=>({borderColor:e.palette.grey[500]})}),_jsx(Box,{sx:e=>({color:e.palette.common.white}),children:l.split(",").map((o=>{if(o){const[r,t]=e?o.split(":"):o.split("=");return _jsxs(Box,{sx:{display:"flex",gap:"4px"},children:[_jsx(Typography,{sx:{fontSize:"11px"},children:void 0!==t?`${r}: `:r}),_jsx(Typography,{sx:e=>({color:e.palette.common.white,fontWeight:700,fontSize:"11px"}),children:t})]},o)}}))})]})}const n=l.replace(/[,]/g,", ").replace(/[:=]/g,": ");return _jsxs(Box,{sx:{display:"table-row",paddingTop:.5},children:[_jsxs(Box,{sx:{display:"table-cell",maxWidth:"520px"},children:[_jsx(SeriesMarker,{markerColor:t}),_jsx(Box,{component:"span",sx:e=>({color:e.palette.common.white,display:"inline-block",maxWidth:TOOLTIP_LABELS_MAX_WIDTH,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:s?"normal":"nowrap",width:"calc(100% - 20px)"}),children:n})]}),_jsx(Box,{sx:{display:"table-cell",fontWeight:"700",paddingLeft:1.5,textAlign:"right",verticalAlign:"top"},children:r})]})}
@@ -1 +1 @@
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,sBAyD1C"}
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 +1 @@
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:l}=t,[n,i]=useState(null),s=useMousePosition();if(null===s)return null;const a=r.current,u=getFocusedSeriesData(s,l,n,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,m=assembleTransform(s,u.length,p,T,n);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,overflowY:"scroll",backgroundColor:"#000",borderRadius:"6px",color:"#fff",fontSize:"11px",visibility:"visible",opacity:1,transition:"all 0.1s ease-out",zIndex:t.zIndex.tooltip}),style:{transform:m},onMouseEnter:()=>{null!==s&&i(s)},onMouseLeave:()=>{null!==n&&i(null)},children:_jsx(TooltipContent,{focusedSeries:u,wrapLabels:t.wrapLabels})})})}function assembleTransform(t,o,e,r,l){if(null===t)return"translate3d(0, 0)";null!==l&&(t=l);const n=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&&n>TOOLTIP_MAX_WIDTH?`translate3d(${n-32}px, ${i}px, 0) translateX(-100%)`:`translate3d(${n+32}px, ${i}px, 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 +1 @@
1
- {"version":3,"file":"focused-series.d.ts","sourceRoot":"","sources":["../../src/tooltip/focused-series.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,UAAU,EAA0C,MAAM,iBAAiB,CAAC;AAErF,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,oBAAY,kBAAkB,GAAG,iBAAiB,EAAE,CAAC;AAErD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAwCnH;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,SAAS,EAAE,iBAAiB,EAC5B,SAAS,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC/B,KAAK,CAAC,EAAE,eAAe,sBA2CxB"}
1
+ {"version":3,"file":"focused-series.d.ts","sourceRoot":"","sources":["../../src/tooltip/focused-series.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,UAAU,EAA0C,MAAM,iBAAiB,CAAC;AAErF,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,oBAAY,kBAAkB,GAAG,iBAAiB,EAAE,CAAC;AAErD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,kBAAkB,CA0CnH;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,SAAS,EAAE,iBAAiB,EAC5B,SAAS,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC/B,KAAK,CAAC,EAAE,eAAe,sBA2CxB"}
@@ -1 +1 @@
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=TOOLTIP_DATE_FORMAT.format(1e3*f);s.push({seriesIdx:t,datumIdx:l,seriesName:n,date:e,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[]}
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[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/components",
3
- "version": "0.3.1",
3
+ "version": "0.4.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",
@@ -23,6 +23,7 @@
23
23
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
24
24
  },
25
25
  "dependencies": {
26
+ "@perses-dev/core": "^0.4.2",
26
27
  "echarts": "^5.3.2",
27
28
  "lodash-es": "^4.17.21",
28
29
  "react-error-boundary": "^3.1.4"
@@ -1 +0,0 @@
1
- {"version":3,"file":"ECharts.d.ts","sourceRoot":"","sources":["../src/ECharts.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAQ,MAAM,cAAc,CAAC;AAChE,OAAO,EAAO,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,WAAW,qBAAqB,CAAC,CAAC;IAGtC,aAAa,EAAE,MAAM,CAAC;IAGtB,UAAU,EAAE,MAAM,CAAC;IAEnB,WAAW,EAAE,MAAM,CAAC;IAEpB,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,EAAE,MAAM,CAAC;IAEb,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAOlC,QAAQ,EAAE,MAAM,CAAC;IAEjB,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAEzB,KAAK,EAAE,MAAM,CAAC;IAId,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,aAAK,eAAe,CAAC,CAAC,IAAI,CACxB,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAGhC,QAAQ,CAAC,EAAE,OAAO,KACf,IAAI,CAAC;AAEV,QAAA,MAAM,WAAW,0HAUP,CAAC;AAEX,oBAAY,cAAc,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAGxD,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,MAAM,CAAC;IAGnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IAGb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,yBAAyB;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IAEpB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,wBAAwB,EAAE,GAAG,yBAAyB,EAAE,CAAC;CACjE;AAED,aAAK,oBAAoB,GAAG,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;AAEpE,QAAA,MAAM,WAAW,gDAAiD,CAAC;AAEnE,oBAAY,cAAc,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAGxD,aAAK,cAAc,GAAG,UAAU,CAAC;AAIjC,oBAAY,YAAY,CAAC,CAAC,IAAI;KAC3B,cAAc,IAAI,cAAc,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;CACxD,GAAG;KACD,cAAc,IAAI,cAAc,CAAC,CAAC,EAAE,oBAAoB;CAC1D,GAAG;KACD,SAAS,IAAI,cAAc,CAAC,CAAC,EAAE,MAAM,IAAI;CAC3C,CAAC;AAEF,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IACxD,eAAe,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CACzC;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC,eAqClG"}
package/dist/ECharts.js DELETED
@@ -1 +0,0 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useState,useLayoutEffect}from"react";import debounce from"lodash/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)}
@@ -1,103 +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.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
- }