Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
feat(plugin-chart-echarts): add orderby on Radar chart (#1112)
Browse files Browse the repository at this point in the history
* feat(plugin-chart-echarts): add SORT BY metrics to Radar

* fix(plugin-chart-echarts): use timeseries_limit_metric to metrics orderby
  • Loading branch information
xiezhongfu authored May 21, 2021
1 parent 2be365b commit 3c24a78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
30 changes: 22 additions & 8 deletions plugins/plugin-chart-echarts/src/Radar/buildQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@
* specific language governing permissions and limitations
* under the License.
*/
import { buildQueryContext, QueryFormData } from '@superset-ui/core';
import { buildQueryContext, QueryFormData, ensureIsArray } from '@superset-ui/core';

export default function buildQuery(formData: QueryFormData) {
const { metric, sort_by_metric } = formData;
return buildQueryContext(formData, baseQueryObject => [
{
...baseQueryObject,
...(sort_by_metric && { orderby: [[metric, false]] }),
},
]);
const { timeseries_limit_metric } = formData;
const sortByMetric = ensureIsArray(timeseries_limit_metric)[0];

return buildQueryContext(formData, baseQueryObject => {
let { metrics, orderby = [] } = baseQueryObject;
metrics = metrics || [];
// orverride orderby with timeseries metric
if (sortByMetric) {
orderby = [[sortByMetric, false]];
} else if (metrics?.length > 0) {
// default to ordering by first metric in descending order
// when no "sort by" metric is set (regargless if "SORT DESC" is set to true)
orderby = [[metrics[0], false]];
}
return [
{
...baseQueryObject,
orderby,
},
];
});
}
1 change: 1 addition & 0 deletions plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const config: ControlPanelConfig = {
controlSetRows: [
['groupby'],
['metrics'],
['timeseries_limit_metric'],
['adhoc_filters'],
[
{
Expand Down

1 comment on commit 3c24a78

@vercel
Copy link

@vercel vercel bot commented on 3c24a78 May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.