@perses-dev/components 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/Drawer/Drawer.d.ts +10 -0
  2. package/dist/Drawer/Drawer.d.ts.map +1 -0
  3. package/dist/Drawer/Drawer.js +1 -0
  4. package/dist/Drawer/index.d.ts +2 -0
  5. package/dist/Drawer/index.d.ts.map +1 -0
  6. package/dist/Drawer/index.js +1 -0
  7. package/dist/EChart.d.ts.map +1 -1
  8. package/dist/EChart.js +1 -1
  9. package/dist/LineChart/LineChart.d.ts.map +1 -1
  10. package/dist/LineChart/LineChart.js +1 -1
  11. package/dist/TimeRangeSelector/AbsoluteTimePicker.d.ts +9 -0
  12. package/dist/TimeRangeSelector/AbsoluteTimePicker.d.ts.map +1 -0
  13. package/dist/TimeRangeSelector/AbsoluteTimePicker.js +1 -0
  14. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts +17 -0
  15. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +1 -0
  16. package/dist/TimeRangeSelector/TimeRangeSelector.js +1 -0
  17. package/dist/TimeRangeSelector/index.d.ts +3 -0
  18. package/dist/TimeRangeSelector/index.d.ts.map +1 -0
  19. package/dist/TimeRangeSelector/index.js +1 -0
  20. package/dist/TimeRangeSelector/utils.d.ts +7 -0
  21. package/dist/TimeRangeSelector/utils.d.ts.map +1 -0
  22. package/dist/TimeRangeSelector/utils.js +1 -0
  23. package/dist/Tooltip/Tooltip.d.ts +3 -4
  24. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  25. package/dist/Tooltip/Tooltip.js +1 -1
  26. package/dist/Tooltip/focused-series.js +1 -1
  27. package/dist/Tooltip/utils.d.ts +6 -0
  28. package/dist/Tooltip/utils.d.ts.map +1 -0
  29. package/dist/Tooltip/utils.js +1 -0
  30. package/dist/cjs/Drawer/Drawer.js +28 -0
  31. package/dist/cjs/Drawer/index.js +29 -0
  32. package/dist/cjs/EChart.js +8 -0
  33. package/dist/cjs/LineChart/LineChart.js +13 -4
  34. package/dist/cjs/TimeRangeSelector/AbsoluteTimePicker.js +101 -0
  35. package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +30 -0
  36. package/dist/cjs/TimeRangeSelector/index.js +30 -0
  37. package/dist/cjs/TimeRangeSelector/utils.js +41 -0
  38. package/dist/cjs/Tooltip/Tooltip.js +36 -50
  39. package/dist/cjs/Tooltip/focused-series.js +1 -1
  40. package/dist/cjs/Tooltip/utils.js +53 -0
  41. package/dist/cjs/index.js +2 -0
  42. package/dist/cjs/model/units.js +3 -1
  43. package/dist/index.d.ts +2 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +1 -1
  46. package/dist/model/units.js +1 -1
  47. package/package.json +6 -3
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ interface DrawerProps {
3
+ isOpen: boolean;
4
+ onClose: () => void;
5
+ anchor?: 'left' | 'right';
6
+ children?: React.ReactNode;
7
+ }
8
+ export declare const Drawer: ({ anchor, isOpen, onClose, children }: DrawerProps) => JSX.Element;
9
+ export {};
10
+ //# sourceMappingURL=Drawer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Drawer.d.ts","sourceRoot":"","sources":["../../src/Drawer/Drawer.tsx"],"names":[],"mappings":";AAeA,UAAU,WAAW;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAID,eAAO,MAAM,MAAM,0CAAqD,WAAW,gBAiBlF,CAAC"}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{Drawer as MuiDrawer}from"@mui/material";const DRAWER_DEFAULT_WIDTH=900;export const Drawer=({anchor:r="right",isOpen:e,onClose:o,children:i})=>_jsx(MuiDrawer,{open:e,onClose:o,anchor:r,PaperProps:{sx:{width:"900px",padding:r=>r.spacing(2),overflow:"hidden"}},children:i});
@@ -0,0 +1,2 @@
1
+ export * from './Drawer';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Drawer/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC"}
@@ -0,0 +1 @@
1
+ export*from"./Drawer";
@@ -1 +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;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,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,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IAC5B,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,6IAkEjB,CAAC"}
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;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,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,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IAC5B,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,6IA0EjB,CAAC"}
package/dist/EChart.js CHANGED
@@ -1 +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,theme:n,renderer:t,sx:r,onEvents:o,_instance:u,onChartInitialized:s}){const c=useRef(e),i=useRef(e),l=useRef(null),f=useRef(null);return useLayoutEffect((()=>{if(null!==l.current&&null===f.current)return f.current=init(l.current,n,{renderer:null!=t?t:"canvas"}),f.current.setOption(c.current,!0),null==s||s(f.current),void 0!==u&&(u.current=f.current),()=>{null!==f.current&&(f.current.dispose(),f.current=null)}}),[u,s,n,t]),useEffect((()=>{void 0===i.current||isEqual(i.current,e)||null!==f.current&&(f.current.setOption(e,!0),i.current=e)}),[e]),useLayoutEffect((()=>{const e=debounce((()=>{null!==f.current&&f.current.resize()}),200);return window.addEventListener("resize",e),e(),()=>{window.removeEventListener("resize",e)}}),[]),useEffect((()=>{const e=f.current;if(null!==e&&void 0!==o)return bindEvents(e,o),()=>{if(void 0!==e&&!0!==e.isDisposed())for(const n in o)e.off(n)}}),[o]),_jsx(Box,{ref:l,sx:r})}));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
+ 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,theme:n,renderer:t,sx:r,onEvents:u,_instance:o,onChartInitialized:s}){const c=useRef(e),i=useRef(e),l=useRef(null),f=useRef(null);return useLayoutEffect((()=>{if(null!==l.current&&null===f.current)return f.current=init(l.current,n,{renderer:null!=t?t:"canvas"}),f.current.setOption(c.current,!0),null==s||s(f.current),void 0!==o&&(o.current=f.current),()=>{null!==f.current&&(f.current.dispose(),f.current=null)}}),[o,s,n,t]),useEffect((()=>{void 0===i.current||isEqual(i.current,e)||null!==f.current&&(f.current.setOption(e,!0),i.current=e)}),[e]),useLayoutEffect((()=>{const e=debounce((()=>{null!==f.current&&f.current.resize()}),200);return window.addEventListener("resize",e),e(),()=>{window.removeEventListener("resize",e)}}),[]),useEffect((()=>{const e=f.current;if(null!==e&&void 0!==u)return bindEvents(e,u),()=>{if(void 0!==e&&!0!==e.isDisposed())for(const n in u)e.off(n)}}),[u]),useEffect((()=>{debounce((()=>{null!==f.current&&f.current.resize()}),200)()}),[r]),_jsx(Box,{ref:l,sx:r})}));function bindEvents(e,n){var t;if(void 0!==n)for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const u=null!==(t=n[e])&&void 0!==t?t:null;u&&r(e,u)}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
- {"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/LineChart/LineChart.tsx"],"names":[],"mappings":";AAgBA,OAAO,KAAK,EAEV,mBAAmB,EAEnB,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAiBjB,OAAO,EAAiC,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI1D,OAAO,EAAgE,aAAa,EAAE,MAAM,SAAS,CAAC;AAiBtG,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC;IACxB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,CAAC,EAAE,mBAAmB,CAAC;IAC3B,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,SAAS,CAAC,EAAE,wBAAwB,EAAE,CAAC;IACvC,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CACzC;AAED,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,cAAc,eA0IpG"}
1
+ {"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/LineChart/LineChart.tsx"],"names":[],"mappings":";AAgBA,OAAO,KAAK,EAEV,mBAAmB,EAEnB,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAiBjB,OAAO,EAAiC,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG1D,OAAO,EAAgE,aAAa,EAAE,MAAM,SAAS,CAAC;AAiBtG,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC;IACxB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,CAAC,EAAE,mBAAmB,CAAC;IAC3B,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,SAAS,CAAC,EAAE,wBAAwB,EAAE,CAAC;IACvC,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CACzC;AAED,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,cAAc,eAsJpG"}
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useMemo,useRef,useState}from"react";import{useDeepMemo}from"@perses-dev/core";import{Box}from"@mui/material";import{use}from"echarts/core";import{LineChart as EChartsLineChart}from"echarts/charts";import{GridComponent,DataZoomComponent,MarkAreaComponent,MarkLineComponent,MarkPointComponent,TitleComponent,ToolboxComponent,TooltipComponent,LegendComponent,VisualMapComponent}from"echarts/components";import{CanvasRenderer}from"echarts/renderers";import{EChart}from"../EChart";import{PROGRESSIVE_MODE_SERIES_LIMIT}from"../model/graph";import{formatValue}from"../model/units";import{useChartsTheme}from"../context/ChartsThemeProvider";import{emptyTooltipData}from"../Tooltip/tooltip-model";import{Tooltip}from"../Tooltip/Tooltip";import{enableDataZoom,restoreChart,getDateRange,getFormattedDate}from"./utils";use([EChartsLineChart,GridComponent,DataZoomComponent,MarkAreaComponent,MarkLineComponent,MarkPointComponent,TitleComponent,ToolboxComponent,TooltipComponent,LegendComponent,VisualMapComponent,CanvasRenderer]);export function LineChart({height:e,data:o,unit:t,grid:r,legend:a,visualMap:n,onDataZoom:i}){const s=useChartsTheme(),m=useRef(),[p,l]=useState(!0),u=useMemo((()=>({datazoom:e=>{var t,r;if(void 0===i||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,s=o.xAxis[a],m=o.xAxis[n];void 0!==s&&void 0!==m&&i({start:s,end:m,startIndex:a,endIndex:n})}})),[o,i]);void 0!==m.current&&enableDataZoom(m.current);const h=useDeepMemo((()=>{var e;if(void 0===o.timeSeries)return{};if(null===o.timeSeries||0===o.timeSeries.length)return s.noDataOption;const i=o.timeSeries.length<PROGRESSIVE_MODE_SERIES_LIMIT,m=null!==(e=o.rangeMs)&&void 0!==e?e:getDateRange(o.xAxis);return{series:o.timeSeries,xAxis:{type:"category",data:o.xAxis,max:o.xAxisMax,axisLabel:{formatter:e=>getFormattedDate(e,m)}},yAxis:{type:"value",boundaryGap:[0,"10%"],axisLabel:{formatter:e=>formatValue(e,t)}},animation:!1,tooltip:{show:i,trigger:"axis",showContent:!1,axisPointer:{type:"none"}},toolbox:{feature:{dataZoom:{icon:null,yAxisIndex:"none"}}},grid:r,legend:a,visualMap:n}}),[o,r,a,n]);return _jsxs(Box,{sx:{height:e},onDoubleClick:()=>{void 0!==m.current&&restoreChart(m.current)},onMouseDown:e=>{e.target instanceof HTMLCanvasElement&&l(!1)},onMouseUp:()=>{l(!0)},onMouseLeave:()=>{l(!1)},onMouseEnter:()=>{l(!0)},children:[!0===p&&_jsx(Tooltip,{chartRef:m,tooltipData:emptyTooltipData,chartData:o,wrapLabels:!0}),_jsx(EChart,{sx:{width:"100%",height:"100%"},option:h,theme:s.themeName,onEvents:u,_instance:m})]})}
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useMemo,useRef,useState}from"react";import{useDeepMemo}from"@perses-dev/core";import{Box}from"@mui/material";import{use}from"echarts/core";import{LineChart as EChartsLineChart}from"echarts/charts";import{GridComponent,DataZoomComponent,MarkAreaComponent,MarkLineComponent,MarkPointComponent,TitleComponent,ToolboxComponent,TooltipComponent,LegendComponent,VisualMapComponent}from"echarts/components";import{CanvasRenderer}from"echarts/renderers";import{EChart}from"../EChart";import{PROGRESSIVE_MODE_SERIES_LIMIT}from"../model/graph";import{formatValue}from"../model/units";import{useChartsTheme}from"../context/ChartsThemeProvider";import{Tooltip}from"../Tooltip/Tooltip";import{enableDataZoom,restoreChart,getDateRange,getFormattedDate}from"./utils";use([EChartsLineChart,GridComponent,DataZoomComponent,MarkAreaComponent,MarkLineComponent,MarkPointComponent,TitleComponent,ToolboxComponent,TooltipComponent,LegendComponent,VisualMapComponent,CanvasRenderer]);export function LineChart({height:e,data:o,unit:t,grid:r,legend:n,visualMap:a,onDataZoom:i}){const s=useChartsTheme(),m=useRef(),[p,l]=useState(!0),[u,h]=useState(!1),x=useMemo((()=>({datazoom:e=>{var t,r;if(void 0===i&&setTimeout((()=>{h(!1)}),10),void 0===i||void 0===e.batch[0])return;const n=null!==(t=e.batch[0].startValue)&&void 0!==t?t:0,a=null!==(r=e.batch[0].endValue)&&void 0!==r?r:o.xAxis.length-1,s=o.xAxis[n],m=o.xAxis[a];void 0!==s&&void 0!==m&&i({start:s,end:m,startIndex:n,endIndex:a})}})),[o,i,h]);void 0!==m.current&&enableDataZoom(m.current);const d=useDeepMemo((()=>{var e;if(void 0===o.timeSeries)return{};if(null===o.timeSeries||0===o.timeSeries.length)return s.noDataOption;const i=o.timeSeries.length<PROGRESSIVE_MODE_SERIES_LIMIT,m=null!==(e=o.rangeMs)&&void 0!==e?e:getDateRange(o.xAxis);return{series:o.timeSeries,xAxis:{type:"category",data:o.xAxis,max:o.xAxisMax,axisLabel:{formatter:e=>getFormattedDate(e,m)}},yAxis:{type:"value",boundaryGap:[0,"10%"],axisLabel:{formatter:e=>formatValue(e,t)}},animation:!1,tooltip:{show:i,trigger:"axis",showContent:!1,axisPointer:{type:"none"}},toolbox:{feature:{dataZoom:{icon:null,yAxisIndex:"none"}}},grid:r,legend:n,visualMap:a}}),[o,r,n,a]);return _jsxs(Box,{sx:{height:e},onClick:()=>h((e=>!e)),onDoubleClick:()=>{h(!1),void 0!==m.current&&restoreChart(m.current)},onMouseDown:e=>{e.target instanceof HTMLCanvasElement&&l(!1)},onMouseUp:()=>{l(!0)},onMouseLeave:()=>{l(!1),h(!1)},onMouseEnter:()=>{l(!0)},children:[!0===p&&_jsx(Tooltip,{chartRef:m,chartData:o,wrapLabels:!0,pinTooltip:u}),_jsx(EChart,{sx:{width:"100%",height:"100%"},option:d,theme:s.themeName,onEvents:x,_instance:m})]})}
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { AbsoluteTimeRange } from '@perses-dev/core';
3
+ interface AbsoluteTimeFormProps {
4
+ initialTimeRange: AbsoluteTimeRange;
5
+ onChange: (timeRange: AbsoluteTimeRange) => void;
6
+ }
7
+ export declare const AbsoluteTimePicker: ({ initialTimeRange, onChange }: AbsoluteTimeFormProps) => JSX.Element;
8
+ export {};
9
+ //# sourceMappingURL=AbsoluteTimePicker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbsoluteTimePicker.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/AbsoluteTimePicker.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAKrD,UAAU,qBAAqB;IAC7B,gBAAgB,EAAE,iBAAiB,CAAC;IACpC,QAAQ,EAAE,CAAC,SAAS,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,kBAAkB,mCAAoC,qBAAqB,gBAmIvF,CAAC"}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState}from"react";import{Box,Stack,TextField,Divider}from"@mui/material";import{LocalizationProvider,StaticDateTimePicker}from"@mui/x-date-pickers";import{AdapterDateFns}from"@mui/x-date-pickers/AdapterDateFns";import{format}from"date-fns";import{validateDateRange}from"./utils";const DATE_TIME_FORMAT="yyyy-MM-dd HH:mm:ss";export const AbsoluteTimePicker=({initialTimeRange:e,onChange:t})=>{const[a,i]=useState(e),[r,n]=useState(!0),o=(e,r)=>{const n=new Date(e);!0===r?!0===validateDateRange(n,a.end)&&i((e=>{const a={start:n,end:e.end};return t(a),a})):!0===validateDateRange(a.start,n)&&i((e=>{const a={start:e.start,end:n};return t(a),a}))};return _jsx(LocalizationProvider,{dateAdapter:AdapterDateFns,children:_jsxs(Stack,{spacing:3,sx:{padding:e=>e.spacing(1,2,3)},children:[r&&_jsxs(Box,{sx:e=>({".MuiPickerStaticWrapper-content":{backgroundColor:e.palette.background.default},".MuiIconButton-sizeMedium":{top:80,bottom:"auto",margin:e.spacing(0,3)}}),children:[_jsx("h3",{children:"Select Start Time"}),_jsx(StaticDateTimePicker,{displayStaticWrapperAs:"desktop",openTo:"day",disableHighlightToday:!0,value:e.start,onChange:e=>{null!==e&&i((t=>({start:e,end:t.end})))},onAccept:()=>{n(!1)},renderInput:e=>_jsx(TextField,{...e})})]}),!r&&_jsxs(Box,{sx:e=>({".MuiPickerStaticWrapper-content":{backgroundColor:e.palette.background.default},".MuiIconButton-sizeMedium":{top:80,bottom:"auto",margin:e.spacing(0,3)}}),children:[_jsx("h3",{children:"Select End Time"}),_jsx(StaticDateTimePicker,{displayStaticWrapperAs:"desktop",openTo:"day",disableHighlightToday:!0,value:e.end,minDateTime:a.start,onChange:e=>{null!==e&&i((t=>({start:t.start,end:e})))},onAccept:()=>{n(!0),t(a)},renderInput:e=>_jsx(TextField,{...e})})]}),_jsx(TextField,{fullWidth:!0,onChange:e=>{o(e.target.value,!0)},value:format(a.start,DATE_TIME_FORMAT),label:"Start Time",placeholder:"mm/dd/yyyy hh:mm",type:"tel"}),_jsx(Divider,{sx:e=>({margin:e.spacing(2,0),borderColor:e.palette.grey[500]})}),_jsx(TextField,{fullWidth:!0,onChange:e=>{o(e.target.value,!1)},value:format(a.end,DATE_TIME_FORMAT),label:"End Time",placeholder:"mm/dd/yyyy hh:mm",type:"tel"})]})})};
@@ -0,0 +1,17 @@
1
+ /// <reference types="react" />
2
+ import { SelectChangeEvent } from '@mui/material';
3
+ import { TimeRangeValue, RelativeTimeRange } from '@perses-dev/core';
4
+ export interface TimeOption {
5
+ value: RelativeTimeRange;
6
+ display: string;
7
+ }
8
+ interface TimeRangeSelectorProps {
9
+ inputLabel: string;
10
+ value: TimeRangeValue;
11
+ timeOptions: TimeOption[];
12
+ onSelectChange: (event: SelectChangeEvent<string>) => void;
13
+ onCustomClick: () => void;
14
+ }
15
+ export declare function TimeRangeSelector(props: TimeRangeSelectorProps): JSX.Element;
16
+ export {};
17
+ //# sourceMappingURL=TimeRangeSelector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeRangeSelector.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/TimeRangeSelector.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAoB,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAmB,MAAM,kBAAkB,CAAC;AAKtF,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,iBAAiB,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,sBAAsB;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,cAAc,CAAC;IACtB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,cAAc,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAC3D,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eA+B9D"}
@@ -0,0 +1 @@
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{MenuItem,Select}from"@mui/material";import{isRelativeValue}from"@perses-dev/core";import{formatAbsoluteRange}from"./utils";const DATE_TIME_FORMAT="yyyy-MM-dd HH:mm:ss";export function TimeRangeSelector(e){const{inputLabel:t,value:a,timeOptions:s,onSelectChange:i,onCustomClick:l}=e,n=isRelativeValue(a)?a.pastDuration:formatAbsoluteRange(a,DATE_TIME_FORMAT);return _jsxs(Select,{value:n,label:t,onChange:i,children:[s.map(((e,t)=>_jsx(MenuItem,{value:e.value.pastDuration,children:e.display},t))),isRelativeValue(a)?_jsx(MenuItem,{onClick:()=>{l()},children:"Custom time range"}):_jsx(MenuItem,{value:n,onClick:()=>{l()},children:n})]})}
@@ -0,0 +1,3 @@
1
+ export * from './TimeRangeSelector';
2
+ export * from './AbsoluteTimePicker';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1 @@
1
+ export*from"./TimeRangeSelector";export*from"./AbsoluteTimePicker";
@@ -0,0 +1,7 @@
1
+ import { AbsoluteTimeRange } from '@perses-dev/core';
2
+ export declare function validateDateRange(startDate: Date, endDate: Date): boolean;
3
+ /**
4
+ * Format start and end time based on provided date format
5
+ */
6
+ export declare function formatAbsoluteRange(timeRange: AbsoluteTimeRange, dateFormat: string): string;
7
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/TimeRangeSelector/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAKrD,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,WAW/D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAInF"}
@@ -0,0 +1 @@
1
+ import{isBefore,isValid,format}from"date-fns";export function validateDateRange(e,r){return isValid(e)&&isValid(r)?!!isBefore(e,r)||(console.error("End Time is before Start Time"),!1):(console.error("Invalid Date"),!1)}export function formatAbsoluteRange(e,r){return`${format(e.start,r)} - ${format(e.end,r)}`}
@@ -1,13 +1,12 @@
1
1
  import React from 'react';
2
2
  import { ECharts as EChartsInstance } from 'echarts/core';
3
3
  import { EChartsDataFormat } from '../model/graph';
4
- import { TooltipData } from './tooltip-model';
5
4
  interface TooltipProps {
6
5
  chartRef: React.MutableRefObject<EChartsInstance | undefined>;
7
- tooltipData: TooltipData;
8
6
  chartData: EChartsDataFormat;
7
+ pinTooltip: boolean;
9
8
  wrapLabels?: boolean;
10
9
  }
11
- export declare function Tooltip(props: TooltipProps): JSX.Element | null;
12
- export {};
10
+ declare const Tooltip: React.NamedExoticComponent<TooltipProps>;
11
+ export { Tooltip };
13
12
  //# sourceMappingURL=Tooltip.d.ts.map
@@ -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,gBAAgB,CAAC;AAEnD,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
+ {"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,gBAAgB,CAAC;AAMnD,UAAU,YAAY;IACpB,QAAQ,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IAC9D,SAAS,EAAE,iBAAiB,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,QAAA,MAAM,OAAO,0CAqDX,CAAC;AAEH,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -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: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
+ import{jsx as _jsx}from"react/jsx-runtime";import React,{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";import{assembleTransform}from"./utils";const Tooltip=React.memo((function({chartRef:o,chartData:t,wrapLabels:e,pinTooltip:r}){var l,i;const[s,n]=useState(null),a=useMousePosition();if(null===a||null===a.target)return null;if(null===s&&"CANVAS"!==a.target.tagName)return null;const u=o.current,m=getFocusedSeriesData(a,t,s,u),p=null!==(l=null==u?void 0:u.getWidth())&&void 0!==l?l:750,f=null!==(i=null==u?void 0:u.getHeight())&&void 0!==i?i:230,c=assembleTransform(a,m.length,p,f,s);return 0===m.length?null:(!0===r&&null===s&&n(a),_jsx(Portal,{children:_jsx(Box,{sx:o=>({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:o.zIndex.tooltip,overflow:"hidden","&:hover":{overflowY:"auto"}}),style:{transform:c},children:_jsx(TooltipContent,{focusedSeries:m,wrapLabels:e})})}))}));export{Tooltip};
@@ -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=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[]}
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[]}
@@ -0,0 +1,6 @@
1
+ import { CursorCoordinates, CursorData } from './tooltip-model';
2
+ /**
3
+ * Determine position of tooltip depending on chart dimensions and the number of focused series
4
+ */
5
+ export declare function assembleTransform(mousePos: CursorData['coords'], seriesNum: number, chartWidth: number, chartHeight: number, pinnedPos: CursorCoordinates | null): string;
6
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/Tooltip/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAqB,MAAM,iBAAiB,CAAC;AAEnF;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,EAC9B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,iBAAiB,GAAG,IAAI,UAoCpC"}
@@ -0,0 +1 @@
1
+ import{TOOLTIP_MAX_WIDTH}from"./tooltip-model";export function assembleTransform(t,o,r,e,n){if(null===t)return"translate3d(0, 0)";null!==n&&(t=n);const p=t.viewport.x;let a=t.viewport.y+16;const l=.75*e;!0==t.viewport.y>.8*window.innerHeight?a=o>6?.65*t.viewport.y:.75*t.viewport.y:t.plotCanvas.y>l&&(a=.85*t.viewport.y);const i=r-.9*(o>1?TOOLTIP_MAX_WIDTH:TOOLTIP_MAX_WIDTH/2);return t.plotCanvas.x>i&&p>TOOLTIP_MAX_WIDTH?`translate3d(${p-32}px, ${a}px, 0) translateX(-100%)`:`translate3d(${p+32}px, ${a}px, 0)`}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Drawer = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ // Copyright 2022 The Perses Authors
6
+ // Licensed under the Apache License, Version 2.0 (the "License");
7
+ // you may not use this file except in compliance with the License.
8
+ // You may obtain a copy of the License at
9
+ //
10
+ // http://www.apache.org/licenses/LICENSE-2.0
11
+ //
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ const material_1 = require("@mui/material");
18
+ const DRAWER_DEFAULT_WIDTH = 900;
19
+ const Drawer = ({ anchor = 'right', isOpen, onClose, children }) => {
20
+ return ((0, jsx_runtime_1.jsx)(material_1.Drawer, { open: isOpen, onClose: onClose, anchor: anchor, PaperProps: {
21
+ sx: {
22
+ width: `${DRAWER_DEFAULT_WIDTH}px`,
23
+ padding: (theme) => theme.spacing(2),
24
+ overflow: 'hidden',
25
+ },
26
+ }, children: children }));
27
+ };
28
+ exports.Drawer = Drawer;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // Copyright 2022 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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ __exportStar(require("./Drawer"), exports);
@@ -117,6 +117,14 @@ exports.EChart = react_1.default.memo(function EChart({ option, theme, renderer,
117
117
  }
118
118
  };
119
119
  }, [onEvents]);
