Skip to content

Commit

Permalink
[NP] Inline buildPointSeriesData and buildHierarchicalData dependenci…
Browse files Browse the repository at this point in the history
…es (#61575) (#63145)

* Move buildHierarchicalData to vislib

* Move shortened version of buildPointSeriesData to Discover

* Move buildPointSeriesData to vis_type_vislib

* Convert unit tests to jest

* Remove ui/agg_response

* Convert point_series files to TS

* Update TS in unit tests

* Convert buildHierarchicalData to TS

* Convert buildPointSeriesData to TS in Discover

* Clean TS in Discover

* Update TS for buildHierarchicalData

* Update buildHierarchicalData unit tests

* Clean up TS in point_series

* Add unit tests fro response_handler.js

* Simplify point_series for Discover

* Return array for data

* Add check for empty row

* Simplify point_series for Discover

* Return all points

* Specify TS

* Refactoring

* Simplifying

* improve types

* Update _get_point.test.ts

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
  • Loading branch information
3 people authored Apr 10, 2020
1 parent ae4b098 commit 7b0c852
Show file tree
Hide file tree
Showing 41 changed files with 1,328 additions and 1,040 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,3 @@ export {
EsQuerySortValue,
SortDirection,
} from '../../../../../plugins/data/public';
// @ts-ignore
export { buildPointSeriesData } from 'ui/agg_response/point_series/point_series';
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ import { IUiSettingsClient } from 'kibana/public';
import { EuiChartThemeType } from '@elastic/eui/dist/eui_charts_theme';
import { Subscription } from 'rxjs';
import { getServices } from '../../../kibana_services';
import { Chart as IChart } from '../helpers/point_series';

export interface DiscoverHistogramProps {
chartData: any;
chartData: IChart;
timefilterUpdateHandler: (ranges: { from: number; to: number }) => void;
}

Expand Down Expand Up @@ -163,7 +164,7 @@ export class DiscoverHistogram extends Component<DiscoverHistogramProps, Discove
};

public formatXValue = (val: string) => {
const xAxisFormat = this.props.chartData.xAxisFormat.params.pattern;
const xAxisFormat = this.props.chartData.xAxisFormat.params!.pattern;

return moment(val).format(xAxisFormat);
};
Expand Down Expand Up @@ -208,18 +209,19 @@ export class DiscoverHistogram extends Component<DiscoverHistogramProps, Discove
const { chartData } = this.props;
const { chartsTheme } = this.state;

if (!chartData || !chartData.series[0]) {
if (!chartData) {
return null;
}

const data = chartData.series[0].values;
const data = chartData.values;

/**
* Deprecation: [interval] on [date_histogram] is deprecated, use [fixed_interval] or [calendar_interval].
* see https://github.com/elastic/kibana/issues/27410
* TODO: Once the Discover query has been update, we should change the below to use the new field
*/
const { intervalESValue, intervalESUnit, interval: xInterval } = chartData.ordered;
const { intervalESValue, intervalESUnit, interval } = chartData.ordered;
const xInterval = interval.asMilliseconds();

const xValues = chartData.xAxisOrderedValues;
const lastXValue = xValues[xValues.length - 1];
Expand All @@ -228,7 +230,7 @@ export class DiscoverHistogram extends Component<DiscoverHistogramProps, Discove
const domainStart = domain.min.valueOf();
const domainEnd = domain.max.valueOf();

const domainMin = data[0].x > domainStart ? domainStart : data[0].x;
const domainMin = data[0]?.x > domainStart ? domainStart : data[0]?.x;
const domainMax = domainEnd - xInterval > lastXValue ? domainEnd - xInterval : lastXValue;

const xDomain = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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.
*/

import { uniq } from 'lodash';
import { Duration, Moment } from 'moment';
import { Unit } from '@elastic/datemath';

import { SerializedFieldFormat } from '../../../../../../../../plugins/expressions/common/types';

export interface Column {
id: string;
name: string;
}

export interface Row {
[key: string]: number | 'NaN';
}

export interface Table {
columns: Column[];
rows: Row[];
}

interface HistogramParams {
date: true;
interval: Duration;
intervalESValue: number;
intervalESUnit: Unit;
format: string;
bounds: {
min: Moment;
max: Moment;
};
}
export interface Dimension {
accessor: 0 | 1;
format: SerializedFieldFormat<{ pattern: string }>;
}

export interface Dimensions {
x: Dimension & { params: HistogramParams };
y: Dimension;
}

interface Ordered {
date: true;
interval: Duration;
intervalESUnit: string;
intervalESValue: number;
min: Moment;
max: Moment;
}
export interface Chart {
values: Array<{
x: number;
y: number;
}>;
xAxisOrderedValues: number[];
xAxisFormat: Dimension['format'];
xAxisLabel: Column['name'];
yAxisLabel?: Column['name'];
ordered: Ordered;
}

export const buildPointSeriesData = (table: Table, dimensions: Dimensions) => {
const { x, y } = dimensions;
const xAccessor = table.columns[x.accessor].id;
const yAccessor = table.columns[y.accessor].id;
const chart = {} as Chart;

chart.xAxisOrderedValues = uniq(table.rows.map(r => r[xAccessor] as number));
chart.xAxisFormat = x.format;
chart.xAxisLabel = table.columns[x.accessor].name;

const { intervalESUnit, intervalESValue, interval, bounds } = x.params;
chart.ordered = {
date: true,
interval,
intervalESUnit,
intervalESValue,
min: bounds.min,
max: bounds.max,
};

chart.yAxisLabel = table.columns[y.accessor].name;

chart.values = table.rows
.filter(row => row && row[yAccessor] !== 'NaN')
.map(row => ({
x: row[xAccessor] as number,
y: row[yAccessor] as number,
}));

return chart;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* under the License.
*/

import { buildPointSeriesData, getServices } from '../../kibana_services';
import { getServices } from '../../kibana_services';
import { buildPointSeriesData } from './helpers';

function tableResponseHandler(table, dimensions) {
const converted = { tables: [] };
Expand Down
1 change: 0 additions & 1 deletion src/legacy/core_plugins/kibana/public/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import './discover/legacy';
import './visualize/legacy';
import './management';
import './dev_tools';
import 'ui/agg_response';
import { showAppRedirectNotification } from '../../../../plugins/kibana_legacy/public';
import 'leaflet';
import { localApplicationService } from './local_application_service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,3 @@

import { search } from '../../../../plugins/data/public';
export const { tabifyAggResponse, tabifyGetColumns } = search;

// @ts-ignore
export { buildHierarchicalData } from 'ui/agg_response/hierarchical/build_hierarchical_data';
// @ts-ignore
export { buildPointSeriesData } from 'ui/agg_response/point_series/point_series';

This file was deleted.

Loading

0 comments on commit 7b0c852

Please sign in to comment.