@perses-dev/components 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ECharts.d.ts +59 -0
- package/dist/ECharts.d.ts.map +1 -0
- package/dist/ECharts.js +1 -0
- package/dist/GaugeChart.d.ts +14 -0
- package/dist/GaugeChart.d.ts.map +1 -0
- package/dist/GaugeChart.js +1 -0
- package/dist/LineChart.d.ts +22 -0
- package/dist/LineChart.d.ts.map +1 -0
- package/dist/LineChart.js +1 -0
- package/dist/StatChart.d.ts +24 -0
- package/dist/StatChart.d.ts.map +1 -0
- package/dist/StatChart.js +1 -0
- package/dist/cjs/ECharts.js +103 -0
- package/dist/cjs/ErrorAlert.js +25 -0
- package/dist/cjs/ErrorBoundary.js +18 -0
- package/dist/cjs/GaugeChart.js +178 -0
- package/dist/cjs/LineChart.js +227 -0
- package/dist/cjs/StatChart.js +205 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/model/graph-model.js +16 -0
- package/dist/cjs/model/units.js +211 -0
- package/dist/cjs/tooltip/SeriesInfo.js +76 -0
- package/dist/cjs/tooltip/SeriesMarker.js +30 -0
- package/dist/cjs/tooltip/Tooltip.js +99 -0
- package/dist/cjs/tooltip/TooltipContent.js +50 -0
- package/dist/cjs/tooltip/focused-series.js +108 -0
- package/dist/cjs/tooltip/tooltip-model.js +82 -0
- package/dist/cjs/utils/combine-sx.js +30 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/model/graph-model.d.ts +13 -0
- package/dist/model/graph-model.d.ts.map +1 -0
- package/dist/model/graph-model.js +1 -0
- package/dist/model/units.d.ts +25 -0
- package/dist/model/units.d.ts.map +1 -0
- package/dist/model/units.js +1 -0
- package/dist/tooltip/SeriesInfo.d.ts +11 -0
- package/dist/tooltip/SeriesInfo.d.ts.map +1 -0
- package/dist/tooltip/SeriesInfo.js +1 -0
- package/dist/tooltip/SeriesMarker.d.ts +7 -0
- package/dist/tooltip/SeriesMarker.d.ts.map +1 -0
- package/dist/tooltip/SeriesMarker.js +1 -0
- package/dist/tooltip/Tooltip.d.ts +13 -0
- package/dist/tooltip/Tooltip.d.ts.map +1 -0
- package/dist/tooltip/Tooltip.js +1 -0
- package/dist/tooltip/TooltipContent.d.ts +9 -0
- package/dist/tooltip/TooltipContent.d.ts.map +1 -0
- package/dist/tooltip/TooltipContent.js +1 -0
- package/dist/tooltip/focused-series.d.ts +24 -0
- package/dist/tooltip/focused-series.d.ts.map +1 -0
- package/dist/tooltip/focused-series.js +1 -0
- package/dist/tooltip/tooltip-model.d.ts +79 -0
- package/dist/tooltip/tooltip-model.d.ts.map +1 -0
- package/dist/tooltip/tooltip-model.js +1 -0
- package/package.json +7 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TooltipContent.d.ts","sourceRoot":"","sources":["../../src/tooltip/TooltipContent.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGtD,UAAU,mBAAmB;IAC3B,aAAa,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACzC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,eAgExD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsxs as _jsxs,jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useMemo}from"react";import{Box,Divider,Stack,Typography}from"@mui/material";import{SeriesInfo}from"./SeriesInfo";export function TooltipContent(r){const{focusedSeries:e,wrapLabels:t}=r,s=e&&e[0]&&e[0].date?e[0].date:null,o=useMemo((()=>null===e?null:e.sort(((r,e)=>r.y>e.y?-1:1))),[e]);return null!==o&&null!==s?_jsxs(Stack,{py:1,px:1.5,spacing:.5,children:[_jsx(Typography,{variant:"caption",children:(r=>{const[e,t,s]=r.split(",");return _jsxs(_Fragment,{children:[_jsxs(Typography,{variant:"caption",sx:r=>({color:r.palette.common.white}),children:[e,", ",t," –"]}),_jsx(Typography,{variant:"caption",children:_jsx("strong",{children:s})})]})})(s)}),_jsx(Divider,{sx:r=>({borderColor:r.palette.grey[500]})}),_jsx(Box,{sx:{display:"table"},children:o.map((({datumIdx:r,seriesIdx:e,seriesName:s,y:n,markerColor:a})=>{if(null===r||null===e)return null;const i=e.toString()+r.toString();return _jsx(SeriesInfo,{seriesName:s,y:n,markerColor:a,totalSeries:o.length,wrapLabels:t},i)}))})]}):_jsx(_Fragment,{})}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ECharts as EChartsInstance } from 'echarts/core';
|
|
2
|
+
import { EChartsDataFormat } from '../model/graph-model';
|
|
3
|
+
import { CursorData } from './tooltip-model';
|
|
4
|
+
export interface FocusedSeriesInfo {
|
|
5
|
+
seriesIdx: number | null;
|
|
6
|
+
datumIdx: number | null;
|
|
7
|
+
seriesName: string;
|
|
8
|
+
date: string;
|
|
9
|
+
markerColor: string;
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
}
|
|
13
|
+
export declare type FocusedSeriesArray = FocusedSeriesInfo[];
|
|
14
|
+
/**
|
|
15
|
+
* Returns formatted series data for the points that are close to the user's cursor
|
|
16
|
+
* Adjust yBuffer to increase or decrease number of series shown
|
|
17
|
+
*/
|
|
18
|
+
export declare function getNearbySeries(data: EChartsDataFormat, pointInGrid: number[], yBuffer: number): FocusedSeriesArray;
|
|
19
|
+
/**
|
|
20
|
+
* Uses mouse position to determine whether user is hovering over a chart canvas
|
|
21
|
+
* If yes, convert from pixel values to logical cartesian coordinates and return all focused series
|
|
22
|
+
*/
|
|
23
|
+
export declare function getFocusedSeriesData(mousePos: CursorData['coords'], chartData: EChartsDataFormat, pinnedPos: CursorData['coords'], chart?: EChartsInstance): FocusedSeriesArray;
|
|
24
|
+
//# sourceMappingURL=focused-series.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +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[]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { FocusedSeriesArray } from './focused-series';
|
|
2
|
+
export declare const TOOLTIP_MAX_WIDTH = 650;
|
|
3
|
+
export declare const TOOLTIP_MAX_HEIGHT = 230;
|
|
4
|
+
export declare const TOOLTIP_LABELS_MAX_WIDTH: number;
|
|
5
|
+
export declare const TOOLTIP_MAX_ITEMS = 50;
|
|
6
|
+
export declare const TOOLTIP_DATE_FORMAT: Intl.DateTimeFormat;
|
|
7
|
+
export declare const defaultCursorData: {
|
|
8
|
+
coords: {
|
|
9
|
+
viewport: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
};
|
|
13
|
+
plotCanvas: {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
};
|
|
17
|
+
zrender: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
};
|
|
21
|
+
target: null;
|
|
22
|
+
};
|
|
23
|
+
chartWidth: number;
|
|
24
|
+
};
|
|
25
|
+
export declare const emptyTooltipData: {
|
|
26
|
+
cursor: {
|
|
27
|
+
coords: {
|
|
28
|
+
viewport: {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
};
|
|
32
|
+
plotCanvas: {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
};
|
|
36
|
+
zrender: {
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
};
|
|
40
|
+
target: null;
|
|
41
|
+
};
|
|
42
|
+
chartWidth: number;
|
|
43
|
+
};
|
|
44
|
+
focusedSeries: null;
|
|
45
|
+
};
|
|
46
|
+
export interface CursorCoordinates {
|
|
47
|
+
viewport: {
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
};
|
|
51
|
+
plotCanvas: {
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
};
|
|
55
|
+
zrender: {
|
|
56
|
+
x?: number;
|
|
57
|
+
y?: number;
|
|
58
|
+
};
|
|
59
|
+
target: EventTarget | null;
|
|
60
|
+
}
|
|
61
|
+
export interface CursorData {
|
|
62
|
+
coords: CursorCoordinates | null;
|
|
63
|
+
chartWidth?: number;
|
|
64
|
+
}
|
|
65
|
+
export interface TooltipData {
|
|
66
|
+
focusedSeries: FocusedSeriesArray | null;
|
|
67
|
+
cursor: CursorData;
|
|
68
|
+
}
|
|
69
|
+
declare type ZREventProperties = {
|
|
70
|
+
zrX?: number;
|
|
71
|
+
zrY?: number;
|
|
72
|
+
zrDelta?: number;
|
|
73
|
+
zrEventControl?: 'no_globalout' | 'only_globalout';
|
|
74
|
+
zrByTouch?: boolean;
|
|
75
|
+
};
|
|
76
|
+
export declare type ZRRawMouseEvent = MouseEvent & ZREventProperties;
|
|
77
|
+
export declare const useMousePosition: () => CursorData['coords'];
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=tooltip-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip-model.d.ts","sourceRoot":"","sources":["../../src/tooltip/tooltip-model.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,wBAAwB,QAA0B,CAAC;AAEhE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,eAAO,MAAM,mBAAmB,qBAQ9B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;CAiB7B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;CAG5B,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE;QACR,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;IACF,UAAU,EAAE;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;IACF,OAAO,EAAE;QACP,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;KACZ,CAAC;IACF,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACzC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,aAAK,iBAAiB,GAAG;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,cAAc,GAAG,gBAAgB,CAAC;IACnD,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,oBAAY,eAAe,GAAG,UAAU,GAAG,iBAAiB,CAAC;AAE7D,eAAO,MAAM,gBAAgB,QAAO,UAAU,CAAC,QAAQ,CAgCtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect,useState}from"react";export const TOOLTIP_MAX_WIDTH=650;export const TOOLTIP_MAX_HEIGHT=230;export const TOOLTIP_LABELS_MAX_WIDTH=500;export const TOOLTIP_MAX_ITEMS=50;export const TOOLTIP_DATE_FORMAT=new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric",hour12:!0});export const defaultCursorData={coords:{viewport:{x:0,y:0},plotCanvas:{x:0,y:0},zrender:{x:0,y:0},target:null},chartWidth:0};export const emptyTooltipData={cursor:defaultCursorData,focusedSeries:null};export const useMousePosition=()=>{const[e,t]=useState(null);return useEffect((()=>{const e=e=>t({viewport:{x:e.clientX,y:e.clientY},plotCanvas:{x:e.offsetX,y:e.offsetY},zrender:{x:e.zrX,y:e.zrY},target:e.target});return window.addEventListener("mousemove",e),()=>{window.removeEventListener("mousemove",e)}}),[]),e};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
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",
|
|
@@ -12,19 +12,23 @@
|
|
|
12
12
|
"url": "https://github.com/perses/perses/issues"
|
|
13
13
|
},
|
|
14
14
|
"module": "dist/index.js",
|
|
15
|
+
"main": "dist/cjs/index.js",
|
|
15
16
|
"types": "dist/index.d.ts",
|
|
16
17
|
"scripts": {
|
|
17
18
|
"clean": "rimraf dist/",
|
|
18
|
-
"build": "tsc",
|
|
19
|
+
"build": "tsc --build",
|
|
20
|
+
"build:cjs": "tsc --project ./tsconfig.cjs.json",
|
|
19
21
|
"test": "echo 'no test to run' && exit 0",
|
|
20
22
|
"lint": "eslint src --ext .ts,.tsx",
|
|
21
23
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
22
24
|
},
|
|
23
25
|
"dependencies": {
|
|
24
|
-
"
|
|
26
|
+
"echarts": "^5.3.2",
|
|
27
|
+
"lodash-es": "^4.17.21",
|
|
25
28
|
"react-error-boundary": "^3.1.4"
|
|
26
29
|
},
|
|
27
30
|
"peerDependencies": {
|
|
31
|
+
"@mui/material": "^5.5.1",
|
|
28
32
|
"react": "^17.0.2"
|
|
29
33
|
},
|
|
30
34
|
"files": [
|