Skip to content

Commit

Permalink
moves all vis state updates into one place (elastic#61960) (elastic#6…
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Apr 29, 2020
1 parent 272f091 commit b0255a0
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 62 deletions.
2 changes: 2 additions & 0 deletions src/plugins/visualizations/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export type VisualizeEmbeddableContract = PublicContract<VisualizeEmbeddable>;
export { VisualizeInput } from './embeddable';
export type ExprVis = ExprVisClass;
export { SchemaConfig } from './legacy/build_pipeline';
// @ts-ignore
export { updateOldState } from './legacy/vis_update_state';
export { PersistedState } from './persisted_state';
export {
VisualizationController,
Expand Down
57 changes: 0 additions & 57 deletions src/plugins/visualizations/public/legacy/vis_update.js

This file was deleted.

75 changes: 75 additions & 0 deletions src/plugins/visualizations/public/legacy/vis_update_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,77 @@ function convertDateHistogramScaleMetrics(visState) {
}
}

function convertSeriesParams(visState) {
if (visState.params.seriesParams) {
return;
}

// update value axis options
const isUserDefinedYAxis = visState.params.setYExtents;
const defaultYExtents = visState.params.defaultYExtents;
const mode = ['stacked', 'overlap'].includes(visState.params.mode)
? 'normal'
: visState.params.mode || 'normal';

if (!visState.params.valueAxes || !visState.params.valueAxes.length) {
visState.params.valueAxes = [
{
id: 'ValueAxis-1',
name: 'LeftAxis-1',
type: 'value',
position: 'left',
show: true,
style: {},
scale: {
type: 'linear',
mode: 'normal',
},
labels: {
show: true,
rotate: 0,
filter: false,
truncate: 100,
},
title: {
text: 'Count',
},
},
];
}

visState.params.valueAxes[0].scale = {
...visState.params.valueAxes[0].scale,
type: visState.params.scale || 'linear',
setYExtents: visState.params.setYExtents || false,
defaultYExtents: visState.params.defaultYExtents || false,
boundsMargin: defaultYExtents ? visState.params.boundsMargin : 0,
min: isUserDefinedYAxis ? visState.params.yAxis.min : undefined,
max: isUserDefinedYAxis ? visState.params.yAxis.max : undefined,
mode: mode,
};

// update series options
const interpolate = visState.params.smoothLines ? 'cardinal' : visState.params.interpolate;
const stacked = ['stacked', 'percentage', 'wiggle', 'silhouette'].includes(visState.params.mode);
visState.params.seriesParams = [
{
show: true,
type: visState.params.type || 'line',
mode: stacked ? 'stacked' : 'normal',
interpolate: interpolate,
drawLinesBetweenPoints: visState.params.drawLinesBetweenPoints,
showCircles: visState.params.showCircles,
radiusRatio: visState.params.radiusRatio,
data: {
label: 'Count',
id: '1',
},
lineWidth: 2,
valueAxis: 'ValueAxis-1',
},
];
}

/**
* This function is responsible for updating old visStates - the actual saved object
* object - into the format, that will be required by the current Kibana version.
Expand All @@ -90,6 +161,10 @@ export const updateOldState = visState => {
convertPropertyNames(newState);
convertDateHistogramScaleMetrics(newState);

if (visState.params && ['line', 'area', 'histogram'].includes(visState.params.type)) {
convertSeriesParams(newState);
}

if (visState.type === 'gauge' && visState.fontSize) {
delete newState.fontSize;
_.set(newState, 'gauge.style.fontSize', visState.fontSize);
Expand Down
5 changes: 0 additions & 5 deletions src/plugins/visualizations/public/vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

import { isFunction, defaults, cloneDeep } from 'lodash';
import { PersistedState } from './persisted_state';
// @ts-ignore
import { updateVisualizationConfig } from './legacy/vis_update';
import { getTypes, getAggs } from './services';
import { VisType } from './vis_types';
import {
Expand Down Expand Up @@ -121,9 +119,6 @@ export class Vis {
this.params = this.getParams(state.params);
}

// move to migration script
updateVisualizationConfig(state.params, this.params);

if (state.data && state.data.searchSource) {
this.data.searchSource = state.data.searchSource!;
this.data.indexPattern = this.data.searchSource.getField('index');
Expand Down

0 comments on commit b0255a0

Please sign in to comment.