feat: Adds the ECharts Sunburst chart (#22833)

This commit is contained in:
Michael S. Molina
2023-01-31 11:39:18 -05:00
committed by GitHub
parent cd6fc35f60
commit 30abefb519
13 changed files with 166 additions and 103 deletions

View File

@@ -16,17 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
import { DataRecord } from '@superset-ui/core';
import { DataRecord, DataRecordValue } from '@superset-ui/core';
import _ from 'lodash';
export type TreeNode = {
name: string;
name: DataRecordValue;
value: number;
secondaryValue: number;
groupBy: string;
children?: TreeNode[];
};
function getMetricValue(datum: DataRecord, metric: string) {
return _.isNumber(datum[metric]) ? (datum[metric] as number) : 0;
}
export function treeBuilder(
data: DataRecord[],
groupBy: string[],
@@ -37,7 +41,8 @@ export function treeBuilder(
const curData = _.groupBy(data, curGroupBy);
return _.transform(
curData,
(result, value, name) => {
(result, value, key) => {
const name = curData[key][0][curGroupBy]!;
if (!restGroupby.length) {
(value ?? []).forEach(datum => {
const metricValue = getMetricValue(datum, metric);
@@ -81,7 +86,3 @@ export function treeBuilder(
[] as TreeNode[],
);
}
function getMetricValue(datum: DataRecord, metric: string) {
return _.isNumber(datum[metric]) ? (datum[metric] as number) : 0;
}