@perses-dev/components 0.27.0 → 0.29.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/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 +0 -4
- 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/tooltip-model.d.ts +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.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/EChart/EChart.js +7 -1
- package/dist/cjs/LineChart/LineChart.js +0 -4
- package/dist/cjs/StatChart/StatChart.js +12 -15
- package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +1 -1
- package/dist/cjs/YAxisLabel.js +1 -0
- package/dist/cjs/model/units/percent.js +23 -7
- package/dist/cjs/model/units/time.js +5 -5
- package/dist/cjs/utils/theme-gen.js +8 -5
- package/dist/model/units/percent.d.ts +1 -1
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js +23 -7
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/time.d.ts +1 -1
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +5 -5
- 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/utils/theme-gen.d.ts.map +1 -1
- package/dist/utils/theme-gen.js +8 -5
- package/dist/utils/theme-gen.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EChart.d.ts","sourceRoot":"","sources":["../../src/EChart/EChart.tsx"],"names":[],"mappings":"AAaA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAQ,MAAM,cAAc,CAAC;AAChE,OAAO,EAAO,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"EChart.d.ts","sourceRoot":"","sources":["../../src/EChart/EChart.tsx"],"names":[],"mappings":"AAaA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAQ,MAAM,cAAc,CAAC;AAChE,OAAO,EAAO,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAIxC,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,aAAK,eAAe,CAAC,CAAC,IAAI,CACxB,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAEhC,QAAQ,CAAC,EAAE,OAAO,KACf,IAAI,CAAC;AAEV,QAAA,MAAM,WAAW,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GAAG,KAAK,CAAC;IAC5B,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IACxD,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,MAAM,6IAwFjB,CAAC"}
|
package/dist/EChart/EChart.js
CHANGED
|
@@ -15,6 +15,7 @@ import React, { useEffect, useLayoutEffect, useRef } from 'react';
|
|
|
15
15
|
import { init } from 'echarts/core';
|
|
16
16
|
import { Box } from '@mui/material';
|
|
17
17
|
import { isEqual, debounce } from 'lodash-es';
|
|
18
|
+
import { combineSx } from '../utils';
|
|
18
19
|
const mouseEvents = [
|
|
19
20
|
'click',
|
|
20
21
|
'dblclick',
|
|
@@ -106,7 +107,12 @@ export const EChart = /*#__PURE__*/ React.memo(function EChart({ option , theme
|
|
|
106
107
|
]);
|
|
107
108
|
return /*#__PURE__*/ _jsx(Box, {
|
|
108
109
|
ref: containerRef,
|
|
109
|
-
sx:
|
|
110
|
+
sx: combineSx({
|
|
111
|
+
// Ensures chart fills container and updates size correctly when resizing,
|
|
112
|
+
// combineSx allows this default behavior to be overriden from parent component
|
|
113
|
+
width: '100%',
|
|
114
|
+
height: '100%'
|
|
115
|
+
}, sx)
|
|
110
116
|
});
|
|
111
117
|
});
|
|
112
118
|
// Validate event config and bind custom events
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/EChart/EChart.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 React, { useEffect, useLayoutEffect, useRef } from 'react';\nimport { ECharts, EChartsCoreOption, init } from 'echarts/core';\nimport { Box, SxProps, Theme } from '@mui/material';\nimport { isEqual, debounce } from 'lodash-es';\nimport { EChartsTheme } from '../model';\n\n// see docs for info about each property: https://echarts.apache.org/en/api.html#events\nexport interface MouseEventsParameters<T> {\n componentType: string;\n seriesType: string;\n seriesIndex: number;\n seriesName: string;\n name: string;\n dataIndex: number;\n data: Record<string, unknown> & T;\n dataType: string;\n value: number | number[];\n color: string;\n info: Record<string, unknown>;\n}\n\ntype OnEventFunction<T> = (\n params: MouseEventsParameters<T>,\n // This is potentially undefined for testing purposes\n instance?: ECharts\n) => void;\n\nconst mouseEvents = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mousemove',\n 'mouseup',\n 'mouseover',\n 'mouseout',\n 'globalout',\n 'contextmenu',\n] as const;\n\nexport type MouseEventName = (typeof mouseEvents)[number];\n\n// batch event types\nexport interface DataZoomPayloadBatchItem {\n dataZoomId: string;\n // start and end not returned unless dataZoom is based on percentProp,\n // which is for cases when a dataZoom component controls multiple axes\n start?: number;\n end?: number;\n // startValue and endValue return data index for 'category' axes,\n // for axis types 'value' and 'time', actual values are returned\n startValue?: number;\n endValue?: number;\n}\n\nexport interface HighlightPayloadBatchItem {\n dataIndex: number;\n dataIndexInside: number;\n seriesIndex: number;\n // highlight action can effect multiple connected charts\n escapeConnect?: boolean;\n // whether blur state was triggered\n notBlur?: boolean;\n}\n\nexport interface BatchEventsParameters {\n type: BatchEventName;\n batch: DataZoomPayloadBatchItem[] & HighlightPayloadBatchItem[];\n}\n\ntype OnBatchEventFunction = (params: BatchEventsParameters) => void;\n\nconst batchEvents = ['datazoom', 'downplay', 'highlight'] as const;\n\nexport type BatchEventName = (typeof batchEvents)[number];\n\ntype ChartEventName = 'finished';\n\ntype EventName = MouseEventName | ChartEventName | BatchEventName;\n\nexport type OnEventsType<T> = {\n [mouseEventName in MouseEventName]?: OnEventFunction<T>;\n} & {\n [batchEventName in BatchEventName]?: OnBatchEventFunction;\n} & {\n [eventName in ChartEventName]?: () => void;\n};\n\nexport interface EChartsProps<T> {\n option: EChartsCoreOption;\n theme?: string | EChartsTheme;\n renderer?: 'canvas' | 'svg';\n sx?: SxProps<Theme>;\n onEvents?: OnEventsType<T>;\n _instance?: React.MutableRefObject<ECharts | undefined>;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = React.memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n onEvents,\n _instance,\n onChartInitialized,\n}: EChartsProps<T>) {\n const initialOption = useRef<EChartsCoreOption>(option);\n const prevOption = useRef<EChartsCoreOption>(option);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const chartElement = useRef<ECharts | null>(null);\n\n // Initialize chart, dispose on unmount\n useLayoutEffect(() => {\n if (containerRef.current === null || chartElement.current !== null) return;\n chartElement.current = init(containerRef.current, theme, { renderer: renderer ?? 'canvas' });\n if (chartElement.current === undefined) return;\n chartElement.current.setOption(initialOption.current, true);\n onChartInitialized?.(chartElement.current);\n if (_instance !== undefined) {\n _instance.current = chartElement.current;\n }\n return () => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [_instance, onChartInitialized, theme, renderer]);\n\n // Update chart data when option changes\n useEffect(() => {\n if (prevOption.current === undefined || isEqual(prevOption.current, option)) return;\n if (!chartElement.current) return;\n chartElement.current.setOption(option, true);\n prevOption.current = option;\n }, [option]);\n\n // Resize chart, cleanup listener on unmount\n useLayoutEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n window.addEventListener('resize', updateSize);\n updateSize();\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, []);\n\n // Bind and unbind chart events passed as prop\n useEffect(() => {\n const chart = chartElement.current;\n if (!chart || onEvents === undefined) return;\n bindEvents(chart, onEvents);\n return () => {\n if (chart === undefined) return;\n if (chart.isDisposed() === true) return;\n for (const event in onEvents) {\n chart.off(event);\n }\n };\n }, [onEvents]);\n\n useEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n updateSize();\n }, [sx]);\n\n return <Box ref={containerRef} sx={sx}></Box>;\n});\n\n// Validate event config and bind custom events\nfunction bindEvents<T>(instance: ECharts, events?: OnEventsType<T>) {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown) {\n if (typeof OnEventFunction === 'function') {\n if (isMouseEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params, instance));\n } else if (isBatchEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params));\n } else {\n instance.on(eventName, () => OnEventFunction(null, instance));\n }\n }\n }\n\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n const customEvent = events[eventName as EventName] ?? null;\n if (customEvent) {\n bindEvent(eventName as EventName, customEvent);\n }\n }\n }\n}\n\nfunction isMouseEvent(eventName: EventName): eventName is MouseEventName {\n return (mouseEvents as readonly string[]).includes(eventName);\n}\n\nfunction isBatchEvent(eventName: EventName): eventName is BatchEventName {\n return (batchEvents as readonly string[]).includes(eventName);\n}\n"],"names":["React","useEffect","useLayoutEffect","useRef","init","Box","isEqual","debounce","mouseEvents","batchEvents","EChart","memo","option","theme","renderer","sx","onEvents","_instance","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","updateSize","resize","window","addEventListener","removeEventListener","chart","bindEvents","isDisposed","event","off","ref","instance","events","bindEvent","eventName","OnEventFunction","isMouseEvent","on","params","isBatchEvent","Object","prototype","hasOwnProperty","call","customEvent","includes"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;A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ACX,SAAS,CAAC,CAAC;AAChE,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/EChart/EChart.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 React, { useEffect, useLayoutEffect, useRef } from 'react';\nimport { ECharts, EChartsCoreOption, init } from 'echarts/core';\nimport { Box, SxProps, Theme } from '@mui/material';\nimport { isEqual, debounce } from 'lodash-es';\nimport { EChartsTheme } from '../model';\nimport { combineSx } from '../utils';\n\n// see docs for info about each property: https://echarts.apache.org/en/api.html#events\nexport interface MouseEventsParameters<T> {\n componentType: string;\n seriesType: string;\n seriesIndex: number;\n seriesName: string;\n name: string;\n dataIndex: number;\n data: Record<string, unknown> & T;\n dataType: string;\n value: number | number[];\n color: string;\n info: Record<string, unknown>;\n}\n\ntype OnEventFunction<T> = (\n params: MouseEventsParameters<T>,\n // This is potentially undefined for testing purposes\n instance?: ECharts\n) => void;\n\nconst mouseEvents = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mousemove',\n 'mouseup',\n 'mouseover',\n 'mouseout',\n 'globalout',\n 'contextmenu',\n] as const;\n\nexport type MouseEventName = (typeof mouseEvents)[number];\n\n// batch event types\nexport interface DataZoomPayloadBatchItem {\n dataZoomId: string;\n // start and end not returned unless dataZoom is based on percentProp,\n // which is for cases when a dataZoom component controls multiple axes\n start?: number;\n end?: number;\n // startValue and endValue return data index for 'category' axes,\n // for axis types 'value' and 'time', actual values are returned\n startValue?: number;\n endValue?: number;\n}\n\nexport interface HighlightPayloadBatchItem {\n dataIndex: number;\n dataIndexInside: number;\n seriesIndex: number;\n // highlight action can effect multiple connected charts\n escapeConnect?: boolean;\n // whether blur state was triggered\n notBlur?: boolean;\n}\n\nexport interface BatchEventsParameters {\n type: BatchEventName;\n batch: DataZoomPayloadBatchItem[] & HighlightPayloadBatchItem[];\n}\n\ntype OnBatchEventFunction = (params: BatchEventsParameters) => void;\n\nconst batchEvents = ['datazoom', 'downplay', 'highlight'] as const;\n\nexport type BatchEventName = (typeof batchEvents)[number];\n\ntype ChartEventName = 'finished';\n\ntype EventName = MouseEventName | ChartEventName | BatchEventName;\n\nexport type OnEventsType<T> = {\n [mouseEventName in MouseEventName]?: OnEventFunction<T>;\n} & {\n [batchEventName in BatchEventName]?: OnBatchEventFunction;\n} & {\n [eventName in ChartEventName]?: () => void;\n};\n\nexport interface EChartsProps<T> {\n option: EChartsCoreOption;\n theme?: string | EChartsTheme;\n renderer?: 'canvas' | 'svg';\n sx?: SxProps<Theme>;\n onEvents?: OnEventsType<T>;\n _instance?: React.MutableRefObject<ECharts | undefined>;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = React.memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n onEvents,\n _instance,\n onChartInitialized,\n}: EChartsProps<T>) {\n const initialOption = useRef<EChartsCoreOption>(option);\n const prevOption = useRef<EChartsCoreOption>(option);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const chartElement = useRef<ECharts | null>(null);\n\n // Initialize chart, dispose on unmount\n useLayoutEffect(() => {\n if (containerRef.current === null || chartElement.current !== null) return;\n chartElement.current = init(containerRef.current, theme, { renderer: renderer ?? 'canvas' });\n if (chartElement.current === undefined) return;\n chartElement.current.setOption(initialOption.current, true);\n onChartInitialized?.(chartElement.current);\n if (_instance !== undefined) {\n _instance.current = chartElement.current;\n }\n return () => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [_instance, onChartInitialized, theme, renderer]);\n\n // Update chart data when option changes\n useEffect(() => {\n if (prevOption.current === undefined || isEqual(prevOption.current, option)) return;\n if (!chartElement.current) return;\n chartElement.current.setOption(option, true);\n prevOption.current = option;\n }, [option]);\n\n // Resize chart, cleanup listener on unmount\n useLayoutEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n window.addEventListener('resize', updateSize);\n updateSize();\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, []);\n\n // Bind and unbind chart events passed as prop\n useEffect(() => {\n const chart = chartElement.current;\n if (!chart || onEvents === undefined) return;\n bindEvents(chart, onEvents);\n return () => {\n if (chart === undefined) return;\n if (chart.isDisposed() === true) return;\n for (const event in onEvents) {\n chart.off(event);\n }\n };\n }, [onEvents]);\n\n useEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n updateSize();\n }, [sx]);\n\n return (\n <Box\n ref={containerRef}\n sx={combineSx(\n {\n // Ensures chart fills container and updates size correctly when resizing,\n // combineSx allows this default behavior to be overriden from parent component\n width: '100%',\n height: '100%',\n },\n sx\n )}\n ></Box>\n );\n});\n\n// Validate event config and bind custom events\nfunction bindEvents<T>(instance: ECharts, events?: OnEventsType<T>) {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown) {\n if (typeof OnEventFunction === 'function') {\n if (isMouseEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params, instance));\n } else if (isBatchEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params));\n } else {\n instance.on(eventName, () => OnEventFunction(null, instance));\n }\n }\n }\n\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n const customEvent = events[eventName as EventName] ?? null;\n if (customEvent) {\n bindEvent(eventName as EventName, customEvent);\n }\n }\n }\n}\n\nfunction isMouseEvent(eventName: EventName): eventName is MouseEventName {\n return (mouseEvents as readonly string[]).includes(eventName);\n}\n\nfunction isBatchEvent(eventName: EventName): eventName is BatchEventName {\n return (batchEvents as readonly string[]).includes(eventName);\n}\n"],"names":["React","useEffect","useLayoutEffect","useRef","init","Box","isEqual","debounce","combineSx","mouseEvents","batchEvents","EChart","memo","option","theme","renderer","sx","onEvents","_instance","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","updateSize","resize","window","addEventListener","removeEventListener","chart","bindEvents","isDisposed","event","off","ref","width","height","instance","events","bindEvent","eventName","OnEventFunction","isMouseEvent","on","params","isBatchEvent","Object","prototype","hasOwnProperty","call","customEvent","includes"],"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,OAAOA,KAAK,IAAIC,SAAS,EAAEC,eAAe,EAAEC,MAAM,QAAQ,OAAO,CAAC;AAClE,SAAqCC,IAAI,QAAQ,cAAc,CAAC;AAChE,SAASC,GAAG,QAAwB,eAAe,CAAC;AACpD,SAASC,OAAO,EAAEC,QAAQ,QAAQ,WAAW,CAAC;AAE9C,SAASC,SAAS,QAAQ,UAAU,CAAC;AAuBrC,MAAMC,WAAW,GAAG;IAClB,OAAO;IACP,UAAU;IACV,WAAW;IACX,WAAW;IACX,SAAS;IACT,WAAW;IACX,UAAU;IACV,WAAW;IACX,aAAa;CACd,AAAS,AAAC;AAkCX,MAAMC,WAAW,GAAG;IAAC,UAAU;IAAE,UAAU;IAAE,WAAW;CAAC,AAAS,AAAC;AA0BnE,OAAO,MAAMC,MAAM,iBAAGX,KAAK,CAACY,IAAI,CAAC,SAASD,MAAM,CAAI,EAClDE,MAAM,CAAA,EACNC,KAAK,CAAA,EACLC,QAAQ,CAAA,EACRC,EAAE,CAAA,EACFC,QAAQ,CAAA,EACRC,SAAS,CAAA,EACTC,kBAAkB,CAAA,EACF,EAAE;IAClB,MAAMC,aAAa,GAAGjB,MAAM,CAAoBU,MAAM,CAAC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B,IAAI,CAAC,EAAE,mBAAmB,CAAC;IAC3B,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IACxC,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IACxC,oCAAoC,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,iBAAiB,CAAC;CAC1F;AAED,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,aAAoC,EACpC,UAAU,EACV,aAAa,EACb,oCAAoC,GACrC,EAAE,cAAc,eAkJhB"}
|
|
@@ -183,10 +183,6 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , toolt
|
|
|
183
183
|
unit: unit
|
|
184
184
|
}),
|
|
185
185
|
/*#__PURE__*/ _jsx(EChart, {
|
|
186
|
-
sx: {
|
|
187
|
-
width: '100%',
|
|
188
|
-
height: '100%'
|
|
189
|
-
},
|
|
190
186
|
option: option,
|
|
191
187
|
theme: chartsTheme.echartsTheme,
|
|
192
188
|
onEvents: handleEvents,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/LineChart/LineChart.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 React, { MouseEvent, useMemo, useRef, useState } from 'react';\nimport { Box } from '@mui/material';\nimport type {\n EChartsCoreOption,\n GridComponentOption,\n LineSeriesOption,\n LegendComponentOption,\n YAXisComponentOption,\n TooltipComponentOption,\n} from 'echarts';\nimport { ECharts as EChartsInstance, use } from 'echarts/core';\nimport { LineChart as EChartsLineChart } from 'echarts/charts';\nimport {\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, OnEventsType } from '../EChart';\nimport { EChartsDataFormat, OPTIMIZED_MODE_SERIES_LIMIT } from '../model/graph';\nimport { UnitOptions } from '../model/units';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { TimeSeriesTooltip } from '../TimeSeriesTooltip';\nimport { useTimeZone } from '../context/TimeZoneProvider';\nimport { enableDataZoom, getDateRange, getFormattedDate, getYAxes, restoreChart, ZoomEventData } from './utils';\n\nuse([\n EChartsLineChart,\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n CanvasRenderer,\n]);\n\nexport type TooltipConfig = {\n wrapLabels: boolean;\n hidden?: boolean;\n};\n\nexport interface LineChartProps {\n /**\n * Height of the chart\n */\n height: number;\n data: EChartsDataFormat;\n yAxis?: YAXisComponentOption;\n unit?: UnitOptions;\n grid?: GridComponentOption;\n legend?: LegendComponentOption;\n tooltipConfig?: TooltipConfig;\n onDataZoom?: (e: ZoomEventData) => void;\n onDoubleClick?: (e: MouseEvent) => void;\n __experimentalEChartsOptionsOverride?: (options: EChartsCoreOption) => EChartsCoreOption;\n}\n\nexport function LineChart({\n height,\n data,\n yAxis,\n unit,\n grid,\n legend,\n tooltipConfig = { wrapLabels: true },\n onDataZoom,\n onDoubleClick,\n __experimentalEChartsOptionsOverride,\n}: LineChartProps) {\n const chartsTheme = useChartsTheme();\n const chartRef = useRef<EChartsInstance>();\n const [showTooltip, setShowTooltip] = useState<boolean>(true);\n const [pinTooltip, setPinTooltip] = useState<boolean>(false);\n const { timeZone } = useTimeZone();\n\n const handleEvents: OnEventsType<LineSeriesOption['data'] | unknown> = useMemo(() => {\n return {\n datazoom: (params) => {\n if (onDataZoom === undefined) {\n setTimeout(() => {\n // workaround so unpin happens after click event\n setPinTooltip(false);\n }, 10);\n }\n if (onDataZoom === undefined || params.batch[0] === undefined) return;\n const startIndex = params.batch[0].startValue ?? 0;\n const endIndex = params.batch[0].endValue ?? data.xAxis.length - 1;\n const xAxisStartValue = data.xAxis[startIndex];\n const xAxisEndValue = data.xAxis[endIndex];\n\n if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {\n const zoomEvent: ZoomEventData = {\n start: xAxisStartValue,\n end: xAxisEndValue,\n startIndex,\n endIndex,\n };\n onDataZoom(zoomEvent);\n }\n },\n // TODO: use legendselectchanged event to fix tooltip when legend selected\n };\n }, [data, onDataZoom, setPinTooltip]);\n\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n\n const handleOnDoubleClick = (e: MouseEvent) => {\n setPinTooltip(false);\n // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior\n if (onDoubleClick === undefined) {\n if (chartRef.current !== undefined) {\n restoreChart(chartRef.current);\n }\n } else {\n onDoubleClick(e);\n }\n };\n\n const { noDataOption } = chartsTheme;\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.timeSeries === undefined) return {};\n if (data.timeSeries === null || data.timeSeries.length === 0) return noDataOption;\n\n // show symbols and axisPointer dashed line on hover\n const isOptimizedMode = data.timeSeries.length > OPTIMIZED_MODE_SERIES_LIMIT;\n\n const rangeMs = data.rangeMs ?? getDateRange(data.xAxis);\n\n const option: EChartsCoreOption = {\n series: data.timeSeries,\n xAxis: {\n type: 'category',\n data: data.xAxis,\n max: data.xAxisMax,\n axisLabel: {\n formatter: (value: number) => {\n return getFormattedDate(value, rangeMs, timeZone);\n },\n },\n },\n yAxis: getYAxes(yAxis, unit),\n animation: false,\n tooltip: {\n show: !isOptimizedMode,\n trigger: 'axis',\n showContent: false, // echarts tooltip content hidden since we use custom tooltip instead\n axisPointer: {\n type: isOptimizedMode ? 'none' : 'line',\n z: 0, // ensure point symbol shows on top of dashed line\n },\n },\n toolbox: {\n feature: {\n dataZoom: {\n icon: null, // https://stackoverflow.com/a/67684076/17575201\n yAxisIndex: 'none',\n },\n },\n },\n grid,\n legend,\n };\n\n if (__experimentalEChartsOptionsOverride) {\n return __experimentalEChartsOptionsOverride(option);\n }\n return option;\n }, [data, yAxis, unit, grid, legend, noDataOption, timeZone, __experimentalEChartsOptionsOverride]);\n\n return (\n <Box\n sx={{ height }}\n onClick={() => {\n setPinTooltip((current) => !current);\n }}\n onMouseDown={(e) => {\n // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels\n if (e.target instanceof HTMLCanvasElement) {\n setShowTooltip(false);\n }\n }}\n onMouseUp={() => {\n setShowTooltip(true);\n }}\n onMouseLeave={() => {\n setShowTooltip(false);\n setPinTooltip(false);\n }}\n onMouseEnter={() => {\n setShowTooltip(true);\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n }}\n onDoubleClick={handleOnDoubleClick}\n >\n {/* Allows overrides prop to hide custom tooltip and use the ECharts option.tooltip instead */}\n {showTooltip === true &&\n (option.tooltip as TooltipComponentOption)?.showContent === false &&\n tooltipConfig.hidden !== true && (\n <TimeSeriesTooltip\n chartRef={chartRef}\n chartData={data}\n wrapLabels={tooltipConfig.wrapLabels}\n pinTooltip={pinTooltip}\n unit={unit}\n />\n )}\n <EChart\n sx={{\n width: '100%',\n height: '100%',\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n onEvents={handleEvents}\n _instance={chartRef}\n />\n </Box>\n );\n}\n"],"names":["React","useMemo","useRef","useState","Box","use","LineChart","EChartsLineChart","GridComponent","DataZoomComponent","MarkAreaComponent","MarkLineComponent","MarkPointComponent","TitleComponent","ToolboxComponent","TooltipComponent","LegendComponent","CanvasRenderer","EChart","OPTIMIZED_MODE_SERIES_LIMIT","useChartsTheme","TimeSeriesTooltip","useTimeZone","enableDataZoom","getDateRange","getFormattedDate","getYAxes","restoreChart","height","data","yAxis","unit","grid","legend","tooltipConfig","wrapLabels","onDataZoom","onDoubleClick","__experimentalEChartsOptionsOverride","option","chartsTheme","chartRef","showTooltip","setShowTooltip","pinTooltip","setPinTooltip","timeZone","handleEvents","datazoom","params","undefined","setTimeout","batch","startIndex","startValue","endIndex","endValue","xAxis","length","xAxisStartValue","xAxisEndValue","zoomEvent","start","end","current","handleOnDoubleClick","e","noDataOption","timeSeries","isOptimizedMode","rangeMs","series","type","max","xAxisMax","axisLabel","formatter","value","animation","tooltip","show","trigger","showContent","axisPointer","z","toolbox","feature","dataZoom","icon","yAxisIndex","sx","onClick","onMouseDown","target","HTMLCanvasElement","onMouseUp","onMouseLeave","onMouseEnter","hidden","chartData","width","theme","echartsTheme","onEvents","_instance"],"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,OAAOA,KAAK,IAAgBC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACrE,SAASC,GAAG,QAAQ,eAAe,CAAC;AASpC,SAAqCC,GAAG,QAAQ,cAAc,CAAC;AAC/D,SAASC,SAAS,IAAIC,gBAAgB,QAAQ,gBAAgB,CAAC;AAC/D,SACEC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,EACdC,gBAAgB,EAChBC,gBAAgB,EAChBC,eAAe,QACV,oBAAoB,CAAC;AAC5B,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,MAAM,QAAsB,WAAW,CAAC;A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AAC;QACDoD,YAAY,EAAE,IAAM;YAClBtD,cAAc,CAAC,IAAI,CAAC,CAAC;YACrB,IAAIF,QAAQ,CAACuB,OAAO,KAAKd,SAAS,EAAE;gBAClC3B,cAAc,CAACkB,QAAQ,CAACuB,OAAO,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QACD3B,aAAa,EAAE4B,mBAAmB;;YAGjCvB,WAAW,KAAK,IAAI,IACnB,CAAA,CAACH,GAAc,GAAdA,MAAM,CAACwC,OAAO,cAAdxC,GAAc,WAAwC,GAAvD,KAAA,CAAuD,GAAtDA,GAAc,CAA6B2C,WAAW,CAAA,KAAK,KAAK,IACjEhD,aAAa,CAACgE,MAAM,KAAK,IAAI,kBAC3B,KAAC7E,iBAAiB;gBAChBoB,QAAQ,EAAEA,QAAQ;gBAClB0D,SAAS,EAAEtE,IAAI;gBACfM,UAAU,EAAED,aAAa,CAACC,UAAU;gBACpCS,UAAU,EAAEA,UAAU;gBACtBb,IAAI,EAAEA,IAAI;cACV,AACH;0BACH,KAACb,MAAM;gBACLwE,EAAE,EAAE;oBACFU,KAAK,EAAE,MAAM;oBACbxE,MAAM,EAAE,MAAM;iBACf;gBACDW,MAAM,EAAEA,MAAM;gBACd8D,KAAK,EAAE7D,WAAW,CAAC8D,YAAY;gBAC/BC,QAAQ,EAAExD,YAAY;gBACtByD,SAAS,EAAE/D,QAAQ;cACnB;;MACE,CACN;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/LineChart/LineChart.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 React, { MouseEvent, useMemo, useRef, useState } from 'react';\nimport { Box } from '@mui/material';\nimport type {\n EChartsCoreOption,\n GridComponentOption,\n LineSeriesOption,\n LegendComponentOption,\n YAXisComponentOption,\n TooltipComponentOption,\n} from 'echarts';\nimport { ECharts as EChartsInstance, use } from 'echarts/core';\nimport { LineChart as EChartsLineChart } from 'echarts/charts';\nimport {\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, OnEventsType } from '../EChart';\nimport { EChartsDataFormat, OPTIMIZED_MODE_SERIES_LIMIT } from '../model/graph';\nimport { UnitOptions } from '../model/units';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { TimeSeriesTooltip } from '../TimeSeriesTooltip';\nimport { useTimeZone } from '../context/TimeZoneProvider';\nimport { enableDataZoom, getDateRange, getFormattedDate, getYAxes, restoreChart, ZoomEventData } from './utils';\n\nuse([\n EChartsLineChart,\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n CanvasRenderer,\n]);\n\nexport type TooltipConfig = {\n wrapLabels: boolean;\n hidden?: boolean;\n};\n\nexport interface LineChartProps {\n /**\n * Height of the chart\n */\n height: number;\n data: EChartsDataFormat;\n yAxis?: YAXisComponentOption;\n unit?: UnitOptions;\n grid?: GridComponentOption;\n legend?: LegendComponentOption;\n tooltipConfig?: TooltipConfig;\n onDataZoom?: (e: ZoomEventData) => void;\n onDoubleClick?: (e: MouseEvent) => void;\n __experimentalEChartsOptionsOverride?: (options: EChartsCoreOption) => EChartsCoreOption;\n}\n\nexport function LineChart({\n height,\n data,\n yAxis,\n unit,\n grid,\n legend,\n tooltipConfig = { wrapLabels: true },\n onDataZoom,\n onDoubleClick,\n __experimentalEChartsOptionsOverride,\n}: LineChartProps) {\n const chartsTheme = useChartsTheme();\n const chartRef = useRef<EChartsInstance>();\n const [showTooltip, setShowTooltip] = useState<boolean>(true);\n const [pinTooltip, setPinTooltip] = useState<boolean>(false);\n const { timeZone } = useTimeZone();\n\n const handleEvents: OnEventsType<LineSeriesOption['data'] | unknown> = useMemo(() => {\n return {\n datazoom: (params) => {\n if (onDataZoom === undefined) {\n setTimeout(() => {\n // workaround so unpin happens after click event\n setPinTooltip(false);\n }, 10);\n }\n if (onDataZoom === undefined || params.batch[0] === undefined) return;\n const startIndex = params.batch[0].startValue ?? 0;\n const endIndex = params.batch[0].endValue ?? data.xAxis.length - 1;\n const xAxisStartValue = data.xAxis[startIndex];\n const xAxisEndValue = data.xAxis[endIndex];\n\n if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {\n const zoomEvent: ZoomEventData = {\n start: xAxisStartValue,\n end: xAxisEndValue,\n startIndex,\n endIndex,\n };\n onDataZoom(zoomEvent);\n }\n },\n // TODO: use legendselectchanged event to fix tooltip when legend selected\n };\n }, [data, onDataZoom, setPinTooltip]);\n\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n\n const handleOnDoubleClick = (e: MouseEvent) => {\n setPinTooltip(false);\n // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior\n if (onDoubleClick === undefined) {\n if (chartRef.current !== undefined) {\n restoreChart(chartRef.current);\n }\n } else {\n onDoubleClick(e);\n }\n };\n\n const { noDataOption } = chartsTheme;\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.timeSeries === undefined) return {};\n if (data.timeSeries === null || data.timeSeries.length === 0) return noDataOption;\n\n // show symbols and axisPointer dashed line on hover\n const isOptimizedMode = data.timeSeries.length > OPTIMIZED_MODE_SERIES_LIMIT;\n\n const rangeMs = data.rangeMs ?? getDateRange(data.xAxis);\n\n const option: EChartsCoreOption = {\n series: data.timeSeries,\n xAxis: {\n type: 'category',\n data: data.xAxis,\n max: data.xAxisMax,\n axisLabel: {\n formatter: (value: number) => {\n return getFormattedDate(value, rangeMs, timeZone);\n },\n },\n },\n yAxis: getYAxes(yAxis, unit),\n animation: false,\n tooltip: {\n show: !isOptimizedMode,\n trigger: 'axis',\n showContent: false, // echarts tooltip content hidden since we use custom tooltip instead\n axisPointer: {\n type: isOptimizedMode ? 'none' : 'line',\n z: 0, // ensure point symbol shows on top of dashed line\n },\n },\n toolbox: {\n feature: {\n dataZoom: {\n icon: null, // https://stackoverflow.com/a/67684076/17575201\n yAxisIndex: 'none',\n },\n },\n },\n grid,\n legend,\n };\n\n if (__experimentalEChartsOptionsOverride) {\n return __experimentalEChartsOptionsOverride(option);\n }\n return option;\n }, [data, yAxis, unit, grid, legend, noDataOption, timeZone, __experimentalEChartsOptionsOverride]);\n\n return (\n <Box\n sx={{ height }}\n onClick={() => {\n setPinTooltip((current) => !current);\n }}\n onMouseDown={(e) => {\n // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels\n if (e.target instanceof HTMLCanvasElement) {\n setShowTooltip(false);\n }\n }}\n onMouseUp={() => {\n setShowTooltip(true);\n }}\n onMouseLeave={() => {\n setShowTooltip(false);\n setPinTooltip(false);\n }}\n onMouseEnter={() => {\n setShowTooltip(true);\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n }}\n onDoubleClick={handleOnDoubleClick}\n >\n {/* Allows overrides prop to hide custom tooltip and use the ECharts option.tooltip instead */}\n {showTooltip === true &&\n (option.tooltip as TooltipComponentOption)?.showContent === false &&\n tooltipConfig.hidden !== true && (\n <TimeSeriesTooltip\n chartRef={chartRef}\n chartData={data}\n wrapLabels={tooltipConfig.wrapLabels}\n pinTooltip={pinTooltip}\n unit={unit}\n />\n )}\n <EChart option={option} theme={chartsTheme.echartsTheme} onEvents={handleEvents} _instance={chartRef} />\n </Box>\n );\n}\n"],"names":["React","useMemo","useRef","useState","Box","use","LineChart","EChartsLineChart","GridComponent","DataZoomComponent","MarkAreaComponent","MarkLineComponent","MarkPointComponent","TitleComponent","ToolboxComponent","TooltipComponent","LegendComponent","CanvasRenderer","EChart","OPTIMIZED_MODE_SERIES_LIMIT","useChartsTheme","TimeSeriesTooltip","useTimeZone","enableDataZoom","getDateRange","getFormattedDate","getYAxes","restoreChart","height","data","yAxis","unit","grid","legend","tooltipConfig","wrapLabels","onDataZoom","onDoubleClick","__experimentalEChartsOptionsOverride","option","chartsTheme","chartRef","showTooltip","setShowTooltip","pinTooltip","setPinTooltip","timeZone","handleEvents","datazoom","params","undefined","setTimeout","batch","startIndex","startValue","endIndex","endValue","xAxis","length","xAxisStartValue","xAxisEndValue","zoomEvent","start","end","current","handleOnDoubleClick","e","noDataOption","timeSeries","isOptimizedMode","rangeMs","series","type","max","xAxisMax","axisLabel","formatter","value","animation","tooltip","show","trigger","showContent","axisPointer","z","toolbox","feature","dataZoom","icon","yAxisIndex","sx","onClick","onMouseDown","target","HTMLCanvasElement","onMouseUp","onMouseLeave","onMouseEnter","hidden","chartData","theme","echartsTheme","onEvents","_instance"],"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,OAAOA,KAAK,IAAgBC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACrE,SAASC,GAAG,QAAQ,eAAe,CAAC;AASpC,SAAqCC,GAAG,QAAQ,cAAc,CAAC;AAC/D,SAASC,SAAS,IAAIC,gBAAgB,QAAQ,gBAAgB,CAAC;AAC/D,SACEC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,EACdC,gBAAgB,EAChBC,gBAAgB,EAChBC,eAAe,QACV,oBAAoB,CAAC;AAC5B,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,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AW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"StatChart.d.ts","sourceRoot":"","sources":["../../src/StatChart/StatChart.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAiC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIjF,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAqF9C"}
|
|
@@ -90,12 +90,18 @@ export function StatChart(props) {
|
|
|
90
90
|
const charactersAdjust = formattedValue.length;
|
|
91
91
|
const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
|
|
92
92
|
const containerPadding = `${chartsTheme.container.padding.default}px`;
|
|
93
|
+
const textAlignment = sparkline ? 'auto' : 'center';
|
|
94
|
+
const textStyles = {
|
|
95
|
+
display: 'flex',
|
|
96
|
+
flexDirection: 'column',
|
|
97
|
+
justifyContent: textAlignment,
|
|
98
|
+
alignItems: textAlignment
|
|
99
|
+
};
|
|
93
100
|
return /*#__PURE__*/ _jsxs(Box, {
|
|
94
101
|
sx: {
|
|
95
102
|
height: '100%',
|
|
96
103
|
width: '100%',
|
|
97
|
-
|
|
98
|
-
flexDirection: 'column'
|
|
104
|
+
...textStyles
|
|
99
105
|
},
|
|
100
106
|
children: [
|
|
101
107
|
/*#__PURE__*/ _jsx(Typography, {
|
|
@@ -107,19 +113,10 @@ export function StatChart(props) {
|
|
|
107
113
|
}),
|
|
108
114
|
children: formattedValue
|
|
109
115
|
}),
|
|
110
|
-
sparkline !== undefined && /*#__PURE__*/ _jsx(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
children: /*#__PURE__*/ _jsx(EChart, {
|
|
115
|
-
sx: {
|
|
116
|
-
width: '100%',
|
|
117
|
-
height: '100%'
|
|
118
|
-
},
|
|
119
|
-
option: option,
|
|
120
|
-
theme: chartsTheme.echartsTheme,
|
|
121
|
-
renderer: "svg"
|
|
122
|
-
})
|
|
116
|
+
sparkline !== undefined && /*#__PURE__*/ _jsx(EChart, {
|
|
117
|
+
option: option,
|
|
118
|
+
theme: chartsTheme.echartsTheme,
|
|
119
|
+
renderer: "svg"
|
|
123
120
|
})
|
|
124
121
|
]
|
|
125
122
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/StatChart/StatChart.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 { useMemo } from 'react';\nimport { Box, Typography } from '@mui/material';\nimport { merge } from 'lodash-es';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { formatValue, UnitOptions } from '../model/units';\nimport { EChart } from '../EChart';\nimport { GraphSeries } from '../model/graph';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst MIN_VALUE_SIZE = 12;\nconst MAX_VALUE_SIZE = 36;\n\nexport interface StatChartData {\n calculatedValue?: number;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n unit: UnitOptions;\n color?: string;\n sparkline?: LineSeriesOption;\n}\n\nexport function StatChart(props: StatChartProps) {\n const { width, height, data, unit, color, sparkline } = props;\n const chartsTheme = useChartsTheme();\n\n const formattedValue = data.calculatedValue === undefined ? '' : formatValue(data.calculatedValue, unit);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.seriesData === undefined) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline !== undefined) {\n const lineSeries = {\n type: 'line',\n data: [...series.values],\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n const mergedSeries = merge(lineSeries, sparkline);\n statSeries.push(mergedSeries);\n }\n\n const option = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline]);\n\n const isLargePanel = width > 250 && height > 180;\n // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute\n const charactersAdjust = formattedValue.length;\n const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;\n\n const containerPadding = `${chartsTheme.container.padding.default}px`;\n\n return (\n <Box sx={{ height: '100%', width: '100%',
|
|
1
|
+
{"version":3,"sources":["../../src/StatChart/StatChart.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 { useMemo } from 'react';\nimport { Box, Typography } from '@mui/material';\nimport { merge } from 'lodash-es';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { formatValue, UnitOptions } from '../model/units';\nimport { EChart } from '../EChart';\nimport { GraphSeries } from '../model/graph';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst MIN_VALUE_SIZE = 12;\nconst MAX_VALUE_SIZE = 36;\n\nexport interface StatChartData {\n calculatedValue?: number;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n unit: UnitOptions;\n color?: string;\n sparkline?: LineSeriesOption;\n}\n\nexport function StatChart(props: StatChartProps) {\n const { width, height, data, unit, color, sparkline } = props;\n const chartsTheme = useChartsTheme();\n\n const formattedValue = data.calculatedValue === undefined ? '' : formatValue(data.calculatedValue, unit);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.seriesData === undefined) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline !== undefined) {\n const lineSeries = {\n type: 'line',\n data: [...series.values],\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n const mergedSeries = merge(lineSeries, sparkline);\n statSeries.push(mergedSeries);\n }\n\n const option = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline]);\n\n const isLargePanel = width > 250 && height > 180;\n // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute\n const charactersAdjust = formattedValue.length;\n const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;\n\n const containerPadding = `${chartsTheme.container.padding.default}px`;\n\n const textAlignment = sparkline ? 'auto' : 'center';\n const textStyles = {\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n };\n\n return (\n <Box sx={{ height: '100%', width: '100%', ...textStyles }}>\n <Typography\n variant=\"h3\"\n sx={(theme) => ({\n color: color ?? theme.palette.text.primary,\n fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,\n padding: `${containerPadding} ${containerPadding} 0 ${containerPadding}`,\n })}\n >\n {formattedValue}\n </Typography>\n {sparkline !== undefined && <EChart option={option} theme={chartsTheme.echartsTheme} renderer=\"svg\" />}\n </Box>\n );\n}\n"],"names":["useMemo","Box","Typography","merge","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","formatValue","EChart","MIN_VALUE_SIZE","MAX_VALUE_SIZE","StatChart","props","width","height","data","unit","color","sparkline","chartsTheme","formattedValue","calculatedValue","undefined","option","seriesData","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","tooltip","isLargePanel","charactersAdjust","length","valueSize","Math","min","containerPadding","container","padding","default","textAlignment","textStyles","display","flexDirection","justifyContent","alignItems","sx","variant","theme","palette","text","primary","fontSize","echartsTheme","renderer"],"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,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAChD,SAASC,KAAK,QAAQ,WAAW,CAAC;AAClC,SAASC,GAAG,QAA2B,cAAc,CAAC;AACtD,SAASC,SAAS,IAAIC,gBAAgB,QAA0B,gBAAgB,CAAC;AACjF,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,oBAAoB,CAAC;AACvG,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,cAAc,QAAQ,gCAAgC,CAAC;AAChE,SAASC,WAAW,QAAqB,gBAAgB,CAAC;AAC1D,SAASC,MAAM,QAAQ,WAAW,CAAC;AAGnCV,GAAG,CAAC;IAACE,gBAAgB;IAAEC,aAAa;IAAEC,gBAAgB;IAAEC,cAAc;IAAEC,gBAAgB;IAAEC,cAAc;CAAC,CAAC,CAAC;AAE3G,MAAMI,cAAc,GAAG,EAAE,AAAC;AAC1B,MAAMC,cAAc,GAAG,EAAE,AAAC;AAgB1B,OAAO,SAASC,SAAS,CAACC,KAAqB,EAAE;IAC/C,MAAM,EAAEC,KAAK,CAAA,EAAEC,MAAM,CAAA,EAAEC,IAAI,CAAA,EAAEC,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cAAc,CAAC,IAAI,EAAE2C,SAAS,CAAC,IAAI,EAAE1C,cAAc,CAAC,GAAG,CAAC;wBAC3E+C,OAAO,EAAE,CAAC,EAAEF,gBAAgB,CAAC,CAAC,EAAEA,gBAAgB,CAAC,GAAG,EAAEA,gBAAgB,CAAC,CAAC;qBACzE,CAAA,AAAC;0BAEDnC,cAAc;cACJ;YACZF,SAAS,KAAKI,SAAS,kBAAI,KAACd,MAAM;gBAACe,MAAM,EAAEA,MAAM;gBAAE4C,KAAK,EAAEhD,WAAW,CAACqD,YAAY;gBAAEC,QAAQ,EAAC,KAAK;cAAG;;MAClG,CACN;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
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
5
|
export declare const TOOLTIP_MAX_ITEMS = 50;
|
|
6
6
|
export declare const TOOLTIP_DATE_FORMAT: Intl.DateTimeFormat;
|
|
@@ -12,7 +12,7 @@
|
|
|
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
17
|
export const TOOLTIP_MAX_ITEMS = 50;
|
|
18
18
|
export const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
|
|
@@ -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 = 50;\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,6CA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EW,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"}
|
package/dist/YAxisLabel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
|
@@ -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
|
|
@@ -230,10 +230,6 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
|
|
|
230
230
|
unit: unit
|
|
231
231
|
}),
|
|
232
232
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
|
|
233
|
-
sx: {
|
|
234
|
-
width: '100%',
|
|
235
|
-
height: '100%'
|
|
236
|
-
},
|
|
237
233
|
option: option,
|
|
238
234
|
theme: chartsTheme.echartsTheme,
|
|
239
235
|
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
|
});
|
|
@@ -32,7 +32,7 @@ _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
37
|
const TOOLTIP_MAX_ITEMS = 50;
|
|
38
38
|
const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
|
package/dist/cjs/YAxisLabel.js
CHANGED
|
@@ -25,7 +25,6 @@ _export(exports, {
|
|
|
25
25
|
PERCENT_UNIT_CONFIG: ()=>PERCENT_UNIT_CONFIG,
|
|
26
26
|
formatPercent: ()=>formatPercent
|
|
27
27
|
});
|
|
28
|
-
const _constants = require("./constants");
|
|
29
28
|
const percentUnitKinds = [
|
|
30
29
|
'Percent',
|
|
31
30
|
'PercentDecimal',
|
|
@@ -54,11 +53,28 @@ const PERCENT_UNIT_CONFIG = {
|
|
|
54
53
|
label: '%'
|
|
55
54
|
}
|
|
56
55
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
value = value
|
|
56
|
+
const MAX_SIGNIFICANT_DIGITS = 3;
|
|
57
|
+
function formatPercent(value, { kind , decimal_places }) {
|
|
58
|
+
// Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
|
|
59
|
+
if (kind === 'Percent') {
|
|
60
|
+
value = value / 100;
|
|
62
61
|
}
|
|
63
|
-
|
|
62
|
+
const hasDecimalPlaces = decimal_places !== undefined;
|
|
63
|
+
let formatter;
|
|
64
|
+
if (hasDecimalPlaces) {
|
|
65
|
+
// If there is a specified # of decimal places, use maximumFractionDigits
|
|
66
|
+
formatter = new Intl.NumberFormat('en-US', {
|
|
67
|
+
style: 'percent',
|
|
68
|
+
maximumFractionDigits: decimal_places,
|
|
69
|
+
useGrouping: true
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
// By default, use maximumSignificantDigits
|
|
73
|
+
formatter = new Intl.NumberFormat('en-US', {
|
|
74
|
+
style: 'percent',
|
|
75
|
+
maximumSignificantDigits: MAX_SIGNIFICANT_DIGITS,
|
|
76
|
+
useGrouping: true
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return formatter.format(value);
|
|
64
80
|
}
|
|
@@ -87,14 +87,14 @@ var TimeIntlDuration;
|
|
|
87
87
|
TimeIntlDuration["Months"] = 'month';
|
|
88
88
|
TimeIntlDuration["Years"] = 'year';
|
|
89
89
|
})(TimeIntlDuration || (TimeIntlDuration = {}));
|
|
90
|
-
function formatTime(value,
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
const
|
|
90
|
+
function formatTime(value, { kind , decimal_places }) {
|
|
91
|
+
const decimalPlaces = decimal_places !== null && decimal_places !== void 0 ? decimal_places : _constants.DEFAULT_DECIMAL_PLACES;
|
|
92
|
+
const timeUnit = TimeIntlDuration[kind];
|
|
93
|
+
const isMonthOrYear = kind === 'Months' || kind === 'Years';
|
|
94
94
|
const formatter = new Intl.NumberFormat('en-US', {
|
|
95
95
|
style: 'unit',
|
|
96
96
|
unit: timeUnit,
|
|
97
|
-
unitDisplay: 'long',
|
|
97
|
+
unitDisplay: isMonthOrYear ? 'long' : 'narrow',
|
|
98
98
|
maximumFractionDigits: decimalPlaces
|
|
99
99
|
});
|
|
100
100
|
return formatter.format(value);
|
|
@@ -40,12 +40,15 @@ function generateChartsTheme(muiTheme, echartsTheme) {
|
|
|
40
40
|
left: 20,
|
|
41
41
|
containLabel: true
|
|
42
42
|
},
|
|
43
|
+
// Accessible categorical palette from: https://davidmathlogic.com/colorblind
|
|
43
44
|
color: [
|
|
44
|
-
'#
|
|
45
|
-
'#
|
|
46
|
-
'#
|
|
47
|
-
'#
|
|
48
|
-
'#
|
|
45
|
+
'#56B4E9',
|
|
46
|
+
'#009E73',
|
|
47
|
+
'#0072B2',
|
|
48
|
+
'#CC79A7',
|
|
49
|
+
'#F0E442',
|
|
50
|
+
'#E69F00',
|
|
51
|
+
'#D55E00'
|
|
49
52
|
],
|
|
50
53
|
categoryAxis: {
|
|
51
54
|
show: true,
|
|
@@ -7,6 +7,6 @@ export declare type PercentUnitOptions = {
|
|
|
7
7
|
};
|
|
8
8
|
export declare const DECIMAL_GROUP_CONFIG: UnitGroupConfig;
|
|
9
9
|
export declare const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>>;
|
|
10
|
-
export declare function formatPercent(value: number,
|
|
10
|
+
export declare function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string;
|
|
11
11
|
export {};
|
|
12
12
|
//# sourceMappingURL=percent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,gBAAgB,6CAA8C,CAAC;AACrE,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAgB7E,CAAC;AAIF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,kBAAkB,GAAG,MAAM,CA0BjG"}
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { DEFAULT_DECIMAL_PLACES } from './constants';
|
|
14
13
|
const percentUnitKinds = [
|
|
15
14
|
'Percent',
|
|
16
15
|
'PercentDecimal',
|
|
@@ -39,13 +38,30 @@ export const PERCENT_UNIT_CONFIG = {
|
|
|
39
38
|
label: '%'
|
|
40
39
|
}
|
|
41
40
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
value = value
|
|
41
|
+
const MAX_SIGNIFICANT_DIGITS = 3;
|
|
42
|
+
export function formatPercent(value, { kind , decimal_places }) {
|
|
43
|
+
// Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
|
|
44
|
+
if (kind === 'Percent') {
|
|
45
|
+
value = value / 100;
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
const hasDecimalPlaces = decimal_places !== undefined;
|
|
48
|
+
let formatter;
|
|
49
|
+
if (hasDecimalPlaces) {
|
|
50
|
+
// If there is a specified # of decimal places, use maximumFractionDigits
|
|
51
|
+
formatter = new Intl.NumberFormat('en-US', {
|
|
52
|
+
style: 'percent',
|
|
53
|
+
maximumFractionDigits: decimal_places,
|
|
54
|
+
useGrouping: true
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
// By default, use maximumSignificantDigits
|
|
58
|
+
formatter = new Intl.NumberFormat('en-US', {
|
|
59
|
+
style: 'percent',
|
|
60
|
+
maximumSignificantDigits: MAX_SIGNIFICANT_DIGITS,
|
|
61
|
+
useGrouping: true
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return formatter.format(value);
|
|
49
65
|
}
|
|
50
66
|
|
|
51
67
|
//# sourceMappingURL=percent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/percent.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 { UnitGroupConfig, UnitConfig } from './types';\
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/percent.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 { UnitGroupConfig, UnitConfig } from './types';\n\nconst percentUnitKinds = ['Percent', 'PercentDecimal', '%'] as const;\ntype PercentUnitKind = (typeof percentUnitKinds)[number];\nexport type PercentUnitOptions = {\n kind: PercentUnitKind;\n decimal_places?: number;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimal_places: true,\n abbreviate: true,\n};\nconst PERCENT_GROUP = 'Percent';\nexport const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>> = {\n Percent: {\n group: PERCENT_GROUP,\n label: 'Percent (0-100)',\n },\n PercentDecimal: {\n group: PERCENT_GROUP,\n label: 'Percent (0.0-1.0)',\n },\n '%': {\n // This option is not shown in the selector because it is a shorthand\n // duplicate of `Percent`.\n disableSelectorOption: true,\n group: PERCENT_GROUP,\n label: '%',\n },\n};\n\nconst MAX_SIGNIFICANT_DIGITS = 3;\n\nexport function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string {\n // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%\n if (kind === 'Percent') {\n value = value / 100;\n }\n\n const hasDecimalPlaces = decimal_places !== undefined;\n\n let formatter;\n if (hasDecimalPlaces) {\n // If there is a specified # of decimal places, use maximumFractionDigits\n formatter = new Intl.NumberFormat('en-US', {\n style: 'percent',\n maximumFractionDigits: decimal_places,\n useGrouping: true,\n });\n } else {\n // By default, use maximumSignificantDigits\n formatter = new Intl.NumberFormat('en-US', {\n style: 'percent',\n maximumSignificantDigits: MAX_SIGNIFICANT_DIGITS,\n useGrouping: true,\n });\n }\n\n return formatter.format(value);\n}\n"],"names":["percentUnitKinds","DECIMAL_GROUP_CONFIG","label","decimal_places","abbreviate","PERCENT_GROUP","PERCENT_UNIT_CONFIG","Percent","group","PercentDecimal","disableSelectorOption","MAX_SIGNIFICANT_DIGITS","formatPercent","value","kind","hasDecimalPlaces","undefined","formatter","Intl","NumberFormat","style","maximumFractionDigits","useGrouping","maximumSignificantDigits","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE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C3CL,SAAS,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAE;YACzCC,KAAK,EAAE,SAAS;YAChBG,wBAAwB,EAAEZ,sBAAsB;YAChDW,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;IACL,CAAC;IAED,OAAOL,SAAS,CAACO,MAAM,CAACX,KAAK,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -17,6 +17,6 @@ export declare enum TimeIntlDuration {
|
|
|
17
17
|
Months = "month",
|
|
18
18
|
Years = "year"
|
|
19
19
|
}
|
|
20
|
-
export declare function formatTime(value: number,
|
|
20
|
+
export declare function formatTime(value: number, { kind, decimal_places }: TimeUnitOptions): string;
|
|
21
21
|
export {};
|
|
22
22
|
//# sourceMappingURL=time.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AACnH,aAAK,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAG/B,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAiCvE,CAAC;AAIF,oBAAY,gBAAgB;IAC1B,YAAY,gBAAgB;IAC5B,OAAO,WAAW;IAClB,OAAO,WAAW;IAClB,KAAK,SAAS;IACd,IAAI,QAAQ;IACZ,KAAK,SAAS;IACd,MAAM,UAAU;IAChB,KAAK,SAAS;CACf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AACnH,aAAK,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAG/B,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAiCvE,CAAC;AAIF,oBAAY,gBAAgB;IAC1B,YAAY,gBAAgB;IAC5B,OAAO,WAAW;IAClB,OAAO,WAAW;IAClB,KAAK,SAAS;IACd,IAAI,QAAQ;IACZ,KAAK,SAAS;IACd,MAAM,UAAU;IAChB,KAAK,SAAS;CACf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,eAAe,GAAG,MAAM,CAa3F"}
|
package/dist/model/units/time.js
CHANGED
|
@@ -71,14 +71,14 @@ export var TimeIntlDuration;
|
|
|
71
71
|
TimeIntlDuration["Months"] = 'month';
|
|
72
72
|
TimeIntlDuration["Years"] = 'year';
|
|
73
73
|
})(TimeIntlDuration || (TimeIntlDuration = {}));
|
|
74
|
-
export function formatTime(value,
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
const
|
|
74
|
+
export function formatTime(value, { kind , decimal_places }) {
|
|
75
|
+
const decimalPlaces = decimal_places !== null && decimal_places !== void 0 ? decimal_places : DEFAULT_DECIMAL_PLACES;
|
|
76
|
+
const timeUnit = TimeIntlDuration[kind];
|
|
77
|
+
const isMonthOrYear = kind === 'Months' || kind === 'Years';
|
|
78
78
|
const formatter = new Intl.NumberFormat('en-US', {
|
|
79
79
|
style: 'unit',
|
|
80
80
|
unit: timeUnit,
|
|
81
|
-
unitDisplay: 'long',
|
|
81
|
+
unitDisplay: isMonthOrYear ? 'long' : 'narrow',
|
|
82
82
|
maximumFractionDigits: decimalPlaces
|
|
83
83
|
});
|
|
84
84
|
return formatter.format(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/time.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 { DEFAULT_DECIMAL_PLACES } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\n\nconst timeUnitKinds = ['Milliseconds', 'Seconds', 'Minutes', 'Hours', 'Days', 'Weeks', 'Months', 'Years'] as const;\ntype TimeUnitKind = (typeof timeUnitKinds)[number];\nexport type TimeUnitOptions = {\n kind: TimeUnitKind;\n decimal_places?: number;\n};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\n decimal_places: true,\n};\nexport const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>> = {\n Milliseconds: {\n group: TIME_GROUP,\n label: 'Milliseconds',\n },\n Seconds: {\n group: TIME_GROUP,\n label: 'Seconds',\n },\n Minutes: {\n group: TIME_GROUP,\n label: 'Minutes',\n },\n Hours: {\n group: TIME_GROUP,\n label: 'Hours',\n },\n Days: {\n group: TIME_GROUP,\n label: 'Days',\n },\n Weeks: {\n group: TIME_GROUP,\n label: 'Weeks',\n },\n Months: {\n group: TIME_GROUP,\n label: 'Months',\n },\n Years: {\n group: TIME_GROUP,\n label: 'Years',\n },\n};\n\n// Mapping of time units to what Intl.NumberFormat formatter expects\n// https://v8.dev/features/intl-numberformat#units\nexport enum TimeIntlDuration {\n Milliseconds = 'millisecond',\n Seconds = 'second',\n Minutes = 'minute',\n Hours = 'hour',\n Days = 'day',\n Weeks = 'week',\n Months = 'month',\n Years = 'year',\n}\n\nexport function formatTime(value: number,
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/time.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 { DEFAULT_DECIMAL_PLACES } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\n\nconst timeUnitKinds = ['Milliseconds', 'Seconds', 'Minutes', 'Hours', 'Days', 'Weeks', 'Months', 'Years'] as const;\ntype TimeUnitKind = (typeof timeUnitKinds)[number];\nexport type TimeUnitOptions = {\n kind: TimeUnitKind;\n decimal_places?: number;\n};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\n decimal_places: true,\n};\nexport const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>> = {\n Milliseconds: {\n group: TIME_GROUP,\n label: 'Milliseconds',\n },\n Seconds: {\n group: TIME_GROUP,\n label: 'Seconds',\n },\n Minutes: {\n group: TIME_GROUP,\n label: 'Minutes',\n },\n Hours: {\n group: TIME_GROUP,\n label: 'Hours',\n },\n Days: {\n group: TIME_GROUP,\n label: 'Days',\n },\n Weeks: {\n group: TIME_GROUP,\n label: 'Weeks',\n },\n Months: {\n group: TIME_GROUP,\n label: 'Months',\n },\n Years: {\n group: TIME_GROUP,\n label: 'Years',\n },\n};\n\n// Mapping of time units to what Intl.NumberFormat formatter expects\n// https://v8.dev/features/intl-numberformat#units\nexport enum TimeIntlDuration {\n Milliseconds = 'millisecond',\n Seconds = 'second',\n Minutes = 'minute',\n Hours = 'hour',\n Days = 'day',\n Weeks = 'week',\n Months = 'month',\n Years = 'year',\n}\n\nexport function formatTime(value: number, { kind, decimal_places }: TimeUnitOptions): string {\n const decimalPlaces = decimal_places ?? DEFAULT_DECIMAL_PLACES;\n\n const timeUnit: string = TimeIntlDuration[kind];\n const isMonthOrYear = kind === 'Months' || kind === 'Years';\n\n const formatter = new Intl.NumberFormat('en-US', {\n style: 'unit',\n unit: timeUnit,\n unitDisplay: isMonthOrYear ? 'long' : 'narrow',\n maximumFractionDigits: decimalPlaces,\n });\n return formatter.format(value);\n}\n"],"names":["DEFAULT_DECIMAL_PLACES","timeUnitKinds","TIME_GROUP","TIME_GROUP_CONFIG","label","decimal_places","TIME_UNIT_CONFIG","Milliseconds","group","Seconds","Minutes","Hours","Days","Weeks","Months","Years","TimeIntlDuration","formatTime","value","kind","decimalPlaces","timeUnit","isMonthOrYear","formatter","Intl","NumberFormat","style","unit","unitDisplay","maximumFractionDigits","format"],"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,sBAAsB,QAAQ,aAAa,CAAC;AAGrD,MAAMC,aAAa,GAAG;IAAC,cAAc;IAAE,SAAS;IAAE,SAAS;IAAE,OAAO;IAAE,MAAM;IAAE,OAAO;IAAE,QAAQ;IAAE,OAAO;CAAC,AAAS,AAAC;AAMnH,MAAMC,UAAU,GAAG,MAAM,AAAC;AAC1B,OAAO,MAAMC,iBAAiB,GAAoB;IACh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A,cAAc,cAAdA,cAAc,GAAIL,sBAAsB,AAAC;IAE/D,MAAMqB,QAAQ,GAAWL,gBAAgB,CAACG,IAAI,CAAC,AAAC;IAChD,MAAMG,aAAa,GAAGH,IAAI,KAAK,QAAQ,IAAIA,IAAI,KAAK,OAAO,AAAC;IAE5D,MAAMI,SAAS,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAE;QAC/CC,KAAK,EAAE,MAAM;QACbC,IAAI,EAAEN,QAAQ;QACdO,WAAW,EAAEN,aAAa,GAAG,MAAM,GAAG,QAAQ;QAC9CO,qBAAqB,EAAET,aAAa;KACrC,CAAC,AAAC;IACH,OAAOG,SAAS,CAACO,MAAM,CAACZ,KAAK,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UnitOptions } from './units';
|
|
1
2
|
export declare const UNIT_GROUPS: readonly ["Time", "Percent", "Decimal", "Bytes"];
|
|
2
3
|
export declare type UnitGroup = (typeof UNIT_GROUPS)[number];
|
|
3
4
|
/**
|
|
@@ -35,4 +36,12 @@ export declare type UnitConfig = {
|
|
|
35
36
|
*/
|
|
36
37
|
label: string;
|
|
37
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Used in the tests for each type of unit.
|
|
41
|
+
*/
|
|
42
|
+
export interface UnitTestCase {
|
|
43
|
+
value: number;
|
|
44
|
+
unit: UnitOptions;
|
|
45
|
+
expected: string;
|
|
46
|
+
}
|
|
38
47
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/model/units/types.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,WAAW,kDAAmD,CAAC;AAC5E,oBAAY,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;GAEG;AACH,oBAAY,eAAe,GAAG;IAC5B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,oBAAY,UAAU,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;IAEjB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/model/units/types.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAO,MAAM,WAAW,kDAAmD,CAAC;AAC5E,oBAAY,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;GAEG;AACH,oBAAY,eAAe,GAAG;IAC5B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,oBAAY,UAAU,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;IAEjB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/types.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\n// Common types needed across individual unit groups and the overall combined\n// units.\n\nexport const UNIT_GROUPS = ['Time', 'Percent', 'Decimal', 'Bytes'] as const;\nexport type UnitGroup = (typeof UNIT_GROUPS)[number];\n\n/**\n * Configuration for rendering units that are part of a group.\n */\nexport type UnitGroupConfig = {\n /**\n * The label that is shown in the UI.\n */\n label: string;\n /**\n * When true, the unit group supports setting decimal places.\n */\n decimal_places?: boolean;\n /**\n * When true, the unit group supports enabling abbreviate.\n */\n abbreviate?: boolean;\n};\n\n/**\n * Configuration for rendering a specific unit.\n */\nexport type UnitConfig = {\n /**\n * The group the unit is part of. This will inform common rendering behavior.\n */\n group: UnitGroup;\n\n /**\n * When true, this unit will not be displayed in the unit selector. This is\n * useful for units that are shorthand variants of other units.\n */\n disableSelectorOption?: boolean;\n\n /**\n * The label that is shown in the UI.\n */\n label: string;\n};\n"],"names":["UNIT_GROUPS"],"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,6EAA6E;AAC7E,SAAS;
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/types.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\n// Common types needed across individual unit groups and the overall combined\n// units.\n\nimport { UnitOptions } from './units';\n\nexport const UNIT_GROUPS = ['Time', 'Percent', 'Decimal', 'Bytes'] as const;\nexport type UnitGroup = (typeof UNIT_GROUPS)[number];\n\n/**\n * Configuration for rendering units that are part of a group.\n */\nexport type UnitGroupConfig = {\n /**\n * The label that is shown in the UI.\n */\n label: string;\n /**\n * When true, the unit group supports setting decimal places.\n */\n decimal_places?: boolean;\n /**\n * When true, the unit group supports enabling abbreviate.\n */\n abbreviate?: boolean;\n};\n\n/**\n * Configuration for rendering a specific unit.\n */\nexport type UnitConfig = {\n /**\n * The group the unit is part of. This will inform common rendering behavior.\n */\n group: UnitGroup;\n\n /**\n * When true, this unit will not be displayed in the unit selector. This is\n * useful for units that are shorthand variants of other units.\n */\n disableSelectorOption?: boolean;\n\n /**\n * The label that is shown in the UI.\n */\n label: string;\n};\n\n/**\n * Used in the tests for each type of unit.\n */\nexport interface UnitTestCase {\n value: number;\n unit: UnitOptions;\n expected: string;\n}\n"],"names":["UNIT_GROUPS"],"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,6EAA6E;AAC7E,SAAS;AAIT,OAAO,MAAMA,WAAW,GAAG;IAAC,MAAM;IAAE,SAAS;IAAE,SAAS;IAAE,OAAO;CAAC,AAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-gen.d.ts","sourceRoot":"","sources":["../../src/utils/theme-gen.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAK3D,aAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AAE1C,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,GAAG,iBAAiB,
|
|
1
|
+
{"version":3,"file":"theme-gen.d.ts","sourceRoot":"","sources":["../../src/utils/theme-gen.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAK3D,aAAK,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AAE1C,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,GAAG,iBAAiB,CA+KrG"}
|
package/dist/utils/theme-gen.js
CHANGED
|
@@ -32,12 +32,15 @@ export function generateChartsTheme(muiTheme, echartsTheme) {
|
|
|
32
32
|
left: 20,
|
|
33
33
|
containLabel: true
|
|
34
34
|
},
|
|
35
|
+
// Accessible categorical palette from: https://davidmathlogic.com/colorblind
|
|
35
36
|
color: [
|
|
36
|
-
'#
|
|
37
|
-
'#
|
|
38
|
-
'#
|
|
39
|
-
'#
|
|
40
|
-
'#
|
|
37
|
+
'#56B4E9',
|
|
38
|
+
'#009E73',
|
|
39
|
+
'#0072B2',
|
|
40
|
+
'#CC79A7',
|
|
41
|
+
'#F0E442',
|
|
42
|
+
'#E69F00',
|
|
43
|
+
'#D55E00'
|
|
41
44
|
],
|
|
42
45
|
categoryAxis: {
|
|
43
46
|
show: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/theme-gen.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 { Theme } from '@mui/material';\nimport { merge } from 'lodash-es';\nimport { EChartsTheme, PersesChartsTheme } from '../model';\n\nconst DEFAULT_TEXT_COLOR = '#222';\n\n// avoid component override type errors since only palette and typography are used\ntype MuiTheme = Omit<Theme, 'components'>;\n\nexport function generateChartsTheme(muiTheme: MuiTheme, echartsTheme: EChartsTheme): PersesChartsTheme {\n const primaryTextColor = muiTheme.palette.text?.primary ?? DEFAULT_TEXT_COLOR;\n\n const muiConvertedTheme: EChartsTheme = {\n title: {\n show: false,\n },\n textStyle: {\n color: primaryTextColor,\n fontFamily: muiTheme.typography.fontFamily,\n fontSize: 12,\n },\n grid: {\n top: 5,\n right: 20,\n bottom: 0,\n left: 20,\n containLabel: true,\n },\n color: ['#8dd3c7', '#fb8072', '#80b1d3', '#bebada', '#fdb462'],\n categoryAxis: {\n show: true,\n axisLabel: {\n show: true,\n color: primaryTextColor,\n margin: 15,\n },\n axisTick: {\n show: false,\n length: 6,\n lineStyle: {\n color: muiTheme.palette.grey[600],\n },\n },\n axisLine: {\n show: true,\n lineStyle: {\n color: muiTheme.palette.grey[600],\n },\n },\n splitLine: {\n show: true,\n lineStyle: {\n width: 0.5,\n color: muiTheme.palette.grey[300],\n opacity: 0.6,\n },\n },\n splitArea: {\n show: false,\n areaStyle: {\n color: [muiTheme.palette.grey[300]],\n },\n },\n },\n valueAxis: {\n show: true,\n axisLabel: {\n color: primaryTextColor,\n margin: 12,\n },\n axisLine: {\n show: false,\n },\n splitLine: {\n show: true,\n lineStyle: {\n width: 0.5,\n color: muiTheme.palette.grey[300],\n opacity: 0.6,\n },\n },\n },\n legend: {\n orient: 'horizontal',\n textStyle: {\n color: primaryTextColor,\n },\n pageTextStyle: {\n color: muiTheme.palette.grey[600],\n },\n pageIconColor: muiTheme?.palette?.action?.active,\n pageIconInactiveColor: muiTheme?.palette?.action?.disabled,\n },\n toolbox: {\n show: true,\n top: 10,\n right: 10,\n iconStyle: {\n borderColor: primaryTextColor,\n },\n },\n tooltip: {},\n line: {\n showSymbol: false,\n symbol: 'circle',\n symbolSize: 4,\n smooth: false,\n lineStyle: {\n width: 1,\n },\n emphasis: {\n lineStyle: {\n width: 1.5,\n },\n },\n },\n bar: {\n barMaxWidth: 150,\n itemStyle: {\n borderWidth: 0,\n borderColor: muiTheme.palette.grey[300],\n },\n },\n gauge: {\n detail: {\n fontSize: 18,\n fontWeight: 600,\n valueAnimation: false,\n },\n splitLine: {\n distance: 0,\n length: 4,\n lineStyle: {\n width: 1,\n },\n },\n splitNumber: 12,\n },\n };\n\n return {\n echartsTheme: merge(muiConvertedTheme, echartsTheme),\n noDataOption: {\n title: {\n show: true,\n textStyle: {\n color: primaryTextColor,\n fontSize: 16,\n fontWeight: 400,\n },\n text: 'No data',\n left: 'center',\n top: 'center',\n },\n xAxis: {\n show: false,\n },\n yAxis: {\n show: false,\n },\n },\n sparkline: {\n width: 2,\n color: '#1976d2',\n },\n container: {\n padding: {\n default: parseInt(muiTheme.spacing(1.5), 10),\n },\n },\n thresholds: {\n defaultColor: muiTheme.palette.success.main,\n palette: ['#FFCC00', muiTheme.palette.warning.main, muiTheme.palette.error.main],\n },\n };\n}\n"],"names":["merge","DEFAULT_TEXT_COLOR","generateChartsTheme","muiTheme","echartsTheme","primaryTextColor","palette","text","primary","muiConvertedTheme","title","show","textStyle","color","fontFamily","typography","fontSize","grid","top","right","bottom","left","containLabel","categoryAxis","axisLabel","margin","axisTick","length","lineStyle","grey","axisLine","splitLine","width","opacity","splitArea","areaStyle","valueAxis","legend","orient","pageTextStyle","pageIconColor","action","active","pageIconInactiveColor","disabled","toolbox","iconStyle","borderColor","tooltip","line","showSymbol","symbol","symbolSize","smooth","emphasis","bar","barMaxWidth","itemStyle","borderWidth","gauge","detail","fontWeight","valueAnimation","distance","splitNumber","noDataOption","xAxis","yAxis","sparkline","container","padding","default","parseInt","spacing","thresholds","defaultColor","success","main","warning","error"],"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,KAAK,QAAQ,WAAW,CAAC;AAGlC,MAAMC,kBAAkB,GAAG,MAAM,AAAC;AAKlC,OAAO,SAASC,mBAAmB,CAACC,QAAkB,EAAEC,YAA0B,EAAqB;QAC5ED,GAAqB,EAgF3BA,IAAiB,QACTA,IAAiB;QAjFnBA,IAA8B;IAAvD,MAAME,gBAAgB,GAAGF,CAAAA,IAA8B,GAA9BA,CAAAA,GAAqB,GAArBA,QAAQ,CAACG,OAAO,CAACC,IAAI,cAArBJ,GAAqB,WAAS,GAA9BA,KAAAA,CAA8B,GAA9BA,GAAqB,CAAEK,OAAO,cAA9BL,IAA8B,cAA9BA,IAA8B,GAAIF,kBAAkB,AAAC;IAE9E,MAAMQ,iBAAiB,GAAiB;QACtCC,KAAK,EAAE;YACLC,IAAI,EAAE,KAAK;SACZ;QACDC,SAAS,EAAE;YACTC,KAAK,EAAER,gBAAgB;YACvBS,UAAU,EAAEX,QAAQ,CAACY,UAAU,CAACD,UAAU;YAC1CE,QAAQ,EAAE,EAAE;SACb;QACDC,IAAI,EAAE;YACJC,GAAG,EAAE,CAAC;YACNC,KAAK,EAAE,EAAE;YACTC,MAAM,EAAE,CAAC;YACTC,IAAI,EAAE,EAAE;YACRC,YAAY,EAAE,IAAI;SACnB;QACDT,KAAK,EAAE;YAAC,SAAS;YAAE,SAAS;YAAE,SAAS;YAAE,SAAS;YAAE,SAAS;SAAC;QAC9DU,YAAY,EAAE;YACZZ,IAAI,EAAE,IAAI;YACVa,SAAS,EAAE;gBACTb,IAAI,EAAE,IAAI;gBACVE,KAAK,EAAER,gBAAgB;gBACvBoB,MAAM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Z6C,UAAU,EAAE,GAAG;gBACfC,cAAc,EAAE,KAAK;aACtB;YACD/B,SAAS,EAAE;gBACTgC,QAAQ,EAAE,CAAC;gBACXpC,MAAM,EAAE,CAAC;gBACTC,SAAS,EAAE;oBACTI,KAAK,EAAE,CAAC;iBACT;aACF;YACDgC,WAAW,EAAE,EAAE;SAChB;KACF,AAAC;IAEF,OAAO;QACL5D,YAAY,EAAEJ,KAAK,CAACS,iBAAiB,EAAEL,YAAY,CAAC;QACpD6D,YAAY,EAAE;YACZvD,KAAK,EAAE;gBACLC,IAAI,EAAE,IAAI;gBACVC,SAAS,EAAE;oBACTC,KAAK,EAAER,gBAAgB;oBACvBW,QAAQ,EAAE,EAAE;oBACZ6C,UAAU,EAAE,GAAG;iBAChB;gBACDtD,IAAI,EAAE,SAAS;gBACfc,IAAI,EAAE,QAAQ;gBACdH,GAAG,EAAE,QAAQ;aACd;YACDgD,KAAK,EAAE;gBACLvD,IAAI,EAAE,KAAK;aACZ;YACDwD,KAAK,EAAE;gBACLxD,IAAI,EAAE,KAAK;aACZ;SACF;QACDyD,SAAS,EAAE;YACTpC,KAAK,EAAE,CAAC;YACRnB,KAAK,EAAE,SAAS;SACjB;QACDwD,SAAS,EAAE;YACTC,OAAO,EAAE;gBACPC,OAAO,EAAEC,QAAQ,CAACrE,QAAQ,CAACsE,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;aAC7C;SACF;QACDC,UAAU,EAAE;YACVC,YAAY,EAAExE,QAAQ,CAACG,OAAO,CAACsE,OAAO,CAACC,IAAI;YAC3CvE,OAAO,EAAE;gBAAC,SAAS;gBAAEH,QAAQ,CAACG,OAAO,CAACwE,OAAO,CAACD,IAAI;gBAAE1E,QAAQ,CAACG,OAAO,CAACyE,KAAK,CAACF,IAAI;aAAC;SACjF;KACF,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/theme-gen.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 { Theme } from '@mui/material';\nimport { merge } from 'lodash-es';\nimport { EChartsTheme, PersesChartsTheme } from '../model';\n\nconst DEFAULT_TEXT_COLOR = '#222';\n\n// avoid component override type errors since only palette and typography are used\ntype MuiTheme = Omit<Theme, 'components'>;\n\nexport function generateChartsTheme(muiTheme: MuiTheme, echartsTheme: EChartsTheme): PersesChartsTheme {\n const primaryTextColor = muiTheme.palette.text?.primary ?? DEFAULT_TEXT_COLOR;\n\n const muiConvertedTheme: EChartsTheme = {\n title: {\n show: false,\n },\n textStyle: {\n color: primaryTextColor,\n fontFamily: muiTheme.typography.fontFamily,\n fontSize: 12,\n },\n grid: {\n top: 5,\n right: 20,\n bottom: 0,\n left: 20,\n containLabel: true,\n },\n // Accessible categorical palette from: https://davidmathlogic.com/colorblind\n color: [\n '#56B4E9', // lt blue\n '#009E73', // med green\n '#0072B2', // dk blue\n '#CC79A7', // lt purple\n '#F0E442', // yellow\n '#E69F00', // orange\n '#D55E00', // red\n ],\n categoryAxis: {\n show: true,\n axisLabel: {\n show: true,\n color: primaryTextColor,\n margin: 15,\n },\n axisTick: {\n show: false,\n length: 6,\n lineStyle: {\n color: muiTheme.palette.grey[600],\n },\n },\n axisLine: {\n show: true,\n lineStyle: {\n color: muiTheme.palette.grey[600],\n },\n },\n splitLine: {\n show: true,\n lineStyle: {\n width: 0.5,\n color: muiTheme.palette.grey[300],\n opacity: 0.6,\n },\n },\n splitArea: {\n show: false,\n areaStyle: {\n color: [muiTheme.palette.grey[300]],\n },\n },\n },\n valueAxis: {\n show: true,\n axisLabel: {\n color: primaryTextColor,\n margin: 12,\n },\n axisLine: {\n show: false,\n },\n splitLine: {\n show: true,\n lineStyle: {\n width: 0.5,\n color: muiTheme.palette.grey[300],\n opacity: 0.6,\n },\n },\n },\n legend: {\n orient: 'horizontal',\n textStyle: {\n color: primaryTextColor,\n },\n pageTextStyle: {\n color: muiTheme.palette.grey[600],\n },\n pageIconColor: muiTheme?.palette?.action?.active,\n pageIconInactiveColor: muiTheme?.palette?.action?.disabled,\n },\n toolbox: {\n show: true,\n top: 10,\n right: 10,\n iconStyle: {\n borderColor: primaryTextColor,\n },\n },\n tooltip: {},\n line: {\n showSymbol: false,\n symbol: 'circle',\n symbolSize: 4,\n smooth: false,\n lineStyle: {\n width: 1,\n },\n emphasis: {\n lineStyle: {\n width: 1.5,\n },\n },\n },\n bar: {\n barMaxWidth: 150,\n itemStyle: {\n borderWidth: 0,\n borderColor: muiTheme.palette.grey[300],\n },\n },\n gauge: {\n detail: {\n fontSize: 18,\n fontWeight: 600,\n valueAnimation: false,\n },\n splitLine: {\n distance: 0,\n length: 4,\n lineStyle: {\n width: 1,\n },\n },\n splitNumber: 12,\n },\n };\n\n return {\n echartsTheme: merge(muiConvertedTheme, echartsTheme),\n noDataOption: {\n title: {\n show: true,\n textStyle: {\n color: primaryTextColor,\n fontSize: 16,\n fontWeight: 400,\n },\n text: 'No data',\n left: 'center',\n top: 'center',\n },\n xAxis: {\n show: false,\n },\n yAxis: {\n show: false,\n },\n },\n sparkline: {\n width: 2,\n color: '#1976d2',\n },\n container: {\n padding: {\n default: parseInt(muiTheme.spacing(1.5), 10),\n },\n },\n thresholds: {\n defaultColor: muiTheme.palette.success.main,\n palette: ['#FFCC00', muiTheme.palette.warning.main, muiTheme.palette.error.main],\n },\n };\n}\n"],"names":["merge","DEFAULT_TEXT_COLOR","generateChartsTheme","muiTheme","echartsTheme","primaryTextColor","palette","text","primary","muiConvertedTheme","title","show","textStyle","color","fontFamily","typography","fontSize","grid","top","right","bottom","left","containLabel","categoryAxis","axisLabel","margin","axisTick","length","lineStyle","grey","axisLine","splitLine","width","opacity","splitArea","areaStyle","valueAxis","legend","orient","pageTextStyle","pageIconColor","action","active","pageIconInactiveColor","disabled","toolbox","iconStyle","borderColor","tooltip","line","showSymbol","symbol","symbolSize","smooth","emphasis","bar","barMaxWidth","itemStyle","borderWidth","gauge","detail","fontWeight","valueAnimation","distance","splitNumber","noDataOption","xAxis","yAxis","sparkline","container","padding","default","parseInt","spacing","thresholds","defaultColor","success","main","warning","error"],"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,KAAK,QAAQ,WAAW,CAAC;AAGlC,MAAMC,kBAAkB,GAAG,MAAM,AAAC;AAKlC,OAAO,SAASC,mBAAmB,CAACC,QAAkB,EAAEC,YAA0B,EAAqB;QAC5ED,GAAqB,EAyF3BA,IAAiB,QACTA,IAAiB;QA1FnBA,IAA8B;IAAvD,MAAME,gBAAgB,GAAGF,CAAAA,IAA8B,GAA9BA,CAAAA,GAAqB,GAArBA,QAAQ,CAACG,OAAO,CAACC,IAAI,cAArBJ,GAAqB,WAAS,GAA9BA,KAAAA,CAA8B,GAA9BA,GAAqB,CAAEK,OAAO,cAA9BL,IAA8B,cAA9BA,IAA8B,GAAIF,kBAAkB,AAAC;IAE9E,MAAMQ,iBAAiB,GAAiB;QACtCC,KAAK,EAAE;YACLC,IAAI,EAAE,KAAK;SACZ;QACDC,SAAS,EAAE;YACTC,KAAK,EAAER,gBAAgB;YACvBS,UAAU,EAAEX,QAAQ,CAACY,UAAU,CAACD,UAAU;YAC1CE,QAAQ,EAAE,EAAE;SACb;QACDC,IAAI,EAAE;YACJC,GAAG,EAAE,CAAC;YACNC,KAAK,EAAE,EAAE;YACTC,MAAM,EAAE,CAAC;YACTC,IAAI,EAAE,EAAE;YACRC,YA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C3CvE,OAAO,EAAE;gBAAC,SAAS;gBAAEH,QAAQ,CAACG,OAAO,CAACwE,OAAO,CAACD,IAAI;gBAAE1E,QAAQ,CAACG,OAAO,CAACyE,KAAK,CAACF,IAAI;aAAC;SACjF;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "Common UI components used across Perses features",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@codemirror/lang-json": "^6.0.1",
|
|
37
37
|
"@fontsource/lato": "^4.5.10",
|
|
38
38
|
"@mui/x-date-pickers": "^5.0.0-beta.1",
|
|
39
|
-
"@perses-dev/core": "0.
|
|
39
|
+
"@perses-dev/core": "0.29.0",
|
|
40
40
|
"@uiw/react-codemirror": "^4.19.1",
|
|
41
41
|
"date-fns": "^2.28.0",
|
|
42
42
|
"date-fns-tz": "^1.3.7",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"react-window": "^1.8.8"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@perses-dev/storybook": "0.
|
|
53
|
+
"@perses-dev/storybook": "0.29.0",
|
|
54
54
|
"@types/react-window": "^1.8.5"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|