120
+ (0, react_1.useEffect)(() => {
121
+ const updateSize = (0, debounce_1.default)(() => {
122
+ if (chartElement.current === null)
123
+ return;
124
+ chartElement.current.resize();
125
+ }, 200);
126
+ updateSize();
127
+ }, [sx]);
120
128
  return (0, jsx_runtime_1.jsx)(material_1.Box, { ref: containerRef, sx: sx });
121
129
  });
122
130
  // Validate event config and bind custom events
@@ -25,7 +25,6 @@ const EChart_1 = require("../EChart");
25
25
  const graph_1 = require("../model/graph");
26
26
  const units_1 = require("../model/units");
27
27
  const ChartsThemeProvider_1 = require("../context/ChartsThemeProvider");
28
- const tooltip_model_1 = require("../Tooltip/tooltip-model");
29
28
  const Tooltip_1 = require("../Tooltip/Tooltip");
30
29
  const utils_1 = require("./utils");
31
30
  (0, core_2.use)([
@@ -46,11 +45,17 @@ function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom })
46
45
  const chartsTheme = (0, ChartsThemeProvider_1.useChartsTheme)();
47
46
  const chartRef = (0, react_1.useRef)();
48
47
  const [showTooltip, setShowTooltip] = (0, react_1.useState)(true);
