Skip to content

Commit

Permalink
Address couples of feedback. Issue: opendistro-for-elasticsearch#26, o…
Browse files Browse the repository at this point in the history
  • Loading branch information
yizheliu-amazon committed Apr 24, 2020
1 parent ab94bdf commit 914b5b1
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 255 deletions.
6 changes: 4 additions & 2 deletions public/components/ContentPanel/ContentPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ type ContentPanelProps = {
titleContainerStyles?: React.CSSProperties;
actions?: React.ReactNode | React.ReactNode[];
children: React.ReactNode | React.ReactNode[];
contentPanelClassName?: string;
};

const ContentPanel = (props: ContentPanelProps) => (
<EuiPanel
style={{ paddingLeft: '0px', paddingRight: '0px', ...props.panelStyles }}
className={props.contentPanelClassName}
>
<EuiFlexGroup
style={{ padding: '0px 10px', ...props.titleContainerStyles }}
style={{ padding: '0px 20px', ...props.titleContainerStyles }}
justifyContent="spaceBetween"
alignItems="center"
>
Expand Down Expand Up @@ -105,7 +107,7 @@ const ContentPanel = (props: ContentPanelProps) => (
className={props.horizontalRuleClassName}
/>
)}
<div style={{ padding: '0px 10px', ...props.bodyStyles }}>
<div style={{ padding: '0px 20px', ...props.bodyStyles }}>
{props.children}
</div>
</EuiPanel>
Expand Down
3 changes: 1 addition & 2 deletions public/components/ContentPanel/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
*/

.content-panel-title {
color: #3f3f3f;
color: #000;
}

