From cfeade4f6e79b6e053f90e86c6004e9c4dcea00d Mon Sep 17 00:00:00 2001 From: sanke Date: Fri, 13 Jul 2018 16:08:40 +0300 Subject: [PATCH 1/6] New analytic units start with a preset color from the palette (redo previous color branch) --- src/colors.ts | 9 +++++++++ src/controllers/analytic_controller.ts | 7 ++++++- src/models/analytic_unit.ts | 7 +++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/colors.ts b/src/colors.ts index e63c031..7cebdcd 100644 --- a/src/colors.ts +++ b/src/colors.ts @@ -68,6 +68,15 @@ let colors = [ '#DEDAF7', ]; +export const ANALYTIC_UNIT_COLORS = [ + '#FF99FF', + '#71b1f9', + '#aee9fb', + '#9ce677', + '#f88990', + '#f9e26e', + '#f8c171', +]; export function hexToHsl(color) { return tinycolor(color).toHsl(); diff --git a/src/controllers/analytic_controller.ts b/src/controllers/analytic_controller.ts index 0e2ae45..346a9db 100644 --- a/src/controllers/analytic_controller.ts +++ b/src/controllers/analytic_controller.ts @@ -14,6 +14,7 @@ import { SegmentArray } from '../models/segment_array'; import { Emitter } from 'grafana/app/core/utils/emitter' +import { ANALYTIC_UNIT_COLORS } from '../colors'; import _ from 'lodash'; @@ -35,6 +36,7 @@ export class AnalyticController { private _savingNewAnalyticUnit: boolean = false; private _tempIdCounted = -1; private _graphLocked = false; + private _currentColorIndex = 0; private _statusRunners: Set = new Set(); @@ -47,6 +49,7 @@ export class AnalyticController { this._labelingDataDeletedSegments = new SegmentArray(); 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 { @@ -65,9 +68,11 @@ export class AnalyticController { } createNew() { - this._newAnalyticUnit = new AnalyticUnit(); + this._newAnalyticUnit = new AnalyticUnit(undefined, ANALYTIC_UNIT_COLORS[this._currentColorIndex]); this._creatingNewAnalyticType = true; this._savingNewAnalyticUnit = false; + this._currentColorIndex++; + this._currentColorIndex %= ANALYTIC_UNIT_COLORS.length; } async saveNew(metricExpanded: MetricExpanded, datasourceRequest: DatasourceRequest, panelId: number) { diff --git a/src/models/analytic_unit.ts b/src/models/analytic_unit.ts index 2a1bf07..6d22321 100644 --- a/src/models/analytic_unit.ts +++ b/src/models/analytic_unit.ts @@ -3,7 +3,9 @@ import { SegmentArray } from './segment_array'; import { Segment, SegmentId } from './segment'; import { Metric } from './metric'; +import { ANALYTIC_UNIT_COLORS } from '../colors'; import _ from 'lodash'; +import { AnalyticController } from 'controllers/analytic_controller'; export type AnalyticSegmentPair = { anomalyType: AnalyticUnit, segment: AnalyticSegment }; @@ -29,15 +31,16 @@ export class AnalyticUnit { private _status: string; private _error: string; private _metric: Metric; + private _color: string; private _alertEnabled?: boolean; - constructor(private _panelObject?: any) { + constructor(private _panelObject?: any, color?: string) { if(_panelObject === undefined) { this._panelObject = {}; } _.defaults(this._panelObject, { - name: 'AnalyticUnitName', confidence: 0.2, color: 'red', type: 'general' + name: 'AnalyticUnitName', confidence: 0.2, color, type: 'general' }); //this._metric = new Metric(_panelObject.metric); From acc2a5724ada3f0ae707fe68a0c0957f96e045d4 Mon Sep 17 00:00:00 2001 From: sanke Date: Fri, 13 Jul 2018 16:54:38 +0300 Subject: [PATCH 2/6] remove unneeded lines according to PR review add type to some fields --- src/controllers/analytic_controller.ts | 6 +++--- src/models/analytic_unit.ts | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/controllers/analytic_controller.ts b/src/controllers/analytic_controller.ts index 346a9db..8348f9e 100644 --- a/src/controllers/analytic_controller.ts +++ b/src/controllers/analytic_controller.ts @@ -34,9 +34,9 @@ export class AnalyticController { private _newAnalyticUnit: AnalyticUnit = null; private _creatingNewAnalyticType: boolean = false; private _savingNewAnalyticUnit: boolean = false; - private _tempIdCounted = -1; - private _graphLocked = false; - private _currentColorIndex = 0; + private _tempIdCounted: number = -1; + private _graphLocked: boolean = false; + private _currentColorIndex: number = 0; private _statusRunners: Set = new Set(); diff --git a/src/models/analytic_unit.ts b/src/models/analytic_unit.ts index 6d22321..301e19a 100644 --- a/src/models/analytic_unit.ts +++ b/src/models/analytic_unit.ts @@ -3,9 +3,7 @@ import { SegmentArray } from './segment_array'; import { Segment, SegmentId } from './segment'; import { Metric } from './metric'; -import { ANALYTIC_UNIT_COLORS } from '../colors'; import _ from 'lodash'; -import { AnalyticController } from 'controllers/analytic_controller'; export type AnalyticSegmentPair = { anomalyType: AnalyticUnit, segment: AnalyticSegment }; @@ -31,7 +29,6 @@ export class AnalyticUnit { private _status: string; private _error: string; private _metric: Metric; - private _color: string; private _alertEnabled?: boolean; From 75eb6a610ddd48aca3612512dfe2b508810e51de Mon Sep 17 00:00:00 2001 From: sanke Date: Fri, 13 Jul 2018 17:40:54 +0300 Subject: [PATCH 3/6] remove passed variable use property instead --- src/controllers/analytic_controller.ts | 3 ++- src/models/analytic_unit.ts | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controllers/analytic_controller.ts b/src/controllers/analytic_controller.ts index 8348f9e..499f2ac 100644 --- a/src/controllers/analytic_controller.ts +++ b/src/controllers/analytic_controller.ts @@ -68,9 +68,10 @@ export class AnalyticController { } createNew() { - this._newAnalyticUnit = new AnalyticUnit(undefined, ANALYTIC_UNIT_COLORS[this._currentColorIndex]); + 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; } diff --git a/src/models/analytic_unit.ts b/src/models/analytic_unit.ts index 301e19a..ba5a4a5 100644 --- a/src/models/analytic_unit.ts +++ b/src/models/analytic_unit.ts @@ -4,6 +4,7 @@ import { Segment, SegmentId } from './segment'; import { Metric } from './metric'; import _ from 'lodash'; +import { ANALYTIC_UNIT_COLORS } from '../colors'; export type AnalyticSegmentPair = { anomalyType: AnalyticUnit, segment: AnalyticSegment }; @@ -32,12 +33,12 @@ export class AnalyticUnit { private _alertEnabled?: boolean; - constructor(private _panelObject?: any, color?: string) { + constructor(private _panelObject?: any) { if(_panelObject === undefined) { this._panelObject = {}; } _.defaults(this._panelObject, { - name: 'AnalyticUnitName', confidence: 0.2, color, type: 'general' + name: 'AnalyticUnitName', confidence: 0.2, color: ANALYTIC_UNIT_COLORS[0], type: 'general' }); //this._metric = new Metric(_panelObject.metric); From 8cb6e29a17ae08e99273e60a5d7061e86c2ded31 Mon Sep 17 00:00:00 2001 From: sanke Date: Fri, 13 Jul 2018 17:42:59 +0300 Subject: [PATCH 4/6] add one more line below color import --- src/controllers/analytic_controller.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controllers/analytic_controller.ts b/src/controllers/analytic_controller.ts index 499f2ac..0f3b27b 100644 --- a/src/controllers/analytic_controller.ts +++ b/src/controllers/analytic_controller.ts @@ -15,6 +15,7 @@ import { SegmentArray } from '../models/segment_array'; import { Emitter } from 'grafana/app/core/utils/emitter' import { ANALYTIC_UNIT_COLORS } from '../colors'; + import _ from 'lodash'; From d80ff132e869f1d89c37e56aa224410e9c9eb1a3 Mon Sep 17 00:00:00 2001 From: sanke Date: Fri, 13 Jul 2018 17:44:18 +0300 Subject: [PATCH 5/6] move import { Emitter } below colors import --- src/controllers/analytic_controller.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/analytic_controller.ts b/src/controllers/analytic_controller.ts index 0f3b27b..813dabc 100644 --- a/src/controllers/analytic_controller.ts +++ b/src/controllers/analytic_controller.ts @@ -12,10 +12,10 @@ import { Segment, SegmentId } from '../models/segment'; import { SegmentsSet } from '../models/segment_set'; import { SegmentArray } from '../models/segment_array'; -import { Emitter } from 'grafana/app/core/utils/emitter' - import { ANALYTIC_UNIT_COLORS } from '../colors'; +import { Emitter } from 'grafana/app/core/utils/emitter'; + import _ from 'lodash'; From c5556bc436875cc11998f1e9ea0eb9b146a190d5 Mon Sep 17 00:00:00 2001 From: sanke Date: Fri, 13 Jul 2018 17:49:14 +0300 Subject: [PATCH 6/6] move import from lodash below colors --- src/models/analytic_unit.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/models/analytic_unit.ts b/src/models/analytic_unit.ts index ba5a4a5..7ae6a5d 100644 --- a/src/models/analytic_unit.ts +++ b/src/models/analytic_unit.ts @@ -3,9 +3,10 @@ import { SegmentArray } from './segment_array'; import { Segment, SegmentId } from './segment'; import { Metric } from './metric'; -import _ from 'lodash'; import { ANALYTIC_UNIT_COLORS } from '../colors'; +import _ from 'lodash'; + export type AnalyticSegmentPair = { anomalyType: AnalyticUnit, segment: AnalyticSegment }; export type AnalyticSegmentsSearcher = (point: number, rangeDist: number) => AnalyticSegmentPair[];