2019-09-17 20:57:53 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
2021-02-04 03:12:39 +01:00
|
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
|
|
* 2.0.
|
2019-09-17 20:57:53 +02:00
|
|
|
*/
|
|
|
|
|
2020-03-20 17:37:11 +01:00
|
|
|
import {
|
|
|
|
AreaSeries,
|
|
|
|
Axis,
|
|
|
|
BarSeries,
|
|
|
|
Position,
|
|
|
|
LineSeries,
|
|
|
|
Settings,
|
|
|
|
ScaleType,
|
2020-03-24 20:51:00 +01:00
|
|
|
GeometryValue,
|
|
|
|
XYChartSeriesIdentifier,
|
2020-03-23 21:44:57 +01:00
|
|
|
SeriesNameFn,
|
2020-07-03 16:15:06 +02:00
|
|
|
Fit,
|
2020-03-20 17:37:11 +01:00
|
|
|
} from '@elastic/charts';
|
2020-11-04 11:27:52 +01:00
|
|
|
import { PaletteOutput } from 'src/plugins/charts/public';
|
2020-12-22 17:35:27 +01:00
|
|
|
import {
|
|
|
|
calculateMinInterval,
|
|
|
|
xyChart,
|
|
|
|
XYChart,
|
|
|
|
XYChartProps,
|
|
|
|
XYChartRenderProps,
|
|
|
|
} from './expression';
|
2019-09-17 20:57:53 +02:00
|
|
|
import { LensMultiTable } from '../types';
|
2020-10-16 18:46:51 +02:00
|
|
|
import { Datatable, DatatableRow } from '../../../../../src/plugins/expressions/public';
|
2019-09-17 20:57:53 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
2020-08-11 19:10:35 +02:00
|
|
|
import {
|
|
|
|
XYArgs,
|
|
|
|
LegendConfig,
|
|
|
|
legendConfig,
|
|
|
|
layerConfig,
|
|
|
|
LayerArgs,
|
|
|
|
AxesSettingsConfig,
|
|
|
|
tickLabelsConfig,
|
|
|
|
gridlinesConfig,
|
|
|
|
} from './types';
|
2020-04-15 12:22:37 +02:00
|
|
|
import { createMockExecutionContext } from '../../../../../src/plugins/expressions/common/mocks';
|
2020-11-13 01:19:56 +01:00
|
|
|
import { mountWithIntl } from '@kbn/test/jest';
|
2020-07-02 16:02:30 +02:00
|
|
|
import { chartPluginMock } from '../../../../../src/plugins/charts/public/mocks';
|
2020-10-07 10:36:56 +02:00
|
|
|
import { EmptyPlaceholder } from '../shared_components/empty_placeholder';
|
2020-03-24 20:51:00 +01:00
|
|
|
|
2020-05-15 12:01:27 +02:00
|
|
|
const onClickValue = jest.fn();
|
|
|
|
const onSelectRange = jest.fn();
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-07-02 16:02:30 +02:00
|
|
|
const chartsThemeService = chartPluginMock.createSetupContract().theme;
|
2020-11-04 11:27:52 +01:00
|
|
|
const paletteService = chartPluginMock.createPaletteRegistry();
|
|
|
|
|
|
|
|
const mockPaletteOutput: PaletteOutput = {
|
|
|
|
type: 'palette',
|
|
|
|
name: 'mock',
|
|
|
|
params: {},
|
|
|
|
};
|
2020-07-02 16:02:30 +02:00
|
|
|
|
2020-04-30 20:36:50 +02:00
|
|
|
const dateHistogramData: LensMultiTable = {
|
|
|
|
type: 'lens_multitable',
|
|
|
|
tables: {
|
|
|
|
timeLayer: {
|
2020-10-16 18:46:51 +02:00
|
|
|
type: 'datatable',
|
2020-04-30 20:36:50 +02:00
|
|
|
rows: [
|
|
|
|
{
|
|
|
|
xAccessorId: 1585758120000,
|
|
|
|
splitAccessorId: "Men's Clothing",
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 1585758360000,
|
|
|
|
splitAccessorId: "Women's Accessories",
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 1585758360000,
|
|
|
|
splitAccessorId: "Women's Clothing",
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 1585759380000,
|
|
|
|
splitAccessorId: "Men's Clothing",
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 1585759380000,
|
|
|
|
splitAccessorId: "Men's Shoes",
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 1585759380000,
|
|
|
|
splitAccessorId: "Women's Clothing",
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 1585760700000,
|
|
|
|
splitAccessorId: "Men's Clothing",
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 1585760760000,
|
|
|
|
splitAccessorId: "Men's Clothing",
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 1585760760000,
|
|
|
|
splitAccessorId: "Men's Shoes",
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 1585761120000,
|
|
|
|
splitAccessorId: "Men's Shoes",
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
id: 'xAccessorId',
|
|
|
|
name: 'order_date per minute',
|
|
|
|
meta: {
|
2020-10-16 18:46:51 +02:00
|
|
|
type: 'date',
|
|
|
|
field: 'order_date',
|
|
|
|
source: 'esaggs',
|
|
|
|
index: 'indexPatternId',
|
|
|
|
sourceParams: {
|
|
|
|
indexPatternId: 'indexPatternId',
|
|
|
|
type: 'date_histogram',
|
|
|
|
params: {
|
|
|
|
field: 'order_date',
|
|
|
|
timeRange: { from: '2020-04-01T16:14:16.246Z', to: '2020-04-01T17:15:41.263Z' },
|
|
|
|
useNormalizedEsInterval: true,
|
|
|
|
scaleMetricValues: false,
|
|
|
|
interval: '1m',
|
|
|
|
drop_partials: false,
|
|
|
|
min_doc_count: 0,
|
|
|
|
extended_bounds: {},
|
|
|
|
},
|
2020-04-30 20:36:50 +02:00
|
|
|
},
|
2020-10-16 18:46:51 +02:00
|
|
|
params: { id: 'date', params: { pattern: 'HH:mm' } },
|
2020-04-30 20:36:50 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'splitAccessorId',
|
|
|
|
name: 'Top values of category.keyword',
|
|
|
|
meta: {
|
2020-10-16 18:46:51 +02:00
|
|
|
type: 'string',
|
|
|
|
field: 'category.keyword',
|
|
|
|
source: 'esaggs',
|
|
|
|
index: 'indexPatternId',
|
|
|
|
sourceParams: {
|
|
|
|
indexPatternId: 'indexPatternId',
|
|
|
|
type: 'terms',
|
|
|
|
params: {
|
|
|
|
field: 'category.keyword',
|
|
|
|
orderBy: 'yAccessorId',
|
|
|
|
order: 'desc',
|
|
|
|
size: 3,
|
|
|
|
otherBucket: false,
|
|
|
|
otherBucketLabel: 'Other',
|
|
|
|
missingBucket: false,
|
|
|
|
missingBucketLabel: 'Missing',
|
|
|
|
},
|
2020-04-30 20:36:50 +02:00
|
|
|
},
|
|
|
|
params: {
|
2020-10-16 18:46:51 +02:00
|
|
|
id: 'terms',
|
|
|
|
params: {
|
|
|
|
id: 'string',
|
|
|
|
otherBucketLabel: 'Other',
|
|
|
|
missingBucketLabel: 'Missing',
|
|
|
|
parsedUrl: {
|
|
|
|
origin: 'http://localhost:5601',
|
|
|
|
pathname: '/jiy/app/kibana',
|
|
|
|
basePath: '/jiy',
|
|
|
|
},
|
2020-04-30 20:36:50 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'yAccessorId',
|
|
|
|
name: 'Count of records',
|
|
|
|
meta: {
|
2020-10-16 18:46:51 +02:00
|
|
|
type: 'number',
|
|
|
|
source: 'esaggs',
|
|
|
|
index: 'indexPatternId',
|
|
|
|
sourceParams: {
|
|
|
|
indexPatternId: 'indexPatternId',
|
|
|
|
params: {},
|
|
|
|
},
|
|
|
|
params: { id: 'number' },
|
2020-04-30 20:36:50 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dateRange: {
|
|
|
|
fromDate: new Date('2020-04-01T16:14:16.246Z'),
|
|
|
|
toDate: new Date('2020-04-01T17:15:41.263Z'),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const dateHistogramLayer: LayerArgs = {
|
|
|
|
layerId: 'timeLayer',
|
|
|
|
hide: false,
|
|
|
|
xAccessor: 'xAccessorId',
|
|
|
|
yScaleType: 'linear',
|
|
|
|
xScaleType: 'time',
|
|
|
|
isHistogram: true,
|
|
|
|
splitAccessor: 'splitAccessorId',
|
|
|
|
seriesType: 'bar_stacked',
|
|
|
|
accessors: ['yAccessorId'],
|
2020-11-04 11:27:52 +01:00
|
|
|
palette: mockPaletteOutput,
|
2020-04-30 20:36:50 +02:00
|
|
|
};
|
|
|
|
|
2020-10-16 18:46:51 +02:00
|
|
|
const createSampleDatatableWithRows = (rows: DatatableRow[]): Datatable => ({
|
|
|
|
type: 'datatable',
|
2020-04-02 09:26:23 +02:00
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
id: 'a',
|
|
|
|
name: 'a',
|
2020-10-16 18:46:51 +02:00
|
|
|
meta: { type: 'number', params: { id: 'number', params: { pattern: '0,0.000' } } },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'b',
|
|
|
|
name: 'b',
|
|
|
|
meta: { type: 'number', params: { id: 'number', params: { pattern: '000,0' } } },
|
2020-04-02 09:26:23 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'c',
|
|
|
|
name: 'c',
|
2020-10-16 18:46:51 +02:00
|
|
|
meta: {
|
|
|
|
type: 'date',
|
|
|
|
field: 'order_date',
|
|
|
|
sourceParams: { type: 'date-histogram', params: { interval: 'auto' } },
|
|
|
|
params: { id: 'string' },
|
|
|
|
},
|
2020-04-02 09:26:23 +02:00
|
|
|
},
|
2020-10-16 18:46:51 +02:00
|
|
|
{ id: 'd', name: 'ColD', meta: { type: 'string' } },
|
2020-04-02 09:26:23 +02:00
|
|
|
],
|
|
|
|
rows,
|
|
|
|
});
|
|
|
|
|
|
|
|
const sampleLayer: LayerArgs = {
|
|
|
|
layerId: 'first',
|
|
|
|
seriesType: 'line',
|
|
|
|
xAccessor: 'c',
|
|
|
|
accessors: ['a', 'b'],
|
|
|
|
splitAccessor: 'd',
|
|
|
|
columnToLabel: '{"a": "Label A", "b": "Label B", "d": "Label D"}',
|
|
|
|
xScaleType: 'ordinal',
|
|
|
|
yScaleType: 'linear',
|
|
|
|
isHistogram: false,
|
2020-11-04 11:27:52 +01:00
|
|
|
palette: mockPaletteOutput,
|
2020-04-02 09:26:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const createArgsWithLayers = (layers: LayerArgs[] = [sampleLayer]): XYArgs => ({
|
|
|
|
xTitle: '',
|
|
|
|
yTitle: '',
|
2020-09-16 10:30:19 +02:00
|
|
|
yRightTitle: '',
|
2020-04-02 09:26:23 +02:00
|
|
|
legend: {
|
|
|
|
type: 'lens_xy_legendConfig',
|
|
|
|
isVisible: false,
|
|
|
|
position: Position.Top,
|
|
|
|
},
|
2020-11-06 16:34:30 +01:00
|
|
|
valueLabels: 'hide',
|
2020-09-16 10:30:19 +02:00
|
|
|
axisTitlesVisibilitySettings: {
|
|
|
|
type: 'lens_xy_axisTitlesVisibilityConfig',
|
|
|
|
x: true,
|
|
|
|
yLeft: true,
|
|
|
|
yRight: true,
|
|
|
|
},
|
2020-08-11 19:10:35 +02:00
|
|
|
tickLabelsVisibilitySettings: {
|
|
|
|
type: 'lens_xy_tickLabelsConfig',
|
|
|
|
x: true,
|
2020-09-16 10:30:19 +02:00
|
|
|
yLeft: false,
|
|
|
|
yRight: false,
|
2020-08-11 19:10:35 +02:00
|
|
|
},
|
|
|
|
gridlinesVisibilitySettings: {
|
|
|
|
type: 'lens_xy_gridlinesConfig',
|
|
|
|
x: true,
|
2020-09-16 10:30:19 +02:00
|
|
|
yLeft: false,
|
|
|
|
yRight: false,
|
2020-08-11 19:10:35 +02:00
|
|
|
},
|
2020-04-02 09:26:23 +02:00
|
|
|
layers,
|
|
|
|
});
|
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
function sampleArgs() {
|
|
|
|
const data: LensMultiTable = {
|
|
|
|
type: 'lens_multitable',
|
|
|
|
tables: {
|
2020-04-02 09:26:23 +02:00
|
|
|
first: createSampleDatatableWithRows([
|
|
|
|
{ a: 1, b: 2, c: 'I', d: 'Foo' },
|
|
|
|
{ a: 1, b: 5, c: 'J', d: 'Bar' },
|
|
|
|
]),
|
2019-09-17 20:57:53 +02:00
|
|
|
},
|
2020-11-20 17:18:22 +01:00
|
|
|
dateRange: {
|
|
|
|
fromDate: new Date('2019-01-02T05:00:00.000Z'),
|
|
|
|
toDate: new Date('2019-01-03T05:00:00.000Z'),
|
|
|
|
},
|
2019-09-17 20:57:53 +02:00
|
|
|
};
|
|
|
|
|
2020-04-02 09:26:23 +02:00
|
|
|
const args: XYArgs = createArgsWithLayers();
|
2019-09-17 20:57:53 +02:00
|
|
|
|
|
|
|
return { data, args };
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('xy_expression', () => {
|
|
|
|
describe('configs', () => {
|
|
|
|
test('legendConfig produces the correct arguments', () => {
|
|
|
|
const args: LegendConfig = {
|
|
|
|
isVisible: true,
|
|
|
|
position: Position.Left,
|
|
|
|
};
|
|
|
|
|
2020-02-11 19:47:36 +01:00
|
|
|
const result = legendConfig.fn(null, args, createMockExecutionContext());
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
2019-09-17 20:57:53 +02:00
|
|
|
type: 'lens_xy_legendConfig',
|
|
|
|
...args,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('layerConfig produces the correct arguments', () => {
|
|
|
|
const args: LayerArgs = {
|
|
|
|
layerId: 'first',
|
|
|
|
seriesType: 'line',
|
|
|
|
xAccessor: 'c',
|
|
|
|
accessors: ['a', 'b'],
|
|
|
|
splitAccessor: 'd',
|
|
|
|
xScaleType: 'linear',
|
|
|
|
yScaleType: 'linear',
|
|
|
|
isHistogram: false,
|
2020-11-04 11:27:52 +01:00
|
|
|
palette: mockPaletteOutput,
|
2019-09-17 20:57:53 +02:00
|
|
|
};
|
|
|
|
|
2020-02-11 19:47:36 +01:00
|
|
|
const result = layerConfig.fn(null, args, createMockExecutionContext());
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
2019-09-17 20:57:53 +02:00
|
|
|
type: 'lens_xy_layer',
|
|
|
|
...args,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-11 19:10:35 +02:00
|
|
|
test('tickLabelsConfig produces the correct arguments', () => {
|
|
|
|
const args: AxesSettingsConfig = {
|
|
|
|
x: true,
|
2020-09-16 10:30:19 +02:00
|
|
|
yLeft: false,
|
|
|
|
yRight: false,
|
2020-08-11 19:10:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const result = tickLabelsConfig.fn(null, args, createMockExecutionContext());
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
type: 'lens_xy_tickLabelsConfig',
|
|
|
|
...args,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('gridlinesConfig produces the correct arguments', () => {
|
|
|
|
const args: AxesSettingsConfig = {
|
|
|
|
x: true,
|
2020-09-16 10:30:19 +02:00
|
|
|
yLeft: false,
|
|
|
|
yRight: false,
|
2020-08-11 19:10:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const result = gridlinesConfig.fn(null, args, createMockExecutionContext());
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
type: 'lens_xy_gridlinesConfig',
|
|
|
|
...args,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
describe('xyChart', () => {
|
|
|
|
test('it renders with the specified data and args', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
2020-02-11 19:47:36 +01:00
|
|
|
const result = xyChart.fn(data, args, createMockExecutionContext());
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-02-11 19:47:36 +01:00
|
|
|
expect(result).toEqual({
|
2019-09-17 20:57:53 +02:00
|
|
|
type: 'render',
|
|
|
|
as: 'lens_xy_chart_renderer',
|
|
|
|
value: { data, args },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('XYChart component', () => {
|
|
|
|
let getFormatSpy: jest.Mock;
|
|
|
|
let convertSpy: jest.Mock;
|
2020-12-22 17:35:27 +01:00
|
|
|
let defaultProps: Omit<XYChartRenderProps, 'data' | 'args'>;
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-07-01 09:57:23 +02:00
|
|
|
const dataWithoutFormats: LensMultiTable = {
|
|
|
|
type: 'lens_multitable',
|
|
|
|
tables: {
|
|
|
|
first: {
|
2020-10-16 18:46:51 +02:00
|
|
|
type: 'datatable',
|
2020-07-01 09:57:23 +02:00
|
|
|
columns: [
|
2020-10-16 18:46:51 +02:00
|
|
|
{ id: 'a', name: 'a', meta: { type: 'number' } },
|
|
|
|
{ id: 'b', name: 'b', meta: { type: 'number' } },
|
|
|
|
{ id: 'c', name: 'c', meta: { type: 'string' } },
|
|
|
|
{ id: 'd', name: 'd', meta: { type: 'string' } },
|
2020-07-01 09:57:23 +02:00
|
|
|
],
|
|
|
|
rows: [
|
|
|
|
{ a: 1, b: 2, c: 'I', d: 'Row 1' },
|
|
|
|
{ a: 1, b: 5, c: 'J', d: 'Row 2' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const dataWithFormats: LensMultiTable = {
|
|
|
|
type: 'lens_multitable',
|
|
|
|
tables: {
|
|
|
|
first: {
|
2020-10-16 18:46:51 +02:00
|
|
|
type: 'datatable',
|
2020-07-01 09:57:23 +02:00
|
|
|
columns: [
|
2020-10-16 18:46:51 +02:00
|
|
|
{ id: 'a', name: 'a', meta: { type: 'number' } },
|
|
|
|
{ id: 'b', name: 'b', meta: { type: 'number' } },
|
|
|
|
{ id: 'c', name: 'c', meta: { type: 'string' } },
|
|
|
|
{ id: 'd', name: 'd', meta: { type: 'string', params: { id: 'custom' } } },
|
2020-07-01 09:57:23 +02:00
|
|
|
],
|
|
|
|
rows: [
|
|
|
|
{ a: 1, b: 2, c: 'I', d: 'Row 1' },
|
|
|
|
{ a: 1, b: 5, c: 'J', d: 'Row 2' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const getRenderedComponent = (data: LensMultiTable, args: XYArgs) => {
|
2020-12-22 17:35:27 +01:00
|
|
|
return shallow(<XYChart {...defaultProps} data={data} args={args} />);
|
2020-07-01 09:57:23 +02:00
|
|
|
};
|
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
beforeEach(() => {
|
2020-05-22 09:08:58 +02:00
|
|
|
convertSpy = jest.fn((x) => x);
|
2019-09-17 20:57:53 +02:00
|
|
|
getFormatSpy = jest.fn();
|
|
|
|
getFormatSpy.mockReturnValue({ convert: convertSpy });
|
2020-12-22 17:35:27 +01:00
|
|
|
|
|
|
|
defaultProps = {
|
|
|
|
formatFactory: getFormatSpy,
|
|
|
|
timeZone: 'UTC',
|
|
|
|
renderMode: 'display',
|
|
|
|
chartsThemeService,
|
|
|
|
paletteService,
|
|
|
|
minInterval: 50,
|
|
|
|
onClickValue,
|
|
|
|
onSelectRange,
|
|
|
|
syncColors: false,
|
|
|
|
};
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it renders line', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={data}
|
|
|
|
args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'line' }] }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(component).toMatchSnapshot();
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(LineSeries)).toHaveLength(2);
|
|
|
|
expect(component.find(LineSeries).at(0).prop('yAccessors')).toEqual(['a']);
|
|
|
|
expect(component.find(LineSeries).at(1).prop('yAccessors')).toEqual(['b']);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2020-04-02 09:26:23 +02:00
|
|
|
describe('date range', () => {
|
|
|
|
const timeSampleLayer: LayerArgs = {
|
|
|
|
layerId: 'first',
|
|
|
|
seriesType: 'line',
|
|
|
|
xAccessor: 'c',
|
|
|
|
accessors: ['a', 'b'],
|
|
|
|
splitAccessor: 'd',
|
|
|
|
columnToLabel: '{"a": "Label A", "b": "Label B", "d": "Label D"}',
|
|
|
|
xScaleType: 'time',
|
|
|
|
yScaleType: 'linear',
|
|
|
|
isHistogram: false,
|
2020-11-04 11:27:52 +01:00
|
|
|
palette: mockPaletteOutput,
|
2020-04-02 09:26:23 +02:00
|
|
|
};
|
|
|
|
const multiLayerArgs = createArgsWithLayers([
|
|
|
|
timeSampleLayer,
|
|
|
|
{
|
|
|
|
...timeSampleLayer,
|
|
|
|
layerId: 'second',
|
|
|
|
seriesType: 'bar',
|
|
|
|
xScaleType: 'time',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
test('it uses the full date range', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
2019-10-16 00:14:40 +02:00
|
|
|
|
2020-04-02 09:26:23 +02:00
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2020-04-02 09:26:23 +02:00
|
|
|
data={{
|
|
|
|
...data,
|
|
|
|
dateRange: {
|
|
|
|
fromDate: new Date('2019-01-02T05:00:00.000Z'),
|
|
|
|
toDate: new Date('2019-01-03T05:00:00.000Z'),
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
args={{
|
|
|
|
...args,
|
|
|
|
layers: [{ ...args.layers[0], seriesType: 'line', xScaleType: 'time' }],
|
|
|
|
}}
|
2020-11-20 17:18:22 +01:00
|
|
|
minInterval={undefined}
|
2020-04-02 09:26:23 +02:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(component.find(Settings).prop('xDomain')).toMatchInlineSnapshot(`
|
|
|
|
Object {
|
|
|
|
"max": 1546491600000,
|
|
|
|
"min": 1546405200000,
|
|
|
|
"minInterval": undefined,
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
|
2020-11-20 17:18:22 +01:00
|
|
|
test('it uses passed in minInterval', () => {
|
2020-04-02 09:26:23 +02:00
|
|
|
const data: LensMultiTable = {
|
|
|
|
type: 'lens_multitable',
|
|
|
|
tables: {
|
|
|
|
first: createSampleDatatableWithRows([{ a: 1, b: 2, c: 'I', d: 'Foo' }]),
|
|
|
|
second: createSampleDatatableWithRows([]),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2020-04-02 09:26:23 +02:00
|
|
|
data={{
|
|
|
|
...data,
|
|
|
|
dateRange: {
|
|
|
|
fromDate: new Date('2019-01-02T05:00:00.000Z'),
|
|
|
|
toDate: new Date('2019-01-03T05:00:00.000Z'),
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
args={multiLayerArgs}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2020-04-29 14:47:45 +02:00
|
|
|
// real auto interval is 30mins = 1800000
|
2020-04-02 09:26:23 +02:00
|
|
|
expect(component.find(Settings).prop('xDomain')).toMatchInlineSnapshot(`
|
|
|
|
Object {
|
|
|
|
"max": 1546491600000,
|
|
|
|
"min": 1546405200000,
|
2020-11-20 17:18:22 +01:00
|
|
|
"minInterval": 50,
|
2020-04-02 09:26:23 +02:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
});
|
2019-10-16 00:14:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it does not use date range if the x is not a time scale', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-10-16 00:14:40 +02:00
|
|
|
data={{
|
|
|
|
...data,
|
|
|
|
dateRange: {
|
|
|
|
fromDate: new Date('2019-01-02T05:00:00.000Z'),
|
|
|
|
toDate: new Date('2019-01-03T05:00:00.000Z'),
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
args={{
|
|
|
|
...args,
|
|
|
|
layers: [{ ...args.layers[0], seriesType: 'line', xScaleType: 'linear' }],
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(component.find(Settings).prop('xDomain')).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
test('it renders bar', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={data}
|
|
|
|
args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'bar' }] }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(component).toMatchSnapshot();
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(BarSeries)).toHaveLength(2);
|
|
|
|
expect(component.find(BarSeries).at(0).prop('yAccessors')).toEqual(['a']);
|
|
|
|
expect(component.find(BarSeries).at(1).prop('yAccessors')).toEqual(['b']);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it renders area', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={data}
|
|
|
|
args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'area' }] }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(component).toMatchSnapshot();
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(AreaSeries)).toHaveLength(2);
|
|
|
|
expect(component.find(AreaSeries).at(0).prop('yAccessors')).toEqual(['a']);
|
|
|
|
expect(component.find(AreaSeries).at(1).prop('yAccessors')).toEqual(['b']);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it renders horizontal bar', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={data}
|
2019-10-02 19:21:39 +02:00
|
|
|
args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'bar_horizontal' }] }}
|
2019-09-17 20:57:53 +02:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(component).toMatchSnapshot();
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(BarSeries)).toHaveLength(2);
|
|
|
|
expect(component.find(BarSeries).at(0).prop('yAccessors')).toEqual(['a']);
|
|
|
|
expect(component.find(BarSeries).at(1).prop('yAccessors')).toEqual(['b']);
|
2019-09-17 20:57:53 +02:00
|
|
|
expect(component.find(Settings).prop('rotation')).toEqual(90);
|
|
|
|
});
|
|
|
|
|
2020-10-07 10:36:56 +02:00
|
|
|
test('it renders regular bar empty placeholder for no results', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
// send empty data to the chart
|
|
|
|
data.tables.first.rows = [];
|
|
|
|
|
2020-12-22 17:35:27 +01:00
|
|
|
const component = shallow(<XYChart {...defaultProps} data={data} args={args} />);
|
2020-10-07 10:36:56 +02:00
|
|
|
|
|
|
|
expect(component.find(BarSeries)).toHaveLength(0);
|
|
|
|
expect(component.find(EmptyPlaceholder).prop('icon')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2020-04-30 20:36:50 +02:00
|
|
|
test('onBrushEnd returns correct context data for date histogram data', () => {
|
|
|
|
const { args } = sampleArgs();
|
|
|
|
|
|
|
|
const wrapper = mountWithIntl(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2020-04-30 20:36:50 +02:00
|
|
|
data={dateHistogramData}
|
|
|
|
args={{
|
|
|
|
...args,
|
|
|
|
layers: [dateHistogramLayer],
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2020-05-22 09:08:58 +02:00
|
|
|
wrapper.find(Settings).first().prop('onBrushEnd')!({ x: [1585757732783, 1585758880838] });
|
2020-04-30 20:36:50 +02:00
|
|
|
|
2020-05-15 12:01:27 +02:00
|
|
|
expect(onSelectRange).toHaveBeenCalledWith({
|
|
|
|
column: 0,
|
|
|
|
table: dateHistogramData.tables.timeLayer,
|
|
|
|
range: [1585757732783, 1585758880838],
|
2020-04-30 20:36:50 +02:00
|
|
|
timeFieldName: 'order_date',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-07 10:20:58 +02:00
|
|
|
test('onBrushEnd returns correct context data for number histogram data', () => {
|
|
|
|
const { args } = sampleArgs();
|
|
|
|
|
|
|
|
const numberLayer: LayerArgs = {
|
|
|
|
layerId: 'numberLayer',
|
|
|
|
hide: false,
|
|
|
|
xAccessor: 'xAccessorId',
|
|
|
|
yScaleType: 'linear',
|
|
|
|
xScaleType: 'linear',
|
|
|
|
isHistogram: true,
|
|
|
|
seriesType: 'bar_stacked',
|
|
|
|
accessors: ['yAccessorId'],
|
2020-11-04 11:27:52 +01:00
|
|
|
palette: mockPaletteOutput,
|
2020-10-07 10:20:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const numberHistogramData: LensMultiTable = {
|
|
|
|
type: 'lens_multitable',
|
|
|
|
tables: {
|
|
|
|
numberLayer: {
|
2020-10-16 18:46:51 +02:00
|
|
|
type: 'datatable',
|
2020-10-07 10:20:58 +02:00
|
|
|
rows: [
|
|
|
|
{
|
|
|
|
xAccessorId: 5,
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 7,
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 8,
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
xAccessorId: 10,
|
|
|
|
yAccessorId: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
id: 'xAccessorId',
|
|
|
|
name: 'bytes',
|
2020-10-16 18:46:51 +02:00
|
|
|
meta: { type: 'number' },
|
2020-10-07 10:20:58 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'yAccessorId',
|
|
|
|
name: 'Count of records',
|
2020-10-16 18:46:51 +02:00
|
|
|
meta: { type: 'number' },
|
2020-10-07 10:20:58 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dateRange: {
|
|
|
|
fromDate: new Date('2020-04-01T16:14:16.246Z'),
|
|
|
|
toDate: new Date('2020-04-01T17:15:41.263Z'),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = mountWithIntl(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2020-10-07 10:20:58 +02:00
|
|
|
data={numberHistogramData}
|
|
|
|
args={{
|
|
|
|
...args,
|
|
|
|
layers: [numberLayer],
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
wrapper.find(Settings).first().prop('onBrushEnd')!({ x: [5, 8] });
|
|
|
|
|
|
|
|
expect(onSelectRange).toHaveBeenCalledWith({
|
|
|
|
column: 0,
|
|
|
|
table: numberHistogramData.tables.numberLayer,
|
|
|
|
range: [5, 8],
|
|
|
|
timeFieldName: undefined,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-24 18:42:02 +01:00
|
|
|
test('onBrushEnd is not set on noInteractivity mode', () => {
|
|
|
|
const { args, data } = sampleArgs();
|
|
|
|
|
|
|
|
const wrapper = mountWithIntl(
|
2020-12-22 17:35:27 +01:00
|
|
|
<XYChart {...defaultProps} data={data} args={args} renderMode="noInteractivity" />
|
2020-11-24 18:42:02 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.find(Settings).first().prop('onBrushEnd')).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2020-03-24 20:51:00 +01:00
|
|
|
test('onElementClick returns correct context data', () => {
|
2020-10-02 19:48:40 +02:00
|
|
|
const geometry: GeometryValue = { x: 5, y: 1, accessor: 'y1', mark: null, datum: {} };
|
2020-03-24 20:51:00 +01:00
|
|
|
const series = {
|
|
|
|
key: 'spec{d}yAccessor{d}splitAccessors{b-2}',
|
|
|
|
specId: 'd',
|
|
|
|
yAccessor: 'd',
|
|
|
|
splitAccessors: {},
|
|
|
|
seriesKeys: [2, 'd'],
|
|
|
|
};
|
|
|
|
|
|
|
|
const { args, data } = sampleArgs();
|
|
|
|
|
|
|
|
const wrapper = mountWithIntl(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2020-03-24 20:51:00 +01:00
|
|
|
data={data}
|
|
|
|
args={{
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
layerId: 'first',
|
|
|
|
isHistogram: true,
|
|
|
|
seriesType: 'bar_stacked',
|
|
|
|
xAccessor: 'b',
|
|
|
|
yScaleType: 'linear',
|
|
|
|
xScaleType: 'time',
|
|
|
|
splitAccessor: 'b',
|
|
|
|
accessors: ['d'],
|
|
|
|
columnToLabel: '{"a": "Label A", "b": "Label B", "d": "Label D"}',
|
2020-11-04 11:27:52 +01:00
|
|
|
palette: mockPaletteOutput,
|
2020-03-24 20:51:00 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2020-05-22 09:08:58 +02:00
|
|
|
wrapper.find(Settings).first().prop('onElementClick')!([
|
|
|
|
[geometry, series as XYChartSeriesIdentifier],
|
|
|
|
]);
|
2020-03-24 20:51:00 +01:00
|
|
|
|
2020-05-15 12:01:27 +02:00
|
|
|
expect(onClickValue).toHaveBeenCalledWith({
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
column: 1,
|
|
|
|
row: 1,
|
|
|
|
table: data.tables.first,
|
|
|
|
value: 5,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
column: 1,
|
|
|
|
row: 0,
|
|
|
|
table: data.tables.first,
|
|
|
|
value: 2,
|
|
|
|
},
|
|
|
|
],
|
2020-03-24 20:51:00 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-24 18:42:02 +01:00
|
|
|
test('onElementClick is not triggering event on noInteractivity mode', () => {
|
|
|
|
const { args, data } = sampleArgs();
|
|
|
|
|
|
|
|
const wrapper = mountWithIntl(
|
2020-12-22 17:35:27 +01:00
|
|
|
<XYChart {...defaultProps} data={data} args={args} renderMode="noInteractivity" />
|
2020-11-24 18:42:02 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.find(Settings).first().prop('onElementClick')).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
test('it renders stacked bar', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={data}
|
|
|
|
args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'bar_stacked' }] }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(component).toMatchSnapshot();
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(BarSeries)).toHaveLength(2);
|
|
|
|
expect(component.find(BarSeries).at(0).prop('stackAccessors')).toHaveLength(1);
|
|
|
|
expect(component.find(BarSeries).at(1).prop('stackAccessors')).toHaveLength(1);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it renders stacked area', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={data}
|
|
|
|
args={{ ...args, layers: [{ ...args.layers[0], seriesType: 'area_stacked' }] }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(component).toMatchSnapshot();
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(AreaSeries)).toHaveLength(2);
|
|
|
|
expect(component.find(AreaSeries).at(0).prop('stackAccessors')).toHaveLength(1);
|
|
|
|
expect(component.find(AreaSeries).at(1).prop('stackAccessors')).toHaveLength(1);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it renders stacked horizontal bar', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={data}
|
|
|
|
args={{
|
|
|
|
...args,
|
2019-10-02 19:21:39 +02:00
|
|
|
layers: [{ ...args.layers[0], seriesType: 'bar_horizontal_stacked' }],
|
2019-09-17 20:57:53 +02:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(component).toMatchSnapshot();
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(BarSeries)).toHaveLength(2);
|
|
|
|
expect(component.find(BarSeries).at(0).prop('stackAccessors')).toHaveLength(1);
|
|
|
|
expect(component.find(BarSeries).at(1).prop('stackAccessors')).toHaveLength(1);
|
2019-09-17 20:57:53 +02:00
|
|
|
expect(component.find(Settings).prop('rotation')).toEqual(90);
|
|
|
|
});
|
|
|
|
|
2020-10-07 10:36:56 +02:00
|
|
|
test('it renders stacked bar empty placeholder for no results', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2020-10-07 10:36:56 +02:00
|
|
|
data={data}
|
|
|
|
args={{
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
xAccessor: undefined,
|
|
|
|
splitAccessor: 'e',
|
|
|
|
seriesType: 'bar_stacked',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(component.find(BarSeries)).toHaveLength(0);
|
|
|
|
expect(component.find(EmptyPlaceholder).prop('icon')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
test('it passes time zone to the series', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
const component = shallow(
|
2020-12-22 17:35:27 +01:00
|
|
|
<XYChart {...defaultProps} data={data} args={args} timeZone="CEST" />
|
2019-09-17 20:57:53 +02:00
|
|
|
);
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(LineSeries).at(0).prop('timeZone')).toEqual('CEST');
|
|
|
|
expect(component.find(LineSeries).at(1).prop('timeZone')).toEqual('CEST');
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it applies histogram mode to the series for single series', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
2020-10-02 13:16:46 +02:00
|
|
|
const firstLayer: LayerArgs = {
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['b'],
|
|
|
|
seriesType: 'bar',
|
|
|
|
isHistogram: true,
|
|
|
|
};
|
2019-09-17 20:57:53 +02:00
|
|
|
delete firstLayer.splitAccessor;
|
|
|
|
const component = shallow(
|
2020-12-22 17:35:27 +01:00
|
|
|
<XYChart {...defaultProps} data={data} args={{ ...args, layers: [firstLayer] }} />
|
2019-09-17 20:57:53 +02:00
|
|
|
);
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(BarSeries).at(0).prop('enableHistogramMode')).toEqual(true);
|
2020-10-02 13:16:46 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it does not apply histogram mode to more than one bar series for unstacked bar chart', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
const firstLayer: LayerArgs = { ...args.layers[0], seriesType: 'bar', isHistogram: true };
|
|
|
|
delete firstLayer.splitAccessor;
|
|
|
|
const component = shallow(
|
2020-12-22 17:35:27 +01:00
|
|
|
<XYChart {...defaultProps} data={data} args={{ ...args, layers: [firstLayer] }} />
|
2020-10-02 13:16:46 +02:00
|
|
|
);
|
|
|
|
expect(component.find(BarSeries).at(0).prop('enableHistogramMode')).toEqual(false);
|
|
|
|
expect(component.find(BarSeries).at(1).prop('enableHistogramMode')).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it applies histogram mode to more than one the series for unstacked line/area chart', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
const firstLayer: LayerArgs = { ...args.layers[0], seriesType: 'line', isHistogram: true };
|
|
|
|
delete firstLayer.splitAccessor;
|
|
|
|
const secondLayer: LayerArgs = { ...args.layers[0], seriesType: 'line', isHistogram: true };
|
|
|
|
delete secondLayer.splitAccessor;
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2020-10-02 13:16:46 +02:00
|
|
|
data={data}
|
|
|
|
args={{ ...args, layers: [firstLayer, secondLayer] }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(component.find(LineSeries).at(0).prop('enableHistogramMode')).toEqual(true);
|
|
|
|
expect(component.find(LineSeries).at(1).prop('enableHistogramMode')).toEqual(true);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it applies histogram mode to the series for stacked series', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={data}
|
|
|
|
args={{
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
seriesType: 'bar_stacked',
|
|
|
|
isHistogram: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(BarSeries).at(0).prop('enableHistogramMode')).toEqual(true);
|
|
|
|
expect(component.find(BarSeries).at(1).prop('enableHistogramMode')).toEqual(true);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it does not apply histogram mode for splitted series', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={data}
|
|
|
|
args={{
|
|
|
|
...args,
|
|
|
|
layers: [{ ...args.layers[0], seriesType: 'bar', isHistogram: true }],
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(BarSeries).at(0).prop('enableHistogramMode')).toEqual(false);
|
|
|
|
expect(component.find(BarSeries).at(1).prop('enableHistogramMode')).toEqual(false);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
2020-07-01 09:57:23 +02:00
|
|
|
describe('y axes', () => {
|
|
|
|
test('single axis if possible', () => {
|
|
|
|
const args = createArgsWithLayers();
|
2020-04-14 23:20:18 +02:00
|
|
|
|
2020-07-01 09:57:23 +02:00
|
|
|
const component = getRenderedComponent(dataWithoutFormats, args);
|
|
|
|
const axes = component.find(Axis);
|
|
|
|
expect(axes).toHaveLength(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('multiple axes because of config', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['a', 'b'],
|
|
|
|
yConfig: [
|
|
|
|
{
|
|
|
|
forAccessor: 'a',
|
|
|
|
axisMode: 'left',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
forAccessor: 'b',
|
|
|
|
axisMode: 'right',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} as XYArgs;
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithoutFormats, newArgs);
|
|
|
|
const axes = component.find(Axis);
|
|
|
|
expect(axes).toHaveLength(3);
|
|
|
|
expect(component.find(LineSeries).at(0).prop('groupId')).toEqual(
|
|
|
|
axes.at(1).prop('groupId')
|
|
|
|
);
|
|
|
|
expect(component.find(LineSeries).at(1).prop('groupId')).toEqual(
|
|
|
|
axes.at(2).prop('groupId')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('multiple axes because of incompatible formatters', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['c', 'd'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} as XYArgs;
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithFormats, newArgs);
|
|
|
|
const axes = component.find(Axis);
|
|
|
|
expect(axes).toHaveLength(3);
|
|
|
|
expect(component.find(LineSeries).at(0).prop('groupId')).toEqual(
|
|
|
|
axes.at(1).prop('groupId')
|
|
|
|
);
|
|
|
|
expect(component.find(LineSeries).at(1).prop('groupId')).toEqual(
|
|
|
|
axes.at(2).prop('groupId')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('single axis despite different formatters if enforced', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['c', 'd'],
|
|
|
|
yConfig: [
|
|
|
|
{
|
|
|
|
forAccessor: 'c',
|
|
|
|
axisMode: 'left',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
forAccessor: 'd',
|
|
|
|
axisMode: 'left',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} as XYArgs;
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithoutFormats, newArgs);
|
|
|
|
const axes = component.find(Axis);
|
|
|
|
expect(axes).toHaveLength(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-03 13:22:47 +02:00
|
|
|
describe('y series coloring', () => {
|
|
|
|
test('color is applied to chart for multiple series', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
splitAccessor: undefined,
|
|
|
|
accessors: ['a', 'b'],
|
|
|
|
yConfig: [
|
|
|
|
{
|
|
|
|
forAccessor: 'a',
|
|
|
|
color: '#550000',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
forAccessor: 'b',
|
|
|
|
color: '#FFFF00',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
splitAccessor: undefined,
|
|
|
|
accessors: ['c'],
|
|
|
|
yConfig: [
|
|
|
|
{
|
|
|
|
forAccessor: 'c',
|
|
|
|
color: '#FEECDF',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} as XYArgs;
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithoutFormats, newArgs);
|
2020-11-04 11:27:52 +01:00
|
|
|
expect(
|
|
|
|
(component.find(LineSeries).at(0).prop('color') as Function)!({
|
|
|
|
yAccessor: 'a',
|
|
|
|
seriesKeys: ['a'],
|
|
|
|
})
|
|
|
|
).toEqual('#550000');
|
|
|
|
expect(
|
|
|
|
(component.find(LineSeries).at(1).prop('color') as Function)!({
|
|
|
|
yAccessor: 'b',
|
|
|
|
seriesKeys: ['b'],
|
|
|
|
})
|
|
|
|
).toEqual('#FFFF00');
|
|
|
|
expect(
|
|
|
|
(component.find(LineSeries).at(2).prop('color') as Function)!({
|
|
|
|
yAccessor: 'c',
|
|
|
|
seriesKeys: ['c'],
|
|
|
|
})
|
|
|
|
).toEqual('#FEECDF');
|
2020-07-03 13:22:47 +02:00
|
|
|
});
|
|
|
|
test('color is not applied to chart when splitAccessor is defined or when yConfig is not configured', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['a'],
|
|
|
|
yConfig: [
|
|
|
|
{
|
|
|
|
forAccessor: 'a',
|
|
|
|
color: '#550000',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
splitAccessor: undefined,
|
|
|
|
accessors: ['c'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} as XYArgs;
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithoutFormats, newArgs);
|
2020-11-04 11:27:52 +01:00
|
|
|
expect(
|
|
|
|
(component.find(LineSeries).at(0).prop('color') as Function)!({
|
|
|
|
yAccessor: 'a',
|
|
|
|
seriesKeys: ['a'],
|
|
|
|
})
|
2020-11-17 10:19:13 +01:00
|
|
|
).toEqual('blue');
|
2020-11-04 11:27:52 +01:00
|
|
|
expect(
|
|
|
|
(component.find(LineSeries).at(1).prop('color') as Function)!({
|
|
|
|
yAccessor: 'c',
|
|
|
|
seriesKeys: ['c'],
|
|
|
|
})
|
2020-11-17 10:19:13 +01:00
|
|
|
).toEqual('blue');
|
2020-07-03 13:22:47 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-01 09:57:23 +02:00
|
|
|
describe('provides correct series naming', () => {
|
2020-04-14 23:20:18 +02:00
|
|
|
const nameFnArgs = {
|
|
|
|
seriesKeys: [],
|
|
|
|
key: '',
|
|
|
|
specId: 'a',
|
|
|
|
yAccessor: '',
|
|
|
|
splitAccessors: new Map(),
|
|
|
|
};
|
|
|
|
|
|
|
|
test('simplest xy chart without human-readable name', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['a'],
|
|
|
|
splitAccessor: undefined,
|
|
|
|
columnToLabel: '',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithoutFormats, newArgs);
|
|
|
|
const nameFn = component.find(LineSeries).prop('name') as SeriesNameFn;
|
|
|
|
|
|
|
|
// In this case, the ID is used as the name. This shouldn't happen in practice
|
|
|
|
expect(nameFn({ ...nameFnArgs, seriesKeys: ['a'] }, false)).toEqual('');
|
|
|
|
expect(nameFn({ ...nameFnArgs, seriesKeys: ['nonsense'] }, false)).toEqual('');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('simplest xy chart with empty name', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['a'],
|
|
|
|
splitAccessor: undefined,
|
|
|
|
columnToLabel: '{"a":""}',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithoutFormats, newArgs);
|
|
|
|
const nameFn = component.find(LineSeries).prop('name') as SeriesNameFn;
|
|
|
|
|
|
|
|
// In this case, the ID is used as the name. This shouldn't happen in practice
|
|
|
|
expect(nameFn({ ...nameFnArgs, seriesKeys: ['a'] }, false)).toEqual('');
|
|
|
|
expect(nameFn({ ...nameFnArgs, seriesKeys: ['nonsense'] }, false)).toEqual('');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('simplest xy chart with human-readable name', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['a'],
|
|
|
|
splitAccessor: undefined,
|
|
|
|
columnToLabel: '{"a":"Column A"}',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithoutFormats, newArgs);
|
|
|
|
const nameFn = component.find(LineSeries).prop('name') as SeriesNameFn;
|
|
|
|
|
|
|
|
expect(nameFn({ ...nameFnArgs, seriesKeys: ['a'] }, false)).toEqual('Column A');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('multiple y accessors', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['a', 'b'],
|
|
|
|
splitAccessor: undefined,
|
|
|
|
columnToLabel: '{"a": "Label A"}',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithoutFormats, newArgs);
|
2020-07-01 09:57:23 +02:00
|
|
|
const nameFn1 = component.find(LineSeries).at(0).prop('name') as SeriesNameFn;
|
|
|
|
const nameFn2 = component.find(LineSeries).at(1).prop('name') as SeriesNameFn;
|
2020-04-14 23:20:18 +02:00
|
|
|
|
|
|
|
// This accessor has a human-readable name
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(nameFn1({ ...nameFnArgs, seriesKeys: ['a'] }, false)).toEqual('Label A');
|
2020-04-14 23:20:18 +02:00
|
|
|
// This accessor does not
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(nameFn2({ ...nameFnArgs, seriesKeys: ['b'] }, false)).toEqual('');
|
|
|
|
expect(nameFn1({ ...nameFnArgs, seriesKeys: ['nonsense'] }, false)).toEqual('');
|
2020-04-14 23:20:18 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('split series without formatting and single y accessor', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['a'],
|
|
|
|
splitAccessor: 'd',
|
|
|
|
columnToLabel: '{"a": "Label A"}',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithoutFormats, newArgs);
|
|
|
|
const nameFn = component.find(LineSeries).prop('name') as SeriesNameFn;
|
|
|
|
|
|
|
|
expect(nameFn({ ...nameFnArgs, seriesKeys: ['split1', 'a'] }, false)).toEqual('split1');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('split series with formatting and single y accessor', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['a'],
|
|
|
|
splitAccessor: 'd',
|
|
|
|
columnToLabel: '{"a": "Label A"}',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithFormats, newArgs);
|
|
|
|
const nameFn = component.find(LineSeries).prop('name') as SeriesNameFn;
|
|
|
|
|
|
|
|
convertSpy.mockReturnValueOnce('formatted');
|
|
|
|
expect(nameFn({ ...nameFnArgs, seriesKeys: ['split1', 'a'] }, false)).toEqual('formatted');
|
|
|
|
expect(getFormatSpy).toHaveBeenCalledWith({ id: 'custom' });
|
|
|
|
});
|
|
|
|
|
|
|
|
test('split series without formatting with multiple y accessors', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['a', 'b'],
|
|
|
|
splitAccessor: 'd',
|
|
|
|
columnToLabel: '{"a": "Label A","b": "Label B"}',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithoutFormats, newArgs);
|
2020-07-01 09:57:23 +02:00
|
|
|
const nameFn1 = component.find(LineSeries).at(0).prop('name') as SeriesNameFn;
|
|
|
|
const nameFn2 = component.find(LineSeries).at(0).prop('name') as SeriesNameFn;
|
2020-04-14 23:20:18 +02:00
|
|
|
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(nameFn1({ ...nameFnArgs, seriesKeys: ['split1', 'a'] }, false)).toEqual(
|
|
|
|
'split1 - Label A'
|
|
|
|
);
|
|
|
|
expect(nameFn2({ ...nameFnArgs, seriesKeys: ['split1', 'b'] }, false)).toEqual(
|
2020-04-14 23:20:18 +02:00
|
|
|
'split1 - Label B'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('split series with formatting with multiple y accessors', () => {
|
|
|
|
const args = createArgsWithLayers();
|
|
|
|
const newArgs = {
|
|
|
|
...args,
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
...args.layers[0],
|
|
|
|
accessors: ['a', 'b'],
|
|
|
|
splitAccessor: 'd',
|
|
|
|
columnToLabel: '{"a": "Label A","b": "Label B"}',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const component = getRenderedComponent(dataWithFormats, newArgs);
|
2020-07-01 09:57:23 +02:00
|
|
|
const nameFn1 = component.find(LineSeries).at(0).prop('name') as SeriesNameFn;
|
|
|
|
const nameFn2 = component.find(LineSeries).at(1).prop('name') as SeriesNameFn;
|
2020-04-14 23:20:18 +02:00
|
|
|
|
|
|
|
convertSpy.mockReturnValueOnce('formatted1').mockReturnValueOnce('formatted2');
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(nameFn1({ ...nameFnArgs, seriesKeys: ['split1', 'a'] }, false)).toEqual(
|
2020-04-14 23:20:18 +02:00
|
|
|
'formatted1 - Label A'
|
|
|
|
);
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(nameFn2({ ...nameFnArgs, seriesKeys: ['split1', 'b'] }, false)).toEqual(
|
2020-04-14 23:20:18 +02:00
|
|
|
'formatted2 - Label B'
|
|
|
|
);
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it set the scale of the x axis according to the args prop', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={data}
|
|
|
|
args={{ ...args, layers: [{ ...args.layers[0], xScaleType: 'ordinal' }] }}
|
|
|
|
/>
|
|
|
|
);
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(LineSeries).at(0).prop('xScaleType')).toEqual(ScaleType.Ordinal);
|
|
|
|
expect(component.find(LineSeries).at(1).prop('xScaleType')).toEqual(ScaleType.Ordinal);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it set the scale of the y axis according to the args prop', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={data}
|
|
|
|
args={{ ...args, layers: [{ ...args.layers[0], yScaleType: 'sqrt' }] }}
|
|
|
|
/>
|
|
|
|
);
|
2020-07-01 09:57:23 +02:00
|
|
|
expect(component.find(LineSeries).at(0).prop('yScaleType')).toEqual(ScaleType.Sqrt);
|
|
|
|
expect(component.find(LineSeries).at(1).prop('yScaleType')).toEqual(ScaleType.Sqrt);
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it gets the formatter for the x axis', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
2020-12-22 17:35:27 +01:00
|
|
|
shallow(<XYChart {...defaultProps} data={{ ...data }} args={{ ...args }} />);
|
2019-09-17 20:57:53 +02:00
|
|
|
|
|
|
|
expect(getFormatSpy).toHaveBeenCalledWith({ id: 'string' });
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it gets the formatter for the y axis if there is only one accessor', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2019-09-17 20:57:53 +02:00
|
|
|
data={{ ...data }}
|
|
|
|
args={{ ...args, layers: [{ ...args.layers[0], accessors: ['a'] }] }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(getFormatSpy).toHaveBeenCalledWith({
|
|
|
|
id: 'number',
|
|
|
|
params: { pattern: '0,0.000' },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it should pass the formatter function to the axis', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
2020-12-22 17:35:27 +01:00
|
|
|
const instance = shallow(<XYChart {...defaultProps} data={{ ...data }} args={{ ...args }} />);
|
2019-09-17 20:57:53 +02:00
|
|
|
|
2020-05-22 09:08:58 +02:00
|
|
|
const tickFormatter = instance.find(Axis).first().prop('tickFormat');
|
2020-01-04 13:38:11 +01:00
|
|
|
|
|
|
|
if (!tickFormatter) {
|
|
|
|
throw new Error('tickFormatter prop not found');
|
|
|
|
}
|
|
|
|
|
2019-09-17 20:57:53 +02:00
|
|
|
tickFormatter('I');
|
|
|
|
|
|
|
|
expect(convertSpy).toHaveBeenCalledWith('I');
|
|
|
|
});
|
2020-05-05 21:59:32 +02:00
|
|
|
|
2020-08-31 19:01:38 +02:00
|
|
|
test('it should set the tickLabel visibility on the x axis if the tick labels is hidden', () => {
|
2020-08-11 19:10:35 +02:00
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
2020-09-16 10:30:19 +02:00
|
|
|
args.tickLabelsVisibilitySettings = {
|
|
|
|
x: false,
|
|
|
|
yLeft: true,
|
|
|
|
yRight: true,
|
|
|
|
type: 'lens_xy_tickLabelsConfig',
|
|
|
|
};
|
2020-08-11 19:10:35 +02:00
|
|
|
|
2020-12-22 17:35:27 +01:00
|
|
|
const instance = shallow(<XYChart {...defaultProps} data={{ ...data }} args={{ ...args }} />);
|
2020-08-11 19:10:35 +02:00
|
|
|
|
2020-08-31 19:01:38 +02:00
|
|
|
const axisStyle = instance.find(Axis).first().prop('style');
|
2020-08-11 19:10:35 +02:00
|
|
|
|
2020-08-31 19:01:38 +02:00
|
|
|
expect(axisStyle).toMatchObject({
|
|
|
|
tickLabel: {
|
|
|
|
visible: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2020-08-11 19:10:35 +02:00
|
|
|
|
2020-08-31 19:01:38 +02:00
|
|
|
test('it should set the tickLabel visibility on the y axis if the tick labels is hidden', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
2020-09-16 10:30:19 +02:00
|
|
|
args.tickLabelsVisibilitySettings = {
|
|
|
|
x: true,
|
|
|
|
yLeft: false,
|
|
|
|
yRight: false,
|
|
|
|
type: 'lens_xy_tickLabelsConfig',
|
|
|
|
};
|
2020-08-11 19:10:35 +02:00
|
|
|
|
2020-12-22 17:35:27 +01:00
|
|
|
const instance = shallow(<XYChart {...defaultProps} data={{ ...data }} args={{ ...args }} />);
|
2020-08-31 19:01:38 +02:00
|
|
|
|
|
|
|
const axisStyle = instance.find(Axis).at(1).prop('style');
|
|
|
|
|
|
|
|
expect(axisStyle).toMatchObject({
|
|
|
|
tickLabel: {
|
|
|
|
visible: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it should set the tickLabel visibility on the x axis if the tick labels is shown', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
2020-09-16 10:30:19 +02:00
|
|
|
args.tickLabelsVisibilitySettings = {
|
|
|
|
x: true,
|
|
|
|
yLeft: true,
|
|
|
|
yRight: true,
|
|
|
|
type: 'lens_xy_tickLabelsConfig',
|
|
|
|
};
|
2020-08-31 19:01:38 +02:00
|
|
|
|
2020-12-22 17:35:27 +01:00
|
|
|
const instance = shallow(<XYChart {...defaultProps} data={{ ...data }} args={{ ...args }} />);
|
2020-08-31 19:01:38 +02:00
|
|
|
|
|
|
|
const axisStyle = instance.find(Axis).first().prop('style');
|
|
|
|
|
|
|
|
expect(axisStyle).toMatchObject({
|
|
|
|
tickLabel: {
|
|
|
|
visible: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it should set the tickLabel visibility on the y axis if the tick labels is shown', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
2020-09-16 10:30:19 +02:00
|
|
|
args.tickLabelsVisibilitySettings = {
|
|
|
|
x: false,
|
|
|
|
yLeft: true,
|
|
|
|
yRight: true,
|
|
|
|
type: 'lens_xy_tickLabelsConfig',
|
|
|
|
};
|
2020-08-31 19:01:38 +02:00
|
|
|
|
2020-12-22 17:35:27 +01:00
|
|
|
const instance = shallow(<XYChart {...defaultProps} data={{ ...data }} args={{ ...args }} />);
|
2020-08-31 19:01:38 +02:00
|
|
|
|
|
|
|
const axisStyle = instance.find(Axis).at(1).prop('style');
|
|
|
|
|
|
|
|
expect(axisStyle).toMatchObject({
|
|
|
|
tickLabel: {
|
|
|
|
visible: true,
|
|
|
|
},
|
|
|
|
});
|
2020-08-11 19:10:35 +02:00
|
|
|
});
|
|
|
|
|
2020-05-05 21:59:32 +02:00
|
|
|
test('it should remove invalid rows', () => {
|
|
|
|
const data: LensMultiTable = {
|
|
|
|
type: 'lens_multitable',
|
|
|
|
tables: {
|
|
|
|
first: {
|
2020-10-16 18:46:51 +02:00
|
|
|
type: 'datatable',
|
2020-05-05 21:59:32 +02:00
|
|
|
columns: [
|
2020-10-16 18:46:51 +02:00
|
|
|
{ id: 'a', name: 'a', meta: { type: 'number' } },
|
|
|
|
{ id: 'b', name: 'b', meta: { type: 'number' } },
|
|
|
|
{ id: 'c', name: 'c', meta: { type: 'string' } },
|
2020-05-05 21:59:32 +02:00
|
|
|
],
|
|
|
|
rows: [
|
|
|
|
{ a: undefined, b: 2, c: 'I', d: 'Row 1' },
|
|
|
|
{ a: 1, b: 5, c: 'J', d: 'Row 2' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
second: {
|
2020-10-16 18:46:51 +02:00
|
|
|
type: 'datatable',
|
2020-05-05 21:59:32 +02:00
|
|
|
columns: [
|
2020-10-16 18:46:51 +02:00
|
|
|
{ id: 'a', name: 'a', meta: { type: 'number' } },
|
|
|
|
{ id: 'b', name: 'b', meta: { type: 'number' } },
|
|
|
|
{ id: 'c', name: 'c', meta: { type: 'string' } },
|
2020-05-05 21:59:32 +02:00
|
|
|
],
|
|
|
|
rows: [
|
|
|
|
{ a: undefined, b: undefined, c: undefined },
|
|
|
|
{ a: undefined, b: undefined, c: undefined },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const args: XYArgs = {
|
|
|
|
xTitle: '',
|
|
|
|
yTitle: '',
|
2020-09-16 10:30:19 +02:00
|
|
|
yRightTitle: '',
|
2020-05-05 21:59:32 +02:00
|
|
|
legend: { type: 'lens_xy_legendConfig', isVisible: false, position: Position.Top },
|
2020-11-06 16:34:30 +01:00
|
|
|
valueLabels: 'hide',
|
2020-08-11 19:10:35 +02:00
|
|
|
tickLabelsVisibilitySettings: {
|
|
|
|
type: 'lens_xy_tickLabelsConfig',
|
|
|
|
x: true,
|
2020-09-16 10:30:19 +02:00
|
|
|
yLeft: true,
|
|
|
|
yRight: true,
|
2020-08-11 19:10:35 +02:00
|
|
|
},
|
|
|
|
gridlinesVisibilitySettings: {
|
|
|
|
type: 'lens_xy_gridlinesConfig',
|
|
|
|
x: true,
|
2020-09-16 10:30:19 +02:00
|
|
|
yLeft: false,
|
|
|
|
yRight: false,
|
2020-08-11 19:10:35 +02:00
|
|
|
},
|
2020-05-05 21:59:32 +02:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
layerId: 'first',
|
|
|
|
seriesType: 'line',
|
|
|
|
xAccessor: 'a',
|
|
|
|
accessors: ['c'],
|
|
|
|
splitAccessor: 'b',
|
|
|
|
columnToLabel: '',
|
|
|
|
xScaleType: 'ordinal',
|
|
|
|
yScaleType: 'linear',
|
|
|
|
isHistogram: false,
|
2020-11-04 11:27:52 +01:00
|
|
|
palette: mockPaletteOutput,
|
2020-05-05 21:59:32 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
layerId: 'second',
|
|
|
|
seriesType: 'line',
|
|
|
|
xAccessor: 'a',
|
|
|
|
accessors: ['c'],
|
|
|
|
splitAccessor: 'b',
|
|
|
|
columnToLabel: '',
|
|
|
|
xScaleType: 'ordinal',
|
|
|
|
yScaleType: 'linear',
|
|
|
|
isHistogram: false,
|
2020-11-04 11:27:52 +01:00
|
|
|
palette: mockPaletteOutput,
|
2020-05-05 21:59:32 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2020-12-22 17:35:27 +01:00
|
|
|
const component = shallow(<XYChart {...defaultProps} data={data} args={args} />);
|
2020-05-05 21:59:32 +02:00
|
|
|
|
|
|
|
const series = component.find(LineSeries);
|
|
|
|
|
|
|
|
// Only one series should be rendered, even though 2 are configured
|
|
|
|
// This one series should only have one row, even though 2 are sent
|
|
|
|
expect(series.prop('data')).toEqual([{ a: 1, b: 5, c: 'J', d: 'Row 2' }]);
|
|
|
|
});
|
|
|
|
|
2020-05-19 14:44:59 +02:00
|
|
|
test('it should not remove rows with falsy but non-undefined values', () => {
|
|
|
|
const data: LensMultiTable = {
|
|
|
|
type: 'lens_multitable',
|
|
|
|
tables: {
|
|
|
|
first: {
|
2020-10-16 18:46:51 +02:00
|
|
|
type: 'datatable',
|
2020-05-19 14:44:59 +02:00
|
|
|
columns: [
|
2020-10-16 18:46:51 +02:00
|
|
|
{ id: 'a', name: 'a', meta: { type: 'number' } },
|
|
|
|
{ id: 'b', name: 'b', meta: { type: 'number' } },
|
|
|
|
{ id: 'c', name: 'c', meta: { type: 'number' } },
|
2020-05-19 14:44:59 +02:00
|
|
|
],
|
|
|
|
rows: [
|
|
|
|
{ a: 0, b: 2, c: 5 },
|
|
|
|
{ a: 1, b: 0, c: 7 },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const args: XYArgs = {
|
|
|
|
xTitle: '',
|
|
|
|
yTitle: '',
|
2020-09-16 10:30:19 +02:00
|
|
|
yRightTitle: '',
|
2020-05-19 14:44:59 +02:00
|
|
|
legend: { type: 'lens_xy_legendConfig', isVisible: false, position: Position.Top },
|
2020-11-06 16:34:30 +01:00
|
|
|
valueLabels: 'hide',
|
2020-08-11 19:10:35 +02:00
|
|
|
tickLabelsVisibilitySettings: {
|
|
|
|
type: 'lens_xy_tickLabelsConfig',
|
|
|
|
x: true,
|
2020-09-16 10:30:19 +02:00
|
|
|
yLeft: false,
|
|
|
|
yRight: false,
|
2020-08-11 19:10:35 +02:00
|
|
|
},
|
|
|
|
gridlinesVisibilitySettings: {
|
|
|
|
type: 'lens_xy_gridlinesConfig',
|
|
|
|
x: true,
|
2020-09-16 10:30:19 +02:00
|
|
|
yLeft: false,
|
|
|
|
yRight: false,
|
2020-08-11 19:10:35 +02:00
|
|
|
},
|
2020-05-19 14:44:59 +02:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
layerId: 'first',
|
|
|
|
seriesType: 'line',
|
|
|
|
xAccessor: 'a',
|
|
|
|
accessors: ['c'],
|
|
|
|
splitAccessor: 'b',
|
|
|
|
columnToLabel: '',
|
|
|
|
xScaleType: 'ordinal',
|
|
|
|
yScaleType: 'linear',
|
|
|
|
isHistogram: false,
|
2020-11-04 11:27:52 +01:00
|
|
|
palette: mockPaletteOutput,
|
2020-05-19 14:44:59 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2020-12-22 17:35:27 +01:00
|
|
|
const component = shallow(<XYChart {...defaultProps} data={data} args={args} />);
|
2020-05-19 14:44:59 +02:00
|
|
|
|
|
|
|
const series = component.find(LineSeries);
|
|
|
|
|
|
|
|
expect(series.prop('data')).toEqual([
|
|
|
|
{ a: 0, b: 2, c: 5 },
|
|
|
|
{ a: 1, b: 0, c: 7 },
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2020-05-05 21:59:32 +02:00
|
|
|
test('it should show legend for split series, even with one row', () => {
|
|
|
|
const data: LensMultiTable = {
|
|
|
|
type: 'lens_multitable',
|
|
|
|
tables: {
|
|
|
|
first: {
|
2020-10-16 18:46:51 +02:00
|
|
|
type: 'datatable',
|
2020-05-05 21:59:32 +02:00
|
|
|
columns: [
|
2020-10-16 18:46:51 +02:00
|
|
|
{ id: 'a', name: 'a', meta: { type: 'number' } },
|
|
|
|
{ id: 'b', name: 'b', meta: { type: 'number' } },
|
|
|
|
{ id: 'c', name: 'c', meta: { type: 'string' } },
|
2020-05-05 21:59:32 +02:00
|
|
|
],
|
|
|
|
rows: [{ a: 1, b: 5, c: 'J' }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const args: XYArgs = {
|
|
|
|
xTitle: '',
|
|
|
|
yTitle: '',
|
2020-09-16 10:30:19 +02:00
|
|
|
yRightTitle: '',
|
2020-05-05 21:59:32 +02:00
|
|
|
legend: { type: 'lens_xy_legendConfig', isVisible: true, position: Position.Top },
|
2020-11-06 16:34:30 +01:00
|
|
|
valueLabels: 'hide',
|
2020-08-11 19:10:35 +02:00
|
|
|
tickLabelsVisibilitySettings: {
|
|
|
|
type: 'lens_xy_tickLabelsConfig',
|
|
|
|
x: true,
|
2020-09-16 10:30:19 +02:00
|
|
|
yLeft: false,
|
|
|
|
yRight: false,
|
2020-08-11 19:10:35 +02:00
|
|
|
},
|
|
|
|
gridlinesVisibilitySettings: {
|
|
|
|
type: 'lens_xy_gridlinesConfig',
|
|
|
|
x: true,
|
2020-09-16 10:30:19 +02:00
|
|
|
yLeft: false,
|
|
|
|
yRight: false,
|
2020-08-11 19:10:35 +02:00
|
|
|
},
|
2020-05-05 21:59:32 +02:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
layerId: 'first',
|
|
|
|
seriesType: 'line',
|
|
|
|
xAccessor: 'a',
|
|
|
|
accessors: ['c'],
|
|
|
|
splitAccessor: 'b',
|
|
|
|
columnToLabel: '',
|
|
|
|
xScaleType: 'ordinal',
|
|
|
|
yScaleType: 'linear',
|
|
|
|
isHistogram: false,
|
2020-11-04 11:27:52 +01:00
|
|
|
palette: mockPaletteOutput,
|
2020-05-05 21:59:32 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2020-12-22 17:35:27 +01:00
|
|
|
const component = shallow(<XYChart {...defaultProps} data={data} args={args} />);
|
2020-05-05 21:59:32 +02:00
|
|
|
|
|
|
|
expect(component.find(Settings).prop('showLegend')).toEqual(true);
|
|
|
|
});
|
2020-07-03 16:15:06 +02:00
|
|
|
|
2020-07-22 12:14:59 +02:00
|
|
|
test('it should always show legend if showSingleSeries is set', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2020-07-22 12:14:59 +02:00
|
|
|
data={{ ...data }}
|
|
|
|
args={{
|
|
|
|
...args,
|
|
|
|
layers: [{ ...args.layers[0], accessors: ['a'], splitAccessor: undefined }],
|
|
|
|
legend: { ...args.legend, isVisible: true, showSingleSeries: true },
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(component.find(Settings).prop('showLegend')).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it not show legend if isVisible is set to false', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2020-07-22 12:14:59 +02:00
|
|
|
data={{ ...data }}
|
|
|
|
args={{
|
|
|
|
...args,
|
|
|
|
legend: { ...args.legend, isVisible: false },
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(component.find(Settings).prop('showLegend')).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it should show legend on right side', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2020-07-22 12:14:59 +02:00
|
|
|
data={{ ...data }}
|
|
|
|
args={{
|
|
|
|
...args,
|
|
|
|
legend: { ...args.legend, position: 'top' },
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(component.find(Settings).prop('legendPosition')).toEqual('top');
|
|
|
|
});
|
|
|
|
|
2020-07-03 16:15:06 +02:00
|
|
|
test('it should apply the fitting function to all non-bar series', () => {
|
|
|
|
const data: LensMultiTable = {
|
|
|
|
type: 'lens_multitable',
|
|
|
|
tables: {
|
|
|
|
first: createSampleDatatableWithRows([
|
|
|
|
{ a: 1, b: 2, c: 'I', d: 'Foo' },
|
|
|
|
{ a: 1, b: 5, c: 'J', d: 'Bar' },
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const args: XYArgs = createArgsWithLayers([
|
|
|
|
{ ...sampleLayer, accessors: ['a'] },
|
|
|
|
{ ...sampleLayer, seriesType: 'bar', accessors: ['a'] },
|
|
|
|
{ ...sampleLayer, seriesType: 'area', accessors: ['a'] },
|
|
|
|
{ ...sampleLayer, seriesType: 'area_stacked', accessors: ['a'] },
|
|
|
|
]);
|
|
|
|
|
|
|
|
const component = shallow(
|
|
|
|
<XYChart
|
2020-12-22 17:35:27 +01:00
|
|
|
{...defaultProps}
|
2020-07-03 16:15:06 +02:00
|
|
|
data={{ ...data }}
|
|
|
|
args={{ ...args, fittingFunction: 'Carry' }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(component.find(LineSeries).prop('fit')).toEqual({ type: Fit.Carry });
|
|
|
|
expect(component.find(BarSeries).prop('fit')).toEqual(undefined);
|
|
|
|
expect(component.find(AreaSeries).at(0).prop('fit')).toEqual({ type: Fit.Carry });
|
|
|
|
expect(component.find(AreaSeries).at(0).prop('stackAccessors')).toEqual([]);
|
2020-08-31 19:01:38 +02:00
|
|
|
expect(component.find(AreaSeries).at(1).prop('fit')).toEqual({ type: Fit.Carry });
|
2020-07-03 16:15:06 +02:00
|
|
|
expect(component.find(AreaSeries).at(1).prop('stackAccessors')).toEqual(['c']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it should apply None fitting function if not specified', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
args.layers[0].accessors = ['a'];
|
|
|
|
|
|
|
|
const component = shallow(
|
2020-12-22 17:35:27 +01:00
|
|
|
<XYChart {...defaultProps} data={{ ...data }} args={{ ...args }} />
|
2020-07-03 16:15:06 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(component.find(LineSeries).prop('fit')).toEqual({ type: Fit.None });
|
|
|
|
});
|
2020-08-11 19:10:35 +02:00
|
|
|
|
|
|
|
test('it should apply the xTitle if is specified', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
|
|
|
args.xTitle = 'My custom x-axis title';
|
|
|
|
|
|
|
|
const component = shallow(
|
2020-12-22 17:35:27 +01:00
|
|
|
<XYChart {...defaultProps} data={{ ...data }} args={{ ...args }} />
|
2020-08-11 19:10:35 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(component.find(Axis).at(0).prop('title')).toEqual('My custom x-axis title');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it should hide the X axis title if the corresponding switch is off', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
2020-09-16 10:30:19 +02:00
|
|
|
args.axisTitlesVisibilitySettings = {
|
|
|
|
x: false,
|
|
|
|
yLeft: true,
|
|
|
|
yRight: true,
|
|
|
|
type: 'lens_xy_axisTitlesVisibilityConfig',
|
|
|
|
};
|
2020-08-11 19:10:35 +02:00
|
|
|
|
|
|
|
const component = shallow(
|
2020-12-22 17:35:27 +01:00
|
|
|
<XYChart {...defaultProps} data={{ ...data }} args={{ ...args }} />
|
2020-08-11 19:10:35 +02:00
|
|
|
);
|
|
|
|
|
2020-08-31 19:01:38 +02:00
|
|
|
const axisStyle = component.find(Axis).first().prop('style');
|
|
|
|
|
|
|
|
expect(axisStyle).toMatchObject({
|
|
|
|
axisTitle: {
|
|
|
|
visible: false,
|
|
|
|
},
|
|
|
|
});
|
2020-08-11 19:10:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('it should show the X axis gridlines if the setting is on', () => {
|
|
|
|
const { data, args } = sampleArgs();
|
|
|
|
|
2020-09-16 10:30:19 +02:00
|
|
|
args.gridlinesVisibilitySettings = {
|
|
|
|
x: true,
|
|
|
|
yLeft: false,
|
|
|
|
yRight: false,
|
|
|
|
type: 'lens_xy_gridlinesConfig',
|
|
|
|
};
|
2020-08-11 19:10:35 +02:00
|
|
|
|
|
|
|
const component = shallow(
|
2020-12-22 17:35:27 +01:00
|
|
|
<XYChart {...defaultProps} data={{ ...data }} args={{ ...args }} />
|
2020-08-11 19:10:35 +02:00
|
|
|
);
|
|
|
|
|
2020-08-31 19:01:38 +02:00
|
|
|
expect(component.find(Axis).at(0).prop('gridLine')).toMatchObject({
|
|
|
|
visible: true,
|
|
|
|
});
|
2020-08-11 19:10:35 +02:00
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|
2020-11-20 17:18:22 +01:00
|
|
|
|
|
|
|
describe('calculateMinInterval', () => {
|
|
|
|
let xyProps: XYChartProps;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
xyProps = sampleArgs();
|
|
|
|
xyProps.args.layers[0].xScaleType = 'time';
|
|
|
|
});
|
|
|
|
it('should use first valid layer and determine interval', async () => {
|
|
|
|
const result = await calculateMinInterval(
|
|
|
|
xyProps,
|
|
|
|
jest.fn().mockResolvedValue({ interval: '5m' })
|
|
|
|
);
|
|
|
|
expect(result).toEqual(5 * 60 * 1000);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return undefined if data table is empty', async () => {
|
|
|
|
xyProps.data.tables.first.rows = [];
|
|
|
|
const result = await calculateMinInterval(
|
|
|
|
xyProps,
|
|
|
|
jest.fn().mockResolvedValue({ interval: '5m' })
|
|
|
|
);
|
|
|
|
expect(result).toEqual(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return undefined if interval can not be checked', async () => {
|
|
|
|
const result = await calculateMinInterval(xyProps, jest.fn().mockResolvedValue(undefined));
|
|
|
|
expect(result).toEqual(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return undefined if date column is not found', async () => {
|
|
|
|
xyProps.data.tables.first.columns.splice(2, 1);
|
|
|
|
const result = await calculateMinInterval(xyProps, jest.fn().mockResolvedValue(undefined));
|
|
|
|
expect(result).toEqual(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return undefined if x axis is not a date', async () => {
|
|
|
|
xyProps.args.layers[0].xScaleType = 'ordinal';
|
|
|
|
xyProps.data.tables.first.columns.splice(2, 1);
|
|
|
|
const result = await calculateMinInterval(xyProps, jest.fn().mockResolvedValue(undefined));
|
|
|
|
expect(result).toEqual(undefined);
|
|
|
|
});
|
|
|
|
});
|
2019-09-17 20:57:53 +02:00
|
|
|
});
|