Skip to content
Merged
Show file tree
Hide file tree
Changes from 23 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 @@ -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,27 @@
.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%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
EuiFlexItem,
EuiButtonEmpty,
EuiFormRow,
EuiIcon,
EuiLink,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
Expand Down Expand Up @@ -207,7 +209,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 @@ -242,7 +246,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 @@ -297,26 +303,66 @@ export function LayerPanel(
}}
>
<div className="lnsLayerPanel__dimension">
<NativeRenderer
render={props.datasourceMap[datasourceId].renderDimensionTrigger}
nativeProps={{
...layerDatasourceConfigProps,
columnId: accessor,
filterOperations: group.filterOperations,
suggestedPriority: group.suggestedPriority,
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,
});
}
}}
/>
>
<EuiFlexGroup gutterSize="none" alignItems="center">
{typeof accessorConfig !== 'string' &&
accessorConfig.triggerIcon === 'color' &&
accessorConfig.color && (
<EuiFlexItem grow={false}>
<div
className="lnsLayerPanel__colorIndicator lnsLayerPanel__colorIndicator--solidColor"
style={{
backgroundColor: accessorConfig.color,
}}
/>
</EuiFlexItem>
)}
{typeof accessorConfig !== 'string' &&
accessorConfig.triggerIcon === 'disabled' && (
<EuiFlexItem grow={false}>
<EuiIcon
type="stopSlash"
size="s"
className="lnsLayerPanel__colorIndicator"
/>
</EuiFlexItem>
)}
{typeof accessorConfig !== 'string' &&
accessorConfig.triggerIcon === 'colorBy' && (
<EuiFlexItem grow={false}>
<EuiIcon
type="brush"
size="s"
className="lnsLayerPanel__colorIndicator"
/>
</EuiFlexItem>
)}
<EuiFlexItem>
<NativeRenderer
render={props.datasourceMap[datasourceId].renderDimensionTrigger}
nativeProps={{
...layerDatasourceConfigProps,
columnId: accessor,
filterOperations: group.filterOperations,
suggestedPriority: group.suggestedPriority,
}}
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiLink>
<EuiButtonIcon
className="lnsLayerPanel__dimensionRemove"
data-test-subj="indexPattern-dimension-remove"
Expand Down Expand Up @@ -350,6 +396,26 @@ export function LayerPanel(
);
}}
/>
{typeof accessorConfig !== 'string' &&
accessorConfig.triggerIcon === 'colorBy' &&
accessorConfig.palette && (
<EuiFlexGroup
className="lnsLayerPanel__paletteContainer"
gutterSize="none"
alignItems="center"
>
{accessorConfig.palette.map((color) => (
<EuiFlexItem
key={color}
className="lnsLayerPanel__paletteColor"
grow={true}
style={{
backgroundColor: color,
}}
/>
))}
</EuiFlexGroup>
)}
</div>
</DragDrop>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React, { memo, useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiLink, EuiIcon, EuiToolTip, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { EuiText, EuiIcon, EuiToolTip, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { IUiSettingsClient, SavedObjectsClientContract, HttpSetup } from 'kibana/public';
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import { DatasourceDimensionTriggerProps, DatasourceDimensionEditorProps } from '../../types';
Expand Down Expand Up @@ -86,11 +86,11 @@ export const IndexPatternDimensionTriggerComponent = function IndexPatternDimens
}
anchorClassName="eui-displayBlock"
>
<EuiLink
<EuiText
Copy link
Contributor

Choose a reason for hiding this comment

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

There are a few questions/concerns I have due to the change from EuiLink to EuiText:

  • Since this element is no longer focusable, the styles applied by @mbondyra in a previous PR no longer set the focus styles (light blue background color behind text) appropriately for the child .lnsLayerPanel__triggerLinkLabel element. Can this be corrected?
  • I believe this aria-label now no longer applies to this element. Can we move to the appropriate location?
  • Should the lnsLayerPanel__triggerLink class name be changed, since it's no longer a link?

size="s"
color="danger"
id={columnId}
className="lnsLayerPanel__triggerLink"
onClick={props.onClick}
data-test-subj="lns-dimensionTrigger"
aria-label={triggerLinkA11yText}
title={triggerLinkA11yText}
Expand All @@ -101,16 +101,16 @@ export const IndexPatternDimensionTriggerComponent = function IndexPatternDimens
</EuiFlexItem>
<EuiFlexItem grow={true}>{selectedColumn.label}</EuiFlexItem>
</EuiFlexGroup>
</EuiLink>
</EuiText>
</EuiToolTip>
);
}

