Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dc03598
implement color indicators
flash1293 Sep 7, 2020
1118d0c
add icon for color by
flash1293 Sep 7, 2020
66f4bd1
fix styling
flash1293 Sep 7, 2020
5d0192e
Merge remote-tracking branch 'upstream/master' into lens/color-in-dim…
flash1293 Sep 18, 2020
d5ba1b3
expose active data in some places
flash1293 Oct 7, 2020
be3dd02
Merge remote-tracking branch 'upstream/master' into lens/expose-activ…
flash1293 Nov 4, 2020
696f791
add active data to all relevant places
flash1293 Nov 4, 2020
1490d31
Fix bugs
flash1293 Nov 4, 2020
f3ca265
fix types
flash1293 Nov 4, 2020
a78946a
add tests
flash1293 Nov 4, 2020
c751be7
Merge remote-tracking branch 'upstream/master' into lens/expose-activ…
flash1293 Nov 4, 2020
8a695d1
remove leftover
flash1293 Nov 4, 2020
3820cfa
add test for expression renderer component
flash1293 Nov 4, 2020
4de8419
Merge branch 'lens/expose-active-data' into lens/color-in-dimension-t…
flash1293 Nov 4, 2020
9e4fb2e
add series and palette indicator
flash1293 Nov 4, 2020
2de1df2
Merge remote-tracking branch 'upstream/master' into lens/expose-activ…
flash1293 Nov 4, 2020
ec31106
update docs
flash1293 Nov 4, 2020
4d708bc
Merge branch 'lens/expose-active-data' into lens/color-in-dimension-t…
flash1293 Nov 4, 2020
b58abd4
put stubs in place for things to test
flash1293 Nov 4, 2020
9cff0b2
Merge remote-tracking branch 'upstream/master' into lens/color-in-dim…
flash1293 Nov 5, 2020
9c80ec2
fix tests and stuff
flash1293 Nov 5, 2020
61e4849
Merge remote-tracking branch 'upstream/master' into lens/color-in-dim…
flash1293 Nov 6, 2020
d32cb66
Merge branch 'master' into lens/color-in-dimension-trigger
kibanamachine Nov 9, 2020
723a3db
Merge remote-tracking branch 'upstream/master' into lens/color-in-dim…
flash1293 Nov 11, 2020
8ed06f8
review comments
flash1293 Nov 11, 2020
188ed08
simplify
flash1293 Nov 11, 2020
b9b6dc5
merge remote-tracking branch 'upstream/master' into lens/color-in-dim…
flash1293 Nov 16, 2020
82580bf
review fixes
flash1293 Nov 16, 2020
4e0a21f
remove unused css class
flash1293 Nov 16, 2020
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
25 changes: 22 additions & 3 deletions src/plugins/charts/public/services/palettes/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { PaletteService } from './service';
import { PaletteDefinition, SeriesLayer } from './types';

export const getPaletteRegistry = () => {
const mockPalette: jest.Mocked<PaletteDefinition> = {
const mockPalette1: jest.Mocked<PaletteDefinition> = {
id: 'default',
title: 'My Palette',
getColor: jest.fn((_: SeriesLayer[]) => 'black'),
Expand All @@ -41,9 +41,28 @@ export const getPaletteRegistry = () => {
})),
};

const mockPalette2: jest.Mocked<PaletteDefinition> = {
id: 'mocked',
title: 'Mocked Palette',
getColor: jest.fn((_: SeriesLayer[]) => 'blue'),
getColors: jest.fn((num: number) => ['blue', 'yellow']),
toExpression: jest.fn(() => ({
type: 'expression',
chain: [
{
type: 'function',
function: 'system_palette',
arguments: {
name: ['mocked'],
},
},
],
})),
};

return {
get: (_: string) => mockPalette,
getAll: () => [mockPalette],
get: (name: string) => (name !== 'default' ? mockPalette2 : mockPalette1),
getAll: () => [mockPalette1, mockPalette2],
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ describe('Datatable Visualization', () => {
state: { layers: [layer] },
frame,
}).groups[1].accessors
).toEqual(['c', 'b']);
).toEqual([{ columnId: 'c' }, { columnId: 'b' }]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ export const datatableVisualization: Visualization<DatatableVisualizationState>
defaultMessage: 'Break down by',
}),
layerId: state.layers[0].layerId,
accessors: sortedColumns.filter(
(c) => datasource!.getOperationForColumnId(c)?.isBucketed
),
accessors: sortedColumns
.filter((c) => datasource!.getOperationForColumnId(c)?.isBucketed)
.map((accessor) => ({ columnId: accessor })),
supportsMoreColumns: true,
filterOperations: (op) => op.isBucketed,
dataTestSubj: 'lnsDatatable_column',
Expand All @@ -162,9 +162,9 @@ export const datatableVisualization: Visualization<DatatableVisualizationState>
defaultMessage: 'Metrics',
}),
layerId: state.layers[0].layerId,
accessors: sortedColumns.filter(
(c) => !datasource!.getOperationForColumnId(c)?.isBucketed
),
accessors: sortedColumns
.filter((c) => !datasource!.getOperationForColumnId(c)?.isBucketed)
.map((accessor) => ({ columnId: accessor })),
supportsMoreColumns: true,
filterOperations: (op) => !op.isBucketed,
required: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiIcon } from '@elastic/eui';
import { AccessorConfig } from '../../../types';

