Skip to content

Commit

Permalink
[FEATURE] Add interactive legend into charts opensearch-project#199 (o…
Browse files Browse the repository at this point in the history
…pensearch-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]>
  • Loading branch information
jovancvetkovic3006 authored Dec 19, 2022
1 parent 3dc90dd commit be6ac4a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
23 changes: 15 additions & 8 deletions cypress/integration/4_findings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,21 @@ describe('Findings', () => {
// Click on detector to be removed
cy.contains('sample_detector').click({ force: true }, { timeout: 2000 });

// Click "Actions" button, the click "Delete"
cy.get('button').contains('Actions').click({ force: true }, { timeout: 2000 });
cy.contains('Delete').click({ force: true });

// Search for sample_detector, presumably deleted
cy.get(`[placeholder="Search threat detectors"]`).type('sample_detector').trigger('search');
cy.url().should('include', 'opensearch_security_analytics_dashboards#/detector-details');

// Confirm sample_detector no longer exists
cy.contains('There are no existing detectors.');
// Click "Actions" button, the click "Delete"
cy.get('button')
.contains('Actions')
.click({ force: true }, { timeout: 2000 })
.then(() => {
// Confirm arrival at detectors page
cy.contains('Delete').click({ force: true });

// Search for sample_detector, presumably deleted
cy.get(`[placeholder="Search threat detectors"]`).type('sample_detector').trigger('search');

// Confirm sample_detector no longer exists
cy.contains('There are no existing detectors.');
});
});
});
38 changes: 32 additions & 6 deletions public/pages/Overview/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,32 @@ export type DateOpts = {
dateFormat: string;
};

/**
* Legend selection config for the chart layer
*/
const legendSelectionCfg = {
selection: {
series: {
type: 'multi',
encodings: ['color'],
on: 'click',
bind: 'legend',
},
},
encoding: {
opacity: {
condition: { selection: 'series', value: 1 },
value: 0.2,
},
},
};

/**
* Adds interactive legends to the chart layer
* @param layer
*/
const addInteractiveLegends = (layer: any) => _.defaultsDeep(layer, legendSelectionCfg);

function getVisualizationSpec(description: string, data: any, layers: any[]): TopLevelSpec {
return {
config: {
Expand Down Expand Up @@ -84,10 +110,10 @@ export function getOverviewVisualizationSpec(
'Plot showing average data with raw values in the background.',
visualizationData,
[
{
addInteractiveLegends({
mark: 'bar',
encoding: findingsEncoding,
},
}),
{
mark: {
type: 'line',
Expand Down Expand Up @@ -163,7 +189,7 @@ export function getFindingsVisualizationSpec(
}
) {
return getVisualizationSpec('Findings data overview', visualizationData, [
{
addInteractiveLegends({
mark: 'bar',
encoding: {
tooltip: [{ field: 'finding', aggregate: 'sum', type: 'quantitative', title: 'Findings' }],
Expand Down Expand Up @@ -192,7 +218,7 @@ export function getFindingsVisualizationSpec(
},
},
},
},
}),
]);
}

Expand All @@ -205,7 +231,7 @@ export function getAlertsVisualizationSpec(
}
) {
return getVisualizationSpec('Alerts data overview', visualizationData, [
{
addInteractiveLegends({
mark: 'bar',
encoding: {
tooltip: [{ field: 'alert', aggregate: 'sum', title: 'Alerts' }],
Expand Down Expand Up @@ -235,7 +261,7 @@ export function getAlertsVisualizationSpec(
},
},
},
},
}),
]);
}

Expand Down

0 comments on commit be6ac4a

Please sign in to comment.