-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APM] Use same colors for HTTP status everywhere (#47915)
* [APM] Use same colors for HTTP status everywhere Use the same colors on the RPM/TPM graphs as in the status code badge. Fixes #47817. * don't export that const * Change colors * Remove unused import
- Loading branch information
Showing
5 changed files
with
85 additions
and
53 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
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
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
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
40 changes: 40 additions & 0 deletions
40
x-pack/legacy/plugins/apm/public/utils/httpStatusCodeToColor.ts
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,40 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import theme from '@elastic/eui/dist/eui_theme_light.json'; | ||
import { StringMap } from '../../typings/common'; | ||
|
||
const { euiColorDarkShade, euiColorWarning } = theme; | ||
|
||
export const errorColor = '#c23c2b'; | ||
export const neutralColor = euiColorDarkShade; | ||
export const successColor = '#327a42'; | ||
export const warningColor = euiColorWarning; | ||
|
||
const httpStatusCodeColors: StringMap<string> = { | ||
1: neutralColor, | ||
2: successColor, | ||
3: neutralColor, | ||
4: warningColor, | ||
5: errorColor | ||
}; | ||
|
||
function getStatusColor(status: number) { | ||
return httpStatusCodeColors[status.toString().substr(0, 1)]; | ||
} | ||
|
||
/** | ||
* Convert an HTTP status code to a color. | ||
* | ||
* If passed a string, it will remove all non-numeric characters | ||
*/ | ||
export function httpStatusCodeToColor(status: string | number) { | ||
if (typeof status === 'string') { | ||
return getStatusColor(parseInt(status.replace(/\D/g, ''), 10)); | ||
} else { | ||
return getStatusColor(status); | ||
} | ||
} |