48
+ const [pinTooltip, setPinTooltip] = (0, react_1.useState)(false);
49
49
  const handleEvents = (0, react_1.useMemo)(() => {
50
50
  return {
51
- // TODO: use legendselectchanged event to fix tooltip when legend selected
52
51
  datazoom: (params) => {
53
52
  var _a, _b;
53
+ if (onDataZoom === undefined) {
54
+ setTimeout(() => {
55
+ // workaround so unpin happens after click event
56
+ setPinTooltip(false);
57
+ }, 10);
58
+ }
54
59
  if (onDataZoom === undefined || params.batch[0] === undefined)
55
60
  return;
56
61
  const startIndex = (_a = params.batch[0].startValue) !== null && _a !== void 0 ? _a : 0;
@@ -67,12 +72,15 @@ function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom })
67
72
  onDataZoom(zoomEvent);
68
73
  }
69
74
  },
75
+ // TODO: use legendselectchanged event to fix tooltip when legend selected
70
76
  };
71
- }, [data, onDataZoom]);
77
+ }, [data, onDataZoom, setPinTooltip]);
72
78
  if (chartRef.current !== undefined) {
73
79
  (0, utils_1.enableDataZoom)(chartRef.current);
74
80
  }
81
+ const handleOnClick = () => setPinTooltip((current) => !current);
75
82
  const handleOnDoubleClick = () => {
83
+ setPinTooltip(false);
76
84
  if (chartRef.current !== undefined) {
77
85
  (0, utils_1.restoreChart)(chartRef.current);
78
86
  }
@@ -91,6 +99,7 @@ function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom })
91
99
  };
