@perses-dev/components 0.0.0-snapshot-color-palette-gen-test-bc1b508 → 0.0.0-snapshot-tooltip-highlight-c995fc8
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/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js +7 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
- package/dist/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +7 -1
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +9 -9
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +12 -15
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/focused-series.d.ts +5 -2
- package/dist/TimeSeriesTooltip/focused-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/focused-series.js +36 -7
- package/dist/TimeSeriesTooltip/focused-series.js.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +2 -2
- package/dist/TimeSeriesTooltip/tooltip-model.js +2 -2
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
- package/dist/UnitSelector/UnitSelector.js +38 -16
- package/dist/UnitSelector/UnitSelector.js.map +1 -1
- package/dist/YAxisLabel.d.ts.map +1 -1
- package/dist/YAxisLabel.js +1 -0
- package/dist/YAxisLabel.js.map +1 -1
- package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +7 -1
- package/dist/cjs/EChart/EChart.js +7 -1
- package/dist/cjs/LineChart/LineChart.js +9 -9
- package/dist/cjs/StatChart/StatChart.js +12 -15
- package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +1 -1
- package/dist/cjs/TimeSeriesTooltip/focused-series.js +37 -6
- package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +2 -2
- package/dist/cjs/UnitSelector/UnitSelector.js +37 -15
- package/dist/cjs/YAxisLabel.js +1 -0
- package/dist/cjs/model/units/bytes.js +18 -16
- package/dist/cjs/model/units/constants.js +3 -3
- package/dist/cjs/model/units/decimal.js +21 -18
- package/dist/cjs/model/units/percent.js +20 -11
- package/dist/cjs/model/units/time.js +25 -21
- package/dist/cjs/model/units/units.js +2 -2
- package/dist/cjs/model/units/utils.js +42 -0
- package/dist/cjs/utils/theme-gen.js +8 -13
- package/dist/model/units/bytes.d.ts +1 -1
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +19 -17
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/constants.d.ts +1 -1
- package/dist/model/units/constants.js +1 -1
- package/dist/model/units/constants.js.map +1 -1
- package/dist/model/units/decimal.d.ts +2 -2
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +21 -18
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/percent.d.ts +2 -2
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js +20 -11
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/time.d.ts +2 -2
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +25 -21
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/types.d.ts +9 -0
- package/dist/model/units/types.d.ts.map +1 -1
- package/dist/model/units/types.js.map +1 -1
- package/dist/model/units/units.js +2 -2
- package/dist/model/units/units.js.map +1 -1
- package/dist/model/units/utils.d.ts +4 -0
- package/dist/model/units/utils.d.ts.map +1 -0
- package/dist/model/units/utils.js +32 -0
- package/dist/model/units/utils.js.map +1 -0
- package/dist/utils/theme-gen.d.ts.map +1 -1
- package/dist/utils/theme-gen.js +8 -13
- package/dist/utils/theme-gen.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/focused-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 } from '../model';\nimport { CursorData, TOOLTIP_DATE_FORMAT, TOOLTIP_MAX_ITEMS } from './tooltip-model';\n\nexport interface FocusedSeriesInfo {\n seriesIdx: number | null;\n datumIdx: number | null;\n seriesName: string;\n date: string;\n markerColor: string;\n x: number;\n y: number;\n formattedY: string;\n}\n\nexport type FocusedSeriesArray = FocusedSeriesInfo[];\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 getNearbySeries(\n data: EChartsDataFormat,\n pointInGrid: number[],\n yBuffer: number,\n unit?: UnitOptions\n): FocusedSeriesArray {\n const currentFocusedData: FocusedSeriesArray = [];\n const focusedX: number | null = pointInGrid[0] ?? null;\n const focusedY: number | null = pointInGrid[1] ?? null;\n\n if (focusedX === null || focusedY === null) {\n return currentFocusedData;\n }\n\n if (Array.isArray(data.xAxis) && Array.isArray(data.timeSeries)) {\n for (let seriesIdx = 0; seriesIdx < data.timeSeries.length; seriesIdx++) {\n const currentSeries = data.timeSeries[seriesIdx];\n if (currentFocusedData.length >= TOOLTIP_MAX_ITEMS) 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 && focusedX === datumIdx) {\n if (yValue !== '-' && focusedY <= yValue + yBuffer && focusedY >= yValue - yBuffer) {\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 formattedDate = TOOLTIP_DATE_FORMAT.format(xValueMilliSeconds);\n const formattedY = formatValue(yValue, unit);\n currentFocusedData.push({\n seriesIdx: seriesIdx,\n datumIdx: datumIdx,\n seriesName: currentSeriesName,\n date: formattedDate,\n x: xValue,\n y: yValue,\n formattedY: formattedY,\n markerColor: markerColor.toString(),\n });\n }\n }\n }\n }\n }\n }\n }\n return currentFocusedData;\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 focused series\n */\nexport function getFocusedSeriesData(\n mousePos: CursorData['coords'],\n chartData: EChartsDataFormat,\n pinnedPos: CursorData['coords'],\n chart?: EChartsInstance,\n unit?: UnitOptions\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 yAxisInterval = chartModel.getComponent('yAxis').axis.scale._interval;\n\n // tooltip trigger area gets smaller with more series, increase yAxisInterval multiplier to expand nearby series range\n const seriesNum = chartData.timeSeries.length;\n const yBuffer = seriesNum > TOOLTIP_MAX_ITEMS ? yAxisInterval * 0.5 : yAxisInterval * 5;\n\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 getNearbySeries(chartData, pointInGrid, yBuffer, unit);\n }\n }\n return [];\n}\n"],"names":["formatValue","TOOLTIP_DATE_FORMAT","TOOLTIP_MAX_ITEMS","getNearbySeries","data","pointInGrid","yBuffer","unit","currentFocusedData","focusedX","focusedY","Array","isArray","xAxis","timeSeries","seriesIdx","length","currentSeries","undefined","currentSeriesName","name","toString","markerColor","color","datumIdx","xValue","yValue","xValueMilliSeconds","formattedDate","format","formattedY","push","seriesName","date","x","y","getFocusedSeriesData","mousePos","chartData","pinnedPos","chart","cursorTargetMatchesChart","target","currentParent","parentElement","currentGrandparent","chartDom","getDom","chartModel","yAxisInterval","getComponent","axis","scale","_interval","seriesNum","pointInPixel","plotCanvas","containPixel","convertFromPixel"],"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,QAAwC,UAAU,CAAC;AACvE,SAAqBC,mBAAmB,EAAEC,iBAAiB,QAAQ,iBAAiB,CAAC;AAerF;;;CAGC,GACD,OAAO,SAASC,eAAe,CAC7BC,IAAuB,EACvBC,WAAqB,EACrBC,OAAe,EACfC,IAAkB,EACE;IACpB,MAAMC,kBAAkB,GAAuB,EAAE,AAAC;QAClBH,G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A,EAAqB;IAAvE,MAAMkB,YAAY,GAAG;QAAClB,CAAAA,EAAqB,GAArBA,QAAQ,CAACmB,UAAU,CAACtB,CAAC,cAArBG,EAAqB,cAArBA,EAAqB,GAAI,CAAC;QAAEA,CAAAA,EAAqB,GAArBA,QAAQ,CAACmB,UAAU,CAACrB,CAAC,cAArBE,EAAqB,cAArBA,EAAqB,GAAI,CAAC;KAAC,AAAC;IAC9E,IAAIG,KAAK,CAACiB,YAAY,CAAC,MAAM,EAAEF,YAAY,CAAC,EAAE;QAC5C,MAAMlD,WAAW,GAAGmC,KAAK,CAACkB,gBAAgB,CAAC,MAAM,EAAEH,YAAY,CAAC,AAAC;QACjE,IAAIlD,WAAW,CAAC,CAAC,CAAC,KAAKa,SAAS,IAAIb,WAAW,CAAC,CAAC,CAAC,KAAKa,SAAS,EAAE;YAChE,OAAOf,eAAe,CAACmC,SAAS,EAAEjC,WAAW,EAAEC,OAAO,EAAEC,IAAI,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/TimeSeriesTooltip/focused-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 } from '../model';\nimport { CursorData, TOOLTIP_MAX_ITEMS } from './tooltip-model';\n\n// increase multipliers to show more series in tooltip\nexport const DEFAULT_NEARBY_SERIES_RANGE_MULTIPLIER = 5.5; // adjusts how many focused series show in tooltip\nexport const NARROW_NEARBY_SERIES_RANGE_MULTIPLIER = 2; // used to reduce number of focused series for heavy queries\nexport const SHOW_MORE_NEARBY_SERIES_LIMIT = 5;\n\nexport interface FocusedSeriesInfo {\n seriesIdx: number | null;\n datumIdx: number | null;\n seriesName: string;\n dateMs: number;\n markerColor: string;\n x: number;\n y: number;\n formattedY: string;\n}\n\nexport type FocusedSeriesArray = FocusedSeriesInfo[];\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 getNearbySeries(\n data: EChartsDataFormat,\n pointInGrid: number[],\n yBuffer: number,\n chart?: EChartsInstance,\n unit?: UnitOptions\n): FocusedSeriesArray {\n const currentFocusedData: FocusedSeriesArray = [];\n const focusedX: number | null = pointInGrid[0] ?? null;\n const focusedY: number | null = pointInGrid[1] ?? null;\n\n if (focusedX === null || focusedY === null) {\n return currentFocusedData;\n }\n\n if (Array.isArray(data.xAxis) && Array.isArray(data.timeSeries)) {\n for (let seriesIdx = 0; seriesIdx < data.timeSeries.length; seriesIdx++) {\n const currentSeries = data.timeSeries[seriesIdx];\n if (currentFocusedData.length >= TOOLTIP_MAX_ITEMS) 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 && focusedX === datumIdx) {\n if (yValue !== '-' && focusedY <= yValue + yBuffer && focusedY >= yValue - yBuffer) {\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 // trigger emphasis state of nearby series so tooltip matches highlighted lines\n // https://echarts.apache.org/en/api.html#action.highlight\n if (chart?.dispatchAction !== undefined) {\n chart.dispatchAction({\n type: 'highlight',\n seriesIndex: seriesIdx,\n });\n }\n currentFocusedData.push({\n seriesIdx: seriesIdx,\n datumIdx: datumIdx,\n seriesName: currentSeriesName,\n dateMs: xValueMilliSeconds,\n x: xValue,\n y: yValue,\n formattedY: formattedY,\n markerColor: markerColor.toString(),\n });\n } else {\n // clear emphasis state of lines that are not focused\n if (chart?.dispatchAction !== undefined) {\n chart.dispatchAction({\n type: 'downplay',\n seriesIndex: seriesIdx,\n });\n }\n }\n }\n }\n }\n }\n }\n }\n return currentFocusedData;\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 focused series\n */\nexport function getFocusedSeriesData(\n mousePos: CursorData['coords'],\n chartData: EChartsDataFormat,\n pinnedPos: CursorData['coords'],\n chart?: EChartsInstance,\n unit?: UnitOptions\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 yAxisInterval = chartModel.getComponent('yAxis').axis.scale._interval;\n\n const seriesNum = chartData.timeSeries.length;\n\n // tooltip trigger area gets smaller with more series, increase yAxisInterval multiplier to expand nearby series range\n const yBuffer =\n seriesNum > SHOW_MORE_NEARBY_SERIES_LIMIT\n ? yAxisInterval * NARROW_NEARBY_SERIES_RANGE_MULTIPLIER\n : yAxisInterval * DEFAULT_NEARBY_SERIES_RANGE_MULTIPLIER;\n\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 getNearbySeries(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 < seriesNum; i++) {\n if (chart?.dispatchAction !== undefined) {\n chart.dispatchAction({\n type: 'downplay',\n seriesIndex: i,\n });\n }\n }\n return [];\n}\n"],"names":["formatValue","TOOLTIP_MAX_ITEMS","DEFAULT_NEARBY_SERIES_RANGE_MULTIPLIER","NARROW_NEARBY_SERIES_RANGE_MULTIPLIER","SHOW_MORE_NEARBY_SERIES_LIMIT","getNearbySeries","data","pointInGrid","yBuffer","chart","unit","currentFocusedData","focusedX","focusedY","Array","isArray","xAxis","timeSeries","seriesIdx","length","currentSeries","undefined","currentSeriesName","name","toString","markerColor","color","datumIdx","xValue","yValue","xValueMilliSeconds","formattedY","dispatchAction","type","seriesIndex","push","seriesName","dateMs","x","y","getFocusedSeriesData","mousePos","chartData","pinnedPos","cursorTargetMatchesChart","target","currentParent","parentElement","currentGrandparent","chartDom","getDom","chartModel","yAxisInterval","getComponent","axis","scale","_interval","seriesNum","pointInPixel","plotCanvas","containPixel","convertFromPixel","i"],"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,QAAwC,UAAU,CAAC;AACvE,SAAqBC,iBAAiB,QAAQ,iBAAiB,CAAC;AAEhE,sDAAsD;AACtD,OAAO,MAAMC,sCAAsC,GAAG,GAAG,CAAC,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,SAAS,IAAId,WAAW,CAAC,CAAC,CAAC,KAAKc,SAAS,EAAE;YAChE,OAAOhB,eAAe,CAACqC,SAAS,EAAEnC,WAAW,EAAEC,OAAO,EAAEC,KAAK,EAAEC,IAAI,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED,wDAAwD;IACxD,yDAAyD;IACzD,IAAK,IAAIoD,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,SAAS,EAAEK,CAAC,EAAE,CAAE;QAClC,IAAIrD,CAAAA,KAAK,aAALA,KAAK,WAAgB,GAArBA,KAAAA,CAAqB,GAArBA,KAAK,CAAEuB,cAAc,CAAA,KAAKX,SAAS,EAAE;YACvCZ,KAAK,CAACuB,cAAc,CAAC;gBACnBC,IAAI,EAAE,UAAU;gBAChBC,WAAW,EAAE4B,CAAC;aACf,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FocusedSeriesArray } from './focused-series';
|
|
2
2
|
export declare const TOOLTIP_MAX_WIDTH = 650;
|
|
3
|
-
export declare const TOOLTIP_MAX_HEIGHT =
|
|
3
|
+
export declare const TOOLTIP_MAX_HEIGHT = 400;
|
|
4
4
|
export declare const TOOLTIP_LABELS_MAX_WIDTH: number;
|
|
5
|
-
export declare const TOOLTIP_MAX_ITEMS =
|
|
5
|
+
export declare const TOOLTIP_MAX_ITEMS = 30;
|
|
6
6
|
export declare const TOOLTIP_DATE_FORMAT: Intl.DateTimeFormat;
|
|
7
7
|
export declare const defaultCursorData: {
|
|
8
8
|
coords: {
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { useEffect, useState } from 'react';
|
|
14
14
|
export const TOOLTIP_MAX_WIDTH = 650;
|
|
15
|
-
export const TOOLTIP_MAX_HEIGHT =
|
|
15
|
+
export const TOOLTIP_MAX_HEIGHT = 400;
|
|
16
16
|
export const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;
|
|
17
|
-
export const TOOLTIP_MAX_ITEMS =
|
|
17
|
+
export const TOOLTIP_MAX_ITEMS = 30;
|
|
18
18
|
export const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
|
|
19
19
|
year: 'numeric',
|
|
20
20
|
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 { FocusedSeriesArray } from './focused-series';\n\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 { FocusedSeriesArray } from './focused-series';\n\nexport const TOOLTIP_MAX_WIDTH = 650;\nexport const TOOLTIP_MAX_HEIGHT = 400;\nexport const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;\n\nexport const TOOLTIP_MAX_ITEMS = 30;\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 CursorCoordinates {\n page: {\n x: number;\n y: number;\n };\n plotCanvas: {\n x: number;\n y: number;\n };\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: FocusedSeriesArray | 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 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_MAX_WIDTH","TOOLTIP_MAX_HEIGHT","TOOLTIP_LABELS_MAX_WIDTH","TOOLTIP_MAX_ITEMS","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","offsetX","offsetY","zrX","zrY","window","addEventListener","removeEventListener"],"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;AAEjC,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAG5C,OAAO,MAAMC,iBAAiB,GAAG,GAAG,CAAC;AACrC,OAAO,MAAMC,kBAAkB,GAAG,GAAG,CAAC;AACtC,OAAO,MAAMC,wBAAwB,GAAGF,iBAAiB,GAAG,GAAG,CAAC;AAEhE,OAAO,MAAMG,iBAAiB,GAAG,EAAE,CAAC;AAEpC,OAAO,MAAMC,mBAAmB,GAAG,IAAIC,IAAI,CAACC,cAAc,CAACC,SAAS,EAAE;IACpEC,IAAI,EAAE,SAAS;IACfC,KAAK,EAAE,OAAO;IACdC,GAAG,EAAE,SAAS;IACdC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE,SAAS;IACjBC,MAAM,EAAE,SAAS;IACjBC,MAAM,EAAE,IAAI;CACb,CAAC,CAAC;AAEH,OAAO,MAAMC,iBAAiB,GAAG;IAC/BC,MAAM,EAAE;QACNC,UAAU,EAAE;YACVC,CAAC,EAAE,CAAC;YACJC,CAAC,EAAE,CAAC;SACL;QACDC,OAAO,EAAE;YACPF,CAAC,EAAE,CAAC;YACJC,CAAC,EAAE,CAAC;SACL;QACDE,MAAM,EAAE,IAAI;KACb;IACDC,UAAU,EAAE,CAAC;CACd,CAAC;AAEF,OAAO,MAAMC,gBAAgB,GAAG;IAC9BC,MAAM,EAAET,iBAAiB;IACzBU,aAAa,EAAE,IAAI;CACpB,CAAC;AAsCF,OAAO,MAAMC,gBAAgB,GAAG,IAA4B;IAC1D,MAAM,CAACV,MAAM,EAAEW,SAAS,CAAC,GAAG5B,QAAQ,CAAuB,IAAI,CAAC,AAAC;IAEjED,SAAS,CAAC,IAAM;QACd,MAAM8B,YAAY,GAAG,CAACC,CAAkB,GAAK;YAC3C,OAAOF,SAAS,CAAC;gBACfG,IAAI,EAAE;oBACJZ,CAAC,EAAEW,CAAC,CAACE,KAAK;oBACVZ,CAAC,EAAEU,CAAC,CAACG,KAAK;iBACX;gBACDf,UAAU,EAAE;oBACVC,CAAC,EAAEW,CAAC,CAACI,OAAO;oBACZd,CAAC,EAAEU,CAAC,CAACK,OAAO;iBACb;gBACDd,OAAO,EAAE;oBACP,4DAA4D;oBAC5D,iHAAiH;oBACjHF,CAAC,EAAEW,CAAC,CAACM,GAAG;oBACRhB,CAAC,EAAEU,CAAC,CAACO,GAAG;iBACT;gBACD,0HAA0H;gBAC1Hf,MAAM,EAAEQ,CAAC,CAACR,MAAM;aACjB,CAAC,CAAC;QACL,CAAC,AAAC;QACFgB,MAAM,CAACC,gBAAgB,CAAC,WAAW,EAAEV,YAAY,CAAC,CAAC;QAEnD,OAAO,IAAM;YACXS,MAAM,CAACE,mBAAmB,CAAC,WAAW,EAAEX,YAAY,CAAC,CAAC;QACxD,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAOZ,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnitSelector.d.ts","sourceRoot":"","sources":["../../src/UnitSelector/UnitSelector.tsx"],"names":[],"mappings":";AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"UnitSelector.d.ts","sourceRoot":"","sources":["../../src/UnitSelector/UnitSelector.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,WAAW,EAA0E,MAAM,UAAU,CAAC;AAG/G,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;CACvC;AA0BD,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,iBAAiB,eAkFlE"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
14
|
import { Box, Switch, TextField, Autocomplete } from '@mui/material';
|
|
15
|
-
import { UNIT_CONFIG,
|
|
15
|
+
import { UNIT_CONFIG, isUnitWithDecimalPlaces, isUnitWithAbbreviate } from '../model';
|
|
16
16
|
import { OptionsEditorControl } from '../OptionsEditorLayout';
|
|
17
17
|
const KIND_OPTIONS = Object.entries(UNIT_CONFIG).map(([id, config])=>{
|
|
18
18
|
return {
|
|
@@ -20,13 +20,35 @@ const KIND_OPTIONS = Object.entries(UNIT_CONFIG).map(([id, config])=>{
|
|
|
20
20
|
...config
|
|
21
21
|
};
|
|
22
22
|
}).filter((config)=>!config.disableSelectorOption);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const DECIMAL_PLACES_OPTIONS = [
|
|
24
|
+
{
|
|
25
|
+
label: 'Default',
|
|
26
|
+
decimal_places: undefined
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
label: '0',
|
|
30
|
+
decimal_places: 0
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
label: '1',
|
|
34
|
+
decimal_places: 1
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
label: '2',
|
|
38
|
+
decimal_places: 2
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: '3',
|
|
42
|
+
decimal_places: 3
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
label: '4',
|
|
46
|
+
decimal_places: 4
|
|
47
|
+
}
|
|
29
48
|
];
|
|
49
|
+
function getOptionByDecimalPlaces(decimal_places) {
|
|
50
|
+
return DECIMAL_PLACES_OPTIONS.find((o)=>o.decimal_places === decimal_places);
|
|
51
|
+
}
|
|
30
52
|
export function UnitSelector({ value , onChange }) {
|
|
31
53
|
const hasDecimalPlaces = isUnitWithDecimalPlaces(value);
|
|
32
54
|
const hasAbbreviate = isUnitWithAbbreviate(value);
|
|
@@ -35,11 +57,11 @@ export function UnitSelector({ value , onChange }) {
|
|
|
35
57
|
kind: newValue.id
|
|
36
58
|
});
|
|
37
59
|
};
|
|
38
|
-
const
|
|
60
|
+
const handleDecimalPlacesChange = (_, { decimal_places })=>{
|
|
39
61
|
if (hasDecimalPlaces) {
|
|
40
62
|
onChange({
|
|
41
63
|
...value,
|
|
42
|
-
decimal_places:
|
|
64
|
+
decimal_places: decimal_places
|
|
43
65
|
});
|
|
44
66
|
}
|
|
45
67
|
};
|
|
@@ -52,7 +74,6 @@ export function UnitSelector({ value , onChange }) {
|
|
|
52
74
|
}
|
|
53
75
|
};
|
|
54
76
|
const kindConfig = UNIT_CONFIG[value.kind];
|
|
55
|
-
var _decimal_places;
|
|
56
77
|
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
57
78
|
children: [
|
|
58
79
|
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
@@ -64,7 +85,7 @@ export function UnitSelector({ value , onChange }) {
|
|
|
64
85
|
})
|
|
65
86
|
}),
|
|
66
87
|
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
67
|
-
label: "
|
|
88
|
+
label: "Unit",
|
|
68
89
|
control: /*#__PURE__*/ _jsx(Autocomplete, {
|
|
69
90
|
value: {
|
|
70
91
|
id: value.kind,
|
|
@@ -92,15 +113,16 @@ export function UnitSelector({ value , onChange }) {
|
|
|
92
113
|
})
|
|
93
114
|
}),
|
|
94
115
|
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
95
|
-
label: "
|
|
116
|
+
label: "Decimals",
|
|
96
117
|
control: /*#__PURE__*/ _jsx(Autocomplete, {
|
|
97
|
-
value:
|
|
98
|
-
options:
|
|
99
|
-
getOptionLabel: (
|
|
118
|
+
value: getOptionByDecimalPlaces(value.decimal_places),
|
|
119
|
+
options: DECIMAL_PLACES_OPTIONS,
|
|
120
|
+
getOptionLabel: (o)=>o.label,
|
|
121
|
+
isOptionEqualToValue: (option, value)=>option.label === value.label,
|
|
100
122
|
renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
|
|
101
123
|
...params
|
|
102
124
|
}),
|
|
103
|
-
onChange:
|
|
125
|
+
onChange: handleDecimalPlacesChange,
|
|
104
126
|
disabled: !hasDecimalPlaces,
|
|
105
127
|
disableClearable: true
|
|
106
128
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/UnitSelector/UnitSelector.tsx"],"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.\nimport { Box, Switch, TextField, Autocomplete, SwitchProps } from '@mui/material';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/UnitSelector/UnitSelector.tsx"],"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.\nimport { Box, Switch, TextField, Autocomplete, SwitchProps } from '@mui/material';\nimport { UnitOptions, UNIT_CONFIG, UnitConfig, isUnitWithDecimalPlaces, isUnitWithAbbreviate } from '../model';\nimport { OptionsEditorControl } from '../OptionsEditorLayout';\n\nexport interface UnitSelectorProps {\n value: UnitOptions;\n onChange: (unit: UnitOptions) => void;\n}\n\ntype AutocompleteKindOption = UnitConfig & { id: UnitOptions['kind'] };\n\nconst KIND_OPTIONS: AutocompleteKindOption[] = Object.entries(UNIT_CONFIG)\n .map(([id, config]) => {\n return {\n id: id as UnitOptions['kind'],\n ...config,\n };\n })\n .filter((config) => !config.disableSelectorOption);\n\nconst DECIMAL_PLACES_OPTIONS = [\n { label: 'Default', decimal_places: undefined },\n { label: '0', decimal_places: 0 },\n { label: '1', decimal_places: 1 },\n { label: '2', decimal_places: 2 },\n { label: '3', decimal_places: 3 },\n { label: '4', decimal_places: 4 },\n];\n\nfunction getOptionByDecimalPlaces(decimal_places?: number) {\n return DECIMAL_PLACES_OPTIONS.find((o) => o.decimal_places === decimal_places);\n}\n\nexport function UnitSelector({ value, onChange }: UnitSelectorProps) {\n const hasDecimalPlaces = isUnitWithDecimalPlaces(value);\n const hasAbbreviate = isUnitWithAbbreviate(value);\n\n const handleKindChange = (_: unknown, newValue: AutocompleteKindOption) => {\n onChange({\n kind: newValue.id,\n });\n };\n\n const handleDecimalPlacesChange = (_: unknown, { decimal_places }: { decimal_places: number | undefined }) => {\n if (hasDecimalPlaces) {\n onChange({\n ...value,\n decimal_places: decimal_places,\n });\n }\n };\n\n const handleAbbreviateChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n if (hasAbbreviate) {\n onChange({\n ...value,\n abbreviate: checked,\n });\n }\n };\n\n const kindConfig = UNIT_CONFIG[value.kind];\n\n return (\n <>\n <OptionsEditorControl\n label=\"Abbreviate\"\n control={\n <Switch\n checked={hasAbbreviate ? !!value.abbreviate : false}\n onChange={handleAbbreviateChange}\n disabled={!hasAbbreviate}\n />\n }\n />\n <OptionsEditorControl\n label=\"Unit\"\n control={\n <Autocomplete\n value={{ id: value.kind, ...kindConfig }}\n options={KIND_OPTIONS}\n isOptionEqualToValue={(option, value) => option.id === value.id}\n groupBy={(option) => option.group}\n renderInput={(params) => <TextField {...params} />}\n renderOption={(renderOptsProps, option) => {\n // Custom option needed to get some increased left padding to make\n // the items more distinct from the group label.\n return (\n <li {...renderOptsProps}>\n <Box paddingLeft={(theme) => theme.spacing(1)}>{option.label}</Box>\n </li>\n );\n }}\n onChange={handleKindChange}\n disableClearable\n ></Autocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Decimals\"\n control={\n <Autocomplete\n value={getOptionByDecimalPlaces(value.decimal_places)}\n options={DECIMAL_PLACES_OPTIONS}\n getOptionLabel={(o) => o.label}\n isOptionEqualToValue={(option, value) => option.label === value.label}\n renderInput={(params) => <TextField {...params} />}\n onChange={handleDecimalPlacesChange}\n disabled={!hasDecimalPlaces}\n disableClearable\n />\n }\n />\n </>\n );\n}\n"],"names":["Box","Switch","TextField","Autocomplete","UNIT_CONFIG","isUnitWithDecimalPlaces","isUnitWithAbbreviate","OptionsEditorControl","KIND_OPTIONS","Object","entries","map","id","config","filter","disableSelectorOption","DECIMAL_PLACES_OPTIONS","label","decimal_places","undefined","getOptionByDecimalPlaces","find","o","UnitSelector","value","onChange","hasDecimalPlaces","hasAbbreviate","handleKindChange","_","newValue","kind","handleDecimalPlacesChange","handleAbbreviateChange","checked","abbreviate","kindConfig","control","disabled","options","isOptionEqualToValue","option","groupBy","group","renderInput","params","renderOption","renderOptsProps","li","paddingLeft","theme","spacing","disableClearable","getOptionLabel"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;A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B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"YAxisLabel.d.ts","sourceRoot":"","sources":["../src/YAxisLabel.tsx"],"names":[],"mappings":";AAeA,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,eAAe,eA2B3D"}
|
package/dist/YAxisLabel.js
CHANGED
package/dist/YAxisLabel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/YAxisLabel.tsx"],"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 { Box, Typography } from '@mui/material';\n\ninterface YAxisLabelProps {\n name: string;\n height: number;\n}\n\nexport function YAxisLabel({ name, height }: YAxisLabelProps) {\n return (\n <Box\n sx={{\n display: 'inline-block',\n maxWidth: height, // allows rotated text to truncate instead of causing overlap\n position: 'absolute',\n top: '45%',\n transform: 'translateX(-50%) rotate(-90deg)',\n transformOrigin: 'top',\n textAlign: 'center',\n zIndex: 1,\n }}\n >\n <Typography\n variant=\"body1\"\n sx={{\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }}\n >\n {name}\n </Typography>\n </Box>\n );\n}\n"],"names":["Box","Typography","YAxisLabel","name","height","sx","display","maxWidth","position","top","transform","transformOrigin","textAlign","zIndex","variant","whiteSpace","overflow","textOverflow"],"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;AAEjC;AAAA,SAASA,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAOhD,OAAO,SAASC,UAAU,CAAC,EAAEC,IAAI,CAAA,EAAEC,MAAM,CAAA,EAAmB,EAAE;IAC5D,qBACE,KAACJ,GAAG;QACFK,EAAE,EAAE;YACFC,OAAO,EAAE,cAAc;YACvBC,QAAQ,EAAEH,MAAM;YAChBI,QAAQ,EAAE,UAAU;YACpBC,GAAG,EAAE,KAAK;YACVC,SAAS,EAAE,iCAAiC;YAC5CC,eAAe,EAAE,KAAK;YACtBC,SAAS,EAAE,QAAQ;YACnBC,MAAM,EAAE,CAAC;SACV;kBAED,cAAA,KAACZ,UAAU;YACTa,OAAO,EAAC,OAAO;
|
|
1
|
+
{"version":3,"sources":["../src/YAxisLabel.tsx"],"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 { Box, Typography } from '@mui/material';\n\ninterface YAxisLabelProps {\n name: string;\n height: number;\n}\n\nexport function YAxisLabel({ name, height }: YAxisLabelProps) {\n return (\n <Box\n sx={{\n display: 'inline-block',\n maxWidth: height, // allows rotated text to truncate instead of causing overlap\n position: 'absolute',\n top: '45%',\n transform: 'translateX(-50%) rotate(-90deg)',\n transformOrigin: 'top',\n textAlign: 'center',\n zIndex: 1,\n }}\n >\n <Typography\n variant=\"body1\"\n aria-label=\"y axis label\"\n sx={{\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }}\n >\n {name}\n </Typography>\n </Box>\n );\n}\n"],"names":["Box","Typography","YAxisLabel","name","height","sx","display","maxWidth","position","top","transform","transformOrigin","textAlign","zIndex","variant","aria-label","whiteSpace","overflow","textOverflow"],"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;AAEjC;AAAA,SAASA,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAOhD,OAAO,SAASC,UAAU,CAAC,EAAEC,IAAI,CAAA,EAAEC,MAAM,CAAA,EAAmB,EAAE;IAC5D,qBACE,KAACJ,GAAG;QACFK,EAAE,EAAE;YACFC,OAAO,EAAE,cAAc;YACvBC,QAAQ,EAAEH,MAAM;YAChBI,QAAQ,EAAE,UAAU;YACpBC,GAAG,EAAE,KAAK;YACVC,SAAS,EAAE,iCAAiC;YAC5CC,eAAe,EAAE,KAAK;YACtBC,SAAS,EAAE,QAAQ;YACnBC,MAAM,EAAE,CAAC;SACV;kBAED,cAAA,KAACZ,UAAU;YACTa,OAAO,EAAC,OAAO;YACfC,YAAU,EAAC,cAAc;YACzBV,EAAE,EAAE;gBACFW,UAAU,EAAE,QAAQ;gBACpBC,QAAQ,EAAE,QAAQ;gBAClBC,YAAY,EAAE,UAAU;aACzB;sBAEAf,IAAI;UACM;MACT,CACN;AACJ,CAAC"}
|
|
@@ -42,8 +42,14 @@ function TimeRangeSelector(props) {
|
|
|
42
42
|
'aria-label': `Select time range. Currently set to ${formattedValue}`
|
|
43
43
|
},
|
|
44
44
|
sx: {
|
|
45
|
+
// `transform: none` prevents calendar icon from flipping over when menu is open
|
|
45
46
|
'.MuiSelect-icon': {
|
|
46
|
-
marginTop: '1px'
|
|
47
|
+
marginTop: '1px',
|
|
48
|
+
transform: 'none'
|
|
49
|
+
},
|
|
50
|
+
// paddingRight creates more space for the calendar icon (it's a bigger icon)
|
|
51
|
+
'.MuiSelect-select.MuiSelect-outlined.MuiInputBase-input': {
|
|
52
|
+
paddingRight: '36px'
|
|
47
53
|
},
|
|
48
54
|
'.MuiSelect-select': height ? {
|
|
49
55
|
lineHeight: height,
|
|
@@ -23,6 +23,7 @@ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
|
23
23
|
const _core = require("echarts/core");
|
|
24
24
|
const _material = require("@mui/material");
|
|
25
25
|
const _lodashEs = require("lodash-es");
|
|
26
|
+
const _utils = require("../utils");
|
|
26
27
|
function _getRequireWildcardCache(nodeInterop) {
|
|
27
28
|
if (typeof WeakMap !== "function") return null;
|
|
28
29
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -153,7 +154,12 @@ const EChart = /*#__PURE__*/ _react.default.memo(function EChart({ option , them
|
|
|
153
154
|
]);
|
|
154
155
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
155
156
|
ref: containerRef,
|
|
156
|
-
sx:
|
|
157
|
+
sx: (0, _utils.combineSx)({
|
|
158
|
+
// Ensures chart fills container and updates size correctly when resizing,
|
|
159
|
+
// combineSx allows this default behavior to be overriden from parent component
|
|
160
|
+
width: '100%',
|
|
161
|
+
height: '100%'
|
|
162
|
+
}, sx)
|
|
157
163
|
});
|
|
158
164
|
});
|
|
159
165
|
// Validate event config and bind custom events
|
|
@@ -163,11 +163,15 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
|
|
|
163
163
|
tooltip: {
|
|
164
164
|
show: !isOptimizedMode,
|
|
165
165
|
trigger: 'axis',
|
|
166
|
-
showContent: false
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
166
|
+
showContent: false
|
|
167
|
+
},
|
|
168
|
+
// https://echarts.apache.org/en/option.html#axisPointer
|
|
169
|
+
axisPointer: {
|
|
170
|
+
type: isOptimizedMode ? 'none' : 'line',
|
|
171
|
+
z: 0,
|
|
172
|
+
triggerEmphasis: false,
|
|
173
|
+
triggerTooltip: false,
|
|
174
|
+
snap: true
|
|
171
175
|
},
|
|
172
176
|
toolbox: {
|
|
173
177
|
feature: {
|
|
@@ -230,10 +234,6 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
|
|
|
230
234
|
unit: unit
|
|
231
235
|
}),
|
|
232
236
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
|
|
233
|
-
sx: {
|
|
234
|
-
width: '100%',
|
|
235
|
-
height: '100%'
|
|
236
|
-
},
|
|
237
237
|
option: option,
|
|
238
238
|
theme: chartsTheme.echartsTheme,
|
|
239
239
|
onEvents: handleEvents,
|
|
@@ -98,12 +98,18 @@ function StatChart(props) {
|
|
|
98
98
|
const charactersAdjust = formattedValue.length;
|
|
99
99
|
const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
|
|
100
100
|
const containerPadding = `${chartsTheme.container.padding.default}px`;
|
|
101
|
+
const textAlignment = sparkline ? 'auto' : 'center';
|
|
102
|
+
const textStyles = {
|
|
103
|
+
display: 'flex',
|
|
104
|
+
flexDirection: 'column',
|
|
105
|
+
justifyContent: textAlignment,
|
|
106
|
+
alignItems: textAlignment
|
|
107
|
+
};
|
|
101
108
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
102
109
|
sx: {
|
|
103
110
|
height: '100%',
|
|
104
111
|
width: '100%',
|
|
105
|
-
|
|
106
|
-
flexDirection: 'column'
|
|
112
|
+
...textStyles
|
|
107
113
|
},
|
|
108
114
|
children: [
|
|
109
115
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
|
|
@@ -115,19 +121,10 @@ function StatChart(props) {
|
|
|
115
121
|
}),
|
|
116
122
|
children: formattedValue
|
|
117
123
|
}),
|
|
118
|
-
sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
|
|
123
|
-
sx: {
|
|
124
|
-
width: '100%',
|
|
125
|
-
height: '100%'
|
|
126
|
-
},
|
|
127
|
-
option: option,
|
|
128
|
-
theme: chartsTheme.echartsTheme,
|
|
129
|
-
renderer: "svg"
|
|
130
|
-
})
|
|
124
|
+
sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
|
|
125
|
+
option: option,
|
|
126
|
+
theme: chartsTheme.echartsTheme,
|
|
127
|
+
renderer: "svg"
|
|
131
128
|
})
|
|
132
129
|
]
|
|
133
130
|
});
|
|
@@ -26,7 +26,7 @@ const _seriesInfo = require("./SeriesInfo");
|
|
|
26
26
|
function TooltipContent(props) {
|
|
27
27
|
const { focusedSeries , wrapLabels } = props;
|
|
28
28
|
const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
|
|
29
|
-
const seriesTime = focusedSeries && focusedSeries[0] && focusedSeries[0].
|
|
29
|
+
const seriesTime = focusedSeries && focusedSeries[0] && focusedSeries[0].dateMs ? focusedSeries[0].dateMs : null;
|
|
30
30
|
const formatTimeSeriesHeader = (timeString)=>{
|
|
31
31
|
const date = new Date(timeString);
|
|
32
32
|
const formattedDate = formatWithUserTimeZone(date, 'MMM dd, yyyy - ');
|
|
@@ -21,12 +21,18 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
+
DEFAULT_NEARBY_SERIES_RANGE_MULTIPLIER: ()=>DEFAULT_NEARBY_SERIES_RANGE_MULTIPLIER,
|
|
25
|
+
NARROW_NEARBY_SERIES_RANGE_MULTIPLIER: ()=>NARROW_NEARBY_SERIES_RANGE_MULTIPLIER,
|
|
26
|
+
SHOW_MORE_NEARBY_SERIES_LIMIT: ()=>SHOW_MORE_NEARBY_SERIES_LIMIT,
|
|
24
27
|
getNearbySeries: ()=>getNearbySeries,
|
|
25
28
|
getFocusedSeriesData: ()=>getFocusedSeriesData
|
|
26
29
|
});
|
|
27
30
|
const _model = require("../model");
|
|
28
31
|
const _tooltipModel = require("./tooltip-model");
|
|
29
|
-
|
|
32
|
+
const DEFAULT_NEARBY_SERIES_RANGE_MULTIPLIER = 5.5; // adjusts how many focused series show in tooltip
|
|
33
|
+
const NARROW_NEARBY_SERIES_RANGE_MULTIPLIER = 2; // used to reduce number of focused series for heavy queries
|
|
34
|
+
const SHOW_MORE_NEARBY_SERIES_LIMIT = 5;
|
|
35
|
+
function getNearbySeries(data, pointInGrid, yBuffer, chart, unit) {
|
|
30
36
|
const currentFocusedData = [];
|
|
31
37
|
var ref;
|
|
32
38
|
const focusedX = (ref = pointInGrid[0]) !== null && ref !== void 0 ? ref : null;
|
|
@@ -53,18 +59,33 @@ function getNearbySeries(data, pointInGrid, yBuffer, unit) {
|
|
|
53
59
|
if (yValue !== '-' && focusedY <= yValue + yBuffer && focusedY >= yValue - yBuffer) {
|
|
54
60
|
// determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
|
|
55
61
|
const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
|
|
56
|
-
const formattedDate = _tooltipModel.TOOLTIP_DATE_FORMAT.format(xValueMilliSeconds);
|
|
57
62
|
const formattedY = (0, _model.formatValue)(yValue, unit);
|
|
63
|
+
// trigger emphasis state of nearby series so tooltip matches highlighted lines
|
|
64
|
+
// https://echarts.apache.org/en/api.html#action.highlight
|
|
65
|
+
if ((chart === null || chart === void 0 ? void 0 : chart.dispatchAction) !== undefined) {
|
|
66
|
+
chart.dispatchAction({
|
|
67
|
+
type: 'highlight',
|
|
68
|
+
seriesIndex: seriesIdx
|
|
69
|
+
});
|
|
70
|
+
}
|
|
58
71
|
currentFocusedData.push({
|
|
59
72
|
seriesIdx: seriesIdx,
|
|
60
73
|
datumIdx: datumIdx,
|
|
61
74
|
seriesName: currentSeriesName,
|
|
62
|
-
|
|
75
|
+
dateMs: xValueMilliSeconds,
|
|
63
76
|
x: xValue,
|
|
64
77
|
y: yValue,
|
|
65
78
|
formattedY: formattedY,
|
|
66
79
|
markerColor: markerColor.toString()
|
|
67
80
|
});
|
|
81
|
+
} else {
|
|
82
|
+
// clear emphasis state of lines that are not focused
|
|
83
|
+
if ((chart === null || chart === void 0 ? void 0 : chart.dispatchAction) !== undefined) {
|
|
84
|
+
chart.dispatchAction({
|
|
85
|
+
type: 'downplay',
|
|
86
|
+
seriesIndex: seriesIdx
|
|
87
|
+
});
|
|
88
|
+
}
|
|
68
89
|
}
|
|
69
90
|
}
|
|
70
91
|
}
|
|
@@ -99,9 +120,9 @@ function getFocusedSeriesData(mousePos, chartData, pinnedPos, chart, unit) {
|
|
|
99
120
|
if (chart['_model'] === undefined) return [];
|
|
100
121
|
const chartModel = chart['_model'];
|
|
101
122
|
const yAxisInterval = chartModel.getComponent('yAxis').axis.scale._interval;
|
|
102
|
-
// tooltip trigger area gets smaller with more series, increase yAxisInterval multiplier to expand nearby series range
|
|
103
123
|
const seriesNum = chartData.timeSeries.length;
|
|
104
|
-
|
|
124
|
+
// tooltip trigger area gets smaller with more series, increase yAxisInterval multiplier to expand nearby series range
|
|
125
|
+
const yBuffer = seriesNum > SHOW_MORE_NEARBY_SERIES_LIMIT ? yAxisInterval * NARROW_NEARBY_SERIES_RANGE_MULTIPLIER : yAxisInterval * DEFAULT_NEARBY_SERIES_RANGE_MULTIPLIER;
|
|
105
126
|
var _x, _y;
|
|
106
127
|
const pointInPixel = [
|
|
107
128
|
(_x = mousePos.plotCanvas.x) !== null && _x !== void 0 ? _x : 0,
|
|
@@ -110,7 +131,17 @@ function getFocusedSeriesData(mousePos, chartData, pinnedPos, chart, unit) {
|
|
|
110
131
|
if (chart.containPixel('grid', pointInPixel)) {
|
|
111
132
|
const pointInGrid = chart.convertFromPixel('grid', pointInPixel);
|
|
112
133
|
if (pointInGrid[0] !== undefined && pointInGrid[1] !== undefined) {
|
|
113
|
-
return getNearbySeries(chartData, pointInGrid, yBuffer, unit);
|
|
134
|
+
return getNearbySeries(chartData, pointInGrid, yBuffer, chart, unit);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// clear all highlighted series when cursor exits canvas
|
|
138
|
+
// https://echarts.apache.org/en/api.html#action.downplay
|
|
139
|
+
for(let i = 0; i < seriesNum; i++){
|
|
140
|
+
if ((chart === null || chart === void 0 ? void 0 : chart.dispatchAction) !== undefined) {
|
|
141
|
+
chart.dispatchAction({
|
|
142
|
+
type: 'downplay',
|
|
143
|
+
seriesIndex: i
|
|
144
|
+
});
|
|
114
145
|
}
|
|
115
146
|
}
|
|
116
147
|
return [];
|
|
@@ -32,9 +32,9 @@ _export(exports, {
|
|
|
32
32
|
});
|
|
33
33
|
const _react = require("react");
|
|
34
34
|
const TOOLTIP_MAX_WIDTH = 650;
|
|
35
|
-
const TOOLTIP_MAX_HEIGHT =
|
|
35
|
+
const TOOLTIP_MAX_HEIGHT = 400;
|
|
36
36
|
const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;
|
|
37
|
-
const TOOLTIP_MAX_ITEMS =
|
|
37
|
+
const TOOLTIP_MAX_ITEMS = 30;
|
|
38
38
|
const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
|
|
39
39
|
year: 'numeric',
|
|
40
40
|
month: 'short',
|
|
@@ -28,13 +28,35 @@ const KIND_OPTIONS = Object.entries(_model.UNIT_CONFIG).map(([id, config])=>{
|
|
|
28
28
|
...config
|
|
29
29
|
};
|
|
30
30
|
}).filter((config)=>!config.disableSelectorOption);
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
const DECIMAL_PLACES_OPTIONS = [
|
|
32
|
+
{
|
|
33
|
+
label: 'Default',
|
|
34
|
+
decimal_places: undefined
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
label: '0',
|
|
38
|
+
decimal_places: 0
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: '1',
|
|
42
|
+
decimal_places: 1
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
label: '2',
|
|
46
|
+
decimal_places: 2
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
label: '3',
|
|
50
|
+
decimal_places: 3
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: '4',
|
|
54
|
+
decimal_places: 4
|
|
55
|
+
}
|
|
37
56
|
];
|
|
57
|
+
function getOptionByDecimalPlaces(decimal_places) {
|
|
58
|
+
return DECIMAL_PLACES_OPTIONS.find((o)=>o.decimal_places === decimal_places);
|
|
59
|
+
}
|
|
38
60
|
function UnitSelector({ value , onChange }) {
|
|
39
61
|
const hasDecimalPlaces = (0, _model.isUnitWithDecimalPlaces)(value);
|
|
40
62
|
const hasAbbreviate = (0, _model.isUnitWithAbbreviate)(value);
|
|
@@ -43,11 +65,11 @@ function UnitSelector({ value , onChange }) {
|
|
|
43
65
|
kind: newValue.id
|
|
44
66
|
});
|
|
45
67
|
};
|
|
46
|
-
const
|
|
68
|
+
const handleDecimalPlacesChange = (_, { decimal_places })=>{
|
|
47
69
|
if (hasDecimalPlaces) {
|
|
48
70
|
onChange({
|
|
49
71
|
...value,
|
|
50
|
-
decimal_places:
|
|
72
|
+
decimal_places: decimal_places
|
|
51
73
|
});
|
|
52
74
|
}
|
|
53
75
|
};
|
|
@@ -60,7 +82,6 @@ function UnitSelector({ value , onChange }) {
|
|
|
60
82
|
}
|
|
61
83
|
};
|
|
62
84
|
const kindConfig = _model.UNIT_CONFIG[value.kind];
|
|
63
|
-
var _decimal_places;
|
|
64
85
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
65
86
|
children: [
|
|
66
87
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
|
|
@@ -72,7 +93,7 @@ function UnitSelector({ value , onChange }) {
|
|
|
72
93
|
})
|
|
73
94
|
}),
|
|
74
95
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
|
|
75
|
-
label: "
|
|
96
|
+
label: "Unit",
|
|
76
97
|
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
|
|
77
98
|
value: {
|
|
78
99
|
id: value.kind,
|
|
@@ -100,15 +121,16 @@ function UnitSelector({ value , onChange }) {
|
|
|
100
121
|
})
|
|
101
122
|
}),
|
|
102
123
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
|
|
103
|
-
label: "
|
|
124
|
+
label: "Decimals",
|
|
104
125
|
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
|
|
105
|
-
value:
|
|
106
|
-
options:
|
|
107
|
-
getOptionLabel: (
|
|
126
|
+
value: getOptionByDecimalPlaces(value.decimal_places),
|
|
127
|
+
options: DECIMAL_PLACES_OPTIONS,
|
|
128
|
+
getOptionLabel: (o)=>o.label,
|
|
129
|
+
isOptionEqualToValue: (option, value)=>option.label === value.label,
|
|
108
130
|
renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
109
131
|
...params
|
|
110
132
|
}),
|
|
111
|
-
onChange:
|
|
133
|
+
onChange: handleDecimalPlacesChange,
|
|
112
134
|
disabled: !hasDecimalPlaces,
|
|
113
135
|
disableClearable: true
|
|
114
136
|
})
|