PR modifications
This commit is contained in:
Родитель
9a5896dcee
Коммит
822a85270e
|
@ -9,8 +9,8 @@ export enum ChartChange {
|
|||
export type ChangesMap = { [key in ChartChange]+?: boolean};
|
||||
|
||||
export class Changes {
|
||||
public changesMap: ChangesMap;
|
||||
public count: number;
|
||||
private changesMap: ChangesMap;
|
||||
|
||||
public constructor() {
|
||||
this.changesMap = {};
|
||||
|
|
|
@ -6,6 +6,7 @@ import * as _ from 'lodash';
|
|||
import * as Highcharts from 'highcharts';
|
||||
import { IVisualizerOptions } from '../../IVisualizerOptions';
|
||||
import { Utilities } from '../../../common/utilities';
|
||||
import { IColumn } from '../../../common/chartModels';
|
||||
|
||||
//#endregion Imports
|
||||
|
||||
|
@ -15,8 +16,11 @@ export interface ICategoriesAndSeries {
|
|||
}
|
||||
|
||||
export abstract class Chart {
|
||||
public getStandardCategoriesAndSeries(options: IVisualizerOptions, xAxisColumnIndex: number, isDatetimeAxis: boolean = false): ICategoriesAndSeries {
|
||||
public getStandardCategoriesAndSeries(options: IVisualizerOptions): ICategoriesAndSeries {
|
||||
const chartOptions = options.chartOptions;
|
||||
const xColumn: IColumn = chartOptions.columnsSelection.xAxis;
|
||||
const isDatetimeAxis: boolean = Utilities.isDate(xColumn.type);
|
||||
const xAxisColumnIndex: number = Utilities.getColumnIndex(options.queryResultData, xColumn);
|
||||
const yAxesIndexes = _.map(chartOptions.columnsSelection.yAxes, (yAxisColumn) => {
|
||||
return Utilities.getColumnIndex(options.queryResultData, yAxisColumn);
|
||||
});
|
||||
|
@ -31,7 +35,7 @@ export abstract class Chart {
|
|||
options.queryResultData.rows.forEach((row) => {
|
||||
let xAxisValue: any = row[xAxisColumnIndex];
|
||||
|
||||
// If the x-axis is a date, convert it's value to milliseconds as this is what expected by 'Highcharts'
|
||||
// If the x-axis is a date, convert its value to milliseconds as this is what expected by 'Highcharts'
|
||||
if(isDatetimeAxis) {
|
||||
const dateValue = Utilities.getValidDate(xAxisValue, chartOptions.utcOffset);
|
||||
|
||||
|
@ -64,7 +68,11 @@ export abstract class Chart {
|
|||
return categoriesAndSeries;
|
||||
}
|
||||
|
||||
public getSplitByCategoriesAndSeries(options: IVisualizerOptions, xAxisColumnIndex: number, isDatetimeAxis: boolean = false): ICategoriesAndSeries {
|
||||
public getSplitByCategoriesAndSeries(options: IVisualizerOptions): ICategoriesAndSeries {
|
||||
const xColumn: IColumn = options.chartOptions.columnsSelection.xAxis;
|
||||
const isDatetimeAxis: boolean = Utilities.isDate(xColumn.type);
|
||||
const xAxisColumnIndex: number = Utilities.getColumnIndex(options.queryResultData, xColumn);
|
||||
|
||||
if(isDatetimeAxis) {
|
||||
return this.getSplitByCategoriesAndSeriesForDateXAxis(options, xAxisColumnIndex);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
import * as _ from 'lodash';
|
||||
import { Chart, ICategoriesAndSeries } from './chart';
|
||||
import { Utilities } from '../../../common/utilities';
|
||||
import { IVisualizerOptions } from '../../IVisualizerOptions';
|
||||
import { Utilities } from '../../../common/utilities';
|
||||
import { IColumn } from '../../../common/chartModels';
|
||||
|
||||
export class Pie extends Chart {
|
||||
//#region Methods override
|
||||
|
@ -21,7 +22,9 @@ export class Pie extends Chart {
|
|||
}
|
||||
}
|
||||
|
||||
public getStandardCategoriesAndSeries(options: IVisualizerOptions, xAxisColumnIndex: number): ICategoriesAndSeries {
|
||||
public getStandardCategoriesAndSeries(options: IVisualizerOptions): ICategoriesAndSeries {
|
||||
const xColumn: IColumn = options.chartOptions.columnsSelection.xAxis;
|
||||
const xAxisColumnIndex: number = Utilities.getColumnIndex(options.queryResultData, xColumn);
|
||||
const yAxisColumn = options.chartOptions.columnsSelection.yAxes[0]; // We allow only 1 yAxis in pie charts
|
||||
const yAxisColumnIndex = Utilities.getColumnIndex(options.queryResultData, yAxisColumn);
|
||||
|
||||
|
@ -46,9 +49,11 @@ export class Pie extends Chart {
|
|||
}
|
||||
}
|
||||
|
||||
public getSplitByCategoriesAndSeries(options: IVisualizerOptions, xAxisColumnIndex: number): ICategoriesAndSeries {
|
||||
public getSplitByCategoriesAndSeries(options: IVisualizerOptions): ICategoriesAndSeries {
|
||||
const yAxisColumn = options.chartOptions.columnsSelection.yAxes[0]; // We allow only 1 yAxis in pie charts
|
||||
const yAxisColumnIndex = Utilities.getColumnIndex(options.queryResultData, yAxisColumn);
|
||||
const xColumn: IColumn = options.chartOptions.columnsSelection.xAxis;
|
||||
const xAxisColumnIndex: number = Utilities.getColumnIndex(options.queryResultData, xColumn);
|
||||
const splitByIndexes = [xAxisColumnIndex];
|
||||
|
||||
options.chartOptions.columnsSelection.splitBy.forEach((splitByColumn) => {
|
||||
|
|
|
@ -134,7 +134,7 @@ export class HighchartsVisualizer implements IVisualizer {
|
|||
yAxis: this.getYAxis()
|
||||
};
|
||||
|
||||
const categoriesAndSeries = this.getCategoriesAndSeries(isDatetimeAxis);
|
||||
const categoriesAndSeries = this.getCategoriesAndSeries();
|
||||
const chartTypeOptions = this.currentChart.getChartTypeOptions();
|
||||
|
||||
highchartsOptions = _.merge(highchartsOptions, chartTypeOptions, categoriesAndSeries);
|
||||
|
@ -165,16 +165,14 @@ export class HighchartsVisualizer implements IVisualizer {
|
|||
}
|
||||
}
|
||||
|
||||
private getCategoriesAndSeries(isDatetimeAxis: boolean): Highcharts.Options {
|
||||
const columnsSelection = this.options.chartOptions.columnsSelection;
|
||||
const xAxisColumn = columnsSelection.xAxis;
|
||||
const xAxisColumnIndex = Utilities.getColumnIndex(this.options.queryResultData, xAxisColumn);
|
||||
private getCategoriesAndSeries(): Highcharts.Options {
|
||||
const columnsSelection = this.options.chartOptions.columnsSelection;
|
||||
let categoriesAndSeries;
|
||||
|
||||
if(columnsSelection.splitBy && columnsSelection.splitBy.length > 0) {
|
||||
categoriesAndSeries = this.currentChart.getSplitByCategoriesAndSeries(this.options, xAxisColumnIndex, isDatetimeAxis);
|
||||
categoriesAndSeries = this.currentChart.getSplitByCategoriesAndSeries(this.options);
|
||||
} else {
|
||||
categoriesAndSeries = this.currentChart.getStandardCategoriesAndSeries(this.options, xAxisColumnIndex, isDatetimeAxis);
|
||||
categoriesAndSeries = this.currentChart.getStandardCategoriesAndSeries(this.options);
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
@ -45,7 +45,7 @@ describe('Unit tests for ChangeDetection', () => {
|
|||
|
||||
// Assert
|
||||
expect(result.count).toEqual(expected.count);
|
||||
expect(result.changesMap).toEqual(expected.changesMap);
|
||||
expect(result['changesMap']).toEqual(expected.changesMap);
|
||||
});
|
||||
|
||||
it('When only the chart type was changed - chart changes is as expected', () => {
|
||||
|
@ -80,7 +80,7 @@ describe('Unit tests for ChangeDetection', () => {
|
|||
|
||||
// Assert
|
||||
expect(result.count).toEqual(expected.count);
|
||||
expect(result.changesMap).toEqual(expected.changesMap);
|
||||
expect(result['changesMap']).toEqual(expected.changesMap);
|
||||
});
|
||||
|
||||
it('When there was columns selection change - chart changes is as expected', () => {
|
||||
|
@ -115,7 +115,7 @@ describe('Unit tests for ChangeDetection', () => {
|
|||
|
||||
// Assert
|
||||
expect(result.count).toEqual(expected.count);
|
||||
expect(result.changesMap).toEqual(expected.changesMap);
|
||||
expect(result['changesMap']).toEqual(expected.changesMap);
|
||||
});
|
||||
|
||||
it('When there was both columns selection and chart type change - chart changes is as expected', () => {
|
||||
|
@ -151,7 +151,7 @@ describe('Unit tests for ChangeDetection', () => {
|
|||
|
||||
// Assert
|
||||
expect(result.count).toEqual(expected.count);
|
||||
expect(result.changesMap).toEqual(expected.changesMap);
|
||||
expect(result['changesMap']).toEqual(expected.changesMap);
|
||||
});
|
||||
|
||||
it('When only the query result data was changed - chart changes is as expected', () => {
|
||||
|
@ -184,7 +184,7 @@ describe('Unit tests for ChangeDetection', () => {
|
|||
|
||||
// Assert
|
||||
expect(result.count).toEqual(expected.count);
|
||||
expect(result.changesMap).toEqual(expected.changesMap);
|
||||
expect(result['changesMap']).toEqual(expected.changesMap);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -41,11 +41,10 @@ describe('Unit tests for Chart methods', () => {
|
|||
];
|
||||
|
||||
// Input
|
||||
const xAxisColumnIndex = 0;
|
||||
const options: any = {
|
||||
chartOptions: {
|
||||
columnsSelection: {
|
||||
xAxis: columns[xAxisColumnIndex], // country
|
||||
xAxis: columns[0], // country
|
||||
yAxes: [columns[2]] // request_count
|
||||
},
|
||||
utcOffset: 0
|
||||
|
@ -58,7 +57,7 @@ describe('Unit tests for Chart methods', () => {
|
|||
|
||||
// Act
|
||||
const chart = ChartFactory.create(ChartType.Line);
|
||||
const result: any = chart.getStandardCategoriesAndSeries(options, xAxisColumnIndex, /*isDatetimeAxis*/ false);
|
||||
const result: any = chart.getStandardCategoriesAndSeries(options);
|
||||
|
||||
const expected: ICategoriesAndSeries = {
|
||||
series: [{
|
||||
|
@ -87,11 +86,10 @@ describe('Unit tests for Chart methods', () => {
|
|||
];
|
||||
|
||||
// Input
|
||||
const xAxisColumnIndex = 1;
|
||||
const options: any = {
|
||||
chartOptions: {
|
||||
columnsSelection: {
|
||||
xAxis: columns[xAxisColumnIndex], // timestamp
|
||||
xAxis: columns[1], // timestamp
|
||||
yAxes: [columns[3]] // request_count
|
||||
},
|
||||
utcOffset: 0
|
||||
|
@ -104,7 +102,7 @@ describe('Unit tests for Chart methods', () => {
|
|||
|
||||
// Act
|
||||
const chart = ChartFactory.create(ChartType.Line);
|
||||
const result: any = chart.getStandardCategoriesAndSeries(options, xAxisColumnIndex, /*isDatetimeAxis*/ true);
|
||||
const result: any = chart.getStandardCategoriesAndSeries(options);
|
||||
|
||||
const expected: ICategoriesAndSeries = {
|
||||
series: [{
|
||||
|
@ -133,11 +131,10 @@ describe('Unit tests for Chart methods', () => {
|
|||
];
|
||||
|
||||
// Input
|
||||
const xAxisColumnIndex = 1;
|
||||
const options: any = {
|
||||
chartOptions: {
|
||||
columnsSelection: {
|
||||
xAxis: columns[xAxisColumnIndex], // city
|
||||
xAxis: columns[1], // city
|
||||
yAxes: [columns[2], columns[3]] // request_count and second_count
|
||||
},
|
||||
utcOffset: 0
|
||||
|
@ -150,7 +147,7 @@ describe('Unit tests for Chart methods', () => {
|
|||
|
||||
// Act
|
||||
const chart = ChartFactory.create(ChartType.Line);
|
||||
const result: any = chart.getStandardCategoriesAndSeries(options, xAxisColumnIndex, /*isDatetimeAxis*/ false);
|
||||
const result: any = chart.getStandardCategoriesAndSeries(options);
|
||||
|
||||
const expected: ICategoriesAndSeries = {
|
||||
series: [{
|
||||
|
@ -184,11 +181,10 @@ describe('Unit tests for Chart methods', () => {
|
|||
];
|
||||
|
||||
// Input
|
||||
const xAxisColumnIndex = 0;
|
||||
const options: any = {
|
||||
chartOptions: {
|
||||
columnsSelection: {
|
||||
xAxis: columns[xAxisColumnIndex], // timestamp
|
||||
xAxis: columns[0], // timestamp
|
||||
yAxes: [columns[3], columns[4]] // request_count and second_count
|
||||
},
|
||||
utcOffset: 0
|
||||
|
@ -201,7 +197,7 @@ describe('Unit tests for Chart methods', () => {
|
|||
|
||||
// Act
|
||||
const chart = ChartFactory.create(ChartType.Line);
|
||||
const result: any = chart.getStandardCategoriesAndSeries(options, xAxisColumnIndex, /*isDatetimeAxis*/ true);
|
||||
const result: any = chart.getStandardCategoriesAndSeries(options);
|
||||
|
||||
const expected: ICategoriesAndSeries = {
|
||||
series: [{
|
||||
|
@ -242,11 +238,10 @@ describe('Unit tests for Chart methods', () => {
|
|||
];
|
||||
|
||||
// Input
|
||||
const xAxisColumnIndex = 0;
|
||||
const options: any = {
|
||||
chartOptions: {
|
||||
columnsSelection: {
|
||||
xAxis: columns[xAxisColumnIndex], // country
|
||||
xAxis: columns[0], // country
|
||||
yAxes: [columns[2]], // request_count
|
||||
splitBy: [columns[1]] // city
|
||||
},
|
||||
|
@ -260,7 +255,7 @@ describe('Unit tests for Chart methods', () => {
|
|||
|
||||
// Act
|
||||
const chart = ChartFactory.create(ChartType.Line);
|
||||
const result: any = chart.getSplitByCategoriesAndSeries(options, xAxisColumnIndex, /*isDatetimeAxis*/ false);
|
||||
const result: any = chart.getSplitByCategoriesAndSeries(options);
|
||||
|
||||
const expected: ICategoriesAndSeries = {
|
||||
series: [{
|
||||
|
@ -322,11 +317,10 @@ describe('Unit tests for Chart methods', () => {
|
|||
];
|
||||
|
||||
// Input
|
||||
const xAxisColumnIndex = 1;
|
||||
const options: any = {
|
||||
chartOptions: {
|
||||
columnsSelection: {
|
||||
xAxis: columns[xAxisColumnIndex], // timestamp
|
||||
xAxis: columns[1], // timestamp
|
||||
yAxes: [columns[3]], // request_count
|
||||
splitBy: [columns[2]], // city
|
||||
},
|
||||
|
@ -340,7 +334,7 @@ describe('Unit tests for Chart methods', () => {
|
|||
|
||||
// Act
|
||||
const chart = ChartFactory.create(ChartType.Line);
|
||||
const result: any = chart.getSplitByCategoriesAndSeries(options, xAxisColumnIndex, /*isDatetimeAxis*/ true);
|
||||
const result: any = chart.getSplitByCategoriesAndSeries(options);
|
||||
|
||||
const expected: ICategoriesAndSeries = {
|
||||
series: [{
|
||||
|
@ -404,11 +398,10 @@ describe('Unit tests for Chart methods', () => {
|
|||
];
|
||||
|
||||
// Input
|
||||
const xAxisColumnIndex = 1;
|
||||
const options: any = {
|
||||
chartOptions: {
|
||||
columnsSelection: {
|
||||
xAxis: columns[xAxisColumnIndex], // city
|
||||
xAxis: columns[1], // city
|
||||
yAxes: [columns[2]], // request_count
|
||||
},
|
||||
utcOffset: 0
|
||||
|
@ -421,7 +414,7 @@ describe('Unit tests for Chart methods', () => {
|
|||
|
||||
// Act
|
||||
const chart = ChartFactory.create(ChartType.Pie);
|
||||
const result: any = chart.getStandardCategoriesAndSeries(options, xAxisColumnIndex, /*isDatetimeAxis*/ false);
|
||||
const result: any = chart.getStandardCategoriesAndSeries(options);
|
||||
|
||||
const expected: ICategoriesAndSeries = {
|
||||
series: [{
|
||||
|
@ -481,11 +474,10 @@ describe('Unit tests for Chart methods', () => {
|
|||
];
|
||||
|
||||
// Input
|
||||
const xAxisColumnIndex = 0;
|
||||
const options: any = {
|
||||
chartOptions: {
|
||||
columnsSelection: {
|
||||
xAxis: columns[xAxisColumnIndex], // country
|
||||
xAxis: columns[0], // country
|
||||
yAxes: [columns[2]], // request_count
|
||||
splitBy: [columns[1]] // city
|
||||
},
|
||||
|
@ -499,7 +491,7 @@ describe('Unit tests for Chart methods', () => {
|
|||
|
||||
// Act
|
||||
const chart = ChartFactory.create(ChartType.Pie);
|
||||
const result: any = chart.getSplitByCategoriesAndSeries(options, xAxisColumnIndex, /*isDatetimeAxis*/ false);
|
||||
const result: any = chart.getSplitByCategoriesAndSeries(options);
|
||||
|
||||
const expected: ICategoriesAndSeries = {
|
||||
series: [{
|
||||
|
@ -558,11 +550,10 @@ describe('Unit tests for Chart methods', () => {
|
|||
];
|
||||
|
||||
// Input
|
||||
const xAxisColumnIndex = 0;
|
||||
const options: any = {
|
||||
chartOptions: {
|
||||
columnsSelection: {
|
||||
xAxis: columns[xAxisColumnIndex], // browser
|
||||
xAxis: columns[0], // browser
|
||||
yAxes: [columns[3]], // usage
|
||||
splitBy: [columns[1], columns[2]] // version, minor_version
|
||||
},
|
||||
|
@ -576,7 +567,7 @@ describe('Unit tests for Chart methods', () => {
|
|||
|
||||
// Act
|
||||
const chart = ChartFactory.create(ChartType.Donut);
|
||||
const result: any = chart.getSplitByCategoriesAndSeries(options, xAxisColumnIndex, /*isDatetimeAxis*/ false);
|
||||
const result: any = chart.getSplitByCategoriesAndSeries(options);
|
||||
|
||||
const expected: ICategoriesAndSeries = {
|
||||
series: [{
|
||||
|
|
Загрузка…
Ссылка в новой задаче