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

[Lens] Add styling options for x and y axes on the settings popover #71829

Merged
merged 25 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0d001d5
[Lens] Add styling options for x axis on the settings popover
stratoula Jul 15, 2020
2c1ec95
ts related changes
stratoula Jul 15, 2020
5b5f3a7
Merge branch 'master' into lens-xy-axia-styling
elasticmachine Jul 15, 2020
4235afb
Changes to the popover's design and y-axis implementatin
stratoula Jul 16, 2020
959a87a
Merge branch 'master' into lens-xy-axia-styling
elasticmachine Jul 17, 2020
a5c7aae
fix types and add unit tests
stratoula Jul 17, 2020
036ef3a
Add extra translations
stratoula Jul 17, 2020
96d60b7
Fix functional test and change the logic of the yTitle
stratoula Jul 17, 2020
ff14e6d
fixes
stratoula Jul 17, 2020
3ddb22f
fix showTitle settings bug
stratoula Jul 17, 2020
9db022f
Merge branch 'master' into lens-xy-axia-styling
elasticmachine Jul 17, 2020
c2e494b
Merge branch 'master' into lens-xy-axia-styling
elasticmachine Jul 20, 2020
56e0df1
Fix ticklabels bug on y axes
stratoula Jul 20, 2020
8cb771b
fix some tests
stratoula Jul 21, 2020
8406b8d
Merge branch 'master' into lens-xy-axia-styling
elasticmachine Jul 21, 2020
ab6ef2b
Change the user flow on x and y titles on settings popover and enable…
stratoula Jul 22, 2020
fe88b4f
resolve merge confict
stratoula Jul 22, 2020
5a23b4c
Merge branch 'master' into lens-xy-axia-styling
elasticmachine Jul 27, 2020
01874bd
Merge branch 'master' into lens-xy-axia-styling
elasticmachine Jul 30, 2020
1ce9a70
Merge branch 'master' into lens-xy-axia-styling
elasticmachine Aug 3, 2020
482af76
Merge branch 'master' into lens-xy-axia-styling
elasticmachine Aug 5, 2020
a03dd0d
Merge branch 'master' into lens-xy-axia-styling
elasticmachine Aug 10, 2020
593f226
disable linter warning
stratoula Aug 10, 2020
33de3d1
PR Comments
stratoula Aug 10, 2020
7b3bc4a
Add a comment to callback to explain the decision to listen only to o…
stratoula Aug 10, 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

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

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

4 changes: 3 additions & 1 deletion x-pack/plugins/lens/public/xy_visualization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ExpressionsSetup } from '../../../../../src/plugins/expressions/public'
import { UI_SETTINGS } from '../../../../../src/plugins/data/public';
import { xyVisualization } from './xy_visualization';
import { xyChart, getXyChartRenderer } from './xy_expression';
import { legendConfig, layerConfig, yAxisConfig } from './types';
import { legendConfig, layerConfig, yAxisConfig, tickLabelsConfig, gridlinesConfig } from './types';
import { EditorFrameSetup, FormatFactory } from '../types';
import { ChartsPluginSetup } from '../../../../../src/plugins/charts/public';

