@perses-dev/components 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DateTimeRangePicker/AbsoluteTimePicker.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/AbsoluteTimePicker.js +4 -3
- package/dist/DateTimeRangePicker/AbsoluteTimePicker.js.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -0
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.js +3 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +1 -0
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js +9 -3
- package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
- package/dist/DateTimeRangePicker/utils.d.ts +1 -1
- package/dist/DateTimeRangePicker/utils.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/utils.js +5 -4
- package/dist/DateTimeRangePicker/utils.js.map +1 -1
- package/dist/GaugeChart/GaugeChart.d.ts +11 -2
- package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
- package/dist/GaugeChart/GaugeChart.js +58 -10
- package/dist/GaugeChart/GaugeChart.js.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.d.ts +3 -1
- package/dist/InfoTooltip/InfoTooltip.d.ts.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.js +4 -2
- package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts +8 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js +82 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts +2 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js +41 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js.map +1 -0
- package/dist/LegendOptionsEditor/index.d.ts +2 -0
- package/dist/LegendOptionsEditor/index.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/index.js +15 -0
- package/dist/LegendOptionsEditor/index.js.map +1 -0
- package/dist/LineChart/LineChart.d.ts +2 -3
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +38 -32
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/LineChart/utils.d.ts +1 -1
- package/dist/LineChart/utils.d.ts.map +1 -1
- package/dist/LineChart/utils.js +4 -3
- package/dist/LineChart/utils.js.map +1 -1
- package/dist/StatChart/StatChart.test.js +9 -2
- package/dist/StatChart/StatChart.test.js.map +1 -1
- package/dist/Tooltip/TooltipContent.d.ts.map +1 -1
- package/dist/Tooltip/TooltipContent.js +8 -9
- package/dist/Tooltip/TooltipContent.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.test.js +3 -4
- package/dist/UnitSelector/UnitSelector.test.js.map +1 -1
- package/dist/cjs/DateTimeRangePicker/AbsoluteTimePicker.js +4 -3
- package/dist/cjs/DateTimeRangePicker/DateTimeRangePicker.js +3 -1
- package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +9 -3
- package/dist/cjs/DateTimeRangePicker/utils.js +4 -3
- package/dist/cjs/GaugeChart/GaugeChart.js +66 -15
- package/dist/cjs/InfoTooltip/InfoTooltip.js +4 -2
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +88 -0
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.test.js +48 -0
- package/dist/cjs/LegendOptionsEditor/index.js +28 -0
- package/dist/cjs/LineChart/LineChart.js +37 -31
- package/dist/cjs/LineChart/utils.js +4 -3
- package/dist/cjs/StatChart/StatChart.test.js +9 -2
- package/dist/cjs/Tooltip/TooltipContent.js +8 -9
- package/dist/cjs/UnitSelector/UnitSelector.test.js +3 -4
- package/dist/cjs/context/TimeZoneProvider.js +90 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/model/graph.js +14 -3
- package/dist/cjs/model/units/bytes.js +32 -6
- package/dist/cjs/model/units/time.js +1 -1
- package/dist/cjs/model/units/units.js +1 -4
- package/dist/cjs/model/units/units.test.js +153 -0
- package/dist/cjs/utils/format.js +56 -0
- package/dist/cjs/utils/format.test.js +47 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/context/TimeZoneProvider.d.ts +13 -0
- package/dist/context/TimeZoneProvider.d.ts.map +1 -0
- package/dist/context/TimeZoneProvider.js +38 -0
- package/dist/context/TimeZoneProvider.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +4 -2
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js +4 -0
- package/dist/model/graph.js.map +1 -1
- package/dist/model/units/bytes.d.ts +6 -1
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +35 -7
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/time.js +1 -1
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +1 -4
- package/dist/model/units/units.js.map +1 -1
- package/dist/model/units/units.test.d.ts +2 -0
- package/dist/model/units/units.test.d.ts.map +1 -0
- package/dist/model/units/units.test.js +151 -0
- package/dist/model/units/units.test.js.map +1 -0
- package/dist/utils/format.d.ts +3 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +44 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/format.test.d.ts +2 -0
- package/dist/utils/format.test.d.ts.map +1 -0
- package/dist/utils/format.test.js +45 -0
- package/dist/utils/format.test.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Tooltip/TooltipContent.tsx"],"sourcesContent":["// Copyright 2022 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, Divider, Stack, Typography } from '@mui/material';\nimport { FocusedSeriesArray } from './focused-series';\nimport { SeriesInfo } from './SeriesInfo';\n\ninterface TooltipContentProps {\n focusedSeries: FocusedSeriesArray | null;\n wrapLabels?: boolean;\n}\n\nexport function TooltipContent(props: TooltipContentProps) {\n const { focusedSeries, wrapLabels } = props;\n\n const seriesTime = focusedSeries && focusedSeries[0] && focusedSeries[0].date ? focusedSeries[0].date : null;\n\n const formatTimeSeriesHeader = (timeString: string) => {\n const
|
|
1
|
+
{"version":3,"sources":["../../src/Tooltip/TooltipContent.tsx"],"sourcesContent":["// Copyright 2022 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, Divider, Stack, Typography } from '@mui/material';\nimport { useTimeZone } from '../context/TimeZoneProvider';\nimport { FocusedSeriesArray } from './focused-series';\nimport { SeriesInfo } from './SeriesInfo';\n\ninterface TooltipContentProps {\n focusedSeries: FocusedSeriesArray | null;\n wrapLabels?: boolean;\n}\n\nexport function TooltipContent(props: TooltipContentProps) {\n const { focusedSeries, wrapLabels } = props;\n const { formatWithUserTimeZone } = useTimeZone();\n\n const seriesTime = focusedSeries && focusedSeries[0] && focusedSeries[0].date ? focusedSeries[0].date : null;\n\n const formatTimeSeriesHeader = (timeString: string) => {\n const date = new Date(timeString);\n const formattedDate = formatWithUserTimeZone(date, 'MMM dd, yyyy - ');\n const formattedTime = formatWithUserTimeZone(date, 'HH:mm:ss');\n\n return (\n <>\n <Typography\n variant=\"caption\"\n sx={(theme) => ({\n color: theme.palette.common.white,\n })}\n >\n {formattedDate}\n </Typography>\n <Typography variant=\"caption\">\n <strong>{formattedTime}</strong>\n </Typography>\n </>\n );\n };\n\n const sortedFocusedSeries = useMemo(() => {\n if (focusedSeries === null) return null;\n return focusedSeries.sort((a, b) => (a.y > b.y ? -1 : 1));\n }, [focusedSeries]);\n\n if (sortedFocusedSeries !== null && seriesTime !== null) {\n return (\n <Stack py={1} px={1.5} spacing={0.5}>\n <Typography variant=\"caption\">{formatTimeSeriesHeader(seriesTime)}</Typography>\n <Divider\n sx={(theme) => ({\n borderColor: theme.palette.grey['500'],\n })}\n />\n <Box\n sx={{\n display: 'table',\n }}\n >\n {sortedFocusedSeries.map(({ datumIdx, seriesIdx, seriesName, y, formattedY, markerColor }) => {\n if (datumIdx === null || seriesIdx === null) return null;\n const key = seriesIdx.toString() + datumIdx.toString();\n\n return (\n <SeriesInfo\n key={key}\n seriesName={seriesName}\n y={y}\n formattedY={formattedY}\n markerColor={markerColor}\n totalSeries={sortedFocusedSeries.length}\n wrapLabels={wrapLabels}\n />\n );\n })}\n </Box>\n </Stack>\n );\n } else {\n return <></>;\n }\n}\n"],"names":["useMemo","Box","Divider","Stack","Typography","useTimeZone","SeriesInfo","TooltipContent","props","focusedSeries","wrapLabels","formatWithUserTimeZone","seriesTime","date","formatTimeSeriesHeader","timeString","Date","formattedDate","formattedTime","variant","sx","theme","color","palette","common","white","strong","sortedFocusedSeries","sort","a","b","y","py","px","spacing","borderColor","grey","display","map","datumIdx","seriesIdx","seriesName","formattedY","markerColor","key","toString","totalSeries","length"],"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,OAAO,EAAEC,KAAK,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAChE,SAASC,WAAW,QAAQ,6BAA6B,CAAC;AAE1D,SAASC,UAAU,QAAQ,cAAc,CAAC;AAO1C,OAAO,SAASC,cAAc,CAACC,KAA0B,EAAE;IACzD,MAAM,EAAEC,aAAa,CAAA,EAAEC,UAAU,CAAA,EAAE,GAAGF,KAAK,AAAC;IAC5C,MAAM,EAAEG,sBAAsB,CAAA,EAAE,GAAGN,WAAW,EAAE,AAAC;IAEjD,MAAMO,UAAU,GAAGH,aAAa,IAAIA,aAAa,CAAC,CAAC,CAAC,IAAIA,aAAa,CAAC,CAAC,CAAC,CAACI,IAAI,GAAGJ,aAAa,CAAC,CAAC,CAAC,CAACI,IAAI,GAAG,IAAI,AAAC;IAE7G,MAAMC,sBAAsB,GAAG,CAACC,UAAkB,GAAK;QACrD,MAAMF,IAAI,GAAG,IAAIG,IAAI,CAACD,UAAU,CAAC,AAAC;QAClC,MAAME,aAAa,GAAGN,sBAAsB,CAACE,IAAI,EAAE,iBAAiB,CAAC,AAAC;QACtE,MAAMK,aAAa,GAAGP,sBAAsB,CAACE,IAAI,EAAE,UAAU,CAAC,AAAC;QAE/D,qBACE;;8BACE,K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AA,EAAEW,UAAU,CAAA,EAAEC,WAAW,CAAA,EAAE,GAAK;wBAC5F,IAAIJ,QAAQ,KAAK,IAAI,IAAIC,SAAS,KAAK,IAAI,EAAE,OAAO,IAAI,CAAC;wBACzD,MAAMI,GAAG,GAAGJ,SAAS,CAACK,QAAQ,EAAE,GAAGN,QAAQ,CAACM,QAAQ,EAAE,AAAC;wBAEvD,qBACE,KAACvC,UAAU;4BAETmC,UAAU,EAAEA,UAAU;4BACtBV,CAAC,EAAEA,CAAC;4BACJW,UAAU,EAAEA,UAAU;4BACtBC,WAAW,EAAEA,WAAW;4BACxBG,WAAW,EAAEnB,mBAAmB,CAACoB,MAAM;4BACvCrC,UAAU,EAAEA,UAAU;2BANjBkC,GAAG,CAOR,CACF;oBACJ,CAAC,CAAC;kBACE;;UACA,CACR;IACJ,OAAO;QACL,qBAAO,mBAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -59,8 +59,7 @@ describe('UnitSelector', ()=>{
|
|
|
59
59
|
kind: 'Bytes'
|
|
60
60
|
}, onChange);
|
|
61
61
|
const unitSelector = getUnitSelector();
|
|
62
|
-
|
|
63
|
-
// abbreviate comes first and is disabled in some cases.
|
|
62
|
+
userEvent.tab();
|
|
64
63
|
userEvent.tab();
|
|
65
64
|
expect(unitSelector).toHaveFocus();
|
|
66
65
|
userEvent.clear(unitSelector);
|
|
@@ -182,11 +181,11 @@ describe('UnitSelector', ()=>{
|
|
|
182
181
|
});
|
|
183
182
|
expect(getDecimalSelector()).toBeEnabled();
|
|
184
183
|
});
|
|
185
|
-
it('
|
|
184
|
+
it('allows the user to set abbreviate', ()=>{
|
|
186
185
|
renderUnitSelector({
|
|
187
186
|
kind: 'Bytes'
|
|
188
187
|
});
|
|
189
|
-
expect(getAbbreviateSwitch()).
|
|
188
|
+
expect(getAbbreviateSwitch()).toBeEnabled();
|
|
190
189
|
});
|
|
191
190
|
});
|
|
192
191
|
it('should not show an option for disabled units', ()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/UnitSelector/UnitSelector.test.tsx"],"sourcesContent":["// Copyright 2022 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 { render, screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { UnitOptions } from '../model';\nimport { UnitSelector } from './UnitSelector';\n\ndescribe('UnitSelector', () => {\n const renderUnitSelector = (value: UnitOptions, onChange = jest.fn()) => {\n render(\n <div>\n <UnitSelector value={value} onChange={onChange} />\n </div>\n );\n };\n\n const getUnitSelector = () => {\n return screen.getByRole('combobox', { name: 'Units' });\n };\n\n const getDecimalSelector = () => {\n return screen.getByRole('combobox', { name: 'Decimal' });\n };\n\n const getAbbreviateSwitch = () => {\n return screen.getByRole('checkbox', { name: 'Abbreviate' });\n };\n\n it('can change the unit kind by clicking', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Minutes' }, onChange);\n\n const unitSelector = getUnitSelector();\n userEvent.click(unitSelector);\n const decimalOption = screen.getByRole('option', {\n name: 'Decimal',\n });\n userEvent.click(decimalOption);\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Decimal',\n });\n });\n\n it('can change the unit kind using a keyboard', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Bytes' }, onChange);\n\n const unitSelector = getUnitSelector();\n // Note that this tab order can change depending on the type because the\n // abbreviate comes first and is disabled in some cases.\n userEvent.tab();\n expect(unitSelector).toHaveFocus();\n\n userEvent.clear(unitSelector);\n userEvent.keyboard('years');\n screen.getByRole('option', {\n name: 'Years',\n });\n\n userEvent.keyboard('{arrowup}{enter}');\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Years',\n });\n });\n\n it('can change the decimal places by clicking', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Decimal', decimal_places: 0, abbreviate: true }, onChange);\n\n userEvent.click(getDecimalSelector());\n const decimalOption = screen.getByRole('option', {\n name: '1',\n });\n userEvent.click(decimalOption);\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Decimal',\n decimal_places: 1,\n abbreviate: true,\n });\n });\n\n it('can change the decimal places using a keyboard', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Percent' }, onChange);\n\n const decimalSelector = getDecimalSelector();\n userEvent.tab();\n userEvent.tab();\n expect(decimalSelector).toHaveFocus();\n\n userEvent.clear(decimalSelector);\n userEvent.keyboard('3');\n screen.getByRole('option', {\n name: '3',\n });\n\n userEvent.keyboard('{arrowup}{enter}');\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Percent',\n decimal_places: 3,\n });\n });\n\n it('can change abbreviate by clicking', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Decimal', decimal_places: 3, abbreviate: true }, onChange);\n\n userEvent.click(getAbbreviateSwitch());\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Decimal',\n decimal_places: 3,\n abbreviate: false,\n });\n });\n\n it('can change abbreviate using a keyboard', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Decimal', decimal_places: 0 }, onChange);\n\n userEvent.tab();\n userEvent.keyboard('{space}');\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Decimal',\n decimal_places: 0,\n abbreviate: true,\n });\n });\n\n describe('with a time unit selected', () => {\n it('does not allow the user to set abbreviate', () => {\n renderUnitSelector({ kind: 'Minutes' });\n expect(getAbbreviateSwitch()).toBeDisabled();\n });\n });\n\n describe('with a percent unit selected', () => {\n it('allows the user to modify the decimal places', () => {\n renderUnitSelector({ kind: 'Percent' });\n expect(getDecimalSelector()).toBeEnabled();\n });\n\n it('does not allow the user to set abbreviate', () => {\n renderUnitSelector({ kind: 'PercentDecimal' });\n expect(getAbbreviateSwitch()).toBeDisabled();\n });\n });\n\n describe('with a decimal unit selected', () => {\n it('allows the user to modify the decimal places', () => {\n renderUnitSelector({ kind: 'Decimal' });\n expect(getDecimalSelector()).toBeEnabled();\n });\n\n it('allows the user to set abbreviate', () => {\n renderUnitSelector({ kind: 'Decimal' });\n expect(getAbbreviateSwitch()).toBeEnabled();\n });\n });\n\n describe('with a bytes unit selected', () => {\n it('allows the user to modify the decimal places', () => {\n renderUnitSelector({ kind: 'Bytes' });\n expect(getDecimalSelector()).toBeEnabled();\n });\n\n it('does not allow the user to set abbreviate', () => {\n renderUnitSelector({ kind: 'Bytes' });\n expect(getAbbreviateSwitch()).toBeDisabled();\n });\n });\n\n it('should not show an option for disabled units', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Decimal' }, onChange);\n\n userEvent.click(getUnitSelector());\n const percentShorthandOption = screen.queryByRole('option', {\n name: '%',\n });\n expect(percentShorthandOption).not.toBeInTheDocument();\n });\n});\n"],"names":["render","screen","userEvent","UnitSelector","describe","renderUnitSelector","value","onChange","jest","fn","div","getUnitSelector","getByRole","name","getDecimalSelector","getAbbreviateSwitch","it","kind","unitSelector","click","decimalOption","expect","toHaveBeenCalledWith","tab","toHaveFocus","clear","keyboard","decimal_places","abbreviate","decimalSelector","toBeDisabled","toBeEnabled","percentShorthandOption","queryByRole","not","toBeInTheDocument"],"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,MAAM,EAAEC,MAAM,QAAQ,wBAAwB,CAAC;AACxD,OAAOC,SAAS,MAAM,6BAA6B,CAAC;AAEpD,SAASC,YAAY,QAAQ,gBAAgB,CAAC;AAE9CC,QAAQ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ACnC,MAAMqB,sBAAsB,GAAG/B,MAAM,CAACgC,WAAW,CAAC,QAAQ,EAAE;YAC1DpB,IAAI,EAAE,GAAG;SACV,CAAC,AAAC;QACHQ,MAAM,CAACW,sBAAsB,CAAC,CAACE,GAAG,CAACC,iBAAiB,EAAE,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/UnitSelector/UnitSelector.test.tsx"],"sourcesContent":["// Copyright 2022 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 { render, screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { UnitOptions } from '../model';\nimport { UnitSelector } from './UnitSelector';\n\ndescribe('UnitSelector', () => {\n const renderUnitSelector = (value: UnitOptions, onChange = jest.fn()) => {\n render(\n <div>\n <UnitSelector value={value} onChange={onChange} />\n </div>\n );\n };\n\n const getUnitSelector = () => {\n return screen.getByRole('combobox', { name: 'Units' });\n };\n\n const getDecimalSelector = () => {\n return screen.getByRole('combobox', { name: 'Decimal' });\n };\n\n const getAbbreviateSwitch = () => {\n return screen.getByRole('checkbox', { name: 'Abbreviate' });\n };\n\n it('can change the unit kind by clicking', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Minutes' }, onChange);\n\n const unitSelector = getUnitSelector();\n userEvent.click(unitSelector);\n const decimalOption = screen.getByRole('option', {\n name: 'Decimal',\n });\n userEvent.click(decimalOption);\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Decimal',\n });\n });\n\n it('can change the unit kind using a keyboard', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Bytes' }, onChange);\n\n const unitSelector = getUnitSelector();\n userEvent.tab();\n userEvent.tab();\n expect(unitSelector).toHaveFocus();\n\n userEvent.clear(unitSelector);\n userEvent.keyboard('years');\n screen.getByRole('option', {\n name: 'Years',\n });\n\n userEvent.keyboard('{arrowup}{enter}');\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Years',\n });\n });\n\n it('can change the decimal places by clicking', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Decimal', decimal_places: 0, abbreviate: true }, onChange);\n\n userEvent.click(getDecimalSelector());\n const decimalOption = screen.getByRole('option', {\n name: '1',\n });\n userEvent.click(decimalOption);\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Decimal',\n decimal_places: 1,\n abbreviate: true,\n });\n });\n\n it('can change the decimal places using a keyboard', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Percent' }, onChange);\n\n const decimalSelector = getDecimalSelector();\n userEvent.tab();\n userEvent.tab();\n expect(decimalSelector).toHaveFocus();\n\n userEvent.clear(decimalSelector);\n userEvent.keyboard('3');\n screen.getByRole('option', {\n name: '3',\n });\n\n userEvent.keyboard('{arrowup}{enter}');\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Percent',\n decimal_places: 3,\n });\n });\n\n it('can change abbreviate by clicking', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Decimal', decimal_places: 3, abbreviate: true }, onChange);\n\n userEvent.click(getAbbreviateSwitch());\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Decimal',\n decimal_places: 3,\n abbreviate: false,\n });\n });\n\n it('can change abbreviate using a keyboard', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Decimal', decimal_places: 0 }, onChange);\n\n userEvent.tab();\n userEvent.keyboard('{space}');\n\n expect(onChange).toHaveBeenCalledWith({\n kind: 'Decimal',\n decimal_places: 0,\n abbreviate: true,\n });\n });\n\n describe('with a time unit selected', () => {\n it('does not allow the user to set abbreviate', () => {\n renderUnitSelector({ kind: 'Minutes' });\n expect(getAbbreviateSwitch()).toBeDisabled();\n });\n });\n\n describe('with a percent unit selected', () => {\n it('allows the user to modify the decimal places', () => {\n renderUnitSelector({ kind: 'Percent' });\n expect(getDecimalSelector()).toBeEnabled();\n });\n\n it('does not allow the user to set abbreviate', () => {\n renderUnitSelector({ kind: 'PercentDecimal' });\n expect(getAbbreviateSwitch()).toBeDisabled();\n });\n });\n\n describe('with a decimal unit selected', () => {\n it('allows the user to modify the decimal places', () => {\n renderUnitSelector({ kind: 'Decimal' });\n expect(getDecimalSelector()).toBeEnabled();\n });\n\n it('allows the user to set abbreviate', () => {\n renderUnitSelector({ kind: 'Decimal' });\n expect(getAbbreviateSwitch()).toBeEnabled();\n });\n });\n\n describe('with a bytes unit selected', () => {\n it('allows the user to modify the decimal places', () => {\n renderUnitSelector({ kind: 'Bytes' });\n expect(getDecimalSelector()).toBeEnabled();\n });\n\n it('allows the user to set abbreviate', () => {\n renderUnitSelector({ kind: 'Bytes' });\n expect(getAbbreviateSwitch()).toBeEnabled();\n });\n });\n\n it('should not show an option for disabled units', () => {\n const onChange = jest.fn();\n renderUnitSelector({ kind: 'Decimal' }, onChange);\n\n userEvent.click(getUnitSelector());\n const percentShorthandOption = screen.queryByRole('option', {\n name: '%',\n });\n expect(percentShorthandOption).not.toBeInTheDocument();\n });\n});\n"],"names":["render","screen","userEvent","UnitSelector","describe","renderUnitSelector","value","onChange","jest","fn","div","getUnitSelector","getByRole","name","getDecimalSelector","getAbbreviateSwitch","it","kind","unitSelector","click","decimalOption","expect","toHaveBeenCalledWith","tab","toHaveFocus","clear","keyboard","decimal_places","abbreviate","decimalSelector","toBeDisabled","toBeEnabled","percentShorthandOption","queryByRole","not","toBeInTheDocument"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2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,IAAM;QACvD,MAAMT,QAAQ,GAAGC,IAAI,CAACC,EAAE,EAAE,AAAC;QAC3BJ,kBAAkB,CAAC;YAAEY,IAAI,EAAE,SAAS;SAAE,EAAEV,QAAQ,CAAC,CAAC;QAElDL,SAAS,CAACiB,KAAK,CAACR,eAAe,EAAE,CAAC,CAAC;QACnC,MAAMqB,sBAAsB,GAAG/B,MAAM,CAACgC,WAAW,CAAC,QAAQ,EAAE;YAC1DpB,IAAI,EAAE,GAAG;SACV,CAAC,AAAC;QACHQ,MAAM,CAACW,sBAAsB,CAAC,CAACE,GAAG,CAACC,iBAAiB,EAAE,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -23,12 +23,13 @@ const _react = require("react");
|
|
|
23
23
|
const _material = require("@mui/material");
|
|
24
24
|
const _xDatePickers = require("@mui/x-date-pickers");
|
|
25
25
|
const _adapterDateFns = require("@mui/x-date-pickers/AdapterDateFns");
|
|
26
|
-
const
|
|
26
|
+
const _timeZoneProvider = require("../context/TimeZoneProvider");
|
|
27
27
|
const _utils = require("./utils");
|
|
28
28
|
const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
|
|
29
29
|
const AbsoluteTimePicker = ({ initialTimeRange , onChange })=>{
|
|
30
30
|
const [timeRange, setTimeRange] = (0, _react.useState)(initialTimeRange);
|
|
31
31
|
const [showStartCalendar, setShowStartCalendar] = (0, _react.useState)(true);
|
|
32
|
+
const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
|
|
32
33
|
// validate start and end time, propagate changes
|
|
33
34
|
const updateDateRange = (input, isStartDate)=>{
|
|
34
35
|
const newDate = new Date(input);
|
|
@@ -163,7 +164,7 @@ const AbsoluteTimePicker = ({ initialTimeRange , onChange })=>{
|
|
|
163
164
|
// TODO: add helperText, fix validation after we decide on form state solution
|
|
164
165
|
updateDateRange(event.target.value, true);
|
|
165
166
|
},
|
|
166
|
-
value: (
|
|
167
|
+
value: formatWithUserTimeZone(timeRange.start, DATE_TIME_FORMAT),
|
|
167
168
|
label: "Start Time",
|
|
168
169
|
placeholder: "mm/dd/yyyy hh:mm",
|
|
169
170
|
// tel used to match MUI DateTimePicker, may change in future: https://github.com/mui/material-ui/issues/27590
|
|
@@ -173,7 +174,7 @@ const AbsoluteTimePicker = ({ initialTimeRange , onChange })=>{
|
|
|
173
174
|
onChange: (event)=>{
|
|
174
175
|
updateDateRange(event.target.value, false);
|
|
175
176
|
},
|
|
176
|
-
value: (
|
|
177
|
+
value: formatWithUserTimeZone(timeRange.end, DATE_TIME_FORMAT),
|
|
177
178
|
label: "End Time",
|
|
178
179
|
placeholder: "mm/dd/yyyy hh:mm",
|
|
179
180
|
type: "tel"
|
|
@@ -25,7 +25,7 @@ const _core = require("@perses-dev/core");
|
|
|
25
25
|
const _absoluteTimePicker = require("./AbsoluteTimePicker");
|
|
26
26
|
const _timeRangeSelector = require("./TimeRangeSelector");
|
|
27
27
|
function DateTimeRangePicker(props) {
|
|
28
|
-
const { value , onChange , timeOptions } = props;
|
|
28
|
+
const { value , onChange , timeOptions , height } = props;
|
|
29
29
|
const [showCustomDateSelector, setShowCustomDateSelector] = (0, _react.useState)(false);
|
|
30
30
|
const anchorEl = (0, _react.useRef)();
|
|
31
31
|
const convertedTimeRange = (0, _react.useMemo)(()=>{
|
|
@@ -36,6 +36,7 @@ function DateTimeRangePicker(props) {
|
|
|
36
36
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
37
37
|
direction: "row",
|
|
38
38
|
spacing: 1,
|
|
39
|
+
height: height,
|
|
39
40
|
children: [
|
|
40
41
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Popover, {
|
|
41
42
|
anchorEl: anchorEl.current,
|
|
@@ -63,6 +64,7 @@ function DateTimeRangePicker(props) {
|
|
|
63
64
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeRangeSelector.TimeRangeSelector, {
|
|
64
65
|
timeOptions: timeOptions,
|
|
65
66
|
value: value,
|
|
67
|
+
height: height,
|
|
66
68
|
onSelectChange: (event)=>{
|
|
67
69
|
const duration = event.target.value;
|
|
68
70
|
const relativeTimeInput = {
|
|
@@ -22,6 +22,7 @@ const _jsxRuntime = require("react/jsx-runtime");
|
|
|
22
22
|
const _material = require("@mui/material");
|
|
23
23
|
const _calendar = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Calendar"));
|
|
24
24
|
const _core = require("@perses-dev/core");
|
|
25
|
+
const _timeZoneProvider = require("../context/TimeZoneProvider");
|
|
25
26
|
const _utils = require("./utils");
|
|
26
27
|
function _interopRequireDefault(obj) {
|
|
27
28
|
return obj && obj.__esModule ? obj : {
|
|
@@ -30,8 +31,9 @@ function _interopRequireDefault(obj) {
|
|
|
30
31
|
}
|
|
31
32
|
const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
|
|
32
33
|
function TimeRangeSelector(props) {
|
|
33
|
-
const { value , timeOptions , onSelectChange , onCustomClick } = props;
|
|
34
|
-
const
|
|
34
|
+
const { value , timeOptions , onSelectChange , onCustomClick , height } = props;
|
|
35
|
+
const { timeZone } = (0, _timeZoneProvider.useTimeZone)();
|
|
36
|
+
const formattedValue = !(0, _core.isRelativeTimeRange)(value) ? (0, _utils.formatAbsoluteRange)(value, DATE_TIME_FORMAT, timeZone) : value.pastDuration;
|
|
35
37
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Select, {
|
|
36
38
|
value: formattedValue,
|
|
37
39
|
onChange: onSelectChange,
|
|
@@ -39,7 +41,11 @@ function TimeRangeSelector(props) {
|
|
|
39
41
|
sx: {
|
|
40
42
|
'.MuiSelect-icon': {
|
|
41
43
|
marginTop: '1px'
|
|
42
|
-
}
|
|
44
|
+
},
|
|
45
|
+
'.MuiSelect-select': height ? {
|
|
46
|
+
lineHeight: height,
|
|
47
|
+
paddingY: 0
|
|
48
|
+
} : {}
|
|
43
49
|
},
|
|
44
50
|
children: [
|
|
45
51
|
timeOptions.map((item, idx)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
|
|
@@ -25,6 +25,7 @@ _export(exports, {
|
|
|
25
25
|
formatAbsoluteRange: ()=>formatAbsoluteRange
|
|
26
26
|
});
|
|
27
27
|
const _dateFns = require("date-fns");
|
|
28
|
+
const _utils = require("../utils");
|
|
28
29
|
function validateDateRange(startDate, endDate) {
|
|
29
30
|
// TODO: display error as helperText
|
|
30
31
|
if (!(0, _dateFns.isValid)(startDate) || !(0, _dateFns.isValid)(endDate)) {
|
|
@@ -37,8 +38,8 @@ function validateDateRange(startDate, endDate) {
|
|
|
37
38
|
}
|
|
38
39
|
return true;
|
|
39
40
|
}
|
|
40
|
-
function formatAbsoluteRange(timeRange, dateFormat) {
|
|
41
|
-
const formattedStart = (0,
|
|
42
|
-
const formattedEnd = (0,
|
|
41
|
+
function formatAbsoluteRange(timeRange, dateFormat, timeZone) {
|
|
42
|
+
const formattedStart = (0, _utils.formatWithTimeZone)(timeRange.start, dateFormat, timeZone);
|
|
43
|
+
const formattedEnd = (0, _utils.formatWithTimeZone)(timeRange.end, dateFormat, timeZone);
|
|
43
44
|
return `${formattedStart} - ${formattedEnd}`;
|
|
44
45
|
}
|
|
@@ -14,32 +14,45 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
GaugeChart: ()=>GaugeChart,
|
|
25
|
+
getResponsiveValueSize: ()=>getResponsiveValueSize
|
|
20
26
|
});
|
|
21
27
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
const
|
|
23
|
-
const
|
|
28
|
+
const _core = require("@perses-dev/core");
|
|
29
|
+
const _core1 = require("echarts/core");
|
|
24
30
|
const _charts = require("echarts/charts");
|
|
25
31
|
const _components = require("echarts/components");
|
|
26
32
|
const _renderers = require("echarts/renderers");
|
|
27
33
|
const _chartsThemeProvider = require("../context/ChartsThemeProvider");
|
|
28
34
|
const _units = require("../model/units");
|
|
29
35
|
const _echart = require("../EChart");
|
|
30
|
-
(0,
|
|
36
|
+
(0, _core1.use)([
|
|
31
37
|
_charts.GaugeChart,
|
|
32
38
|
_components.GridComponent,
|
|
33
39
|
_components.TitleComponent,
|
|
34
40
|
_components.TooltipComponent,
|
|
35
41
|
_renderers.CanvasRenderer
|
|
36
42
|
]);
|
|
43
|
+
const PROGRESS_WIDTH = 16;
|
|
44
|
+
// adjusts when to show pointer icon
|
|
45
|
+
const GAUGE_SMALL_BREAKPOINT = 170;
|
|
37
46
|
function GaugeChart(props) {
|
|
38
47
|
const { width , height , data , unit , axisLine , max } = props;
|
|
39
48
|
const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
// useDeepMemo ensures value size util does not rerun everytime you hover on the chart
|
|
50
|
+
const option = (0, _core.useDeepMemo)(()=>{
|
|
51
|
+
var ref;
|
|
52
|
+
if (data.value === undefined || data.value === null) return chartsTheme.noDataOption;
|
|
53
|
+
// adjusts fontSize depending on number of characters
|
|
54
|
+
const valueSizeClamp = getResponsiveValueSize(data.value, unit, width, height);
|
|
55
|
+
var ref1;
|
|
43
56
|
return {
|
|
44
57
|
title: {
|
|
45
58
|
show: false
|
|
@@ -62,7 +75,7 @@ function GaugeChart(props) {
|
|
|
62
75
|
silent: true,
|
|
63
76
|
progress: {
|
|
64
77
|
show: true,
|
|
65
|
-
width:
|
|
78
|
+
width: PROGRESS_WIDTH,
|
|
66
79
|
itemStyle: {
|
|
67
80
|
color: 'auto'
|
|
68
81
|
}
|
|
@@ -78,7 +91,7 @@ function GaugeChart(props) {
|
|
|
78
91
|
'#e1e5e9'
|
|
79
92
|
]
|
|
80
93
|
],
|
|
81
|
-
width:
|
|
94
|
+
width: PROGRESS_WIDTH
|
|
82
95
|
}
|
|
83
96
|
},
|
|
84
97
|
axisTick: {
|
|
@@ -86,7 +99,7 @@ function GaugeChart(props) {
|
|
|
86
99
|
distance: 0
|
|
87
100
|
},
|
|
88
101
|
splitLine: {
|
|
89
|
-
show:
|
|
102
|
+
show: false
|
|
90
103
|
},
|
|
91
104
|
axisLabel: {
|
|
92
105
|
show: false,
|
|
@@ -105,7 +118,7 @@ function GaugeChart(props) {
|
|
|
105
118
|
},
|
|
106
119
|
data: [
|
|
107
120
|
{
|
|
108
|
-
value:
|
|
121
|
+
value: data.value
|
|
109
122
|
}
|
|
110
123
|
]
|
|
111
124
|
},
|
|
@@ -121,7 +134,15 @@ function GaugeChart(props) {
|
|
|
121
134
|
min: 0,
|
|
122
135
|
max,
|
|
123
136
|
pointer: {
|
|
124
|
-
show:
|
|
137
|
+
show: true,
|
|
138
|
+
// pointer hidden for small panels, path taken from ex: https://echarts.apache.org/examples/en/editor.html?c=gauge-grade
|
|
139
|
+
icon: width > GAUGE_SMALL_BREAKPOINT ? 'path://M12.8,0.7l12,40.1H0.7L12.8,0.7z' : 'none',
|
|
140
|
+
length: 10,
|
|
141
|
+
width: 5,
|
|
142
|
+
offsetCenter: [
|
|
143
|
+
0,
|
|
144
|
+
'-49%'
|
|
145
|
+
],
|
|
125
146
|
itemStyle: {
|
|
126
147
|
color: 'auto'
|
|
127
148
|
}
|
|
@@ -145,6 +166,7 @@ function GaugeChart(props) {
|
|
|
145
166
|
'-9%'
|
|
146
167
|
],
|
|
147
168
|
color: 'inherit',
|
|
169
|
+
fontSize: valueSizeClamp,
|
|
148
170
|
formatter: (value)=>{
|
|
149
171
|
return (0, _units.formatValue)(value, {
|
|
150
172
|
kind: unit.kind,
|
|
@@ -154,7 +176,21 @@ function GaugeChart(props) {
|
|
|
154
176
|
},
|
|
155
177
|
data: [
|
|
156
178
|
{
|
|
157
|
-
value:
|
|
179
|
+
value: data.value,
|
|
180
|
+
name: data.label,
|
|
181
|
+
// TODO: new UX for series names, create separate React component or reuse ListLegendItem
|
|
182
|
+
// https://echarts.apache.org/en/option.html#series-gauge.data.title
|
|
183
|
+
title: {
|
|
184
|
+
show: true,
|
|
185
|
+
color: (ref1 = (ref = chartsTheme.echartsTheme.textStyle) === null || ref === void 0 ? void 0 : ref.color) !== null && ref1 !== void 0 ? ref1 : 'inherit',
|
|
186
|
+
offsetCenter: [
|
|
187
|
+
0,
|
|
188
|
+
'55%'
|
|
189
|
+
],
|
|
190
|
+
overflow: 'truncate',
|
|
191
|
+
fontSize: 12,
|
|
192
|
+
width: width * 0.8
|
|
193
|
+
}
|
|
158
194
|
}
|
|
159
195
|
]
|
|
160
196
|
}
|
|
@@ -162,6 +198,8 @@ function GaugeChart(props) {
|
|
|
162
198
|
};
|
|
163
199
|
}, [
|
|
164
200
|
data,
|
|
201
|
+
width,
|
|
202
|
+
height,
|
|
165
203
|
chartsTheme,
|
|
166
204
|
unit,
|
|
167
205
|
axisLine,
|
|
@@ -176,3 +214,16 @@ function GaugeChart(props) {
|
|
|
176
214
|
theme: chartsTheme.echartsTheme
|
|
177
215
|
});
|
|
178
216
|
}
|
|
217
|
+
function getResponsiveValueSize(value, unit, width, height) {
|
|
218
|
+
const MIN_SIZE = 3;
|
|
219
|
+
const MAX_SIZE = 24;
|
|
220
|
+
const SIZE_MULTIPLIER = 0.7;
|
|
221
|
+
const formattedValue = (0, _units.formatValue)(value, {
|
|
222
|
+
kind: unit.kind,
|
|
223
|
+
decimal_places: 0
|
|
224
|
+
});
|
|
225
|
+
var _length;
|
|
226
|
+
const valueCharacters = (_length = formattedValue.length) !== null && _length !== void 0 ? _length : 2;
|
|
227
|
+
const valueSize = Math.min(width, height) / valueCharacters * SIZE_MULTIPLIER;
|
|
228
|
+
return `clamp(${MIN_SIZE}px, ${valueSize}px, ${MAX_SIZE}px)`;
|
|
229
|
+
}
|
|
@@ -39,15 +39,17 @@ var TooltipPlacement;
|
|
|
39
39
|
TooltipPlacement["Right"] = 'right';
|
|
40
40
|
TooltipPlacement["Bottom"] = 'bottom';
|
|
41
41
|
})(TooltipPlacement || (TooltipPlacement = {}));
|
|
42
|
-
const InfoTooltip = ({ id , title , description , placement , children })=>{
|
|
42
|
+
const InfoTooltip = ({ id , title , description , placement , children , enterDelay , enterNextDelay })=>{
|
|
43
43
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(StyledTooltip, {
|
|
44
44
|
arrow: true,
|
|
45
45
|
id: id,
|
|
46
|
-
placement: placement,
|
|
46
|
+
placement: placement !== null && placement !== void 0 ? placement : TooltipPlacement.Top,
|
|
47
47
|
title: /*#__PURE__*/ (0, _jsxRuntime.jsx)(TooltipContent, {
|
|
48
48
|
title: title,
|
|
49
49
|
description: description
|
|
50
50
|
}),
|
|
51
|
+
enterDelay: enterDelay !== null && enterDelay !== void 0 ? enterDelay : 500,
|
|
52
|
+
enterNextDelay: enterNextDelay !== null && enterNextDelay !== void 0 ? enterNextDelay : 500,
|
|
51
53
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
52
54
|
children: children
|
|
53
55
|
})
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "LegendOptionsEditor", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>LegendOptionsEditor
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
const _model = require("../model");
|
|
24
|
+
const _optionsEditorLayout = require("../OptionsEditorLayout");
|
|
25
|
+
const LEGEND_POSITIONS = [
|
|
26
|
+
'bottom',
|
|
27
|
+
'right'
|
|
28
|
+
];
|
|
29
|
+
const LEGEND_POSITIONS_CONFIG = {
|
|
30
|
+
bottom: {
|
|
31
|
+
label: 'Bottom'
|
|
32
|
+
},
|
|
33
|
+
right: {
|
|
34
|
+
label: 'Right'
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const POSITION_OPTIONS = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config])=>{
|
|
38
|
+
return {
|
|
39
|
+
id: id,
|
|
40
|
+
...config
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
function LegendOptionsEditor({ value , onChange }) {
|
|
44
|
+
const handleLegendShowChange = (_, checked)=>{
|
|
45
|
+
// legend is hidden when legend obj is undefined
|
|
46
|
+
const legendValue = checked === true ? {
|
|
47
|
+
position: _model.DEFAULT_LEGEND.position
|
|
48
|
+
} : undefined;
|
|
49
|
+
onChange(legendValue);
|
|
50
|
+
};
|
|
51
|
+
const handleLegendPositionChange = (_, newValue)=>{
|
|
52
|
+
onChange({
|
|
53
|
+
...value,
|
|
54
|
+
position: newValue.id
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
var ref;
|
|
58
|
+
const legendConfig = LEGEND_POSITIONS_CONFIG[(ref = value === null || value === void 0 ? void 0 : value.position) !== null && ref !== void 0 ? ref : _model.DEFAULT_LEGEND.position];
|
|
59
|
+
var ref1;
|
|
60
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
61
|
+
children: [
|
|
62
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
|
|
63
|
+
label: "Show",
|
|
64
|
+
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
|
|
65
|
+
checked: value !== undefined,
|
|
66
|
+
onChange: handleLegendShowChange
|
|
67
|
+
})
|
|
68
|
+
}),
|
|
69
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
|
|
70
|
+
label: "Position",
|
|
71
|
+
control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
|
|
72
|
+
value: {
|
|
73
|
+
...legendConfig,
|
|
74
|
+
id: (ref1 = value === null || value === void 0 ? void 0 : value.position) !== null && ref1 !== void 0 ? ref1 : _model.DEFAULT_LEGEND.position
|
|
75
|
+
},
|
|
76
|
+
options: POSITION_OPTIONS,
|
|
77
|
+
isOptionEqualToValue: (option, value)=>option.id === value.id,
|
|
78
|
+
renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
79
|
+
...params
|
|
80
|
+
}),
|
|
81
|
+
onChange: handleLegendPositionChange,
|
|
82
|
+
disabled: value === undefined,
|
|
83
|
+
disableClearable: true
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
const _react = require("@testing-library/react");
|
|
19
|
+
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
20
|
+
const _legendOptionsEditor = require("./LegendOptionsEditor");
|
|
21
|
+
function _interopRequireDefault(obj) {
|
|
22
|
+
return obj && obj.__esModule ? obj : {
|
|
23
|
+
default: obj
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
describe('LegendOptionsEditor', ()=>{
|
|
27
|
+
const renderLegendOptionsEditor = (value, onChange = jest.fn())=>{
|
|
28
|
+
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
29
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_legendOptionsEditor.LegendOptionsEditor, {
|
|
30
|
+
value: value,
|
|
31
|
+
onChange: onChange
|
|
32
|
+
})
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
const getLegendShowSwitch = ()=>{
|
|
36
|
+
return _react.screen.getByRole('checkbox', {
|
|
37
|
+
name: 'Show'
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
it('can change legend visibility by clicking', ()=>{
|
|
41
|
+
const onChange = jest.fn();
|
|
42
|
+
renderLegendOptionsEditor(undefined, onChange);
|
|
43
|
+
_userEvent.default.click(getLegendShowSwitch());
|
|
44
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
45
|
+
position: 'bottom'
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
_exportStar(require("./LegendOptionsEditor"), exports);
|
|
18
|
+
function _exportStar(from, to) {
|
|
19
|
+
Object.keys(from).forEach(function(k) {
|
|
20
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return from[k];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return from;
|
|
28
|
+
}
|