diff --git a/src/plugins/data/common/search/aggs/agg_config.ts b/src/plugins/data/common/search/aggs/agg_config.ts index 1a70a41e72dd5..0ddddea890294 100644 --- a/src/plugins/data/common/search/aggs/agg_config.ts +++ b/src/plugins/data/common/search/aggs/agg_config.ts @@ -23,6 +23,7 @@ import { IAggType } from './agg_type'; import { writeParams } from './agg_params'; import { IAggConfigs } from './agg_configs'; import { parseTimeShift } from './utils'; +import { TimeBuckets } from './buckets/lib/time_buckets'; /** @public **/ export type AggConfigSerialized = Ensure< @@ -92,6 +93,7 @@ export class AggConfig { public parent?: IAggConfigs; public brandNew?: boolean; public schema?: string; + public buckets?: TimeBuckets; private __type: IAggType; private __typeDecorations: any; diff --git a/src/plugins/vis_types/vislib/public/constants.ts b/src/plugins/vis_types/vislib/public/constants.ts new file mode 100644 index 0000000000000..964fa70b648da --- /dev/null +++ b/src/plugins/vis_types/vislib/public/constants.ts @@ -0,0 +1,48 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export enum AxisType { + Category = 'category', + Value = 'value', +} + +export enum ScaleType { + Linear = 'linear', + Log = 'log', + SquareRoot = 'square root', +} + +export enum AxisMode { + Normal = 'normal', + Percentage = 'percentage', + Wiggle = 'wiggle', + Silhouette = 'silhouette', +} + +export enum InterpolationMode { + Linear = 'linear', + Cardinal = 'cardinal', + StepAfter = 'step-after', +} + +export enum ChartMode { + Normal = 'normal', + Stacked = 'stacked', +} + +export enum ChartType { + Line = 'line', + Area = 'area', + Histogram = 'histogram', +} + +export enum ThresholdLineStyle { + Full = 'full', + Dashed = 'dashed', + DotDashed = 'dot-dashed', +} diff --git a/src/plugins/vis_types/vislib/public/editor/components/heatmap/index.tsx b/src/plugins/vis_types/vislib/public/editor/components/heatmap/index.tsx index c0d89f2f66958..688a329f163d5 100644 --- a/src/plugins/vis_types/vislib/public/editor/components/heatmap/index.tsx +++ b/src/plugins/vis_types/vislib/public/editor/components/heatmap/index.tsx @@ -13,7 +13,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { VisEditorOptionsProps } from 'src/plugins/visualizations/public'; -import { ValueAxis } from '../../../../../xy/public'; +import { ValueAxis } from '../../../types'; import { BasicOptions, SelectOption, diff --git a/src/plugins/vis_types/vislib/public/editor/components/heatmap/labels_panel.tsx b/src/plugins/vis_types/vislib/public/editor/components/heatmap/labels_panel.tsx index 05b8949901e79..17c9f8e804c84 100644 --- a/src/plugins/vis_types/vislib/public/editor/components/heatmap/labels_panel.tsx +++ b/src/plugins/vis_types/vislib/public/editor/components/heatmap/labels_panel.tsx @@ -14,7 +14,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { VisEditorOptionsProps } from 'src/plugins/visualizations/public'; import { SwitchOption } from '../../../../../../vis_default_editor/public'; -import { ValueAxis } from '../../../../../xy/public'; +import { ValueAxis } from '../../../types'; import { HeatmapVisParams } from '../../../heatmap'; diff --git a/src/plugins/vis_types/vislib/public/heatmap.ts b/src/plugins/vis_types/vislib/public/heatmap.ts index 3ea3a4b1e4a06..37b4da9e8a0a9 100644 --- a/src/plugins/vis_types/vislib/public/heatmap.ts +++ b/src/plugins/vis_types/vislib/public/heatmap.ts @@ -13,7 +13,8 @@ import { RangeValues } from '../../../vis_default_editor/public'; import { AggGroupNames } from '../../../data/public'; import { ColorSchemas, ColorSchemaParams } from '../../../charts/public'; import { VIS_EVENT_TO_TRIGGER, VisTypeDefinition } from '../../../visualizations/public'; -import { ValueAxis, ScaleType, AxisType } from '../../xy/public'; +import { ScaleType, AxisType } from './constants'; +import { ValueAxis } from './types'; import { HeatmapOptions } from './editor'; import { TimeMarker } from './vislib/visualizations/time_marker'; diff --git a/src/plugins/vis_types/vislib/public/to_ast.ts b/src/plugins/vis_types/vislib/public/to_ast.ts index c1de94ba0f5f9..766e42227bca0 100644 --- a/src/plugins/vis_types/vislib/public/to_ast.ts +++ b/src/plugins/vis_types/vislib/public/to_ast.ts @@ -15,7 +15,7 @@ import { VisParams, } from '../../../visualizations/public'; import { buildExpression, buildExpressionFunction } from '../../../expressions/public'; -import type { Dimensions } from '../../xy/public'; +import type { Dimensions } from './types'; import type { DateHistogramParams, HistogramParams } from '../../../visualizations/public'; import { BUCKET_TYPES } from '../../../data/public'; @@ -23,6 +23,7 @@ import { BUCKET_TYPES } from '../../../data/public'; import { vislibVisName, VisTypeVislibExpressionFunctionDefinition } from './vis_type_vislib_vis_fn'; import { BasicVislibParams, VislibChartType } from './types'; import { getEsaggsFn } from './to_ast_esaggs'; +import { getColumnByAccessor } from './vislib/helpers'; export const toExpressionAst = async ( vis: Vis, @@ -42,7 +43,8 @@ export const toExpressionAst = async ( const responseAggs = vis.data.aggs?.getResponseAggs() ?? []; if (dimensions.x) { - const xAgg = responseAggs[dimensions.x.accessor] as any; + const xAgg = getColumnByAccessor(responseAggs, dimensions.x?.accessor) as any; + if (xAgg.type.name === BUCKET_TYPES.DATE_HISTOGRAM) { (dimensions.x.params as DateHistogramParams).date = true; const { esUnit, esValue } = xAgg.buckets.getInterval(); @@ -67,7 +69,9 @@ export const toExpressionAst = async ( const visConfig = { ...vis.params }; (dimensions.y || []).forEach((yDimension) => { - const yAgg = responseAggs.filter(({ enabled }) => enabled)[yDimension.accessor]; + const enabledAggs = responseAggs.filter(({ enabled }) => enabled); + const yAgg = getColumnByAccessor(enabledAggs, yDimension.accessor); + const seriesParam = ((visConfig.seriesParams as BasicVislibParams['seriesParams']) || []).find( (param) => param.data.id === yAgg.id ); diff --git a/src/plugins/vis_types/vislib/public/types.ts b/src/plugins/vis_types/vislib/public/types.ts index 9184e2a4c884c..e40229baa3fac 100644 --- a/src/plugins/vis_types/vislib/public/types.ts +++ b/src/plugins/vis_types/vislib/public/types.ts @@ -9,16 +9,82 @@ import { $Values } from '@kbn/utility-types'; import { Position } from '@elastic/charts'; -import { Labels } from '../../../charts/public'; import { - CategoryAxis, - Dimensions, - Grid, - SeriesParam, - ThresholdLine, - ValueAxis, -} from '../../../vis_types/xy/public'; + DateHistogramParams, + FakeParams, + HistogramParams, + SchemaConfig, +} from '../../../visualizations/public'; +import { Labels, Style } from '../../../charts/public'; import { TimeMarker } from './vislib/visualizations/time_marker'; +import { + AxisMode, + AxisType, + ChartMode, + ChartType, + InterpolationMode, + ScaleType, + ThresholdLineStyle, +} from './constants'; + +export interface ThresholdLine { + show: boolean; + value: number | null; + width: number | null; + style: ThresholdLineStyle; + color: string; +} + +export interface SeriesParam { + data: { label: string; id: string }; + drawLinesBetweenPoints?: boolean; + interpolate?: InterpolationMode; + lineWidth?: number; + mode: ChartMode; + show: boolean; + showCircles: boolean; + circlesRadius: number; + type: ChartType; + valueAxis: string; +} + +export interface Grid { + categoryLines: boolean; + valueAxis?: string; +} + +export interface Scale { + boundsMargin?: number | ''; + defaultYExtents?: boolean; + max?: number | null; + min?: number | null; + mode?: AxisMode; + setYExtents?: boolean; + type: ScaleType; +} + +export interface CategoryAxis { + id: string; + labels: Labels; + position: Position; + scale: Scale; + show: boolean; + title: { + text?: string; + }; + type: AxisType; + /** + * Used only for heatmap, here for consistent types when used in vis_type_vislib + * + * remove with vis_type_vislib + * https://github.com/elastic/kibana/issues/56143 + */ + style?: Partial