92
100
  const handleOnMouseLeave = () => {
93
101
  setShowTooltip(false);
102
+ setPinTooltip(false);
94
103
  };
95
104
  const option = (0, core_1.useDeepMemo)(() => {
96
105
  var _a;
@@ -146,7 +155,7 @@ function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom })
146
155
  }, [data, grid, legend, visualMap]);
147
156
  return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
148
157
  height,
149
- }, onDoubleClick: handleOnDoubleClick, 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: {
158
+ }, onClick: handleOnClick, onDoubleClick: handleOnDoubleClick, onMouseDown: handleOnMouseDown, onMouseUp: handleOnMouseUp, onMouseLeave: handleOnMouseLeave, onMouseEnter: handleOnMouseEnter, children: [showTooltip === true && ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { chartRef: chartRef, chartData: data, wrapLabels: true, pinTooltip: pinTooltip })), (0, jsx_runtime_1.jsx)(EChart_1.EChart, { sx: {
150
159
  width: '100%',
151
160
  height: '100%',
152
161
  }, option: option, theme: chartsTheme.themeName, onEvents: handleEvents, _instance: chartRef })] }));
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbsoluteTimePicker = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ // Copyright 2022 The Perses Authors
6
+ // Licensed under the Apache License, Version 2.0 (the "License");
7
+ // you may not use this file except in compliance with the License.
8
+ // You may obtain a copy of the License at
9
+ //
10
+ // http://www.apache.org/licenses/LICENSE-2.0
11
+ //
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ const react_1 = require("react");
18
+ const material_1 = require("@mui/material");
19
+ const x_date_pickers_1 = require("@mui/x-date-pickers");
20
+ const AdapterDateFns_1 = require("@mui/x-date-pickers/AdapterDateFns");
21
+ const date_fns_1 = require("date-fns");
22
+ const utils_1 = require("./utils");
23
+ const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
24
+ const AbsoluteTimePicker = ({ initialTimeRange, onChange }) => {
25
+ const [timeRange, setTimeRange] = (0, react_1.useState)(initialTimeRange);
26
+ const [showStartCalendar, setShowStartCalendar] = (0, react_1.useState)(true);
27
+ // validate start and end time, propagate changes
28
+ const updateDateRange = (input, isStartDate) => {
29
+ const newDate = new Date(input);
30
+ if (isStartDate === true) {
31
+ const isValidDateRange = (0, utils_1.validateDateRange)(newDate, timeRange.end);
32
+ if (isValidDateRange === true) {
33
+ setTimeRange((current) => {
34
+ const updatedRange = { start: newDate, end: current.end };
35
+ onChange(updatedRange);
36
+ return updatedRange;
37
+ });
38
+ }
39
+ }
40
+ else {
41
+ const isValidDateRange = (0, utils_1.validateDateRange)(timeRange.start, newDate);
42
+ if (isValidDateRange === true) {
43
+ setTimeRange((current) => {
44
+ const updatedRange = { start: current.start, end: newDate };
45
+ onChange(updatedRange);
46
+ return updatedRange;
47
+ });
48
+ }
49
+ }
50
+ };
51
+ return ((0, jsx_runtime_1.jsx)(x_date_pickers_1.LocalizationProvider, { dateAdapter: AdapterDateFns_1.AdapterDateFns, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 3, sx: { padding: (theme) => theme.spacing(1, 2, 3) }, children: [showStartCalendar && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: (theme) => ({
52
+ // TODO: create separate reusable calendar component
53
+ '.MuiPickerStaticWrapper-content': {
54
+ backgroundColor: theme.palette.background.default,
55
+ },
56
+ // reposition AM and PM buttons
57
+ '.MuiIconButton-sizeMedium': {
58
+ top: 80,
59
+ bottom: 'auto',
60
+ margin: theme.spacing(0, 3),
61
+ },
62
+ }), children: [(0, jsx_runtime_1.jsx)("h3", { children: "Select Start Time" }), (0, jsx_runtime_1.jsx)(x_date_pickers_1.StaticDateTimePicker, { displayStaticWrapperAs: "desktop", openTo: "day", disableHighlightToday: true, value: initialTimeRange.start, onChange: (newValue) => {
63
+ if (newValue === null)
64
+ return;
65
+ setTimeRange((current) => {
66
+ return { start: newValue, end: current.end };
67
+ });
68
+ }, onAccept: () => {
69
+ setShowStartCalendar(false);
70
+ }, renderInput: (params) => (0, jsx_runtime_1.jsx)(material_1.TextField, { ...params }) })] })), !showStartCalendar && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: (theme) => ({
71
+ '.MuiPickerStaticWrapper-content': {
72
+ backgroundColor: theme.palette.background.default,
73
+ },
74
+ // reposition AM and PM buttons
75
+ '.MuiIconButton-sizeMedium': {
76
+ top: 80,
77
+ bottom: 'auto',
78
+ margin: theme.spacing(0, 3),
79
+ },
80
+ }), children: [(0, jsx_runtime_1.jsx)("h3", { children: "Select End Time" }), (0, jsx_runtime_1.jsx)(x_date_pickers_1.StaticDateTimePicker, { displayStaticWrapperAs: "desktop", openTo: "day", disableHighlightToday: true, value: initialTimeRange.end, minDateTime: timeRange.start, onChange: (newValue) => {
81
+ if (newValue === null)
82
+ return;
83
+ setTimeRange((current) => {
84
+ return { start: current.start, end: newValue };
85
+ });
86
+ }, onAccept: () => {
87
+ setShowStartCalendar(true);
88
+ onChange(timeRange);
89
+ }, renderInput: (params) => (0, jsx_runtime_1.jsx)(material_1.TextField, { ...params }) })] })), (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, onChange: (event) => {
90
+ // TODO: add helperText, fix validation after we decide on form state solution
91
+ updateDateRange(event.target.value, true);
92
+ }, value: (0, date_fns_1.format)(timeRange.start, DATE_TIME_FORMAT), label: "Start Time", placeholder: "mm/dd/yyyy hh:mm",
93
+ // tel used to match MUI DateTimePicker, may change in future: https://github.com/mui/material-ui/issues/27590
94
+ type: "tel" }), (0, jsx_runtime_1.jsx)(material_1.Divider, { sx: (theme) => ({
95
+ margin: theme.spacing(2, 0),
96
+ borderColor: theme.palette.grey['500'],
97
+ }) }), (0, jsx_runtime_1.jsx)(material_1.TextField, { fullWidth: true, onChange: (event) => {
98
+ updateDateRange(event.target.value, false);
99
+ }, value: (0, date_fns_1.format)(timeRange.end, DATE_TIME_FORMAT), label: "End Time", placeholder: "mm/dd/yyyy hh:mm", type: "tel" })] }) }));
100
+ };
101
+ exports.AbsoluteTimePicker = AbsoluteTimePicker;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeRangeSelector = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ // Copyright 2022 The Perses Authors
6
+ // Licensed under the Apache License, Version 2.0 (the "License");
7
+ // you may not use this file except in compliance with the License.
8
+ // You may obtain a copy of the License at
9
+ //
10
+ // http://www.apache.org/licenses/LICENSE-2.0
11
+ //
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ const material_1 = require("@mui/material");
18
+ const core_1 = require("@perses-dev/core");
19
+ const utils_1 = require("./utils");
20
+ const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
21
+ function TimeRangeSelector(props) {
22
+ const { inputLabel, value, timeOptions, onSelectChange, onCustomClick } = props;
23
+ const formattedValue = !(0, core_1.isRelativeValue)(value) ? (0, utils_1.formatAbsoluteRange)(value, DATE_TIME_FORMAT) : value.pastDuration;
24
+ return ((0, jsx_runtime_1.jsxs)(material_1.Select, { value: formattedValue, label: inputLabel, onChange: onSelectChange, children: [timeOptions.map((item, idx) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: item.value.pastDuration, children: item.display }, idx))), (0, core_1.isRelativeValue)(value) ? ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { onClick: () => {
25
+ onCustomClick();
26
+ }, children: "Custom time range" })) : ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: formattedValue, onClick: () => {
27
+ onCustomClick();
28
+ }, children: formattedValue }))] }));
29
+ }
30
+ exports.TimeRangeSelector = TimeRangeSelector;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ // Copyright 2022 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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ __exportStar(require("./TimeRangeSelector"), exports);
30
+ __exportStar(require("./AbsoluteTimePicker"), exports);
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ // Copyright 2022 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.formatAbsoluteRange = exports.validateDateRange = void 0;
16
+ const date_fns_1 = require("date-fns");
17
+ /*
18
+ * Date validation and check if end is after start
19
+ */
20
+ function validateDateRange(startDate, endDate) {
21
+ // TODO: display error as helperText
22
+ if (!(0, date_fns_1.isValid)(startDate) || !(0, date_fns_1.isValid)(endDate)) {
23
+ console.error('Invalid Date');
24
+ return false;
25
+ }
26
+ if (!(0, date_fns_1.isBefore)(startDate, endDate)) {
27
+ console.error('End Time is before Start Time');
28
+ return false;
29
+ }
30
+ return true;
31
+ }
32
+ exports.validateDateRange = validateDateRange;
33
+ /**
34
+ * Format start and end time based on provided date format
35
+ */
36
+ function formatAbsoluteRange(timeRange, dateFormat) {
37
+ const formattedStart = (0, date_fns_1.format)(timeRange.start, dateFormat);
38
+ const formattedEnd = (0, date_fns_1.format)(timeRange.end, dateFormat);
39
+ return `${formattedStart} - ${formattedEnd}`;
40
+ }
41
+ exports.formatAbsoluteRange = formatAbsoluteRange;
@@ -1,4 +1,27 @@
1
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.Tooltip = void 0;
4
27
  const jsx_runtime_1 = require("react/jsx-runtime");
