Browse Source

fix issue #49 (#52)

* remove color index from code
use different approach

fix issue #49

* remove unneeded space
change var to let

* add 2 more tests to check correct color choice behaviour after deleting anomalies

* use more descriptive word in text description
master
sanke1 6 years ago committed by Alexey Velikiy
parent
commit
3557a14aae
  1. 14
      src/controllers/analytic_controller.ts
  2. 16
      tests/analyticController.jest.ts

14
src/controllers/analytic_controller.ts

@ -37,11 +37,8 @@ export class AnalyticController {
private _savingNewAnalyticUnit: boolean = false;
private _tempIdCounted: number = -1;
private _graphLocked: boolean = false;
private _currentColorIndex: number = 0;
private _statusRunners: Set<AnalyticUnitId> = new Set<AnalyticUnitId>();
constructor(private _panelObject: any, private _analyticService: AnalyticService, private _emitter: Emitter) {
if(_panelObject.anomalyTypes === undefined) {
_panelObject.anomalyTypes = [];
@ -50,7 +47,6 @@ export class AnalyticController {
this._labelingDataDeletedSegments = new SegmentArray<AnalyticSegment>();
this._analyticUnitsSet = new AnalyticUnitsSet(this._panelObject.anomalyTypes);
this.analyticUnits.forEach(a => this.runEnabledWaiter(a));
this._currentColorIndex = this._panelObject.anomalyTypes.length % ANALYTIC_UNIT_COLORS.length;
}
getSegmentsSearcher(): AnalyticSegmentsSearcher {
@ -72,9 +68,13 @@ export class AnalyticController {
this._newAnalyticUnit = new AnalyticUnit();
this._creatingNewAnalyticType = true;
this._savingNewAnalyticUnit = false;
this._newAnalyticUnit.color = ANALYTIC_UNIT_COLORS[this._currentColorIndex];
this._currentColorIndex++;
this._currentColorIndex %= ANALYTIC_UNIT_COLORS.length;
if (this.analyticUnits.length === 0) {
this._newAnalyticUnit.color = ANALYTIC_UNIT_COLORS[0];
} else {
let colorIndex = ANALYTIC_UNIT_COLORS.indexOf(_.last(this.analyticUnits).color) + 1;
colorIndex %= ANALYTIC_UNIT_COLORS.length;
this._newAnalyticUnit.color = ANALYTIC_UNIT_COLORS[colorIndex];
}
}
async saveNew(metricExpanded: MetricExpanded, datasourceRequest: DatasourceRequest, panelId: number) {

16
tests/analyticController.jest.ts

@ -3,6 +3,7 @@ import { MetricExpanded } from '../src/models/metric';
import { DatasourceRequest } from '../src/models/datasource';
import { analyticController } from './setup_tests';
import { AnalyticUnit } from '../src/models/analytic_unit';
describe('AnalyticController', function () {
@ -25,6 +26,21 @@ describe('AnalyticController', function () {
}
});
it('should set different color to newly created Analytic Unit, afer NOT last AU was deleted', async function() {
let auArray = analyticController.analyticUnits;
analyticController.createNew();
await analyticController.saveNew({} as MetricExpanded, {} as DatasourceRequest, 1);
expect(auArray[auArray.length - 2].panelObject.color).not.toBe(auArray[auArray.length - 1].panelObject.color);
});
it('should set different color to newly created Analytic Unit, afer LAST AU was deleted', async function () {
let auArray = analyticController.analyticUnits;
auArray.splice(-1, 1);
analyticController.createNew();
await analyticController.saveNew({} as MetricExpanded, {} as DatasourceRequest, 1);
expect(auArray[auArray.length - 2].panelObject.color).not.toBe(auArray[auArray.length - 1].panelObject.color);
});
it('should change color on choosing from palette', function () {
analyticController.onAnalyticUnitColorChange('1', 'red');
expect(analyticController.analyticUnits[0].color).toBe('red');

Loading…
Cancel
Save