fix the issue that chart axis's min/max value can't be zero (#18743)

* fix chart option issue

* pr comment
This commit is contained in:
Alan Ren
2022-03-15 17:55:16 -07:00
committed by GitHub
parent d585e75706
commit 784a9270c8
2 changed files with 9 additions and 8 deletions

View File

@@ -389,8 +389,9 @@ export class ChartView extends Disposable implements IPanelView {
numberInput.setAriaLabel(option.label); numberInput.setAriaLabel(option.label);
numberInput.value = value || ''; numberInput.value = value || '';
numberInput.onDidChange(e => { numberInput.onDidChange(e => {
if (this._options[entry] !== Number(e)) { if (this._options[entry] !== e) {
(this._options[entry] as any) = Number(e); // When user clears the input box, the value we get from the input box will be empty string.
(this._options[entry] as any) = (e === '' ? undefined : Number(e));
if (this.insight) { if (this.insight) {
this.insight.options = this._options; this.insight.options = this._options;
} }

View File

@@ -208,11 +208,11 @@ export class Graph implements IInsight {
} }
}]; }];
if (options.xAxisMax) { if (options.xAxisMax !== undefined) {
retval.scales = mixin(retval.scales, { xAxes: [{ ticks: { max: options.xAxisMax } }] }, true, customMixin); retval.scales = mixin(retval.scales, { xAxes: [{ ticks: { max: options.xAxisMax } }] }, true, customMixin);
} }
if (options.xAxisMin) { if (options.xAxisMin !== undefined) {
retval.scales = mixin(retval.scales, { xAxes: [{ ticks: { min: options.xAxisMin } }] }, true, customMixin); retval.scales = mixin(retval.scales, { xAxes: [{ ticks: { min: options.xAxisMin } }] }, true, customMixin);
} }
@@ -230,17 +230,17 @@ export class Graph implements IInsight {
} }
}]; }];
if (options.yAxisMax) { if (options.yAxisMax !== undefined) {
retval.scales = mixin(retval.scales, { yAxes: [{ ticks: { max: options.yAxisMax } }] }, true, customMixin); retval.scales = mixin(retval.scales, { yAxes: [{ ticks: { max: options.yAxisMax } }] }, true, customMixin);
} }
if (options.yAxisMin) { if (options.yAxisMin !== undefined) {
retval.scales = mixin(retval.scales, { yAxes: [{ ticks: { min: options.yAxisMin } }] }, true, customMixin); retval.scales = mixin(retval.scales, { yAxes: [{ ticks: { min: options.yAxisMin } }] }, true, customMixin);
} }
if (this.originalType === ChartType.TimeSeries) { if (this.originalType === ChartType.TimeSeries) {
retval = mixin(retval, timeSeriesScales, true, customMixin); retval = mixin(retval, timeSeriesScales, true, customMixin);
if (options.xAxisMax) { if (options.xAxisMax !== undefined) {
retval = mixin(retval, { retval = mixin(retval, {
scales: { scales: {
xAxes: [{ xAxes: [{
@@ -252,7 +252,7 @@ export class Graph implements IInsight {
}, true, customMixin); }, true, customMixin);
} }
if (options.xAxisMin) { if (options.xAxisMin !== undefined) {
retval = mixin(retval, { retval = mixin(retval, {
scales: { scales: {
xAxes: [{ xAxes: [{