Skip to content

Commit

Permalink
Fix all remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
VladLasitsa committed Aug 3, 2022
1 parent dd78ebd commit 8a756f8
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export const layeredXyVisFunction: LayeredXyVisFn = {
types: ['vis_dimension', 'string'],
help: strings.getSplitRowAccessorHelp(),
},
singleTable: {
types: ['boolean'],
help: i18n.translate('expressionXY.layeredXyVis.singleTable.help', {
defaultMessage: 'All layers use the one datatable',
}),
default: false,
},
},
async fn(data, args, handlers) {
const { layeredXyVisFn } = await import('./layered_xy_vis_fn');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,14 @@ import {
errors,
validateAxes,
} from './validate';
import { appendLayerIds, getDataLayers, getLayersWithTable } from '../helpers';
import { appendLayerIds, getDataLayers } from '../helpers';

export const layeredXyVisFn: LayeredXyVisFn['fn'] = async (data, args, handlers) => {
const layers = appendLayerIds(args.layers ?? [], 'layers');
const dataLayers = getDataLayers(layers);
const layersWithTable = getLayersWithTable(layers);

// if layers have the same table should log only one
if (layersWithTable.every((l) => l.table === layersWithTable[0].table)) {
logDatatable(
layersWithTable[0].table,
layers,
handlers,
args.splitColumnAccessor,
args.splitRowAccessor
);
if (args.singleTable) {
logDatatable(data, layers, handlers, args.splitColumnAccessor, args.splitRowAccessor);
} else {
logDatatables(layers, handlers, args.splitColumnAccessor, args.splitRowAccessor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import {
XYExtendedLayerConfigResult,
ExtendedDataLayerArgs,
DataLayerArgs,
XYExtendedLayerConfigResultWithTable,
} from '../types';
import { LayerTypes, SeriesTypes, REFERENCE_LINE_LAYER } from '../constants';
import { LayerTypes, SeriesTypes } from '../constants';

function isWithLayerId<T>(layer: T): layer is T & WithLayerId {
return (layer as T & WithLayerId).layerId ? true : false;
Expand Down Expand Up @@ -45,13 +44,6 @@ export function getDataLayers(layers: XYExtendedLayerConfigResult[]) {
);
}

export function getLayersWithTable(layers: XYExtendedLayerConfigResult[]) {
return layers.filter<XYExtendedLayerConfigResultWithTable>(
(layer): layer is XYExtendedLayerConfigResultWithTable =>
layer.layerType === LayerTypes.DATA || layer.type === REFERENCE_LINE_LAYER || !layer.layerType
);
}

export function getAccessors<
T,
U extends { splitAccessors?: T[]; xAccessor?: T; accessors: T[]; markSizeAccessor?: T }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export interface LayeredXYArgs {
showTooltip: boolean;
splitRowAccessor?: ExpressionValueVisDimension | string;
splitColumnAccessor?: ExpressionValueVisDimension | string;
singleTable?: boolean;
}

export interface XYProps {
Expand All @@ -277,6 +278,7 @@ export interface XYProps {
detailedTooltip?: boolean;
orderBucketsBySum?: boolean;
showTooltip: boolean;
singleTable?: boolean;
}

export interface AnnotationLayerArgs {
Expand Down Expand Up @@ -327,10 +329,6 @@ export type XYExtendedLayerConfigResult =
| ExtendedAnnotationLayerConfigResult
| ReferenceLineConfigResult;

export type XYExtendedLayerConfigResultWithTable =
| ExtendedDataLayerConfigResult
| ReferenceLineLayerConfigResult;

export interface ExtendedReferenceLineDecorationConfig extends ReferenceLineArgs {
type: typeof EXTENDED_REFERENCE_LINE_DECORATION_CONFIG;
}
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 @@ -54,6 +54,7 @@ interface Props {
defaultXScaleType: XScaleType;
fieldFormats: LayersFieldFormats;
uiState?: PersistedState;
singleTable?: boolean;
}

export const DataLayers: FC<Props> = ({
Expand All @@ -75,8 +76,38 @@ export const DataLayers: FC<Props> = ({
defaultXScaleType,
fieldFormats,
uiState,
singleTable,
}) => {
const colorAssignments = getColorAssignments(layers, titles, fieldFormats, formattedDatatables);
// for singleTable mode we should use y accessors from all layers for creating correct series name and getting color
const allYAccessors = layers.flatMap((layer) => layer.accessors);
const allColumnsToLabel = layers.reduce((acc, layer) => {
if (layer.columnToLabel) {
return { ...acc, ...JSON.parse(layer.columnToLabel) };
}

return acc;
}, {});
const allYTitles = Object.keys(titles).reduce((acc, key) => {
if (titles[key].yTitles) {
return { ...acc, ...titles[key].yTitles };
}
return acc;
}, {});
const colorAssignments = singleTable
? getColorAssignments(
[
{
...layers[0],
layerId: 'commonLayerId',
accessors: allYAccessors,
columnToLabel: JSON.stringify(allColumnsToLabel),
},
],
{ commonLayerId: { ...titles, yTitles: allYTitles } },
{ commonLayerId: fieldFormats[layers[0].layerId] },
{ commonLayerId: formattedDatatables[layers[0].layerId] }
)
: getColorAssignments(layers, titles, fieldFormats, formattedDatatables);
return (
<>
{layers.flatMap((layer) =>
Expand Down Expand Up @@ -118,6 +149,8 @@ export const DataLayers: FC<Props> = ({
defaultXScaleType,
fieldFormats,
uiState,
allYAccessors,
singleTable,
});

const index = `${layer.layerId}-${accessorIndex}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ export const LegendColorPickerWrapper: LegendColorPicker = ({
panelPaddingSize="s"
>
<ColorPicker
color={color}
color={layer?.palette.name === 'kibana_palette' ? color : color.toLowerCase()}
onChange={handleChange}
label={seriesName}
useLegacyColors={false}
useLegacyColors={layer?.palette.name === 'kibana_palette'}
colorIsOverwritten={colorIsOverwritten}
onKeyDown={onKeyDown}
/>
Expand Down
Loading

0 comments on commit 8a756f8

Please sign in to comment.