Skip to content

Commit be6ac4a

Browse files
[FEATURE] Add interactive legend into charts opensearch-project#199 (opensearch-project#226)
* [FEATURE] Add interactive legend into charts opensearch-project#199 Signed-off-by: Jovan Cvetkovic <[email protected]> * Fix cypress test Signed-off-by: Jovan Cvetkovic <[email protected]> Signed-off-by: Jovan Cvetkovic <[email protected]>
1 parent 3dc90dd commit be6ac4a

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

cypress/integration/4_findings.spec.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,21 @@ describe('Findings', () => {
135135
// Click on detector to be removed
136136
cy.contains('sample_detector').click({ force: true }, { timeout: 2000 });
137137

138-
// Click "Actions" button, the click "Delete"
139-
cy.get('button').contains('Actions').click({ force: true }, { timeout: 2000 });
140-
cy.contains('Delete').click({ force: true });
141-
142-
// Search for sample_detector, presumably deleted
143-
cy.get(`[placeholder="Search threat detectors"]`).type('sample_detector').trigger('search');
138+
cy.url().should('include', 'opensearch_security_analytics_dashboards#/detector-details');
144139

145-
// Confirm sample_detector no longer exists
146-
cy.contains('There are no existing detectors.');
140+
// Click "Actions" button, the click "Delete"
141+
cy.get('button')
142+
.contains('Actions')
143+
.click({ force: true }, { timeout: 2000 })
144+
.then(() => {
145+
// Confirm arrival at detectors page
146+
cy.contains('Delete').click({ force: true });
147+
148+
// Search for sample_detector, presumably deleted
149+
cy.get(`[placeholder="Search threat detectors"]`).type('sample_detector').trigger('search');
150+
151+
// Confirm sample_detector no longer exists
152+
cy.contains('There are no existing detectors.');
153+
});
147154
});
148155
});

public/pages/Overview/utils/helpers.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ export type DateOpts = {
1616
dateFormat: string;
1717
};
1818

19+
/**
20+
* Legend selection config for the chart layer
21+
*/
22+
const legendSelectionCfg = {
23+
selection: {
24+
series: {
25+
type: 'multi',
26+
encodings: ['color'],
27+
on: 'click',
28+
bind: 'legend',
29+
},
30+
},
31+
encoding: {
32+
opacity: {
33+
condition: { selection: 'series', value: 1 },
34+
value: 0.2,
35+
},
36+
},
37+
};
38+
39+
/**
40+
* Adds interactive legends to the chart layer
41+
* @param layer
42+
*/
43+
const addInteractiveLegends = (layer: any) => _.defaultsDeep(layer, legendSelectionCfg);
44+
1945
function getVisualizationSpec(description: string, data: any, layers: any[]): TopLevelSpec {
2046
return {
2147
config: {
@@ -84,10 +110,10 @@ export function getOverviewVisualizationSpec(
84110
'Plot showing average data with raw values in the background.',
85111
visualizationData,
86112
[
87-
{
113+
addInteractiveLegends({
88114
mark: 'bar',
89115
encoding: findingsEncoding,
90-
},
116+
}),
91117
{
92118
mark: {
93119
type: 'line',
@@ -163,7 +189,7 @@ export function getFindingsVisualizationSpec(
163189
}
164190
) {
165191
return getVisualizationSpec('Findings data overview', visualizationData, [
166-
{
192+
addInteractiveLegends({
167193
mark: 'bar',
168194
encoding: {
169195
tooltip: [{ field: 'finding', aggregate: 'sum', type: 'quantitative', title: 'Findings' }],
@@ -192,7 +218,7 @@ export function getFindingsVisualizationSpec(
192218
},
193219
},
194220
},
195-
},
221+
}),
196222
]);
197223
}
198224

@@ -205,7 +231,7 @@ export function getAlertsVisualizationSpec(
205231
}
206232
) {
207233
return getVisualizationSpec('Alerts data overview', visualizationData, [
208-
{
234+
addInteractiveLegends({
209235
mark: 'bar',
210236
encoding: {
211237
tooltip: [{ field: 'alert', aggregate: 'sum', title: 'Alerts' }],
@@ -235,7 +261,7 @@ export function getAlertsVisualizationSpec(
235261
},
236262
},
237263
},
238-
},
264+
}),
239265
]);
240266
}
241267

0 commit comments

Comments
 (0)