Set columnsOptions as optional, allow empty splitBy selection and ignore empty date values for timeline charts

This commit is contained in:
Violet Voronetzky 2019-11-26 09:47:21 +02:00
Родитель a813278cd2
Коммит db9c2ee8ac
4 изменённых файлов: 73 добавлений и 91 удалений

Просмотреть файл

@ -82,8 +82,9 @@ export interface IChartOptions {
/**
* The columns selection for the Axes and the split-by of the chart
* If not provided, default columns will be selected. See: getDefaultSelection method
*/
columnsSelection: IAxesInfo<IColumn>;
columnsSelection?: IAxesInfo<IColumn>;
/**
* The maximum number of the unique X-axis values.

Просмотреть файл

@ -104,7 +104,7 @@ export class KustoChartHelper implements IChartHelper {
*/
public transformQueryResultData(queryResultData: IQueryResultData, chartOptions: IChartOptions): ITransformedQueryResultData {
// Update the chart options with defaults for optional values that weren't provided
chartOptions = this.updateDefaultChartOptions(chartOptions);
chartOptions = this.updateDefaultChartOptions(queryResultData, chartOptions);
const chartColumns: IColumn[] = [];
const indexOfXAxisColumn: number[] = [];
@ -113,9 +113,10 @@ export class KustoChartHelper implements IChartHelper {
}
// Get all the indexes for all the splitBy columns
const splitByColumnsSelection = chartOptions.columnsSelection.splitBy;
const indexesOfSplitByColumns: number[] = [];
if (!this.addColumnsIfExistInResult(chartOptions.columnsSelection.splitBy, queryResultData, indexesOfSplitByColumns, chartColumns)) {
if (splitByColumnsSelection && !this.addColumnsIfExistInResult(splitByColumnsSelection, queryResultData, indexesOfSplitByColumns, chartColumns)) {
return null;
}
@ -294,9 +295,14 @@ export class KustoChartHelper implements IChartHelper {
return true;
}
private updateDefaultChartOptions(chartOptions: IChartOptions): IChartOptions {
private updateDefaultChartOptions(queryResultData: IQueryResultData, chartOptions: IChartOptions): IChartOptions {
const updatedChartOptions: IChartOptions = { ...KustoChartHelper.defaultChartOptions, ...chartOptions };
// Apply default columns selection is columns selection wasn't provided
if(!updatedChartOptions.columnsSelection) {
updatedChartOptions.columnsSelection = this.getDefaultSelection(queryResultData, updatedChartOptions.chartType);
}
return updatedChartOptions;
}

Просмотреть файл

@ -12,7 +12,6 @@ import { ChartAggregation, IAggregationMethod } from './chartAggregation';
export class LimitedResults {
public constructor(
public rows: any[] = [],
public orderedXValues: any[] = [],
public isAggregationApplied: boolean = false,
public isPartialData: boolean = false) { }
}
@ -75,11 +74,24 @@ export class _LimitVisResults {
this.limitAllRows(internalParams, limitedResults);
this.aggregateAndEscapeRows(internalParams, limitedResults);
const xIndex = params.axesIndexes.xAxis;
// Sort the x-Axis only if it's a date time column
if (params.xColumnType === DraftColumnType.DateTime) {
limitedResults.rows = _.sortBy(limitedResults.rows, (row) => {
return moment(row[0]).valueOf();
// Remove empty dates since they can't be placed on the x-axis
let validRows = [];
_.forEach(limitedResults.rows, (row) => {
if(row[xIndex] != null) {
validRows.push(row);
}
});
const sortedAndValidRows = _.sortBy(validRows, (row) => {
return moment(row[xIndex]).valueOf();
});
limitedResults.rows = sortedAndValidRows;
}
return limitedResults;
@ -342,14 +354,18 @@ export class _LimitVisResults {
});
});
// Restore rows order
const aggregatedRowInfo: IAggregatedRowInfo[] = _.sortBy(aggregatedRowInfoMap, 'order');
let aggregatedRowInfo: IAggregatedRowInfo[];
if(params.xColumnType === DraftColumnType.DateTime) {
aggregatedRowInfo = _.map(aggregatedRowInfoMap);
} else {
// Restore rows order
aggregatedRowInfo = _.sortBy(aggregatedRowInfoMap, 'order');
}
const aggregationResult: IAggregationResult = this.applyAggregation(aggregatedRowInfo, params.aggregationMethod);
limitedResults.orderedXValues = _.map(limitedResults.rows, (row) => {
return row[params.axesIndexes.xAxis];
}) || [];
limitedResults.isAggregationApplied = aggregationResult.isAggregated;
limitedResults.rows = aggregationResult.rows;
}

Просмотреть файл

@ -373,41 +373,10 @@ describe('Unit tests for LimitVisResults', () => {
["2019-09-16T00:00:00Z", "United States", 52451]
];
const expectedOrderedXValues = [
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-16T00:00:00Z",
"2019-09-15T00:00:00Z",
"2019-09-15T00:00:00Z",
"2019-09-15T00:00:00Z",
"2019-09-15T00:00:00Z",
"2019-09-15T00:00:00Z",
"2019-09-15T00:00:00Z",
"2019-09-15T00:00:00Z",
"2019-09-15T00:00:00Z",
"2019-09-15T00:00:00Z"
];
// Assert
expect(limitedResults.isPartialData).toEqual(false);
expect(limitedResults.isAggregationApplied).toEqual(true);
expect(limitedResults.rows).toEqual(expectedLimitesRows);
expect(limitedResults.orderedXValues).toEqual(expectedOrderedXValues);
});
it("When the X have the same value, and there is no split-by, the X values are aggregated", () => {
@ -445,41 +414,10 @@ describe('Unit tests for LimitVisResults', () => {
["Kfar Saba", 95]
];
const expectedOrderedXValues = [
"Chicago",
"San Antonio",
"Washington",
"Washington",
"Washington",
"Ogden",
"New York",
"New York",
"Atlanta",
"Atlanta",
"San Jose",
"Ashburn",
"",
"",
"Cazadero",
"Des Moines",
"Los Angeles",
"Santa Clara",
"San Antonio",
"Chicago",
"Washington",
"Washington",
"Washington",
"Mountain View",
"San Jose",
"Kfar Saba",
"Kfar Saba",
];
// Assert
expect(limitedResults.isPartialData).toEqual(false);
expect(limitedResults.isAggregationApplied).toEqual(true);
expect(limitedResults.rows).toEqual(expectedLimitesRows);
expect(limitedResults.orderedXValues).toEqual(expectedOrderedXValues);
});
it("When the X values exceeds maximum size, they are limited", () => {
@ -505,25 +443,46 @@ describe('Unit tests for LimitVisResults', () => {
[exceedMaxDataPointLabel, 1929],
];
const expectedOrderedXValues = [
"Chicago",
"San Antonio",
"Washington",
"Washington",
"Washington",
"San Antonio",
"Chicago",
"Washington",
"Washington",
"Washington",
exceedMaxDataPointLabel
];
// Assert
expect(limitedResults.isPartialData).toEqual(true);
expect(limitedResults.isAggregationApplied).toEqual(true);
expect(limitedResults.rows).toEqual(expectedLimitesRows);
expect(limitedResults.orderedXValues).toEqual(expectedOrderedXValues);
});
it("When the X is Date, and there is an empty date value in the results - this value is ignored", () => {
const rows = [
["2019-09-16T00:00:00Z", "United States", 10],
[null, "United States", 50],
["2019-09-16T00:00:00Z", "United States", 20],
["2019-09-15T00:00:00Z", "Israel", 100],
[null, "Israel", 200]
];
const limitAndAggregateParams: ILimitAndAggregateParams = {
queryResultData: { rows: rows, columns: [] },
axesIndexes: {
xAxis: 0,
yAxes: [2],
splitBy: [1]
},
xColumnType: DraftColumnType.DateTime,
aggregationType: AggregationType.Sum,
maxUniqueXValues: maxUniqueXValues,
otherStr: exceedMaxDataPointLabel
}
// Act
const limitedResults = LimitVisResultsSingleton.limitAndAggregateRows(limitAndAggregateParams);
const expectedLimitesRows = [
["2019-09-15T00:00:00Z", "Israel", 100],
["2019-09-16T00:00:00Z", "United States", 30]
];
// Assert
expect(limitedResults.isPartialData).toEqual(false);
expect(limitedResults.isAggregationApplied).toEqual(true);
expect(limitedResults.rows).toEqual(expectedLimitesRows);
});
});