fix(plugin-chart-echarts): support truncated numeric x-axis (#26215)

Co-authored-by: Michael S. Molina <michael.s.molina@gmail.com>
This commit is contained in:
Ville Brofeldt
2023-12-08 05:40:09 -08:00
committed by GitHub
parent 05d7060d83
commit 07e5fe8a66
19 changed files with 150 additions and 31 deletions

View File

@@ -48,6 +48,7 @@ describe('Bubble transformProps', () => {
expressionType: 'simple',
label: 'SUM(sales)',
},
xAxisBounds: [null, null],
yAxisBounds: [null, null],
};
const chartProps = new ChartProps({

View File

@@ -16,22 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
import { parseYAxisBound } from '../../src/utils/controls';
import { parseAxisBound } from '../../src/utils/controls';
describe('parseYAxisBound', () => {
it('should return undefined for invalid values', () => {
expect(parseYAxisBound(null)).toBeUndefined();
expect(parseYAxisBound(undefined)).toBeUndefined();
expect(parseYAxisBound(NaN)).toBeUndefined();
expect(parseYAxisBound('abc')).toBeUndefined();
expect(parseAxisBound(null)).toBeUndefined();
expect(parseAxisBound(undefined)).toBeUndefined();
expect(parseAxisBound(NaN)).toBeUndefined();
expect(parseAxisBound('abc')).toBeUndefined();
});
it('should return numeric value for valid values', () => {
expect(parseYAxisBound(0)).toEqual(0);
expect(parseYAxisBound('0')).toEqual(0);
expect(parseYAxisBound(1)).toEqual(1);
expect(parseYAxisBound('1')).toEqual(1);
expect(parseYAxisBound(10.1)).toEqual(10.1);
expect(parseYAxisBound('10.1')).toEqual(10.1);
expect(parseAxisBound(0)).toEqual(0);
expect(parseAxisBound('0')).toEqual(0);
expect(parseAxisBound(1)).toEqual(1);
expect(parseAxisBound('1')).toEqual(1);
expect(parseAxisBound(10.1)).toEqual(10.1);
expect(parseAxisBound('10.1')).toEqual(10.1);
});
});

View File

@@ -36,6 +36,7 @@ import {
getChartPadding,
getLegendProps,
getOverMaxHiddenFormatter,
getMinAndMaxFromBounds,
sanitizeHtml,
sortAndFilterSeries,
sortRows,
@@ -879,3 +880,30 @@ test('getAxisType', () => {
expect(getAxisType(GenericDataType.BOOLEAN)).toEqual(AxisType.category);
expect(getAxisType(GenericDataType.STRING)).toEqual(AxisType.category);
});
test('getMinAndMaxFromBounds returns empty object when not truncating', () => {
expect(getMinAndMaxFromBounds(AxisType.value, false, 10, 100)).toEqual({});
});
test('getMinAndMaxFromBounds returns automatic bounds when truncating', () => {
expect(
getMinAndMaxFromBounds(AxisType.value, true, undefined, undefined),
).toEqual({
min: 'dataMin',
max: 'dataMax',
});
});
test('getMinAndMaxFromBounds returns automatic upper bound when truncating', () => {
expect(getMinAndMaxFromBounds(AxisType.value, true, 10, undefined)).toEqual({
min: 10,
max: 'dataMax',
});
});
test('getMinAndMaxFromBounds returns automatic lower bound when truncating', () => {
expect(getMinAndMaxFromBounds(AxisType.value, true, undefined, 100)).toEqual({
min: 'dataMin',
max: 100,
});
});