Skip to content

Commit 36fc3fc

Browse files
author
mbrill-nt
committed
Graph now updates on settings change with grafana setting modules
1 parent ba90798 commit 36fc3fc

File tree

8 files changed

+28
-76
lines changed

8 files changed

+28
-76
lines changed

src/options/DefaultSettings.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ export const DefaultSettings: PanelSettings = {
2323
showDummyData: false,
2424
},
2525

26-
sumTimings: { value: true },
27-
filterEmptyConnections: { value: true },
28-
showDebugInformation: { value: false },
29-
showConnectionStats: { value: true },
30-
showBaselines: { value: false },
26+
sumTimings: true,
27+
filterEmptyConnections: true,
28+
showDebugInformation: false,
29+
showConnectionStats: true,
30+
showBaselines: false,
3131

3232
style: {
3333
healthyColor: 'rgb(87, 148, 242)',

src/options/genericDataSwitch/GenericDataSwitch.tsx

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/options/options.tsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { TypeaheadTextField } from './TypeAheadTextfield/TypeaheadTextfield';
44
import { ServiceIconMapping } from './serviceIconMapping/ServiceIconMapping';
55
import { ExternalIconMapping } from './externalIconMapping/ExternalIconMapping';
66
import { DummyDataSwitch } from './dummyDataSwitch/DummyDataSwitch';
7-
import { GenericDataSwitch } from './genericDataSwitch/GenericDataSwitch';
87
import { DefaultSettings } from './DefaultSettings';
98

109
export const optionsBuilder = (builder: PanelOptionsEditorBuilder<PanelSettings>) => {
@@ -122,20 +121,16 @@ export const optionsBuilder = (builder: PanelOptionsEditorBuilder<PanelSettings>
122121
})
123122

124123
//General Settings
125-
.addCustomEditor({
126-
id: 'connectionStats',
124+
.addBooleanSwitch({
127125
path: 'showConnectionStats',
128126
name: 'Show Connection Statistics',
129-
editor: GenericDataSwitch,
130127
category: ['General Settings'],
131128
defaultValue: DefaultSettings.showConnectionStats,
132129
})
133130

134-
.addCustomEditor({
135-
id: 'sumTimings',
131+
.addBooleanSwitch({
136132
path: 'sumTimings',
137133
name: 'Handle Timings as Sums',
138-
editor: GenericDataSwitch,
139134
description:
140135
'If this setting is active, the timings provided' +
141136
'by the mapped response time columns are considered as a ' +
@@ -146,11 +141,9 @@ export const optionsBuilder = (builder: PanelOptionsEditorBuilder<PanelSettings>
146141
defaultValue: DefaultSettings.sumTimings,
147142
})
148143

149-
.addCustomEditor({
150-
id: 'filterEmptyConnections',
144+
.addBooleanSwitch({
151145
path: 'filterEmptyConnections',
152146
name: 'Filter Empty Data',
153-
editor: GenericDataSwitch,
154147
description:
155148
'If this setting is active, the timings provided by ' +
156149
'the mapped response time columns are considered as a continually ' +
@@ -160,11 +153,9 @@ export const optionsBuilder = (builder: PanelOptionsEditorBuilder<PanelSettings>
160153
defaultValue: DefaultSettings.filterEmptyConnections,
161154
})
162155

163-
.addCustomEditor({
164-
id: 'showDebugInformation',
156+
.addBooleanSwitch({
165157
path: 'showDebugInformation',
166158
name: 'Show Debug Information',
167-
editor: GenericDataSwitch,
168159
category: ['General Settings'],
169160
defaultValue: DefaultSettings.showDebugInformation,
170161
})
@@ -178,11 +169,9 @@ export const optionsBuilder = (builder: PanelOptionsEditorBuilder<PanelSettings>
178169
defaultValue: DefaultSettings.dataMapping,
179170
})
180171

181-
.addCustomEditor({
182-
id: 'showBaselines',
172+
.addBooleanSwitch({
183173
path: 'showBaselines',
184174
name: 'Show Baselines',
185-
editor: GenericDataSwitch,
186175
category: ['General Settings'],
187176
defaultValue: DefaultSettings.showBaselines,
188177
})

src/panel/ServiceDependencyGraphPanelController.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class ServiceDependencyGraphPanelController extends PureComponent<Props,
5353
}
5454

5555
getSettings(): PanelSettings {
56-
return this.state.options;
56+
return this.props.options;
5757
}
5858

5959
componentDidUpdate() {
@@ -186,7 +186,7 @@ export class ServiceDependencyGraphPanelController extends PureComponent<Props,
186186
}
187187

188188
render() {
189-
this.processData();
189+
const data = this.processData();
190190
const error = this.getError();
191191
var panel = <div>{error}</div>;
192192
if (error === null) {
@@ -199,7 +199,7 @@ export class ServiceDependencyGraphPanelController extends PureComponent<Props,
199199
id="cy"
200200
>
201201
<ServiceDependencyGraph
202-
data={this.processData()}
202+
data={data}
203203
zoom={1}
204204
controller={this}
205205
animate={false}

src/panel/canvas/graph_canvas.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export default class CanvasDrawer {
229229
// static element rendering
230230
// cyCanvas.resetTransform(ctx);
231231
cyCanvas.clear(ctx);
232-
if (this.controller.getSettings().showDebugInformation.value) {
232+
if (this.controller.getSettings().showDebugInformation) {
233233
this._drawDebugInformation();
234234
}
235235

@@ -278,7 +278,7 @@ export default class CanvasDrawer {
278278
}
279279

280280
const { showConnectionStats } = this.controller.getSettings();
281-
if (showConnectionStats.value && cy.zoom() > 1) {
281+
if (showConnectionStats && cy.zoom() > 1) {
282282
for (const edge of edges) {
283283
this._drawEdgeLabel(ctx, edge);
284284
}
@@ -510,7 +510,7 @@ export default class CanvasDrawer {
510510
this._drawDonut(ctx, node, 15, 5, 0.5, [errorPct, unknownPct, healthyPct]);
511511

512512
// drawing the baseline status
513-
const showBaselines = this.controller.getSettings().showBaselines.value;
513+
const {showBaselines} = this.controller.getSettings();
514514
if (showBaselines && responseTime >= 0 && threshold >= 0) {
515515
const thresholdViolation = threshold < responseTime;
516516

@@ -573,11 +573,7 @@ export default class CanvasDrawer {
573573
if (responseTime >= 0) {
574574
const decimals = responseTime >= 1000 ? 1 : 0;
575575

576-
var labelText = 'Avg. Resp. Time: ';
577-
if (this.controller.getSettings().sumTimings.value) {
578-
labelText = 'Total Resp. Time: ';
579-
}
580-
lines.push(labelText + humanFormat(responseTime, { scale: timeScale, decimals }));
576+
lines.push('Avg. Resp. Time: ' + humanFormat(responseTime, { scale: timeScale, decimals }));
581577
}
582578

583579
const pos = node.position();
@@ -679,7 +675,7 @@ export default class CanvasDrawer {
679675
const xPos = pos.x - labelWidth / 2;
680676
const yPos = pos.y + node.height() * 0.8;
681677

682-
const showBaselines = this.controller.getSettings().showBaselines.value;
678+
const {showBaselines} = this.controller.getSettings();
683679
const metrics: IntGraphMetrics = node.data('metrics');
684680
const responseTime = _.defaultTo(metrics.response_time, -1);
685681
const threshold = _.defaultTo(metrics.threshold, -1);

src/panel/serviceDependencyGraph/ServiceDependencyGraph.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export class ServiceDependencyGraph extends PureComponent<PanelState, PanelState
140140
this.runLayout(true);
141141
}
142142
}
143+
this.state.graphCanvas.repaint(true);
143144
}
144145

145146
_transformNodes(nodes: IntGraphNode[]): ElementDefinition[] {

src/processing/graph_generator.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class GraphGenerator {
3838
return undefined;
3939
}
4040

41-
const sumMetrics = !this.controller.getSettings().sumTimings.value;
41+
const sumMetrics = !this.controller.getSettings().sumTimings;
4242

4343
var nodeName = dataElements[0].target;
4444
if (nodeName === '' || nodeName === undefined || nodeName === null) {
@@ -62,6 +62,7 @@ class GraphGenerator {
6262
};
6363

6464
const aggregationFunction = sumMetrics ? sum : mean;
65+
6566
if (internalNode) {
6667
metrics.rate = sum(map(dataElements, element => element.data.rate_in));
6768
metrics.error_rate = sum(map(dataElements, element => element.data.error_rate_in));
@@ -201,7 +202,7 @@ class GraphGenerator {
201202
if (!isUndefined(response_time_out)) {
202203
const { sumTimings } = this.controller.getSettings();
203204

204-
if (!sumTimings.value && metrics.rate) {
205+
if (!sumTimings && metrics.rate) {
205206
metrics.response_time = response_time_out / metrics.rate;
206207
} else {
207208
metrics.response_time = response_time_out;
@@ -224,7 +225,7 @@ class GraphGenerator {
224225
_filterData(graph: IntGraph): IntGraph {
225226
const { filterEmptyConnections: filterData } = this.controller.getSettings();
226227

227-
if (filterData.value) {
228+
if (filterData) {
228229
const filteredGraph: IntGraph = {
229230
nodes: [],
230231
edges: [],

src/types.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
export interface PanelSettings {
22
animate: boolean;
3-
sumTimings: IntSwitch;
4-
filterEmptyConnections: IntSwitch;
3+
sumTimings: boolean;
4+
filterEmptyConnections: boolean;
55
style: PanelStyleSettings;
6-
showDebugInformation: IntSwitch;
7-
showConnectionStats: IntSwitch;
6+
showDebugInformation: boolean;
7+
showConnectionStats: boolean;
88
externalIcons: ExternalIconResource[];
99
serviceIcons: IconResource[];
1010
dataMapping: DataMapping;
1111
drillDownLink: string;
12-
showBaselines: IntSwitch;
12+
showBaselines: boolean;
1313
timeFormat: string;
1414
}
1515

@@ -188,7 +188,3 @@ export interface IntTableHeader {
188188
sortFunc?: any;
189189
ignoreLiteral?: string;
190190
}
191-
192-
export interface IntSwitch {
193-
value: boolean;
194-
}

0 commit comments

Comments
 (0)