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

moves all vis state updates into one place #61960

Merged
merged 4 commits into from
Apr 23, 2020
Merged
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions src/plugins/visualizations/public/index.ts
Original file line number Diff line number Diff line change
@@ -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,
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
@@ -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.
@@ -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);
5 changes: 0 additions & 5 deletions src/plugins/visualizations/public/vis.ts
Original file line number Diff line number Diff line change
@@ -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 {
@@ -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');