Skip to content

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 and zhaoyongjie committed Nov 26, 2021
1 parent ade57cf commit 32ebeff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
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,
},
];
});
}
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

0 comments on commit 32ebeff

Please sign in to comment.