@perses-dev/components 0.19.0 → 0.21.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/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 +39 -34
- 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 +42 -21
- 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 -10
- 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 +40 -35
- package/dist/cjs/LineChart/utils.js +4 -3
- package/dist/cjs/StatChart/StatChart.test.js +43 -27
- package/dist/cjs/Tooltip/TooltipContent.js +8 -9
- package/dist/cjs/UnitSelector/UnitSelector.test.js +3 -10
- 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 +26 -62
- package/dist/cjs/model/units/units.js +1 -4
- package/dist/cjs/model/units/units.test.js +153 -0
- package/dist/cjs/theme/theme.js +19 -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.d.ts +11 -0
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +25 -62
- 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/theme/theme.d.ts +2 -2
- package/dist/theme/theme.d.ts.map +1 -1
- package/dist/theme/theme.js +19 -0
- package/dist/theme/theme.js.map +1 -1
- 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
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { LegendOptions } from '../model';
|
|
3
|
+
export interface LegendOptionsEditorProps {
|
|
4
|
+
value?: LegendOptions;
|
|
5
|
+
onChange: (legend?: LegendOptions) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function LegendOptionsEditor({ value, onChange }: LegendOptionsEditorProps): JSX.Element;
|
|
8
|
+
//# sourceMappingURL=LegendOptionsEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LegendOptionsEditor.d.ts","sourceRoot":"","sources":["../../src/LegendOptionsEditor/LegendOptionsEditor.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAkB,aAAa,EAAE,MAAM,UAAU,CAAC;AAyBzD,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CAC5C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,eAyChF"}
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import { Autocomplete, Switch, TextField } from '@mui/material';
|
|
15
|
+
import { DEFAULT_LEGEND } from '../model';
|
|
16
|
+
import { OptionsEditorControl } from '../OptionsEditorLayout';
|
|
17
|
+
const LEGEND_POSITIONS = [
|
|
18
|
+
'bottom',
|
|
19
|
+
'right'
|
|
20
|
+
];
|
|
21
|
+
const LEGEND_POSITIONS_CONFIG = {
|
|
22
|
+
bottom: {
|
|
23
|
+
label: 'Bottom'
|
|
24
|
+
},
|
|
25
|
+
right: {
|
|
26
|
+
label: 'Right'
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const POSITION_OPTIONS = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config])=>{
|
|
30
|
+
return {
|
|
31
|
+
id: id,
|
|
32
|
+
...config
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
export function LegendOptionsEditor({ value , onChange }) {
|
|
36
|
+
const handleLegendShowChange = (_, checked)=>{
|
|
37
|
+
// legend is hidden when legend obj is undefined
|
|
38
|
+
const legendValue = checked === true ? {
|
|
39
|
+
position: DEFAULT_LEGEND.position
|
|
40
|
+
} : undefined;
|
|
41
|
+
onChange(legendValue);
|
|
42
|
+
};
|
|
43
|
+
const handleLegendPositionChange = (_, newValue)=>{
|
|
44
|
+
onChange({
|
|
45
|
+
...value,
|
|
46
|
+
position: newValue.id
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var ref;
|
|
50
|
+
const legendConfig = LEGEND_POSITIONS_CONFIG[(ref = value === null || value === void 0 ? void 0 : value.position) !== null && ref !== void 0 ? ref : DEFAULT_LEGEND.position];
|
|
51
|
+
var ref1;
|
|
52
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
53
|
+
children: [
|
|
54
|
+
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
55
|
+
label: "Show",
|
|
56
|
+
control: /*#__PURE__*/ _jsx(Switch, {
|
|
57
|
+
checked: value !== undefined,
|
|
58
|
+
onChange: handleLegendShowChange
|
|
59
|
+
})
|
|
60
|
+
}),
|
|
61
|
+
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
62
|
+
label: "Position",
|
|
63
|
+
control: /*#__PURE__*/ _jsx(Autocomplete, {
|
|
64
|
+
value: {
|
|
65
|
+
...legendConfig,
|
|
66
|
+
id: (ref1 = value === null || value === void 0 ? void 0 : value.position) !== null && ref1 !== void 0 ? ref1 : DEFAULT_LEGEND.position
|
|
67
|
+
},
|
|
68
|
+
options: POSITION_OPTIONS,
|
|
69
|
+
isOptionEqualToValue: (option, value)=>option.id === value.id,
|
|
70
|
+
renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
|
|
71
|
+
...params
|
|
72
|
+
}),
|
|
73
|
+
onChange: handleLegendPositionChange,
|
|
74
|
+
disabled: value === undefined,
|
|
75
|
+
disableClearable: true
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=LegendOptionsEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/LegendOptionsEditor/LegendOptionsEditor.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 { Autocomplete, Switch, SwitchProps, TextField } from '@mui/material';\nimport { DEFAULT_LEGEND, LegendOptions } from '../model';\nimport { OptionsEditorControl } from '../OptionsEditorLayout';\n\ntype LegendPositionConfig = {\n label: string;\n};\n\nconst LEGEND_POSITIONS = ['bottom', 'right'] as const;\n\ntype LegendPositions = typeof LEGEND_POSITIONS[number];\n\nconst LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendPositionConfig>> = {\n bottom: { label: 'Bottom' },\n right: { label: 'Right' },\n};\n\ntype LegendPositionOption = LegendPositionConfig & { id: LegendOptions['position'] };\n\nconst POSITION_OPTIONS: LegendPositionOption[] = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendOptions['position'],\n ...config,\n };\n});\n\nexport interface LegendOptionsEditorProps {\n value?: LegendOptions;\n onChange: (legend?: LegendOptions) => void;\n}\n\nexport function LegendOptionsEditor({ value, onChange }: LegendOptionsEditorProps) {\n const handleLegendShowChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n // legend is hidden when legend obj is undefined\n const legendValue = checked === true ? { position: DEFAULT_LEGEND.position } : undefined;\n onChange(legendValue);\n };\n\n const handleLegendPositionChange = (_: unknown, newValue: LegendPositionOption) => {\n onChange({\n ...value,\n position: newValue.id,\n });\n };\n\n const legendConfig = LEGEND_POSITIONS_CONFIG[value?.position ?? DEFAULT_LEGEND.position];\n\n return (\n <>\n <OptionsEditorControl\n label=\"Show\"\n control={<Switch checked={value !== undefined} onChange={handleLegendShowChange} />}\n />\n <OptionsEditorControl\n label=\"Position\"\n control={\n <Autocomplete\n value={{\n ...legendConfig,\n id: value?.position ?? DEFAULT_LEGEND.position,\n }}\n options={POSITION_OPTIONS}\n isOptionEqualToValue={(option, value) => option.id === value.id}\n renderInput={(params) => <TextField {...params} />}\n onChange={handleLegendPositionChange}\n disabled={value === undefined}\n disableClearable\n ></Autocomplete>\n }\n />\n </>\n );\n}\n"],"names":["Autocomplete","Switch","TextField","DEFAULT_LEGEND","OptionsEditorControl","LEGEND_POSITIONS","LEGEND_POSITIONS_CONFIG","bottom","label","right","POSITION_OPTIONS","Object","entries","map","id","config","LegendOptionsEditor","value","onChange","handleLegendShowChange","_","checked","legendValue","position","undefined","handleLegendPositionChange","newValue","legendConfig","control","options","isOptionEqualToValue","option","renderInput","params","disabled","disableClearable"],"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,YAAY,EAAEC,MAAM,EAAeC,SAAS,QAAQ,eAAe,CAAC;AAC7E,SAASC,cAAc,QAAuB,UAAU,CAAC;AACzD,SAASC,oBAAoB,QAAQ,wBAAwB,CAAC;AAM9D,MAAMC,gBAAgB,GAAG;IAAC,QAAQ;IAAE,OAAO;CAAC,AAAS,AAAC;AAItD,MAAMC,uBAAuB,GAA4D;IACvFC,MAAM,EAAE;QAAEC,KAAK,EAAE,QAAQ;KAAE;IAC3BC,KAAK,EAAE;QAAED,KAAK,EAAE,OAAO;KAAE;CAC1B,AAAC;AAIF,MAAME,gBAAgB,GAA2BC,MAAM,CAACC,OAAO,CAACN,uBAAuB,CAAC,CAACO,GAAG,CAAC,CAAC,CAACC,EAAE,EAAEC,MAAM,CAAC,GAAK;IAC7G,OAAO;QACLD,EAAE,EAAEA,EAAE;QACN,GAAGC,MAAM;KACV,CAAC;AACJ,CAAC,CAAC,AAAC;AAOH,OAAO,SAASC,mBAAmB,CAAC,EAAEC,KAAK,CAAA,EAAEC,QAAQ,CAAA,EAA4B,EAAE;IACjF,MAAMC,sBAAsB,GAA4B,CAACC,CAAU,EAAE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,WAAW,EAAE,CAACC,MAAM,iBAAK,KAAC/B,SAAS;4BAAE,GAAG+B,MAAM;0BAAI;oBAClDf,QAAQ,EAAEO,0BAA0B;oBACpCS,QAAQ,EAAEjB,KAAK,KAAKO,SAAS;oBAC7BW,gBAAgB;kBACF;cAElB;;MACD,CACH;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LegendOptionsEditor.test.d.ts","sourceRoot":"","sources":["../../src/LegendOptionsEditor/LegendOptionsEditor.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { render, screen } from '@testing-library/react';
|
|
15
|
+
import userEvent from '@testing-library/user-event';
|
|
16
|
+
import { LegendOptionsEditor } from './LegendOptionsEditor';
|
|
17
|
+
describe('LegendOptionsEditor', ()=>{
|
|
18
|
+
const renderLegendOptionsEditor = (value, onChange = jest.fn())=>{
|
|
19
|
+
render(/*#__PURE__*/ _jsx("div", {
|
|
20
|
+
children: /*#__PURE__*/ _jsx(LegendOptionsEditor, {
|
|
21
|
+
value: value,
|
|
22
|
+
onChange: onChange
|
|
23
|
+
})
|
|
24
|
+
}));
|
|
25
|
+
};
|
|
26
|
+
const getLegendShowSwitch = ()=>{
|
|
27
|
+
return screen.getByRole('checkbox', {
|
|
28
|
+
name: 'Show'
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
it('can change legend visibility by clicking', ()=>{
|
|
32
|
+
const onChange = jest.fn();
|
|
33
|
+
renderLegendOptionsEditor(undefined, onChange);
|
|
34
|
+
userEvent.click(getLegendShowSwitch());
|
|
35
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
36
|
+
position: 'bottom'
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=LegendOptionsEditor.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/LegendOptionsEditor/LegendOptionsEditor.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 { LegendOptions } from '../model';\nimport { LegendOptionsEditor } from './LegendOptionsEditor';\n\ndescribe('LegendOptionsEditor', () => {\n const renderLegendOptionsEditor = (value?: LegendOptions, onChange = jest.fn()) => {\n render(\n <div>\n <LegendOptionsEditor value={value} onChange={onChange} />\n </div>\n );\n };\n\n const getLegendShowSwitch = () => {\n return screen.getByRole('checkbox', { name: 'Show' });\n };\n\n it('can change legend visibility by clicking', () => {\n const onChange = jest.fn();\n renderLegendOptionsEditor(undefined, onChange);\n userEvent.click(getLegendShowSwitch());\n expect(onChange).toHaveBeenCalledWith({ position: 'bottom' });\n });\n});\n"],"names":["render","screen","userEvent","LegendOptionsEditor","describe","renderLegendOptionsEditor","value","onChange","jest","fn","div","getLegendShowSwitch","getByRole","name","it","undefined","click","expect","toHaveBeenCalledWith","position"],"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,mBAAmB,QAAQ,uBAAuB,CAAC;AAE5DC,QAAQ,CAAC,qBAAqB,EAAE,IAAM;IACpC,MAAMC,yBAAyB,GAAG,CAACC,KAAqB,EAAEC,QAAQ,GAAGC,IAAI,CAACC,EAAE,EAAE,GAAK;QACjFT,MAAM,eACJ,KAACU,KAAG;sBACF,cAAA,KAACP,mBAAmB;gBAACG,KAAK,EAAEA,KAAK;gBAAEC,QAAQ,EAAEA,QAAQ;cAAI;UACrD,CACP,CAAC;IACJ,CAAC,AAAC;IAEF,MAAMI,mBAAmB,GAAG,IAAM;QAChC,OAAOV,MAAM,CAACW,SAAS,CAAC,UAAU,EAAE;YAAEC,IAAI,EAAE,MAAM;SAAE,CAAC,CAAC;IACxD,CAAC,AAAC;IAEFC,EAAE,CAAC,0CAA0C,EAAE,IAAM;QACnD,MAAMP,QAAQ,GAAGC,IAAI,CAACC,EAAE,EAAE,AAAC;QAC3BJ,yBAAyB,CAACU,SAAS,EAAER,QAAQ,CAAC,CAAC;QAC/CL,SAAS,CAACc,KAAK,CAACL,mBAAmB,EAAE,CAAC,CAAC;QACvCM,MAAM,CAACV,QAAQ,CAAC,CAACW,oBAAoB,CAAC;YAAEC,QAAQ,EAAE,QAAQ;SAAE,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/LegendOptionsEditor/index.ts"],"names":[],"mappings":"AAaA,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
export * from './LegendOptionsEditor';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/LegendOptionsEditor/index.ts"],"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\nexport * from './LegendOptionsEditor';\n"],"names":[],"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,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MouseEvent } from 'react';
|
|
2
|
-
import type { GridComponentOption, LegendComponentOption,
|
|
2
|
+
import type { GridComponentOption, LegendComponentOption, YAXisComponentOption } from 'echarts';
|
|
3
3
|
import { EChartsDataFormat } from '../model/graph';
|
|
4
4
|
import { UnitOptions } from '../model/units';
|
|
5
5
|
import { ZoomEventData } from './utils';
|
|
@@ -10,10 +10,9 @@ interface LineChartProps {
|
|
|
10
10
|
unit?: UnitOptions;
|
|
11
11
|
grid?: GridComponentOption;
|
|
12
12
|
legend?: LegendComponentOption;
|
|
13
|
-
visualMap?: VisualMapComponentOption[];
|
|
14
13
|
onDataZoom?: (e: ZoomEventData) => void;
|
|
15
14
|
onDoubleClick?: (e: MouseEvent) => void;
|
|
16
15
|
}
|
|
17
|
-
export declare function LineChart({ height, data, yAxis, unit, grid, legend,
|
|
16
|
+
export declare function LineChart({ height, data, yAxis, unit, grid, legend, onDataZoom, onDoubleClick }: LineChartProps): JSX.Element;
|
|
18
17
|
export {};
|
|
19
18
|
//# sourceMappingURL=LineChart.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/LineChart/LineChart.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAA6B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/LineChart/LineChart.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAA6B,MAAM,OAAO,CAAC;AAE9D,OAAO,KAAK,EAEV,mBAAmB,EAEnB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAgBjB,OAAO,EAAE,iBAAiB,EAA+B,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,OAAO,EAA0E,aAAa,EAAE,MAAM,SAAS,CAAC;AAgBhH,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,CAAC,EAAE,mBAAmB,CAAC;IAC3B,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IACxC,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;CACzC;AAED,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,EAAE,cAAc,eAgJ/G"}
|
|
@@ -12,15 +12,16 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { useMemo, useRef, useState } from 'react';
|
|
15
|
-
import { useDeepMemo } from '@perses-dev/core';
|
|
16
15
|
import { Box } from '@mui/material';
|
|
17
16
|
import { use } from 'echarts/core';
|
|
18
17
|
import { LineChart as EChartsLineChart } from 'echarts/charts';
|
|
19
|
-
import { GridComponent, DataZoomComponent, MarkAreaComponent, MarkLineComponent, MarkPointComponent, TitleComponent, ToolboxComponent, TooltipComponent, LegendComponent
|
|
18
|
+
import { GridComponent, DataZoomComponent, MarkAreaComponent, MarkLineComponent, MarkPointComponent, TitleComponent, ToolboxComponent, TooltipComponent, LegendComponent } from 'echarts/components';
|
|
20
19
|
import { CanvasRenderer } from 'echarts/renderers';
|
|
21
20
|
import { EChart } from '../EChart';
|
|
21
|
+
import { OPTIMIZED_MODE_SERIES_LIMIT } from '../model/graph';
|
|
22
22
|
import { useChartsTheme } from '../context/ChartsThemeProvider';
|
|
23
23
|
import { Tooltip } from '../Tooltip/Tooltip';
|
|
24
|
+
import { useTimeZone } from '../context/TimeZoneProvider';
|
|
24
25
|
import { enableDataZoom, getDateRange, getFormattedDate, getYAxes, restoreChart } from './utils';
|
|
25
26
|
use([
|
|
26
27
|
EChartsLineChart,
|
|
@@ -33,14 +34,14 @@ use([
|
|
|
33
34
|
ToolboxComponent,
|
|
34
35
|
TooltipComponent,
|
|
35
36
|
LegendComponent,
|
|
36
|
-
VisualMapComponent,
|
|
37
37
|
CanvasRenderer
|
|
38
38
|
]);
|
|
39
|
-
export function LineChart({ height , data , yAxis , unit , grid , legend ,
|
|
39
|
+
export function LineChart({ height , data , yAxis , unit , grid , legend , onDataZoom , onDoubleClick }) {
|
|
40
40
|
const chartsTheme = useChartsTheme();
|
|
41
41
|
const chartRef = useRef();
|
|
42
42
|
const [showTooltip, setShowTooltip] = useState(true);
|
|
43
43
|
const [pinTooltip, setPinTooltip] = useState(false);
|
|
44
|
+
const { timeZone } = useTimeZone();
|
|
44
45
|
const handleEvents = useMemo(()=>{
|
|
45
46
|
return {
|
|
46
47
|
datazoom: (params)=>{
|
|
@@ -76,7 +77,6 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , visua
|
|
|
76
77
|
if (chartRef.current !== undefined) {
|
|
77
78
|
enableDataZoom(chartRef.current);
|
|
78
79
|
}
|
|
79
|
-
const handleOnClick = ()=>setPinTooltip((current)=>!current);
|
|
80
80
|
const handleOnDoubleClick = (e)=>{
|
|
81
81
|
setPinTooltip(false);
|
|
82
82
|
// either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
|
|
@@ -88,25 +88,12 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , visua
|
|
|
88
88
|
onDoubleClick(e);
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
if (e.target instanceof HTMLCanvasElement) {
|
|
94
|
-
setShowTooltip(false);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const handleOnMouseUp = ()=>{
|
|
98
|
-
setShowTooltip(true);
|
|
99
|
-
};
|
|
100
|
-
const handleOnMouseEnter = ()=>{
|
|
101
|
-
setShowTooltip(true);
|
|
102
|
-
};
|
|
103
|
-
const handleOnMouseLeave = ()=>{
|
|
104
|
-
setShowTooltip(false);
|
|
105
|
-
setPinTooltip(false);
|
|
106
|
-
};
|
|
107
|
-
const option = useDeepMemo(()=>{
|
|
91
|
+
const { noDataOption } = chartsTheme;
|
|
92
|
+
const option = useMemo(()=>{
|
|
108
93
|
if (data.timeSeries === undefined) return {};
|
|
109
|
-
if (data.timeSeries === null || data.timeSeries.length === 0) return
|
|
94
|
+
if (data.timeSeries === null || data.timeSeries.length === 0) return noDataOption;
|
|
95
|
+
// show symbols and axisPointer dashed line on hover
|
|
96
|
+
const isOptimizedMode = data.timeSeries.length > OPTIMIZED_MODE_SERIES_LIMIT;
|
|
110
97
|
var _rangeMs;
|
|
111
98
|
const rangeMs = (_rangeMs = data.rangeMs) !== null && _rangeMs !== void 0 ? _rangeMs : getDateRange(data.xAxis);
|
|
112
99
|
const option = {
|
|
@@ -117,18 +104,18 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , visua
|
|
|
117
104
|
max: data.xAxisMax,
|
|
118
105
|
axisLabel: {
|
|
119
106
|
formatter: (value)=>{
|
|
120
|
-
return getFormattedDate(value, rangeMs);
|
|
107
|
+
return getFormattedDate(value, rangeMs, timeZone);
|
|
121
108
|
}
|
|
122
109
|
}
|
|
123
110
|
},
|
|
124
111
|
yAxis: getYAxes(yAxis, unit),
|
|
125
112
|
animation: false,
|
|
126
113
|
tooltip: {
|
|
127
|
-
show:
|
|
114
|
+
show: !isOptimizedMode,
|
|
128
115
|
trigger: 'axis',
|
|
129
116
|
showContent: false,
|
|
130
117
|
axisPointer: {
|
|
131
|
-
type: 'line',
|
|
118
|
+
type: isOptimizedMode ? 'none' : 'line',
|
|
132
119
|
z: 0
|
|
133
120
|
}
|
|
134
121
|
},
|
|
@@ -141,27 +128,45 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , visua
|
|
|
141
128
|
}
|
|
142
129
|
},
|
|
143
130
|
grid,
|
|
144
|
-
legend
|
|
145
|
-
visualMap
|
|
131
|
+
legend
|
|
146
132
|
};
|
|
147
133
|
return option;
|
|
148
134
|
}, [
|
|
149
135
|
data,
|
|
150
136
|
yAxis,
|
|
137
|
+
unit,
|
|
151
138
|
grid,
|
|
152
139
|
legend,
|
|
153
|
-
|
|
140
|
+
noDataOption,
|
|
141
|
+
timeZone
|
|
154
142
|
]);
|
|
155
143
|
return /*#__PURE__*/ _jsxs(Box, {
|
|
156
144
|
sx: {
|
|
157
145
|
height
|
|
158
146
|
},
|
|
159
|
-
onClick:
|
|
147
|
+
onClick: ()=>{
|
|
148
|
+
setPinTooltip((current)=>!current);
|
|
149
|
+
},
|
|
150
|
+
onMouseDown: (e)=>{
|
|
151
|
+
// hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
|
|
152
|
+
if (e.target instanceof HTMLCanvasElement) {
|
|
153
|
+
setShowTooltip(false);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
onMouseUp: ()=>{
|
|
157
|
+
setShowTooltip(true);
|
|
158
|
+
},
|
|
159
|
+
onMouseLeave: ()=>{
|
|
160
|
+
setShowTooltip(false);
|
|
161
|
+
setPinTooltip(false);
|
|
162
|
+
},
|
|
163
|
+
onMouseEnter: ()=>{
|
|
164
|
+
setShowTooltip(true);
|
|
165
|
+
if (chartRef.current !== undefined) {
|
|
166
|
+
enableDataZoom(chartRef.current);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
160
169
|
onDoubleClick: handleOnDoubleClick,
|
|
161
|
-
onMouseDown: handleOnMouseDown,
|
|
162
|
-
onMouseUp: handleOnMouseUp,
|
|
163
|
-
onMouseLeave: handleOnMouseLeave,
|
|
164
|
-
onMouseEnter: handleOnMouseEnter,
|
|
165
170
|
children: [
|
|
166
171
|
showTooltip === true && /*#__PURE__*/ _jsx(Tooltip, {
|
|
167
172
|
chartRef: chartRef,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/LineChart/LineChart.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 { MouseEvent, useMemo, useRef, useState } from 'react';\nimport { useDeepMemo } from '@perses-dev/core';\nimport { Box } from '@mui/material';\nimport type {\n EChartsCoreOption,\n GridComponentOption,\n LineSeriesOption,\n LegendComponentOption,\n VisualMapComponentOption,\n YAXisComponentOption,\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 VisualMapComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, OnEventsType } from '../EChart';\nimport { EChartsDataFormat } from '../model/graph';\nimport { UnitOptions } from '../model/units';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { Tooltip } from '../Tooltip/Tooltip';\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 VisualMapComponent,\n CanvasRenderer,\n]);\n\ninterface LineChartProps {\n height: number;\n data: EChartsDataFormat;\n yAxis?: YAXisComponentOption;\n unit?: UnitOptions;\n grid?: GridComponentOption;\n legend?: LegendComponentOption;\n visualMap?: VisualMapComponentOption[];\n onDataZoom?: (e: ZoomEventData) => void;\n onDoubleClick?: (e: MouseEvent) => void;\n}\n\nexport function LineChart({\n height,\n data,\n yAxis,\n unit,\n grid,\n legend,\n visualMap,\n onDataZoom,\n onDoubleClick,\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\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 handleOnClick = () => setPinTooltip((current) => !current);\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 handleOnMouseDown = (e: MouseEvent) => {\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\n const handleOnMouseUp = () => {\n setShowTooltip(true);\n };\n\n const handleOnMouseEnter = () => {\n setShowTooltip(true);\n };\n\n const handleOnMouseLeave = () => {\n setShowTooltip(false);\n setPinTooltip(false);\n };\n\n const option: EChartsCoreOption = useDeepMemo(() => {\n if (data.timeSeries === undefined) return {};\n if (data.timeSeries === null || data.timeSeries.length === 0) return chartsTheme.noDataOption;\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);\n },\n },\n },\n yAxis: getYAxes(yAxis, unit),\n animation: false,\n tooltip: {\n show: true,\n trigger: 'axis',\n showContent: false, // echarts tooltip content hidden since we use custom tooltip instead\n axisPointer: {\n type: '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 visualMap,\n };\n\n return option;\n }, [data, yAxis, grid, legend, visualMap]);\n\n return (\n <Box\n sx={{\n height,\n }}\n onClick={handleOnClick}\n onDoubleClick={handleOnDoubleClick}\n onMouseDown={handleOnMouseDown}\n onMouseUp={handleOnMouseUp}\n onMouseLeave={handleOnMouseLeave}\n onMouseEnter={handleOnMouseEnter}\n >\n {showTooltip === true && (\n <Tooltip chartRef={chartRef} chartData={data} wrapLabels={true} pinTooltip={pinTooltip} unit={unit}></Tooltip>\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":["useMemo","useRef","useState","useDeepMemo","Box","use","LineChart","EChartsLineChart","GridComponent","DataZoomComponent","MarkAreaComponent","MarkLineComponent","MarkPointComponent","TitleComponent","ToolboxComponent","TooltipComponent","LegendComponent","VisualMapComponent","CanvasRenderer","EChart","useChartsTheme","Tooltip","enableDataZoom","getDateRange","getFormattedDate","getYAxes","restoreChart","height","data","yAxis","unit","grid","legend","visualMap","onDataZoom","onDoubleClick","chartsTheme","chartRef","showTooltip","setShowTooltip","pinTooltip","setPinTooltip","handleEvents","datazoom","params","undefined","setTimeout","batch","startIndex","startValue","endIndex","endValue","xAxis","length","xAxisStartValue","xAxisEndValue","zoomEvent","start","end","current","handleOnClick","handleOnDoubleClick","e","handleOnMouseDown","target","HTMLCanvasElement","handleOnMouseUp","handleOnMouseEnter","handleOnMouseLeave","option","timeSeries","noDataOption","rangeMs","series","type","max","xAxisMax","axisLabel","formatter","value","animation","tooltip","show","trigger","showContent","axisPointer","z","toolbox","feature","dataZoom","icon","yAxisIndex","sx","onClick","onMouseDown","onMouseUp","onMouseLeave","onMouseEnter","chartData","wrapLabels","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,SAAqBA,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAC9D,SAASC,WAAW,QAAQ,kBAAkB,CAAC;AAC/C,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,EACfC,kBAAkB,QACb,oBAAoB,CAAC;AAC5B,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,MAAM,QAAsB,WAAW,CAAC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cAAY,AAC/G;0BAED,KAACX,MAAM;gBACLyE,EAAE,EAAE;oBACFQ,KAAK,EAAE,MAAM;oBACbzE,MAAM,EAAE,MAAM;iBACf;gBACD0C,MAAM,EAAEA,MAAM;gBACdgC,KAAK,EAAEjE,WAAW,CAACkE,YAAY;gBAC/BC,QAAQ,EAAE7D,YAAY;gBACtB8D,SAAS,EAAEnE,QAAQ;cACnB;;MACE,CACN;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/LineChart/LineChart.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 { MouseEvent, useMemo, useRef, useState } from 'react';\nimport { Box } from '@mui/material';\nimport type {\n EChartsCoreOption,\n GridComponentOption,\n LineSeriesOption,\n LegendComponentOption,\n YAXisComponentOption,\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 { Tooltip } from '../Tooltip/Tooltip';\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\ninterface LineChartProps {\n height: number;\n data: EChartsDataFormat;\n yAxis?: YAXisComponentOption;\n unit?: UnitOptions;\n grid?: GridComponentOption;\n legend?: LegendComponentOption;\n onDataZoom?: (e: ZoomEventData) => void;\n onDoubleClick?: (e: MouseEvent) => void;\n}\n\nexport function LineChart({ height, data, yAxis, unit, grid, legend, onDataZoom, onDoubleClick }: 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 return option;\n }, [data, yAxis, unit, grid, legend, noDataOption, timeZone]);\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 {showTooltip === true && (\n <Tooltip chartRef={chartRef} chartData={data} wrapLabels={true} pinTooltip={pinTooltip} unit={unit}></Tooltip>\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":["useMemo","useRef","useState","Box","use","LineChart","EChartsLineChart","GridComponent","DataZoomComponent","MarkAreaComponent","MarkLineComponent","MarkPointComponent","TitleComponent","ToolboxComponent","TooltipComponent","LegendComponent","CanvasRenderer","EChart","OPTIMIZED_MODE_SERIES_LIMIT","useChartsTheme","Tooltip","useTimeZone","enableDataZoom","getDateRange","getFormattedDate","getYAxes","restoreChart","height","data","yAxis","unit","grid","legend","onDataZoom","onDoubleClick","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","option","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","chartData","wrapLabels","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,SAAqBA,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAC9D,SAASC,GAAG,QAAQ,eAAe,CAAC;AAQpC,SAAqCC,GAAG,QAAQ,cAAc,CAAC;AAC/D,SAASC,SAAS,IAAIC,gBAAgB,QAAQ,gBAAgB,CAAC;AAC/D,SACEC,aAAa,EACbC,iBAAiB,EACjBC,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AAC;QACvB,CAAC;QACDqD,YAAY,EAAE,IAAM;YAClBvD,cAAc,CAAC,IAAI,CAAC,CAAC;YACrB,IAAIF,QAAQ,CAACuB,OAAO,KAAKd,SAAS,EAAE;gBAClCvB,cAAc,CAACc,QAAQ,CAACuB,OAAO,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QACDzB,aAAa,EAAE0B,mBAAmB;;YAEjCvB,WAAW,KAAK,IAAI,kBACnB,KAACjB,OAAO;gBAACgB,QAAQ,EAAEA,QAAQ;gBAAE0D,SAAS,EAAElE,IAAI;gBAAEmE,UAAU,EAAE,IAAI;gBAAExD,UAAU,EAAEA,UAAU;gBAAET,IAAI,EAAEA,IAAI;cAAY,AAC/G;0BAED,KAACb,MAAM;gBACLqE,EAAE,EAAE;oBACFU,KAAK,EAAE,MAAM;oBACbrE,MAAM,EAAE,MAAM;iBACf;gBACDoC,MAAM,EAAEA,MAAM;gBACdkC,KAAK,EAAE9D,WAAW,CAAC+D,YAAY;gBAC/BC,QAAQ,EAAEzD,YAAY;gBACtB0D,SAAS,EAAEhE,QAAQ;cACnB;;MACE,CACN;AACJ,CAAC"}
|
|
@@ -19,7 +19,7 @@ export declare function restoreChart(chart: EChartsInstance): void;
|
|
|
19
19
|
* Calculate date range, used as a fallback when xAxis time range not passed as prop
|
|
20
20
|
*/
|
|
21
21
|
export declare function getDateRange(data: number[]): number;
|
|
22
|
-
export declare function getFormattedDate(value: number, rangeMs: number): string;
|
|
22
|
+
export declare function getFormattedDate(value: number, rangeMs: number, timeZone?: string): string;
|
|
23
23
|
export declare function getYAxes(yAxis?: YAXisComponentOption, unit?: UnitOptions): ({
|
|
24
24
|
type: string;
|
|
25
25
|
boundaryGap: (string | number)[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/LineChart/utils.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAe,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/LineChart/utils.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAe,WAAW,EAAE,MAAM,UAAU,CAAC;AAGpD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,eAAe,QAapD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,QAKlD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,UAM1C;AAKD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,UAoBjF;AAKD,wBAAgB,QAAQ,CAAC,KAAK,CAAC,EAAE,oBAAoB,EAAE,IAAI,CAAC,EAAE,WAAW;;;;2BAMhD,MAAM;;0CAM9B"}
|
package/dist/LineChart/utils.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { merge } from 'lodash-es';
|
|
14
14
|
import { formatValue } from '../model';
|
|
15
|
+
import { dateFormatOptionsWithTimeZone } from '../utils';
|
|
15
16
|
/**
|
|
16
17
|
* Enable dataZoom without requring user to click toolbox icon
|
|
17
18
|
*/ export function enableDataZoom(chart) {
|
|
@@ -47,12 +48,12 @@ import { formatValue } from '../model';
|
|
|
47
48
|
}
|
|
48
49
|
/*
|
|
49
50
|
* Determines time granularity for axis labels, defaults to hh:mm
|
|
50
|
-
*/ export function getFormattedDate(value, rangeMs) {
|
|
51
|
-
const dateFormatOptions = {
|
|
51
|
+
*/ export function getFormattedDate(value, rangeMs, timeZone) {
|
|
52
|
+
const dateFormatOptions = dateFormatOptionsWithTimeZone({
|
|
52
53
|
hour: 'numeric',
|
|
53
54
|
minute: 'numeric',
|
|
54
55
|
hourCycle: 'h23'
|
|
55
|
-
};
|
|
56
|
+
}, timeZone);
|
|
56
57
|
const thirtyMinMs = 1800000;
|
|
57
58
|
const dayMs = 86400000;
|
|
58
59
|
if (rangeMs <= thirtyMinMs) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/LineChart/utils.ts"],"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 { merge } from 'lodash-es';\nimport type { YAXisComponentOption } from 'echarts';\nimport { ECharts as EChartsInstance } from 'echarts/core';\nimport { formatValue, UnitOptions } from '../model';\n\nexport interface ZoomEventData {\n start: number;\n end: number;\n startIndex: number;\n endIndex: number;\n}\n\n/**\n * Enable dataZoom without requring user to click toolbox icon\n */\nexport function enableDataZoom(chart: EChartsInstance) {\n const chartModel = chart['_model'];\n if (chartModel === undefined) return;\n if (chartModel.option.toolbox !== undefined && chartModel.option.toolbox.length > 0) {\n // check if hidden data zoom icon is unselected (if selected it would be 'emphasis' instead of 'normal')\n if (chartModel.option.toolbox[0].feature.dataZoom.iconStatus.zoom === 'normal') {\n chart.dispatchAction({\n type: 'takeGlobalCursor',\n key: 'dataZoomSelect',\n dataZoomSelectActive: true,\n });\n }\n }\n}\n\n/**\n * Restore chart to original state before zoom or other actions were dispatched\n */\nexport function restoreChart(chart: EChartsInstance) {\n // TODO: support incremental unzoom instead of restore to original state\n chart.dispatchAction({\n type: 'restore', // https://echarts.apache.org/en/api.html#events.restore\n });\n}\n\n/**\n * Calculate date range, used as a fallback when xAxis time range not passed as prop\n */\nexport function getDateRange(data: number[]) {\n const defaultRange = 3600000; // hour in ms\n if (data.length === 0) return defaultRange;\n const lastDatum = data[data.length - 1];\n if (data[0] === undefined || lastDatum === undefined) return defaultRange;\n return lastDatum - data[0];\n}\n\n/*\n * Determines time granularity for axis labels, defaults to hh:mm\n */\nexport function getFormattedDate(value: number, rangeMs: number) {\n const dateFormatOptions: Intl.DateTimeFormatOptions = {\n
|
|
1
|
+
{"version":3,"sources":["../../src/LineChart/utils.ts"],"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 { merge } from 'lodash-es';\nimport type { YAXisComponentOption } from 'echarts';\nimport { ECharts as EChartsInstance } from 'echarts/core';\nimport { formatValue, UnitOptions } from '../model';\nimport { dateFormatOptionsWithTimeZone } from '../utils';\n\nexport interface ZoomEventData {\n start: number;\n end: number;\n startIndex: number;\n endIndex: number;\n}\n\n/**\n * Enable dataZoom without requring user to click toolbox icon\n */\nexport function enableDataZoom(chart: EChartsInstance) {\n const chartModel = chart['_model'];\n if (chartModel === undefined) return;\n if (chartModel.option.toolbox !== undefined && chartModel.option.toolbox.length > 0) {\n // check if hidden data zoom icon is unselected (if selected it would be 'emphasis' instead of 'normal')\n if (chartModel.option.toolbox[0].feature.dataZoom.iconStatus.zoom === 'normal') {\n chart.dispatchAction({\n type: 'takeGlobalCursor',\n key: 'dataZoomSelect',\n dataZoomSelectActive: true,\n });\n }\n }\n}\n\n/**\n * Restore chart to original state before zoom or other actions were dispatched\n */\nexport function restoreChart(chart: EChartsInstance) {\n // TODO: support incremental unzoom instead of restore to original state\n chart.dispatchAction({\n type: 'restore', // https://echarts.apache.org/en/api.html#events.restore\n });\n}\n\n/**\n * Calculate date range, used as a fallback when xAxis time range not passed as prop\n */\nexport function getDateRange(data: number[]) {\n const defaultRange = 3600000; // hour in ms\n if (data.length === 0) return defaultRange;\n const lastDatum = data[data.length - 1];\n if (data[0] === undefined || lastDatum === undefined) return defaultRange;\n return lastDatum - data[0];\n}\n\n/*\n * Determines time granularity for axis labels, defaults to hh:mm\n */\nexport function getFormattedDate(value: number, rangeMs: number, timeZone?: string) {\n const dateFormatOptions: Intl.DateTimeFormatOptions = dateFormatOptionsWithTimeZone(\n {\n hour: 'numeric',\n minute: 'numeric',\n hourCycle: 'h23',\n },\n timeZone\n );\n const thirtyMinMs = 1800000;\n const dayMs = 86400000;\n if (rangeMs <= thirtyMinMs) {\n dateFormatOptions.second = 'numeric';\n } else if (rangeMs >= dayMs) {\n dateFormatOptions.month = 'numeric';\n dateFormatOptions.day = 'numeric';\n }\n const DATE_FORMAT = new Intl.DateTimeFormat(undefined, dateFormatOptions);\n // remove comma when month / day present\n return DATE_FORMAT.format(value).replace(/, /g, ' ');\n}\n\n/*\n * Populate yAxis properties, returns an Array since multiple y axes will be supported in the future\n */\nexport function getYAxes(yAxis?: YAXisComponentOption, unit?: UnitOptions) {\n // TODO: support alternate yAxis that shows on right side\n const Y_AXIS_DEFAULT = {\n type: 'value',\n boundaryGap: [0, '10%'],\n axisLabel: {\n formatter: (value: number) => {\n return formatValue(value, unit);\n },\n },\n };\n return [merge(Y_AXIS_DEFAULT, yAxis)];\n}\n"],"names":["merge","formatValue","dateFormatOptionsWithTimeZone","enableDataZoom","chart","chartModel","undefined","option","toolbox","length","feature","dataZoom","iconStatus","zoom","dispatchAction","type","key","dataZoomSelectActive","restoreChart","getDateRange","data","defaultRange","lastDatum","getFormattedDate","value","rangeMs","timeZone","dateFormatOptions","hour","minute","hourCycle","thirtyMinMs","dayMs","second","month","day","DATE_FORMAT","Intl","DateTimeFormat","format","replace","getYAxes","yAxis","unit","Y_AXIS_DEFAULT","boundaryGap","axisLabel","formatter"],"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,KAAK,QAAQ,WAAW,CAAC;AAGlC,SAASC,WAAW,QAAqB,UAAU,CAAC;AACpD,SAASC,6BAA6B,QAAQ,UAAU,CAAC;AASzD;;CAEC,GACD,OAAO,SAASC,cAAc,CAACC,KAAsB,EAAE;IACrD,MAAMC,UAAU,GAAGD,KAAK,CAAC,QAAQ,CAAC,AAAC;IACnC,IAAIC,UAAU,KAAKC,SAAS,EAAE,OAAO;IACrC,IAAID,UAAU,CAACE,MAAM,CAACC,OAAO,KAAKF,SAAS,IAAID,UAAU,CAACE,MAAM,CAACC,OAAO,CAACC,MAAM,GAAG,CAAC,EAAE;QACnF,wGAAwG;QACxG,IAAIJ,UAAU,CAACE,MAAM,CAACC,OAAO,CAAC,CAAC,CAAC,CAACE,OAAO,CAACC,QAAQ,CAACC,UAAU,CAACC,IAAI,KAAK,QAAQ,EAAE;YAC9ET,KAAK,CAACU,cAAc,CAAC;gBACnBC,IAAI,EAAE,kBAAkB;gBACxBC,GAAG,EAAE,gBAAgB;gBACrBC,oBAAoB,EAAE,IAAI;aAC3B,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,YAAY,CAACd,KAAsB,EAAE;IACnD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gB,OAAO,QAAQ,GAAG,CAAC,CAAC;AACvD,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,QAAQ,CAACC,KAA4B,EAAEC,IAAkB,EAAE;IACzE,yDAAyD;IACzD,MAAMC,cAAc,GAAG;QACrB7B,IAAI,EAAE,OAAO;QACb8B,WAAW,EAAE;AAAC,aAAC;YAAE,KAAK;SAAC;QACvBC,SAAS,EAAE;YACTC,SAAS,EAAE,CAACvB,KAAa,GAAK;gBAC5B,OAAOvB,WAAW,CAACuB,KAAK,EAAEmB,IAAI,CAAC,CAAC;YAClC,CAAC;SACF;KACF,AAAC;IACF,OAAO;QAAC3C,KAAK,CAAC4C,cAAc,EAAEF,KAAK,CAAC;KAAC,CAAC;AACxC,CAAC"}
|
|
@@ -11,19 +11,25 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import React from 'react';
|
|
15
14
|
import { render, screen } from '@testing-library/react';
|
|
16
15
|
import { ChartsThemeProvider } from '../context/ChartsThemeProvider';
|
|
17
16
|
import { testChartsTheme } from '../test-utils';
|
|
18
17
|
import { StatChart } from './StatChart';
|
|
19
18
|
describe('StatChart', ()=>{
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
const renderChart = (unit)=>{
|
|
20
|
+
const contentDimensions = {
|
|
21
|
+
width: 200,
|
|
22
|
+
height: 200
|
|
23
|
+
};
|
|
24
|
+
render(/*#__PURE__*/ _jsx(ChartsThemeProvider, {
|
|
25
|
+
chartsTheme: testChartsTheme,
|
|
26
|
+
children: /*#__PURE__*/ _jsx(StatChart, {
|
|
27
|
+
width: contentDimensions.width,
|
|
28
|
+
height: contentDimensions.height,
|
|
29
|
+
data: mockStatData,
|
|
30
|
+
unit: unit
|
|
31
|
+
})
|
|
32
|
+
}));
|
|
27
33
|
};
|
|
28
34
|
const mockStatData = {
|
|
29
35
|
calculatedValue: 7.72931659687181,
|
|
@@ -54,19 +60,34 @@ describe('StatChart', ()=>{
|
|
|
54
60
|
]
|
|
55
61
|
}
|
|
56
62
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
it('render default options (no sparkline)', ()=>{
|
|
64
|
+
const unit = {
|
|
65
|
+
kind: 'Decimal',
|
|
66
|
+
decimal_places: 2
|
|
67
|
+
};
|
|
68
|
+
renderChart(unit);
|
|
69
|
+
expect(screen.getByText('7.73')).toBeInTheDocument();
|
|
70
|
+
});
|
|
71
|
+
it('show value with bytes unit formatting', ()=>{
|
|
72
|
+
const unit = {
|
|
73
|
+
kind: 'Bytes'
|
|
74
|
+
};
|
|
75
|
+
renderChart(unit);
|
|
76
|
+
expect(screen.getByText('7.73 bytes')).toBeInTheDocument();
|
|
77
|
+
});
|
|
78
|
+
it('show value with seconds time unit formatting', ()=>{
|
|
79
|
+
const unit = {
|
|
80
|
+
kind: 'Seconds'
|
|
81
|
+
};
|
|
82
|
+
renderChart(unit);
|
|
83
|
+
expect(screen.getByText('7.73 seconds')).toBeInTheDocument();
|
|
84
|
+
});
|
|
85
|
+
it('show value with months time unit formatting', ()=>{
|
|
86
|
+
const unit = {
|
|
87
|
+
kind: 'Months'
|
|
88
|
+
};
|
|
89
|
+
renderChart(unit);
|
|
90
|
+
expect(screen.getByText('7.73 months')).toBeInTheDocument();
|
|
70
91
|
});
|
|
71
92
|
});
|
|
72
93
|
|