forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Use the same colors on the RPM/TPM graphs as in the status code badge. Fixes elastic#47817.
- Loading branch information
Showing
4 changed files
with
59 additions
and
42 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
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, | ||
euiColorSecondary, | ||
euiColorWarning, | ||
euiColorDanger | ||
} = theme; | ||
|
||
export const httpsStatusCodeColors: StringMap<string> = { | ||
1: euiColorDarkShade, | ||
2: euiColorSecondary, | ||
3: euiColorDarkShade, | ||
4: euiColorWarning, | ||
5: euiColorDanger | ||
}; | ||
|
||
function getStatusColor(status: number) { | ||
return httpsStatusCodeColors[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); | ||
} | ||
} |