@perses-dev/pie-chart-plugin 0.6.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.
Files changed (129) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +41 -0
  3. package/__mf/css/async/263.80005a4a.css +1 -0
  4. package/__mf/css/async/341.80005a4a.css +1 -0
  5. package/__mf/css/async/759.80005a4a.css +1 -0
  6. package/__mf/font/lato-all-300-normal.322bdf14.woff +0 -0
  7. package/__mf/font/lato-all-400-normal.63513b00.woff +0 -0
  8. package/__mf/font/lato-all-700-normal.bb27db94.woff +0 -0
  9. package/__mf/font/lato-all-900-normal.a27049a3.woff +0 -0
  10. package/__mf/font/lato-latin-300-normal.c5195215.woff2 +0 -0
  11. package/__mf/font/lato-latin-400-normal.b7ffde23.woff2 +0 -0
  12. package/__mf/font/lato-latin-700-normal.d5eb20bc.woff2 +0 -0
  13. package/__mf/font/lato-latin-900-normal.d884a71c.woff2 +0 -0
  14. package/__mf/font/lato-latin-ext-300-normal.abcc64a9.woff2 +0 -0
  15. package/__mf/font/lato-latin-ext-400-normal.6ebed106.woff2 +0 -0
  16. package/__mf/font/lato-latin-ext-700-normal.8697d1d5.woff2 +0 -0
  17. package/__mf/font/lato-latin-ext-900-normal.20a2b415.woff2 +0 -0
  18. package/__mf/js/693.77ca36d8.js +5 -0
  19. package/__mf/js/PieChart.9e5c2bf5.js +5 -0
  20. package/__mf/js/async/162.668ea958.js +73 -0
  21. package/__mf/js/async/162.668ea958.js.LICENSE.txt +19 -0
  22. package/__mf/js/async/173.ee70b493.js +2 -0
  23. package/__mf/js/async/173.ee70b493.js.LICENSE.txt +19 -0
  24. package/__mf/js/async/214.df2e7807.js +1 -0
  25. package/__mf/js/async/224.dbeed4db.js +1 -0
  26. package/__mf/js/async/238.5287310b.js +1 -0
  27. package/__mf/js/async/292.f278784e.js +1 -0
  28. package/__mf/js/async/331.a0d6355f.js +2 -0
  29. package/__mf/js/async/331.a0d6355f.js.LICENSE.txt +21 -0
  30. package/__mf/js/async/36.ac56ec70.js +38 -0
  31. package/__mf/js/async/360.fdc4e499.js +29 -0
  32. package/__mf/js/async/360.fdc4e499.js.LICENSE.txt +37 -0
  33. package/__mf/js/async/488.0fc5dcbb.js +1 -0
  34. package/__mf/js/async/610.8c8cf7f2.js +1 -0
  35. package/__mf/js/async/620.9a73a66b.js +2 -0
  36. package/__mf/js/async/620.9a73a66b.js.LICENSE.txt +9 -0
  37. package/__mf/js/async/651.a1042e18.js +1 -0
  38. package/__mf/js/async/656.5efccb26.js +1 -0
  39. package/__mf/js/async/694.b227b636.js +1 -0
  40. package/__mf/js/async/707.55fda5d1.js +1 -0
  41. package/__mf/js/async/738.4ac98841.js +1 -0
  42. package/__mf/js/async/740.b86dfa00.js +1 -0
  43. package/__mf/js/async/75.905151a5.js +1 -0
  44. package/__mf/js/async/770.93415255.js +1 -0
  45. package/__mf/js/async/960.208437e1.js +2 -0
  46. package/__mf/js/async/960.208437e1.js.LICENSE.txt +8 -0
  47. package/__mf/js/async/964.6df60c3e.js +2 -0
  48. package/__mf/js/async/964.6df60c3e.js.LICENSE.txt +9 -0
  49. package/__mf/js/async/973.74031340.js +110 -0
  50. package/__mf/js/async/973.74031340.js.LICENSE.txt +27 -0
  51. package/__mf/js/async/981.3ecbf5ea.js +2 -0
  52. package/__mf/js/async/981.3ecbf5ea.js.LICENSE.txt +8 -0
  53. package/__mf/js/async/996.9e160813.js +2 -0
  54. package/__mf/js/async/996.9e160813.js.LICENSE.txt +24 -0
  55. package/__mf/js/async/__federation_expose_PieChart.f03b1180.js +1 -0
  56. package/__mf/js/async/lib-router.d29f3ef0.js +2 -0
  57. package/__mf/js/async/lib-router.d29f3ef0.js.LICENSE.txt +32 -0
  58. package/__mf/js/main.518abb8d.js +1 -0
  59. package/lib/PieChart.d.ts +8 -0
  60. package/lib/PieChart.d.ts.map +1 -0
  61. package/lib/PieChart.js +32 -0
  62. package/lib/PieChart.js.map +1 -0
  63. package/lib/PieChartOptionsEditorSettings.d.ts +4 -0
  64. package/lib/PieChartOptionsEditorSettings.d.ts.map +1 -0
  65. package/lib/PieChartOptionsEditorSettings.js +104 -0
  66. package/lib/PieChartOptionsEditorSettings.js.map +1 -0
  67. package/lib/PieChartPanel.d.ts +7 -0
  68. package/lib/PieChartPanel.d.ts.map +1 -0
  69. package/lib/PieChartPanel.js +164 -0
  70. package/lib/PieChartPanel.js.map +1 -0
  71. package/lib/bootstrap.d.ts +2 -0
  72. package/lib/bootstrap.d.ts.map +1 -0
  73. package/lib/bootstrap.js +19 -0
  74. package/lib/bootstrap.js.map +1 -0
  75. package/lib/cjs/PieChart.js +38 -0
  76. package/lib/cjs/PieChartOptionsEditorSettings.js +117 -0
  77. package/lib/cjs/PieChartPanel.js +177 -0
  78. package/lib/cjs/bootstrap.js +26 -0
  79. package/lib/cjs/env.d.js +14 -0
  80. package/lib/cjs/getPluginModule.js +27 -0
  81. package/lib/cjs/index-federation.js +55 -0
  82. package/lib/cjs/index.js +31 -0
  83. package/lib/cjs/model.js +16 -0
  84. package/lib/cjs/palette-gen.js +75 -0
  85. package/lib/cjs/palette.js +83 -0
  86. package/lib/cjs/pie-chart-model.js +114 -0
  87. package/lib/cjs/setup-tests.js +19 -0
  88. package/lib/cjs/utils.js +72 -0
  89. package/lib/env.d.js +15 -0
  90. package/lib/env.d.js.map +1 -0
  91. package/lib/getPluginModule.d.ts +6 -0
  92. package/lib/getPluginModule.d.ts.map +1 -0
  93. package/lib/getPluginModule.js +16 -0
  94. package/lib/getPluginModule.js.map +1 -0
  95. package/lib/index-federation.d.ts +1 -0
  96. package/lib/index-federation.d.ts.map +1 -0
  97. package/lib/index-federation.js +15 -0
  98. package/lib/index-federation.js.map +1 -0
  99. package/lib/index.d.ts +9 -0
  100. package/lib/index.d.ts.map +1 -0
  101. package/lib/index.js +10 -0
  102. package/lib/index.js.map +1 -0
  103. package/lib/model.d.ts +20 -0
  104. package/lib/model.d.ts.map +1 -0
  105. package/lib/model.js +15 -0
  106. package/lib/model.js.map +1 -0
  107. package/lib/palette-gen.d.ts +25 -0
  108. package/lib/palette-gen.d.ts.map +1 -0
  109. package/lib/palette-gen.js +62 -0
  110. package/lib/palette-gen.js.map +1 -0
  111. package/lib/palette.d.ts +6 -0
  112. package/lib/palette.d.ts.map +1 -0
  113. package/lib/palette.js +64 -0
  114. package/lib/palette.js.map +1 -0
  115. package/lib/pie-chart-model.d.ts +71 -0
  116. package/lib/pie-chart-model.d.ts.map +1 -0
  117. package/lib/pie-chart-model.js +71 -0
  118. package/lib/pie-chart-model.js.map +1 -0
  119. package/lib/setup-tests.d.ts +2 -0
  120. package/lib/setup-tests.d.ts.map +1 -0
  121. package/lib/setup-tests.js +17 -0
  122. package/lib/setup-tests.js.map +1 -0
  123. package/lib/utils.d.ts +7 -0
  124. package/lib/utils.d.ts.map +1 -0
  125. package/lib/utils.js +56 -0
  126. package/lib/utils.js.map +1 -0
  127. package/mf-manifest.json +321 -0
  128. package/mf-stats.json +366 -0
  129. package/package.json +53 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"palette-gen.d.ts","sourceRoot":"","sources":["../../src/palette-gen.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGnE,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAgC9D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAI/E;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAUhH;AAKD,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAExE"}
