Skip to content

feat(stack by dimension): add a stack by dimension dropdown list #32707

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 } from '@superset-ui/core';
import { JsonArray, t } from '@superset-ui/core';
import {
ControlPanelConfig,
ControlPanelsContainerProps,
Expand Down Expand Up @@ -53,6 +53,7 @@ const {
yAxisBounds,
zoomable,
orientation,
stackbydimension,
} = DEFAULT_FORM_DATA;

function createAxisTitleControl(axis: 'x' | 'y'): ControlSetRow[] {
Expand Down Expand Up @@ -317,6 +318,52 @@ const config: ControlPanelConfig = {
label: t('Chart Options'),
expanded: true,
controlSetRows: [
[
{
name: 'stackbydimension',
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we use camelCase for the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

config: {
type: 'CheckboxControl',
label: t('Stack by dimension'),
default: stackbydimension,
renderTrigger: true,
description: t(
'Stack in groups, where each group corresponds to a dimension',
),
},
},
],
[
{
name: 'stackdimension',
Copy link
Member

Choose a reason for hiding this comment

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

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

config: {
type: 'SelectControl',
label: t('Dimension to stack by'),
visibility: ({ controls }) =>
Boolean(controls?.stackbydimension?.value),
renderTrigger: true,
description: t(
'Stack in groups, where each group corresponds to a dimension',
),
shouldMapStateToProps: (
prevState,
state,
controlState,
chartState,
) => true,
mapStateToProps: (state, controlState, chartState) => {
const value: JsonArray = state.controls.groupby
.value as JsonArray;
const valueAsStringArr: string[][] = value.map(v => {
if (v) return [v.toString(), v.toString()];
return ['', ''];
});
return {
choices: valueAsStringArr,
};
},
},
},
],
...seriesOrderSection,
['color_scheme'],
['time_shift_color'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const DEFAULT_FORM_DATA: EchartsTimeseriesFormData = {
truncateYAxis: false,
yAxisBounds: [null, null],
zoomable: false,
stackbydimension: false,
richTooltip: true,
xAxisForceCategorical: false,
xAxisLabelRotation: defaultXAxis.xAxisLabelRotation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ export default function transformProps(
yAxisTitleMargin,
yAxisTitlePosition,
zoomable,
stackbydimension,
stackdimension,
}: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData };
const refs: Refs = {};
const groupBy = ensureIsArray(groupby);
Expand Down Expand Up @@ -420,6 +422,19 @@ export default function transformProps(
}
});

if (stackbydimension && stackdimension && chartProps.rawFormData.groupby) {
const idxSelectedDimension =
formData.metrics.length > 1
? 1
: 0 + chartProps.rawFormData.groupby.indexOf(stackdimension);
for (const s of series) {
if (s.id) {
const columnsArr = labelMap[s.id];
(s as any).stack = columnsArr[idxSelectedDimension];
}
}
}

// axis bounds need to be parsed to replace incompatible values with undefined
const [xAxisMin, xAxisMax] = (xAxisBounds || []).map(parseAxisBound);
let [yAxisMin, yAxisMax] = (yAxisBounds || []).map(parseAxisBound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export type EchartsTimeseriesFormData = QueryFormData & {
rowLimit: number;
seriesType: EchartsTimeseriesSeriesType;
stack: StackType;
stackbydimension: boolean;
stackdimension: string;
timeCompare?: string[];
tooltipTimeFormat?: string;
showTooltipTotal?: boolean;
Expand Down
Loading