@perses-dev/components 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +1 -1
- package/dist/Tooltip/Tooltip.d.ts +2 -4
- package/dist/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip/Tooltip.js +1 -1
- package/dist/Tooltip/focused-series.js +1 -1
- package/dist/Tooltip/tooltip-model.d.ts +1 -1
- package/dist/Tooltip/tooltip-model.js +1 -1
- package/dist/Tooltip/utils.d.ts +6 -0
- package/dist/Tooltip/utils.d.ts.map +1 -0
- package/dist/Tooltip/utils.js +1 -0
- package/dist/cjs/LineChart/LineChart.js +1 -2
- package/dist/cjs/Tooltip/Tooltip.js +33 -40
- package/dist/cjs/Tooltip/focused-series.js +1 -1
- package/dist/cjs/Tooltip/tooltip-model.js +1 -1
- package/dist/cjs/Tooltip/utils.js +53 -0
- package/package.json +2 -2
|
@@ -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;
|
|
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,eAwIpG"}
|
|
@@ -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{
|
|
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=useMemo((()=>({datazoom:e=>{var t,r;if(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]);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:n,visualMap:a}}),[o,r,n,a]);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,chartData:o,wrapLabels:!0}),_jsx(EChart,{sx:{width:"100%",height:"100%"},option:h,theme:s.themeName,onEvents:u,_instance:m})]})}
|
|
@@ -1,13 +1,11 @@
|
|
|
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;
|
|
9
7
|
wrapLabels?: boolean;
|
|
10
8
|
}
|
|
11
|
-
|
|
12
|
-
export {};
|
|
9
|
+
declare const Tooltip: React.NamedExoticComponent<TooltipProps>;
|
|
10
|
+
export { Tooltip };
|
|
13
11
|
//# 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;
|
|
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,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,QAAA,MAAM,OAAO,0CA+DX,CAAC;AAEH,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/Tooltip/Tooltip.js
CHANGED
|
@@ -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";
|
|
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}){var r,l;const[i,n]=useState(null),s=useMousePosition();if(null===s||null===s.target)return null;if("CANVAS"!==s.target.tagName)return null;const a=o.current,u=getFocusedSeriesData(s,t,i,a),m=null!==(r=null==a?void 0:a.getWidth())&&void 0!==r?r:750,f=null!==(l=null==a?void 0:a.getHeight())&&void 0!==l?l:230,p=assembleTransform(s,u.length,m,f,i);return 0===u.length?null:_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:p},onMouseEnter:()=>{null!==s&&n(s)},onMouseLeave:()=>{null!==i&&n(null)},children:_jsx(TooltipContent,{focusedSeries:u,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
|
|
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[]}
|
|
@@ -2,7 +2,7 @@ import { FocusedSeriesArray } from './focused-series';
|
|
|
2
2
|
export declare const TOOLTIP_MAX_WIDTH = 650;
|
|
3
3
|
export declare const TOOLTIP_MAX_HEIGHT = 230;
|
|
4
4
|
export declare const TOOLTIP_LABELS_MAX_WIDTH: number;
|
|
5
|
-
export declare const TOOLTIP_MAX_ITEMS =
|
|
5
|
+
export declare const TOOLTIP_MAX_ITEMS = 20;
|
|
6
6
|
export declare const TOOLTIP_DATE_FORMAT: Intl.DateTimeFormat;
|
|
7
7
|
export declare const defaultCursorData: {
|
|
8
8
|
coords: {
|
|
@@ -1 +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=
|
|
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=20;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};
|
|
@@ -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)`}
|
|
@@ -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)([
|
|
@@ -146,7 +145,7 @@ function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom })
|
|
|
146
145
|
}, [data, grid, legend, visualMap]);
|
|
147
146
|
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
148
147
|
height,
|
|
149
|
-
}, onDoubleClick: handleOnDoubleClick, onMouseDown: handleOnMouseDown, onMouseUp: handleOnMouseUp, onMouseLeave: handleOnMouseLeave, onMouseEnter: handleOnMouseEnter, children: [showTooltip === true && (
|
|
148
|
+
}, 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 }), (0, jsx_runtime_1.jsx)(EChart_1.EChart, { sx: {
|
|
150
149
|
width: '100%',
|
|
151
150
|
height: '100%',
|
|
152
151
|
}, option: option, theme: chartsTheme.themeName, onEvents: handleEvents, _instance: chartRef })] }));
|
|
@@ -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,23 +37,26 @@ 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
|
-
|
|
45
|
+
const utils_1 = require("./utils");
|
|
46
|
+
const Tooltip = react_1.default.memo(function Tooltip({ chartRef, chartData, wrapLabels }) {
|
|
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 (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);
|
|
59
|
+
const cursorTransform = (0, utils_1.assembleTransform)(mousePos, focusedSeries.length, chartWidth, chartHeight, pinnedPos);
|
|
34
60
|
function handleMouseEnter() {
|
|
35
61
|
if (mousePos !== null) {
|
|
36
62
|
setPinnedPos(mousePos);
|
|
@@ -64,39 +90,6 @@ function Tooltip(props) {
|
|
|
64
90
|
},
|
|
65
91
|
}), style: {
|
|
66
92
|
transform: cursorTransform,
|
|
67
|
-
}, onMouseEnter: () => handleMouseEnter(), onMouseLeave: () => handleMouseLeave(), children: (0, jsx_runtime_1.jsx)(TooltipContent_1.TooltipContent, { focusedSeries: focusedSeries, wrapLabels:
|
|
68
|
-
}
|
|
93
|
+
}, onMouseEnter: () => handleMouseEnter(), onMouseLeave: () => handleMouseLeave(), children: (0, jsx_runtime_1.jsx)(TooltipContent_1.TooltipContent, { focusedSeries: focusedSeries, wrapLabels: wrapLabels }) }) }));
|
|
94
|
+
});
|
|
69
95
|
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
|
|
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() : '';
|
|
@@ -17,7 +17,7 @@ const react_1 = require("react");
|
|
|
17
17
|
exports.TOOLTIP_MAX_WIDTH = 650;
|
|
18
18
|
exports.TOOLTIP_MAX_HEIGHT = 230;
|
|
19
19
|
exports.TOOLTIP_LABELS_MAX_WIDTH = exports.TOOLTIP_MAX_WIDTH - 150;
|
|
20
|
-
exports.TOOLTIP_MAX_ITEMS =
|
|
20
|
+
exports.TOOLTIP_MAX_ITEMS = 20;
|
|
21
21
|
exports.TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
|
|
22
22
|
year: 'numeric',
|
|
23
23
|
month: 'short',
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/components",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Common UI components used across Perses features",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@perses-dev/core": "^0.5.
|
|
27
|
+
"@perses-dev/core": "^0.5.2",
|
|
28
28
|
"echarts": "^5.3.3",
|
|
29
29
|
"lodash-es": "^4.17.21",
|
|
30
30
|
"react-error-boundary": "^3.1.4"
|