@perses-dev/bar-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.
- package/LICENSE +201 -0
- package/README.md +23 -0
- package/__mf/css/async/263.1f61a808.css +1 -0
- package/__mf/css/async/341.1f61a808.css +1 -0
- package/__mf/css/async/759.1f61a808.css +1 -0
- package/__mf/font/lato-all-300-normal.322bdf14.woff +0 -0
- package/__mf/font/lato-all-400-normal.63513b00.woff +0 -0
- package/__mf/font/lato-all-700-normal.bb27db94.woff +0 -0
- package/__mf/font/lato-all-900-normal.a27049a3.woff +0 -0
- package/__mf/font/lato-latin-300-normal.c5195215.woff2 +0 -0
- package/__mf/font/lato-latin-400-normal.b7ffde23.woff2 +0 -0
- package/__mf/font/lato-latin-700-normal.d5eb20bc.woff2 +0 -0
- package/__mf/font/lato-latin-900-normal.d884a71c.woff2 +0 -0
- package/__mf/font/lato-latin-ext-300-normal.abcc64a9.woff2 +0 -0
- package/__mf/font/lato-latin-ext-400-normal.6ebed106.woff2 +0 -0
- package/__mf/font/lato-latin-ext-700-normal.8697d1d5.woff2 +0 -0
- package/__mf/font/lato-latin-ext-900-normal.20a2b415.woff2 +0 -0
- package/__mf/js/590.f6491b3d.js +5 -0
- package/__mf/js/BarChart.5408c279.js +5 -0
- package/__mf/js/async/162.5c4c80cc.js +73 -0
- package/__mf/js/async/162.5c4c80cc.js.LICENSE.txt +19 -0
- package/__mf/js/async/173.de56afb5.js +2 -0
- package/__mf/js/async/173.de56afb5.js.LICENSE.txt +19 -0
- package/__mf/js/async/214.39425df9.js +1 -0
- package/__mf/js/async/224.02bf0727.js +1 -0
- package/__mf/js/async/238.2c28749b.js +1 -0
- package/__mf/js/async/292.fc25f0b4.js +1 -0
- package/__mf/js/async/296.4e6e1192.js +1 -0
- package/__mf/js/async/331.987fc9d1.js +2 -0
- package/__mf/js/async/331.987fc9d1.js.LICENSE.txt +21 -0
- package/__mf/js/async/360.49d19c17.js +29 -0
- package/__mf/js/async/360.49d19c17.js.LICENSE.txt +37 -0
- package/__mf/js/async/488.64e4ab62.js +1 -0
- package/__mf/js/async/553.cebe1061.js +1 -0
- package/__mf/js/async/610.c4c81845.js +1 -0
- package/__mf/js/async/620.1ddf3cfa.js +2 -0
- package/__mf/js/async/620.1ddf3cfa.js.LICENSE.txt +9 -0
- package/__mf/js/async/623.a42c5576.js +1 -0
- package/__mf/js/async/656.ebaf4c29.js +1 -0
- package/__mf/js/async/69.5f20cd9b.js +10 -0
- package/__mf/js/async/69.5f20cd9b.js.LICENSE.txt +27 -0
- package/__mf/js/async/694.f18442c5.js +1 -0
- package/__mf/js/async/738.0b38462b.js +1 -0
- package/__mf/js/async/740.bd4a2dd3.js +1 -0
- package/__mf/js/async/75.602a691f.js +1 -0
- package/__mf/js/async/762.0d4292e6.js +101 -0
- package/__mf/js/async/770.a4ed49b7.js +1 -0
- package/__mf/js/async/774.6d4b81a0.js +1 -0
- package/__mf/js/async/790.23e35958.js +1 -0
- package/__mf/js/async/802.393c9711.js +38 -0
- package/__mf/js/async/929.4de7287b.js +1 -0
- package/__mf/js/async/930.7db974d8.js +1 -0
- package/__mf/js/async/960.07c2f8a6.js +2 -0
- package/__mf/js/async/960.07c2f8a6.js.LICENSE.txt +8 -0
- package/__mf/js/async/964.d446c7a1.js +2 -0
- package/__mf/js/async/964.d446c7a1.js.LICENSE.txt +9 -0
- package/__mf/js/async/981.d5ccd920.js +2 -0
- package/__mf/js/async/981.d5ccd920.js.LICENSE.txt +8 -0
- package/__mf/js/async/996.2287354b.js +2 -0
- package/__mf/js/async/996.2287354b.js.LICENSE.txt +24 -0
- package/__mf/js/async/__federation_expose_BarChart.7c81d310.js +1 -0
- package/__mf/js/async/lib-router.c524d5f3.js +2 -0
- package/__mf/js/async/lib-router.c524d5f3.js.LICENSE.txt +32 -0
- package/__mf/js/main.c53cadb4.js +1 -0
- package/lib/BarChart.d.ts +8 -0
- package/lib/BarChart.d.ts.map +1 -0
- package/lib/BarChart.js +32 -0
- package/lib/BarChart.js.map +1 -0
- package/lib/BarChartOptionsEditorSettings.d.ts +4 -0
- package/lib/BarChartOptionsEditorSettings.d.ts.map +1 -0
- package/lib/BarChartOptionsEditorSettings.js +95 -0
- package/lib/BarChartOptionsEditorSettings.js.map +1 -0
- package/lib/BarChartPanel.d.ts +7 -0
- package/lib/BarChartPanel.d.ts.map +1 -0
- package/lib/BarChartPanel.js +62 -0
- package/lib/BarChartPanel.js.map +1 -0
- package/lib/bar-chart-model.d.ts +27 -0
- package/lib/bar-chart-model.d.ts.map +1 -0
- package/lib/bar-chart-model.js +31 -0
- package/lib/bar-chart-model.js.map +1 -0
- package/lib/bootstrap.d.ts +2 -0
- package/lib/bootstrap.d.ts.map +1 -0
- package/lib/bootstrap.js +19 -0
- package/lib/bootstrap.js.map +1 -0
- package/lib/cjs/BarChart.js +38 -0
- package/lib/cjs/BarChartOptionsEditorSettings.js +108 -0
- package/lib/cjs/BarChartPanel.js +70 -0
- package/lib/cjs/bar-chart-model.js +51 -0
- package/lib/cjs/bootstrap.js +26 -0
- package/lib/cjs/env.d.js +14 -0
- package/lib/cjs/getPluginModule.js +27 -0
- package/lib/cjs/index-federation.js +55 -0
- package/lib/cjs/index.js +40 -0
- package/lib/cjs/setup-tests.js +19 -0
- package/lib/cjs/tresholds.js +65 -0
- package/lib/cjs/utils.js +72 -0
- package/lib/env.d.js +15 -0
- package/lib/env.d.js.map +1 -0
- package/lib/getPluginModule.d.ts +6 -0
- package/lib/getPluginModule.d.ts.map +1 -0
- package/lib/getPluginModule.js +16 -0
- package/lib/getPluginModule.js.map +1 -0
- package/lib/index-federation.d.ts +1 -0
- package/lib/index-federation.d.ts.map +1 -0
- package/lib/index-federation.js +15 -0
- package/lib/index-federation.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/lib/setup-tests.d.ts +2 -0
- package/lib/setup-tests.d.ts.map +1 -0
- package/lib/setup-tests.js +17 -0
- package/lib/setup-tests.js.map +1 -0
- package/lib/tresholds.d.ts +6 -0
- package/lib/tresholds.d.ts.map +1 -0
- package/lib/tresholds.js +44 -0
- package/lib/tresholds.js.map +1 -0
- package/lib/utils.d.ts +7 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +56 -0
- package/lib/utils.js.map +1 -0
- package/mf-manifest.json +396 -0
- package/mf-stats.json +453 -0
- package/package.json +53 -0
package/lib/cjs/utils.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
calculatePercentages: function() {
|
|
25
|
+
return calculatePercentages;
|
|
26
|
+
},
|
|
27
|
+
sortSeriesData: function() {
|
|
28
|
+
return sortSeriesData;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const _barchartmodel = require("./bar-chart-model");
|
|
32
|
+
function calculatePercentages(data) {
|
|
33
|
+
const sum = data.reduce((accumulator, { value })=>accumulator + (value ?? 0), 0);
|
|
34
|
+
return data.map((seriesData)=>{
|
|
35
|
+
const percentage = (seriesData.value ?? 0) / sum * 100;
|
|
36
|
+
return {
|
|
37
|
+
...seriesData,
|
|
38
|
+
value: percentage
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function sortSeriesData(data, sortOrder = _barchartmodel.DEFAULT_SORT) {
|
|
43
|
+
if (sortOrder === 'asc') {
|
|
44
|
+
// sort in ascending order by value
|
|
45
|
+
return data.sort((a, b)=>{
|
|
46
|
+
if (a.value === null) {
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
if (b.value === null) {
|
|
50
|
+
return -1;
|
|
51
|
+
}
|
|
52
|
+
if (a.value === b.value) {
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
return a.value < b.value ? 1 : -1;
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
// sort in descending order by value
|
|
59
|
+
return data.sort((a, b)=>{
|
|
60
|
+
if (a.value === null) {
|
|
61
|
+
return -1;
|
|
62
|
+
}
|
|
63
|
+
if (b.value === null) {
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
if (a.value === b.value) {
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
return a.value < b.value ? -1 : 1;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
package/lib/env.d.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
/// <reference types="@rsbuild/core/types" />
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=env.d.js.map
|
package/lib/env.d.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/env.d.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\n/// <reference types=\"@rsbuild/core/types\" />\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,6CAA6C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPluginModule.d.ts","sourceRoot":"","sources":["../../src/getPluginModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAoB,MAAM,2BAA2B,CAAC;AAGnF;;GAEG;AACH,wBAAgB,eAAe,IAAI,oBAAoB,CAUtD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import packageJson from '../package.json';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the plugin module information from package.json
|
|
4
|
+
*/ export function getPluginModule() {
|
|
5
|
+
const { name, version, perses } = packageJson;
|
|
6
|
+
return {
|
|
7
|
+
kind: 'PluginModule',
|
|
8
|
+
metadata: {
|
|
9
|
+
name,
|
|
10
|
+
version
|
|
11
|
+
},
|
|
12
|
+
spec: perses
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=getPluginModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/getPluginModule.ts"],"sourcesContent":["import { PluginModuleResource, PluginModuleSpec } from '@perses-dev/plugin-system';\nimport packageJson from '../package.json';\n\n/**\n * Returns the plugin module information from package.json\n */\nexport function getPluginModule(): PluginModuleResource {\n const { name, version, perses } = packageJson;\n return {\n kind: 'PluginModule',\n metadata: {\n name,\n version,\n },\n spec: perses as PluginModuleSpec,\n };\n}\n"],"names":["packageJson","getPluginModule","name","version","perses","kind","metadata","spec"],"mappings":"AACA,OAAOA,iBAAiB,kBAAkB;AAE1C;;CAEC,GACD,OAAO,SAASC;IACd,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGJ;IAClC,OAAO;QACLK,MAAM;QACNC,UAAU;YACRJ;YACAC;QACF;QACAI,MAAMH;IACR;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=index-federation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-federation.d.ts","sourceRoot":"","sources":["../../src/index-federation.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
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('./bootstrap');
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index-federation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index-federation.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('./bootstrap');\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,MAAM,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,iCAAiC,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,cAAc,SAAS,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
export * from './bar-chart-model';
|
|
14
|
+
export * from './BarChart';
|
|
15
|
+
export * from './BarChartOptionsEditorSettings';
|
|
16
|
+
export { getPluginModule } from './getPluginModule';
|
|
17
|
+
export * from './utils';
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.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\nexport * from './bar-chart-model';\nexport * from './BarChart';\nexport * from './BarChartOptionsEditorSettings';\nexport { getPluginModule } from './getPluginModule';\nexport * from './utils';\n"],"names":["getPluginModule"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,oBAAoB;AAClC,cAAc,aAAa;AAC3B,cAAc,kCAAkC;AAChD,SAASA,eAAe,QAAQ,oBAAoB;AACpD,cAAc,UAAU"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ThresholdColorPalette, ThresholdOptions, FormatOptions } from '@perses-dev/core';
|
|
2
|
+
export type GaugeColorStop = [number, string];
|
|
3
|
+
export type EChartsAxisLineColors = GaugeColorStop[];
|
|
4
|
+
export declare const defaultThresholdInput: ThresholdOptions;
|
|
5
|
+
export declare function convertThresholds(thresholds: ThresholdOptions, unit: FormatOptions, max: number, palette: ThresholdColorPalette): EChartsAxisLineColors;
|
|
6
|
+
//# sourceMappingURL=tresholds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tresholds.d.ts","sourceRoot":"","sources":["../../src/tresholds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,qBAAqB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGvG,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE9C,MAAM,MAAM,qBAAqB,GAAG,cAAc,EAAE,CAAC;AAErD,eAAO,MAAM,qBAAqB,EAAE,gBAA4C,CAAC;AAEjF,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,gBAAgB,EAC5B,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,qBAAqB,GAC7B,qBAAqB,CA4BvB"}
|
package/lib/tresholds.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import zip from 'lodash/zip';
|
|
2
|
+
export const defaultThresholdInput = {
|
|
3
|
+
steps: [
|
|
4
|
+
{
|
|
5
|
+
value: 0
|
|
6
|
+
}
|
|
7
|
+
]
|
|
8
|
+
};
|
|
9
|
+
export function convertThresholds(thresholds, unit, max, palette) {
|
|
10
|
+
const defaultThresholdColor = thresholds.defaultColor ?? palette.defaultColor;
|
|
11
|
+
const defaultThresholdSteps = [
|
|
12
|
+
[
|
|
13
|
+
0,
|
|
14
|
+
defaultThresholdColor
|
|
15
|
+
]
|
|
16
|
+
];
|
|
17
|
+
if (thresholds.steps !== undefined) {
|
|
18
|
+
// https://echarts.apache.org/en/option.html#series-gauge.axisLine.lineStyle.color
|
|
19
|
+
// color segments must be decimal between 0 and 1
|
|
20
|
+
const segmentMax = 1;
|
|
21
|
+
const valuesArr = thresholds.steps.map((step)=>{
|
|
22
|
+
if (thresholds.mode === 'percent') {
|
|
23
|
+
return step.value / 100;
|
|
24
|
+
}
|
|
25
|
+
return step.value / max;
|
|
26
|
+
});
|
|
27
|
+
valuesArr.push(segmentMax);
|
|
28
|
+
const colorsArr = thresholds.steps.map((step, index)=>step.color ?? palette.palette[index]);
|
|
29
|
+
colorsArr.unshift(defaultThresholdColor);
|
|
30
|
+
const zippedArr = zip(valuesArr, colorsArr);
|
|
31
|
+
return zippedArr.map((elem)=>{
|
|
32
|
+
const convertedValues = elem[0] ?? segmentMax;
|
|
33
|
+
const convertedColors = elem[1] ?? defaultThresholdColor;
|
|
34
|
+
return [
|
|
35
|
+
convertedValues,
|
|
36
|
+
convertedColors
|
|
37
|
+
];
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
return defaultThresholdSteps;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=tresholds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/tresholds.ts"],"sourcesContent":["import { StepOptions, ThresholdColorPalette, ThresholdOptions, FormatOptions } from '@perses-dev/core';\nimport zip from 'lodash/zip';\n\nexport type GaugeColorStop = [number, string];\n\nexport type EChartsAxisLineColors = GaugeColorStop[];\n\nexport const defaultThresholdInput: ThresholdOptions = { steps: [{ value: 0 }] };\n\nexport function convertThresholds(\n thresholds: ThresholdOptions,\n unit: FormatOptions,\n max: number,\n palette: ThresholdColorPalette\n): EChartsAxisLineColors {\n const defaultThresholdColor = thresholds.defaultColor ?? palette.defaultColor;\n const defaultThresholdSteps: EChartsAxisLineColors = [[0, defaultThresholdColor]];\n\n if (thresholds.steps !== undefined) {\n // https://echarts.apache.org/en/option.html#series-gauge.axisLine.lineStyle.color\n // color segments must be decimal between 0 and 1\n const segmentMax = 1;\n const valuesArr: number[] = thresholds.steps.map((step: StepOptions) => {\n if (thresholds.mode === 'percent') {\n return step.value / 100;\n }\n return step.value / max;\n });\n valuesArr.push(segmentMax);\n\n const colorsArr = thresholds.steps.map((step: StepOptions, index) => step.color ?? palette.palette[index]);\n colorsArr.unshift(defaultThresholdColor);\n\n const zippedArr = zip(valuesArr, colorsArr);\n return zippedArr.map((elem) => {\n const convertedValues = elem[0] ?? segmentMax;\n const convertedColors = elem[1] ?? defaultThresholdColor;\n return [convertedValues, convertedColors];\n });\n } else {\n return defaultThresholdSteps;\n }\n}\n"],"names":["zip","defaultThresholdInput","steps","value","convertThresholds","thresholds","unit","max","palette","defaultThresholdColor","defaultColor","defaultThresholdSteps","undefined","segmentMax","valuesArr","map","step","mode","push","colorsArr","index","color","unshift","zippedArr","elem","convertedValues","convertedColors"],"mappings":"AACA,OAAOA,SAAS,aAAa;AAM7B,OAAO,MAAMC,wBAA0C;IAAEC,OAAO;QAAC;YAAEC,OAAO;QAAE;KAAE;AAAC,EAAE;AAEjF,OAAO,SAASC,kBACdC,UAA4B,EAC5BC,IAAmB,EACnBC,GAAW,EACXC,OAA8B;IAE9B,MAAMC,wBAAwBJ,WAAWK,YAAY,IAAIF,QAAQE,YAAY;IAC7E,MAAMC,wBAA+C;QAAC;YAAC;YAAGF;SAAsB;KAAC;IAEjF,IAAIJ,WAAWH,KAAK,KAAKU,WAAW;QAClC,kFAAkF;QAClF,iDAAiD;QACjD,MAAMC,aAAa;QACnB,MAAMC,YAAsBT,WAAWH,KAAK,CAACa,GAAG,CAAC,CAACC;YAChD,IAAIX,WAAWY,IAAI,KAAK,WAAW;gBACjC,OAAOD,KAAKb,KAAK,GAAG;YACtB;YACA,OAAOa,KAAKb,KAAK,GAAGI;QACtB;QACAO,UAAUI,IAAI,CAACL;QAEf,MAAMM,YAAYd,WAAWH,KAAK,CAACa,GAAG,CAAC,CAACC,MAAmBI,QAAUJ,KAAKK,KAAK,IAAIb,QAAQA,OAAO,CAACY,MAAM;QACzGD,UAAUG,OAAO,CAACb;QAElB,MAAMc,YAAYvB,IAAIc,WAAWK;QACjC,OAAOI,UAAUR,GAAG,CAAC,CAACS;YACpB,MAAMC,kBAAkBD,IAAI,CAAC,EAAE,IAAIX;YACnC,MAAMa,kBAAkBF,IAAI,CAAC,EAAE,IAAIf;YACnC,OAAO;gBAACgB;gBAAiBC;aAAgB;QAC3C;IACF,OAAO;QACL,OAAOf;IACT;AACF"}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BarChartData, SortOption } from '@perses-dev/components';
|
|
2
|
+
export declare function calculatePercentages(data: BarChartData[]): Array<{
|
|
3
|
+
label: string;
|
|
4
|
+
value: number;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function sortSeriesData(data: BarChartData[], sortOrder?: SortOption): BarChartData[];
|
|
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,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CASlG;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 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 { DEFAULT_SORT } from './bar-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
|
package/lib/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils.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 { BarChartData, SortOption } from '@perses-dev/components';\nimport { DEFAULT_SORT } from './bar-chart-model';\n\nexport function calculatePercentages(data: BarChartData[]): Array<{ label: 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: BarChartData[], sortOrder: SortOption = DEFAULT_SORT): BarChartData[] {\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"}
|