Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
ed208f2b
Commit
ed208f2b
authored
Feb 11, 2019
by
Dominik Prokop
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error caused by named colors that are not part of named colors palette
parent
b590c4da
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
packages/grafana-ui/src/utils/namedColorsPalette.test.ts
+4
-4
packages/grafana-ui/src/utils/namedColorsPalette.ts
+2
-1
No files found.
packages/grafana-ui/src/utils/namedColorsPalette.test.ts
View file @
ed208f2b
...
@@ -44,10 +44,6 @@ describe('colors', () => {
...
@@ -44,10 +44,6 @@ describe('colors', () => {
});
});
describe
(
'getColorFromHexRgbOrName'
,
()
=>
{
describe
(
'getColorFromHexRgbOrName'
,
()
=>
{
it
(
'returns undefined for unknown color'
,
()
=>
{
expect
(()
=>
getColorFromHexRgbOrName
(
'aruba-sunshine'
)).
toThrow
();
});
it
(
'returns dark hex variant for known color if theme not specified'
,
()
=>
{
it
(
'returns dark hex variant for known color if theme not specified'
,
()
=>
{
expect
(
getColorFromHexRgbOrName
(
SemiDarkBlue
.
name
)).
toBe
(
SemiDarkBlue
.
variants
.
dark
);
expect
(
getColorFromHexRgbOrName
(
SemiDarkBlue
.
name
)).
toBe
(
SemiDarkBlue
.
variants
.
dark
);
});
});
...
@@ -64,5 +60,9 @@ describe('colors', () => {
...
@@ -64,5 +60,9 @@ describe('colors', () => {
expect
(
getColorFromHexRgbOrName
(
'rgb(0,0,0)'
)).
toBe
(
'rgb(0,0,0)'
);
expect
(
getColorFromHexRgbOrName
(
'rgb(0,0,0)'
)).
toBe
(
'rgb(0,0,0)'
);
expect
(
getColorFromHexRgbOrName
(
'rgba(0,0,0,1)'
)).
toBe
(
'rgba(0,0,0,1)'
);
expect
(
getColorFromHexRgbOrName
(
'rgba(0,0,0,1)'
)).
toBe
(
'rgba(0,0,0,1)'
);
});
});
it
(
'returns hex for named color that is not a part of named colors palette'
,
()
=>
{
expect
(
getColorFromHexRgbOrName
(
'lime'
)).
toBe
(
'#00ff00'
);
});
});
});
});
});
packages/grafana-ui/src/utils/namedColorsPalette.ts
View file @
ed208f2b
import
{
flatten
}
from
'lodash'
;
import
{
flatten
}
from
'lodash'
;
import
{
GrafanaThemeType
}
from
'../types'
;
import
{
GrafanaThemeType
}
from
'../types'
;
import
tinycolor
from
'tinycolor2'
;
type
Hue
=
'green'
|
'yellow'
|
'red'
|
'blue'
|
'orange'
|
'purple'
;
type
Hue
=
'green'
|
'yellow'
|
'red'
|
'blue'
|
'orange'
|
'purple'
;
...
@@ -106,7 +107,7 @@ export const getColorFromHexRgbOrName = (color: string, theme?: GrafanaThemeType
...
@@ -106,7 +107,7 @@ export const getColorFromHexRgbOrName = (color: string, theme?: GrafanaThemeType
const
colorDefinition
=
getColorByName
(
color
);
const
colorDefinition
=
getColorByName
(
color
);
if
(
!
colorDefinition
)
{
if
(
!
colorDefinition
)
{
throw
new
Error
(
'Unknown color'
);
return
new
tinycolor
(
color
).
toHexString
(
);
}
}
return
theme
?
colorDefinition
.
variants
[
theme
]
:
colorDefinition
.
variants
.
dark
;
return
theme
?
colorDefinition
.
variants
[
theme
]
:
colorDefinition
.
variants
.
dark
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment