-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: get Axis from a helper function #21449
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* 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 { | ||
DTTM_ALIAS, | ||
getColumnLabel, | ||
isDefined, | ||
QueryFormData, | ||
} from '@superset-ui/core'; | ||
|
||
export const getAxis = (formData: QueryFormData): string | undefined => { | ||
// The formData should be "raw form_data" -- the snake_case version of formData rather than camelCase. | ||
if (!(formData.granularity_sqla || formData.x_axis)) { | ||
return undefined; | ||
} | ||
|
||
return isDefined(formData.x_axis) | ||
? getColumnLabel(formData.x_axis) | ||
: DTTM_ALIAS; | ||
}; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,18 +20,17 @@ | |
import { | ||
AnnotationLayer, | ||
CategoricalColorNamespace, | ||
DTTM_ALIAS, | ||
GenericDataType, | ||
getColumnLabel, | ||
getNumberFormatter, | ||
isEventAnnotationLayer, | ||
isFormulaAnnotationLayer, | ||
isIntervalAnnotationLayer, | ||
isTimeseriesAnnotationLayer, | ||
TimeseriesChartDataResponseResult, | ||
t, | ||
DTTM_ALIAS, | ||
} from '@superset-ui/core'; | ||
import { isDerivedSeries } from '@superset-ui/chart-controls'; | ||
import { getAxis, isDerivedSeries } from '@superset-ui/chart-controls'; | ||
import { EChartsCoreOption, SeriesOption } from 'echarts'; | ||
import { ZRLineType } from 'echarts/types/src/util/types'; | ||
import { | ||
|
@@ -149,8 +148,9 @@ export default function transformProps( | |
|
||
const colorScale = CategoricalColorNamespace.getScale(colorScheme as string); | ||
const rebasedData = rebaseForecastDatum(data, verboseMap); | ||
// todo: if the both granularity_sqla and x_axis are `null`, should throw an error | ||
const xAxisCol = | ||
verboseMap[xAxisOrig] || getColumnLabel(xAxisOrig || DTTM_ALIAS); | ||
verboseMap[xAxisOrig] || getAxis(chartProps.rawFormData) || DTTM_ALIAS; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the |
||
const isHorizontal = orientation === OrientationType.horizontal; | ||
const { totalStackedValues, thresholdValues } = extractDataTotalValues( | ||
rebasedData, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To future proof this to n dimensions, I think it might make sense to call this helper
getBaseAxes
that returns an array (that way we also wouldn't need to wrap the return value in an array when passing it to theindex
prop). Also, I believe the return type should be based onQueryFormColumn
, as it may also be anAdhocColumn
. So maybe the sig should beAlso, shouldn't we assume that the return value should always be defined, i.e. we always fall back to
DTTM_ALIAS
(at least for now) unlessformData.x_axis
is defined?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function returns a label of a column(the label of the columns, or alias clause for the SQL), so the return value might be a string rather than a structure data(QueryFormColumn).
another issue is that whether the return value is a
string
or astring array
. both work for me, but thestring array
return value might not directly apply to thepost processing
function. I promise that if we will support the multiple axes, I am going to refactor this.The
undefined
value represents a form_data that cannot apply a query with an axis. For example, if aform_data
hadgranularity_sqla
neither noraxis
, this function would return anundefined
value, then the caller should easily skip some logic.