From cfeade4f6e79b6e053f90e86c6004e9c4dcea00d Mon Sep 17 00:00:00 2001 From: sanke Date: Fri, 13 Jul 2018 16:08:40 +0300 Subject: [PATCH] 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);