@@ -14,36 +37,32 @@ const jsx_runtime_1 = require("react/jsx-runtime");
14
37
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
38
  // See the License for the specific language governing permissions and
16
39
  // limitations under the License.
17
- const react_1 = require("react");
40
+ const react_1 = __importStar(require("react"));
18
41
  const material_1 = require("@mui/material");
19
42
  const focused_series_1 = require("./focused-series");
20
43
  const tooltip_model_1 = require("./tooltip-model");
21
44
  const TooltipContent_1 = require("./TooltipContent");
22
- function Tooltip(props) {
45
+ const utils_1 = require("./utils");
46
+ const Tooltip = react_1.default.memo(function Tooltip({ chartRef, chartData, wrapLabels, pinTooltip }) {
23
47
  var _a, _b;
24
- const { chartRef, chartData } = props;
25
48
  const [pinnedPos, setPinnedPos] = (0, react_1.useState)(null);
26
49
  const mousePos = (0, tooltip_model_1.useMousePosition)();
27
- if (mousePos === null)
50
+ if (mousePos === null || mousePos.target === null)
51
+ return null;
52
+ // ensure user is hovering over a chart before checking for nearby series
53
+ if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS')
28
54
  return null;
29
55
  const chart = chartRef.current;
30
56
  const focusedSeries = (0, focused_series_1.getFocusedSeriesData)(mousePos, chartData, pinnedPos, chart);
31
57
  const chartWidth = (_a = chart === null || chart === void 0 ? void 0 : chart.getWidth()) !== null && _a !== void 0 ? _a : 750;
32
58
  const chartHeight = (_b = chart === null || chart === void 0 ? void 0 : chart.getHeight()) !== null && _b !== void 0 ? _b : 230;
33
- const cursorTransform = assembleTransform(mousePos, focusedSeries.length, chartWidth, chartHeight, pinnedPos);
34
- function handleMouseEnter() {
35
- if (mousePos !== null) {
36
- setPinnedPos(mousePos);
37
- }
38
- }
39
- function handleMouseLeave() {
40
- if (pinnedPos !== null) {
41
- setPinnedPos(null);
42
- }
43
- }
59
+ const cursorTransform = (0, utils_1.assembleTransform)(mousePos, focusedSeries.length, chartWidth, chartHeight, pinnedPos);
44
60
  if (focusedSeries.length === 0) {
45
61
  return null;
46
62
  }
63
+ if (pinTooltip === true && pinnedPos === null) {
64
+ setPinnedPos(mousePos);
65
+ }
47
66
  return ((0, jsx_runtime_1.jsx)(material_1.Portal, { children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: (theme) => ({
48
67
  maxWidth: tooltip_model_1.TOOLTIP_MAX_WIDTH,
49
68
  maxHeight: tooltip_model_1.TOOLTIP_MAX_HEIGHT,
@@ -64,39 +83,6 @@ function Tooltip(props) {
64
83
  },
65
84
  }), style: {
66
85
  transform: cursorTransform,
67
- }, onMouseEnter: () => handleMouseEnter(), onMouseLeave: () => handleMouseLeave(), children: (0, jsx_runtime_1.jsx)(TooltipContent_1.TooltipContent, { focusedSeries: focusedSeries, wrapLabels: props.wrapLabels }) }) }));
68
- }
86
+ }, children: (0, jsx_runtime_1.jsx)(TooltipContent_1.TooltipContent, { focusedSeries: focusedSeries, wrapLabels: wrapLabels }) }) }));
87
+ });
69
88
  exports.Tooltip = Tooltip;
