Skip to content

Commit

Permalink
[Lens] fit line charts by default (#196184)
Browse files Browse the repository at this point in the history
## Summary

Every line charts are now interpolated by default with a linear
interpolation.

Solves the second task of
[#186076](#186076)

fix [#186076](#186076)

before:
<img width="816" alt="Screenshot 2024-10-17 at 16 25 47"
src="https://github.com/user-attachments/assets/3b14c80b-deef-4d8d-9d5b-e118619e31cb">

after:
<img width="814" alt="Screenshot 2024-10-17 at 16 25 56"
src="https://github.com/user-attachments/assets/45788530-aeb6-4851-ac1e-c53efcd73068">

## Release note
Newly and default configured Lens line charts are now interpolated by
default with a straight Linear interpolation.

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Marta Bondyra <[email protected]>
(cherry picked from commit 5fe8aad)
  • Loading branch information
markov00 committed Oct 21, 2024
1 parent 904d201 commit 40922d1
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 68 deletions.
2 changes: 1 addition & 1 deletion dev_docs/lens/xy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Understanding `LensXYConfig` in detail
### `emphasizeFitting`

- **Type:** `boolean`
- **Description:** When set to true, emphasizes the fitting of lines to the data points in line charts, making trends and patterns more apparent.
- **Description:** When set to true a straight line will be used between isolated points in a line chart, a dashed line will be used otherwise.

### `fittingFunction`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ test('generates xy chart config', async () => {
"yLeft": true,
"yRight": true,
},
"emphasizeFitting": false,
"fittingFunction": "None",
"emphasizeFitting": true,
"fittingFunction": "Linear",
"gridlinesVisibilitySettings": Object {
"x": true,
"yLeft": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function buildVisualizationState(config: LensXYConfig): XYState {
hideEndzones: true,
preferredSeriesType: 'line',
valueLabels: 'hide',
emphasizeFitting: config?.emphasizeFitting ?? false,
fittingFunction: config?.fittingFunction ?? 'None',
emphasizeFitting: config?.emphasizeFitting ?? true,
fittingFunction: config?.fittingFunction ?? 'Linear',
yLeftExtent: {
mode: config.yBounds?.mode ?? 'full',
lowerBound: config.yBounds?.lowerBound,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const commonXYArgs: CommonXYFn['args'] = {
},
emphasizeFitting: {
types: ['boolean'],
default: false,
default: true,
help: '',
},
valueLabels: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
export const PLUGIN_ID = 'expressionXy';
export const PLUGIN_NAME = 'expressionXy';

export { LayerTypes, XYCurveTypes } from './constants';
export { LayerTypes, XYCurveTypes, FittingFunctions } from './constants';

export type {
AllowedXYOverrides,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ type GetColorFn = (
type GetPointConfigFn = (config: {
xAccessor: string | undefined;
markSizeAccessor: string | undefined;
emphasizeFitting?: boolean;
showPoints?: boolean;
pointsRadius?: number;
}) => Partial<AreaSeriesStyle['point']>;
Expand Down Expand Up @@ -297,18 +296,10 @@ export const getSeriesName: GetSeriesNameFn = (
return splitValues.length > 0 ? splitValues.join(' - ') : yAccessorTitle;
};

const getPointConfig: GetPointConfigFn = ({
xAccessor,
markSizeAccessor,
emphasizeFitting,
showPoints,
pointsRadius,
}) => {
const getPointConfig: GetPointConfigFn = ({ markSizeAccessor, showPoints, pointsRadius }) => {
return {
visible: (showPoints !== undefined ? showPoints : !xAccessor || markSizeAccessor !== undefined)
? 'always'
: 'never',
radius: pointsRadius !== undefined ? pointsRadius : xAccessor && !emphasizeFitting ? 5 : 0,
visible: showPoints || markSizeAccessor ? 'always' : 'never',
radius: pointsRadius,
fill: markSizeAccessor ? ColorVariant.Series : undefined,
};
};
Expand Down Expand Up @@ -550,7 +541,6 @@ export const getSeriesProps: GetSeriesPropsFn = ({
point: getPointConfig({
xAccessor: xColumnId,
markSizeAccessor: markSizeColumnId,
emphasizeFitting,
showPoints: layer.showPoints,
pointsRadius: layer.pointsRadius,
}),
Expand All @@ -567,7 +557,6 @@ export const getSeriesProps: GetSeriesPropsFn = ({
point: getPointConfig({
xAccessor: xColumnId,
markSizeAccessor: markSizeColumnId,
emphasizeFitting,
showPoints: layer.showPoints,
pointsRadius: layer.pointsRadius,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export function plugin() {
return new ExpressionXyPlugin();
}

export { LayerTypes, XYCurveTypes } from '../common';
export { LayerTypes, XYCurveTypes, FittingFunctions } from '../common';

export type { ExpressionXyPluginSetup, ExpressionXyPluginStart } from './types';
45 changes: 22 additions & 23 deletions x-pack/plugins/lens/public/visualizations/xy/to_expression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,31 +121,30 @@ describe('#toExpression', () => {
).toMatchSnapshot();
});

it('should default the fitting function to None', () => {
expect(
(
xyVisualization.toExpression(
it('should default the fitting function to Linear', () => {
const ast = xyVisualization.toExpression(
{
legend: { position: Position.Bottom, isVisible: true },
valueLabels: 'hide',
preferredSeriesType: 'bar',
layers: [
{
legend: { position: Position.Bottom, isVisible: true },
valueLabels: 'hide',
preferredSeriesType: 'bar',
layers: [
{
layerId: 'first',
layerType: LayerTypes.DATA,
seriesType: 'area',
splitAccessor: 'd',
xAccessor: 'a',
accessors: ['b', 'c'],
},
],
layerId: 'first',
layerType: LayerTypes.DATA,
seriesType: 'area',
splitAccessor: 'd',
xAccessor: 'a',
accessors: ['b', 'c'],
},
frame.datasourceLayers,
undefined,
datasourceExpressionsByLayers
) as Ast
).chain[0].arguments.fittingFunction[0]
).toEqual('None');
],
},
frame.datasourceLayers,
undefined,
datasourceExpressionsByLayers
) as Ast;

expect(ast.chain[0].arguments.fittingFunction[0]).toEqual('Linear');
expect(ast.chain[0].arguments.emphasizeFitting[0]).toEqual(true);
});

it('should default the axisTitles visibility settings to true', () => {
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/lens/public/visualizations/xy/to_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
XYCurveType,
YAxisConfigFn,
} from '@kbn/expression-xy-plugin/common';

import { FittingFunctions } from '@kbn/expression-xy-plugin/public';
import type { EventAnnotationConfig } from '@kbn/event-annotation-common';
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import { SystemPaletteExpressionFunctionDefinition } from '@kbn/charts-plugin/common';
Expand Down Expand Up @@ -336,9 +338,9 @@ export const buildXYExpression = (

const layeredXyVisFn = buildExpressionFunction<LayeredXyVisFn>('layeredXyVis', {
legend: buildExpression([legendConfigFn]).toAst(),
fittingFunction: state.fittingFunction ?? 'None',
fittingFunction: state.fittingFunction ?? FittingFunctions.LINEAR,
endValue: state.endValue ?? 'None',
emphasizeFitting: state.emphasizeFitting ?? false,
emphasizeFitting: state.emphasizeFitting ?? true,
minBarHeight: state.minBarHeight ?? 1,
fillOpacity: state.fillOpacity ?? 0.3,
valueLabels: state.valueLabels ?? 'hide',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import { i18n } from '@kbn/i18n';
import type { FittingFunction } from '@kbn/expression-xy-plugin/common';
import { FittingFunctions } from '@kbn/expression-xy-plugin/public';

export const fittingFunctionDefinitions: Array<{ id: FittingFunction } & Record<string, string>> = [
{
id: 'None',
id: FittingFunctions.NONE,
title: i18n.translate('xpack.lens.fittingFunctionsTitle.none', {
defaultMessage: 'Hide',
}),
Expand All @@ -19,7 +20,7 @@ export const fittingFunctionDefinitions: Array<{ id: FittingFunction } & Record<
}),
},
{
id: 'Zero',
id: FittingFunctions.ZERO,
title: i18n.translate('xpack.lens.fittingFunctionsTitle.zero', {
defaultMessage: 'Zero',
}),
Expand All @@ -28,7 +29,7 @@ export const fittingFunctionDefinitions: Array<{ id: FittingFunction } & Record<
}),
},
{
id: 'Linear',
id: FittingFunctions.LINEAR,
title: i18n.translate('xpack.lens.fittingFunctionsTitle.linear', {
defaultMessage: 'Linear',
}),
Expand All @@ -37,7 +38,7 @@ export const fittingFunctionDefinitions: Array<{ id: FittingFunction } & Record<
}),
},
{
id: 'Carry',
id: FittingFunctions.CARRY,
title: i18n.translate('xpack.lens.fittingFunctionsTitle.carry', {
defaultMessage: 'Last',
}),
Expand All @@ -46,7 +47,7 @@ export const fittingFunctionDefinitions: Array<{ id: FittingFunction } & Record<
}),
},
{
id: 'Lookahead',
id: FittingFunctions.LOOKAHEAD,
title: i18n.translate('xpack.lens.fittingFunctionsTitle.lookahead', {
defaultMessage: 'Next',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiIconTip, EuiSuperSelect, EuiSwitch, EuiText } from '@elastic/eui';
import type { FittingFunction, EndValue } from '@kbn/expression-xy-plugin/common';
import { FittingFunctions } from '@kbn/expression-xy-plugin/public';
import { fittingFunctionDefinitions } from './fitting_function_definitions';
import { endValueDefinitions } from './end_value_definitions';

Expand All @@ -25,7 +26,7 @@ export interface MissingValuesOptionProps {
export const MissingValuesOptions: React.FC<MissingValuesOptionProps> = ({
onFittingFnChange,
fittingFunction,
emphasizeFitting,
emphasizeFitting = true,
onEmphasizeFittingChange,
onEndValueChange,
endValue,
Expand Down Expand Up @@ -78,13 +79,13 @@ export const MissingValuesOptions: React.FC<MissingValuesOptionProps> = ({
inputDisplay: title,
};
})}
valueOfSelected={fittingFunction || 'None'}
valueOfSelected={fittingFunction || FittingFunctions.LINEAR}
onChange={(value) => onFittingFnChange(value)}
itemLayoutAlign="top"
hasDividers
/>
</EuiFormRow>
{fittingFunction && fittingFunction !== 'None' && (
{fittingFunction && fittingFunction !== FittingFunctions.NONE && (
<>
<EuiFormRow
display="columnCompressed"
Expand All @@ -109,7 +110,7 @@ export const MissingValuesOptions: React.FC<MissingValuesOptionProps> = ({
inputDisplay: title,
};
})}
valueOfSelected={endValue || 'None'}
valueOfSelected={endValue || FittingFunctions.NONE}
onChange={(value) => onEndValueChange(value)}
itemLayoutAlign="top"
hasDividers
Expand Down
20 changes: 10 additions & 10 deletions x-pack/plugins/lens/public/visualizations/xy/xy_suggestions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ describe('xy_suggestions', () => {
legend: { isVisible: true, position: 'bottom' },
valueLabels: 'hide',
preferredSeriesType: 'bar',
fittingFunction: 'None',
fittingFunction: 'Linear',
layers: [
{
accessors: ['price'],
Expand Down Expand Up @@ -691,7 +691,7 @@ describe('xy_suggestions', () => {
legend: { isVisible: true, position: 'bottom' },
valueLabels: 'hide',
preferredSeriesType: 'bar',
fittingFunction: 'None',
fittingFunction: 'Linear',
layers: [
{
layerId: 'first',
Expand Down Expand Up @@ -823,7 +823,7 @@ describe('xy_suggestions', () => {
const currentState: XYState = {
legend: { isVisible: true, position: 'bottom' },
valueLabels: 'hide',
fittingFunction: 'None',
fittingFunction: 'Linear',
preferredSeriesType: 'line',
layers: [
{
Expand Down Expand Up @@ -858,7 +858,7 @@ describe('xy_suggestions', () => {
const currentState: XYState = {
legend: { isVisible: true, position: 'bottom' },
valueLabels: 'hide',
fittingFunction: 'None',
fittingFunction: 'Linear',
axisTitlesVisibilitySettings: { x: true, yLeft: true, yRight: true },
gridlinesVisibilitySettings: { x: true, yLeft: true, yRight: true },
tickLabelsVisibilitySettings: { x: true, yLeft: false, yRight: false },
Expand Down Expand Up @@ -908,7 +908,7 @@ describe('xy_suggestions', () => {
legend: { isVisible: true, position: 'bottom' },
valueLabels: 'hide',
preferredSeriesType: 'bar',
fittingFunction: 'None',
fittingFunction: 'Linear',
axisTitlesVisibilitySettings: { x: true, yLeft: true, yRight: true },
gridlinesVisibilitySettings: { x: true, yLeft: true, yRight: true },
tickLabelsVisibilitySettings: { x: true, yLeft: false, yRight: false },
Expand Down Expand Up @@ -967,7 +967,7 @@ describe('xy_suggestions', () => {
const currentState: XYState = {
legend: { isVisible: true, position: 'bottom' },
valueLabels: 'hide',
fittingFunction: 'None',
fittingFunction: 'Linear',
preferredSeriesType: 'bar',
layers: [
{
Expand Down Expand Up @@ -1006,7 +1006,7 @@ describe('xy_suggestions', () => {
legend: { isVisible: true, position: 'bottom' },
valueLabels: 'hide',
preferredSeriesType: 'bar',
fittingFunction: 'None',
fittingFunction: 'Linear',
layers: [
{
accessors: ['price'],
Expand Down Expand Up @@ -1043,7 +1043,7 @@ describe('xy_suggestions', () => {
legend: { isVisible: true, position: 'bottom' },
valueLabels: 'hide',
preferredSeriesType: 'bar',
fittingFunction: 'None',
fittingFunction: 'Linear',
axisTitlesVisibilitySettings: { x: true, yLeft: true, yRight: true },
gridlinesVisibilitySettings: { x: true, yLeft: true, yRight: true },
tickLabelsVisibilitySettings: { x: true, yLeft: false, yRight: false },
Expand Down Expand Up @@ -1089,7 +1089,7 @@ describe('xy_suggestions', () => {
legend: { isVisible: true, position: 'bottom' },
valueLabels: 'hide',
preferredSeriesType: 'bar',
fittingFunction: 'None',
fittingFunction: 'Linear',
axisTitlesVisibilitySettings: { x: true, yLeft: true, yRight: true },
gridlinesVisibilitySettings: { x: true, yLeft: true, yRight: true },
tickLabelsVisibilitySettings: { x: true, yLeft: false, yRight: false },
Expand Down Expand Up @@ -1136,7 +1136,7 @@ describe('xy_suggestions', () => {
legend: { isVisible: true, position: 'bottom' },
valueLabels: 'hide',
preferredSeriesType: 'bar',
fittingFunction: 'None',
fittingFunction: 'Linear',
axisTitlesVisibilitySettings: { x: true, yLeft: true, yRight: true },
gridlinesVisibilitySettings: { x: true, yLeft: true, yRight: true },
tickLabelsVisibilitySettings: { x: true, yLeft: false, yRight: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import { i18n } from '@kbn/i18n';
import { partition } from 'lodash';
import { Position } from '@elastic/charts';
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import { FittingFunctions, LayerTypes } from '@kbn/expression-xy-plugin/public';

import type {
SuggestionRequest,
VisualizationSuggestion,
Expand Down Expand Up @@ -573,7 +574,7 @@ function buildSuggestion({
const state: State = {
legend: currentState ? currentState.legend : { isVisible: true, position: Position.Right },
valueLabels: currentState?.valueLabels || 'hide',
fittingFunction: currentState?.fittingFunction || 'None',
fittingFunction: currentState?.fittingFunction ?? FittingFunctions.LINEAR,
curveType: currentState?.curveType,
fillOpacity: currentState?.fillOpacity,
xTitle: currentState?.xTitle,
Expand Down

0 comments on commit 40922d1

Please sign in to comment.