@perses-dev/pie-chart-plugin 0.6.0 → 0.7.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/js/{693.77ca36d8.js → 693.bfc02377.js} +1 -1
- package/__mf/js/{PieChart.9e5c2bf5.js → PieChart.84baed80.js} +3 -3
- package/__mf/js/async/470.9e513ba5.js +2 -0
- package/__mf/js/async/{610.8c8cf7f2.js → 610.0d00ec39.js} +1 -1
- package/__mf/js/async/658.78ccd02d.js +1 -0
- package/__mf/js/async/__federation_expose_PieChart.5f41b08c.js +1 -0
- package/__mf/js/main.8157a179.js +1 -0
- package/lib/PieChartBase.d.ts +14 -0
- package/lib/PieChartBase.d.ts.map +1 -0
- package/lib/PieChartBase.js +92 -0
- package/lib/PieChartBase.js.map +1 -0
- package/lib/PieChartPanel.d.ts.map +1 -1
- package/lib/PieChartPanel.js +6 -27
- package/lib/PieChartPanel.js.map +1 -1
- package/lib/cjs/PieChartBase.js +100 -0
- package/lib/cjs/PieChartPanel.js +5 -26
- package/lib/cjs/palette-gen.js +1 -13
- package/lib/cjs/pie-chart-model.js +1 -63
- package/lib/palette-gen.d.ts +0 -5
- package/lib/palette-gen.d.ts.map +1 -1
- package/lib/palette-gen.js +1 -13
- package/lib/palette-gen.js.map +1 -1
- package/lib/pie-chart-model.d.ts +0 -51
- package/lib/pie-chart-model.d.ts.map +1 -1
- package/lib/pie-chart-model.js +1 -42
- package/lib/pie-chart-model.js.map +1 -1
- package/mf-manifest.json +10 -8
- package/mf-stats.json +10 -8
- package/package.json +1 -1
- package/__mf/js/async/996.9e160813.js +0 -2
- package/__mf/js/async/__federation_expose_PieChart.f03b1180.js +0 -1
- package/__mf/js/main.518abb8d.js +0 -1
- /package/__mf/js/async/{996.9e160813.js.LICENSE.txt → 470.9e513ba5.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{var e={5311:function(e,r,t){Promise.all([t.e("677"),t.e("179"),t.e("620")]).then(t.bind(t,29161))}},r={};function t(n){var o=r[n];if(void 0!==o)return o.exports;var a=r[n]={id:n,loaded:!1,exports:{}};return e[n].call(a.exports,a,a.exports,t),a.loaded=!0,a.exports}t.m=e,t.c=r,t.federation||(t.federation={chunkMatcher:function(e){return!/^(1(57|61|79)|23|263|494|677|759|946)$/.test(e)}}),t.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return t.d(r,{a:r}),r},t.d=(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},t.f={},t.e=e=>Promise.all(Object.keys(t.f).reduce((r,n)=>(t.f[n](e,r),r),[])),t.u=e=>"__mf/js/async/"+("118"===e?"lib-router":e)+"."+({118:"d29f3ef0",162:"668ea958",173:"ee70b493",214:"df2e7807",224:"dbeed4db",238:"5287310b",292:"f278784e",331:"a0d6355f",36:"ac56ec70",360:"fdc4e499",470:"9e513ba5",610:"0d00ec39",620:"9a73a66b",651:"a1042e18",656:"5efccb26",658:"78ccd02d",694:"b227b636",738:"4ac98841",740:"b86dfa00",75:"905151a5",770:"93415255",960:"208437e1",964:"6df60c3e",973:"74031340",981:"3ecbf5ea"})[e]+".js",t.miniCssF=e=>"__mf/css/async/"+e+"."+({263:"80005a4a",759:"80005a4a"})[e]+".css",t.h=()=>"6071bda2ea737d6a",(()=>{t.g=(()=>{if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}})()})(),t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={},r="PieChart:";t.l=function(n,o,a,i){if(e[n]){e[n].push(o);return}if(void 0!==a)for(var s,l,d=document.getElementsByTagName("script"),c=0;c<d.length;c++){var u=d[c];if(u.getAttribute("src")==n||u.getAttribute("data-webpack")==r+a){s=u;break}}s||(l=!0,(s=document.createElement("script")).charset="utf-8",s.timeout=120,t.nc&&s.setAttribute("nonce",t.nc),s.setAttribute("data-webpack",r+a),s.src=n),e[n]=[o];var f=function(r,t){s.onerror=s.onload=null,clearTimeout(h);var o=e[n];if(delete e[n],s.parentNode&&s.parentNode.removeChild(s),o&&o.forEach(function(e){return e(t)}),r)return r(t)},h=setTimeout(f.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=f.bind(null,s.onerror),s.onload=f.bind(null,s.onload),l&&document.head.appendChild(s)}})(),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),t.nc=void 0,(()=>{var e=[];t.O=(r,n,o,a)=>{if(n){a=a||0;for(var i=e.length;i>0&&e[i-1][2]>a;i--)e[i]=e[i-1];e[i]=[n,o,a];return}for(var s=1/0,i=0;i<e.length;i++){for(var[n,o,a]=e[i],l=!0,d=0;d<n.length;d++)(!1&a||s>=a)&&Object.keys(t.O).every(e=>t.O[e](n[d]))?n.splice(d--,1):(l=!1,a<s&&(s=a));if(l){e.splice(i--,1);var c=o();void 0!==c&&(r=c)}}return r}})(),t.p="/plugins/PieChart/",t.rv=()=>"1.2.8",t.j="909",t.S={},t.initializeSharingData={scopeToSharingDataMapping:{default:[{name:"@emotion/react",version:"11.14.0",factory:()=>Promise.all([t.e("960"),t.e("677"),t.e("651")]).then(()=>()=>t(96434)),eager:0,singleton:1,requiredVersion:"^11.11.3"},{name:"@emotion/styled",version:"11.14.0",factory:()=>Promise.all([t.e("677"),t.e("157"),t.e("694")]).then(()=>()=>t(51958)),eager:0,singleton:1},{name:"@hookform/resolvers",version:"3.10.0",factory:()=>Promise.all([t.e("292"),t.e("677"),t.e("214")]).then(()=>()=>t(81228)),eager:0,singleton:1},{name:"@perses-dev/components",version:"0.51.0-beta.1",factory:()=>Promise.all([t.e("238"),t.e("224"),t.e("292"),t.e("470"),t.e("36"),t.e("658"),t.e("360"),t.e("973"),t.e("331"),t.e("677"),t.e("179"),t.e("161"),t.e("157"),t.e("946"),t.e("759")]).then(()=>()=>t(13425)),eager:0,singleton:1},{name:"@perses-dev/plugin-system",version:"0.51.0-beta.1",factory:()=>Promise.all([t.e("118"),t.e("292"),t.e("36"),t.e("973"),t.e("162"),t.e("677"),t.e("179"),t.e("161"),t.e("157"),t.e("946"),t.e("23"),t.e("656")]).then(()=>()=>t(57910)),eager:0,singleton:1},{name:"date-fns",version:"4.1.0",factory:()=>Promise.all([t.e("238"),t.e("224"),t.e("75")]).then(()=>()=>t(99657)),eager:0,singleton:1},{name:"echarts",version:"5.5.0",factory:()=>Promise.all([t.e("470"),t.e("658"),t.e("610")]).then(()=>()=>t(2138)),eager:0,singleton:1},{name:"lodash",version:"4.17.21",factory:()=>t.e("981").then(()=>()=>t(98784)),eager:0,singleton:1},{name:"react-dom",version:"18.3.1",factory:()=>Promise.all([t.e("173"),t.e("677")]).then(()=>()=>t(31542)),eager:0,singleton:1,requiredVersion:"18.2.0"},{name:"react",version:"18.3.1",factory:()=>t.e("964").then(()=>()=>t(27378)),eager:0,singleton:1,requiredVersion:"18.2.0"}]},uniqueName:"PieChart"},t.I=t.I||function(){throw Error("should have __webpack_require__.I")},t.consumesLoadingData={chunkMapping:{161:["4665","20461"],494:["57871"],946:["45913"],179:["6085"],157:["72116"],23:["84275","74614","30156","3553","55922","57751","68393"],677:["54538"]},moduleIdToConsumeDataMapping:{45913:{shareScope:"default",shareKey:"@emotion/styled",import:"@emotion/styled",requiredVersion:"^11.3.0",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>t.e("770").then(()=>()=>t(51958))},57751:{shareScope:"default",shareKey:"@perses-dev/plugin-system",import:"@perses-dev/plugin-system",requiredVersion:"*",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>()=>t(57910)},68393:{shareScope:"default",shareKey:"@perses-dev/components",import:"@perses-dev/components",requiredVersion:"0.51.0-beta.1",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>Promise.all([t.e("238"),t.e("224"),t.e("470"),t.e("658"),t.e("360"),t.e("331"),t.e("263")]).then(()=>()=>t(13425))},30156:{shareScope:"default",shareKey:"echarts",import:"echarts",requiredVersion:"*",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>Promise.all([t.e("470"),t.e("658"),t.e("610")]).then(()=>()=>t(2138))},6085:{shareScope:"default",shareKey:"react-dom",import:"react-dom",requiredVersion:"18.2.0",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>t.e("173").then(()=>()=>t(31542))},72116:{shareScope:"default",shareKey:"@emotion/react",import:"@emotion/react",requiredVersion:"^11.11.3",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>t.e("960").then(()=>()=>t(96434))},57871:{shareScope:"default",shareKey:"date-fns",import:"date-fns",requiredVersion:"^3.0.0 || ^4.0.0",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>Promise.all([t.e("238"),t.e("75")]).then(()=>()=>t(99657))},84275:{shareScope:"default",shareKey:"@hookform/resolvers",import:"@hookform/resolvers",requiredVersion:"^2.0.0",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>t.e("738").then(()=>()=>t(81228))},74614:{shareScope:"default",shareKey:"lodash",import:"lodash",requiredVersion:"*",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>t.e("981").then(()=>()=>t(98784))},4665:{shareScope:"default",shareKey:"date-fns-tz",import:"date-fns-tz",requiredVersion:"^3.2.0",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>Promise.all([t.e("224"),t.e("740"),t.e("494")]).then(()=>()=>t(48872))},54538:{shareScope:"default",shareKey:"react",import:"react",requiredVersion:"18.2.0",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>t.e("964").then(()=>()=>t(27378))},3553:{shareScope:"default",shareKey:"@perses-dev/plugin-system",import:"@perses-dev/plugin-system",requiredVersion:"0.51.0-beta.1",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>()=>t(57910)},55922:{shareScope:"default",shareKey:"@emotion/styled",import:"@emotion/styled",requiredVersion:"*",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>t.e("770").then(()=>()=>t(51958))},20461:{shareScope:"default",shareKey:"date-fns",import:"date-fns",requiredVersion:"^4.1.0",strictVersion:!1,singleton:!0,eager:!1,fallback:()=>Promise.all([t.e("238"),t.e("224"),t.e("75")]).then(()=>()=>t(99657))}},initialConsumes:[]},t.f.consumes=t.f.consumes||function(){throw Error("should have __webpack_require__.f.consumes")},(()=>{if("undefined"!=typeof document){var e=function(e,r,n,o,a){var i=document.createElement("link");return i.rel="stylesheet",i.type="text/css",t.nc&&(i.nonce=t.nc),i.onerror=i.onload=function(t){if(i.onerror=i.onload=null,"load"===t.type)o();else{var n=t&&("load"===t.type?"missing":t.type),s=t&&t.target&&t.target.href||r,l=Error("Loading CSS chunk "+e+" failed.\\n("+s+")");l.code="CSS_CHUNK_LOAD_FAILED",l.type=n,l.request=s,i.parentNode&&i.parentNode.removeChild(i),a(l)}},i.href=r,n?n.parentNode.insertBefore(i,n.nextSibling):document.head.appendChild(i),i},r=function(e,r){for(var t=document.getElementsByTagName("link"),n=0;n<t.length;n++){var o=t[n],a=o.getAttribute("data-href")||o.getAttribute("href");if("stylesheet"===o.rel&&(a===e||a===r))return o}for(var i=document.getElementsByTagName("style"),n=0;n<i.length;n++){var o=i[n],a=o.getAttribute("data-href");if(a===e||a===r)return o}},n={909:0};t.f.miniCss=function(o,a){if(n[o])a.push(n[o]);else if(0!==n[o]&&({263:1,759:1})[o])a.push(n[o]=new Promise(function(n,a){var i=t.miniCssF(o),s=t.p+i;if(r(i,s))return n();e(o,s,null,n,a)}).then(function(){n[o]=0},function(e){throw delete n[o],e}))}}})(),(()=>{var e={909:0};t.f.j=function(r,n){var o=t.o(e,r)?e[r]:void 0;if(0!==o){if(o)n.push(o[2]);else if(/^(1(57|61|79)|23|263|494|677|759|946)$/.test(r))e[r]=0;else{var a=new Promise((t,n)=>o=e[r]=[t,n]);n.push(o[2]=a);var i=t.p+t.u(r),s=Error();t.l(i,function(n){if(t.o(e,r)&&(0!==(o=e[r])&&(e[r]=void 0),o)){var a=n&&("load"===n.type?"missing":n.type),i=n&&n.target&&n.target.src;s.message="Loading chunk "+r+" failed.\n("+a+": "+i+")",s.name="ChunkLoadError",s.type=a,s.request=i,o[1](s)}},"chunk-"+r,r)}}},t.O.j=r=>0===e[r];var r=(r,n)=>{var o,a,[i,s,l]=n,d=0;if(i.some(r=>0!==e[r])){for(o in s)t.o(s,o)&&(t.m[o]=s[o]);if(l)var c=l(t)}for(r&&r(n);d<i.length;d++)a=i[d],t.o(e,a)&&e[a]&&e[a][0](),e[a]=0;return t.O(c)},n=self.webpackChunkPieChart=self.webpackChunkPieChart||[];n.forEach(r.bind(null,0)),n.push=r.bind(null,n.push.bind(n))})(),t.ruid="bundler=rspack@1.2.8",t.O(void 0,["693"],function(){return t(18955)});var n=t.O(void 0,["693"],function(){return t(5311)});n=t.O(n)})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LegendComponentOption } from 'echarts/components';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
|
+
export interface PieChartData {
|
|
4
|
+
name: string;
|
|
5
|
+
value: number | null;
|
|
6
|
+
}
|
|
7
|
+
export interface PieChartBaseProps {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
data: PieChartData[] | null;
|
|
11
|
+
legend?: LegendComponentOption;
|
|
12
|
+
}
|
|
13
|
+
export declare function PieChartBase(props: PieChartBaseProps): ReactElement;
|
|
14
|
+
//# sourceMappingURL=PieChartBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PieChartBase.d.ts","sourceRoot":"","sources":["../../src/PieChartBase.tsx"],"names":[],"mappings":"AAeA,OAAO,EAKL,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAOrC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAC5B,MAAM,CAAC,EAAE,qBAAqB,CAAC;CAChC;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CA4DnE"}
|
|
@@ -0,0 +1,92 @@
|
|
|
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 { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { use } from 'echarts/core';
|
|
15
|
+
import { PieChart as EChartsPieChart } from 'echarts/charts';
|
|
16
|
+
import { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';
|
|
17
|
+
import { CanvasRenderer } from 'echarts/renderers';
|
|
18
|
+
import { Box } from '@mui/material';
|
|
19
|
+
import { EChart, useChartsTheme } from '@perses-dev/components';
|
|
20
|
+
use([
|
|
21
|
+
EChartsPieChart,
|
|
22
|
+
GridComponent,
|
|
23
|
+
DatasetComponent,
|
|
24
|
+
TitleComponent,
|
|
25
|
+
TooltipComponent,
|
|
26
|
+
CanvasRenderer
|
|
27
|
+
]);
|
|
28
|
+
const PIE_WIN_WIDTH = 12;
|
|
29
|
+
const PIE_GAP = 4;
|
|
30
|
+
export function PieChartBase(props) {
|
|
31
|
+
console.log(props);
|
|
32
|
+
const { width, height, data } = props;
|
|
33
|
+
const chartsTheme = useChartsTheme();
|
|
34
|
+
const option = {
|
|
35
|
+
title: {
|
|
36
|
+
text: 'Referer of a Website',
|
|
37
|
+
subtext: 'Fake Data',
|
|
38
|
+
left: 'center'
|
|
39
|
+
},
|
|
40
|
+
tooltip: {
|
|
41
|
+
trigger: 'item',
|
|
42
|
+
formatter: '{a} <br/>{b} : {c} ({d}%)'
|
|
43
|
+
},
|
|
44
|
+
axisLabel: {
|
|
45
|
+
overflow: 'truncate',
|
|
46
|
+
width: width / 3
|
|
47
|
+
},
|
|
48
|
+
series: [
|
|
49
|
+
{
|
|
50
|
+
name: 'Access From',
|
|
51
|
+
type: 'pie',
|
|
52
|
+
radius: '55%',
|
|
53
|
+
label: false,
|
|
54
|
+
center: [
|
|
55
|
+
'40%',
|
|
56
|
+
'50%'
|
|
57
|
+
],
|
|
58
|
+
data: data,
|
|
59
|
+
emphasis: {
|
|
60
|
+
itemStyle: {
|
|
61
|
+
shadowBlur: 10,
|
|
62
|
+
shadowOffsetX: 0,
|
|
63
|
+
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
itemStyle: {
|
|
69
|
+
borderRadius: 2,
|
|
70
|
+
color: chartsTheme.echartsTheme[0]
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
return /*#__PURE__*/ _jsx(Box, {
|
|
74
|
+
style: {
|
|
75
|
+
width: width,
|
|
76
|
+
height: height
|
|
77
|
+
},
|
|
78
|
+
sx: {
|
|
79
|
+
overflow: 'auto'
|
|
80
|
+
},
|
|
81
|
+
children: /*#__PURE__*/ _jsx(EChart, {
|
|
82
|
+
sx: {
|
|
83
|
+
minHeight: height,
|
|
84
|
+
height: data ? data.length * (PIE_WIN_WIDTH + PIE_GAP) : '100%'
|
|
85
|
+
},
|
|
86
|
+
option: option,
|
|
87
|
+
theme: chartsTheme.echartsTheme
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=PieChartBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/PieChartBase.tsx"],"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 { use } from 'echarts/core';\nimport { PieChart as EChartsPieChart } from 'echarts/charts';\nimport {\n GridComponent,\n DatasetComponent,\n TitleComponent,\n TooltipComponent,\n LegendComponentOption,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { Box } from '@mui/material';\nimport { ReactElement } from 'react';\nimport { EChart, useChartsTheme } from '@perses-dev/components';\n\nuse([EChartsPieChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst PIE_WIN_WIDTH = 12;\nconst PIE_GAP = 4;\nexport interface PieChartData {\n name: string;\n value: number | null;\n}\n\nexport interface PieChartBaseProps {\n width: number;\n height: number;\n data: PieChartData[] | null;\n legend?: LegendComponentOption;\n}\n\nexport function PieChartBase(props: PieChartBaseProps): ReactElement {\n console.log(props);\n const { width, height, data } = props;\n const chartsTheme = useChartsTheme();\n\n const option = {\n title: {\n text: 'Referer of a Website',\n subtext: 'Fake Data',\n left: 'center',\n },\n tooltip: {\n trigger: 'item',\n formatter: '{a} <br/>{b} : {c} ({d}%)',\n },\n axisLabel: {\n overflow: 'truncate',\n width: width / 3,\n },\n series: [\n {\n name: 'Access From',\n type: 'pie',\n radius: '55%',\n label: false,\n center: ['40%', '50%'],\n data: data,\n emphasis: {\n itemStyle: {\n shadowBlur: 10,\n shadowOffsetX: 0,\n shadowColor: 'rgba(0, 0, 0, 0.5)',\n },\n },\n },\n ],\n itemStyle: {\n borderRadius: 2,\n color: chartsTheme.echartsTheme[0],\n },\n };\n\n return (\n <Box\n style={{\n width: width,\n height: height,\n }}\n sx={{ overflow: 'auto' }}\n >\n <EChart\n sx={{\n minHeight: height,\n height: data ? data.length * (PIE_WIN_WIDTH + PIE_GAP) : '100%',\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n />\n </Box>\n );\n}\n"],"names":["use","PieChart","EChartsPieChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","Box","EChart","useChartsTheme","PIE_WIN_WIDTH","PIE_GAP","PieChartBase","props","console","log","width","height","data","chartsTheme","option","title","text","subtext","left","tooltip","trigger","formatter","axisLabel","overflow","series","name","type","radius","label","center","emphasis","itemStyle","shadowBlur","shadowOffsetX","shadowColor","borderRadius","color","echartsTheme","style","sx","minHeight","length","theme"],"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,GAAG,QAAQ,eAAe;AACnC,SAASC,YAAYC,eAAe,QAAQ,iBAAiB;AAC7D,SACEC,aAAa,EACbC,gBAAgB,EAChBC,cAAc,EACdC,gBAAgB,QAEX,qBAAqB;AAC5B,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,GAAG,QAAQ,gBAAgB;AAEpC,SAASC,MAAM,EAAEC,cAAc,QAAQ,yBAAyB;AAEhEV,IAAI;IAACE;IAAiBC;IAAeC;IAAkBC;IAAgBC;IAAkBC;CAAe;AAExG,MAAMI,gBAAgB;AACtB,MAAMC,UAAU;AAahB,OAAO,SAASC,aAAaC,KAAwB;IACnDC,QAAQC,GAAG,CAACF;IACZ,MAAM,EAAEG,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAE,GAAGL;IAChC,MAAMM,cAAcV;IAEpB,MAAMW,SAAS;QACbC,OAAO;YACLC,MAAM;YACNC,SAAS;YACTC,MAAM;QACR;QACAC,SAAS;YACPC,SAAS;YACTC,WAAW;QACb;QACAC,WAAW;YACTC,UAAU;YACVb,OAAOA,QAAQ;QACjB;QACAc,QAAQ;YACN;gBACEC,MAAM;gBACNC,MAAM;gBACNC,QAAQ;gBACRC,OAAO;gBACPC,QAAQ;oBAAC;oBAAO;iBAAM;gBACtBjB,MAAMA;gBACNkB,UAAU;oBACRC,WAAW;wBACTC,YAAY;wBACZC,eAAe;wBACfC,aAAa;oBACf;gBACF;YACF;SACD;QACDH,WAAW;YACTI,cAAc;YACdC,OAAOvB,YAAYwB,YAAY,CAAC,EAAE;QACpC;IACF;IAEA,qBACE,KAACpC;QACCqC,OAAO;YACL5B,OAAOA;YACPC,QAAQA;QACV;QACA4B,IAAI;YAAEhB,UAAU;QAAO;kBAEvB,cAAA,KAACrB;YACCqC,IAAI;gBACFC,WAAW7B;gBACXA,QAAQC,OAAOA,KAAK6B,MAAM,GAAIrC,CAAAA,gBAAgBC,OAAM,IAAK;YAC3D;YACAS,QAAQA;YACR4B,OAAO7B,YAAYwB,YAAY;;;AAIvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PieChartPanel.d.ts","sourceRoot":"","sources":["../../src/PieChartPanel.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PieChartPanel.d.ts","sourceRoot":"","sources":["../../src/PieChartPanel.tsx"],"names":[],"mappings":"AAuBA,OAAO,EAAoD,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,UAAU,EAAsB,MAAM,2BAA2B,CAAC;AAE3E,OAAO,EAAE,YAAY,EAA6B,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;AAE7E,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,YAAY,GAAG,IAAI,CA+H5E"}
|
package/lib/PieChartPanel.js
CHANGED
|
@@ -12,26 +12,21 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { Box, useTheme } from '@mui/material';
|
|
15
|
-
import { ContentWithLegend,
|
|
15
|
+
import { ContentWithLegend, useChartsTheme, useId } from '@perses-dev/components';
|
|
16
16
|
import { CalculationsMap, DEFAULT_LEGEND } from '@perses-dev/core';
|
|
17
17
|
import { validateLegendSpec } from '@perses-dev/plugin-system';
|
|
18
18
|
import merge from 'lodash/merge';
|
|
19
19
|
import { useMemo, useRef, useState } from 'react';
|
|
20
20
|
import { getSeriesColor } from './palette-gen';
|
|
21
|
-
import { DEFAULT_VISUAL } from './pie-chart-model';
|
|
22
21
|
import { calculatePercentages, sortSeriesData } from './utils';
|
|
22
|
+
import { PieChartBase } from './PieChartBase';
|
|
23
23
|
export function PieChartPanel(props) {
|
|
24
|
-
const { spec: { calculation, sort, mode
|
|
24
|
+
const { spec: { calculation, sort, mode }, contentDimensions, queryResults } = props;
|
|
25
25
|
const chartsTheme = useChartsTheme();
|
|
26
26
|
const muiTheme = useTheme();
|
|
27
27
|
const PADDING = chartsTheme.container.padding.default;
|
|
28
28
|
const chartId = useId('time-series-panel');
|
|
29
29
|
const categoricalPalette = chartsTheme.echartsTheme.color;
|
|
30
|
-
const visual = useMemo(()=>{
|
|
31
|
-
return merge({}, DEFAULT_VISUAL, props.spec.visual);
|
|
32
|
-
}, [
|
|
33
|
-
props.spec.visual
|
|
34
|
-
]);
|
|
35
30
|
const { pieChartData, legendItems } = useMemo(()=>{
|
|
36
31
|
const calculate = CalculationsMap[calculation];
|
|
37
32
|
const pieChartData = [];
|
|
@@ -40,24 +35,10 @@ export function PieChartPanel(props) {
|
|
|
40
35
|
const result = queryResults[queryIndex];
|
|
41
36
|
let seriesIndex = 0;
|
|
42
37
|
for (const seriesData of result?.data.series ?? []){
|
|
43
|
-
// Retrieve querySettings for this query, if exists.
|
|
44
|
-
// queries & querySettings indices do not necessarily match, so we have to check the tail value of the $ref attribute
|
|
45
|
-
let querySettings;
|
|
46
|
-
for (const item of querySettingsList ?? []){
|
|
47
|
-
if (item.queryIndex === queryIndex) {
|
|
48
|
-
querySettings = item;
|
|
49
|
-
// We don't break the loop here just in case there are multiple querySettings defined for the
|
|
50
|
-
// same queryIndex, because in that case we want the last one to take precedence.
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
38
|
const seriesColor = getSeriesColor({
|
|
54
39
|
categoricalPalette: categoricalPalette,
|
|
55
|
-
visual,
|
|
56
40
|
muiPrimaryColor: muiTheme.palette.primary.main,
|
|
57
|
-
seriesName: seriesData.name
|
|
58
|
-
seriesIndex,
|
|
59
|
-
querySettings: querySettings,
|
|
60
|
-
queryHasMultipleResults: (queryResults[queryIndex]?.data?.series?.length ?? 0) > 1
|
|
41
|
+
seriesName: seriesData.name
|
|
61
42
|
});
|
|
62
43
|
const series = {
|
|
63
44
|
value: calculate(seriesData.values) ?? null,
|
|
@@ -93,10 +74,8 @@ export function PieChartPanel(props) {
|
|
|
93
74
|
mode,
|
|
94
75
|
queryResults,
|
|
95
76
|
categoricalPalette,
|
|
96
|
-
visual,
|
|
97
77
|
muiTheme.palette.primary.main,
|
|
98
|
-
chartId
|
|
99
|
-
querySettingsList
|
|
78
|
+
chartId
|
|
100
79
|
]);
|
|
101
80
|
const contentPadding = chartsTheme.container.padding.default;
|
|
102
81
|
const adjustedContentDimensions = contentDimensions ? {
|
|
@@ -150,7 +129,7 @@ export function PieChartPanel(props) {
|
|
|
150
129
|
height,
|
|
151
130
|
width
|
|
152
131
|
},
|
|
153
|
-
children: /*#__PURE__*/ _jsx(
|
|
132
|
+
children: /*#__PURE__*/ _jsx(PieChartBase, {
|
|
154
133
|
data: pieChartData,
|
|
155
134
|
width: contentDimensions.width - PADDING * 2,
|
|
156
135
|
height: contentDimensions.height - PADDING * 2
|
package/lib/PieChartPanel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/PieChartPanel.tsx"],"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 { Box, useTheme } from '@mui/material';\nimport {\n ChartInstance,\n ContentWithLegend,\n LegendItem,\n LegendProps,\n PieChart,\n PieChartData,\n SelectedLegendItemState,\n useChartsTheme,\n useId,\n} from '@perses-dev/components';\nimport { CalculationType, CalculationsMap, DEFAULT_LEGEND, TimeSeriesData } from '@perses-dev/core';\nimport { PanelProps, validateLegendSpec } from '@perses-dev/plugin-system';\nimport merge from 'lodash/merge';\nimport { ReactElement, useMemo, useRef, useState } from 'react';\nimport { QuerySettingsOptions } from './model';\nimport { getSeriesColor } from './palette-gen';\nimport { DEFAULT_VISUAL, PieChartOptions } from './pie-chart-model';\nimport { calculatePercentages, sortSeriesData } from './utils';\n\nexport type PieChartPanelProps = PanelProps<PieChartOptions, TimeSeriesData>;\n\nexport function PieChartPanel(props: PieChartPanelProps): ReactElement | null {\n const {\n spec: { calculation, sort, mode, querySettings: querySettingsList },\n contentDimensions,\n queryResults,\n } = props;\n const chartsTheme = useChartsTheme();\n const muiTheme = useTheme();\n const PADDING = chartsTheme.container.padding.default;\n const chartId = useId('time-series-panel');\n const categoricalPalette = chartsTheme.echartsTheme.color;\n\n const visual = useMemo(() => {\n return merge({}, DEFAULT_VISUAL, props.spec.visual);\n }, [props.spec.visual]);\n\n const { pieChartData, legendItems } = useMemo(() => {\n const calculate = CalculationsMap[calculation as CalculationType];\n const pieChartData: PieChartData[] = [];\n const legendItems: LegendItem[] = [];\n\n for (let queryIndex = 0; queryIndex < queryResults.length; queryIndex++) {\n const result = queryResults[queryIndex];\n\n let seriesIndex = 0;\n for (const seriesData of result?.data.series ?? []) {\n // Retrieve querySettings for this query, if exists.\n // queries & querySettings indices do not necessarily match, so we have to check the tail value of the $ref attribute\n let querySettings: QuerySettingsOptions | undefined;\n for (const item of querySettingsList ?? []) {\n if (item.queryIndex === queryIndex) {\n querySettings = item;\n // We don't break the loop here just in case there are multiple querySettings defined for the\n // same queryIndex, because in that case we want the last one to take precedence.\n }\n }\n const seriesColor = getSeriesColor({\n categoricalPalette: categoricalPalette as string[],\n visual,\n muiPrimaryColor: muiTheme.palette.primary.main,\n seriesName: seriesData.name,\n seriesIndex,\n querySettings: querySettings,\n queryHasMultipleResults: (queryResults[queryIndex]?.data?.series?.length ?? 0) > 1,\n });\n const series = {\n value: calculate(seriesData.values) ?? null,\n name: seriesData.formattedName ?? '',\n itemStyle: {\n color: seriesColor,\n },\n };\n pieChartData.push(series);\n\n const seriesId = chartId + seriesData.name + seriesIndex;\n legendItems.push({\n id: seriesId,\n label: series.name,\n color: seriesColor,\n });\n seriesIndex++;\n }\n }\n\n const sortedPieChartData = sortSeriesData(pieChartData, sort);\n if (mode === 'percentage') {\n return {\n pieChartData: calculatePercentages(sortedPieChartData),\n legendItems,\n };\n }\n return {\n pieChartData: sortedPieChartData,\n legendItems,\n };\n }, [\n calculation,\n sort,\n mode,\n queryResults,\n categoricalPalette,\n visual,\n muiTheme.palette.primary.main,\n chartId,\n querySettingsList,\n ]);\n\n const contentPadding = chartsTheme.container.padding.default;\n const adjustedContentDimensions: typeof contentDimensions = contentDimensions\n ? {\n width: contentDimensions.width - contentPadding * 2,\n height: contentDimensions.height - contentPadding * 2,\n }\n : undefined;\n\n const legend = useMemo(() => {\n return props.spec.legend && validateLegendSpec(props.spec.legend)\n ? merge({}, DEFAULT_LEGEND, props.spec.legend)\n : undefined;\n }, [props.spec.legend]);\n\n const [selectedLegendItems, setSelectedLegendItems] = useState<SelectedLegendItemState>('ALL');\n\n const [legendSorting, setLegendSorting] = useState<NonNullable<LegendProps['tableProps']>['sorting']>();\n\n const chartRef = useRef<ChartInstance>(null);\n\n // ensures there are fallbacks for unset properties since most\n // users should not need to customize visual display\n\n if (contentDimensions === undefined) return null;\n\n return (\n <Box sx={{ padding: `${PADDING}px` }}>\n <ContentWithLegend\n width={adjustedContentDimensions?.width ?? 400}\n height={adjustedContentDimensions?.height ?? 1000}\n // Making this small enough that the medium size doesn't get\n // responsive-handling-ed away when in the panel options editor.\n minChildrenHeight={50}\n legendSize={legend?.size}\n legendProps={\n legend && {\n options: legend,\n data: legendItems,\n selectedItems: selectedLegendItems,\n onSelectedItemsChange: setSelectedLegendItems,\n tableProps: {\n columns: [],\n sorting: legendSorting,\n onSortingChange: setLegendSorting,\n },\n onItemMouseOver: (e, { id }): void => {\n chartRef.current?.highlightSeries({ name: id });\n },\n onItemMouseOut: (): void => {\n chartRef.current?.clearHighlightedSeries();\n },\n }\n }\n >\n {({ height, width }) => {\n return (\n <Box style={{ height, width }}>\n <PieChart\n data={pieChartData}\n width={contentDimensions.width - PADDING * 2}\n height={contentDimensions.height - PADDING * 2}\n />\n </Box>\n );\n }}\n </ContentWithLegend>\n </Box>\n );\n}\n"],"names":["Box","useTheme","ContentWithLegend","PieChart","useChartsTheme","useId","CalculationsMap","DEFAULT_LEGEND","validateLegendSpec","merge","useMemo","useRef","useState","getSeriesColor","DEFAULT_VISUAL","calculatePercentages","sortSeriesData","PieChartPanel","props","spec","calculation","sort","mode","querySettings","querySettingsList","contentDimensions","queryResults","chartsTheme","muiTheme","PADDING","container","padding","default","chartId","categoricalPalette","echartsTheme","color","visual","pieChartData","legendItems","calculate","queryIndex","length","result","seriesIndex","seriesData","data","series","item","seriesColor","muiPrimaryColor","palette","primary","main","seriesName","name","queryHasMultipleResults","value","values","formattedName","itemStyle","push","seriesId","id","label","sortedPieChartData","contentPadding","adjustedContentDimensions","width","height","undefined","legend","selectedLegendItems","setSelectedLegendItems","legendSorting","setLegendSorting","chartRef","sx","minChildrenHeight","legendSize","size","legendProps","options","selectedItems","onSelectedItemsChange","tableProps","columns","sorting","onSortingChange","onItemMouseOver","e","current","highlightSeries","onItemMouseOut","clearHighlightedSeries","style"],"mappings":"AAAA,mCAAmC;AACnC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,EAAEC,QAAQ,QAAQ,gBAAgB;AAC9C,SAEEC,iBAAiB,EAGjBC,QAAQ,EAGRC,cAAc,EACdC,KAAK,QACA,yBAAyB;AAChC,SAA0BC,eAAe,EAAEC,cAAc,QAAwB,mBAAmB;AACpG,SAAqBC,kBAAkB,QAAQ,4BAA4B;AAC3E,OAAOC,WAAW,eAAe;AACjC,SAAuBC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAEhE,SAASC,cAAc,QAAQ,gBAAgB;AAC/C,SAASC,cAAc,QAAyB,oBAAoB;AACpE,SAASC,oBAAoB,EAAEC,cAAc,QAAQ,UAAU;AAI/D,OAAO,SAASC,cAAcC,KAAyB;IACrD,MAAM,EACJC,MAAM,EAAEC,WAAW,EAAEC,IAAI,EAAEC,IAAI,EAAEC,eAAeC,iBAAiB,EAAE,EACnEC,iBAAiB,EACjBC,YAAY,EACb,GAAGR;IACJ,MAAMS,cAAcvB;IACpB,MAAMwB,WAAW3B;IACjB,MAAM4B,UAAUF,YAAYG,SAAS,CAACC,OAAO,CAACC,OAAO;IACrD,MAAMC,UAAU5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,mBAAmB;YACnBC,YAAYR,QAAQS;YACpBC,aACEV,UAAU;gBACRW,SAASX;gBACTzB,MAAMP;gBACN4C,eAAeX;gBACfY,uBAAuBX;gBACvBY,YAAY;oBACVC,SAAS,EAAE;oBACXC,SAASb;oBACTc,iBAAiBb;gBACnB;gBACAc,iBAAiB,CAACC,GAAG,EAAE3B,EAAE,EAAE;oBACzBa,SAASe,OAAO,EAAEC,gBAAgB;wBAAErC,MAAMQ;oBAAG;gBAC/C;gBACA8B,gBAAgB;oBACdjB,SAASe,OAAO,EAAEG;gBACpB;YACF;sBAGD,CAAC,EAAEzB,MAAM,EAAED,KAAK,EAAE;gBACjB,qBACE,KAACpE;oBAAI+F,OAAO;wBAAE1B;wBAAQD;oBAAM;8BAC1B,cAAA,KAACjE;wBACC2C,MAAMR;wBACN8B,OAAO3C,kBAAkB2C,KAAK,GAAGvC,UAAU;wBAC3CwC,QAAQ5C,kBAAkB4C,MAAM,GAAGxC,UAAU;;;YAIrD;;;AAIR"}
|
|
1
|
+
{"version":3,"sources":["../../src/PieChartPanel.tsx"],"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 { Box, useTheme } from '@mui/material';\nimport {\n ChartInstance,\n ContentWithLegend,\n LegendItem,\n LegendProps,\n SelectedLegendItemState,\n useChartsTheme,\n useId,\n} from '@perses-dev/components';\nimport { CalculationType, CalculationsMap, DEFAULT_LEGEND, TimeSeriesData } from '@perses-dev/core';\nimport { PanelProps, validateLegendSpec } from '@perses-dev/plugin-system';\nimport merge from 'lodash/merge';\nimport { ReactElement, useMemo, useRef, useState } from 'react';\nimport { getSeriesColor } from './palette-gen';\nimport { PieChartOptions } from './pie-chart-model';\nimport { calculatePercentages, sortSeriesData } from './utils';\nimport { PieChartBase, PieChartData } from './PieChartBase';\n\nexport type PieChartPanelProps = PanelProps<PieChartOptions, TimeSeriesData>;\n\nexport function PieChartPanel(props: PieChartPanelProps): ReactElement | null {\n const {\n spec: { calculation, sort, mode },\n contentDimensions,\n queryResults,\n } = props;\n const chartsTheme = useChartsTheme();\n const muiTheme = useTheme();\n const PADDING = chartsTheme.container.padding.default;\n const chartId = useId('time-series-panel');\n const categoricalPalette = chartsTheme.echartsTheme.color;\n\n const { pieChartData, legendItems } = useMemo(() => {\n const calculate = CalculationsMap[calculation as CalculationType];\n const pieChartData: PieChartData[] = [];\n const legendItems: LegendItem[] = [];\n\n for (let queryIndex = 0; queryIndex < queryResults.length; queryIndex++) {\n const result = queryResults[queryIndex];\n\n let seriesIndex = 0;\n for (const seriesData of result?.data.series ?? []) {\n const seriesColor = getSeriesColor({\n categoricalPalette: categoricalPalette as string[],\n muiPrimaryColor: muiTheme.palette.primary.main,\n seriesName: seriesData.name,\n });\n const series = {\n value: calculate(seriesData.values) ?? null,\n name: seriesData.formattedName ?? '',\n itemStyle: {\n color: seriesColor,\n },\n };\n pieChartData.push(series);\n\n const seriesId = chartId + seriesData.name + seriesIndex;\n legendItems.push({\n id: seriesId,\n label: series.name,\n color: seriesColor,\n });\n seriesIndex++;\n }\n }\n\n const sortedPieChartData = sortSeriesData(pieChartData, sort);\n if (mode === 'percentage') {\n return {\n pieChartData: calculatePercentages(sortedPieChartData),\n legendItems,\n };\n }\n return {\n pieChartData: sortedPieChartData,\n legendItems,\n };\n }, [calculation, sort, mode, queryResults, categoricalPalette, muiTheme.palette.primary.main, chartId]);\n\n const contentPadding = chartsTheme.container.padding.default;\n const adjustedContentDimensions: typeof contentDimensions = contentDimensions\n ? {\n width: contentDimensions.width - contentPadding * 2,\n height: contentDimensions.height - contentPadding * 2,\n }\n : undefined;\n\n const legend = useMemo(() => {\n return props.spec.legend && validateLegendSpec(props.spec.legend)\n ? merge({}, DEFAULT_LEGEND, props.spec.legend)\n : undefined;\n }, [props.spec.legend]);\n\n const [selectedLegendItems, setSelectedLegendItems] = useState<SelectedLegendItemState>('ALL');\n\n const [legendSorting, setLegendSorting] = useState<NonNullable<LegendProps['tableProps']>['sorting']>();\n\n const chartRef = useRef<ChartInstance>(null);\n\n // ensures there are fallbacks for unset properties since most\n // users should not need to customize visual display\n\n if (contentDimensions === undefined) return null;\n\n return (\n <Box sx={{ padding: `${PADDING}px` }}>\n <ContentWithLegend\n width={adjustedContentDimensions?.width ?? 400}\n height={adjustedContentDimensions?.height ?? 1000}\n // Making this small enough that the medium size doesn't get\n // responsive-handling-ed away when in the panel options editor.\n minChildrenHeight={50}\n legendSize={legend?.size}\n legendProps={\n legend && {\n options: legend,\n data: legendItems,\n selectedItems: selectedLegendItems,\n onSelectedItemsChange: setSelectedLegendItems,\n tableProps: {\n columns: [],\n sorting: legendSorting,\n onSortingChange: setLegendSorting,\n },\n onItemMouseOver: (e, { id }): void => {\n chartRef.current?.highlightSeries({ name: id });\n },\n onItemMouseOut: (): void => {\n chartRef.current?.clearHighlightedSeries();\n },\n }\n }\n >\n {({ height, width }) => {\n return (\n <Box style={{ height, width }}>\n <PieChartBase\n data={pieChartData}\n width={contentDimensions.width - PADDING * 2}\n height={contentDimensions.height - PADDING * 2}\n />\n </Box>\n );\n }}\n </ContentWithLegend>\n </Box>\n );\n}\n"],"names":["Box","useTheme","ContentWithLegend","useChartsTheme","useId","CalculationsMap","DEFAULT_LEGEND","validateLegendSpec","merge","useMemo","useRef","useState","getSeriesColor","calculatePercentages","sortSeriesData","PieChartBase","PieChartPanel","props","spec","calculation","sort","mode","contentDimensions","queryResults","chartsTheme","muiTheme","PADDING","container","padding","default","chartId","categoricalPalette","echartsTheme","color","pieChartData","legendItems","calculate","queryIndex","length","result","seriesIndex","seriesData","data","series","seriesColor","muiPrimaryColor","palette","primary","main","seriesName","name","value","values","formattedName","itemStyle","push","seriesId","id","label","sortedPieChartData","contentPadding","adjustedContentDimensions","width","height","undefined","legend","selectedLegendItems","setSelectedLegendItems","legendSorting","setLegendSorting","chartRef","sx","minChildrenHeight","legendSize","size","legendProps","options","selectedItems","onSelectedItemsChange","tableProps","columns","sorting","onSortingChange","onItemMouseOver","e","current","highlightSeries","onItemMouseOut","clearHighlightedSeries","style"],"mappings":"AAAA,mCAAmC;AACnC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,EAAEC,QAAQ,QAAQ,gBAAgB;AAC9C,SAEEC,iBAAiB,EAIjBC,cAAc,EACdC,KAAK,QACA,yBAAyB;AAChC,SAA0BC,eAAe,EAAEC,cAAc,QAAwB,mBAAmB;AACpG,SAAqBC,kBAAkB,QAAQ,4BAA4B;AAC3E,OAAOC,WAAW,eAAe;AACjC,SAAuBC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAChE,SAASC,cAAc,QAAQ,gBAAgB;AAE/C,SAASC,oBAAoB,EAAEC,cAAc,QAAQ,UAAU;AAC/D,SAASC,YAAY,QAAsB,iBAAiB;AAI5D,OAAO,SAASC,cAAcC,KAAyB;IACrD,MAAM,EACJC,MAAM,EAAEC,WAAW,EAAEC,IAAI,EAAEC,IAAI,EAAE,EACjCC,iBAAiB,EACjBC,YAAY,EACb,GAAGN;IACJ,MAAMO,cAAcrB;IACpB,MAAMsB,WAAWxB;IACjB,MAAMyB,UAAUF,YAAYG,SAAS,CAACC,OAAO,CAACC,OAAO;IACrD,MAAMC,UAAU1B,MAAM;IACtB,MAAM2B,qBAAqBP,YAAYQ,YAAY,CAACC,KAAK;IAEzD,MAAM,EAAEC,YAAY,EAAEC,WAAW,EAAE,GAAG1B,QAAQ;QAC5C,MA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AAIR"}
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "PieChartBase", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return PieChartBase;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
+
const _core = require("echarts/core");
|
|
25
|
+
const _charts = require("echarts/charts");
|
|
26
|
+
const _components = require("echarts/components");
|
|
27
|
+
const _renderers = require("echarts/renderers");
|
|
28
|
+
const _material = require("@mui/material");
|
|
29
|
+
const _components1 = require("@perses-dev/components");
|
|
30
|
+
(0, _core.use)([
|
|
31
|
+
_charts.PieChart,
|
|
32
|
+
_components.GridComponent,
|
|
33
|
+
_components.DatasetComponent,
|
|
34
|
+
_components.TitleComponent,
|
|
35
|
+
_components.TooltipComponent,
|
|
36
|
+
_renderers.CanvasRenderer
|
|
37
|
+
]);
|
|
38
|
+
const PIE_WIN_WIDTH = 12;
|
|
39
|
+
const PIE_GAP = 4;
|
|
40
|
+
function PieChartBase(props) {
|
|
41
|
+
console.log(props);
|
|
42
|
+
const { width, height, data } = props;
|
|
43
|
+
const chartsTheme = (0, _components1.useChartsTheme)();
|
|
44
|
+
const option = {
|
|
45
|
+
title: {
|
|
46
|
+
text: 'Referer of a Website',
|
|
47
|
+
subtext: 'Fake Data',
|
|
48
|
+
left: 'center'
|
|
49
|
+
},
|
|
50
|
+
tooltip: {
|
|
51
|
+
trigger: 'item',
|
|
52
|
+
formatter: '{a} <br/>{b} : {c} ({d}%)'
|
|
53
|
+
},
|
|
54
|
+
axisLabel: {
|
|
55
|
+
overflow: 'truncate',
|
|
56
|
+
width: width / 3
|
|
57
|
+
},
|
|
58
|
+
series: [
|
|
59
|
+
{
|
|
60
|
+
name: 'Access From',
|
|
61
|
+
type: 'pie',
|
|
62
|
+
radius: '55%',
|
|
63
|
+
label: false,
|
|
64
|
+
center: [
|
|
65
|
+
'40%',
|
|
66
|
+
'50%'
|
|
67
|
+
],
|
|
68
|
+
data: data,
|
|
69
|
+
emphasis: {
|
|
70
|
+
itemStyle: {
|
|
71
|
+
shadowBlur: 10,
|
|
72
|
+
shadowOffsetX: 0,
|
|
73
|
+
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
itemStyle: {
|
|
79
|
+
borderRadius: 2,
|
|
80
|
+
color: chartsTheme.echartsTheme[0]
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
84
|
+
style: {
|
|
85
|
+
width: width,
|
|
86
|
+
height: height
|
|
87
|
+
},
|
|
88
|
+
sx: {
|
|
89
|
+
overflow: 'auto'
|
|
90
|
+
},
|
|
91
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components1.EChart, {
|
|
92
|
+
sx: {
|
|
93
|
+
minHeight: height,
|
|
94
|
+
height: data ? data.length * (PIE_WIN_WIDTH + PIE_GAP) : '100%'
|
|
95
|
+
},
|
|
96
|
+
option: option,
|
|
97
|
+
theme: chartsTheme.echartsTheme
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
}
|
package/lib/cjs/PieChartPanel.js
CHANGED
|
@@ -28,25 +28,20 @@ const _pluginsystem = require("@perses-dev/plugin-system");
|
|
|
28
28
|
const _merge = /*#__PURE__*/ _interop_require_default(require("lodash/merge"));
|
|
29
29
|
const _react = require("react");
|
|
30
30
|
const _palettegen = require("./palette-gen");
|
|
31
|
-
const _piechartmodel = require("./pie-chart-model");
|
|
32
31
|
const _utils = require("./utils");
|
|
32
|
+
const _PieChartBase = require("./PieChartBase");
|
|
33
33
|
function _interop_require_default(obj) {
|
|
34
34
|
return obj && obj.__esModule ? obj : {
|
|
35
35
|
default: obj
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
function PieChartPanel(props) {
|
|
39
|
-
const { spec: { calculation, sort, mode
|
|
39
|
+
const { spec: { calculation, sort, mode }, contentDimensions, queryResults } = props;
|
|
40
40
|
const chartsTheme = (0, _components.useChartsTheme)();
|
|
41
41
|
const muiTheme = (0, _material.useTheme)();
|
|
42
42
|
const PADDING = chartsTheme.container.padding.default;
|
|
43
43
|
const chartId = (0, _components.useId)('time-series-panel');
|
|
44
44
|
const categoricalPalette = chartsTheme.echartsTheme.color;
|
|
45
|
-
const visual = (0, _react.useMemo)(()=>{
|
|
46
|
-
return (0, _merge.default)({}, _piechartmodel.DEFAULT_VISUAL, props.spec.visual);
|
|
47
|
-
}, [
|
|
48
|
-
props.spec.visual
|
|
49
|
-
]);
|
|
50
45
|
const { pieChartData, legendItems } = (0, _react.useMemo)(()=>{
|
|
51
46
|
const calculate = _core.CalculationsMap[calculation];
|
|
52
47
|
const pieChartData = [];
|
|
@@ -55,24 +50,10 @@ function PieChartPanel(props) {
|
|
|
55
50
|
const result = queryResults[queryIndex];
|
|
56
51
|
let seriesIndex = 0;
|
|
57
52
|
for (const seriesData of result?.data.series ?? []){
|
|
58
|
-
// Retrieve querySettings for this query, if exists.
|
|
59
|
-
// queries & querySettings indices do not necessarily match, so we have to check the tail value of the $ref attribute
|
|
60
|
-
let querySettings;
|
|
61
|
-
for (const item of querySettingsList ?? []){
|
|
62
|
-
if (item.queryIndex === queryIndex) {
|
|
63
|
-
querySettings = item;
|
|
64
|
-
// We don't break the loop here just in case there are multiple querySettings defined for the
|
|
65
|
-
// same queryIndex, because in that case we want the last one to take precedence.
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
53
|
const seriesColor = (0, _palettegen.getSeriesColor)({
|
|
69
54
|
categoricalPalette: categoricalPalette,
|
|
70
|
-
visual,
|
|
71
55
|
muiPrimaryColor: muiTheme.palette.primary.main,
|
|
72
|
-
seriesName: seriesData.name
|
|
73
|
-
seriesIndex,
|
|
74
|
-
querySettings: querySettings,
|
|
75
|
-
queryHasMultipleResults: (queryResults[queryIndex]?.data?.series?.length ?? 0) > 1
|
|
56
|
+
seriesName: seriesData.name
|
|
76
57
|
});
|
|
77
58
|
const series = {
|
|
78
59
|
value: calculate(seriesData.values) ?? null,
|
|
@@ -108,10 +89,8 @@ function PieChartPanel(props) {
|
|
|
108
89
|
mode,
|
|
109
90
|
queryResults,
|
|
110
91
|
categoricalPalette,
|
|
111
|
-
visual,
|
|
112
92
|
muiTheme.palette.primary.main,
|
|
113
|
-
chartId
|
|
114
|
-
querySettingsList
|
|
93
|
+
chartId
|
|
115
94
|
]);
|
|
116
95
|
const contentPadding = chartsTheme.container.padding.default;
|
|
117
96
|
const adjustedContentDimensions = contentDimensions ? {
|
|
@@ -165,7 +144,7 @@ function PieChartPanel(props) {
|
|
|
165
144
|
height,
|
|
166
145
|
width
|
|
167
146
|
},
|
|
168
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(
|
|
147
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_PieChartBase.PieChartBase, {
|
|
169
148
|
data: pieChartData,
|
|
170
149
|
width: contentDimensions.width - PADDING * 2,
|
|
171
150
|
height: contentDimensions.height - PADDING * 2
|
package/lib/cjs/palette-gen.js
CHANGED
|
@@ -36,22 +36,10 @@ _export(exports, {
|
|
|
36
36
|
});
|
|
37
37
|
const _palette = require("./palette");
|
|
38
38
|
function getSeriesColor(props) {
|
|
39
|
-
const { categoricalPalette,
|
|
40
|
-
// Use color overrides defined in query settings in priority, if applicable
|
|
41
|
-
if (querySettings) {
|
|
42
|
-
if (querySettings.colorMode === 'fixed') {
|
|
43
|
-
return querySettings.colorValue;
|
|
44
|
-
} else if (querySettings.colorMode === 'fixed-single' && !queryHasMultipleResults) {
|
|
45
|
-
return querySettings.colorValue;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
39
|
+
const { categoricalPalette, muiPrimaryColor, seriesName } = props;
|
|
48
40
|
// Fallback is unlikely to set unless echarts theme palette in charts theme provider is undefined.
|
|
49
41
|
const fallbackColor = Array.isArray(categoricalPalette) && categoricalPalette[0] ? categoricalPalette[0] // Needed since echarts color property isn't always an array.
|
|
50
42
|
: muiPrimaryColor;
|
|
51
|
-
// Explicit way to always cycle through classical palette instead of changing when based on number of series.
|
|
52
|
-
if (visual.palette?.mode === 'categorical') {
|
|
53
|
-
return getCategoricalPaletteColor(categoricalPalette, seriesIndex, fallbackColor);
|
|
54
|
-
}
|
|
55
43
|
return getAutoPaletteColor(seriesName, fallbackColor);
|
|
56
44
|
}
|
|
57
45
|
function getAutoPaletteColor(name, fallbackColor) {
|
|
@@ -21,94 +21,32 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
DEFAULT_AREA_OPACITY: function() {
|
|
25
|
-
return DEFAULT_AREA_OPACITY;
|
|
26
|
-
},
|
|
27
|
-
DEFAULT_CONNECT_NULLS: function() {
|
|
28
|
-
return DEFAULT_CONNECT_NULLS;
|
|
29
|
-
},
|
|
30
24
|
DEFAULT_FORMAT: function() {
|
|
31
25
|
return DEFAULT_FORMAT;
|
|
32
26
|
},
|
|
33
|
-
DEFAULT_LINE_WIDTH: function() {
|
|
34
|
-
return DEFAULT_LINE_WIDTH;
|
|
35
|
-
},
|
|
36
27
|
DEFAULT_MODE: function() {
|
|
37
28
|
return DEFAULT_MODE;
|
|
38
29
|
},
|
|
39
|
-
DEFAULT_POINT_RADIUS: function() {
|
|
40
|
-
return DEFAULT_POINT_RADIUS;
|
|
41
|
-
},
|
|
42
30
|
DEFAULT_SORT: function() {
|
|
43
31
|
return DEFAULT_SORT;
|
|
44
32
|
},
|
|
45
|
-
DEFAULT_VISUAL: function() {
|
|
46
|
-
return DEFAULT_VISUAL;
|
|
47
|
-
},
|
|
48
|
-
POINT_SIZE_OFFSET: function() {
|
|
49
|
-
return POINT_SIZE_OFFSET;
|
|
50
|
-
},
|
|
51
|
-
VISUAL_CONFIG: function() {
|
|
52
|
-
return VISUAL_CONFIG;
|
|
53
|
-
},
|
|
54
33
|
createInitialPieChartOptions: function() {
|
|
55
34
|
return createInitialPieChartOptions;
|
|
56
35
|
}
|
|
57
36
|
});
|
|
58
37
|
const _core = require("@perses-dev/core");
|
|
59
|
-
const DEFAULT_CONNECT_NULLS = false;
|
|
60
|
-
const POINT_SIZE_OFFSET = 1.5;
|
|
61
38
|
const DEFAULT_FORMAT = {
|
|
62
39
|
unit: 'decimal',
|
|
63
40
|
shortValues: true
|
|
64
41
|
};
|
|
65
42
|
const DEFAULT_SORT = 'desc';
|
|
66
43
|
const DEFAULT_MODE = 'value';
|
|
67
|
-
const DEFAULT_LINE_WIDTH = 1.25;
|
|
68
|
-
const DEFAULT_AREA_OPACITY = 0;
|
|
69
|
-
const DEFAULT_POINT_RADIUS = DEFAULT_LINE_WIDTH + POINT_SIZE_OFFSET;
|
|
70
|
-
const VISUAL_CONFIG = {
|
|
71
|
-
lineWidth: {
|
|
72
|
-
label: 'Line Width',
|
|
73
|
-
testId: 'slider-line-width',
|
|
74
|
-
min: 0.25,
|
|
75
|
-
max: 3,
|
|
76
|
-
step: 0.25
|
|
77
|
-
},
|
|
78
|
-
pointRadius: {
|
|
79
|
-
label: 'Point Radius',
|
|
80
|
-
testId: 'slider-point-radius',
|
|
81
|
-
min: 0,
|
|
82
|
-
max: 6,
|
|
83
|
-
step: 0.25
|
|
84
|
-
},
|
|
85
|
-
areaOpacity: {
|
|
86
|
-
label: 'Area Opacity',
|
|
87
|
-
testId: 'slider-area-opacity',
|
|
88
|
-
min: 0,
|
|
89
|
-
max: 1,
|
|
90
|
-
step: 0.05
|
|
91
|
-
},
|
|
92
|
-
stack: {
|
|
93
|
-
label: 'Stack Series'
|
|
94
|
-
},
|
|
95
|
-
connectNulls: {
|
|
96
|
-
label: 'Connect Nulls'
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const DEFAULT_VISUAL = {
|
|
100
|
-
lineWidth: DEFAULT_LINE_WIDTH,
|
|
101
|
-
areaOpacity: DEFAULT_AREA_OPACITY,
|
|
102
|
-
pointRadius: DEFAULT_POINT_RADIUS,
|
|
103
|
-
connectNulls: DEFAULT_CONNECT_NULLS
|
|
104
|
-
};
|
|
105
44
|
function createInitialPieChartOptions() {
|
|
106
45
|
return {
|
|
107
46
|
calculation: _core.DEFAULT_CALCULATION,
|
|
108
47
|
format: DEFAULT_FORMAT,
|
|
109
48
|
radius: 50,
|
|
110
49
|
sort: DEFAULT_SORT,
|
|
111
|
-
mode: DEFAULT_MODE
|
|
112
|
-
visual: DEFAULT_VISUAL
|
|
50
|
+
mode: DEFAULT_MODE
|
|
113
51
|
};
|
|
114
52
|
}
|
package/lib/palette-gen.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { ChartVisualOptions, QuerySettingsOptions } from './model';
|
|
2
1
|
export interface SeriesColorProps {
|
|
3
2
|
categoricalPalette: string[];
|
|
4
|
-
visual: ChartVisualOptions;
|
|
5
3
|
muiPrimaryColor: string;
|
|
6
4
|
seriesName: string;
|
|
7
|
-
seriesIndex: number;
|
|
8
|
-
querySettings?: QuerySettingsOptions;
|
|
9
|
-
queryHasMultipleResults?: boolean;
|
|
10
5
|
}
|
|
11
6
|
/**
|
|
12
7
|
* Get line color as well as color for tooltip and legend, account for whether palette is 'categorical' or 'auto' aka generative
|
package/lib/palette-gen.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"palette-gen.d.ts","sourceRoot":"","sources":["../../src/palette-gen.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"palette-gen.d.ts","sourceRoot":"","sources":["../../src/palette-gen.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAU9D;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"}
|
package/lib/palette-gen.js
CHANGED
|
@@ -14,22 +14,10 @@ import { getConsistentColor } from './palette';
|
|
|
14
14
|
/**
|
|
15
15
|
* Get line color as well as color for tooltip and legend, account for whether palette is 'categorical' or 'auto' aka generative
|
|
16
16
|
*/ export function getSeriesColor(props) {
|
|
17
|
-
const { categoricalPalette,
|
|
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
|
-
}
|
|
17
|
+
const { categoricalPalette, muiPrimaryColor, seriesName } = props;
|
|
26
18
|
// Fallback is unlikely to set unless echarts theme palette in charts theme provider is undefined.
|
|
27
19
|
const fallbackColor = Array.isArray(categoricalPalette) && categoricalPalette[0] ? categoricalPalette[0] // Needed since echarts color property isn't always an array.
|
|
28
20
|
: 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
21
|
return getAutoPaletteColor(seriesName, fallbackColor);
|
|
34
22
|
}
|
|
35
23
|
/**
|