@@ -0,0 +1,62 @@
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 { getConsistentColor } from './palette';
14
+ /**
15
+ * Get line color as well as color for tooltip and legend, account for whether palette is 'categorical' or 'auto' aka generative
16
+ */ export function getSeriesColor(props) {
17
+ const { categoricalPalette, visual, muiPrimaryColor, seriesName, seriesIndex, querySettings, queryHasMultipleResults } = props;
18
+ // Use color overrides defined in query settings in priority, if applicable
19
+ if (querySettings) {
20
+ if (querySettings.colorMode === 'fixed') {
21
+ return querySettings.colorValue;
22
+ } else if (querySettings.colorMode === 'fixed-single' && !queryHasMultipleResults) {
23
+ return querySettings.colorValue;
24
+ }
25
+ }
26
+ // Fallback is unlikely to set unless echarts theme palette in charts theme provider is undefined.
27
+ const fallbackColor = Array.isArray(categoricalPalette) && categoricalPalette[0] ? categoricalPalette[0] // Needed since echarts color property isn't always an array.
28
+ : muiPrimaryColor;
29
+ // Explicit way to always cycle through classical palette instead of changing when based on number of series.
30
+ if (visual.palette?.mode === 'categorical') {
31
+ return getCategoricalPaletteColor(categoricalPalette, seriesIndex, fallbackColor);
32
+ }
33
+ return getAutoPaletteColor(seriesName, fallbackColor);
34
+ }
35
+ /**
36
+ * Get color from generative color palette, this approaches uses series name as the seed and
37
+ * allows for consistent colors across panels (when all panels use this approach).
38
+ */ export function getAutoPaletteColor(name, fallbackColor) {
39
+ // corresponds to 'Auto' in palette.kind for generative color palette
40
+ const generatedColor = getConsistentSeriesNameColor(name);
41
+ return generatedColor ?? fallbackColor;
42
+ }
43
+ /**
44
+ * Default classical qualitative palette that cycles through the colors array by index.
45
+ */ export function getCategoricalPaletteColor(palette, seriesIndex, fallbackColor) {
46
+ if (palette === undefined) {
47
+ return fallbackColor;
48
+ }
49
+ // Loop through predefined static color palette
50
+ const paletteTotalColors = palette.length ?? 1;
51
+ const paletteIndex = seriesIndex % paletteTotalColors;
52
+ // fallback color comes from echarts theme
53
+ const seriesColor = palette[paletteIndex] ?? fallbackColor;
54
+ return seriesColor;
55
+ }
56
+ /*
57
+ * Generate a consistent series name color (if series name includes 'error', it will have a red hue).
58
+ */ export function getConsistentSeriesNameColor(inputString) {
59
+ return getConsistentColor(inputString, inputString.toLowerCase().includes('error'));
60
+ }
61
+
62
+ //# sourceMappingURL=palette-gen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/palette-gen.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ChartVisualOptions, QuerySettingsOptions } from './model';\nimport { getConsistentColor } from './palette';\n\nexport interface SeriesColorProps {\n categoricalPalette: string[];\n visual: ChartVisualOptions;\n muiPrimaryColor: string;\n seriesName: string;\n seriesIndex: number;\n querySettings?: QuerySettingsOptions;\n queryHasMultipleResults?: boolean;\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 getSeriesColor(props: SeriesColorProps): string {\n const {\n categoricalPalette,\n visual,\n muiPrimaryColor,\n seriesName,\n seriesIndex,\n querySettings,\n queryHasMultipleResults,\n } = props;\n\n // Use color overrides defined in query settings in priority, if applicable\n if (querySettings) {\n if (querySettings.colorMode === 'fixed') {\n return querySettings.colorValue;\n } else if (querySettings.colorMode === 'fixed-single' && !queryHasMultipleResults) {\n return querySettings.colorValue;\n }\n }\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 // Explicit way to always cycle through classical palette instead of changing when based on number of series.\n if (visual.palette?.mode === 'categorical') {\n return getCategoricalPaletteColor(categoricalPalette, seriesIndex, fallbackColor);\n }\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\n/**\n * Default classical qualitative palette that cycles through the colors array by index.\n */\nexport function getCategoricalPaletteColor(palette: string[], seriesIndex: number, fallbackColor: string): string {\n if (palette === undefined) {\n return fallbackColor;\n }\n // Loop through predefined static color palette\n const paletteTotalColors = palette.length ?? 1;\n const paletteIndex = seriesIndex % paletteTotalColors;\n // fallback color comes from echarts theme\n const seriesColor = palette[paletteIndex] ?? fallbackColor;\n return seriesColor;\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"],"names":["getConsistentColor","getSeriesColor","props","categoricalPalette","visual","muiPrimaryColor","seriesName","seriesIndex","querySettings","queryHasMultipleResults","colorMode","colorValue","fallbackColor","Array","isArray","palette","mode","getCategoricalPaletteColor","getAutoPaletteColor","name","generatedColor","getConsistentSeriesNameColor","undefined","paletteTotalColors","length","paletteIndex","seriesColor","inputString","toLowerCase","includes"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,kBAAkB,QAAQ,YAAY;AAY/C;;CAEC,GACD,OAAO,SAASC,eAAeC,KAAuB;IACpD,MAAM,EACJC,kBAAkB,EAClBC,MAAM,EACNC,eAAe,EACfC,UAAU,EACVC,WAAW,EACXC,aAAa,EACbC,uBAAuB,EACxB,GAAGP;IAEJ,2EAA2E;IAC3E,IAAIM,eAAe;QACjB,IAAIA,cAAcE,SAAS,KAAK,SAAS;YACvC,OAAOF,cAAcG,UAAU;QACjC,OAAO,IAAIH,cAAcE,SAAS,KAAK,kBAAkB,CAACD,yBAAyB;YACjF,OAAOD,cAAcG,UAAU;QACjC;IACF;IAEA,kGAAkG;IAClG,MAAMC,gBACJC,MAAMC,OAAO,CAACX,uBAAuBA,kBAAkB,CAAC,EAAE,GACrDA,kBAAkB,CAAC,EAAE,CAAY,6DAA6D;OAC/FE;IAEN,6GAA6G;IAC7G,IAAID,OAAOW,OAAO,EAAEC,SAAS,eAAe;QAC1C,OAAOC,2BAA2Bd,oBAAoBI,aAAaK;IACrE;IAEA,OAAOM,oBAAoBZ,YAAYM;AACzC;AAEA;;;CAGC,GACD,OAAO,SAASM,oBAAoBC,IAAY,EAAEP,aAAqB;IACrE,qEAAqE;IACrE,MAAMQ,iBAAiBC,6BAA6BF;IACpD,OAAOC,kBAAkBR;AAC3B;AAEA;;CAEC,GACD,OAAO,SAASK,2BAA2BF,OAAiB,EAAER,WAAmB,EAAEK,aAAqB;IACtG,IAAIG,YAAYO,WAAW;QACzB,OAAOV;IACT;IACA,+CAA+C;IAC/C,MAAMW,qBAAqBR,QAAQS,MAAM,IAAI;IAC7C,MAAMC,eAAelB,cAAcgB;IACnC,0CAA0C;IAC1C,MAAMG,cAAcX,OAAO,CAACU,aAAa,IAAIb;IAC7C,OAAOc;AACT;AAEA;;CAEC,GACD,OAAO,SAASL,6BAA6BM,WAAmB;IAC9D,OAAO3B,mBAAmB2B,aAAaA,YAAYC,WAAW,GAAGC,QAAQ,CAAC;AAC5E"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Return a consistent color for (name, error) tuple
3
+ */
4
+ export declare function getConsistentColor(name: string, error: boolean): string;
5
+ export declare function getConsistentCategoricalColor(name: string, error: boolean, categoricalPalette: string[], errorPalette: string[]): string;
6
+ //# sourceMappingURL=palette.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"palette.d.ts","sourceRoot":"","sources":["../../src/palette.ts"],"names":[],"mappings":"AAkCA;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAQvE;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,kBAAkB,EAAE,MAAM,EAAE,EAC5B,YAAY,EAAE,MAAM,EAAE,GACrB,MAAM,CAaR"}
package/lib/palette.js ADDED
@@ -0,0 +1,64 @@
1
+ // Copyright 2024 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
+ function computeConsistentColor(name, error) {
32
+ const [hue, saturation, lightness] = error ? redColorGenerator.hsl(name) : colorGenerator.hsl(name);
33
+ const saturationPercent = `${(saturation * 100).toFixed(0)}%`;
34
+ const lightnessPercent = `${(lightness * 100).toFixed(0)}%`;
35
+ return `hsla(${hue.toFixed(2)},${saturationPercent},${lightnessPercent},0.9)`;
36
+ }
37
+ // To check whether a color has already been generated for a given string.
38
+ // TODO: Predefined color aliases will be defined here
39
+ const colorLookup = {};
40
+ /**
41
+ * Return a consistent color for (name, error) tuple
42
+ */ export function getConsistentColor(name, error) {
43
+ const key = `${name}_____${error}`;
44
+ let value = colorLookup[key];
45
+ if (!value) {
46
+ value = computeConsistentColor(name, error);
47
+ colorLookup[key] = value;
48
+ }
49
+ return value;
50
+ }
51
+ export function getConsistentCategoricalColor(name, error, categoricalPalette, errorPalette) {
52
+ const palette = error ? errorPalette : categoricalPalette;
53
+ if (palette.length === 0) {
54
+ console.warn('getConsistentCategoricalColor() called with empty color palette, fallback to #000');
55
+ return '#000';
56
+ }
57
+ let hash = 0;
58
+ for(let i = 0; i < name.length; i++){
59
+ hash = name.charCodeAt(i) + ((hash << 5) - hash);
60
+ }
61
+ return palette[Math.abs(hash) % palette.length] ?? '#000';
62
+ }
63
+
64
+ //# sourceMappingURL=palette.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/palette.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 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\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\nexport function getConsistentCategoricalColor(\n name: string,\n error: boolean,\n categoricalPalette: string[],\n errorPalette: string[]\n): string {\n const palette = error ? errorPalette : categoricalPalette;\n if (palette.length === 0) {\n console.warn('getConsistentCategoricalColor() called with empty color palette, fallback to #000');\n return '#000';\n }\n\n let hash = 0;\n for (let i = 0; i < name.length; i++) {\n hash = name.charCodeAt(i) + ((hash << 5) - hash);\n }\n\n return palette[Math.abs(hash) % palette.length] ?? '#000';\n}\n"],"names":["ColorHash","ERROR_HUE_CUTOFF","colorGenerator","hue","min","max","redColorGenerator","computeConsistentColor","name","error","saturation","lightness","hsl","saturationPercent","toFixed","lightnessPercent","colorLookup","getConsistentColor","key","value","getConsistentCategoricalColor","categoricalPalette","errorPalette","palette","length","console","warn","hash","i","charCodeAt","Math","abs"],"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,iBAAiB,IAAIF,UAAU;IAAEG,KAAK;QAAEC,KAAKH;QAAkBI,KAAK;IAAI;AAAE;AAChF,MAAMC,oBAAoB,IAAIN,UAAU;IAAEG,KAAK;QAAEC,KAAK;QAAGC,KAAKJ;IAAiB;AAAE;AAEjF,SAASM,uBAAuBC,IAAY,EAAEC,KAAc;IAC1D,MAAM,CAACN,KAAKO,YAAYC,UAAU,GAAGF,QAAQH,kBAAkBM,GAAG,CAACJ,QAAQN,eAAeU,GAAG,CAACJ;IAC9F,MAAMK,oBAAoB,GAAG,AAACH,CAAAA,aAAa,GAAE,EAAGI,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7D,MAAMC,mBAAmB,GAAG,AAACJ,CAAAA,YAAY,GAAE,EAAGG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3D,OAAO,CAAC,KAAK,EAAEX,IAAIW,OAAO,CAAC,GAAG,CAAC,EAAED,kBAAkB,CAAC,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,OAAO,SAASC,8BACdZ,IAAY,EACZC,KAAc,EACdY,kBAA4B,EAC5BC,YAAsB;IAEtB,MAAMC,UAAUd,QAAQa,eAAeD;IACvC,IAAIE,QAAQC,MAAM,KAAK,GAAG;QACxBC,QAAQC,IAAI,CAAC;QACb,OAAO;IACT;IAEA,IAAIC,OAAO;IACX,IAAK,IAAIC,IAAI,GAAGA,IAAIpB,KAAKgB,MAAM,EAAEI,IAAK;QACpCD,OAAOnB,KAAKqB,UAAU,CAACD,KAAM,CAAA,AAACD,CAAAA,QAAQ,CAAA,IAAKA,IAAG;IAChD;IAEA,OAAOJ,OAAO,CAACO,KAAKC,GAAG,CAACJ,QAAQJ,QAAQC,MAAM,CAAC,IAAI;AACrD"}
@@ -0,0 +1,71 @@
1
+ import { ModeOption, SortOption } from '@perses-dev/components';
2
+ import { CalculationType, Definition, FormatOptions } from '@perses-dev/core';
3
+ import { LegendSpecOptions, OptionsEditorProps } from '@perses-dev/plugin-system';
4
+ import { QuerySettingsOptions, StackOptions } from './model';
5
+ export declare const DEFAULT_CONNECT_NULLS = false;
6
+ export declare const POINT_SIZE_OFFSET = 1.5;
7
+ export declare const DEFAULT_FORMAT: FormatOptions;
8
+ export declare const DEFAULT_SORT: SortOption;
9
+ export declare const DEFAULT_MODE: ModeOption;
10
+ export declare const DEFAULT_LINE_WIDTH = 1.25;
11
+ export declare const DEFAULT_AREA_OPACITY = 0;
12
+ export declare const DEFAULT_POINT_RADIUS: number;
13
+ export declare const VISUAL_CONFIG: {
14
+ lineWidth: {
15
+ label: string;
16
+ testId: string;
17
+ min: number;
18
+ max: number;
19
+ step: number;
20
+ };
21
+ pointRadius: {
22
+ label: string;
23
+ testId: string;
24
+ min: number;
25
+ max: number;
26
+ step: number;
27
+ };
28
+ areaOpacity: {
29
+ label: string;
30
+ testId: string;
31
+ min: number;
32
+ max: number;
33
+ step: number;
34
+ };
35
+ stack: {
36
+ label: string;
37
+ };
38
+ connectNulls: {
39
+ label: string;
40
+ };
41
+ };
42
+ export interface BarChartDefinition extends Definition<PieChartOptions> {
43
+ kind: 'PieChart';
44
+ }
45
+ export declare const DEFAULT_VISUAL: PieChartVisualOptions;
46
+ export interface PieChartPaletteOptions {
47
+ mode: 'auto' | 'categorical';
48
+ }
49
+ export interface PieChartOptions {
50
+ legend?: LegendSpecOptions;
51
+ visual?: PieChartVisualOptions;
52
+ querySettings?: QuerySettingsOptions[];
53
+ calculation: CalculationType;
54
+ radius: number;
55
+ format?: FormatOptions;
56
+ sort?: SortOption;
57
+ mode?: ModeOption;
58
+ }
59
+ export type PieChartVisualOptions = {
60
+ display?: 'line' | 'bar';
61
+ lineWidth?: number;
62
+ areaOpacity?: number;
63
+ showPoints?: 'auto' | 'always';
64
+ palette?: PieChartPaletteOptions;
65
+ pointRadius?: number;
66
+ stack?: StackOptions;
67
+ connectNulls?: boolean;
68
+ };
69
+ export type PieChartOptionsEditorProps = OptionsEditorProps<PieChartOptions>;
70
+ export declare function createInitialPieChartOptions(): PieChartOptions;
71
+ //# sourceMappingURL=pie-chart-model.d.ts.map
@@ -0,0 +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,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE7D,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAC3C,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,cAAc,EAAE,aAAsD,CAAC;AACpF,eAAO,MAAM,YAAY,EAAE,UAAmB,CAAC;AAC/C,eAAO,MAAM,YAAY,EAAE,UAAoB,CAAC;AAChD,eAAO,MAAM,kBAAkB,OAAO,CAAC;AACvC,eAAO,MAAM,oBAAoB,IAAI,CAAC;AACtC,eAAO,MAAM,oBAAoB,QAAyC,CAAC;AAE3E,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BzB,CAAC;AAEF,MAAM,WAAW,kBAAmB,SAAQ,UAAU,CAAC,eAAe,CAAC;IACrE,IAAI,EAAE,UAAU,CAAC;CAClB;AACD,eAAO,MAAM,cAAc,EAAE,qBAK5B,CAAC;AACF,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC;CAC9B;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,aAAa,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACvC,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC/B,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAAC;AAE7E,wBAAgB,4BAA4B,IAAI,eAAe,CAS9D"}
@@ -0,0 +1,71 @@
1
+ // Copyright 2024 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 { DEFAULT_CALCULATION } from '@perses-dev/core';
14
+ export const DEFAULT_CONNECT_NULLS = false;
15
+ export const POINT_SIZE_OFFSET = 1.5;
16
+ export const DEFAULT_FORMAT = {
17
+ unit: 'decimal',
18
+ shortValues: true
19
+ };
20
+ export const DEFAULT_SORT = 'desc';
21
+ export const DEFAULT_MODE = 'value';
22
+ export const DEFAULT_LINE_WIDTH = 1.25;
23
+ export const DEFAULT_AREA_OPACITY = 0;
24
+ export const DEFAULT_POINT_RADIUS = DEFAULT_LINE_WIDTH + POINT_SIZE_OFFSET;
25
+ export const VISUAL_CONFIG = {
26
+ lineWidth: {
27
+ label: 'Line Width',
28
+ testId: 'slider-line-width',
29
+ min: 0.25,
30
+ max: 3,
31
+ step: 0.25
32
+ },
33
+ pointRadius: {
34
+ label: 'Point Radius',
35
+ testId: 'slider-point-radius',
36
+ min: 0,
37
+ max: 6,
38
+ step: 0.25
39
+ },
40
+ areaOpacity: {
41
+ label: 'Area Opacity',
42
+ testId: 'slider-area-opacity',
43
+ min: 0,
44
+ max: 1,
45
+ step: 0.05
46
+ },
47
+ stack: {
48
+ label: 'Stack Series'
49
+ },
50
+ connectNulls: {
51
+ label: 'Connect Nulls'
52
+ }
53
+ };
54
+ export const DEFAULT_VISUAL = {
55
+ lineWidth: DEFAULT_LINE_WIDTH,
56
+ areaOpacity: DEFAULT_AREA_OPACITY,
57
+ pointRadius: DEFAULT_POINT_RADIUS,
58
+ connectNulls: DEFAULT_CONNECT_NULLS
59
+ };
60
+ export function createInitialPieChartOptions() {
61
+ return {
62
+ calculation: DEFAULT_CALCULATION,
63
+ format: DEFAULT_FORMAT,
64
+ radius: 50,
65
+ sort: DEFAULT_SORT,
66
+ mode: DEFAULT_MODE,
67
+ visual: DEFAULT_VISUAL
68
+ };
69
+ }
70
+
71
+ //# sourceMappingURL=pie-chart-model.js.map
@@ -0,0 +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\nimport { QuerySettingsOptions, StackOptions } from './model';\n\nexport const DEFAULT_CONNECT_NULLS = false;\nexport const POINT_SIZE_OFFSET = 1.5;\nexport const DEFAULT_FORMAT: FormatOptions = { unit: 'decimal', shortValues: true };\nexport const DEFAULT_SORT: SortOption = 'desc';\nexport const DEFAULT_MODE: ModeOption = 'value';\nexport const DEFAULT_LINE_WIDTH = 1.25;\nexport const DEFAULT_AREA_OPACITY = 0;\nexport const DEFAULT_POINT_RADIUS = DEFAULT_LINE_WIDTH + POINT_SIZE_OFFSET;\n\nexport const VISUAL_CONFIG = {\n lineWidth: {\n label: 'Line Width',\n testId: 'slider-line-width',\n min: 0.25,\n max: 3,\n step: 0.25,\n },\n pointRadius: {\n label: 'Point Radius',\n testId: 'slider-point-radius',\n min: 0,\n max: 6,\n step: 0.25,\n },\n areaOpacity: {\n label: 'Area Opacity',\n testId: 'slider-area-opacity',\n min: 0,\n max: 1,\n step: 0.05,\n },\n stack: {\n label: 'Stack Series',\n },\n connectNulls: {\n label: 'Connect Nulls',\n },\n};\n\nexport interface BarChartDefinition extends Definition<PieChartOptions> {\n kind: 'PieChart';\n}\nexport const DEFAULT_VISUAL: PieChartVisualOptions = {\n lineWidth: DEFAULT_LINE_WIDTH,\n areaOpacity: DEFAULT_AREA_OPACITY,\n pointRadius: DEFAULT_POINT_RADIUS,\n connectNulls: DEFAULT_CONNECT_NULLS,\n};\nexport interface PieChartPaletteOptions {\n mode: 'auto' | 'categorical';\n}\n\nexport interface PieChartOptions {\n legend?: LegendSpecOptions;\n visual?: PieChartVisualOptions;\n querySettings?: QuerySettingsOptions[];\n calculation: CalculationType;\n radius: number;\n format?: FormatOptions;\n sort?: SortOption;\n mode?: ModeOption;\n}\n\nexport type PieChartVisualOptions = {\n display?: 'line' | 'bar';\n lineWidth?: number;\n areaOpacity?: number;\n showPoints?: 'auto' | 'always';\n palette?: PieChartPaletteOptions;\n pointRadius?: number;\n stack?: StackOptions;\n connectNulls?: boolean;\n};\n\nexport type PieChartOptionsEditorProps = OptionsEditorProps<PieChartOptions>;\n\nexport function createInitialPieChartOptions(): PieChartOptions {\n return {\n calculation: DEFAULT_CALCULATION,\n format: DEFAULT_FORMAT,\n radius: 50,\n sort: DEFAULT_SORT,\n mode: DEFAULT_MODE,\n visual: DEFAULT_VISUAL,\n };\n}\n"],"names":["DEFAULT_CALCULATION","DEFAULT_CONNECT_NULLS","POINT_SIZE_OFFSET","DEFAULT_FORMAT","unit","shortValues","DEFAULT_SORT","DEFAULT_MODE","DEFAULT_LINE_WIDTH","DEFAULT_AREA_OPACITY","DEFAULT_POINT_RADIUS","VISUAL_CONFIG","lineWidth","label","testId","min","max","step","pointRadius","areaOpacity","stack","connectNulls","DEFAULT_VISUAL","createInitialPieChartOptions","calculation","format","radius","sort","mode","visual"],"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;AAKnG,OAAO,MAAMC,wBAAwB,MAAM;AAC3C,OAAO,MAAMC,oBAAoB,IAAI;AACrC,OAAO,MAAMC,iBAAgC;IAAEC,MAAM;IAAWC,aAAa;AAAK,EAAE;AACpF,OAAO,MAAMC,eAA2B,OAAO;AAC/C,OAAO,MAAMC,eAA2B,QAAQ;AAChD,OAAO,MAAMC,qBAAqB,KAAK;AACvC,OAAO,MAAMC,uBAAuB,EAAE;AACtC,OAAO,MAAMC,uBAAuBF,qBAAqBN,kBAAkB;AAE3E,OAAO,MAAMS,gBAAgB;IAC3BC,WAAW;QACTC,OAAO;QACPC,QAAQ;QACRC,KAAK;QACLC,KAAK;QACLC,MAAM;IACR;IACAC,aAAa;QACXL,OAAO;QACPC,QAAQ;QACRC,KAAK;QACLC,KAAK;QACLC,MAAM;IACR;IACAE,aAAa;QACXN,OAAO;QACPC,QAAQ;QACRC,KAAK;QACLC,KAAK;QACLC,MAAM;IACR;IACAG,OAAO;QACLP,OAAO;IACT;IACAQ,cAAc;QACZR,OAAO;IACT;AACF,EAAE;AAKF,OAAO,MAAMS,iBAAwC;IACnDV,WAAWJ;IACXW,aAAaV;IACbS,aAAaR;IACbW,cAAcpB;AAChB,EAAE;AA6BF,OAAO,SAASsB;IACd,OAAO;QACLC,aAAaxB;QACbyB,QAAQtB;QACRuB,QAAQ;QACRC,MAAMrB;QACNsB,MAAMrB;QACNsB,QAAQP;IACV;AACF"}
@@ -0,0 +1,2 @@
1
+ import '@testing-library/jest-dom';
2
+ //# sourceMappingURL=setup-tests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-tests.d.ts","sourceRoot":"","sources":["../../src/setup-tests.ts"],"names":[],"mappings":"AAaA,OAAO,2BAA2B,CAAC"}
@@ -0,0 +1,17 @@
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 '@testing-library/jest-dom';
14
+ // Always mock e-charts during tests since we don't have a proper canvas in jsdom
15
+ jest.mock('echarts/core');
16
+
17
+ //# sourceMappingURL=setup-tests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/setup-tests.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 '@testing-library/jest-dom';\n\n// Always mock e-charts during tests since we don't have a proper canvas in jsdom\njest.mock('echarts/core');\n"],"names":["jest","mock"],"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,OAAO,4BAA4B;AAEnC,iFAAiF;AACjFA,KAAKC,IAAI,CAAC"}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { PieChartData, SortOption } from '@perses-dev/components';
2
+ export declare function calculatePercentages(data: PieChartData[]): Array<{
3
+ name: string;
4
+ value: number;
5
+ }>;
6
+ export declare function sortSeriesData(data: PieChartData[], sortOrder?: SortOption): PieChartData[];
7
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGlE,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CASjG;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,SAAS,GAAE,UAAyB,GAAG,YAAY,EAAE,CA8BzG"}
package/lib/utils.js ADDED
@@ -0,0 +1,56 @@
1
+ // Copyright 2024 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 { DEFAULT_SORT } from './pie-chart-model';
14
+ export function calculatePercentages(data) {
15
+ const sum = data.reduce((accumulator, { value })=>accumulator + (value ?? 0), 0);
16
+ return data.map((seriesData)=>{
17
+ const percentage = (seriesData.value ?? 0) / sum * 100;
18
+ return {
19
+ ...seriesData,
20
+ value: percentage
21
+ };
22
+ });
23
+ }
24
+ export function sortSeriesData(data, sortOrder = DEFAULT_SORT) {
25
+ if (sortOrder === 'asc') {
26
+ // sort in ascending order by value
27
+ return data.sort((a, b)=>{
28
+ if (a.value === null) {
29
+ return 1;
30
+ }
31
+ if (b.value === null) {
32
+ return -1;
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
+ }
54
+ }
55
+
56
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +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 { PieChartData, SortOption } from '@perses-dev/components';\nimport { DEFAULT_SORT } from './pie-chart-model';\n\nexport function calculatePercentages(data: PieChartData[]): Array<{ 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 if (sortOrder === 'asc') {\n // sort in ascending order by value\n return data.sort((a, b) => {\n if (a.value === null) {\n return 1;\n }\n if (b.value === null) {\n return -1;\n }\n if (a.value === b.value) {\n return 0;\n }\n return a.value < b.value ? 1 : -1;\n });\n } else {\n // sort in descending order by value\n return data.sort((a, b) => {\n if (a.value === null) {\n return -1;\n }\n if (b.value === null) {\n return 1;\n }\n if (a.value === b.value) {\n return 0;\n }\n return a.value < b.value ? -1 : 1;\n });\n }\n}\n"],"names":["DEFAULT_SORT","calculatePercentages","data","sum","reduce","accumulator","value","map","seriesData","percentage","sortSeriesData","sortOrder","sort","a","b"],"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;AAEjD,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,OAAOG;QACT;IACF;AACF;AAEA,OAAO,SAASC,eAAeR,IAAoB,EAAES,YAAwBX,YAAY;IACvF,IAAIW,cAAc,OAAO;QACvB,mCAAmC;QACnC,OAAOT,KAAKU,IAAI,CAAC,CAACC,GAAGC;YACnB,IAAID,EAAEP,KAAK,KAAK,MAAM;gBACpB,OAAO;YACT;YACA,IAAIQ,EAAER,KAAK,KAAK,MAAM;gBACpB,OAAO,CAAC;YACV;YACA,IAAIO,EAAEP,KAAK,KAAKQ,EAAER,KAAK,EAAE;gBACvB,OAAO;YACT;YACA,OAAOO,EAAEP,KAAK,GAAGQ,EAAER,KAAK,GAAG,IAAI,CAAC;QAClC;IACF,OAAO;QACL,oCAAoC;QACpC,OAAOJ,KAAKU,IAAI,CAAC,CAACC,GAAGC;YACnB,IAAID,EAAEP,KAAK,KAAK,MAAM;gBACpB,OAAO,CAAC;YACV;YACA,IAAIQ,EAAER,KAAK,KAAK,MAAM;gBACpB,OAAO;YACT;YACA,IAAIO,EAAEP,KAAK,KAAKQ,EAAER,KAAK,EAAE;gBACvB,OAAO;YACT;YACA,OAAOO,EAAEP,KAAK,GAAGQ,EAAER,KAAK,GAAG,CAAC,IAAI;QAClC;IACF;AACF"}