Skip to content

Commit

Permalink
Specify TS
Browse files Browse the repository at this point in the history
  • Loading branch information
maryia-lapata committed Apr 8, 2020
1 parent ad8ab46 commit 10eca3f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ export class DiscoverHistogram extends Component<DiscoverHistogramProps, Discove
* TODO: Once the Discover query has been update, we should change the below to use the new field
*/
const { intervalESValue, intervalESUnit, interval } = chartData.ordered;
const xInterval = interval as number;
const xInterval = interval.asMilliseconds();

const xValues = chartData.xAxisOrderedValues;
const lastXValue = xValues[xValues.length - 1];

const domain = chartData.ordered;
const domainStart = domain.min!.valueOf();
const domainEnd = domain.max!.valueOf();
const domainStart = domain.min.valueOf();
const domainEnd = domain.max.valueOf();

const domainMin = data[0].x > domainStart ? domainStart : data[0].x;
const domainMax = domainEnd - xInterval > lastXValue ? domainEnd - xInterval : lastXValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

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

import { SerializedFieldFormat } from '../../../../../../../../plugins/expressions/common/types';
Expand All @@ -43,9 +43,9 @@ interface HistogramParams {
intervalESValue: number;
intervalESUnit: Unit;
format: string;
bounds?: {
min: string | number;
max: string | number;
bounds: {
min: Moment;
max: Moment;
};
}
export interface Dimension {
Expand All @@ -60,11 +60,11 @@ export interface Dimensions {

interface Ordered {
date: true;
interval: Duration | number;
interval: Duration;
intervalESUnit: string;
intervalESValue: number;
min?: number;
max?: number;
min: Moment;
max: Moment;
}
export interface Chart {
values: Array<{
Expand All @@ -91,20 +91,13 @@ export const buildPointSeriesData = (table: Table, dimensions: Dimensions) => {
const { intervalESUnit, intervalESValue, interval, bounds } = x.params;
chart.ordered = {
date: true,
interval: moment.duration(interval),
interval,
intervalESUnit,
intervalESValue,
min: bounds.min,
max: bounds.max,
};

if (bounds) {
chart.ordered.min = isNaN(bounds.min as number)
? Date.parse(bounds.min as string)
: (bounds.min as number);
chart.ordered.max = isNaN(bounds.max as number)
? Date.parse(bounds.max as string)
: (bounds.max as number);
}

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

chart.values = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function tableVisResponseHandler(table: Table, dimensions: Dimensions) {
let splitIndex = 0;

table.rows.forEach((row, rowIndex) => {
const splitValue = row[splitColumn.id];
const splitValue = row[splitColumn.id] as string;

if (!splitMap.hasOwnProperty(splitValue)) {
splitMap[splitValue] = splitIndex++;
Expand All @@ -49,15 +49,15 @@ function tableVisResponseHandler(table: Table, dimensions: Dimensions) {
row: rowIndex,
table,
tables: [] as Table[],
};
} as any;

tableGroup.tables.push({
$parent: tableGroup as TableParent,
$parent: tableGroup,
columns: table.columns,
rows: [],
});

converted.tables.push(tableGroup as TableParent);
converted.tables.push(tableGroup);
}

const tableIndex = splitMap[splitValue];
Expand Down Expand Up @@ -328,8 +328,8 @@ describe('buildHierarchicalData convertTable', () => {
{ id: 'col-1-1', name: 'Count' },
],
rows: [
{ 'col-0-agg_2': { gte: 0, lt: 1000 } as any, 'col-1-1': 606 },
{ 'col-0-agg_2': { gte: 1000, lt: 2000 } as any, 'col-1-1': 298 },
{ 'col-0-agg_2': { gte: 0, lt: 1000 }, 'col-1-1': 606 },
{ 'col-0-agg_2': { gte: 1000, lt: 2000 }, 'col-1-1': 298 },
],
};
dimensions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface Slice {
table: Table;
row: number;
column: number;
value: string | number;
value: string | number | object;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type Ordered = (DateHistogramOrdered | HistogramOrdered) & {
export interface Chart {
aspects: Aspects;
series: Serie[];
xAxisOrderedValues?: Array<string | number>;
xAxisOrderedValues?: Array<string | number | object>;
xAxisFormat?: Dimension['format'];
xAxisLabel?: Column['name'];
yAxisFormat?: Dimension['format'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface Column {
}

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

export interface TableParent {
Expand Down

0 comments on commit 10eca3f

Please sign in to comment.