chore: clean up mixed-timeseries chart (#1352)

This commit is contained in:
Yongjie Zhao
2021-11-26 11:47:29 +08:00
parent e149c537ee
commit 463b15382e
@@ -16,13 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import {
buildQueryContext,
getMetricLabel,
QueryFormData,
QueryObject,
normalizeOrderBy,
} from '@superset-ui/core';
import { buildQueryContext, QueryFormData, QueryObject, normalizeOrderBy } from '@superset-ui/core';
import { pivotOperator } from '@superset-ui/chart-controls';
export default function buildQuery(formData: QueryFormData) {
const {
@@ -61,45 +56,19 @@ export default function buildQuery(formData: QueryFormData) {
};
const queryContextA = buildQueryContext(formData1, baseQueryObject => {
const metricLabels = (baseQueryObject.metrics || []).map(getMetricLabel);
const queryObjectA = {
...baseQueryObject,
is_timeseries: true,
post_processing: [
{
operation: 'pivot',
options: {
index: ['__timestamp'],
columns: formData1.columns || [],
// Create 'dummy' sum aggregates to assign cell values in pivot table
aggregates: Object.fromEntries(
metricLabels.map(metric => [metric, { operator: 'sum' }]),
),
},
},
],
post_processing: [pivotOperator(formData1, { ...baseQueryObject, is_timeseries: true })],
} as QueryObject;
return [normalizeOrderBy(queryObjectA)];
});
const queryContextB = buildQueryContext(formData2, baseQueryObject => {
const metricLabels = (baseQueryObject.metrics || []).map(getMetricLabel);
const queryObjectB = {
...baseQueryObject,
is_timeseries: true,
post_processing: [
{
operation: 'pivot',
options: {
index: ['__timestamp'],
columns: formData2.columns || [],
// Create 'dummy' sum aggregates to assign cell values in pivot table
aggregates: Object.fromEntries(
metricLabels.map(metric => [metric, { operator: 'sum' }]),
),
},
},
],
post_processing: [pivotOperator(formData2, { ...baseQueryObject, is_timeseries: true })],
} as QueryObject;
return [normalizeOrderBy(queryObjectB)];
});