return (
<EuiLink
<EuiText
size="s"
id={columnId}
className="lnsLayerPanel__triggerLink"
onClick={props.onClick}
data-test-subj="lns-dimensionTrigger"
aria-label={triggerLinkA11yText}
title={triggerLinkA11yText}
Expand All @@ -120,7 +120,7 @@ export const IndexPatternDimensionTriggerComponent = function IndexPatternDimens
<span className="lnsLayerPanel__triggerLinkLabel">{formattedLabel}</span>
</span>
</EuiFlexItem>
</EuiLink>
</EuiText>
);
};

Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/lens/public/pie_visualization/visualization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { render } from 'react-dom';
import { i18n } from '@kbn/i18n';
import { I18nProvider } from '@kbn/i18n/react';
import { PaletteRegistry } from 'src/plugins/charts/public';
import { Visualization, OperationMetadata } from '../types';
import { Visualization, OperationMetadata, AccessorConfig } from '../types';
import { toExpression, toPreviewExpression } from './to_expression';
import { LayerState, PieVisualizationState } from './types';
import { suggestions } from './suggestions';
Expand Down Expand Up @@ -113,7 +113,16 @@ export const getPieVisualization = ({
.map(({ columnId }) => columnId)
.filter((columnId) => columnId !== layer.metric);
// When we add a column it could be empty, and therefore have no order
const sortedColumns = Array.from(new Set(originalOrder.concat(layer.groups)));
const sortedColumns: AccessorConfig[] = Array.from(new Set(originalOrder.concat(layer.groups)));
if (sortedColumns.length > 0) {
sortedColumns[0] = {
columnId: sortedColumns[0] as string,
triggerIcon: 'colorBy',
palette: paletteService
.get(state.palette?.name || 'default')
.getColors(10, state.palette?.params),
};
}

if (state.shape === 'treemap') {
return {
Expand Down
12 changes: 10 additions & 2 deletions x-pack/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ export type DatasourceDimensionEditorProps<T = unknown> = DatasourceDimensionPro

export type DatasourceDimensionTriggerProps<T> = DatasourceDimensionProps<T> & {
dragDropContext: DragContextState;
onClick: () => void;
};

export interface DatasourceLayerPanelProps<T> {
Expand Down Expand Up @@ -345,12 +344,21 @@ export type VisualizationDimensionEditorProps<T = unknown> = VisualizationConfig
setState: (newState: T) => void;
};

export type AccessorConfig =
| string
| {
columnId: string;
triggerIcon?: 'color' | 'disabled' | 'colorBy' | 'none';
color?: string;
palette?: string[];
};

export type VisualizationDimensionGroupConfig = SharedDimensionProps & {
groupLabel: string;

/** ID is passed back to visualization. For example, `x` */
groupId: string;
accessors: string[];
accessors: AccessorConfig[];
supportsMoreColumns: boolean;
/** If required, a warning will appear if accessors are empty */
required?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,31 @@ describe('color_assignment', () => {
expect(assignments.palette2.totalSeriesCount).toEqual(2 * 3);
expect(formatMock).toHaveBeenCalledWith(complexObject);
});

it('should handle missing tables', () => {
const assignments = getColorAssignments(layers, { ...data, tables: {} }, formatFactory);
// if there is no data, just assume a single split
expect(assignments.palette1.totalSeriesCount).toEqual(2);
});

it('should handle missing columns', () => {
const assignments = getColorAssignments(
layers,
{
...data,
tables: {
...data.tables,
'1': {
...data.tables['1'],
columns: [],
},
},
},
formatFactory
);
// if the split column is missing, just assume a single split
expect(assignments.palette1.totalSeriesCount).toEqual(2);
});
});

describe('getRank', () => {
Expand Down Expand Up @@ -178,5 +203,30 @@ describe('color_assignment', () => {
// 3 series in front of (complex object)/y1 - abc/y1, abc/y2
expect(assignments.palette1.getRank(layers[0], 'formatted', 'y1')).toEqual(2);
});

it('should handle missing tables', () => {
const assignments = getColorAssignments(layers, { ...data, tables: {} }, formatFactory);
// if there is no data, assume it is the first splitted series. One series in front - 0/y1
expect(assignments.palette1.getRank(layers[0], '2', 'y2')).toEqual(1);
});

it('should handle missing columns', () => {
const assignments = getColorAssignments(
layers,
{
...data,
tables: {
...data.tables,
'1': {
...data.tables['1'],
columns: [],
},
},
},
formatFactory
);
// if the split column is missing, assume it is the first splitted series. One series in front - 0/y1
expect(assignments.palette1.getRank(layers[0], '2', 'y2')).toEqual(1);
});
});
});
Loading