(core) Changes X-AXIS to LABEL in the axis config when chart is a pie chart

Summary:
Also fixes issue with group data options when switching to pie chart.

Issue was that if the group data picker was on, switching to the pie
chart was not hiding it.

Test Plan: Adds more tests.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3028
This commit is contained in:
Cyprien P 2021-09-17 11:32:12 +02:00
parent 9bc9872915
commit a1480faa09

View File

@ -372,6 +372,25 @@ export class ChartConfig extends GrainJSDisposable {
this._groupDataForce.set(val);
});
// The label to show for the first field in the axis configurator.
private _firstFieldLabel = Computed.create(this, fromKo(this._section.chartTypeDef), (
(_use, chartType) => chartType === 'pie' ? 'LABEL' : 'X-AXIS'
));
// A computed that returns `this._section.chartTypeDef` and that takes care of removing the group
// data option when type is switched to 'pie'.
private _chartType = Computed.create(this, (use) => use(this._section.chartTypeDef))
.onWrite((val) => {
return this._gristDoc.docData.bundleActions('switched chart type', async () => {
await this._section.chartTypeDef.saveOnly(val);
// When switching chart type to 'pie' makes sure to remove the group data option.
if (val === 'pie') {
await this._setGroupDataColumn(-1);
this._groupDataForce.set(false);
}
});
});
constructor(private _gristDoc: GristDoc, private _section: ViewSectionRec) {
super();
@ -385,7 +404,7 @@ export class ChartConfig extends GrainJSDisposable {
return [
cssRow(
select(fromKoSave(this._section.chartTypeDef), [
select(this._chartType, [
{value: 'bar', label: 'Bar Chart', icon: 'ChartBar' },
{value: 'pie', label: 'Pie Chart', icon: 'ChartPie' },
{value: 'area', label: 'Area Chart', icon: 'ChartArea' },
@ -434,7 +453,7 @@ export class ChartConfig extends GrainJSDisposable {
]),
// TODO: user should select x axis before widget reach page
cssLabel('X-AXIS'),
cssLabel(dom.text(this._firstFieldLabel), testId('first-field-label')),
cssRow(
select(
this._xAxis, this._section.table().columns().peek()
@ -525,7 +544,7 @@ export class ChartConfig extends GrainJSDisposable {
this._freezeXAxis.set(false);
this._freezeYAxis.set(false);
}
});
}, {nestInActiveBundle: true});
}
private _buildField(col: IField) {