Skip to content

Commit

Permalink
feat: Adds the ECharts Heatmap chart (#25353)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Mar 28, 2024
1 parent d69a187 commit 546d48a
Show file tree
Hide file tree
Showing 23 changed files with 929 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export { contributionOperator } from './contributionOperator';
export { prophetOperator } from './prophetOperator';
export { boxplotOperator } from './boxplotOperator';
export { flattenOperator } from './flattenOperator';
export { rankOperator } from './rankOperator';
export * from './utils';
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitationsxw
* under the License.
*/
import { PostProcessingRank } from '@superset-ui/core';
import { PostProcessingFactory } from './types';

/* eslint-disable @typescript-eslint/no-unused-vars */
export const rankOperator: PostProcessingFactory<PostProcessingRank> = (
formData,
queryObject,
options,
) => ({
operation: 'rank',
options,
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
import { QueryFormData, QueryObject } from '@superset-ui/core';

export interface PostProcessingFactory<T> {
(formData: QueryFormData, queryObject: QueryObject): T;
(formData: QueryFormData, queryObject: QueryObject, options?: any): T;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { QueryObject, SqlaFormData } from '@superset-ui/core';
import { rankOperator } from '@superset-ui/chart-controls';

const formData: SqlaFormData = {
x_axis: 'dttm',
metrics: ['sales'],
groupby: ['department'],
time_range: '2015 : 2016',
granularity: 'month',
datasource: 'foo',
viz_type: 'table',
truncate_metric: true,
};
const queryObject: QueryObject = {
is_timeseries: true,
metrics: ['sales'],
columns: ['department'],
time_range: '2015 : 2016',
granularity: 'month',
post_processing: [],
};

test('should add rankOperator', () => {
const options = { metric: 'sales', group_by: 'department' };
expect(rankOperator(formData, queryObject, options)).toEqual({
operation: 'rank',
options,
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ export type PostProcessingFlatten =
| _PostProcessingFlatten
| DefaultPostProcessing;

interface _PostProcessingRank {
operation: 'rank';
options?: {
metric: string;
group_by: string | null;
};
}
export type PostProcessingRank = _PostProcessingRank | DefaultPostProcessing;

/**
* Parameters for chart data postprocessing.
* See superset/utils/pandas_processing.py.
Expand All @@ -241,7 +250,8 @@ export type PostProcessingRule =
| PostProcessingSort
| PostProcessingResample
| PostProcessingRename
| PostProcessingFlatten;
| PostProcessingFlatten
| PostProcessingRank;

export function isPostProcessingAggregation(
rule?: PostProcessingRule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { t, ChartMetadata, ChartPlugin } from '@superset-ui/core';
import { t, ChartMetadata, ChartPlugin, ChartLabel } from '@superset-ui/core';
import transformProps from './transformProps';
import transportation from './images/transportation.jpg';
import channels from './images/channels.jpg';
Expand All @@ -35,19 +35,24 @@ const metadata = new ChartMetadata({
{ url: channels, caption: t('Relationships between community channels') },
{ url: employment, caption: t('Employment and education') },
],
name: t('Heatmap'),
label: ChartLabel.DEPRECATED,
name: t('Heatmap (legacy)'),
tags: [
t('Business'),
t('Intensity'),
t('Legacy'),
t('Density'),
t('Predictive'),
t('Single Metric'),
t('Deprecated'),
],
thumbnail,
useLegacyApi: true,
});

/**
* @deprecated in version 4.0.
*/
export default class HeatmapChartPlugin extends ChartPlugin {
constructor() {
super({
Expand Down
35 changes: 18 additions & 17 deletions superset-frontend/plugins/plugin-chart-echarts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@
"name": "@superset-ui/plugin-chart-echarts",
"version": "0.18.25",
"description": "Superset Chart - Echarts",
"sideEffects": false,
"main": "lib/index.js",
"module": "esm/index.js",
"files": [
"esm",
"lib"
],
"repository": {
"type": "git",
"url": "https://github.com/apache/superset.git",
"directory": "superset-frontend/plugins/plugin-chart-echarts"
},
"keywords": [
"superset"
],
"author": "Superset",
"license": "Apache-2.0",
"homepage": "https://github.com/apache/superset/tree/master/superset-frontend/plugins/plugin-chart-echarts#readme",
"bugs": {
"url": "https://github.com/apache/superset/issues"
},
"homepage": "https://github.com/apache/superset/tree/master/superset-frontend/plugins/plugin-chart-echarts#readme",
"publishConfig": {
"access": "public"
"repository": {
"type": "git",
"url": "https://github.com/apache/superset.git",
"directory": "superset-frontend/plugins/plugin-chart-echarts"
},
"license": "Apache-2.0",
"author": "Superset",
"sideEffects": false,
"main": "lib/index.js",
"module": "esm/index.js",
"files": [
"esm",
"lib"
],
"dependencies": {
"d3-array": "^1.2.0",
"echarts": "^5.4.1",
Expand All @@ -35,6 +32,10 @@
"peerDependencies": {
"@superset-ui/chart-controls": "*",
"@superset-ui/core": "*",
"memoize-one": "*",
"react": "^16.13.1"
},
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { HeatmapTransformedProps } from './types';
import Echart from '../components/Echart';

export default function Heatmap(props: HeatmapTransformedProps) {
const { height, width, echartOptions, refs } = props;
return (
<Echart
refs={refs}
height={height}
width={width}
echartOptions={echartOptions}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import {
QueryFormColumn,
QueryFormOrderBy,
buildQueryContext,
ensureIsArray,
getColumnLabel,
getMetricLabel,
getXAxisColumn,
} from '@superset-ui/core';
import { rankOperator } from '@superset-ui/chart-controls';
import { HeatmapFormData } from './types';

export default function buildQuery(formData: HeatmapFormData) {
const { groupby, normalize_across, sort_x_axis, sort_y_axis, x_axis } =
formData;
const metric = getMetricLabel(formData.metric);
const columns = [
...ensureIsArray(getXAxisColumn(formData)),
...ensureIsArray(groupby),
];
const orderby: QueryFormOrderBy[] = [
[
sort_x_axis.includes('value') ? metric : columns[0],
sort_x_axis.includes('asc'),
],
[
sort_y_axis.includes('value') ? metric : columns[1],
sort_y_axis.includes('asc'),
],
];
const group_by =
normalize_across === 'x'
? getColumnLabel(x_axis)
: normalize_across === 'y'
? getColumnLabel(groupby as unknown as QueryFormColumn)
: undefined;
return buildQueryContext(formData, baseQueryObject => [
{
...baseQueryObject,
columns,
orderby,
post_processing: [
rankOperator(formData, baseQueryObject, {
metric,
group_by,
}),
],
},
]);
}
Loading

0 comments on commit 546d48a

Please sign in to comment.