export function ColorIndicator({
accessorConfig,
children,
}: {
accessorConfig: AccessorConfig;
children: React.ReactChild;
}) {
return (
<EuiFlexGroup gutterSize="none" alignItems="center">
{accessorConfig.triggerIcon === 'color' && accessorConfig.color && (
<EuiFlexItem grow={false}>
<div
className="lnsLayerPanel__colorIndicator lnsLayerPanel__colorIndicator--solidColor"
style={{
backgroundColor: accessorConfig.color,
}}
/>
</EuiFlexItem>
)}
{accessorConfig.triggerIcon === 'disabled' && (
<EuiFlexItem grow={false}>
<EuiIcon
type="stopSlash"
color="subdued"
size="s"
className="lnsLayerPanel__colorIndicator"
/>
</EuiFlexItem>
)}
{accessorConfig.triggerIcon === 'colorBy' && (
<EuiFlexItem grow={false}>
<EuiIcon type="brush" color="text" size="s" className="lnsLayerPanel__colorIndicator" />
</EuiFlexItem>
)}
<EuiFlexItem>{children}</EuiFlexItem>
</EuiFlexGroup>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
align-items: center;
overflow: hidden;
min-height: $euiSizeXXL;
position: relative;

// NativeRenderer is messing this up
> div {
Expand Down Expand Up @@ -111,3 +112,32 @@
.lnsLayerPanel__styleEditor {
padding: 0 $euiSizeS $euiSizeS;
}

.lnsLayerPanel__colorIndicator {
margin-left: $euiSizeS;
}

.lnsLayerPanel__colorIndicator--solidColor {
width: $euiSizeS;
height: $euiSizeS;
}

.lnsLayerPanel__paletteContainer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}

.lnsLayerPanel__paletteColor {
height: $euiSizeXS;
}

.lnsLayerPanel__dimensionLink {
width: 100%;

&:focus {
background-color: transparent !important; // sass-lint:disable-line no-important
outline: none !important; // sass-lint:disable-line no-important
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('LayerPanel', () => {
{
groupLabel: 'A',
groupId: 'a',
accessors: ['x'],
accessors: [{ columnId: 'x' }],
filterOperations: () => true,
supportsMoreColumns: false,
dataTestSubj: 'lnsGroup',
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('LayerPanel', () => {
{
groupLabel: 'A',
groupId: 'a',
accessors: ['x'],
accessors: [{ columnId: 'x' }],
filterOperations: () => true,
supportsMoreColumns: false,
dataTestSubj: 'lnsGroup',
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('LayerPanel', () => {
{
groupLabel: 'A',
groupId: 'a',
accessors: ['newid'],
accessors: [{ columnId: 'newid' }],
filterOperations: () => true,
supportsMoreColumns: true,
dataTestSubj: 'lnsGroup',
Expand Down Expand Up @@ -257,7 +257,7 @@ describe('LayerPanel', () => {
{
groupLabel: 'A',
groupId: 'a',
accessors: ['newid'],
accessors: [{ columnId: 'newid' }],
filterOperations: () => true,
supportsMoreColumns: false,
dataTestSubj: 'lnsGroup',
Expand Down Expand Up @@ -302,7 +302,7 @@ describe('LayerPanel', () => {
{
groupLabel: 'A',
groupId: 'a',
accessors: ['newid'],
accessors: [{ columnId: 'newid' }],
filterOperations: () => true,
supportsMoreColumns: false,
dataTestSubj: 'lnsGroup',
Expand Down Expand Up @@ -377,7 +377,7 @@ describe('LayerPanel', () => {
{
groupLabel: 'A',
groupId: 'a',
accessors: ['a'],
accessors: [{ columnId: 'a' }],
filterOperations: () => true,
supportsMoreColumns: true,
dataTestSubj: 'lnsGroup',
Expand Down Expand Up @@ -416,15 +416,15 @@ describe('LayerPanel', () => {
{
groupLabel: 'A',
groupId: 'a',
accessors: ['a'],
accessors: [{ columnId: 'a' }],
filterOperations: () => true,
supportsMoreColumns: false,
dataTestSubj: 'lnsGroupA',
},
{
groupLabel: 'B',
groupId: 'b',
accessors: ['b'],
accessors: [{ columnId: 'b' }],
filterOperations: () => true,
supportsMoreColumns: true,
dataTestSubj: 'lnsGroupB',
Expand Down Expand Up @@ -480,7 +480,7 @@ describe('LayerPanel', () => {
{
groupLabel: 'A',
groupId: 'a',
accessors: ['a', 'b'],
accessors: [{ columnId: 'a' }, { columnId: 'b' }],
filterOperations: () => true,
supportsMoreColumns: true,
dataTestSubj: 'lnsGroup',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
EuiFlexItem,
EuiButtonEmpty,
EuiFormRow,
EuiLink,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
Expand All @@ -25,6 +26,8 @@ import { trackUiEvent } from '../../../lens_ui_telemetry';
import { generateId } from '../../../id_generator';
import { ConfigPanelWrapperProps, ActiveDimensionState } from './types';
import { DimensionContainer } from './dimension_container';
import { ColorIndicator } from './color_indicator';
import { PaletteIndicator } from './palette_indicator';

const initialActiveDimensionState = {
isNew: false,
Expand Down Expand Up @@ -207,7 +210,9 @@ export function LayerPanel(
>
<>
<ReorderProvider id={group.groupId} className={'lnsLayerPanel__group'}>
{group.accessors.map((accessor) => {
{group.accessors.map((accessorConfig) => {
const accessor =
typeof accessorConfig === 'string' ? accessorConfig : accessorConfig.columnId;
const { dragging } = dragDropContext;
const dragType =
isDraggedOperation(dragging) && accessor === dragging.columnId
Expand Down Expand Up @@ -253,7 +258,9 @@ export function LayerPanel(
dragType={dragType}
dropType={dropType}
data-test-subj={group.dataTestSubj}
itemsInGroup={group.accessors}
itemsInGroup={group.accessors.map((a) =>
typeof a === 'string' ? a : a.columnId
)}
className={'lnsLayerPanel__dimensionContainer'}
value={{
columnId: accessor,
Expand Down Expand Up @@ -304,25 +311,31 @@ export function LayerPanel(
}}
>
<div className="lnsLayerPanel__dimension">
<NativeRenderer
render={props.datasourceMap[datasourceId].renderDimensionTrigger}
nativeProps={{
...layerDatasourceConfigProps,
columnId: accessor,
filterOperations: group.filterOperations,
onClick: () => {
if (activeId) {
setActiveDimension(initialActiveDimensionState);
} else {
setActiveDimension({
isNew: false,
activeGroup: group,
activeId: accessor,
});
}
},
<EuiLink
className="lnsLayerPanel__dimensionLink"
onClick={() => {
if (activeId) {
setActiveDimension(initialActiveDimensionState);
} else {
setActiveDimension({
isNew: false,
activeGroup: group,
activeId: accessor,
});
}
}}
/>
>
<ColorIndicator accessorConfig={accessorConfig}>
<NativeRenderer
render={props.datasourceMap[datasourceId].renderDimensionTrigger}
nativeProps={{
...layerDatasourceConfigProps,
columnId: accessor,
filterOperations: group.filterOperations,
}}
/>
</ColorIndicator>
</EuiLink>
<EuiButtonIcon
className="lnsLayerPanel__dimensionRemove"
data-test-subj="indexPattern-dimension-remove"
Expand Down Expand Up @@ -356,6 +369,7 @@ export function LayerPanel(
);
}}
/>
<PaletteIndicator accessorConfig={accessorConfig} />
</div>
</DragDrop>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { AccessorConfig } from '../../../types';

export function PaletteIndicator({ accessorConfig }: { accessorConfig: AccessorConfig }) {
if (accessorConfig.triggerIcon !== 'colorBy' || !accessorConfig.palette) return null;
return (
<EuiFlexGroup className="lnsLayerPanel__paletteContainer" gutterSize="none" alignItems="center">
{accessorConfig.palette.map((color) => (
<EuiFlexItem
key={color}
className="lnsLayerPanel__paletteColor"
grow={true}
style={{
backgroundColor: color,
}}
/>
))}
</EuiFlexGroup>
Comment on lines +14 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than rolling out a custom color palette component, would it be better to use EuiColorPaletteDisplay instead (and override as necessary if needed)?

https://elastic.github.io/eui/#/forms/color-selection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component is very new - the version supporting it is not available in Kibana yet. I'm fine with using it once it becomes available, but #82730 has to get merged first.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Should I open an issue as a reminder? Or is that unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't bother, I will take care of it.

);
}
Loading