.content-panel-subTitle {
color: #879196;
font-family: 'Helvetica Neue';
font-size: 12px;
letter-spacing: 0;
}
147 changes: 75 additions & 72 deletions public/pages/Dashboard/Components/AnomaliesDistribution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import { useDispatch } from 'react-redux';
import { Datum } from '@elastic/charts/dist/utils/commons';
import React from 'react';
import { TIME_RANGE_OPTIONS } from '../../Dashboard/utils/constants';
import { get } from 'lodash';
import { get, isEmpty } from 'lodash';
import { searchES } from '../../../redux/reducers/elasticsearch';
import { MAX_DETECTORS } from '../../../utils/constants';
import { MAX_DETECTORS, MAX_ANOMALIES } from '../../../utils/constants';
import { AD_DOC_FIELDS } from '../../../../server/utils/constants';
export interface AnomaliesDistributionChartProps {
allDetectorsSelected: boolean;
Expand Down Expand Up @@ -64,17 +64,23 @@ export const AnomaliesDistributionChart = (
const [timeRange, setTimeRange] = useState(TIME_RANGE_OPTIONS[0].value);

const getAnomalyResult = async (currentDetectors: DetectorListItem[]) => {
const finalAnomalyResult = await getLatestAnomalyResultsForDetectorsByTimeRange(
const latestAnomalyResult = await getLatestAnomalyResultsForDetectorsByTimeRange(
searchES,
props.selectedDetectors,
timeRange,
MAX_DETECTORS,
dispatch
dispatch,
0,
MAX_ANOMALIES,
MAX_DETECTORS
);
setAnomalyResults(finalAnomalyResult);

const nonZeroAnomalyResult = latestAnomalyResult.filter(
anomalyData => get(anomalyData, AD_DOC_FIELDS.ANOMALY_GRADE, 0) > 0
);
setAnomalyResults(nonZeroAnomalyResult);

const resultDetectors = getFinalDetectors(
finalAnomalyResult,
nonZeroAnomalyResult,
props.selectedDetectors
);
setIndicesNumber(getFinalIndices(resultDetectors).size);
Expand Down Expand Up @@ -123,9 +129,8 @@ export const AnomaliesDistributionChart = (
<EuiFlexItem>
<EuiText className={'anomaly-distribution-subtitle'}>
<p>
{
'The inner circle shows the anomaly distribution by your indices. The outer circle shows the anomaly distribution by your detector'
}
{'The inner circle shows the anomaly distribution by your indices. ' +
'The outer circle shows the anomaly distribution by your detectors.'}
</p>
</EuiText>
</EuiFlexItem>
Expand All @@ -141,13 +146,14 @@ export const AnomaliesDistributionChart = (
/>
}
>
<EuiFlexGroup style={{ padding: '10px' }}>
<EuiFlexGroup style={{ marginTop: '0px' }}>
<EuiFlexItem>
<EuiStat
description={'Indices with anomalies'}
title={indicesNumber}
isLoading={anomalyResultsLoading}
titleSize="s"
style={{ color: '#000' }}
/>
</EuiFlexItem>
<EuiFlexItem>
Expand All @@ -156,85 +162,82 @@ export const AnomaliesDistributionChart = (
title={finalDetectors.length}
isLoading={anomalyResultsLoading}
titleSize="s"
style={{ color: '#000' }}
/>
</EuiFlexItem>
</EuiFlexGroup>
{anomalyResultsLoading ? (
<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<EuiLoadingChart size="m" />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiLoadingChart size="l" />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiLoadingChart size="xl" />
</EuiFlexItem>
</EuiFlexGroup>
) : (
<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<Chart className="anomalies-distribution-sunburst">
<Partition
id="Anomalies by index and detector"
data={visualizeAnomalyResultForSunburstChart(
anomalyResults,
finalDetectors
)}
valueAccessor={(d: Datum) => d.count as number}
valueFormatter={(d: number) => d.toString()}
layers={[
{
groupByRollup: (d: Datum) => d.indices,
nodeLabel: (d: Datum) => {
return d;
},
fillLabel: {
textInvertible: true,
},
shape: {
fillColor: d => {
return fillOutColors(
d,
(d.x0 + d.x1) / 2 / (2 * Math.PI),
[]
);
{isEmpty(anomalyResults) ? null : (
<Chart className="anomalies-distribution-sunburst">
<Partition
id="Anomalies by index and detector"
data={visualizeAnomalyResultForSunburstChart(
anomalyResults,
finalDetectors
)}
valueAccessor={(d: Datum) => d.count as number}
valueFormatter={(d: number) => d.toString()}
layers={[
{
groupByRollup: (d: Datum) => d.indices,
nodeLabel: (d: Datum) => {
return d;
},
fillLabel: {
textInvertible: true,
},
shape: {
fillColor: d => {
return fillOutColors(
d,
(d.x0 + d.x1) / 2 / (2 * Math.PI),
[]
);
},
},
},
},
{
groupByRollup: (d: Datum) => d.name,
nodeLabel: (d: Datum) => {
return d;
{
groupByRollup: (d: Datum) => d.name,
nodeLabel: (d: Datum) => {
return d;
},
fillLabel: {
textInvertible: true,
},
shape: {
fillColor: d => {
return fillOutColors(
d,
(d.x0 + d.x1) / 2 / (2 * Math.PI),
[]
);
},
},
},
]}
config={{
partitionLayout: PartitionLayout.sunburst,
fontFamily: 'Arial',
outerSizeRatio: 1,
fillLabel: {
textInvertible: true,
},
shape: {
fillColor: d => {
return fillOutColors(
d,
(d.x0 + d.x1) / 2 / (2 * Math.PI),
[]
);
},
},
},
]}
config={{
partitionLayout: PartitionLayout.sunburst,
fontFamily: 'Arial',
outerSizeRatio: 1,
fillLabel: {
textInvertible: true,
},
// TODO: Given only 1 detector exists, the inside Index circle will have issue in following scenarios:
// 1: if Linked Label is configured for identifying index, label of Index circle will be invisible;
// 2: if Fill Label is configured for identifying index, label of it will be overlapped with outer Detector circle
// Issue link: https://github.com/opendistro-for-elasticsearch/anomaly-detection-kibana-plugin/issues/24
}}
/>
</Chart>
// TODO: Given only 1 detector exists, the inside Index circle will have issue in following scenarios:
// 1: if Linked Label is configured for identifying index, label of Index circle will be invisible;
// 2: if Fill Label is configured for identifying index, label of it will be overlapped with outer Detector circle
// Issue link: https://github.com/opendistro-for-elasticsearch/anomaly-detection-kibana-plugin/issues/24
}}
/>
</Chart>
)}
</EuiFlexItem>
</EuiFlexGroup>
)}
Expand Down
Loading

0 comments on commit 914b5b1

Please sign in to comment.