From 3599fa27ef4d2c99c68576f00f9927357de1d1fd Mon Sep 17 00:00:00 2001 From: ppisljar Date: Tue, 31 Mar 2020 05:25:43 -0700 Subject: [PATCH 1/3] moves all vis updates into one file --- src/plugins/visualizations/public/index.ts | 2 + .../public/legacy/vis_update.js | 57 ------------- .../public/legacy/vis_update_state.js | 84 +++++++++++++++++++ src/plugins/visualizations/public/vis.ts | 5 -- 4 files changed, 86 insertions(+), 62 deletions(-) delete mode 100644 src/plugins/visualizations/public/legacy/vis_update.js diff --git a/src/plugins/visualizations/public/index.ts b/src/plugins/visualizations/public/index.ts index 7df420e7ba585..e475684ed5934 100644 --- a/src/plugins/visualizations/public/index.ts +++ b/src/plugins/visualizations/public/index.ts @@ -43,6 +43,8 @@ export type VisualizeEmbeddableContract = PublicContract; 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, diff --git a/src/plugins/visualizations/public/legacy/vis_update.js b/src/plugins/visualizations/public/legacy/vis_update.js deleted file mode 100644 index 338a322e6aa57..0000000000000 --- a/src/plugins/visualizations/public/legacy/vis_update.js +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// TODO: this should be moved to vis_update_state -// Currently the migration takes place in Vis when calling setCurrentState. -// It should rather convert the raw saved object before starting to instantiate -// any JavaScript classes from it. -const updateVisualizationConfig = (stateConfig, config) => { - if (!stateConfig || stateConfig.seriesParams) return; - if (!['line', 'area', 'histogram'].includes(config.type)) return; - - // update value axis options - const isUserDefinedYAxis = config.setYExtents; - const defaultYExtents = config.defaultYExtents; - const mode = ['stacked', 'overlap'].includes(config.mode) ? 'normal' : config.mode || 'normal'; - config.valueAxes[0].scale = { - ...config.valueAxes[0].scale, - type: config.scale || 'linear', - setYExtents: config.setYExtents || false, - defaultYExtents: config.defaultYExtents || false, - boundsMargin: defaultYExtents ? config.boundsMargin : 0, - min: isUserDefinedYAxis ? config.yAxis.min : undefined, - max: isUserDefinedYAxis ? config.yAxis.max : undefined, - mode: mode, - }; - - // update series options - const interpolate = config.smoothLines ? 'cardinal' : config.interpolate; - const stacked = ['stacked', 'percentage', 'wiggle', 'silhouette'].includes(config.mode); - config.seriesParams[0] = { - ...config.seriesParams[0], - type: config.type || 'line', - mode: stacked ? 'stacked' : 'normal', - interpolate: interpolate, - drawLinesBetweenPoints: config.drawLinesBetweenPoints, - showCircles: config.showCircles, - radiusRatio: config.radiusRatio, - }; -}; - -export { updateVisualizationConfig }; diff --git a/src/plugins/visualizations/public/legacy/vis_update_state.js b/src/plugins/visualizations/public/legacy/vis_update_state.js index 45610701e08c8..12e46036e4b72 100644 --- a/src/plugins/visualizations/public/legacy/vis_update_state.js +++ b/src/plugins/visualizations/public/legacy/vis_update_state.js @@ -18,6 +18,15 @@ */ import _ from 'lodash'; +import { + AxisModes, + AxisTypes, + Positions, + ScaleTypes, +} from '../../../../legacy/core_plugins/vis_type_vislib/public/utils/collections'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { Rotates } from '../../../charts/public/static/components'; +import { countLabel } from '../../../../legacy/core_plugins/vis_type_vislib/public/utils/common_config'; /** * Will figure out if an heatmap state was saved before the auto coloring @@ -75,6 +84,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: AxisTypes.VALUE, + position: Positions.LEFT, + show: true, + style: {}, + scale: { + type: ScaleTypes.LINEAR, + mode: AxisModes.NORMAL, + }, + labels: { + show: true, + rotate: Rotates.HORIZONTAL, + filter: false, + truncate: 100, + }, + title: { + text: countLabel, + }, + }, + ]; + } + + 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: countLabel, + 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 +170,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); diff --git a/src/plugins/visualizations/public/vis.ts b/src/plugins/visualizations/public/vis.ts index 3cab4faf2a27f..009dd71b9a912 100644 --- a/src/plugins/visualizations/public/vis.ts +++ b/src/plugins/visualizations/public/vis.ts @@ -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'); From 976a06a7b69263d7ccf757ac1784657ce52d066a Mon Sep 17 00:00:00 2001 From: ppisljar Date: Tue, 14 Apr 2020 03:04:17 -0700 Subject: [PATCH 2/3] ... --- .../visualizations/public/legacy/vis_update_state.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/plugins/visualizations/public/legacy/vis_update_state.js b/src/plugins/visualizations/public/legacy/vis_update_state.js index 12e46036e4b72..a1c9681908bc1 100644 --- a/src/plugins/visualizations/public/legacy/vis_update_state.js +++ b/src/plugins/visualizations/public/legacy/vis_update_state.js @@ -24,9 +24,6 @@ import { Positions, ScaleTypes, } from '../../../../legacy/core_plugins/vis_type_vislib/public/utils/collections'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { Rotates } from '../../../charts/public/static/components'; -import { countLabel } from '../../../../legacy/core_plugins/vis_type_vislib/public/utils/common_config'; /** * Will figure out if an heatmap state was saved before the auto coloring @@ -111,12 +108,12 @@ function convertSeriesParams(visState) { }, labels: { show: true, - rotate: Rotates.HORIZONTAL, + rotate: 0, filter: false, truncate: 100, }, title: { - text: countLabel, + text: 'Count', }, }, ]; @@ -146,7 +143,7 @@ function convertSeriesParams(visState) { showCircles: visState.params.showCircles, radiusRatio: visState.params.radiusRatio, data: { - label: countLabel, + label: 'Count', id: '1', }, lineWidth: 2, From 60e3f0d24914588b0b6a1517ec0be606d87b06ea Mon Sep 17 00:00:00 2001 From: ppisljar Date: Tue, 21 Apr 2020 05:13:11 -0700 Subject: [PATCH 3/3] ... --- .../public/legacy/vis_update_state.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/plugins/visualizations/public/legacy/vis_update_state.js b/src/plugins/visualizations/public/legacy/vis_update_state.js index a1c9681908bc1..e345b9e5b8c9a 100644 --- a/src/plugins/visualizations/public/legacy/vis_update_state.js +++ b/src/plugins/visualizations/public/legacy/vis_update_state.js @@ -18,12 +18,6 @@ */ import _ from 'lodash'; -import { - AxisModes, - AxisTypes, - Positions, - ScaleTypes, -} from '../../../../legacy/core_plugins/vis_type_vislib/public/utils/collections'; /** * Will figure out if an heatmap state was saved before the auto coloring @@ -98,13 +92,13 @@ function convertSeriesParams(visState) { { id: 'ValueAxis-1', name: 'LeftAxis-1', - type: AxisTypes.VALUE, - position: Positions.LEFT, + type: 'value', + position: 'left', show: true, style: {}, scale: { - type: ScaleTypes.LINEAR, - mode: AxisModes.NORMAL, + type: 'linear', + mode: 'normal', }, labels: { show: true,