@perses-dev/components 0.34.0 → 0.35.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/Drawer/Drawer.js +1 -1
- package/dist/Drawer/Drawer.js.map +1 -1
- package/dist/GaugeChart/GaugeChart.d.ts +1 -1
- package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
- package/dist/GaugeChart/GaugeChart.js +6 -3
- package/dist/GaugeChart/GaugeChart.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
- package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts +36 -0
- package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts.map +1 -0
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js +65 -0
- package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -0
- package/dist/SettingsAutocomplete/index.d.ts +2 -0
- package/dist/SettingsAutocomplete/index.d.ts.map +1 -0
- package/dist/SettingsAutocomplete/index.js +15 -0
- package/dist/SettingsAutocomplete/index.js.map +1 -0
- package/dist/StatChart/StatChart.d.ts +2 -1
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +73 -20
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/StatChart/calculateFontSize.d.ts +14 -0
- package/dist/StatChart/calculateFontSize.d.ts.map +1 -0
- package/dist/StatChart/calculateFontSize.js +47 -0
- package/dist/StatChart/calculateFontSize.js.map +1 -0
- package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
- package/dist/UnitSelector/UnitSelector.js +10 -22
- package/dist/UnitSelector/UnitSelector.js.map +1 -1
- package/dist/YAxisLabel.js +1 -1
- package/dist/YAxisLabel.js.map +1 -1
- package/dist/cjs/Drawer/Drawer.js +1 -1
- package/dist/cjs/GaugeChart/GaugeChart.js +6 -3
- package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +1 -1
- package/dist/cjs/SettingsAutocomplete/SettingsAutocomplete.js +66 -0
- package/dist/cjs/SettingsAutocomplete/index.js +28 -0
- package/dist/cjs/StatChart/StatChart.js +72 -19
- package/dist/cjs/StatChart/calculateFontSize.js +51 -0
- package/dist/cjs/UnitSelector/UnitSelector.js +9 -21
- package/dist/cjs/YAxisLabel.js +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model/theme.d.ts +3 -2
- package/dist/model/theme.d.ts.map +1 -1
- package/dist/model/theme.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { useChartsTheme } from '../context/ChartsThemeProvider';
|
|
14
|
+
let canvasContext;
|
|
15
|
+
function getGlobalCanvasContext() {
|
|
16
|
+
if (!canvasContext) {
|
|
17
|
+
canvasContext = document.createElement('canvas').getContext('2d');
|
|
18
|
+
if (canvasContext === null) {
|
|
19
|
+
throw new Error('Canvas context is null.');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return canvasContext;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Find the optimal font size given available space
|
|
26
|
+
*/ export function useOptimalFontSize({ text , fontWeight , width , height , lineHeight , maxSize }) {
|
|
27
|
+
const ctx = getGlobalCanvasContext();
|
|
28
|
+
const chartsTheme = useChartsTheme();
|
|
29
|
+
const textStyle = chartsTheme.echartsTheme.textStyle;
|
|
30
|
+
var ref;
|
|
31
|
+
const fontSize = (ref = Number(textStyle === null || textStyle === void 0 ? void 0 : textStyle.fontSize)) !== null && ref !== void 0 ? ref : 12;
|
|
32
|
+
var ref1;
|
|
33
|
+
const fontFamily = (ref1 = textStyle === null || textStyle === void 0 ? void 0 : textStyle.fontFamily) !== null && ref1 !== void 0 ? ref1 : 'Lato';
|
|
34
|
+
// set the font on the canvas context
|
|
35
|
+
const fontStyle = `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
36
|
+
ctx.font = fontStyle;
|
|
37
|
+
// measure the width of the text with the given font style
|
|
38
|
+
const textMetrics = ctx.measureText(text);
|
|
39
|
+
// check how much bigger we can make the font while staying within the width and height
|
|
40
|
+
const fontSizeBasedOnWidth = width / textMetrics.width * fontSize;
|
|
41
|
+
const fontSizeBasedOnHeight = height / lineHeight;
|
|
42
|
+
// return the smaller font size
|
|
43
|
+
const finalFontSize = Math.min(fontSizeBasedOnHeight, fontSizeBasedOnWidth);
|
|
44
|
+
return maxSize ? Math.min(finalFontSize, maxSize) : finalFontSize;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=calculateFontSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/StatChart/calculateFontSize.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\n\ninterface CalculateFontSize {\n text: string;\n fontWeight: number;\n width: number;\n height: number;\n lineHeight: number;\n maxSize?: number;\n}\n\nlet canvasContext: CanvasRenderingContext2D | null;\n\nfunction getGlobalCanvasContext() {\n if (!canvasContext) {\n canvasContext = document.createElement('canvas').getContext('2d');\n if (canvasContext === null) {\n throw new Error('Canvas context is null.');\n }\n }\n return canvasContext;\n}\n\n/**\n * Find the optimal font size given available space\n */\nexport function useOptimalFontSize({ text, fontWeight, width, height, lineHeight, maxSize }: CalculateFontSize) {\n const ctx = getGlobalCanvasContext();\n const chartsTheme = useChartsTheme();\n\n const textStyle = chartsTheme.echartsTheme.textStyle;\n const fontSize = Number(textStyle?.fontSize) ?? 12;\n const fontFamily = textStyle?.fontFamily ?? 'Lato';\n\n // set the font on the canvas context\n const fontStyle = `${fontWeight} ${fontSize}px ${fontFamily}`;\n ctx.font = fontStyle;\n // measure the width of the text with the given font style\n const textMetrics: TextMetrics = ctx.measureText(text);\n\n // check how much bigger we can make the font while staying within the width and height\n const fontSizeBasedOnWidth = (width / textMetrics.width) * fontSize;\n const fontSizeBasedOnHeight = height / lineHeight;\n\n // return the smaller font size\n const finalFontSize = Math.min(fontSizeBasedOnHeight, fontSizeBasedOnWidth);\n return maxSize ? Math.min(finalFontSize, maxSize) : finalFontSize;\n}\n"],"names":["useChartsTheme","canvasContext","getGlobalCanvasContext","document","createElement","getContext","Error","useOptimalFontSize","text","fontWeight","width","height","lineHeight","maxSize","ctx","chartsTheme","textStyle","echartsTheme","Number","fontSize","fontFamily","fontStyle","font","textMetrics","measureText","fontSizeBasedOnWidth","fontSizeBasedOnHeight","finalFontSize","Math","min"],"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,cAAc,QAAQ,gCAAgC,CAAC;AAWhE,IAAIC,aAAa,AAAiC,AAAC;AAEnD,SAASC,sBAAsB,GAAG;IAChC,IAAI,CAACD,aAAa,EAAE;QAClBA,aAAa,GAAGE,QAAQ,CAACC,aAAa,CAAC,QAAQ,CAAC,CAACC,UAAU,CAAC,IAAI,CAAC,CAAC;QAClE,IAAIJ,aAAa,KAAK,IAAI,EAAE;YAC1B,MAAM,IAAIK,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IACD,OAAOL,aAAa,CAAC;AACvB,CAAC;AAED;;CAEC,GACD,OAAO,SAASM,kBAAkB,CAAC,EAAEC,IAAI,CAAA,EAAEC,UAAU,CAAA,EAAEC,KAAK,CAAA,EAAEC,MAAM,CAAA,EAAEC,UAAU,CAAA,EAAEC,OAAO,CAAA,EAAqB,EAAE;IAC9G,MAAMC,GAAG,GAAGZ,sBAAsB,EAAE,AAAC;IACrC,MAAMa,WAAW,GAAGf,cAAc,EAAE,AAAC;IAErC,MAAMgB,SAAS,GAAGD,WAAW,CAACE,YAAY,CAACD,SAAS,AAAC;QACpCE,GAA2B;IAA5C,MAAMC,QAAQ,GAAGD,CAAAA,GAA2B,GAA3BA,MAAM,CAACF,SAAS,aAATA,SAAS,WAAU,GAAnBA,KAAAA,CAAmB,GAAnBA,SAAS,CAAEG,QAAQ,CAAC,cAA3BD,GAA2B,cAA3BA,GAA2B,GAAI,EAAE,AAAC;QAChCF,IAAqB;IAAxC,MAAMI,UAAU,GAAGJ,CAAAA,IAAqB,GAArBA,SAAS,aAATA,SAAS,WAAY,GAArBA,KAAAA,CAAqB,GAArBA,SAAS,CAAEI,UAAU,cAArBJ,IAAqB,cAArBA,IAAqB,GAAI,MAAM,AAAC;IAEnD,qCAAqC;IACrC,MAAMK,SAAS,GAAG,CAAC,EAAEZ,UAAU,CAAC,CAAC,EAAEU,QAAQ,CAAC,GAAG,EAAEC,UAAU,CAAC,CAAC,AAAC;IAC9DN,GAAG,CAACQ,IAAI,GAAGD,SAAS,CAAC;IACrB,0DAA0D;IAC1D,MAAME,WAAW,GAAgBT,GAAG,CAACU,WAAW,CAAChB,IAAI,CAAC,AAAC;IAEvD,uFAAuF;IACvF,MAAMiB,oBAAoB,GAAG,AAACf,KAAK,GAAGa,WAAW,CAACb,KAAK,GAAIS,QAAQ,AAAC;IACpE,MAAMO,qBAAqB,GAAGf,MAAM,GAAGC,UAAU,AAAC;IAElD,+BAA+B;IAC/B,MAAMe,aAAa,GAAGC,IAAI,CAACC,GAAG,CAACH,qBAAqB,EAAED,oBAAoB,CAAC,AAAC;IAC5E,OAAOZ,OAAO,GAAGe,IAAI,CAACC,GAAG,CAACF,aAAa,EAAEd,OAAO,CAAC,GAAGc,aAAa,CAAC;AACpE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnitSelector.d.ts","sourceRoot":"","sources":["../../src/UnitSelector/UnitSelector.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,WAAW,EAA0E,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"UnitSelector.d.ts","sourceRoot":"","sources":["../../src/UnitSelector/UnitSelector.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,WAAW,EAA0E,MAAM,UAAU,CAAC;AAK/G,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;CACvC;AA0BD,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,iBAAiB,eAqElE"}
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
-
import {
|
|
14
|
+
import { Switch } from '@mui/material';
|
|
15
15
|
import { UNIT_CONFIG, isUnitWithDecimalPlaces, isUnitWithAbbreviate } from '../model';
|
|
16
16
|
import { shouldAbbreviate } from '../model/units/utils';
|
|
17
17
|
import { OptionsEditorControl } from '../OptionsEditorLayout';
|
|
18
|
+
import { SettingsAutocomplete } from '../SettingsAutocomplete';
|
|
18
19
|
const KIND_OPTIONS = Object.entries(UNIT_CONFIG).map(([id, config])=>{
|
|
19
20
|
return {
|
|
20
21
|
id: id,
|
|
@@ -23,26 +24,32 @@ const KIND_OPTIONS = Object.entries(UNIT_CONFIG).map(([id, config])=>{
|
|
|
23
24
|
}).filter((config)=>!config.disableSelectorOption);
|
|
24
25
|
const DECIMAL_PLACES_OPTIONS = [
|
|
25
26
|
{
|
|
27
|
+
id: 'default',
|
|
26
28
|
label: 'Default',
|
|
27
29
|
decimal_places: undefined
|
|
28
30
|
},
|
|
29
31
|
{
|
|
32
|
+
id: '0',
|
|
30
33
|
label: '0',
|
|
31
34
|
decimal_places: 0
|
|
32
35
|
},
|
|
33
36
|
{
|
|
37
|
+
id: '1',
|
|
34
38
|
label: '1',
|
|
35
39
|
decimal_places: 1
|
|
36
40
|
},
|
|
37
41
|
{
|
|
42
|
+
id: '2',
|
|
38
43
|
label: '2',
|
|
39
44
|
decimal_places: 2
|
|
40
45
|
},
|
|
41
46
|
{
|
|
47
|
+
id: '3',
|
|
42
48
|
label: '3',
|
|
43
49
|
decimal_places: 3
|
|
44
50
|
},
|
|
45
51
|
{
|
|
52
|
+
id: '4',
|
|
46
53
|
label: '4',
|
|
47
54
|
decimal_places: 4
|
|
48
55
|
}
|
|
@@ -87,42 +94,23 @@ export function UnitSelector({ value , onChange }) {
|
|
|
87
94
|
}),
|
|
88
95
|
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
89
96
|
label: "Unit",
|
|
90
|
-
control: /*#__PURE__*/ _jsx(
|
|
97
|
+
control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
|
|
91
98
|
value: {
|
|
92
99
|
id: value.kind,
|
|
93
100
|
...kindConfig
|
|
94
101
|
},
|
|
95
102
|
options: KIND_OPTIONS,
|
|
96
|
-
isOptionEqualToValue: (option, value)=>option.id === value.id,
|
|
97
103
|
groupBy: (option)=>option.group,
|
|
98
|
-
renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
|
|
99
|
-
...params
|
|
100
|
-
}),
|
|
101
|
-
renderOption: (renderOptsProps, option)=>{
|
|
102
|
-
// Custom option needed to get some increased left padding to make
|
|
103
|
-
// the items more distinct from the group label.
|
|
104
|
-
return /*#__PURE__*/ _jsx("li", {
|
|
105
|
-
...renderOptsProps,
|
|
106
|
-
children: /*#__PURE__*/ _jsx(Box, {
|
|
107
|
-
paddingLeft: (theme)=>theme.spacing(1),
|
|
108
|
-
children: option.label
|
|
109
|
-
})
|
|
110
|
-
});
|
|
111
|
-
},
|
|
112
104
|
onChange: handleKindChange,
|
|
113
105
|
disableClearable: true
|
|
114
106
|
})
|
|
115
107
|
}),
|
|
116
108
|
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
117
109
|
label: "Decimals",
|
|
118
|
-
control: /*#__PURE__*/ _jsx(
|
|
110
|
+
control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
|
|
119
111
|
value: getOptionByDecimalPlaces(value.decimal_places),
|
|
120
112
|
options: DECIMAL_PLACES_OPTIONS,
|
|
121
113
|
getOptionLabel: (o)=>o.label,
|
|
122
|
-
isOptionEqualToValue: (option, value)=>option.label === value.label,
|
|
123
|
-
renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
|
|
124
|
-
...params
|
|
125
|
-
}),
|
|
126
114
|
onChange: handleDecimalPlacesChange,
|
|
127
115
|
disabled: !hasDecimalPlaces,
|
|
128
116
|
disableClearable: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/UnitSelector/UnitSelector.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/UnitSelector/UnitSelector.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport { Switch, SwitchProps } from '@mui/material';\nimport { UnitOptions, UNIT_CONFIG, UnitConfig, isUnitWithDecimalPlaces, isUnitWithAbbreviate } from '../model';\nimport { shouldAbbreviate } from '../model/units/utils';\nimport { OptionsEditorControl } from '../OptionsEditorLayout';\nimport { SettingsAutocomplete } from '../SettingsAutocomplete';\n\nexport interface UnitSelectorProps {\n value: UnitOptions;\n onChange: (unit: UnitOptions) => void;\n}\n\ntype AutocompleteKindOption = UnitConfig & { id: UnitOptions['kind'] };\n\nconst KIND_OPTIONS: AutocompleteKindOption[] = Object.entries(UNIT_CONFIG)\n .map(([id, config]) => {\n return {\n id: id as UnitOptions['kind'],\n ...config,\n };\n })\n .filter((config) => !config.disableSelectorOption);\n\nconst DECIMAL_PLACES_OPTIONS = [\n { id: 'default', label: 'Default', decimal_places: undefined },\n { id: '0', label: '0', decimal_places: 0 },\n { id: '1', label: '1', decimal_places: 1 },\n { id: '2', label: '2', decimal_places: 2 },\n { id: '3', label: '3', decimal_places: 3 },\n { id: '4', label: '4', decimal_places: 4 },\n];\n\nfunction getOptionByDecimalPlaces(decimal_places?: number) {\n return DECIMAL_PLACES_OPTIONS.find((o) => o.decimal_places === decimal_places);\n}\n\nexport function UnitSelector({ value, onChange }: UnitSelectorProps) {\n const hasDecimalPlaces = isUnitWithDecimalPlaces(value);\n const hasAbbreviate = isUnitWithAbbreviate(value);\n\n const handleKindChange = (_: unknown, newValue: AutocompleteKindOption) => {\n onChange({\n kind: newValue.id,\n });\n };\n\n const handleDecimalPlacesChange = (_: unknown, { decimal_places }: { decimal_places: number | undefined }) => {\n if (hasDecimalPlaces) {\n onChange({\n ...value,\n decimal_places: decimal_places,\n });\n }\n };\n\n const handleAbbreviateChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n if (hasAbbreviate) {\n onChange({\n ...value,\n abbreviate: checked,\n });\n }\n };\n\n const kindConfig = UNIT_CONFIG[value.kind];\n\n return (\n <>\n <OptionsEditorControl\n label=\"Abbreviate\"\n control={\n <Switch\n checked={hasAbbreviate ? shouldAbbreviate(value.abbreviate) : false}\n onChange={handleAbbreviateChange}\n disabled={!hasAbbreviate}\n />\n }\n />\n <OptionsEditorControl\n label=\"Unit\"\n control={\n <SettingsAutocomplete\n value={{ id: value.kind, ...kindConfig }}\n options={KIND_OPTIONS}\n groupBy={(option) => option.group}\n onChange={handleKindChange}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Decimals\"\n control={\n <SettingsAutocomplete\n value={getOptionByDecimalPlaces(value.decimal_places)}\n options={DECIMAL_PLACES_OPTIONS}\n getOptionLabel={(o) => o.label}\n onChange={handleDecimalPlacesChange}\n disabled={!hasDecimalPlaces}\n disableClearable\n />\n }\n />\n </>\n );\n}\n"],"names":["Switch","UNIT_CONFIG","isUnitWithDecimalPlaces","isUnitWithAbbreviate","shouldAbbreviate","OptionsEditorControl","SettingsAutocomplete","KIND_OPTIONS","Object","entries","map","id","config","filter","disableSelectorOption","DECIMAL_PLACES_OPTIONS","label","decimal_places","undefined","getOptionByDecimalPlaces","find","o","UnitSelector","value","onChange","hasDecimalPlaces","hasAbbreviate","handleKindChange","_","newValue","kind","handleDecimalPlacesChange","handleAbbreviateChange","checked","abbreviate","kindConfig","control","disabled","options","groupBy","option","group","disableClearable","getOptionLabel"],"mappings":"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"}
|
package/dist/YAxisLabel.js
CHANGED
|
@@ -18,7 +18,7 @@ export function YAxisLabel({ name , height }) {
|
|
|
18
18
|
display: 'inline-block',
|
|
19
19
|
maxWidth: height,
|
|
20
20
|
position: 'absolute',
|
|
21
|
-
top:
|
|
21
|
+
top: `calc(${height}px / 2)`,
|
|
22
22
|
transform: 'translateX(-50%) rotate(-90deg)',
|
|
23
23
|
transformOrigin: 'top',
|
|
24
24
|
textAlign: 'center',
|
package/dist/YAxisLabel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/YAxisLabel.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, Typography } from '@mui/material';\n\ninterface YAxisLabelProps {\n name: string;\n height: number;\n}\n\nexport function YAxisLabel({ name, height }: YAxisLabelProps) {\n return (\n <Box\n sx={{\n display: 'inline-block',\n maxWidth: height, // allows rotated text to truncate instead of causing overlap\n position: 'absolute',\n top:
|
|
1
|
+
{"version":3,"sources":["../src/YAxisLabel.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, Typography } from '@mui/material';\n\ninterface YAxisLabelProps {\n name: string;\n height: number;\n}\n\nexport function YAxisLabel({ name, height }: YAxisLabelProps) {\n return (\n <Box\n sx={{\n display: 'inline-block',\n maxWidth: height, // allows rotated text to truncate instead of causing overlap\n position: 'absolute',\n top: `calc(${height}px / 2)`,\n transform: 'translateX(-50%) rotate(-90deg)',\n transformOrigin: 'top',\n textAlign: 'center',\n zIndex: 1,\n }}\n >\n <Typography\n variant=\"body1\"\n aria-label=\"y axis label\"\n sx={{\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }}\n >\n {name}\n </Typography>\n </Box>\n );\n}\n"],"names":["Box","Typography","YAxisLabel","name","height","sx","display","maxWidth","position","top","transform","transformOrigin","textAlign","zIndex","variant","aria-label","whiteSpace","overflow","textOverflow"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAOhD,OAAO,SAASC,UAAU,CAAC,EAAEC,IAAI,CAAA,EAAEC,MAAM,CAAA,EAAmB,EAAE;IAC5D,qBACE,KAACJ,GAAG;QACFK,EAAE,EAAE;YACFC,OAAO,EAAE,cAAc;YACvBC,QAAQ,EAAEH,MAAM;YAChBI,QAAQ,EAAE,UAAU;YACpBC,GAAG,EAAE,CAAC,KAAK,EAAEL,MAAM,CAAC,OAAO,CAAC;YAC5BM,SAAS,EAAE,iCAAiC;YAC5CC,eAAe,EAAE,KAAK;YACtBC,SAAS,EAAE,QAAQ;YACnBC,MAAM,EAAE,CAAC;SACV;kBAED,cAAA,KAACZ,UAAU;YACTa,OAAO,EAAC,OAAO;YACfC,YAAU,EAAC,cAAc;YACzBV,EAAE,EAAE;gBACFW,UAAU,EAAE,QAAQ;gBACpBC,QAAQ,EAAE,QAAQ;gBAClBC,YAAY,EAAE,UAAU;aACzB;sBAEAf,IAAI;UACM;MACT,CACN;AACJ,CAAC"}
|
|
@@ -21,7 +21,7 @@ Object.defineProperty(exports, "Drawer", {
|
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
22
|
const _material = require("@mui/material");
|
|
23
23
|
const _utils = require("../utils");
|
|
24
|
-
const DRAWER_DEFAULT_WIDTH =
|
|
24
|
+
const DRAWER_DEFAULT_WIDTH = 1080;
|
|
25
25
|
const Drawer = ({ anchor ='right' , isOpen , onClose , PaperProps , children , ...rest })=>{
|
|
26
26
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Drawer, {
|
|
27
27
|
...rest,
|
|
@@ -49,7 +49,7 @@ function GaugeChart(props) {
|
|
|
49
49
|
// useDeepMemo ensures value size util does not rerun everytime you hover on the chart
|
|
50
50
|
const option = (0, _core.useDeepMemo)(()=>{
|
|
51
51
|
var ref;
|
|
52
|
-
if (data.value === undefined
|
|
52
|
+
if (data.value === undefined) return chartsTheme.noDataOption;
|
|
53
53
|
// adjusts fontSize depending on number of characters
|
|
54
54
|
const valueSizeClamp = getResponsiveValueSize(data.value, unit, width, height);
|
|
55
55
|
var ref1;
|
|
@@ -167,7 +167,10 @@ function GaugeChart(props) {
|
|
|
167
167
|
],
|
|
168
168
|
color: 'inherit',
|
|
169
169
|
fontSize: valueSizeClamp,
|
|
170
|
-
formatter:
|
|
170
|
+
formatter: data.value === null ? // at this level because the `formatter` function argument is `NaN`
|
|
171
|
+
// when the value is `null`, making it difficult to differentiate
|
|
172
|
+
// `null` from a true `NaN` case.
|
|
173
|
+
()=>'null' : (value)=>{
|
|
171
174
|
return (0, _units.formatValue)(value, unit);
|
|
172
175
|
}
|
|
173
176
|
},
|
|
@@ -216,7 +219,7 @@ function getResponsiveValueSize(value, unit, width, height) {
|
|
|
216
219
|
const MIN_SIZE = 3;
|
|
217
220
|
const MAX_SIZE = 24;
|
|
218
221
|
const SIZE_MULTIPLIER = 0.7;
|
|
219
|
-
const formattedValue = (0, _units.formatValue)(value, unit)
|
|
222
|
+
const formattedValue = typeof value === 'number' ? (0, _units.formatValue)(value, unit) : `${value}`;
|
|
220
223
|
var _length;
|
|
221
224
|
const valueCharacters = (_length = formattedValue.length) !== null && _length !== void 0 ? _length : 2;
|
|
222
225
|
const valueSize = Math.min(width, height) / valueCharacters * SIZE_MULTIPLIER;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "SettingsAutocomplete", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>SettingsAutocomplete
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
function SettingsAutocomplete({ options , renderInput =(params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
24
|
+
...params
|
|
25
|
+
}) , ...otherProps }) {
|
|
26
|
+
const getOptionLabel = (option)=>{
|
|
27
|
+
var _label;
|
|
28
|
+
return (_label = option.label) !== null && _label !== void 0 ? _label : option.id;
|
|
29
|
+
};
|
|
30
|
+
// Note: this component currently is not virtualized because it is specific
|
|
31
|
+
// to being used for settings, which generally have a pretty small list of
|
|
32
|
+
// options. If this changes to include values with many options, virtualization
|
|
33
|
+
// should be added using react-virtuoso.
|
|
34
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
|
|
35
|
+
isOptionEqualToValue: (option, value)=>option.id === value.id,
|
|
36
|
+
getOptionDisabled: (option)=>!!option.disabled,
|
|
37
|
+
getOptionLabel: getOptionLabel,
|
|
38
|
+
options: options,
|
|
39
|
+
renderInput: renderInput,
|
|
40
|
+
renderOption: (props, option)=>{
|
|
41
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)("li", {
|
|
42
|
+
...props,
|
|
43
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
|
|
44
|
+
children: [
|
|
45
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
|
|
46
|
+
variant: "body1",
|
|
47
|
+
component: "div",
|
|
48
|
+
children: getOptionLabel(option)
|
|
49
|
+
}),
|
|
50
|
+
option.description && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
|
|
51
|
+
variant: "body2",
|
|
52
|
+
component: "div",
|
|
53
|
+
color: (theme)=>theme.palette.text.secondary,
|
|
54
|
+
children: option.description
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
filterOptions: (0, _material.createFilterOptions)({
|
|
61
|
+
// Include the label and the description in search.
|
|
62
|
+
stringify: (option)=>`${getOptionLabel(option)} ${option.description || ''}`
|
|
63
|
+
}),
|
|
64
|
+
...otherProps
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
_exportStar(require("./SettingsAutocomplete"), 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
|
+
}
|
|
@@ -29,6 +29,7 @@ const _renderers = require("echarts/renderers");
|
|
|
29
29
|
const _chartsThemeProvider = require("../context/ChartsThemeProvider");
|
|
30
30
|
const _units = require("../model/units");
|
|
31
31
|
const _echart = require("../EChart");
|
|
32
|
+
const _calculateFontSize = require("./calculateFontSize");
|
|
32
33
|
function _interopRequireDefault(obj) {
|
|
33
34
|
return obj && obj.__esModule ? obj : {
|
|
34
35
|
default: obj
|
|
@@ -42,12 +43,48 @@ function _interopRequireDefault(obj) {
|
|
|
42
43
|
_components.TooltipComponent,
|
|
43
44
|
_renderers.CanvasRenderer
|
|
44
45
|
]);
|
|
45
|
-
const
|
|
46
|
-
const
|
|
46
|
+
const LINE_HEIGHT = 1.2;
|
|
47
|
+
const SERIES_NAME_MAX_FONT_SIZE = 30;
|
|
48
|
+
const SERIES_NAME_FONT_WEIGHT = 400;
|
|
49
|
+
const VALUE_FONT_WEIGHT = 700;
|
|
47
50
|
function StatChart(props) {
|
|
48
|
-
|
|
51
|
+
var ref, ref1;
|
|
52
|
+
const { width , height , data , unit , color , sparkline , showSeriesName } = props;
|
|
49
53
|
const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
|
|
50
|
-
|
|
54
|
+
let formattedValue = '';
|
|
55
|
+
if (data.calculatedValue === null) {
|
|
56
|
+
formattedValue = 'null';
|
|
57
|
+
} else if (typeof data.calculatedValue === 'number') {
|
|
58
|
+
formattedValue = (0, _units.formatValue)(data.calculatedValue, unit);
|
|
59
|
+
}
|
|
60
|
+
const containerPadding = chartsTheme.container.padding.default;
|
|
61
|
+
var ref2;
|
|
62
|
+
// calculate series name font size and height
|
|
63
|
+
let seriesNameFontSize = (0, _calculateFontSize.useOptimalFontSize)({
|
|
64
|
+
text: (ref2 = data === null || data === void 0 ? void 0 : (ref = data.seriesData) === null || ref === void 0 ? void 0 : ref.name) !== null && ref2 !== void 0 ? ref2 : '',
|
|
65
|
+
fontWeight: SERIES_NAME_FONT_WEIGHT,
|
|
66
|
+
width,
|
|
67
|
+
height: height * 0.125,
|
|
68
|
+
lineHeight: LINE_HEIGHT,
|
|
69
|
+
maxSize: SERIES_NAME_MAX_FONT_SIZE
|
|
70
|
+
});
|
|
71
|
+
const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;
|
|
72
|
+
// calculate value font size and height
|
|
73
|
+
const availableWidth = width - containerPadding * 2;
|
|
74
|
+
const availableHeight = height - seriesNameHeight;
|
|
75
|
+
const valueFontSize = (0, _calculateFontSize.useOptimalFontSize)({
|
|
76
|
+
text: formattedValue,
|
|
77
|
+
fontWeight: VALUE_FONT_WEIGHT,
|
|
78
|
+
// without sparkline, use only 50% of the available width so it looks better for multiseries
|
|
79
|
+
width: sparkline ? availableWidth : availableWidth * 0.5,
|
|
80
|
+
// with sparkline, use only 25% of available height to leave room for chart
|
|
81
|
+
// without sparkline, value should take up 90% of available space
|
|
82
|
+
height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,
|
|
83
|
+
lineHeight: LINE_HEIGHT
|
|
84
|
+
});
|
|
85
|
+
const valueFontHeight = valueFontSize * LINE_HEIGHT;
|
|
86
|
+
// make sure the series name font size is slightly smaller than value font size
|
|
87
|
+
seriesNameFontSize = Math.min(valueFontSize * 0.7, seriesNameFontSize);
|
|
51
88
|
const option = (0, _react.useMemo)(()=>{
|
|
52
89
|
if (data.seriesData === undefined) return chartsTheme.noDataOption;
|
|
53
90
|
const series = data.seriesData;
|
|
@@ -55,9 +92,8 @@ function StatChart(props) {
|
|
|
55
92
|
if (sparkline !== undefined) {
|
|
56
93
|
const lineSeries = {
|
|
57
94
|
type: 'line',
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
],
|
|
95
|
+
name: series.name,
|
|
96
|
+
data: series.values,
|
|
61
97
|
zlevel: 1,
|
|
62
98
|
symbol: 'none',
|
|
63
99
|
animation: false,
|
|
@@ -105,11 +141,6 @@ function StatChart(props) {
|
|
|
105
141
|
chartsTheme,
|
|
106
142
|
sparkline
|
|
107
143
|
]);
|
|
108
|
-
const isLargePanel = width > 250 && height > 180;
|
|
109
|
-
// adjusts fontSize depending on number of characters, clamp also used in fontSize attribute
|
|
110
|
-
const charactersAdjust = formattedValue.length;
|
|
111
|
-
const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
|
|
112
|
-
const containerPadding = `${chartsTheme.container.padding.default}px`;
|
|
113
144
|
const textAlignment = sparkline ? 'auto' : 'center';
|
|
114
145
|
const textStyles = {
|
|
115
146
|
display: 'flex',
|
|
@@ -124,19 +155,22 @@ function StatChart(props) {
|
|
|
124
155
|
...textStyles
|
|
125
156
|
},
|
|
126
157
|
children: [
|
|
127
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(
|
|
158
|
+
showSeriesName && /*#__PURE__*/ (0, _jsxRuntime.jsx)(SeriesName, {
|
|
159
|
+
padding: containerPadding,
|
|
160
|
+
fontSize: seriesNameFontSize,
|
|
161
|
+
children: (ref1 = data.seriesData) === null || ref1 === void 0 ? void 0 : ref1.name
|
|
162
|
+
}),
|
|
163
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(Value, {
|
|
128
164
|
variant: "h3",
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
padding: sparkline ? `${containerPadding} ${containerPadding} 0 ${containerPadding}` : ` 0 ${containerPadding}`
|
|
133
|
-
}),
|
|
165
|
+
color: color,
|
|
166
|
+
fontSize: valueFontSize,
|
|
167
|
+
padding: containerPadding,
|
|
134
168
|
children: formattedValue
|
|
135
169
|
}),
|
|
136
170
|
sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
|
|
137
171
|
sx: {
|
|
138
172
|
width: '100%',
|
|
139
|
-
height:
|
|
173
|
+
height: height - seriesNameHeight - valueFontHeight
|
|
140
174
|
},
|
|
141
175
|
option: option,
|
|
142
176
|
theme: chartsTheme.echartsTheme,
|
|
@@ -145,3 +179,22 @@ function StatChart(props) {
|
|
|
145
179
|
]
|
|
146
180
|
});
|
|
147
181
|
}
|
|
182
|
+
const SeriesName = (0, _material.styled)(_material.Typography, {
|
|
183
|
+
shouldForwardProp: (prop)=>prop !== 'padding' && prop !== 'fontSize'
|
|
184
|
+
})(({ theme , padding , fontSize })=>({
|
|
185
|
+
color: theme.palette.text.secondary,
|
|
186
|
+
padding: `${padding}px`,
|
|
187
|
+
fontSize: `${fontSize}px`,
|
|
188
|
+
overflow: 'hidden',
|
|
189
|
+
textOverflow: 'ellipsis',
|
|
190
|
+
whiteSpace: 'nowrap'
|
|
191
|
+
}));
|
|
192
|
+
const Value = (0, _material.styled)(_material.Typography, {
|
|
193
|
+
shouldForwardProp: (prop)=>prop !== 'color' && prop !== 'padding' && prop !== 'fontSize' && prop !== 'sparkline'
|
|
194
|
+
})(({ theme , color , padding , fontSize , sparkline })=>({
|
|
195
|
+
color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
|
|
196
|
+
fontSize: `${fontSize}px`,
|
|
197
|
+
padding: sparkline ? `${padding}px ${padding}px 0 ${padding}px` : ` 0 ${padding}px`,
|
|
198
|
+
whiteSpace: 'nowrap',
|
|
199
|
+
lineHeight: LINE_HEIGHT
|
|
200
|
+
}));
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "useOptimalFontSize", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>useOptimalFontSize
|
|
20
|
+
});
|
|
21
|
+
const _chartsThemeProvider = require("../context/ChartsThemeProvider");
|
|
22
|
+
let canvasContext;
|
|
23
|
+
function getGlobalCanvasContext() {
|
|
24
|
+
if (!canvasContext) {
|
|
25
|
+
canvasContext = document.createElement('canvas').getContext('2d');
|
|
26
|
+
if (canvasContext === null) {
|
|
27
|
+
throw new Error('Canvas context is null.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return canvasContext;
|
|
31
|
+
}
|
|
32
|
+
function useOptimalFontSize({ text , fontWeight , width , height , lineHeight , maxSize }) {
|
|
33
|
+
const ctx = getGlobalCanvasContext();
|
|
34
|
+
const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
|
|
35
|
+
const textStyle = chartsTheme.echartsTheme.textStyle;
|
|
36
|
+
var ref;
|
|
37
|
+
const fontSize = (ref = Number(textStyle === null || textStyle === void 0 ? void 0 : textStyle.fontSize)) !== null && ref !== void 0 ? ref : 12;
|
|
38
|
+
var ref1;
|
|
39
|
+
const fontFamily = (ref1 = textStyle === null || textStyle === void 0 ? void 0 : textStyle.fontFamily) !== null && ref1 !== void 0 ? ref1 : 'Lato';
|
|
40
|
+
// set the font on the canvas context
|
|
41
|
+
const fontStyle = `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
42
|
+
ctx.font = fontStyle;
|
|
43
|
+
// measure the width of the text with the given font style
|
|
44
|
+
const textMetrics = ctx.measureText(text);
|
|
45
|
+
// check how much bigger we can make the font while staying within the width and height
|
|
46
|
+
const fontSizeBasedOnWidth = width / textMetrics.width * fontSize;
|
|
47
|
+
const fontSizeBasedOnHeight = height / lineHeight;
|
|
48
|
+
// return the smaller font size
|
|
49
|
+
const finalFontSize = Math.min(fontSizeBasedOnHeight, fontSizeBasedOnWidth);
|
|
50
|
+
return maxSize ? Math.min(finalFontSize, maxSize) : finalFontSize;
|
|
51
|
+
}
|