@perses-dev/pie-chart-plugin 0.9.1 → 0.12.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/__mf/css/async/263.d3010b86.css +1 -0
- package/__mf/css/async/341.d3010b86.css +1 -0
- package/__mf/css/async/759.d3010b86.css +1 -0
- package/__mf/js/{PieChart.684c09d1.js → PieChart.1d58bffe.js} +3 -3
- package/__mf/js/async/156.1cf9ec35.js +1 -0
- package/__mf/js/async/264.6e9f3f27.js +110 -0
- package/__mf/js/async/298.e575048a.js +1 -0
- package/__mf/js/async/398.9b0b9c83.js +1 -0
- package/__mf/js/async/567.672f2dce.js +2 -0
- package/__mf/js/async/706.3e6ace36.js +38 -0
- package/__mf/js/async/711.2e914849.js +22 -0
- package/__mf/js/async/{75.a825d10b.js → 75.b6a33f75.js} +1 -1
- package/__mf/js/async/922.560b8115.js +7 -0
- package/__mf/js/async/__federation_expose_PieChart.6ae68990.js +1 -0
- package/__mf/js/{main.b15063c5.js → main.efe2355f.js} +3 -3
- package/lib/PieChartBase.d.ts +1 -2
- package/lib/PieChartBase.d.ts.map +1 -1
- package/lib/PieChartBase.js +26 -25
- package/lib/PieChartBase.js.map +1 -1
- package/lib/PieChartOptionsEditorSettings.d.ts.map +1 -1
- package/lib/PieChartOptionsEditorSettings.js +144 -17
- package/lib/PieChartOptionsEditorSettings.js.map +1 -1
- package/lib/PieChartPanel.d.ts.map +1 -1
- package/lib/PieChartPanel.js +36 -27
- package/lib/PieChartPanel.js.map +1 -1
- package/lib/cjs/PieChartBase.js +24 -23
- package/lib/cjs/PieChartOptionsEditorSettings.js +142 -15
- package/lib/cjs/PieChartPanel.js +35 -26
- package/lib/cjs/colors.js +207 -0
- package/lib/cjs/index.js +2 -4
- package/lib/cjs/pie-chart-model.js +3 -2
- package/lib/cjs/utils.js +10 -30
- package/lib/colors.d.ts +38 -0
- package/lib/colors.d.ts.map +1 -0
- package/lib/colors.js +192 -0
- package/lib/colors.js.map +1 -0
- package/lib/index.d.ts +2 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -4
- package/lib/index.js.map +1 -1
- package/lib/pie-chart-model.d.ts +5 -3
- package/lib/pie-chart-model.d.ts.map +1 -1
- package/lib/pie-chart-model.js +3 -2
- package/lib/pie-chart-model.js.map +1 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +10 -30
- package/lib/utils.js.map +1 -1
- package/mf-manifest.json +22 -42
- package/mf-stats.json +22 -45
- package/package.json +5 -5
- package/__mf/css/async/263.80005a4a.css +0 -1
- package/__mf/css/async/341.80005a4a.css +0 -1
- package/__mf/css/async/759.80005a4a.css +0 -1
- package/__mf/js/async/109.77dcc7d9.js +0 -73
- package/__mf/js/async/224.43460380.js +0 -1
- package/__mf/js/async/238.3e689a99.js +0 -1
- package/__mf/js/async/288.4cad0403.js +0 -7
- package/__mf/js/async/289.c295f73f.js +0 -38
- package/__mf/js/async/298.707087d2.js +0 -1
- package/__mf/js/async/470.1e913aa7.js +0 -2
- package/__mf/js/async/680.f1da299d.js +0 -110
- package/__mf/js/async/708.77a1c1f6.js +0 -1
- package/__mf/js/async/740.254a5697.js +0 -1
- package/__mf/js/async/__federation_expose_PieChart.3d887a98.js +0 -1
- package/lib/cjs/model.js +0 -16
- package/lib/cjs/palette-gen.js +0 -63
- package/lib/cjs/palette.js +0 -83
- package/lib/model.d.ts +0 -20
- package/lib/model.d.ts.map +0 -1
- package/lib/model.js +0 -15
- package/lib/model.js.map +0 -1
- package/lib/palette-gen.d.ts +0 -20
- package/lib/palette-gen.d.ts.map +0 -1
- package/lib/palette-gen.js +0 -50
- package/lib/palette-gen.js.map +0 -1
- package/lib/palette.d.ts +0 -6
- package/lib/palette.d.ts.map +0 -1
- package/lib/palette.js +0 -64
- package/lib/palette.js.map +0 -1
- /package/__mf/js/async/{680.f1da299d.js.LICENSE.txt → 264.6e9f3f27.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{470.1e913aa7.js.LICENSE.txt → 567.672f2dce.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{109.77dcc7d9.js.LICENSE.txt → 711.2e914849.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{288.4cad0403.js.LICENSE.txt → 922.560b8115.js.LICENSE.txt} +0 -0
package/lib/colors.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Copyright 2025 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 ColorHash from 'color-hash';
|
|
14
|
+
// Valid hue values are 0 to 360 and can be adjusted to control the generated colors.
|
|
15
|
+
// More info: https://github.com/zenozeng/color-hash#custom-hue
|
|
16
|
+
// Picked min of 20 and max of 360 to exclude common threshold colors (red).
|
|
17
|
+
// Items with "error" in them will always be generated as red.
|
|
18
|
+
const ERROR_HUE_CUTOFF = 20;
|
|
19
|
+
const colorGenerator = new ColorHash({
|
|
20
|
+
hue: {
|
|
21
|
+
min: ERROR_HUE_CUTOFF,
|
|
22
|
+
max: 360
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const redColorGenerator = new ColorHash({
|
|
26
|
+
hue: {
|
|
27
|
+
min: 0,
|
|
28
|
+
max: ERROR_HUE_CUTOFF
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
// Color utility functions
|
|
32
|
+
/**
|
|
33
|
+
* Converts a number to a 2-digit hex string
|
|
34
|
+
*/ function toHex(n) {
|
|
35
|
+
const hex = n.toString(16);
|
|
36
|
+
return hex.length === 1 ? '0' + hex : hex;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts a hex color string to RGB values
|
|
40
|
+
*/ function hexToRgb(hex) {
|
|
41
|
+
const cleanHex = hex.replace('#', '');
|
|
42
|
+
return {
|
|
43
|
+
r: parseInt(cleanHex.substring(0, 2), 16),
|
|
44
|
+
g: parseInt(cleanHex.substring(2, 4), 16),
|
|
45
|
+
b: parseInt(cleanHex.substring(4, 6), 16)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns a deterministic number between 0 and 1 for a given string
|
|
50
|
+
*/ function stringToSeed(str) {
|
|
51
|
+
let hash = 0;
|
|
52
|
+
for(let i = 0; i < str.length; i++){
|
|
53
|
+
const char = str.charCodeAt(i);
|
|
54
|
+
hash = (hash << 5) - hash + char;
|
|
55
|
+
hash = hash & hash; // Convert to 32-bit integer
|
|
56
|
+
}
|
|
57
|
+
// Convert to positive number and normalize to 0-1 range
|
|
58
|
+
return Math.abs(hash) / 2147483647;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Helper function to generate gradient colors for series within a query
|
|
62
|
+
*/ export function generateGradientColor(baseColor, factor) {
|
|
63
|
+
// Convert hex color to RGB
|
|
64
|
+
const { r, g, b } = hexToRgb(baseColor);
|
|
65
|
+
const newR = Math.round(r * factor);
|
|
66
|
+
const newG = Math.round(g * factor);
|
|
67
|
+
const newB = Math.round(b * factor);
|
|
68
|
+
return `#${toHex(newR)}${toHex(newG)}${toHex(newB)}`;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generates a list of color strings for a given number of series using a categorical palette.
|
|
72
|
+
* When the number of series exceeds the palette size, it cycles through the palette
|
|
73
|
+
* and applies gradients to create visual distinction.
|
|
74
|
+
* @param totalSeries - The total number of series that need colors
|
|
75
|
+
* @param colorPalette - Array of color strings to use as the base palette
|
|
76
|
+
* @returns Array of color strings, one for each series
|
|
77
|
+
*/ export function getSeriesColor(seriesNames, colorPalette) {
|
|
78
|
+
const totalSeries = seriesNames.length;
|
|
79
|
+
if (totalSeries <= 0) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
const colors = [];
|
|
83
|
+
// undefined palette - default
|
|
84
|
+
if (colorPalette === undefined) {
|
|
85
|
+
for(let nameIndex = 0; nameIndex < seriesNames.length; nameIndex++){
|
|
86
|
+
const seriesColor = getDefaultSeriesColor({
|
|
87
|
+
categoricalPalette: [
|
|
88
|
+
'#ff0000'
|
|
89
|
+
],
|
|
90
|
+
muiPrimaryColor: '#ff0000',
|
|
91
|
+
seriesName: seriesNames[nameIndex] || ''
|
|
92
|
+
});
|
|
93
|
+
colors.push(seriesColor);
|
|
94
|
+
}
|
|
95
|
+
return colors;
|
|
96
|
+
}
|
|
97
|
+
// single color palette - generate gradients from that color
|
|
98
|
+
if (colorPalette.length === 1) {
|
|
99
|
+
const baseColor = colorPalette[0] ?? '#ff0000';
|
|
100
|
+
for(let i = 0; i < totalSeries; i++){
|
|
101
|
+
if (i === 0) {
|
|
102
|
+
colors.push(baseColor);
|
|
103
|
+
} else {
|
|
104
|
+
const gradientFactor = 1 * ((totalSeries - i) / totalSeries);
|
|
105
|
+
colors.push(generateGradientColor(baseColor, gradientFactor));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return colors.sort((a, b)=>{
|
|
109
|
+
const seedA = stringToSeed(seriesNames[colors.indexOf(a)] || 'fallback');
|
|
110
|
+
const seedB = stringToSeed(seriesNames[colors.indexOf(b)] || 'fallback');
|
|
111
|
+
return seedA - seedB;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// multi color palette - loops through colors and adds gradient when palette is exhausted
|
|
115
|
+
for(let i = 0; i < totalSeries; i++){
|
|
116
|
+
const color = getColor(colorPalette, i);
|
|
117
|
+
colors.push(color);
|
|
118
|
+
}
|
|
119
|
+
if (totalSeries > colorPalette.length) {
|
|
120
|
+
return colors.sort((a, b)=>{
|
|
121
|
+
const seedA = stringToSeed(seriesNames[colors.indexOf(a)] || 'fallback');
|
|
122
|
+
const seedB = stringToSeed(seriesNames[colors.indexOf(b)] || 'fallback');
|
|
123
|
+
return seedA - seedB;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return colors;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Default classical qualitative palette that cycles through the colors array by index.
|
|
130
|
+
* When colors start repeating (after exhausting the palette), applies gradients for distinction.
|
|
131
|
+
*/ export function getColor(palette, seriesIndex) {
|
|
132
|
+
// Handle undefined or empty palette
|
|
133
|
+
if (!palette || palette.length === 0) {
|
|
134
|
+
return '#ff0000';
|
|
135
|
+
}
|
|
136
|
+
const paletteTotalColors = palette.length;
|
|
137
|
+
const paletteIndex = seriesIndex % paletteTotalColors;
|
|
138
|
+
const baseColor = palette[paletteIndex] ?? '#ff0000';
|
|
139
|
+
// If we haven't exhausted the palette yet, use the original color
|
|
140
|
+
if (seriesIndex < paletteTotalColors) {
|
|
141
|
+
return baseColor;
|
|
142
|
+
}
|
|
143
|
+
// Calculate which "cycle" we're in (0 = first repeat, 1 = second repeat, etc.)
|
|
144
|
+
const cycleNumber = Math.floor(seriesIndex / paletteTotalColors);
|
|
145
|
+
// Apply gradient based on cycle number to create visual distinction
|
|
146
|
+
const gradientFactor = Math.min(1 - cycleNumber * 0.2, 1);
|
|
147
|
+
return generateGradientColor(baseColor, gradientFactor);
|
|
148
|
+
}
|
|
149
|
+
function computeConsistentColor(name, error) {
|
|
150
|
+
const [hue, saturation, lightness] = error ? redColorGenerator.hsl(name) : colorGenerator.hsl(name);
|
|
151
|
+
const saturationPercent = `${(saturation * 100).toFixed(0)}%`;
|
|
152
|
+
const lightnessPercent = `${(lightness * 100).toFixed(0)}%`;
|
|
153
|
+
return `hsla(${hue.toFixed(2)},${saturationPercent},${lightnessPercent},0.9)`;
|
|
154
|
+
}
|
|
155
|
+
// To check whether a color has already been generated for a given string.
|
|
156
|
+
// TODO: Predefined color aliases will be defined here
|
|
157
|
+
const colorLookup = {};
|
|
158
|
+
/**
|
|
159
|
+
* Return a consistent color for (name, error) tuple
|
|
160
|
+
*/ export function getConsistentColor(name, error) {
|
|
161
|
+
const key = `${name}_____${error}`;
|
|
162
|
+
let value = colorLookup[key];
|
|
163
|
+
if (!value) {
|
|
164
|
+
value = computeConsistentColor(name, error);
|
|
165
|
+
colorLookup[key] = value;
|
|
166
|
+
}
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
/*
|
|
170
|
+
* Generate a consistent series name color (if series name includes 'error', it will have a red hue).
|
|
171
|
+
*/ export function getConsistentSeriesNameColor(inputString) {
|
|
172
|
+
return getConsistentColor(inputString, inputString.toLowerCase().includes('error'));
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Get line color as well as color for tooltip and legend, account for whether palette is 'categorical' or 'auto' aka generative
|
|
176
|
+
*/ export function getDefaultSeriesColor(props) {
|
|
177
|
+
const { categoricalPalette, muiPrimaryColor, seriesName } = props;
|
|
178
|
+
// Fallback is unlikely to set unless echarts theme palette in charts theme provider is undefined.
|
|
179
|
+
const fallbackColor = Array.isArray(categoricalPalette) && categoricalPalette[0] ? categoricalPalette[0] // Needed since echarts color property isn't always an array.
|
|
180
|
+
: muiPrimaryColor;
|
|
181
|
+
return getAutoPaletteColor(seriesName, fallbackColor);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get color from generative color palette, this approaches uses series name as the seed and
|
|
185
|
+
* allows for consistent colors across panels (when all panels use this approach).
|
|
186
|
+
*/ export function getAutoPaletteColor(name, fallbackColor) {
|
|
187
|
+
// corresponds to 'Auto' in palette.kind for generative color palette
|
|
188
|
+
const generatedColor = getConsistentSeriesNameColor(name);
|
|
189
|
+
return generatedColor ?? fallbackColor;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/colors.ts"],"sourcesContent":["// Copyright 2025 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 ColorHash from 'color-hash';\n\n// Valid hue values are 0 to 360 and can be adjusted to control the generated colors.\n// More info: https://github.com/zenozeng/color-hash#custom-hue\n// Picked min of 20 and max of 360 to exclude common threshold colors (red).\n// Items with \"error\" in them will always be generated as red.\nconst ERROR_HUE_CUTOFF = 20;\nconst colorGenerator = new ColorHash({ hue: { min: ERROR_HUE_CUTOFF, max: 360 } });\nconst redColorGenerator = new ColorHash({ hue: { min: 0, max: ERROR_HUE_CUTOFF } });\n\nexport interface SeriesColorProps {\n categoricalPalette: string[];\n muiPrimaryColor: string;\n seriesName: string;\n}\n\n// Color utility functions\n/**\n * Converts a number to a 2-digit hex string\n */\nfunction toHex(n: number): string {\n const hex = n.toString(16);\n return hex.length === 1 ? '0' + hex : hex;\n}\n\n/**\n * Converts a hex color string to RGB values\n */\nfunction hexToRgb(hex: string): { r: number; g: number; b: number } {\n const cleanHex = hex.replace('#', '');\n return {\n r: parseInt(cleanHex.substring(0, 2), 16),\n g: parseInt(cleanHex.substring(2, 4), 16),\n b: parseInt(cleanHex.substring(4, 6), 16),\n };\n}\n\n/**\n * Returns a deterministic number between 0 and 1 for a given string\n */\nfunction stringToSeed(str: string): number {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i);\n hash = (hash << 5) - hash + char;\n hash = hash & hash; // Convert to 32-bit integer\n }\n // Convert to positive number and normalize to 0-1 range\n return Math.abs(hash) / 2147483647;\n}\n\n/**\n * Helper function to generate gradient colors for series within a query\n */\nexport function generateGradientColor(baseColor: string, factor: number): string {\n // Convert hex color to RGB\n const { r, g, b } = hexToRgb(baseColor);\n\n const newR = Math.round(r * factor);\n const newG = Math.round(g * factor);\n const newB = Math.round(b * factor);\n\n return `#${toHex(newR)}${toHex(newG)}${toHex(newB)}`;\n}\n\n/**\n * Generates a list of color strings for a given number of series using a categorical palette.\n * When the number of series exceeds the palette size, it cycles through the palette\n * and applies gradients to create visual distinction.\n * @param totalSeries - The total number of series that need colors\n * @param colorPalette - Array of color strings to use as the base palette\n * @returns Array of color strings, one for each series\n */\nexport function getSeriesColor(seriesNames: string[], colorPalette?: string[]): string[] {\n const totalSeries = seriesNames.length;\n\n if (totalSeries <= 0) {\n return [];\n }\n\n const colors: string[] = [];\n\n // undefined palette - default\n if (colorPalette === undefined) {\n for (let nameIndex = 0; nameIndex < seriesNames.length; nameIndex++) {\n const seriesColor = getDefaultSeriesColor({\n categoricalPalette: ['#ff0000'],\n muiPrimaryColor: '#ff0000',\n seriesName: seriesNames[nameIndex] || '',\n });\n colors.push(seriesColor);\n }\n return colors;\n }\n\n // single color palette - generate gradients from that color\n if (colorPalette.length === 1) {\n const baseColor = colorPalette[0] ?? '#ff0000';\n for (let i = 0; i < totalSeries; i++) {\n if (i === 0) {\n colors.push(baseColor);\n } else {\n const gradientFactor = 1 * ((totalSeries - i) / totalSeries);\n colors.push(generateGradientColor(baseColor, gradientFactor));\n }\n }\n return colors.sort((a, b) => {\n const seedA = stringToSeed(seriesNames[colors.indexOf(a)] || 'fallback');\n const seedB = stringToSeed(seriesNames[colors.indexOf(b)] || 'fallback');\n return seedA - seedB;\n });\n }\n\n // multi color palette - loops through colors and adds gradient when palette is exhausted\n for (let i = 0; i < totalSeries; i++) {\n const color = getColor(colorPalette, i);\n colors.push(color);\n }\n\n if (totalSeries > colorPalette.length) {\n return colors.sort((a, b) => {\n const seedA = stringToSeed(seriesNames[colors.indexOf(a)] || 'fallback');\n const seedB = stringToSeed(seriesNames[colors.indexOf(b)] || 'fallback');\n return seedA - seedB;\n });\n }\n return colors;\n}\n\n/**\n * Default classical qualitative palette that cycles through the colors array by index.\n * When colors start repeating (after exhausting the palette), applies gradients for distinction.\n */\nexport function getColor(palette: string[], seriesIndex: number): string {\n // Handle undefined or empty palette\n if (!palette || palette.length === 0) {\n return '#ff0000';\n }\n\n const paletteTotalColors = palette.length;\n const paletteIndex = seriesIndex % paletteTotalColors;\n const baseColor = palette[paletteIndex] ?? '#ff0000';\n\n // If we haven't exhausted the palette yet, use the original color\n if (seriesIndex < paletteTotalColors) {\n return baseColor;\n }\n\n // Calculate which \"cycle\" we're in (0 = first repeat, 1 = second repeat, etc.)\n const cycleNumber = Math.floor(seriesIndex / paletteTotalColors);\n\n // Apply gradient based on cycle number to create visual distinction\n const gradientFactor = Math.min(1 - cycleNumber * 0.2, 1);\n return generateGradientColor(baseColor, gradientFactor);\n}\n\nfunction computeConsistentColor(name: string, error: boolean): string {\n const [hue, saturation, lightness] = error ? redColorGenerator.hsl(name) : colorGenerator.hsl(name);\n const saturationPercent = `${(saturation * 100).toFixed(0)}%`;\n const lightnessPercent = `${(lightness * 100).toFixed(0)}%`;\n return `hsla(${hue.toFixed(2)},${saturationPercent},${lightnessPercent},0.9)`;\n}\n\n// To check whether a color has already been generated for a given string.\n// TODO: Predefined color aliases will be defined here\nconst colorLookup: Record<string, string> = {};\n\n/**\n * Return a consistent color for (name, error) tuple\n */\nexport function getConsistentColor(name: string, error: boolean): string {\n const key = `${name}_____${error}`;\n let value = colorLookup[key];\n if (!value) {\n value = computeConsistentColor(name, error);\n colorLookup[key] = value;\n }\n return value;\n}\n\n/*\n * Generate a consistent series name color (if series name includes 'error', it will have a red hue).\n */\nexport function getConsistentSeriesNameColor(inputString: string): string {\n return getConsistentColor(inputString, inputString.toLowerCase().includes('error'));\n}\n\n/**\n * Get line color as well as color for tooltip and legend, account for whether palette is 'categorical' or 'auto' aka generative\n */\nexport function getDefaultSeriesColor(props: SeriesColorProps): string {\n const { categoricalPalette, muiPrimaryColor, seriesName } = props;\n\n // Fallback is unlikely to set unless echarts theme palette in charts theme provider is undefined.\n const fallbackColor =\n Array.isArray(categoricalPalette) && categoricalPalette[0]\n ? (categoricalPalette[0] as string) // Needed since echarts color property isn't always an array.\n : muiPrimaryColor;\n\n return getAutoPaletteColor(seriesName, fallbackColor);\n}\n\n/**\n * Get color from generative color palette, this approaches uses series name as the seed and\n * allows for consistent colors across panels (when all panels use this approach).\n */\nexport function getAutoPaletteColor(name: string, fallbackColor: string): string {\n // corresponds to 'Auto' in palette.kind for generative color palette\n const generatedColor = getConsistentSeriesNameColor(name);\n return generatedColor ?? fallbackColor;\n}\n"],"names":["ColorHash","ERROR_HUE_CUTOFF","colorGenerator","hue","min","max","redColorGenerator","toHex","n","hex","toString","length","hexToRgb","cleanHex","replace","r","parseInt","substring","g","b","stringToSeed","str","hash","i","char","charCodeAt","Math","abs","generateGradientColor","baseColor","factor","newR","round","newG","newB","getSeriesColor","seriesNames","colorPalette","totalSeries","colors","undefined","nameIndex","seriesColor","getDefaultSeriesColor","categoricalPalette","muiPrimaryColor","seriesName","push","gradientFactor","sort","a","seedA","indexOf","seedB","color","getColor","palette","seriesIndex","paletteTotalColors","paletteIndex","cycleNumber","floor","computeConsistentColor","name","error","saturation","lightness","hsl","saturationPercent","toFixed","lightnessPercent","colorLookup","getConsistentColor","key","value","getConsistentSeriesNameColor","inputString","toLowerCase","includes","props","fallbackColor","Array","isArray","getAutoPaletteColor","generatedColor"],"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,OAAOA,eAAe,aAAa;AAEnC,qFAAqF;AACrF,+DAA+D;AAC/D,4EAA4E;AAC5E,8DAA8D;AAC9D,MAAMC,mBAAmB;AACzB,MAAMC,i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EAAEE,iBAAiB,KAAK,CAAC;AAC/E;AAEA,0EAA0E;AAC1E,sDAAsD;AACtD,MAAMC,cAAsC,CAAC;AAE7C;;CAEC,GACD,OAAO,SAASC,mBAAmBT,IAAY,EAAEC,KAAc;IAC7D,MAAMS,MAAM,GAAGV,KAAK,KAAK,EAAEC,OAAO;IAClC,IAAIU,QAAQH,WAAW,CAACE,IAAI;IAC5B,IAAI,CAACC,OAAO;QACVA,QAAQZ,uBAAuBC,MAAMC;QACrCO,WAAW,CAACE,IAAI,GAAGC;IACrB;IACA,OAAOA;AACT;AAEA;;CAEC,GACD,OAAO,SAASC,6BAA6BC,WAAmB;IAC9D,OAAOJ,mBAAmBI,aAAaA,YAAYC,WAAW,GAAGC,QAAQ,CAAC;AAC5E;AAEA;;CAEC,GACD,OAAO,SAASnC,sBAAsBoC,KAAuB;IAC3D,MAAM,EAAEnC,kBAAkB,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAGiC;IAE5D,kGAAkG;IAClG,MAAMC,gBACJC,MAAMC,OAAO,CAACtC,uBAAuBA,kBAAkB,CAAC,EAAE,GACrDA,kBAAkB,CAAC,EAAE,CAAY,6DAA6D;OAC/FC;IAEN,OAAOsC,oBAAoBrC,YAAYkC;AACzC;AAEA;;;CAGC,GACD,OAAO,SAASG,oBAAoBpB,IAAY,EAAEiB,aAAqB;IACrE,qEAAqE;IACrE,MAAMI,iBAAiBT,6BAA6BZ;IACpD,OAAOqB,kBAAkBJ;AAC3B"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export * from '
|
|
1
|
+
export * from './PieChartPanel';
|
|
2
2
|
export { getPluginModule } from './getPluginModule';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './palette';
|
|
5
|
-
export * from './palette-gen';
|
|
3
|
+
export * from './colors';
|
|
6
4
|
export * from './pie-chart-model';
|
|
7
5
|
export * from './PieChart';
|
|
8
6
|
export * from './PieChartOptionsEditorSettings';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,iCAAiC,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export * from '
|
|
1
|
+
export * from './PieChartPanel';
|
|
2
2
|
export { getPluginModule } from './getPluginModule';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './palette';
|
|
5
|
-
export * from './palette-gen';
|
|
3
|
+
export * from './colors';
|
|
6
4
|
export * from './pie-chart-model';
|
|
7
5
|
export * from './PieChart';
|
|
8
6
|
export * from './PieChartOptionsEditorSettings';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from '
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './PieChartPanel';\nexport { getPluginModule } from './getPluginModule';\nexport * from './colors';\nexport * from './pie-chart-model';\nexport * from './PieChart';\nexport * from './PieChartOptionsEditorSettings';\n"],"names":["getPluginModule"],"mappings":"AAAA,cAAc,kBAAkB;AAChC,SAASA,eAAe,QAAQ,oBAAoB;AACpD,cAAc,WAAW;AACzB,cAAc,oBAAoB;AAClC,cAAc,aAAa;AAC3B,cAAc,kCAAkC"}
|
package/lib/pie-chart-model.d.ts
CHANGED
|
@@ -8,12 +8,14 @@ export interface BarChartDefinition extends Definition<PieChartOptions> {
|
|
|
8
8
|
kind: 'PieChart';
|
|
9
9
|
}
|
|
10
10
|
export interface PieChartOptions {
|
|
11
|
-
legend?: LegendSpecOptions;
|
|
12
11
|
calculation: CalculationType;
|
|
13
|
-
radius: number;
|
|
14
12
|
format?: FormatOptions;
|
|
15
|
-
|
|
13
|
+
colorPalette?: string[];
|
|
14
|
+
legend?: LegendSpecOptions;
|
|
16
15
|
mode?: ModeOption;
|
|
16
|
+
radius: number;
|
|
17
|
+
showLabels?: boolean;
|
|
18
|
+
sort?: SortOption;
|
|
17
19
|
}
|
|
18
20
|
export type PieChartOptionsEditorProps = OptionsEditorProps<PieChartOptions>;
|
|
19
21
|
export declare function createInitialPieChartOptions(): PieChartOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pie-chart-model.d.ts","sourceRoot":"","sources":["../../src/pie-chart-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAuB,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnG,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAElF,eAAO,MAAM,cAAc,EAAE,aAAsD,CAAC;AACpF,eAAO,MAAM,YAAY,EAAE,UAAmB,CAAC;AAC/C,eAAO,MAAM,YAAY,EAAE,UAAoB,CAAC;AAEhD,MAAM,WAAW,kBAAmB,SAAQ,UAAU,CAAC,eAAe,CAAC;IACrE,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,
|
|
1
|
+
{"version":3,"file":"pie-chart-model.d.ts","sourceRoot":"","sources":["../../src/pie-chart-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAuB,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnG,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAElF,eAAO,MAAM,cAAc,EAAE,aAAsD,CAAC;AACpF,eAAO,MAAM,YAAY,EAAE,UAAmB,CAAC;AAC/C,eAAO,MAAM,YAAY,EAAE,UAAoB,CAAC;AAEhD,MAAM,WAAW,kBAAmB,SAAQ,UAAU,CAAC,eAAe,CAAC;IACrE,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,MAAM,MAAM,0BAA0B,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAAC;AAE7E,wBAAgB,4BAA4B,IAAI,eAAe,CAS9D"}
|
package/lib/pie-chart-model.js
CHANGED
|
@@ -21,9 +21,10 @@ export function createInitialPieChartOptions() {
|
|
|
21
21
|
return {
|
|
22
22
|
calculation: DEFAULT_CALCULATION,
|
|
23
23
|
format: DEFAULT_FORMAT,
|
|
24
|
+
mode: DEFAULT_MODE,
|
|
24
25
|
radius: 50,
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
showLabels: false,
|
|
27
|
+
sort: DEFAULT_SORT
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/pie-chart-model.ts"],"sourcesContent":["// Copyright 2024 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 { ModeOption, SortOption } from '@perses-dev/components';\nimport { CalculationType, DEFAULT_CALCULATION, Definition, FormatOptions } from '@perses-dev/core';\nimport { LegendSpecOptions, OptionsEditorProps } from '@perses-dev/plugin-system';\n\nexport const DEFAULT_FORMAT: FormatOptions = { unit: 'decimal', shortValues: true };\nexport const DEFAULT_SORT: SortOption = 'desc';\nexport const DEFAULT_MODE: ModeOption = 'value';\n\nexport interface BarChartDefinition extends Definition<PieChartOptions> {\n kind: 'PieChart';\n}\n\nexport interface PieChartOptions {\n legend?: LegendSpecOptions;\n
|
|
1
|
+
{"version":3,"sources":["../../src/pie-chart-model.ts"],"sourcesContent":["// Copyright 2024 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 { ModeOption, SortOption } from '@perses-dev/components';\nimport { CalculationType, DEFAULT_CALCULATION, Definition, FormatOptions } from '@perses-dev/core';\nimport { LegendSpecOptions, OptionsEditorProps } from '@perses-dev/plugin-system';\n\nexport const DEFAULT_FORMAT: FormatOptions = { unit: 'decimal', shortValues: true };\nexport const DEFAULT_SORT: SortOption = 'desc';\nexport const DEFAULT_MODE: ModeOption = 'value';\n\nexport interface BarChartDefinition extends Definition<PieChartOptions> {\n kind: 'PieChart';\n}\n\nexport interface PieChartOptions {\n calculation: CalculationType;\n format?: FormatOptions;\n colorPalette?: string[];\n legend?: LegendSpecOptions;\n mode?: ModeOption;\n radius: number;\n showLabels?: boolean;\n sort?: SortOption;\n}\n\nexport type PieChartOptionsEditorProps = OptionsEditorProps<PieChartOptions>;\n\nexport function createInitialPieChartOptions(): PieChartOptions {\n return {\n calculation: DEFAULT_CALCULATION,\n format: DEFAULT_FORMAT,\n mode: DEFAULT_MODE,\n radius: 50,\n showLabels: false,\n sort: DEFAULT_SORT,\n };\n}\n"],"names":["DEFAULT_CALCULATION","DEFAULT_FORMAT","unit","shortValues","DEFAULT_SORT","DEFAULT_MODE","createInitialPieChartOptions","calculation","format","mode","radius","showLabels","sort"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAA0BA,mBAAmB,QAAmC,mBAAmB;AAGnG,OAAO,MAAMC,iBAAgC;IAAEC,MAAM;IAAWC,aAAa;AAAK,EAAE;AACpF,OAAO,MAAMC,eAA2B,OAAO;AAC/C,OAAO,MAAMC,eAA2B,QAAQ;AAmBhD,OAAO,SAASC;IACd,OAAO;QACLC,aAAaP;QACbQ,QAAQP;QACRQ,MAAMJ;QACNK,QAAQ;QACRC,YAAY;QACZC,MAAMR;IACR;AACF"}
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAS9G;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,SAAS,GAAE,UAAyB,GAAG,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAS9G;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,SAAS,GAAE,UAAyB,GAAG,YAAY,EAAE,CAWzG"}
|
package/lib/utils.js
CHANGED
|
@@ -17,40 +17,20 @@ export function calculatePercentages(data) {
|
|
|
17
17
|
const percentage = (seriesData.value ?? 0) / sum * 100;
|
|
18
18
|
return {
|
|
19
19
|
...seriesData,
|
|
20
|
-
value: percentage
|
|
20
|
+
value: Number(percentage.toFixed(2))
|
|
21
21
|
};
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
export function sortSeriesData(data, sortOrder = DEFAULT_SORT) {
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (a.value === b.value) {
|
|
35
|
-
return 0;
|
|
36
|
-
}
|
|
37
|
-
return a.value < b.value ? 1 : -1;
|
|
38
|
-
});
|
|
39
|
-
} else {
|
|
40
|
-
// sort in descending order by value
|
|
41
|
-
return data.sort((a, b)=>{
|
|
42
|
-
if (a.value === null) {
|
|
43
|
-
return -1;
|
|
44
|
-
}
|
|
45
|
-
if (b.value === null) {
|
|
46
|
-
return 1;
|
|
47
|
-
}
|
|
48
|
-
if (a.value === b.value) {
|
|
49
|
-
return 0;
|
|
50
|
-
}
|
|
51
|
-
return a.value < b.value ? -1 : 1;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
25
|
+
return data.sort((a, b)=>{
|
|
26
|
+
// Handle null values - push them to the end regardless of sort order
|
|
27
|
+
if (a.value === null && b.value === null) return 0;
|
|
28
|
+
if (a.value === null) return 1;
|
|
29
|
+
if (b.value === null) return -1;
|
|
30
|
+
// Sort by value
|
|
31
|
+
const diff = (a.value ?? 0) - (b.value ?? 0);
|
|
32
|
+
return sortOrder === 'asc' ? diff : -diff;
|
|
33
|
+
});
|
|
54
34
|
}
|
|
55
35
|
|
|
56
36
|
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["// Copyright 2024 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 { SortOption } from '@perses-dev/components';\nimport { DEFAULT_SORT } from './pie-chart-model';\nimport { PieChartData } from './PieChartBase';\n\nexport function calculatePercentages(data: PieChartData[]): Array<{ id?: string; name: string; value: number }> {\n const sum = data.reduce((accumulator, { value }) => accumulator + (value ?? 0), 0);\n return data.map((seriesData) => {\n const percentage = ((seriesData.value ?? 0) / sum) * 100;\n return {\n ...seriesData,\n value: percentage,\n };\n });\n}\n\nexport function sortSeriesData(data: PieChartData[], sortOrder: SortOption = DEFAULT_SORT): PieChartData[] {\n
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["// Copyright 2024 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 { SortOption } from '@perses-dev/components';\nimport { DEFAULT_SORT } from './pie-chart-model';\nimport { PieChartData } from './PieChartBase';\n\nexport function calculatePercentages(data: PieChartData[]): Array<{ id?: string; name: string; value: number }> {\n const sum = data.reduce((accumulator, { value }) => accumulator + (value ?? 0), 0);\n return data.map((seriesData) => {\n const percentage = ((seriesData.value ?? 0) / sum) * 100;\n return {\n ...seriesData,\n value: Number(percentage.toFixed(2)),\n };\n });\n}\n\nexport function sortSeriesData(data: PieChartData[], sortOrder: SortOption = DEFAULT_SORT): PieChartData[] {\n return data.sort((a, b) => {\n // Handle null values - push them to the end regardless of sort order\n if (a.value === null && b.value === null) return 0;\n if (a.value === null) return 1;\n if (b.value === null) return -1;\n\n // Sort by value\n const diff = (a.value ?? 0) - (b.value ?? 0);\n return sortOrder === 'asc' ? diff : -diff;\n });\n}\n"],"names":["DEFAULT_SORT","calculatePercentages","data","sum","reduce","accumulator","value","map","seriesData","percentage","Number","toFixed","sortSeriesData","sortOrder","sort","a","b","diff"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,YAAY,QAAQ,oBAAoB;AAGjD,OAAO,SAASC,qBAAqBC,IAAoB;IACvD,MAAMC,MAAMD,KAAKE,MAAM,CAAC,CAACC,aAAa,EAAEC,KAAK,EAAE,GAAKD,cAAeC,CAAAA,SAAS,CAAA,GAAI;IAChF,OAAOJ,KAAKK,GAAG,CAAC,CAACC;QACf,MAAMC,aAAa,AAAED,CAAAA,WAAWF,KAAK,IAAI,CAAA,IAAKH,MAAO;QACrD,OAAO;YACL,GAAGK,UAAU;YACbF,OAAOI,OAAOD,WAAWE,OAAO,CAAC;QACnC;IACF;AACF;AAEA,OAAO,SAASC,eAAeV,IAAoB,EAAEW,YAAwBb,YAAY;IACvF,OAAOE,KAAKY,IAAI,CAAC,CAACC,GAAGC;QACnB,qEAAqE;QACrE,IAAID,EAAET,KAAK,KAAK,QAAQU,EAAEV,KAAK,KAAK,MAAM,OAAO;QACjD,IAAIS,EAAET,KAAK,KAAK,MAAM,OAAO;QAC7B,IAAIU,EAAEV,KAAK,KAAK,MAAM,OAAO,CAAC;QAE9B,gBAAgB;QAChB,MAAMW,OAAO,AAACF,CAAAA,EAAET,KAAK,IAAI,CAAA,IAAMU,CAAAA,EAAEV,KAAK,IAAI,CAAA;QAC1C,OAAOO,cAAc,QAAQI,OAAO,CAACA;IACvC;AACF"}
|
package/mf-manifest.json
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
"name": "PieChart",
|
|
6
6
|
"type": "app",
|
|
7
7
|
"buildInfo": {
|
|
8
|
-
"buildVersion": "0.
|
|
8
|
+
"buildVersion": "0.12.0",
|
|
9
9
|
"buildName": "@perses-dev/pie-chart-plugin"
|
|
10
10
|
},
|
|
11
11
|
"remoteEntry": {
|
|
12
|
-
"name": "__mf/js/PieChart.
|
|
12
|
+
"name": "__mf/js/PieChart.1d58bffe.js",
|
|
13
13
|
"path": "",
|
|
14
14
|
"type": "global"
|
|
15
15
|
},
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"globalName": "PieChart",
|
|
23
23
|
"pluginVersion": "0.19.1",
|
|
24
24
|
"prefetchInterface": false,
|
|
25
|
-
"
|
|
25
|
+
"getPublicPath": "function() { const prefix = window.PERSES_PLUGIN_ASSETS_PATH || window.PERSES_APP_CONFIG?.api_prefix || \"\"; return prefix + \"/plugins/PieChart/\"; }"
|
|
26
26
|
},
|
|
27
27
|
"shared": [
|
|
28
28
|
{
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"name": "@emotion/styled",
|
|
50
50
|
"version": "11.14.0",
|
|
51
51
|
"singleton": true,
|
|
52
|
-
"requiredVersion": "^11.
|
|
52
|
+
"requiredVersion": "^11.6.0",
|
|
53
53
|
"assets": {
|
|
54
54
|
"js": {
|
|
55
55
|
"async": [],
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"name": "@hookform/resolvers",
|
|
70
70
|
"version": "3.10.0",
|
|
71
71
|
"singleton": true,
|
|
72
|
-
"requiredVersion": "^3.
|
|
72
|
+
"requiredVersion": "^3.2.0",
|
|
73
73
|
"assets": {
|
|
74
74
|
"js": {
|
|
75
75
|
"async": [],
|
|
@@ -87,14 +87,14 @@
|
|
|
87
87
|
{
|
|
88
88
|
"id": "PieChart:@perses-dev/components",
|
|
89
89
|
"name": "@perses-dev/components",
|
|
90
|
-
"version": "0.
|
|
90
|
+
"version": "0.53.0-beta.1",
|
|
91
91
|
"singleton": true,
|
|
92
|
-
"requiredVersion": "^0.
|
|
92
|
+
"requiredVersion": "^0.53.0-beta.1",
|
|
93
93
|
"assets": {
|
|
94
94
|
"js": {
|
|
95
95
|
"async": [],
|
|
96
96
|
"sync": [
|
|
97
|
-
"__mf/js/async/
|
|
97
|
+
"__mf/js/async/922.560b8115.js"
|
|
98
98
|
]
|
|
99
99
|
},
|
|
100
100
|
"css": {
|
|
@@ -106,14 +106,14 @@
|
|
|
106
106
|
{
|
|
107
107
|
"id": "PieChart:@perses-dev/plugin-system",
|
|
108
108
|
"name": "@perses-dev/plugin-system",
|
|
109
|
-
"version": "0.
|
|
109
|
+
"version": "0.53.0-beta.1",
|
|
110
110
|
"singleton": true,
|
|
111
|
-
"requiredVersion": "^0.
|
|
111
|
+
"requiredVersion": "^0.53.0-beta.1",
|
|
112
112
|
"assets": {
|
|
113
113
|
"js": {
|
|
114
114
|
"async": [],
|
|
115
115
|
"sync": [
|
|
116
|
-
"__mf/js/async/
|
|
116
|
+
"__mf/js/async/711.2e914849.js"
|
|
117
117
|
]
|
|
118
118
|
},
|
|
119
119
|
"css": {
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
"js": {
|
|
133
133
|
"async": [],
|
|
134
134
|
"sync": [
|
|
135
|
-
"__mf/js/async/75.
|
|
135
|
+
"__mf/js/async/75.b6a33f75.js"
|
|
136
136
|
]
|
|
137
137
|
},
|
|
138
138
|
"css": {
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"name": "echarts",
|
|
147
147
|
"version": "5.5.0",
|
|
148
148
|
"singleton": true,
|
|
149
|
-
"requiredVersion": "
|
|
149
|
+
"requiredVersion": "5.5.0",
|
|
150
150
|
"assets": {
|
|
151
151
|
"js": {
|
|
152
152
|
"async": [],
|
|
@@ -216,25 +216,6 @@
|
|
|
216
216
|
"sync": []
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
"id": "PieChart:date-fns-tz",
|
|
222
|
-
"name": "date-fns-tz",
|
|
223
|
-
"version": "3.2.0",
|
|
224
|
-
"singleton": true,
|
|
225
|
-
"requiredVersion": "^3.2.0",
|
|
226
|
-
"assets": {
|
|
227
|
-
"js": {
|
|
228
|
-
"async": [],
|
|
229
|
-
"sync": [
|
|
230
|
-
"__mf/js/async/740.254a5697.js"
|
|
231
|
-
]
|
|
232
|
-
},
|
|
233
|
-
"css": {
|
|
234
|
-
"async": [],
|
|
235
|
-
"sync": []
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
219
|
}
|
|
239
220
|
],
|
|
240
221
|
"remotes": [],
|
|
@@ -245,27 +226,26 @@
|
|
|
245
226
|
"assets": {
|
|
246
227
|
"js": {
|
|
247
228
|
"sync": [
|
|
248
|
-
"__mf/js/async/
|
|
249
|
-
"__mf/js/async/
|
|
250
|
-
"__mf/js/async/298.
|
|
229
|
+
"__mf/js/async/567.672f2dce.js",
|
|
230
|
+
"__mf/js/async/264.6e9f3f27.js",
|
|
231
|
+
"__mf/js/async/298.e575048a.js",
|
|
251
232
|
"__mf/js/async/707.c77cb775.js",
|
|
252
|
-
"__mf/js/async/__federation_expose_PieChart.
|
|
233
|
+
"__mf/js/async/__federation_expose_PieChart.6ae68990.js"
|
|
253
234
|
],
|
|
254
235
|
"async": [
|
|
255
236
|
"__mf/js/async/lib-router.5205dc27.js",
|
|
256
237
|
"__mf/js/async/292.67519c5b.js",
|
|
257
|
-
"__mf/js/async/
|
|
238
|
+
"__mf/js/async/706.3e6ace36.js",
|
|
258
239
|
"__mf/js/async/488.a0bde6cf.js",
|
|
259
|
-
"__mf/js/async/
|
|
260
|
-
"__mf/js/async/
|
|
261
|
-
"__mf/js/async/708.77a1c1f6.js"
|
|
240
|
+
"__mf/js/async/398.9b0b9c83.js",
|
|
241
|
+
"__mf/js/async/156.1cf9ec35.js"
|
|
262
242
|
]
|
|
263
243
|
},
|
|
264
244
|
"css": {
|
|
265
245
|
"sync": [],
|
|
266
246
|
"async": [
|
|
267
|
-
"__mf/css/async/263.
|
|
268
|
-
"__mf/css/async/341.
|
|
247
|
+
"__mf/css/async/263.d3010b86.css",
|
|
248
|
+
"__mf/css/async/341.d3010b86.css"
|
|
269
249
|
]
|
|
270
250
|
}
|
|
271
251
|
},
|