Skip to content
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

[XY] Add addTimeMarker arg #131495

Merged
Merged
Show file tree
Hide file tree
Changes from 13 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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const commonDataLayerArgs: Omit<
xScaleType: {
options: [...Object.values(XScaleTypes)],
help: strings.getXScaleTypeHelp(),
default: XScaleTypes.ORDINAL,
strict: true,
},
isHistogram: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ export const commonXYArgs: CommonXYFn['args'] = {
types: ['string'],
help: strings.getAriaLabelHelp(),
},
addTimeMarker: {
types: ['boolean'],
default: false,
help: strings.getAddTimeMakerHelp(),
},
minTimeBarInterval: {
types: ['string'],
help: strings.getMinTimeBarIntervalHelp(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*/

import { XY_VIS_RENDERER } from '../constants';
import { appendLayerIds, getDataLayers } from '../helpers';
import { LayeredXyVisFn } from '../types';
import { logDatatables } from '../utils';
import { validateMinTimeBarInterval, hasBarLayer } from './validate';
import { validateAddTimeMarker, validateMinTimeBarInterval, hasBarLayer } from './validate';
import { appendLayerIds, getDataLayers } from '../helpers';

export const layeredXyVisFn: LayeredXyVisFn['fn'] = async (data, args, handlers) => {
const layers = appendLayerIds(args.layers ?? [], 'layers');
Expand All @@ -19,6 +19,7 @@ export const layeredXyVisFn: LayeredXyVisFn['fn'] = async (data, args, handlers)

const dataLayers = getDataLayers(layers);
const hasBar = hasBarLayer(dataLayers);
validateAddTimeMarker(dataLayers, args.addTimeMarker);
validateMinTimeBarInterval(dataLayers, hasBar, args.minTimeBarInterval);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
CommonXYDataLayerConfigResult,
ValueLabelMode,
CommonXYDataLayerConfig,
ExtendedDataLayerConfigResult,
} from '../types';
import { isTimeChart } from '../helpers';

Expand All @@ -40,6 +41,10 @@ const errors = {
i18n.translate('expressionXY.reusable.function.xyVis.errors.dataBoundsForNotLineChartError', {
defaultMessage: 'Only line charts can be fit to the data bounds',
}),
timeMarkerForNotTimeChartsError: () =>
i18n.translate('expressionXY.reusable.function.xyVis.errors.timeMarkerForNotTimeChartsError', {
defaultMessage: 'Only time charts can have current time marker',
}),
isInvalidIntervalError: () =>
i18n.translate('expressionXY.reusable.function.xyVis.errors.isInvalidIntervalError', {
defaultMessage:
Expand Down Expand Up @@ -117,6 +122,15 @@ export const validateValueLabels = (
}
};

export const validateAddTimeMarker = (
dataLayers: Array<DataLayerConfigResult | ExtendedDataLayerConfigResult>,
addTimeMarker?: boolean
) => {
if (addTimeMarker && !isTimeChart(dataLayers)) {
throw new Error(errors.timeMarkerForNotTimeChartsError());
}
};

export const validateMinTimeBarInterval = (
dataLayers: CommonXYDataLayerConfigResult[],
hasBar: boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ describe('xyVis', () => {
).rejects.toThrowErrorMatchingSnapshot();
});

test('it should throw error if addTimeMarker applied for not time chart', async () => {
const { data, args } = sampleArgs();
const { layers, ...rest } = args;
const { layerId, layerType, table, type, ...restLayerArgs } = sampleLayer;
expect(
xyVisFunction.fn(
data,
{
...rest,
...restLayerArgs,
addTimeMarker: true,
referenceLineLayers: [],
annotationLayers: [],
},
createMockExecutionContext()
)
).rejects.toThrowErrorMatchingSnapshot();
});

test('it should throw error if splitRowAccessor is pointing to the absent column', async () => {
const { data, args } = sampleArgs();
const { layers, ...rest } = args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
validateExtent,
validateFillOpacity,
validateValueLabels,
validateAddTimeMarker,
validateMinTimeBarInterval,
} from './validate';

Expand Down Expand Up @@ -100,6 +101,7 @@ export const xyVisFn: XyVisFn['fn'] = async (data, args, handlers) => {
validateExtent(args.yLeftExtent, hasBar || hasArea, dataLayers);
validateExtent(args.yRightExtent, hasBar || hasArea, dataLayers);
validateFillOpacity(args.fillOpacity, hasArea);
validateAddTimeMarker(dataLayers, args.addTimeMarker);
validateMinTimeBarInterval(dataLayers, hasBar, args.minTimeBarInterval);

const hasNotHistogramBars = !hasHistogramBarLayer(dataLayers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export function isTimeChart(layers: CommonXYDataLayerConfigResult[]) {
return layers.every<CommonXYDataLayerConfigResult>(
(l): l is CommonXYDataLayerConfigResult =>
l.table.columns.find((col) => col.id === l.xAccessor)?.meta.type === 'date' &&
l.xScaleType === XScaleTypes.TIME
(!l.xScaleType || l.xScaleType === XScaleTypes.TIME)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export const strings = {
i18n.translate('expressionXY.xyVis.ariaLabel.help', {
defaultMessage: 'Specifies the aria label of the xy chart',
}),
getAddTimeMakerHelp: () =>
i18n.translate('expressionXY.xyVis.addTimeMaker.help', {
defaultMessage: 'Show time marker',
}),
getMinTimeBarIntervalHelp: () =>
i18n.translate('expressionXY.xyVis.xAxisInterval.help', {
defaultMessage: 'Specifies the min interval for time bar chart',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export interface XYArgs extends DataLayerArgs {
hideEndzones?: boolean;
valuesInLegend?: boolean;
ariaLabel?: string;
addTimeMarker?: boolean;
minTimeBarInterval?: string;
splitRowAccessor?: ExpressionValueVisDimension | string;
splitColumnAccessor?: ExpressionValueVisDimension | string;
Expand Down Expand Up @@ -231,6 +232,7 @@ export interface LayeredXYArgs {
hideEndzones?: boolean;
valuesInLegend?: boolean;
ariaLabel?: string;
addTimeMarker?: boolean;
minTimeBarInterval?: string;
}

Expand All @@ -257,6 +259,7 @@ export interface XYProps {
hideEndzones?: boolean;
valuesInLegend?: boolean;
ariaLabel?: string;
addTimeMarker?: boolean;
minTimeBarInterval?: string;
splitRowAccessor?: ExpressionValueVisDimension | string;
splitColumnAccessor?: ExpressionValueVisDimension | string;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
FittingFunction,
ValueLabelMode,
XYCurveType,
XScaleType,
} from '../../common';
import { SeriesTypes, ValueLabelModes } from '../../common/constants';
import {
Expand All @@ -49,6 +50,7 @@ interface Props {
fillOpacity?: number;
shouldShowValueLabels?: boolean;
valueLabels: ValueLabelMode;
defaultXScaleType: XScaleType;
}

export const DataLayers: FC<Props> = ({
Expand All @@ -67,6 +69,7 @@ export const DataLayers: FC<Props> = ({
shouldShowValueLabels,
formattedDatatables,
chartHasMoreThanOneBarSeries,
defaultXScaleType,
}) => {
const colorAssignments = getColorAssignments(layers, formatFactory);
return (
Expand Down Expand Up @@ -104,6 +107,7 @@ export const DataLayers: FC<Props> = ({
timeZone,
emphasizeFitting,
fillOpacity,
defaultXScaleType,
});

const index = `${layer.layerId}-${accessorIndex}`;
Expand Down
Loading