@perses-dev/components 0.3.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/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/model/units.d.ts +4 -0
- package/dist/model/units.d.ts.map +1 -1
- package/dist/model/units.js +1 -1
- package/dist/tooltip/SeriesInfo.js +1 -1
- package/dist/tooltip/TooltipContent.js +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TooltipContent = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
// Copyright 2021 The Perses Authors
|
|
6
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
// you may not use this file except in compliance with the License.
|
|
8
|
+
// You may obtain a copy of the License at
|
|
9
|
+
//
|
|
10
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
//
|
|
12
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
// See the License for the specific language governing permissions and
|
|
16
|
+
// limitations under the License.
|
|
17
|
+
const react_1 = require("react");
|
|
18
|
+
const material_1 = require("@mui/material");
|
|
19
|
+
const SeriesInfo_1 = require("./SeriesInfo");
|
|
20
|
+
function TooltipContent(props) {
|
|
21
|
+
const { focusedSeries, wrapLabels } = props;
|
|
22
|
+
const seriesTime = focusedSeries && focusedSeries[0] && focusedSeries[0].date ? focusedSeries[0].date : null;
|
|
23
|
+
const formatTimeSeriesHeader = (timeString) => {
|
|
24
|
+
const [month, year, time] = timeString.split(',');
|
|
25
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "caption", sx: (theme) => ({
|
|
26
|
+
color: theme.palette.common.white,
|
|
27
|
+
}), children: [month, ", ", year, " \u2013"] }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "caption", children: (0, jsx_runtime_1.jsx)("strong", { children: time }) })] }));
|
|
28
|
+
};
|
|
29
|
+
const sortedFocusedSeries = (0, react_1.useMemo)(() => {
|
|
30
|
+
if (focusedSeries === null)
|
|
31
|
+
return null;
|
|
32
|
+
return focusedSeries.sort((a, b) => (a.y > b.y ? -1 : 1));
|
|
33
|
+
}, [focusedSeries]);
|
|
34
|
+
if (sortedFocusedSeries !== null && seriesTime !== null) {
|
|
35
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { py: 1, px: 1.5, spacing: 0.5, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "caption", children: formatTimeSeriesHeader(seriesTime) }), (0, jsx_runtime_1.jsx)(material_1.Divider, { sx: (theme) => ({
|
|
36
|
+
borderColor: theme.palette.grey['500'],
|
|
37
|
+
}) }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
38
|
+
display: 'table',
|
|
39
|
+
}, children: sortedFocusedSeries.map(({ datumIdx, seriesIdx, seriesName, y, markerColor }) => {
|
|
40
|
+
if (datumIdx === null || seriesIdx === null)
|
|
41
|
+
return null;
|
|
42
|
+
const key = seriesIdx.toString() + datumIdx.toString();
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(SeriesInfo_1.SeriesInfo, { seriesName: seriesName, y: y, markerColor: markerColor, totalSeries: sortedFocusedSeries.length, wrapLabels: wrapLabels }, key));
|
|
44
|
+
}) })] }));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.TooltipContent = TooltipContent;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getFocusedSeriesData = exports.getNearbySeries = void 0;
|
|
16
|
+
const tooltip_model_1 = require("./tooltip-model");
|
|
17
|
+
/**
|
|
18
|
+
* Returns formatted series data for the points that are close to the user's cursor
|
|
19
|
+
* Adjust yBuffer to increase or decrease number of series shown
|
|
20
|
+
*/
|
|
21
|
+
function getNearbySeries(data, pointInGrid, yBuffer) {
|
|
22
|
+
var _a, _b, _c, _d, _e;
|
|
23
|
+
const currentFocusedData = [];
|
|
24
|
+
const focusedX = (_a = pointInGrid[0]) !== null && _a !== void 0 ? _a : null;
|
|
25
|
+
const focusedY = (_b = pointInGrid[1]) !== null && _b !== void 0 ? _b : null;
|
|
26
|
+
if (focusedX === null || focusedY === null) {
|
|
27
|
+
return currentFocusedData;
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(data.xAxis) && Array.isArray(data.timeSeries)) {
|
|
30
|
+
for (let seriesIdx = 0; seriesIdx < data.timeSeries.length; seriesIdx++) {
|
|
31
|
+
const currentSeries = data.timeSeries[seriesIdx];
|
|
32
|
+
if (currentFocusedData.length > tooltip_model_1.TOOLTIP_MAX_ITEMS)
|
|
33
|
+
break;
|
|
34
|
+
if (currentSeries !== undefined) {
|
|
35
|
+
const currentSeriesName = currentSeries.name ? currentSeries.name.toString() : '';
|
|
36
|
+
const markerColor = (_c = currentSeries.color) !== null && _c !== void 0 ? _c : '#000';
|
|
37
|
+
if (Array.isArray(currentSeries.data)) {
|
|
38
|
+
for (let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++) {
|
|
39
|
+
const xValue = (_d = data.xAxis[datumIdx]) !== null && _d !== void 0 ? _d : 0;
|
|
40
|
+
const yValue = (_e = currentSeries.data[datumIdx]) !== null && _e !== void 0 ? _e : 0;
|
|
41
|
+
if (focusedX === datumIdx) {
|
|
42
|
+
if (yValue !== '-' && focusedY <= yValue + yBuffer && focusedY >= yValue - yBuffer) {
|
|
43
|
+
const formattedDate = tooltip_model_1.TOOLTIP_DATE_FORMAT.format(xValue * 1000);
|
|
44
|
+
currentFocusedData.push({
|
|
45
|
+
seriesIdx: seriesIdx,
|
|
46
|
+
datumIdx: datumIdx,
|
|
47
|
+
seriesName: currentSeriesName,
|
|
48
|
+
date: formattedDate,
|
|
49
|
+
x: xValue,
|
|
50
|
+
y: yValue,
|
|
51
|
+
markerColor: markerColor.toString(),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return currentFocusedData;
|
|
61
|
+
}
|
|
62
|
+
exports.getNearbySeries = getNearbySeries;
|
|
63
|
+
/**
|
|
64
|
+
* Uses mouse position to determine whether user is hovering over a chart canvas
|
|
65
|
+
* If yes, convert from pixel values to logical cartesian coordinates and return all focused series
|
|
66
|
+
*/
|
|
67
|
+
function getFocusedSeriesData(mousePos, chartData, pinnedPos, chart) {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
if (chart === undefined || mousePos === null)
|
|
70
|
+
return [];
|
|
71
|
+
// prevents multiple tooltips showing from adjacent charts
|
|
72
|
+
let cursorTargetMatchesChart = false;
|
|
73
|
+
if (mousePos.target !== null) {
|
|
74
|
+
const currentParent = mousePos.target.parentElement;
|
|
75
|
+
if (currentParent !== null) {
|
|
76
|
+
const currentGrandparent = currentParent.parentElement;
|
|
77
|
+
if (currentGrandparent !== null) {
|
|
78
|
+
const chartDom = chart.getDom();
|
|
79
|
+
if (chartDom === currentGrandparent) {
|
|
80
|
+
cursorTargetMatchesChart = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// allows moving cursor inside tooltip
|
|
86
|
+
if (pinnedPos !== null) {
|
|
87
|
+
mousePos = pinnedPos;
|
|
88
|
+
cursorTargetMatchesChart = true;
|
|
89
|
+
}
|
|
90
|
+
if (cursorTargetMatchesChart === false)
|
|
91
|
+
return [];
|
|
92
|
+
if (chart['_model'] === undefined)
|
|
93
|
+
return [];
|
|
94
|
+
const chartModel = chart['_model'];
|
|
95
|
+
const yAxisInterval = chartModel.getComponent('yAxis').axis.scale._interval;
|
|
96
|
+
const seriesNum = chartData.timeSeries.length;
|
|
97
|
+
// tooltip trigger area gets smaller with more series
|
|
98
|
+
const yBuffer = seriesNum > tooltip_model_1.TOOLTIP_MAX_ITEMS ? yAxisInterval * 0.5 : yAxisInterval * 2;
|
|
99
|
+
const pointInPixel = [(_a = mousePos.plotCanvas.x) !== null && _a !== void 0 ? _a : 0, (_b = mousePos.plotCanvas.y) !== null && _b !== void 0 ? _b : 0];
|
|
100
|
+
if (chart.containPixel('grid', pointInPixel)) {
|
|
101
|
+
const pointInGrid = chart.convertFromPixel('grid', pointInPixel);
|
|
102
|
+
if (pointInGrid[0] !== undefined && pointInGrid[1] !== undefined) {
|
|
103
|
+
return getNearbySeries(chartData, pointInGrid, yBuffer);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
exports.getFocusedSeriesData = getFocusedSeriesData;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.useMousePosition = exports.emptyTooltipData = exports.defaultCursorData = exports.TOOLTIP_DATE_FORMAT = exports.TOOLTIP_MAX_ITEMS = exports.TOOLTIP_LABELS_MAX_WIDTH = exports.TOOLTIP_MAX_HEIGHT = exports.TOOLTIP_MAX_WIDTH = void 0;
|
|
16
|
+
const react_1 = require("react");
|
|
17
|
+
exports.TOOLTIP_MAX_WIDTH = 650;
|
|
18
|
+
exports.TOOLTIP_MAX_HEIGHT = 230;
|
|
19
|
+
exports.TOOLTIP_LABELS_MAX_WIDTH = exports.TOOLTIP_MAX_WIDTH - 150;
|
|
20
|
+
exports.TOOLTIP_MAX_ITEMS = 50;
|
|
21
|
+
exports.TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
|
|
22
|
+
year: 'numeric',
|
|
23
|
+
month: 'short',
|
|
24
|
+
day: 'numeric',
|
|
25
|
+
hour: 'numeric',
|
|
26
|
+
minute: 'numeric',
|
|
27
|
+
second: 'numeric',
|
|
28
|
+
hour12: true,
|
|
29
|
+
});
|
|
30
|
+
exports.defaultCursorData = {
|
|
31
|
+
coords: {
|
|
32
|
+
viewport: {
|
|
33
|
+
x: 0,
|
|
34
|
+
y: 0,
|
|
35
|
+
},
|
|
36
|
+
plotCanvas: {
|
|
37
|
+
x: 0,
|
|
38
|
+
y: 0,
|
|
39
|
+
},
|
|
40
|
+
zrender: {
|
|
41
|
+
x: 0,
|
|
42
|
+
y: 0,
|
|
43
|
+
},
|
|
44
|
+
target: null,
|
|
45
|
+
},
|
|
46
|
+
chartWidth: 0,
|
|
47
|
+
};
|
|
48
|
+
exports.emptyTooltipData = {
|
|
49
|
+
cursor: exports.defaultCursorData,
|
|
50
|
+
focusedSeries: null,
|
|
51
|
+
};
|
|
52
|
+
const useMousePosition = () => {
|
|
53
|
+
const [coords, setCoords] = (0, react_1.useState)(null);
|
|
54
|
+
(0, react_1.useEffect)(() => {
|
|
55
|
+
const setFromEvent = (e) => {
|
|
56
|
+
return setCoords({
|
|
57
|
+
viewport: {
|
|
58
|
+
x: e.clientX,
|
|
59
|
+
y: e.clientY,
|
|
60
|
+
},
|
|
61
|
+
plotCanvas: {
|
|
62
|
+
x: e.offsetX,
|
|
63
|
+
y: e.offsetY,
|
|
64
|
+
},
|
|
65
|
+
zrender: {
|
|
66
|
+
// echarts canvas coordinates added automatically by zrender
|
|
67
|
+
// zrX and zrY are similar to offsetX and offsetY but they return undefined when not hovering over a chart canvas
|
|
68
|
+
x: e.zrX,
|
|
69
|
+
y: e.zrY,
|
|
70
|
+
},
|
|
71
|
+
// necessary to check whether cursor target matches correct chart canvas (since each chart has its own mousemove listener)
|
|
72
|
+
target: e.target,
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
window.addEventListener('mousemove', setFromEvent);
|
|
76
|
+
return () => {
|
|
77
|
+
window.removeEventListener('mousemove', setFromEvent);
|
|
78
|
+
};
|
|
79
|
+
}, []);
|
|
80
|
+
return coords;
|
|
81
|
+
};
|
|
82
|
+
exports.useMousePosition = useMousePosition;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.combineSx = void 0;
|
|
16
|
+
/**
|
|
17
|
+
* Combines sx props from multiple sources. Useful when creating a component and
|
|
18
|
+
* you want consumers to be able to provide SxProps that should be combined with
|
|
19
|
+
* some built-in styles.
|
|
20
|
+
*/
|
|
21
|
+
function combineSx(...sxProps) {
|
|
22
|
+
return sxProps.flatMap((sx) => {
|
|
23
|
+
if (sx === undefined)
|
|
24
|
+
return [];
|
|
25
|
+
if (Array.isArray(sx))
|
|
26
|
+
return sx;
|
|
27
|
+
return [sx];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.combineSx = combineSx;
|
package/dist/model/units.d.ts
CHANGED
|
@@ -17,5 +17,9 @@ declare type DecimalUnitOptions = {
|
|
|
17
17
|
unitDisplay?: 'short' | 'long' | 'narrow';
|
|
18
18
|
};
|
|
19
19
|
export declare function abbreviateLargeNumber(num: number): string | number;
|
|
20
|
+
export declare function isSanctionedSimpleUnitIdentifier(unitIdentifier: string): boolean;
|
|
21
|
+
export declare const SANCTIONED_UNITS: string[];
|
|
22
|
+
export declare function removeUnitNamespace(unit: string): string;
|
|
23
|
+
export declare const SIMPLE_UNITS: string[];
|
|
20
24
|
export {};
|
|
21
25
|
//# sourceMappingURL=units.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/model/units.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/model/units.ts"],"names":[],"mappings":"AAeA,oBAAY,WAAW,GAAG,eAAe,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAEpF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,MAAM,CAmB5E;AAED,QAAA,MAAM,aAAa,8FAA+F,CAAC;AAGnH,aAAK,eAAe,GAAG;IACrB,IAAI,EAAE,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;CACpC,CAAC;AA0EF,QAAA,MAAM,gBAAgB,wCAAyC,CAAC;AAGhE,aAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtC,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAcF,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAG9C,aAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtC,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;CAC3C,CAAC;AAkCF,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,mBAUhD;AAGD,wBAAgB,gCAAgC,CAAC,cAAc,EAAE,MAAM,WAEtE;AAGD,eAAO,MAAM,gBAAgB,UA4C5B,CAAC;AAGF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,UAE/C;AAED,eAAO,MAAM,YAAY,UAA4C,CAAC"}
|
package/dist/model/units.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{milliseconds}from"date-fns";export function formatValue(e,i){if(void 0===i)return e.toString();if(isTimeUnit(i))return formatTime(e,i);if(isPercentUnit(i))return formatPercent(e,i);if(isDecimalUnit(i))return formatDecimal(e,i);throw new Error(`Unknown unit options ${i}`)}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,i){const t={};switch(i.kind){case"Milliseconds":t.seconds=e/1e3;break;case"Seconds":t.seconds=e;break;case"Minutes":t.minutes=e;break;case"Hours":t.hours=e;break;case"Days":t.days=e;break;case"Weeks":t.weeks=e;break;case"Months":t.months=e;break;case"Years":t.years=e;break;default:const n=i.kind;throw new Error(`Unknown time unit type ${n}`)}const n=milliseconds(t),r=n/1e3;if(r<1)return`${n.toFixed()} milliseconds`;const a=r/60;if(a<1)return`${r.toFixed()} seconds`;const s=a/60;if(s<1)return`${a.toFixed()} minutes`;const o=s/24;if(o<1)return`${s.toFixed()} hours`;const c=o/7;if(c<1)return`${o.toFixed()} days`;const m=c/52;return m<1?`${c.toFixed()} weeks`:`${m.toFixed()} years`}const percentUnitKinds=["Percent","PercentDecimal"],percentUnitKindsSet=new Set(percentUnitKinds);function isPercentUnit(e){return percentUnitKindsSet.has(e.kind)}function formatPercent(e,i){return"PercentDecimal"===i.kind&&(e*=100),e.toFixed(i.decimal_places)+"%"}const decimalUnitKinds=["Decimal"],decimalUnitKindsSet=new Set(decimalUnitKinds);function isDecimalUnit(e){return decimalUnitKindsSet.has(e.kind)}function formatDecimal(e,i){var t,n;const r=null!==(t=i.decimal_places)&&void 0!==t?t:2;if(void 0!==i.suffix&&isSanctionedSimpleUnitIdentifier(i.suffix)){const t={style:"unit",minimumFractionDigits:0,maximumFractionDigits:r,useGrouping:!0,unit:i.suffix,unitDisplay:null!==(n=i.unitDisplay)&&void 0!==n?n:"narrow"};return new Intl.NumberFormat("en-US",t).format(e)}const a={style:"decimal",minimumFractionDigits:0,maximumFractionDigits:r,useGrouping:!0};return new Intl.NumberFormat("en-US",a).format(e)}export function abbreviateLargeNumber(e){return e>=1e12?e/1e12+"T":e>=1e9?e/1e9+"B":e>=1e6?e/1e6+"M":e>=1e3?e/1e3+"k":e}export function isSanctionedSimpleUnitIdentifier(e){return SIMPLE_UNITS.indexOf(e)>-1}export const SANCTIONED_UNITS=["angle-degree","area-acre","area-hectare","concentr-percent","digital-bit","digital-byte","digital-gigabit","digital-gigabyte","digital-kilobit","digital-kilobyte","digital-megabit","digital-megabyte","digital-petabyte","digital-terabit","digital-terabyte","duration-day","duration-hour","duration-millisecond","duration-minute","duration-month","duration-second","duration-week","duration-year","length-centimeter","length-foot","length-inch","length-kilometer","length-meter","length-mile-scandinavian","length-mile","length-millimeter","length-yard","mass-gram","mass-kilogram","mass-ounce","mass-pound","mass-stone","temperature-celsius","temperature-fahrenheit","volume-fluid-ounce","volume-gallon","volume-liter","volume-milliliter"];export function removeUnitNamespace(e){return e.slice(e.indexOf("-")+1)}export const SIMPLE_UNITS=SANCTIONED_UNITS.map(removeUnitNamespace);
|
|
@@ -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:
|
|
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 +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:
|
|
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,{})}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/components",
|
|
3
|
-
"version": "0.3.
|
|
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,10 +12,12 @@
|
|
|
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"
|