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
a2363f4d
Unverified
Commit
a2363f4d
authored
May 05, 2020
by
Tobias Skarhed
Committed by
GitHub
May 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Storybook: Convert final CSF stories (#24283)
* Convert BigValue and GraphLegend * Convert last stories
parent
428b4ae5
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
91 additions
and
89 deletions
+91
-89
packages/grafana-ui/src/components/BigValue/BigValue.story.tsx
+37
-44
packages/grafana-ui/src/components/Graph/GraphLegend.story.tsx
+10
-9
packages/grafana-ui/src/components/Graph/GraphLegend.tsx
+1
-1
packages/grafana-ui/src/components/Graph/GraphWithLegend.story.tsx
+9
-6
packages/grafana-ui/src/components/Legend/Legend.story.tsx
+10
-23
packages/grafana-ui/src/components/Legend/Legend.tsx
+15
-0
packages/grafana-ui/src/components/Legend/LegendTable.tsx
+1
-1
packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx
+8
-5
No files found.
packages/grafana-ui/src/components/BigValue/BigValue.story.tsx
View file @
a2363f4d
import
{
storiesOf
}
from
'@storybook/react'
;
import
{
text
}
from
'@storybook/addon-knobs'
;
import
{
text
,
select
,
number
,
color
}
from
'@storybook/addon-knobs'
;
import
{
BigValue
,
BigValueColorMode
,
BigValueGraphMode
}
from
'./BigValue'
;
import
{
withCenteredStory
}
from
'../../utils/storybook/withCenteredStory'
;
import
{
renderComponentWithTheme
}
from
'../../utils/storybook/withTheme'
;
...
...
@@ -8,51 +7,45 @@ const getKnobs = () => {
return
{
value
:
text
(
'value'
,
'$5022'
),
title
:
text
(
'title'
,
'Total Earnings'
),
colorMode
:
select
(
'Color mode'
,
[
BigValueColorMode
.
Value
,
BigValueColorMode
.
Background
],
BigValueColorMode
.
Value
),
graphMode
:
select
(
'Graph mode'
,
[
BigValueGraphMode
.
Area
,
BigValueGraphMode
.
Line
],
BigValueGraphMode
.
Area
),
width
:
number
(
'Width'
,
400
,
{
range
:
true
,
max
:
800
,
min
:
200
}),
height
:
number
(
'Height'
,
300
,
{
range
:
true
,
max
:
800
,
min
:
200
}),
color
:
color
(
'Value color'
,
'red'
),
};
};
const
BigValueStories
=
storiesOf
(
'Visualizations/BigValue'
,
module
);
BigValueStories
.
addDecorator
(
withCenteredStory
);
interface
StoryOptions
{
colorMode
:
BigValueColorMode
;
graphMode
:
BigValueGraphMode
;
width
?:
number
;
height
?:
number
;
noSparkline
?:
boolean
;
}
export
default
{
title
:
'Visualizations/BigValue'
,
component
:
BigValue
,
decorators
:
[
withCenteredStory
],
};
function
addStoryForMode
(
options
:
StoryOptions
)
{
BigValueStories
.
add
(
`Color:
${
options
.
colorMode
}
`
,
()
=>
{
const
{
value
,
title
}
=
getKnobs
();
export
const
basic
=
()
=>
{
const
{
value
,
title
,
colorMode
,
graphMode
,
height
,
width
,
color
}
=
getKnobs
();
return
renderComponentWithTheme
(
BigValue
,
{
width
:
options
.
width
||
400
,
height
:
options
.
height
||
300
,
colorMode
:
options
.
colorMode
,
graphMode
:
options
.
graphMode
,
value
:
{
text
:
value
,
numeric
:
5022
,
color
:
'red'
,
title
,
},
sparkline
:
{
minX
:
0
,
maxX
:
5
,
data
:
[
[
0
,
10
],
[
1
,
20
],
[
2
,
15
],
[
3
,
25
],
[
4
,
5
],
[
5
,
10
],
],
},
});
return
renderComponentWithTheme
(
BigValue
,
{
width
:
width
,
height
:
height
,
colorMode
:
colorMode
,
graphMode
:
graphMode
,
value
:
{
text
:
value
,
numeric
:
5022
,
color
:
color
,
title
,
},
sparkline
:
{
minX
:
0
,
maxX
:
5
,
data
:
[
[
0
,
10
],
[
1
,
20
],
[
2
,
15
],
[
3
,
25
],
[
4
,
5
],
[
5
,
10
],
],
},
});
}
addStoryForMode
({
colorMode
:
BigValueColorMode
.
Value
,
graphMode
:
BigValueGraphMode
.
Area
});
addStoryForMode
({
colorMode
:
BigValueColorMode
.
Background
,
graphMode
:
BigValueGraphMode
.
Line
});
};
packages/grafana-ui/src/components/Graph/GraphLegend.story.tsx
View file @
a2363f4d
import
React
from
'react'
;
import
{
storiesOf
}
from
'@storybook/react'
;
import
{
GraphLegend
}
from
'./GraphLegend'
;
import
{
action
}
from
'@storybook/addon-actions'
;
import
{
select
,
number
}
from
'@storybook/addon-knobs'
;
import
{
withHorizontallyCenteredStory
}
from
'../../utils/storybook/withCenteredStory'
;
import
{
generateLegendItems
}
from
'../Legend/Legend
.story
'
;
import
{
generateLegendItems
}
from
'../Legend/Legend'
;
import
{
LegendPlacement
,
LegendDisplayMode
}
from
'../Legend/Legend'
;
const
GraphLegendStories
=
storiesOf
(
'Visualizations/Graph/GraphLegend'
,
module
);
GraphLegendStories
.
addDecorator
(
withHorizontallyCenteredStory
);
export
default
{
title
:
'Visualizations/Graph/GraphLegend'
,
component
:
GraphLegend
,
decororators
:
[
withHorizontallyCenteredStory
],
};
const
getStoriesKnobs
=
(
isList
=
false
)
=>
{
const
statsToDisplay
=
select
<
any
>
(
...
...
@@ -54,7 +55,7 @@ const getStoriesKnobs = (isList = false) => {
};
};
GraphLegendStories
.
add
(
'list'
,
()
=>
{
export
const
list
=
()
=>
{
const
{
statsToDisplay
,
numberOfSeries
,
containerWidth
,
legendPlacement
}
=
getStoriesKnobs
(
true
);
return
(
<
div
style=
{
{
width
:
containerWidth
}
}
>
...
...
@@ -77,9 +78,9 @@ GraphLegendStories.add('list', () => {
/>
</
div
>
);
}
)
;
};
GraphLegendStories
.
add
(
'table'
,
()
=>
{
export
const
table
=
()
=>
{
const
{
statsToDisplay
,
numberOfSeries
,
containerWidth
,
legendPlacement
}
=
getStoriesKnobs
();
return
(
<
div
style=
{
{
width
:
containerWidth
}
}
>
...
...
@@ -102,4 +103,4 @@ GraphLegendStories.add('table', () => {
/>
</
div
>
);
}
)
;
};
packages/grafana-ui/src/components/Graph/GraphLegend.tsx
View file @
a2363f4d
...
...
@@ -10,7 +10,7 @@ import { ThemeContext } from '../../themes/ThemeContext';
import
{
css
}
from
'emotion'
;
import
{
selectThemeVariant
}
from
'../../themes/index'
;
interface
GraphLegendProps
extends
LegendProps
{
export
interface
GraphLegendProps
extends
LegendProps
{
displayMode
:
LegendDisplayMode
;
sortBy
?:
string
;
sortDesc
?:
boolean
;
...
...
packages/grafana-ui/src/components/Graph/GraphWithLegend.story.tsx
View file @
a2363f4d
import
React
from
'react'
;
import
{
storiesOf
}
from
'@storybook/react'
;
import
{
select
,
text
}
from
'@storybook/addon-knobs'
;
import
{
with
Horizontally
CenteredStory
}
from
'../../utils/storybook/withCenteredStory'
;
import
{
withCenteredStory
}
from
'../../utils/storybook/withCenteredStory'
;
import
{
GraphWithLegend
,
GraphWithLegendProps
}
from
'./GraphWithLegend'
;
import
{
LegendPlacement
,
LegendDisplayMode
}
from
'../Legend/Legend'
;
import
{
GraphSeriesXY
,
FieldType
,
ArrayVector
,
dateTime
,
FieldColorMode
}
from
'@grafana/data'
;
const
GraphWithLegendStories
=
storiesOf
(
'Visualizations/Graph/GraphWithLegend'
,
module
);
GraphWithLegendStories
.
addDecorator
(
withHorizontallyCenteredStory
);
export
default
{
title
:
'Visualizations/Graph'
,
component
:
GraphWithLegend
,
decorator
:
[
withCenteredStory
],
};
const
series
:
GraphSeriesXY
[]
=
[
{
...
...
@@ -104,7 +107,7 @@ const getStoriesKnobs = () => {
};
};
GraphWithLegendStories
.
add
(
'default'
,
()
=>
{
export
const
graphWithLegend
=
()
=>
{
const
{
legendPlacement
,
rightAxisSeries
,
renderLegendAsTable
}
=
getStoriesKnobs
();
const
props
:
GraphWithLegendProps
=
{
series
:
series
.
map
(
s
=>
{
...
...
@@ -138,4 +141,4 @@ GraphWithLegendStories.add('default', () => {
};
return
<
GraphWithLegend
{
...
props
}
/>;
}
)
;
};
packages/grafana-ui/src/components/Legend/Legend.story.tsx
View file @
a2363f4d
import
React
from
'react'
;
import
{
storiesOf
}
from
'@storybook/react'
;
import
{
LegendList
,
LegendPlacement
,
LegendItem
,
LegendTable
}
from
'./Legend'
;
import
tinycolor
from
'tinycolor2'
;
import
{
DisplayValue
}
from
'@grafana/data'
;
import
{
LegendList
,
LegendPlacement
,
LegendItem
,
LegendTable
,
generateLegendItems
}
from
'./Legend'
;
import
{
number
,
select
,
text
}
from
'@storybook/addon-knobs'
;
import
{
action
}
from
'@storybook/addon-actions'
;
import
{
GraphLegendListItem
,
GraphLegendTableRow
,
GraphLegendItemProps
}
from
'../Graph/GraphLegendItem'
;
export
const
generateLegendItems
=
(
numberOfSeries
:
number
,
statsToDisplay
?:
DisplayValue
[]):
LegendItem
[]
=>
{
const
alphabet
=
'abcdefghijklmnopqrstuvwxyz'
.
split
(
''
);
return
[...
new
Array
(
numberOfSeries
)].
map
((
item
,
i
)
=>
{
return
{
label
:
`
${
alphabet
[
i
].
toUpperCase
()}
-series`
,
color
:
tinycolor
.
fromRatio
({
h
:
i
/
alphabet
.
length
,
s
:
1
,
v
:
1
}).
toHexString
(),
isVisible
:
true
,
yAxis
:
1
,
displayValues
:
statsToDisplay
||
[],
};
});
};
const
getStoriesKnobs
=
(
table
=
false
)
=>
{
const
numberOfSeries
=
number
(
'Number of series'
,
3
);
const
containerWidth
=
select
(
...
...
@@ -87,9 +70,13 @@ const getStoriesKnobs = (table = false) => {
};
};
const
LegendStories
=
storiesOf
(
'Visualizations/Legend'
,
module
);
export
default
{
title
:
'Visualizations/Legend'
,
component
:
LegendList
,
subcomponents
:
{
LegendTable
},
};
LegendStories
.
add
(
'list'
,
()
=>
{
export
const
list
=
()
=>
{
const
{
numberOfSeries
,
itemRenderer
,
containerWidth
,
rightAxisSeries
,
legendPlacement
}
=
getStoriesKnobs
();
let
items
=
generateLegendItems
(
numberOfSeries
);
...
...
@@ -110,9 +97,9 @@ LegendStories.add('list', () => {
<
LegendList
itemRenderer=
{
itemRenderer
}
items=
{
items
}
placement=
{
legendPlacement
}
/>
</
div
>
);
}
)
;
};
LegendStories
.
add
(
'table'
,
()
=>
{
export
const
table
=
()
=>
{
const
{
numberOfSeries
,
itemRenderer
,
containerWidth
,
rightAxisSeries
,
legendPlacement
}
=
getStoriesKnobs
(
true
);
let
items
=
generateLegendItems
(
numberOfSeries
);
...
...
@@ -139,4 +126,4 @@ LegendStories.add('table', () => {
<
LegendTable
itemRenderer=
{
itemRenderer
}
items=
{
items
}
columns=
{
[
''
,
'min'
,
'max'
]
}
placement=
{
legendPlacement
}
/>
</
div
>
);
}
)
;
};
packages/grafana-ui/src/components/Legend/Legend.tsx
View file @
a2363f4d
...
...
@@ -2,6 +2,21 @@ import { DisplayValue } from '@grafana/data';
import
{
LegendList
}
from
'./LegendList'
;
import
{
LegendTable
}
from
'./LegendTable'
;
import
tinycolor
from
'tinycolor2'
;
export
const
generateLegendItems
=
(
numberOfSeries
:
number
,
statsToDisplay
?:
DisplayValue
[]):
LegendItem
[]
=>
{
const
alphabet
=
'abcdefghijklmnopqrstuvwxyz'
.
split
(
''
);
return
[...
new
Array
(
numberOfSeries
)].
map
((
item
,
i
)
=>
{
return
{
label
:
`
${
alphabet
[
i
].
toUpperCase
()}
-series`
,
color
:
tinycolor
.
fromRatio
({
h
:
i
/
alphabet
.
length
,
s
:
1
,
v
:
1
}).
toHexString
(),
isVisible
:
true
,
yAxis
:
1
,
displayValues
:
statsToDisplay
||
[],
};
});
};
export
enum
LegendDisplayMode
{
List
=
'list'
,
...
...
packages/grafana-ui/src/components/Legend/LegendTable.tsx
View file @
a2363f4d
...
...
@@ -4,7 +4,7 @@ import { LegendComponentProps } from './Legend';
import
{
Icon
}
from
'../Icon/Icon'
;
import
{
ThemeContext
}
from
'../../themes/ThemeContext'
;
interface
LegendTableProps
extends
LegendComponentProps
{
export
interface
LegendTableProps
extends
LegendComponentProps
{
columns
:
string
[];
sortBy
?:
string
;
sortDesc
?:
boolean
;
...
...
packages/grafana-ui/src/components/StatsPicker/StatsPicker.story.tsx
View file @
a2363f4d
import
React
,
{
PureComponent
}
from
'react'
;
import
{
storiesOf
}
from
'@storybook/react'
;
import
{
action
}
from
'@storybook/addon-actions'
;
import
{
withCenteredStory
}
from
'../../utils/storybook/withCenteredStory'
;
import
{
StatsPicker
}
from
'./StatsPicker'
;
...
...
@@ -61,9 +60,13 @@ export class WrapperWithState extends PureComponent<any, State> {
}
}
const
story
=
storiesOf
(
'Pickers and Editors/StatsPicker'
,
module
);
story
.
addDecorator
(
withCenteredStory
);
story
.
add
(
'picker'
,
()
=>
{
export
default
{
title
:
'Pickers and Editors/StatsPicker'
,
component
:
StatsPicker
,
decorators
:
[
withCenteredStory
],
};
export
const
picker
=
()
=>
{
const
{
placeholder
,
defaultStat
,
allowMultiple
,
initialStats
}
=
getKnobs
();
return
(
...
...
@@ -76,4 +79,4 @@ story.add('picker', () => {
/>
</
div
>
);
}
)
;
};
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