Expand Down Expand Up @@ -39,6 +39,8 @@ export class XyVisualization {
) {
expressions.registerFunction(() => legendConfig);
expressions.registerFunction(() => yAxisConfig);
expressions.registerFunction(() => tickLabelsConfig);
expressions.registerFunction(() => gridlinesConfig);
expressions.registerFunction(() => layerConfig);
expressions.registerFunction(() => xyChart);

Expand Down
77 changes: 75 additions & 2 deletions x-pack/plugins/lens/public/xy_visualization/to_expression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ describe('#toExpression', () => {
legend: { position: Position.Bottom, isVisible: true },
preferredSeriesType: 'bar',
fittingFunction: 'Carry',
tickLabelsVisibilitySettings: { x: false, y: true },
gridlinesVisibilitySettings: { x: false, y: true },
layers: [
{
layerId: 'first',
Expand Down Expand Up @@ -77,6 +79,27 @@ describe('#toExpression', () => {
).toEqual('None');
});

it('should default the showXAxisTitle and showYAxisTitle to true', () => {
const expression = xyVisualization.toExpression(
{
legend: { position: Position.Bottom, isVisible: true },
preferredSeriesType: 'bar',
layers: [
{
layerId: 'first',
seriesType: 'area',
splitAccessor: 'd',
xAccessor: 'a',
accessors: ['b', 'c'],
},
],
},
frame
) as Ast;
expect(expression.chain[0].arguments.showXAxisTitle[0]).toBe(true);
expect(expression.chain[0].arguments.showYAxisTitle[0]).toBe(true);
});

it('should not generate an expression when missing x', () => {
expect(
xyVisualization.toExpression(
Expand Down Expand Up @@ -140,8 +163,8 @@ describe('#toExpression', () => {
expect(mockDatasource.publicAPIMock.getOperationForColumnId).toHaveBeenCalledWith('b');
expect(mockDatasource.publicAPIMock.getOperationForColumnId).toHaveBeenCalledWith('c');
expect(mockDatasource.publicAPIMock.getOperationForColumnId).toHaveBeenCalledWith('d');
expect(expression.chain[0].arguments.xTitle).toEqual(['col_a']);
expect(expression.chain[0].arguments.yTitle).toEqual(['col_b']);
expect(expression.chain[0].arguments.xTitle).toEqual(['']);
expect(expression.chain[0].arguments.yTitle).toEqual(['']);
expect(
(expression.chain[0].arguments.layers[0] as Ast).chain[0].arguments.columnToLabel
).toEqual([
Expand All @@ -152,4 +175,54 @@ describe('#toExpression', () => {
}),
]);
});

it('should default the tick labels visibility settings to true', () => {
const expression = xyVisualization.toExpression(
{
legend: { position: Position.Bottom, isVisible: true },
preferredSeriesType: 'bar',
layers: [
{
layerId: 'first',
seriesType: 'area',
splitAccessor: 'd',
xAccessor: 'a',
accessors: ['b', 'c'],
},
],
},
frame
) as Ast;
expect(
(expression.chain[0].arguments.tickLabelsVisibilitySettings[0] as Ast).chain[0].arguments
).toEqual({
x: [true],
y: [true],
});
});

it('should default the gridlines visibility settings to true', () => {
const expression = xyVisualization.toExpression(
{
legend: { position: Position.Bottom, isVisible: true },
preferredSeriesType: 'bar',
layers: [
{
layerId: 'first',
seriesType: 'area',
splitAccessor: 'd',
xAccessor: 'a',
accessors: ['b', 'c'],
},
],
},
frame
) as Ast;
expect(
(expression.chain[0].arguments.gridlinesVisibilitySettings[0] as Ast).chain[0].arguments
).toEqual({
x: [true],
y: [true],
});
});
});
63 changes: 36 additions & 27 deletions x-pack/plugins/lens/public/xy_visualization/to_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,6 @@ interface ValidLayer extends LayerConfig {
xAccessor: NonNullable<LayerConfig['xAccessor']>;
}

function xyTitles(layer: LayerConfig, frame: FramePublicAPI) {
const defaults = {
xTitle: 'x',
yTitle: 'y',
};

if (!layer || !layer.accessors.length) {
return defaults;
}
const datasource = frame.datasourceLayers[layer.layerId];
if (!datasource) {
return defaults;
}
const x = layer.xAccessor ? datasource.getOperationForColumnId(layer.xAccessor) : null;
const y = layer.accessors[0] ? datasource.getOperationForColumnId(layer.accessors[0]) : null;

return {
xTitle: x ? x.label : defaults.xTitle,
yTitle: y ? y.label : defaults.yTitle,
};
}

export const toExpression = (state: State, frame: FramePublicAPI): Ast | null => {
if (!state || !state.layers.length) {
return null;
Expand All @@ -52,7 +30,7 @@ export const toExpression = (state: State, frame: FramePublicAPI): Ast | null =>
});
});

return buildExpression(state, metadata, frame, xyTitles(state.layers[0], frame));
return buildExpression(state, metadata, frame);
};

export function toPreviewExpression(state: State, frame: FramePublicAPI) {
Expand Down Expand Up @@ -99,8 +77,7 @@ export function getScaleType(metadata: OperationMetadata | null, defaultScale: S
export const buildExpression = (
state: State,
metadata: Record<string, Record<string, OperationMetadata | null>>,
frame?: FramePublicAPI,
{ xTitle, yTitle }: { xTitle: string; yTitle: string } = { xTitle: '', yTitle: '' }
frame?: FramePublicAPI
): Ast | null => {
const validLayers = state.layers.filter((layer): layer is ValidLayer =>
Boolean(layer.xAccessor && layer.accessors.length)
Expand All @@ -116,8 +93,8 @@ export const buildExpression = (
type: 'function',
function: 'lens_xy_chart',
arguments: {
xTitle: [xTitle],
yTitle: [yTitle],
xTitle: [state.xTitle || ''],
yTitle: [state.yTitle || ''],
legend: [
{
type: 'expression',
Expand All @@ -137,6 +114,38 @@ export const buildExpression = (
},
],
fittingFunction: [state.fittingFunction || 'None'],
showXAxisTitle: [state.showXAxisTitle ?? true],
showYAxisTitle: [state.showYAxisTitle ?? true],
tickLabelsVisibilitySettings: [
{
type: 'expression',
chain: [
{
type: 'function',
function: 'lens_xy_tickLabelsConfig',
arguments: {
x: [state?.tickLabelsVisibilitySettings?.x ?? true],
y: [state?.tickLabelsVisibilitySettings?.y ?? true],
},
},
],
},
],
gridlinesVisibilitySettings: [
{
type: 'expression',
chain: [
{
type: 'function',
function: 'lens_xy_gridlinesConfig',
arguments: {
x: [state?.gridlinesVisibilitySettings?.x ?? true],
y: [state?.gridlinesVisibilitySettings?.y ?? true],
},
},
],
},
],
layers: validLayers.map((layer) => {
const columnToLabel: Record<string, string> = {};

Expand Down
Loading