70
- function assembleTransform(mousePos, seriesNum, chartWidth, chartHeight, pinnedPos) {
71
- if (mousePos === null) {
72
- return 'translate3d(0, 0)';
73
- }
74
- if (pinnedPos !== null) {
75
- mousePos = pinnedPos;
76
- }
77
- const cursorPaddingX = 32;
78
- const cursorPaddingY = 16;
79
- const x = mousePos.viewport.x;
80
- let y = mousePos.viewport.y + cursorPaddingY;
81
- const isCloseToBottom = mousePos.viewport.y > window.innerHeight * 0.8;
82
- const yPosAdjustThreshold = chartHeight * 0.75;
83
- // adjust so tooltip does not get cut off at bottom of chart, reduce multiplier to move up
84
- if (isCloseToBottom === true) {
85
- if (seriesNum > 6) {
86
- y = mousePos.viewport.y * 0.65;
87
- }
88
- else {
89
- y = mousePos.viewport.y * 0.75;
90
- }
91
- }
92
- else if (mousePos.plotCanvas.y > yPosAdjustThreshold) {
93
- y = mousePos.viewport.y * 0.85;
94
- }
95
- // use tooltip width to determine when to repos from right to left (width is narrower when only 1 focused series since labels wrap)
96
- const tooltipWidth = seriesNum > 1 ? tooltip_model_1.TOOLTIP_MAX_WIDTH : tooltip_model_1.TOOLTIP_MAX_WIDTH / 2;
97
- const xPosAdjustThreshold = chartWidth - tooltipWidth * 0.9;
98
- // reposition so tooltip is never too close to right side of chart or left side of browser window
99
- return mousePos.plotCanvas.x > xPosAdjustThreshold && x > tooltip_model_1.TOOLTIP_MAX_WIDTH
100
- ? `translate3d(${x - cursorPaddingX}px, ${y}px, 0) translateX(-100%)`
101
- : `translate3d(${x + cursorPaddingX}px, ${y}px, 0)`;
102
- }
@@ -29,7 +29,7 @@ function getNearbySeries(data, pointInGrid, yBuffer) {
29
29
  if (Array.isArray(data.xAxis) && Array.isArray(data.timeSeries)) {
30
30
  for (let seriesIdx = 0; seriesIdx < data.timeSeries.length; seriesIdx++) {
31
31
  const currentSeries = data.timeSeries[seriesIdx];
32
- if (currentFocusedData.length > tooltip_model_1.TOOLTIP_MAX_ITEMS)
32
+ if (currentFocusedData.length >= tooltip_model_1.TOOLTIP_MAX_ITEMS)
33
33
  break;
34
34
  if (currentSeries !== undefined) {
35
35
  const currentSeriesName = currentSeries.name ? currentSeries.name.toString() : '';
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ // Copyright 2022 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.assembleTransform = void 0;
16
+ const tooltip_model_1 = require("./tooltip-model");
17
+ /**
18
+ * Determine position of tooltip depending on chart dimensions and the number of focused series
19
+ */
20
+ function assembleTransform(mousePos, seriesNum, chartWidth, chartHeight, pinnedPos) {
21
+ if (mousePos === null) {
22
+ return 'translate3d(0, 0)';
23
+ }
24
+ if (pinnedPos !== null) {
25
+ mousePos = pinnedPos;
26
+ }
27
+ const cursorPaddingX = 32;
28
+ const cursorPaddingY = 16;
29
+ const x = mousePos.viewport.x;
30
+ let y = mousePos.viewport.y + cursorPaddingY;
31
+ const isCloseToBottom = mousePos.viewport.y > window.innerHeight * 0.8;
32
+ const yPosAdjustThreshold = chartHeight * 0.75;
33
+ // adjust so tooltip does not get cut off at bottom of chart, reduce multiplier to move up
34
+ if (isCloseToBottom === true) {
35
+ if (seriesNum > 6) {
36
+ y = mousePos.viewport.y * 0.65;
37
+ }
38
+ else {
39
+ y = mousePos.viewport.y * 0.75;
40
+ }
41
+ }
42
+ else if (mousePos.plotCanvas.y > yPosAdjustThreshold) {
43
+ y = mousePos.viewport.y * 0.85;
44
+ }
45
+ // use tooltip width to determine when to repos from right to left (width is narrower when only 1 focused series since labels wrap)
46
+ const tooltipWidth = seriesNum > 1 ? tooltip_model_1.TOOLTIP_MAX_WIDTH : tooltip_model_1.TOOLTIP_MAX_WIDTH / 2;
47
+ const xPosAdjustThreshold = chartWidth - tooltipWidth * 0.9;
48
+ // reposition so tooltip is never too close to right side of chart or left side of browser window
49
+ return mousePos.plotCanvas.x > xPosAdjustThreshold && x > tooltip_model_1.TOOLTIP_MAX_WIDTH
50
+ ? `translate3d(${x - cursorPaddingX}px, ${y}px, 0) translateX(-100%)`
51
+ : `translate3d(${x + cursorPaddingX}px, ${y}px, 0)`;
52
+ }
53
+ exports.assembleTransform = assembleTransform;
package/dist/cjs/index.js CHANGED
@@ -26,6 +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("./Drawer"), exports);
29
30
  __exportStar(require("./EChart"), exports);
30
31
  __exportStar(require("./ErrorAlert"), exports);
31
32
  __exportStar(require("./ErrorBoundary"), exports);
@@ -33,6 +34,7 @@ __exportStar(require("./InfoTooltip"), exports);
33
34
  __exportStar(require("./LineChart"), exports);
34
35
  __exportStar(require("./GaugeChart"), exports);
35
36
  __exportStar(require("./StatChart"), exports);
37
+ __exportStar(require("./TimeRangeSelector"), exports);
36
38
  __exportStar(require("./context/ChartsThemeProvider"), exports);
37
39
  __exportStar(require("./utils"), exports);
38
40
  __exportStar(require("./model"), exports);
@@ -179,6 +179,8 @@ function formatBytes(bytes, decimals = 2) {
179
179
  const k = 1024;
180
180
  const dm = decimals < 0 ? 0 : decimals;
181
181
  const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
182
- const i = Math.floor(Math.log(bytes) / Math.log(k));
182
+ // Math.max(0, ...) ensures that we don't return -1 as a value for the index.
183
+ // Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.
184
+ const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));
183
185
  return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
184
186
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './Drawer';
1
2
  export * from './EChart';
2
3
  export * from './ErrorAlert';
3
4
  export * from './ErrorBoundary';
@@ -5,6 +6,7 @@ export * from './InfoTooltip';
5
6
  export * from './LineChart';
6
7
  export * from './GaugeChart';
7
8
  export * from './StatChart';
9
+ export * from './TimeRangeSelector';
8
10
  export * from './context/ChartsThemeProvider';
9
11
  export * from './utils';
10
12
  export * from './model';
@@ -1 +1 @@
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,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export*from"./EChart";export*from"./ErrorAlert";export*from"./ErrorBoundary";export*from"./InfoTooltip";export*from"./LineChart";export*from"./GaugeChart";export*from"./StatChart";export*from"./context/ChartsThemeProvider";export*from"./utils";export*from"./model";
1
+ export*from"./Drawer";export*from"./EChart";export*from"./ErrorAlert";export*from"./ErrorBoundary";export*from"./InfoTooltip";export*from"./LineChart";export*from"./GaugeChart";export*from"./StatChart";export*from"./TimeRangeSelector";export*from"./context/ChartsThemeProvider";export*from"./utils";export*from"./model";
@@ -1 +1 @@
1
- import{milliseconds}from"date-fns";import{round}from"mathjs";export const DEFAULT_DECIMAL_PLACES=2;export function formatValue(e,t){var n;if(void 0===t)return e.toString();if(isDecimalUnit(t))return formatDecimal(e,t);if(isTimeUnit(t))return formatTime(e,t);if(isPercentUnit(t))return formatPercent(e,t);if(isBytesUnit(t))return formatBytes(e,null!==(n=t.decimal_places)&&void 0!==n?n:2);throw new Error(`Unknown unit options ${t}`)}const timeUnitKinds=["Milliseconds","Seconds","Minutes","Hours","Days","Weeks","Months","Years"],timeUnitKindsSet=new Set(timeUnitKinds);function isTimeUnit(e){return timeUnitKindsSet.has(e.kind)}function formatTime(e,t){const n={};switch(t.kind){case"Milliseconds":n.seconds=e/1e3;break;case"Seconds":n.seconds=e;break;case"Minutes":n.minutes=e;break;case"Hours":n.hours=e;break;case"Days":n.days=e;break;case"Weeks":n.weeks=e;break;case"Months":n.months=e;break;case"Years":n.years=e;break;default:const i=t.kind;throw new Error(`Unknown time unit type ${i}`)}const i=milliseconds(n),r=i/1e3;if(r<1)return`${i.toFixed()} milliseconds`;const s=r/60;if(s<1)return`${r.toFixed()} seconds`;const o=s/60;if(o<1)return`${s.toFixed()} minutes`;const a=o/24;if(a<1)return`${o.toFixed()} hours`;const c=a/7;if(c<1)return`${a.toFixed()} days`;const d=c/52;return d<1?`${c.toFixed()} weeks`:`${d.toFixed()} years`}const percentUnitKinds=["Percent","PercentDecimal","%"],percentUnitKindsSet=new Set(percentUnitKinds);function isPercentUnit(e){return percentUnitKindsSet.has(e.kind)}function formatPercent(e,t){var n;const i=null!==(n=t.decimal_places)&&void 0!==n?n:2;return"PercentDecimal"===t.kind&&(e*=100),e.toFixed(i)+"%"}const decimalUnitKinds=["Decimal"],decimalUnitKindsSet=new Set(decimalUnitKinds);function isDecimalUnit(e){return decimalUnitKindsSet.has(e.kind)}function formatDecimal(e,t){var n;const i=null!==(n=t.decimal_places)&&void 0!==n?n:2;if(!0===t.abbreviate)return abbreviateLargeNumber(e,i);const r={style:"decimal",minimumFractionDigits:0,maximumFractionDigits:i,useGrouping:!0};return new Intl.NumberFormat("en-US",r).format(e)}export function abbreviateLargeNumber(e,t=2){return formatNumber(e,(e=>round(e,t)))}export function formatNumber(e,t){const n=null!=t?t:Math.round;return e>=1e12?n(e/1e12)+"T":e>=1e9?n(e/1e9)+"B":e>=1e6?n(e/1e6)+"M":e>=1e3?n(e/1e3)+"K":e.toString()}const bytesUnitKinds=["Bytes"],bytesUnitKindsSet=new Set(bytesUnitKinds);function isBytesUnit(e){return bytesUnitKindsSet.has(e.kind)}function formatBytes(e,t=2){if(0===e)return"0 Bytes";const n=t<0?0:t,i=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,i)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][i]}
1
+ import{milliseconds}from"date-fns";import{round}from"mathjs";export const DEFAULT_DECIMAL_PLACES=2;export function formatValue(e,t){var n;if(void 0===t)return e.toString();if(isDecimalUnit(t))return formatDecimal(e,t);if(isTimeUnit(t))return formatTime(e,t);if(isPercentUnit(t))return formatPercent(e,t);if(isBytesUnit(t))return formatBytes(e,null!==(n=t.decimal_places)&&void 0!==n?n:2);throw new Error(`Unknown unit options ${t}`)}const timeUnitKinds=["Milliseconds","Seconds","Minutes","Hours","Days","Weeks","Months","Years"],timeUnitKindsSet=new Set(timeUnitKinds);function isTimeUnit(e){return timeUnitKindsSet.has(e.kind)}function formatTime(e,t){const n={};switch(t.kind){case"Milliseconds":n.seconds=e/1e3;break;case"Seconds":n.seconds=e;break;case"Minutes":n.minutes=e;break;case"Hours":n.hours=e;break;case"Days":n.days=e;break;case"Weeks":n.weeks=e;break;case"Months":n.months=e;break;case"Years":n.years=e;break;default:const i=t.kind;throw new Error(`Unknown time unit type ${i}`)}const i=milliseconds(n),r=i/1e3;if(r<1)return`${i.toFixed()} milliseconds`;const s=r/60;if(s<1)return`${r.toFixed()} seconds`;const o=s/60;if(o<1)return`${s.toFixed()} minutes`;const a=o/24;if(a<1)return`${o.toFixed()} hours`;const c=a/7;if(c<1)return`${a.toFixed()} days`;const d=c/52;return d<1?`${c.toFixed()} weeks`:`${d.toFixed()} years`}const percentUnitKinds=["Percent","PercentDecimal","%"],percentUnitKindsSet=new Set(percentUnitKinds);function isPercentUnit(e){return percentUnitKindsSet.has(e.kind)}function formatPercent(e,t){var n;const i=null!==(n=t.decimal_places)&&void 0!==n?n:2;return"PercentDecimal"===t.kind&&(e*=100),e.toFixed(i)+"%"}const decimalUnitKinds=["Decimal"],decimalUnitKindsSet=new Set(decimalUnitKinds);function isDecimalUnit(e){return decimalUnitKindsSet.has(e.kind)}function formatDecimal(e,t){var n;const i=null!==(n=t.decimal_places)&&void 0!==n?n:2;if(!0===t.abbreviate)return abbreviateLargeNumber(e,i);const r={style:"decimal",minimumFractionDigits:0,maximumFractionDigits:i,useGrouping:!0};return new Intl.NumberFormat("en-US",r).format(e)}export function abbreviateLargeNumber(e,t=2){return formatNumber(e,(e=>round(e,t)))}export function formatNumber(e,t){const n=null!=t?t:Math.round;return e>=1e12?n(e/1e12)+"T":e>=1e9?n(e/1e9)+"B":e>=1e6?n(e/1e6)+"M":e>=1e3?n(e/1e3)+"K":e.toString()}const bytesUnitKinds=["Bytes"],bytesUnitKindsSet=new Set(bytesUnitKinds);function isBytesUnit(e){return bytesUnitKindsSet.has(e.kind)}function formatBytes(e,t=2){if(0===e)return"0 Bytes";const n=t<0?0:t,i=Math.max(0,Math.floor(Math.log(e)/Math.log(1024)));return parseFloat((e/Math.pow(1024,i)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][i]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/components",
3
- "version": "0.5.1",
3
+ "version": "0.7.0",
4
4
  "description": "Common UI components used across Perses features",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -24,14 +24,17 @@
24
24
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
25
25
  },
26
26
  "dependencies": {
27
- "@perses-dev/core": "^0.5.1",
27
+ "@mui/x-date-pickers": "^5.0.0-beta.1",
28
+ "@perses-dev/core": "^0.7.0",
29
+ "date-fns": "^2.28.0",
28
30
  "echarts": "^5.3.3",
29
31
  "lodash-es": "^4.17.21",
30
32
  "react-error-boundary": "^3.1.4"
31
33
  },
32
34
  "peerDependencies": {
33
35
  "@mui/material": "^5.5.1",
34
- "react": "^17.0.2"
36
+ "react": "^17.0.2",
37
+ "react-dom": "^17.0.2"
35
38
  },
36
39
  "files": [
37
40
  "dist"