@perses-dev/components 0.31.0 → 0.32.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.
- package/dist/ContentWithLegend/ContentWithLegend.d.ts +11 -0
- package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -0
- package/dist/ContentWithLegend/ContentWithLegend.js +65 -0
- package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -0
- package/dist/ContentWithLegend/index.d.ts +2 -0
- package/dist/ContentWithLegend/index.d.ts.map +1 -0
- package/dist/ContentWithLegend/index.js +15 -0
- package/dist/ContentWithLegend/index.js.map +1 -0
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +68 -0
- package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -0
- package/dist/ContentWithLegend/model/content-with-legend-model.js +90 -0
- package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -0
- package/dist/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +9 -1
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/Legend/Legend.d.ts.map +1 -1
- package/dist/Legend/Legend.js +30 -15
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/ListLegend.d.ts.map +1 -1
- package/dist/Legend/ListLegend.js +2 -23
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.d.ts +1 -1
- package/dist/Legend/TableLegend.d.ts +12 -0
- package/dist/Legend/TableLegend.d.ts.map +1 -0
- package/dist/Legend/TableLegend.js +61 -0
- package/dist/Legend/TableLegend.js.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js +35 -3
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +60 -22
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +8 -1
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +5 -5
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +36 -54
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts +0 -2
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +21 -97
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +12 -0
- package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -0
- package/dist/TimeSeriesTooltip/TooltipHeader.js +163 -0
- package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -0
- package/dist/TimeSeriesTooltip/index.d.ts +1 -0
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +1 -0
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -2
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.js +2 -2
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +10 -14
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +2 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/utils.js +2 -2
- package/dist/TimeSeriesTooltip/utils.js.map +1 -1
- package/dist/cjs/ContentWithLegend/ContentWithLegend.js +70 -0
- package/dist/cjs/ContentWithLegend/index.js +28 -0
- package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +100 -0
- package/dist/cjs/EChart/EChart.js +9 -1
- package/dist/cjs/Legend/Legend.js +30 -15
- package/dist/cjs/Legend/ListLegend.js +2 -23
- package/dist/cjs/Legend/TableLegend.js +67 -0
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +34 -2
- package/dist/cjs/LineChart/LineChart.js +60 -22
- package/dist/cjs/StatChart/StatChart.js +8 -1
- package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +34 -91
- package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +19 -100
- package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +174 -0
- package/dist/cjs/TimeSeriesTooltip/index.js +1 -0
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -2
- package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +3 -1
- package/dist/cjs/TimeSeriesTooltip/utils.js +2 -2
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/model/legend.js +30 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model/legend.d.ts +9 -3
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +26 -1
- package/dist/model/legend.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ECharts as EChartsInstance } from 'echarts/core';
|
|
2
2
|
import { UnitOptions, EChartsDataFormat } from '../model';
|
|
3
|
-
import { CursorData } from './tooltip-model';
|
|
3
|
+
import { CursorCoordinates, CursorData } from './tooltip-model';
|
|
4
4
|
export declare const INCREASE_NEARBY_SERIES_MULTIPLIER = 5.5;
|
|
5
5
|
export declare const DYNAMIC_NEARBY_SERIES_MULTIPLIER = 30;
|
|
6
6
|
export declare const SHOW_FEWER_SERIES_LIMIT = 5;
|
|
@@ -27,7 +27,7 @@ export declare function checkforNearbySeries(data: EChartsDataFormat, pointInGri
|
|
|
27
27
|
*/
|
|
28
28
|
export declare function getNearbySeriesData({ mousePos, pinnedPos, chartData, chart, unit, showAllSeries, }: {
|
|
29
29
|
mousePos: CursorData['coords'];
|
|
30
|
-
pinnedPos:
|
|
30
|
+
pinnedPos: CursorCoordinates | null;
|
|
31
31
|
chartData: EChartsDataFormat;
|
|
32
32
|
chart?: EChartsInstance;
|
|
33
33
|
unit?: UnitOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nearby-series.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/nearby-series.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAe,WAAW,EAAE,iBAAiB,EAA+B,MAAM,UAAU,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"nearby-series.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/nearby-series.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAe,WAAW,EAAE,iBAAiB,EAA+B,MAAM,UAAU,CAAC;AACpG,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGhE,eAAO,MAAM,iCAAiC,MAAM,CAAC;AACrD,eAAO,MAAM,gCAAgC,KAAK,CAAC;AACnD,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,MAAM,WAAW,gBAAgB;IAC/B,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;IACV,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,oBAAY,iBAAiB,GAAG,gBAAgB,EAAE,CAAC;AAEnD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,iBAAiB,EACvB,WAAW,EAAE,MAAM,EAAE,EACrB,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,eAAe,EACvB,IAAI,CAAC,EAAE,WAAW,GACjB,iBAAiB,CAiGnB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,SAAS,EACT,SAAS,EACT,KAAK,EACL,IAAI,EACJ,aAAqB,GACtB,EAAE;IACD,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC/B,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACpC,SAAS,EAAE,iBAAiB,CAAC;IAC7B,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,qBAkDA;AAKD,wBAAgB,uBAAuB,CAAC,EACtC,YAAY,EACZ,SAAS,EACT,UAAU,GACX,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAKV;AAKD,wBAAgB,UAAU,CAAC,EACzB,SAAS,EACT,WAAW,EACX,aAAqB,GACtB,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,UAgBA"}
|
|
@@ -120,7 +120,7 @@ export const SHOW_FEWER_SERIES_LIMIT = 5;
|
|
|
120
120
|
* If yes, convert from pixel values to logical cartesian coordinates and return all nearby series
|
|
121
121
|
*/ export function getNearbySeriesData({ mousePos , pinnedPos , chartData , chart , unit , showAllSeries =false }) {
|
|
122
122
|
if (chart === undefined || mousePos === null) return [];
|
|
123
|
-
// prevents multiple tooltips showing from adjacent charts
|
|
123
|
+
// prevents multiple tooltips showing from adjacent charts unless tooltip is pinned
|
|
124
124
|
let cursorTargetMatchesChart = false;
|
|
125
125
|
if (mousePos.target !== null) {
|
|
126
126
|
const currentParent = mousePos.target.parentElement;
|
|
@@ -134,7 +134,7 @@ export const SHOW_FEWER_SERIES_LIMIT = 5;
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
// allows moving cursor inside tooltip
|
|
137
|
+
// allows moving cursor inside tooltip without it fading away
|
|
138
138
|
if (pinnedPos !== null) {
|
|
139
139
|
mousePos = pinnedPos;
|
|
140
140
|
cursorTargetMatchesChart = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/nearby-series.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ECharts as EChartsInstance } from 'echarts/core';\nimport { formatValue, UnitOptions, EChartsDataFormat, OPTIMIZED_MODE_SERIES_LIMIT } from '../model';\nimport { CursorData } from './tooltip-model';\n\n// increase multipliers to show more series in tooltip\nexport const INCREASE_NEARBY_SERIES_MULTIPLIER = 5.5; // adjusts how many series show in tooltip (higher == more series shown)\nexport const DYNAMIC_NEARBY_SERIES_MULTIPLIER = 30; // used for adjustment after series number divisor\nexport const SHOW_FEWER_SERIES_LIMIT = 5;\n\nexport interface NearbySeriesInfo {\n seriesIdx: number | null;\n datumIdx: number | null;\n seriesName: string;\n date: number;\n markerColor: string;\n x: number;\n y: number;\n formattedY: string;\n isClosestToCursor: boolean;\n}\n\nexport type NearbySeriesArray = NearbySeriesInfo[];\n\n/**\n * Returns formatted series data for the points that are close to the user's cursor\n * Adjust yBuffer to increase or decrease number of series shown\n */\nexport function checkforNearbySeries(\n data: EChartsDataFormat,\n pointInGrid: number[],\n yBuffer: number,\n chart?: EChartsInstance,\n unit?: UnitOptions\n): NearbySeriesArray {\n const currentNearbySeriesData: NearbySeriesArray = [];\n const cursorX: number | null = pointInGrid[0] ?? null;\n const cursorY: number | null = pointInGrid[1] ?? null;\n\n if (cursorX === null || cursorY === null) {\n return currentNearbySeriesData;\n }\n\n const nearbySeriesIndexes: number[] = [];\n const emphasizedSeriesIndexes: number[] = [];\n const nonEmphasizedSeriesIndexes: number[] = [];\n const totalSeries = data.timeSeries.length;\n if (Array.isArray(data.xAxis) && Array.isArray(data.timeSeries)) {\n for (let seriesIdx = 0; seriesIdx < totalSeries; seriesIdx++) {\n const currentSeries = data.timeSeries[seriesIdx];\n if (currentNearbySeriesData.length >= OPTIMIZED_MODE_SERIES_LIMIT) break;\n if (currentSeries !== undefined) {\n const currentSeriesName = currentSeries.name ? currentSeries.name.toString() : '';\n const markerColor = currentSeries.color ?? '#000';\n if (Array.isArray(currentSeries.data)) {\n for (let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++) {\n const xValue = data.xAxis[datumIdx] ?? 0;\n const yValue = currentSeries.data[datumIdx];\n // ensure null values not displayed in tooltip\n if (yValue !== undefined && yValue !== null && cursorX === datumIdx) {\n if (yValue !== '-' && cursorY <= yValue + yBuffer && cursorY >= yValue - yBuffer) {\n // show fewer bold series in tooltip when many total series\n const minPercentRange = totalSeries > SHOW_FEWER_SERIES_LIMIT ? 2 : 5;\n const percentRangeToCheck = Math.max(minPercentRange, 100 / totalSeries);\n const isClosestToCursor = isWithinPercentageRange({\n valueToCheck: cursorY,\n baseValue: yValue,\n percentage: percentRangeToCheck,\n });\n if (isClosestToCursor) {\n emphasizedSeriesIndexes.push(seriesIdx);\n } else {\n nonEmphasizedSeriesIndexes.push(seriesIdx);\n // ensure series not close to cursor are not highlighted\n if (chart?.dispatchAction !== undefined) {\n chart.dispatchAction({\n type: 'downplay',\n seriesIndex: seriesIdx,\n });\n }\n }\n\n // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201\n const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;\n const formattedY = formatValue(yValue, unit);\n currentNearbySeriesData.push({\n seriesIdx: seriesIdx,\n datumIdx: datumIdx,\n seriesName: currentSeriesName,\n date: xValueMilliSeconds,\n x: xValue,\n y: yValue,\n formattedY: formattedY,\n markerColor: markerColor.toString(),\n isClosestToCursor,\n });\n nearbySeriesIndexes.push(seriesIdx);\n }\n }\n }\n }\n }\n }\n }\n if (chart?.dispatchAction !== undefined) {\n // Clears emphasis state of all lines that are not emphasized.\n // Emphasized is a subset of just the nearby series that are closest to cursor.\n chart.dispatchAction({\n type: 'downplay',\n seriesIndex: nonEmphasizedSeriesIndexes,\n });\n\n // https://echarts.apache.org/en/api.html#action.highlight\n if (emphasizedSeriesIndexes.length > 0) {\n // Fadeout opacity of all series not closest to cursor.\n chart.dispatchAction({\n type: 'highlight',\n seriesIndex: emphasizedSeriesIndexes,\n notBlur: false,\n });\n } else {\n // When no emphasized series with bold text, notBlur allows opacity fadeout to not trigger.\n chart.dispatchAction({\n type: 'highlight',\n seriesIndex: nearbySeriesIndexes,\n notBlur: true,\n });\n }\n }\n\n return currentNearbySeriesData;\n}\n\n/**\n * Uses mouse position to determine whether user is hovering over a chart canvas\n * If yes, convert from pixel values to logical cartesian coordinates and return all nearby series\n */\nexport function getNearbySeriesData({\n mousePos,\n pinnedPos,\n chartData,\n chart,\n unit,\n showAllSeries = false,\n}: {\n mousePos: CursorData['coords'];\n pinnedPos: CursorData['coords'];\n chartData: EChartsDataFormat;\n chart?: EChartsInstance;\n unit?: UnitOptions;\n showAllSeries?: boolean;\n}) {\n if (chart === undefined || mousePos === null) return [];\n\n // prevents multiple tooltips showing from adjacent charts\n let cursorTargetMatchesChart = false;\n if (mousePos.target !== null) {\n const currentParent = (<HTMLElement>mousePos.target).parentElement;\n if (currentParent !== null) {\n const currentGrandparent = currentParent.parentElement;\n if (currentGrandparent !== null) {\n const chartDom = chart.getDom();\n if (chartDom === currentGrandparent) {\n cursorTargetMatchesChart = true;\n }\n }\n }\n }\n\n // allows moving cursor inside tooltip\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n cursorTargetMatchesChart = true;\n }\n\n if (cursorTargetMatchesChart === false) return [];\n\n if (chart['_model'] === undefined) return [];\n const chartModel = chart['_model'];\n const yInterval = chartModel.getComponent('yAxis').axis.scale._interval;\n const totalSeries = chartData.timeSeries.length;\n const yBuffer = getYBuffer({ yInterval, totalSeries, showAllSeries });\n const pointInPixel = [mousePos.plotCanvas.x ?? 0, mousePos.plotCanvas.y ?? 0];\n if (chart.containPixel('grid', pointInPixel)) {\n const pointInGrid = chart.convertFromPixel('grid', pointInPixel);\n if (pointInGrid[0] !== undefined && pointInGrid[1] !== undefined) {\n return checkforNearbySeries(chartData, pointInGrid, yBuffer, chart, unit);\n }\n }\n\n // clear all highlighted series when cursor exits canvas\n // https://echarts.apache.org/en/api.html#action.downplay\n for (let i = 0; i < totalSeries; i++) {\n if (chart?.dispatchAction !== undefined) {\n chart.dispatchAction({\n type: 'downplay',\n seriesIndex: i,\n });\n }\n }\n return [];\n}\n\n/*\n * Check if two numbers are within a specified percentage range\n */\nexport function isWithinPercentageRange({\n valueToCheck,\n baseValue,\n percentage,\n}: {\n valueToCheck: number;\n baseValue: number;\n percentage: number;\n}): boolean {\n const range = (percentage / 100) * baseValue;\n const lowerBound = baseValue - range;\n const upperBound = baseValue + range;\n return valueToCheck >= lowerBound && valueToCheck <= upperBound;\n}\n\n/*\n * Get range to check within for nearby series to show in tooltip.\n */\nexport function getYBuffer({\n yInterval,\n totalSeries,\n showAllSeries = false,\n}: {\n yInterval: number;\n totalSeries: number;\n showAllSeries?: boolean;\n}) {\n if (showAllSeries) {\n return yInterval * 10; // roughly correlates with grid so entire canvas is searched\n }\n\n // never let nearby series range be less than roughly the size of a single tick\n const yBufferMin = yInterval * 0.3;\n\n // tooltip trigger area gets smaller with more series\n if (totalSeries > SHOW_FEWER_SERIES_LIMIT) {\n const adjustedBuffer = (yInterval * DYNAMIC_NEARBY_SERIES_MULTIPLIER) / totalSeries;\n return Math.max(yBufferMin, adjustedBuffer);\n }\n\n // increase multiplier to expand nearby series range\n return Math.max(yBufferMin, yInterval * INCREASE_NEARBY_SERIES_MULTIPLIER);\n}\n"],"names":["formatValue","OPTIMIZED_MODE_SERIES_LIMIT","INCREASE_NEARBY_SERIES_MULTIPLIER","DYNAMIC_NEARBY_SERIES_MULTIPLIER","SHOW_FEWER_SERIES_LIMIT","checkforNearbySeries","data","pointInGrid","yBuffer","chart","unit","currentNearbySeriesData","cursorX","cursorY","nearbySeriesIndexes","emphasizedSeriesIndexes","nonEmphasizedSeriesIndexes","totalSeries","timeSeries","length","Array","isArray","xAxis","seriesIdx","currentSeries","undefined","currentSeriesName","name","toString","markerColor","color","datumIdx","xValue","yValue","minPercentRange","percentRangeToCheck","Math","max","isClosestToCursor","isWithinPercentageRange","valueToCheck","baseValue","percentage","push","dispatchAction","type","seriesIndex","xValueMilliSeconds","formattedY","seriesName","date","x","y","notBlur","getNearbySeriesData","mousePos","pinnedPos","chartData","showAllSeries","cursorTargetMatchesChart","target","currentParent","parentElement","currentGrandparent","chartDom","getDom","chartModel","yInterval","getComponent","axis","scale","_interval","getYBuffer","pointInPixel","plotCanvas","containPixel","convertFromPixel","i","range","lowerBound","upperBound","yBufferMin","adjustedBuffer"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,WAAW,EAAkCC,2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d,SAAS,GAAG,GAAG,AAAC;IAEnC,qDAAqD;IACrD,IAAIlD,WAAW,GAAGb,uBAAuB,EAAE;QACzC,MAAM8E,cAAc,GAAG,AAACf,SAAS,GAAGhE,gCAAgC,GAAIc,WAAW,AAAC;QACpF,OAAOmB,IAAI,CAACC,GAAG,CAAC4C,UAAU,EAAEC,cAAc,CAAC,CAAC;IAC9C,CAAC;IAED,oDAAoD;IACpD,OAAO9C,IAAI,CAACC,GAAG,CAAC4C,UAAU,EAAEd,SAAS,GAAGjE,iCAAiC,CAAC,CAAC;AAC7E,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/nearby-series.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ECharts as EChartsInstance } from 'echarts/core';\nimport { formatValue, UnitOptions, EChartsDataFormat, OPTIMIZED_MODE_SERIES_LIMIT } from '../model';\nimport { CursorCoordinates, CursorData } from './tooltip-model';\n\n// increase multipliers to show more series in tooltip\nexport const INCREASE_NEARBY_SERIES_MULTIPLIER = 5.5; // adjusts how many series show in tooltip (higher == more series shown)\nexport const DYNAMIC_NEARBY_SERIES_MULTIPLIER = 30; // used for adjustment after series number divisor\nexport const SHOW_FEWER_SERIES_LIMIT = 5;\n\nexport interface NearbySeriesInfo {\n seriesIdx: number | null;\n datumIdx: number | null;\n seriesName: string;\n date: number;\n markerColor: string;\n x: number;\n y: number;\n formattedY: string;\n isClosestToCursor: boolean;\n}\n\nexport type NearbySeriesArray = NearbySeriesInfo[];\n\n/**\n * Returns formatted series data for the points that are close to the user's cursor\n * Adjust yBuffer to increase or decrease number of series shown\n */\nexport function checkforNearbySeries(\n data: EChartsDataFormat,\n pointInGrid: number[],\n yBuffer: number,\n chart?: EChartsInstance,\n unit?: UnitOptions\n): NearbySeriesArray {\n const currentNearbySeriesData: NearbySeriesArray = [];\n const cursorX: number | null = pointInGrid[0] ?? null;\n const cursorY: number | null = pointInGrid[1] ?? null;\n\n if (cursorX === null || cursorY === null) {\n return currentNearbySeriesData;\n }\n\n const nearbySeriesIndexes: number[] = [];\n const emphasizedSeriesIndexes: number[] = [];\n const nonEmphasizedSeriesIndexes: number[] = [];\n const totalSeries = data.timeSeries.length;\n if (Array.isArray(data.xAxis) && Array.isArray(data.timeSeries)) {\n for (let seriesIdx = 0; seriesIdx < totalSeries; seriesIdx++) {\n const currentSeries = data.timeSeries[seriesIdx];\n if (currentNearbySeriesData.length >= OPTIMIZED_MODE_SERIES_LIMIT) break;\n if (currentSeries !== undefined) {\n const currentSeriesName = currentSeries.name ? currentSeries.name.toString() : '';\n const markerColor = currentSeries.color ?? '#000';\n if (Array.isArray(currentSeries.data)) {\n for (let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++) {\n const xValue = data.xAxis[datumIdx] ?? 0;\n const yValue = currentSeries.data[datumIdx];\n // ensure null values not displayed in tooltip\n if (yValue !== undefined && yValue !== null && cursorX === datumIdx) {\n if (yValue !== '-' && cursorY <= yValue + yBuffer && cursorY >= yValue - yBuffer) {\n // show fewer bold series in tooltip when many total series\n const minPercentRange = totalSeries > SHOW_FEWER_SERIES_LIMIT ? 2 : 5;\n const percentRangeToCheck = Math.max(minPercentRange, 100 / totalSeries);\n const isClosestToCursor = isWithinPercentageRange({\n valueToCheck: cursorY,\n baseValue: yValue,\n percentage: percentRangeToCheck,\n });\n if (isClosestToCursor) {\n emphasizedSeriesIndexes.push(seriesIdx);\n } else {\n nonEmphasizedSeriesIndexes.push(seriesIdx);\n // ensure series not close to cursor are not highlighted\n if (chart?.dispatchAction !== undefined) {\n chart.dispatchAction({\n type: 'downplay',\n seriesIndex: seriesIdx,\n });\n }\n }\n\n // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201\n const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;\n const formattedY = formatValue(yValue, unit);\n currentNearbySeriesData.push({\n seriesIdx: seriesIdx,\n datumIdx: datumIdx,\n seriesName: currentSeriesName,\n date: xValueMilliSeconds,\n x: xValue,\n y: yValue,\n formattedY: formattedY,\n markerColor: markerColor.toString(),\n isClosestToCursor,\n });\n nearbySeriesIndexes.push(seriesIdx);\n }\n }\n }\n }\n }\n }\n }\n if (chart?.dispatchAction !== undefined) {\n // Clears emphasis state of all lines that are not emphasized.\n // Emphasized is a subset of just the nearby series that are closest to cursor.\n chart.dispatchAction({\n type: 'downplay',\n seriesIndex: nonEmphasizedSeriesIndexes,\n });\n\n // https://echarts.apache.org/en/api.html#action.highlight\n if (emphasizedSeriesIndexes.length > 0) {\n // Fadeout opacity of all series not closest to cursor.\n chart.dispatchAction({\n type: 'highlight',\n seriesIndex: emphasizedSeriesIndexes,\n notBlur: false,\n });\n } else {\n // When no emphasized series with bold text, notBlur allows opacity fadeout to not trigger.\n chart.dispatchAction({\n type: 'highlight',\n seriesIndex: nearbySeriesIndexes,\n notBlur: true,\n });\n }\n }\n\n return currentNearbySeriesData;\n}\n\n/**\n * Uses mouse position to determine whether user is hovering over a chart canvas\n * If yes, convert from pixel values to logical cartesian coordinates and return all nearby series\n */\nexport function getNearbySeriesData({\n mousePos,\n pinnedPos,\n chartData,\n chart,\n unit,\n showAllSeries = false,\n}: {\n mousePos: CursorData['coords'];\n pinnedPos: CursorCoordinates | null;\n chartData: EChartsDataFormat;\n chart?: EChartsInstance;\n unit?: UnitOptions;\n showAllSeries?: boolean;\n}) {\n if (chart === undefined || mousePos === null) return [];\n\n // prevents multiple tooltips showing from adjacent charts unless tooltip is pinned\n let cursorTargetMatchesChart = false;\n if (mousePos.target !== null) {\n const currentParent = (<HTMLElement>mousePos.target).parentElement;\n if (currentParent !== null) {\n const currentGrandparent = currentParent.parentElement;\n if (currentGrandparent !== null) {\n const chartDom = chart.getDom();\n if (chartDom === currentGrandparent) {\n cursorTargetMatchesChart = true;\n }\n }\n }\n }\n\n // allows moving cursor inside tooltip without it fading away\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n cursorTargetMatchesChart = true;\n }\n\n if (cursorTargetMatchesChart === false) return [];\n\n if (chart['_model'] === undefined) return [];\n const chartModel = chart['_model'];\n const yInterval = chartModel.getComponent('yAxis').axis.scale._interval;\n const totalSeries = chartData.timeSeries.length;\n const yBuffer = getYBuffer({ yInterval, totalSeries, showAllSeries });\n const pointInPixel = [mousePos.plotCanvas.x ?? 0, mousePos.plotCanvas.y ?? 0];\n if (chart.containPixel('grid', pointInPixel)) {\n const pointInGrid = chart.convertFromPixel('grid', pointInPixel);\n if (pointInGrid[0] !== undefined && pointInGrid[1] !== undefined) {\n return checkforNearbySeries(chartData, pointInGrid, yBuffer, chart, unit);\n }\n }\n\n // clear all highlighted series when cursor exits canvas\n // https://echarts.apache.org/en/api.html#action.downplay\n for (let i = 0; i < totalSeries; i++) {\n if (chart?.dispatchAction !== undefined) {\n chart.dispatchAction({\n type: 'downplay',\n seriesIndex: i,\n });\n }\n }\n return [];\n}\n\n/*\n * Check if two numbers are within a specified percentage range\n */\nexport function isWithinPercentageRange({\n valueToCheck,\n baseValue,\n percentage,\n}: {\n valueToCheck: number;\n baseValue: number;\n percentage: number;\n}): boolean {\n const range = (percentage / 100) * baseValue;\n const lowerBound = baseValue - range;\n const upperBound = baseValue + range;\n return valueToCheck >= lowerBound && valueToCheck <= upperBound;\n}\n\n/*\n * Get range to check within for nearby series to show in tooltip.\n */\nexport function getYBuffer({\n yInterval,\n totalSeries,\n showAllSeries = false,\n}: {\n yInterval: number;\n totalSeries: number;\n showAllSeries?: boolean;\n}) {\n if (showAllSeries) {\n return yInterval * 10; // roughly correlates with grid so entire canvas is searched\n }\n\n // never let nearby series range be less than roughly the size of a single tick\n const yBufferMin = yInterval * 0.3;\n\n // tooltip trigger area gets smaller with more series\n if (totalSeries > SHOW_FEWER_SERIES_LIMIT) {\n const adjustedBuffer = (yInterval * DYNAMIC_NEARBY_SERIES_MULTIPLIER) / totalSeries;\n return Math.max(yBufferMin, adjustedBuffer);\n }\n\n // increase multiplier to expand nearby series range\n return Math.max(yBufferMin, yInterval * INCREASE_NEARBY_SERIES_MULTIPLIER);\n}\n"],"names":["formatValue","OPTIMIZED_MODE_SERIES_LIMIT","INCREASE_NEARBY_SERIES_MULTIPLIER","DYNAMIC_NEARBY_SERIES_MULTIPLIER","SHOW_FEWER_SERIES_LIMIT","checkforNearbySeries","data","pointInGrid","yBuffer","chart","unit","currentNearbySeriesData","cursorX","cursorY","nearbySeriesIndexes","emphasizedSeriesIndexes","nonEmphasizedSeriesIndexes","totalSeries","timeSeries","length","Array","isArray","xAxis","seriesIdx","currentSeries","undefined","currentSeriesName","name","toString","markerColor","color","datumIdx","xValue","yValue","minPercentRange","percentRangeToCheck","Math","max","isClosestToCursor","isWithinPercentageRange","valueToCheck","baseValue","percentage","push","dispatchAction","type","seriesIndex","xValueMilliSeconds","formattedY","seriesName","date","x","y","notBlur","getNearbySeriesData","mousePos","pinnedPos","chartData","showAllSeries","cursorTargetMatchesChart","target","currentParent","parentElement","currentGrandparent","chartDom","getDom","chartModel","yInterval","getComponent","axis","scale","_interval","getYBuffer","pointInPixel","plotCanvas","containPixel","convertFromPixel","i","range","lowerBound","upperBound","yBufferMin","adjustedBuffer"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,WAAW,EAAkCC,2BAA2B,QAAQ,UAAU,CAAC;AAGpG,sDAAsD;AACtD,OAAO,MAAMC,iCAAiC,GAAG,GAAG,C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;QACzC,MAAM8E,cAAc,GAAG,AAACf,SAAS,GAAGhE,gCAAgC,GAAIc,WAAW,AAAC;QACpF,OAAOmB,IAAI,CAACC,GAAG,CAAC4C,UAAU,EAAEC,cAAc,CAAC,CAAC;IAC9C,CAAC;IAED,oDAAoD;IACpD,OAAO9C,IAAI,CAACC,GAAG,CAAC4C,UAAU,EAAEd,SAAS,GAAGjE,iCAAiC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { NearbySeriesArray } from './nearby-series';
|
|
2
2
|
export declare const TOOLTIP_MIN_WIDTH = 375;
|
|
3
3
|
export declare const TOOLTIP_MAX_WIDTH = 650;
|
|
4
|
-
export declare const TOOLTIP_MAX_HEIGHT =
|
|
4
|
+
export declare const TOOLTIP_MAX_HEIGHT = 650;
|
|
5
5
|
export declare const TOOLTIP_LABELS_MAX_WIDTH: number;
|
|
6
6
|
export declare const TOOLTIP_ADJUST_Y_POS_MULTIPLIER = 0.75;
|
|
7
7
|
export declare const FALLBACK_CHART_WIDTH = 750;
|
|
8
8
|
export declare const NEARBY_SERIES_DESCRIPTION = "nearby series showing in tooltip";
|
|
9
9
|
export declare const EMPHASIZED_SERIES_DESCRIPTION = "emphasized series showing as bold in tooltip";
|
|
10
|
+
export declare const TOOLTIP_BG_COLOR_FALLBACK = "#2E313E";
|
|
10
11
|
export declare const TOOLTIP_DATE_FORMAT: Intl.DateTimeFormat;
|
|
11
12
|
export declare const defaultCursorData: {
|
|
12
13
|
coords: {
|
|
@@ -39,20 +40,15 @@ export declare const emptyTooltipData: {
|
|
|
39
40
|
};
|
|
40
41
|
focusedSeries: null;
|
|
41
42
|
};
|
|
43
|
+
export interface Coordinate {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
}
|
|
42
47
|
export interface CursorCoordinates {
|
|
43
|
-
page:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
client: {
|
|
48
|
-
x: number;
|
|
49
|
-
y: number;
|
|
50
|
-
};
|
|
51
|
-
plotCanvas: {
|
|
52
|
-
x: number;
|
|
53
|
-
y: number;
|
|
54
|
-
};
|
|
55
|
-
zrender: {
|
|
48
|
+
page: Coordinate;
|
|
49
|
+
client: Coordinate;
|
|
50
|
+
plotCanvas: Coordinate;
|
|
51
|
+
zrender?: {
|
|
56
52
|
x?: number;
|
|
57
53
|
y?: number;
|
|
58
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip-model.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/tooltip-model.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,wBAAwB,QAA0B,CAAC;AAChE,eAAO,MAAM,+BAA+B,OAAO,CAAC;AAEpD,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,eAAO,MAAM,yBAAyB,qCAAqC,CAAC;AAC5E,eAAO,MAAM,6BAA6B,iDAAiD,CAAC;AAE5F,eAAO,MAAM,mBAAmB,qBAQ9B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAa7B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;CAG5B,CAAC;AAEF,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"tooltip-model.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/tooltip-model.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,wBAAw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eAAO,MAAM,gBAAgB,QAAO,UAAU,CAAC,QAAQ,CAoCtD,CAAC"}
|
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
import { useEffect, useState } from 'react';
|
|
14
14
|
export const TOOLTIP_MIN_WIDTH = 375;
|
|
15
15
|
export const TOOLTIP_MAX_WIDTH = 650;
|
|
16
|
-
export const TOOLTIP_MAX_HEIGHT =
|
|
16
|
+
export const TOOLTIP_MAX_HEIGHT = 650;
|
|
17
17
|
export const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;
|
|
18
18
|
export const TOOLTIP_ADJUST_Y_POS_MULTIPLIER = 0.75;
|
|
19
19
|
export const FALLBACK_CHART_WIDTH = 750;
|
|
20
20
|
export const NEARBY_SERIES_DESCRIPTION = 'nearby series showing in tooltip';
|
|
21
21
|
export const EMPHASIZED_SERIES_DESCRIPTION = 'emphasized series showing as bold in tooltip';
|
|
22
|
+
export const TOOLTIP_BG_COLOR_FALLBACK = '#2E313E';
|
|
22
23
|
export const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
|
|
23
24
|
year: 'numeric',
|
|
24
25
|
month: 'short',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/tooltip-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useEffect, useState } from 'react';\nimport { NearbySeriesArray } from './nearby-series';\n\nexport const TOOLTIP_MIN_WIDTH = 375;\nexport const TOOLTIP_MAX_WIDTH = 650;\nexport const TOOLTIP_MAX_HEIGHT =
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/tooltip-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useEffect, useState } from 'react';\nimport { NearbySeriesArray } from './nearby-series';\n\nexport const TOOLTIP_MIN_WIDTH = 375;\nexport const TOOLTIP_MAX_WIDTH = 650;\nexport const TOOLTIP_MAX_HEIGHT = 650;\nexport const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;\nexport const TOOLTIP_ADJUST_Y_POS_MULTIPLIER = 0.75;\n\nexport const FALLBACK_CHART_WIDTH = 750;\n\nexport const NEARBY_SERIES_DESCRIPTION = 'nearby series showing in tooltip';\nexport const EMPHASIZED_SERIES_DESCRIPTION = 'emphasized series showing as bold in tooltip';\n\nexport const TOOLTIP_BG_COLOR_FALLBACK = '#2E313E';\n\nexport const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n hour12: true,\n});\n\nexport const defaultCursorData = {\n coords: {\n plotCanvas: {\n x: 0,\n y: 0,\n },\n zrender: {\n x: 0,\n y: 0,\n },\n target: null,\n },\n chartWidth: 0,\n};\n\nexport const emptyTooltipData = {\n cursor: defaultCursorData,\n focusedSeries: null,\n};\n\nexport interface Coordinate {\n x: number;\n y: number;\n}\n\nexport interface CursorCoordinates {\n page: Coordinate;\n client: Coordinate;\n plotCanvas: Coordinate;\n zrender?: {\n x?: number;\n y?: number;\n };\n target: EventTarget | null;\n}\n\nexport interface CursorData {\n coords: CursorCoordinates | null;\n chartWidth?: number;\n}\n\nexport interface TooltipData {\n focusedSeries: NearbySeriesArray | null;\n cursor: CursorData;\n}\n\ntype ZREventProperties = {\n zrX?: number;\n zrY?: number;\n zrDelta?: number;\n zrEventControl?: 'no_globalout' | 'only_globalout';\n zrByTouch?: boolean;\n};\n\nexport type ZRRawMouseEvent = MouseEvent & ZREventProperties;\n\nexport const useMousePosition = (): CursorData['coords'] => {\n const [coords, setCoords] = useState<CursorData['coords']>(null);\n\n useEffect(() => {\n const setFromEvent = (e: ZRRawMouseEvent) => {\n return setCoords({\n page: {\n x: e.pageX,\n y: e.pageY,\n },\n client: {\n x: e.clientX,\n y: e.clientY,\n },\n plotCanvas: {\n x: e.offsetX,\n y: e.offsetY,\n },\n zrender: {\n // echarts canvas coordinates added automatically by zrender\n // zrX and zrY are similar to offsetX and offsetY but they return undefined when not hovering over a chart canvas\n x: e.zrX,\n y: e.zrY,\n },\n // necessary to check whether cursor target matches correct chart canvas (since each chart has its own mousemove listener)\n target: e.target,\n });\n };\n window.addEventListener('mousemove', setFromEvent);\n\n return () => {\n window.removeEventListener('mousemove', setFromEvent);\n };\n }, []);\n\n return coords;\n};\n"],"names":["useEffect","useState","TOOLTIP_MIN_WIDTH","TOOLTIP_MAX_WIDTH","TOOLTIP_MAX_HEIGHT","TOOLTIP_LABELS_MAX_WIDTH","TOOLTIP_ADJUST_Y_POS_MULTIPLIER","FALLBACK_CHART_WIDTH","NEARBY_SERIES_DESCRIPTION","EMPHASIZED_SERIES_DESCRIPTION","TOOLTIP_BG_COLOR_FALLBACK","TOOLTIP_DATE_FORMAT","Intl","DateTimeFormat","undefined","year","month","day","hour","minute","second","hour12","defaultCursorData","coords","plotCanvas","x","y","zrender","target","chartWidth","emptyTooltipData","cursor","focusedSeries","useMousePosition","setCoords","setFromEvent","e","page","pageX","pageY","client","clientX","clientY","offsetX","offsetY","zrX","zrY","window","addEventListener","removeEventListener"],"mappings":"AAAA,oCA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20
|
+
const cursorPaddingX = 32;
|
|
21
|
+
const cursorPaddingY = 16;
|
|
20
22
|
if (pinnedPos !== null) {
|
|
21
23
|
mousePos = pinnedPos;
|
|
22
24
|
}
|
|
23
|
-
const cursorPaddingX = 32;
|
|
24
|
-
const cursorPaddingY = 16;
|
|
25
25
|
// Tooltip is located in a Portal attached to the body.
|
|
26
26
|
// Using page coordinates instead of viewport ensures the tooltip is
|
|
27
27
|
// absolutely positioned correctly as the user scrolls
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/utils.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { CursorCoordinates, CursorData, TOOLTIP_MAX_WIDTH, TOOLTIP_ADJUST_Y_POS_MULTIPLIER } from './tooltip-model';\n\n/**\n * Determine position of tooltip depending on chart dimensions and the number of focused series\n */\nexport function assembleTransform(\n mousePos: CursorData['coords'],\n chartWidth: number,\n pinnedPos: CursorCoordinates | null,\n tooltipHeight: number,\n tooltipWidth: number\n) {\n if (mousePos === null) {\n return 'translate3d(0, 0)';\n }\n\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/utils.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { CursorCoordinates, CursorData, TOOLTIP_MAX_WIDTH, TOOLTIP_ADJUST_Y_POS_MULTIPLIER } from './tooltip-model';\n\n/**\n * Determine position of tooltip depending on chart dimensions and the number of focused series\n */\nexport function assembleTransform(\n mousePos: CursorData['coords'],\n chartWidth: number,\n pinnedPos: CursorCoordinates | null,\n tooltipHeight: number,\n tooltipWidth: number\n) {\n if (mousePos === null) {\n return 'translate3d(0, 0)';\n }\n\n const cursorPaddingX = 32;\n const cursorPaddingY = 16;\n\n if (pinnedPos !== null) {\n mousePos = pinnedPos;\n }\n\n // Tooltip is located in a Portal attached to the body.\n // Using page coordinates instead of viewport ensures the tooltip is\n // absolutely positioned correctly as the user scrolls\n const x = mousePos.page.x;\n let y = mousePos.page.y + cursorPaddingY;\n\n // adjust so tooltip does not get cut off at bottom of chart\n if (mousePos.client.y + tooltipHeight + cursorPaddingY > window.innerHeight) {\n // multiplier ensures tooltip isn't overly adjusted and gets cut off at the top of the viewport\n y = mousePos.page.y - tooltipHeight * TOOLTIP_ADJUST_Y_POS_MULTIPLIER;\n }\n\n // use tooltip width to determine when to repos from right to left\n const xPosAdjustThreshold = chartWidth - tooltipWidth * 0.9;\n\n // reposition so tooltip is never too close to right side of chart or left side of browser window\n return mousePos.plotCanvas.x > xPosAdjustThreshold && x > TOOLTIP_MAX_WIDTH\n ? `translate3d(${x - cursorPaddingX}px, ${y}px, 0) translateX(-100%)`\n : `translate3d(${x + cursorPaddingX}px, ${y}px, 0)`;\n}\n"],"names":["TOOLTIP_MAX_WIDTH","TOOLTIP_ADJUST_Y_POS_MULTIPLIER","assembleTransform","mousePos","chartWidth","pinnedPos","tooltipHeight","tooltipWidth","cursorPaddingX","cursorPaddingY","x","page","y","client","window","innerHeight","xPosAdjustThreshold","plotCanvas"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;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BAAwB,CAAC,GACnE,CAAC,YAAY,EAAEF,CAAC,GAAGF,cAAc,CAAC,IAAI,EAAEI,CAAC,CAAC,MAAM,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "ContentWithLegend", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>ContentWithLegend
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _react = /*#__PURE__*/ _interopRequireDefault(require("react"));
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
const _legend = require("../Legend");
|
|
25
|
+
const _contentWithLegendModel = require("./model/content-with-legend-model");
|
|
26
|
+
function _interopRequireDefault(obj) {
|
|
27
|
+
return obj && obj.__esModule ? obj : {
|
|
28
|
+
default: obj
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function ContentWithLegend({ children , legendProps , width , height , spacing =0 , minChildrenWidth =100 , minChildrenHeight =100 }) {
|
|
32
|
+
const theme = (0, _material.useTheme)();
|
|
33
|
+
const { content , legend , margin } = (0, _contentWithLegendModel.getContentWithLegendLayout)({
|
|
34
|
+
width,
|
|
35
|
+
height,
|
|
36
|
+
legendOptions: legendProps === null || legendProps === void 0 ? void 0 : legendProps.options,
|
|
37
|
+
minChildrenHeight,
|
|
38
|
+
minChildrenWidth,
|
|
39
|
+
spacing,
|
|
40
|
+
theme
|
|
41
|
+
});
|
|
42
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
43
|
+
sx: {
|
|
44
|
+
width,
|
|
45
|
+
height,
|
|
46
|
+
position: 'relative',
|
|
47
|
+
overflow: 'hidden'
|
|
48
|
+
},
|
|
49
|
+
children: [
|
|
50
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
51
|
+
sx: {
|
|
52
|
+
width: content.width,
|
|
53
|
+
height: content.height,
|
|
54
|
+
marginRight: `${margin.right}px`,
|
|
55
|
+
marginBottom: `${margin.bottom}px`,
|
|
56
|
+
overflow: 'hidden'
|
|
57
|
+
},
|
|
58
|
+
children: typeof children === 'function' ? children({
|
|
59
|
+
width: content.width,
|
|
60
|
+
height: content.height
|
|
61
|
+
}) : children
|
|
62
|
+
}),
|
|
63
|
+
legendProps && legend.show && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_legend.Legend, {
|
|
64
|
+
...legendProps,
|
|
65
|
+
height: legend.height,
|
|
66
|
+
width: legend.width
|
|
67
|
+
})
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
_exportStar(require("./ContentWithLegend"), exports);
|
|
18
|
+
function _exportStar(from, to) {
|
|
19
|
+
Object.keys(from).forEach(function(k) {
|
|
20
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return from[k];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return from;
|
|
28
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
TABLE_LEGEND_SIZE: ()=>TABLE_LEGEND_SIZE,
|
|
25
|
+
getContentWithLegendLayout: ()=>getContentWithLegendLayout
|
|
26
|
+
});
|
|
27
|
+
const _table = require("../../Table");
|
|
28
|
+
const _legend = require("../../model/legend");
|
|
29
|
+
const TABLE_LEGEND_SIZE = {
|
|
30
|
+
// 5 rows plus header. Value to be multiplied by row height in pixels.
|
|
31
|
+
Bottom: 6,
|
|
32
|
+
// Pixel value
|
|
33
|
+
Right: 250
|
|
34
|
+
};
|
|
35
|
+
const PANEL_HEIGHT_LG_BREAKPOINT = 300;
|
|
36
|
+
const LEGEND_HEIGHT_SM = 40;
|
|
37
|
+
const LEGEND_HEIGHT_LG = 100;
|
|
38
|
+
function getContentWithLegendLayout({ width , height , legendOptions , minChildrenHeight , minChildrenWidth , spacing , theme }) {
|
|
39
|
+
const hasLegend = !!legendOptions;
|
|
40
|
+
const noLegendLayout = {
|
|
41
|
+
legend: {
|
|
42
|
+
show: false,
|
|
43
|
+
width: 0,
|
|
44
|
+
height: 0
|
|
45
|
+
},
|
|
46
|
+
content: {
|
|
47
|
+
width,
|
|
48
|
+
height
|
|
49
|
+
},
|
|
50
|
+
margin: {
|
|
51
|
+
right: 0,
|
|
52
|
+
bottom: 0
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
if (!hasLegend) {
|
|
56
|
+
return noLegendLayout;
|
|
57
|
+
}
|
|
58
|
+
const { position } = legendOptions;
|
|
59
|
+
const mode = (0, _legend.getLegendMode)(legendOptions.mode);
|
|
60
|
+
let legendWidth;
|
|
61
|
+
let legendHeight;
|
|
62
|
+
if (mode === 'List') {
|
|
63
|
+
// TODO: normalize list to share similar height options as the table
|
|
64
|
+
// when we add more size options.
|
|
65
|
+
legendWidth = position === 'Right' ? 200 : width;
|
|
66
|
+
// TODO: account for number of legend items returned when adjusting legend spacing
|
|
67
|
+
legendHeight = LEGEND_HEIGHT_SM;
|
|
68
|
+
if (position === 'Right') {
|
|
69
|
+
legendHeight = height;
|
|
70
|
+
} else if (height >= PANEL_HEIGHT_LG_BREAKPOINT) {
|
|
71
|
+
legendHeight = LEGEND_HEIGHT_LG;
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
// Table mode
|
|
75
|
+
const tableLayout = (0, _table.getTableCellLayout)(theme, 'compact');
|
|
76
|
+
legendWidth = position === 'Right' ? TABLE_LEGEND_SIZE['Right'] : width;
|
|
77
|
+
legendHeight = position === 'Bottom' ? TABLE_LEGEND_SIZE['Bottom'] * tableLayout.height : height;
|
|
78
|
+
}
|
|
79
|
+
const contentWidth = position === 'Right' ? width - legendWidth - spacing : width;
|
|
80
|
+
const contentHeight = position === 'Bottom' ? height - legendHeight - spacing : height;
|
|
81
|
+
if (position === 'Right' && contentWidth < minChildrenWidth || position === 'Bottom' && contentHeight < minChildrenHeight) {
|
|
82
|
+
// Legend does not fit. Just show the content.
|
|
83
|
+
return noLegendLayout;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
legend: {
|
|
87
|
+
width: legendWidth,
|
|
88
|
+
height: legendHeight,
|
|
89
|
+
show: true
|
|
90
|
+
},
|
|
91
|
+
content: {
|
|
92
|
+
width: contentWidth,
|
|
93
|
+
height: contentHeight
|
|
94
|
+
},
|
|
95
|
+
margin: {
|
|
96
|
+
right: position === 'Right' ? spacing : 0,
|
|
97
|
+
bottom: position === 'Bottom' ? spacing : 0
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -142,11 +142,19 @@ const EChart = /*#__PURE__*/ _react.default.memo(function EChart({ option , them
|
|
|
142
142
|
}, [
|
|
143
143
|
onEvents
|
|
144
144
|
]);
|
|
145
|
+
// TODO: re-evaluate how this is triggered. It's technically working right
|
|
146
|
+
// now because the sx prop is an object that gets re-created, but that also
|
|
147
|
+
// means it runs unnecessarily some of the time and theoretically might
|
|
148
|
+
// not run in some other cases. Maybe it should use a resize observer?
|
|
145
149
|
(0, _react.useEffect)(()=>{
|
|
150
|
+
// TODO: fix this debouncing. This likely isn't working as intended because
|
|
151
|
+
// the debounced function is re-created every time this useEffect is called.
|
|
146
152
|
const updateSize = (0, _lodashEs.debounce)(()=>{
|
|
147
153
|
if (!chartElement.current) return;
|
|
148
154
|
chartElement.current.resize();
|
|
149
|
-
}, 200
|
|
155
|
+
}, 200, {
|
|
156
|
+
leading: true
|
|
157
|
+
});
|
|
150
158
|
updateSize();
|
|
151
159
|
}, [
|
|
152
160
|
sx
|
|
@@ -21,8 +21,10 @@ Object.defineProperty(exports, "Legend", {
|
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
22
|
const _material = require("@mui/material");
|
|
23
23
|
const _immer = require("immer");
|
|
24
|
+
const _model = require("../model");
|
|
24
25
|
const _listLegend = require("./ListLegend");
|
|
25
26
|
const _compactLegend = require("./CompactLegend");
|
|
27
|
+
const _tableLegend = require("./TableLegend");
|
|
26
28
|
// When the number of items to display is above this number, it is likely to
|
|
27
29
|
// cause performance issues in the browser. The legend will be displayed in a
|
|
28
30
|
// format (list) that allows for virtualization to minimize the performance impact.
|
|
@@ -62,12 +64,37 @@ function Legend({ width , height , options , data , selectedItems , onSelectedIt
|
|
|
62
64
|
});
|
|
63
65
|
onSelectedItemsChange(newSelected);
|
|
64
66
|
};
|
|
67
|
+
const mode = (0, _model.getLegendMode)(options.mode);
|
|
68
|
+
// The bottom legend is displayed as a list when the number of items is too
|
|
69
|
+
// large and requires virtualization. Otherwise, it is rendered more compactly.
|
|
70
|
+
// We do not need this check for the right-side legend because it is always
|
|
71
|
+
// a virtualized list.
|
|
72
|
+
const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;
|
|
65
73
|
const commonLegendProps = {
|
|
66
74
|
height,
|
|
67
75
|
items: data,
|
|
68
76
|
selectedItems,
|
|
69
77
|
onLegendItemClick
|
|
70
78
|
};
|
|
79
|
+
let legendContent;
|
|
80
|
+
if (mode === 'Table') {
|
|
81
|
+
legendContent = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableLegend.TableLegend, {
|
|
82
|
+
...commonLegendProps,
|
|
83
|
+
onSelectedItemsChange: onSelectedItemsChange,
|
|
84
|
+
width: width
|
|
85
|
+
});
|
|
86
|
+
} else if (options.position === 'Right' || needsVirtualization) {
|
|
87
|
+
legendContent = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegend.ListLegend, {
|
|
88
|
+
...commonLegendProps,
|
|
89
|
+
width: width,
|
|
90
|
+
onLegendItemClick: onLegendItemClick
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
legendContent = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_compactLegend.CompactLegend, {
|
|
94
|
+
...commonLegendProps,
|
|
95
|
+
onLegendItemClick: onLegendItemClick
|
|
96
|
+
});
|
|
97
|
+
}
|
|
71
98
|
if (options.position === 'Right') {
|
|
72
99
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
73
100
|
sx: {
|
|
@@ -77,17 +104,10 @@ function Legend({ width , height , options , data , selectedItems , onSelectedIt
|
|
|
77
104
|
top: 0,
|
|
78
105
|
right: 0
|
|
79
106
|
},
|
|
80
|
-
children:
|
|
81
|
-
...commonLegendProps,
|
|
82
|
-
width: width
|
|
83
|
-
})
|
|
107
|
+
children: legendContent
|
|
84
108
|
});
|
|
85
109
|
}
|
|
86
|
-
//
|
|
87
|
-
// large and requires virtualization. Otherwise, it is rendered more compactly.
|
|
88
|
-
// We do not need this check for the right-side legend because it is always
|
|
89
|
-
// a virtualized list.
|
|
90
|
-
const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;
|
|
110
|
+
// Position bottom
|
|
91
111
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
92
112
|
sx: {
|
|
93
113
|
width: width,
|
|
@@ -95,11 +115,6 @@ function Legend({ width , height , options , data , selectedItems , onSelectedIt
|
|
|
95
115
|
position: 'absolute',
|
|
96
116
|
bottom: 0
|
|
97
117
|
},
|
|
98
|
-
children:
|
|
99
|
-
...commonLegendProps,
|
|
100
|
-
width: width
|
|
101
|
-
}) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_compactLegend.CompactLegend, {
|
|
102
|
-
...commonLegendProps
|
|
103
|
-
})
|
|
118
|
+
children: legendContent
|
|
104
119
|
});
|
|
105
120
|
}
|
|
@@ -19,23 +19,10 @@ Object.defineProperty(exports, "ListLegend", {
|
|
|
19
19
|
get: ()=>ListLegend
|
|
20
20
|
});
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
const _material = require("@mui/material");
|
|
23
22
|
const _reactVirtuoso = require("react-virtuoso");
|
|
24
23
|
const _model = require("../model");
|
|
25
24
|
const _listLegendItem = require("./ListLegendItem");
|
|
26
25
|
function ListLegend({ items , height , width , selectedItems , onLegendItemClick }) {
|
|
27
|
-
const theme = (0, _material.useTheme)();
|
|
28
|
-
// Padding value used in the react virtuoso header/footer components to
|
|
29
|
-
// simulate top/bottom padding based on recommendation in this
|
|
30
|
-
// issue.
|
|
31
|
-
// https://github.com/petyosi/react-virtuoso/issues/238
|
|
32
|
-
const LIST_PADDING = parseInt(theme.spacing(1), 10);
|
|
33
|
-
const mockPadding = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
34
|
-
sx: {
|
|
35
|
-
width: '100%',
|
|
36
|
-
height: `${LIST_PADDING}px`
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
26
|
// show full labels on hover when there are many total series
|
|
40
27
|
const truncateLabels = items.length > 5;
|
|
41
28
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactVirtuoso.Virtuoso, {
|
|
@@ -53,20 +40,12 @@ function ListLegend({ items , height , width , selectedItems , onLegendItemClick
|
|
|
53
40
|
sx: {
|
|
54
41
|
// Having an explicit width is important for the ellipsizing to
|
|
55
42
|
// work correctly. Subtract padding to simulate padding.
|
|
56
|
-
width: width
|
|
43
|
+
width: width,
|
|
57
44
|
wordBreak: 'break-word',
|
|
58
45
|
overflow: 'hidden'
|
|
59
46
|
}
|
|
60
47
|
}, item.id);
|
|
61
48
|
},
|
|
62
|
-
role: "list"
|
|
63
|
-
components: {
|
|
64
|
-
Header: ()=>{
|
|
65
|
-
return mockPadding;
|
|
66
|
-
},
|
|
67
|
-
Footer: ()=>{
|
|
68
|
-
return mockPadding;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
49
|
+
role: "list"
|
|
71
50
|
});
|
|
72
51
|
}
|