Skip to content

Commit

Permalink
fit line by default
Browse files Browse the repository at this point in the history
  • Loading branch information
markov00 committed Oct 14, 2024
1 parent 512a31d commit 9f432d6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
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 @@ -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';
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 9f432d6

Please sign in to comment.