-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [ML] Convert Explorer Influencers List to EUI/React * [ML] Remove unused abbreviate_whole_number Angular filter * [ML] Convert React Influencers List to stateless function
- Loading branch information
1 parent
a77e2bf
commit 375f5f1
Showing
8 changed files
with
208 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,5 @@ | |
*/ | ||
|
||
|
||
|
||
|
||
import './influencers_list_directive'; | ||
import './styles/main.less'; |
51 changes: 0 additions & 51 deletions
51
x-pack/plugins/ml/public/components/influencers_list/influencers_list.html
This file was deleted.
Oops, something went wrong.
150 changes: 150 additions & 0 deletions
150
x-pack/plugins/ml/public/components/influencers_list/influencers_list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
/* | ||
* React component for rendering a list of Machine Learning influencers. | ||
*/ | ||
|
||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiSpacer, | ||
EuiText, | ||
EuiTitle, | ||
EuiToolTip | ||
} from '@elastic/eui'; | ||
|
||
import { abbreviateWholeNumber } from 'plugins/ml/formatters/abbreviate_whole_number'; | ||
import { getSeverity } from 'plugins/ml/util/anomaly_utils'; | ||
|
||
|
||
function getTooltipContent(maxScoreLabel, totalScoreLabel) { | ||
return ( | ||
<React.Fragment> | ||
<p>Maximum anomaly score: {maxScoreLabel}</p> | ||
<p>Total anomaly score: {totalScoreLabel}</p> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
function Influencer({ influencerFieldName, valueData }) { | ||
const maxScorePrecise = valueData.maxAnomalyScore; | ||
const maxScore = parseInt(maxScorePrecise); | ||
const maxScoreLabel = (maxScore !== 0) ? maxScore : '< 1'; | ||
const severity = getSeverity(maxScore); | ||
const totalScore = parseInt(valueData.sumAnomalyScore); | ||
const totalScoreLabel = (totalScore !== 0) ? totalScore : '< 1'; | ||
|
||
// Ensure the bar has some width for 0 scores. | ||
const barScore = (maxScore !== 0) ? maxScore : 1; | ||
const barStyle = { | ||
width: `${barScore}%` | ||
}; | ||
|
||
const tooltipContent = getTooltipContent(maxScoreLabel, totalScoreLabel); | ||
|
||
return ( | ||
<div> | ||
<div className="field-label"> | ||
{(influencerFieldName !== 'mlcategory') ? ( | ||
<div className="field-value">{valueData.influencerFieldValue}</div> | ||
) : ( | ||
<div className="field-value">mlcategory {valueData.influencerFieldValue}</div> | ||
)} | ||
</div> | ||
<div className={`progress ${severity}`} value="{valueData.maxAnomalyScore}" max="100"> | ||
<div className="progress-bar-holder"> | ||
<div className="progress-bar" style={barStyle}/> | ||
</div> | ||
<div className="score-label"> | ||
<EuiToolTip | ||
position="right" | ||
className="ml-influencers-list-tooltip" | ||
title={`${influencerFieldName}: ${valueData.influencerFieldValue}`} | ||
content={tooltipContent} | ||
> | ||
<span>{maxScoreLabel}</span> | ||
</EuiToolTip> | ||
</div> | ||
</div> | ||
<div className="total-score-label"> | ||
<EuiToolTip | ||
position="right" | ||
className="ml-influencers-list-tooltip" | ||
title={`${influencerFieldName}: ${valueData.influencerFieldValue}`} | ||
content={tooltipContent} | ||
> | ||
<span>{(totalScore > 0) ? abbreviateWholeNumber(totalScore, 4) : totalScoreLabel}</span> | ||
</EuiToolTip> | ||
</div> | ||
</div> | ||
); | ||
} | ||
Influencer.propTypes = { | ||
influencerFieldName: PropTypes.string.isRequired, | ||
valueData: PropTypes.object.isRequired | ||
}; | ||
|
||
function InfluencersByName({ influencerFieldName, fieldValues }) { | ||
const influencerValues = fieldValues.map(valueData => ( | ||
<Influencer | ||
key={valueData.influencerFieldValue} | ||
influencerFieldName={influencerFieldName} | ||
valueData={valueData} | ||
/> | ||
)); | ||
|
||
return ( | ||
<React.Fragment key={influencerFieldName}> | ||
<EuiTitle size="xs"> | ||
<h4>{influencerFieldName}</h4> | ||
</EuiTitle> | ||
<EuiSpacer size="xs"/> | ||
{influencerValues} | ||
</React.Fragment> | ||
); | ||
} | ||
InfluencersByName.propTypes = { | ||
influencerFieldName: PropTypes.string.isRequired, | ||
fieldValues: PropTypes.array.isRequired | ||
}; | ||
|
||
export function InfluencersList({ influencers }) { | ||
|
||
if (influencers === undefined || Object.keys(influencers).length === 0) { | ||
return ( | ||
<EuiFlexGroup justifyContent="spaceAround"> | ||
<EuiFlexItem grow={false}> | ||
<EuiSpacer size="xxl" /> | ||
<EuiText> | ||
<h4>No influencers found</h4> | ||
</EuiText> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} | ||
|
||
const influencersByName = Object.keys(influencers).map(influencerFieldName => ( | ||
<InfluencersByName | ||
key={influencerFieldName} | ||
influencerFieldName={influencerFieldName} | ||
fieldValues={influencers[influencerFieldName]} | ||
/> | ||
)); | ||
|
||
return ( | ||
<div className="ml-influencers-list"> | ||
{influencersByName} | ||
</div> | ||
); | ||
} | ||
InfluencersList.propTypes = { | ||
influencers: PropTypes.object | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.