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
dbec66b3
Commit
dbec66b3
authored
Mar 14, 2019
by
corpglory-dev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tooltip: show percent instead of value
parent
4ba5217a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
2 deletions
+5
-2
packages/grafana-ui/src/components/PieChart/PieChart.tsx
+5
-2
No files found.
packages/grafana-ui/src/components/PieChart/PieChart.tsx
View file @
dbec66b3
import
React
,
{
PureComponent
}
from
'react'
;
import
{
select
,
pie
,
arc
,
event
}
from
'd3'
;
import
{
sum
}
from
'lodash'
;
import
{
GrafanaThemeType
}
from
'../../types'
;
import
{
Themeable
}
from
'../../index'
;
...
...
@@ -58,6 +59,9 @@ export class PieChart extends PureComponent<Props> {
const
names
=
datapoints
.
map
(
datapoint
=>
datapoint
.
name
);
const
colors
=
datapoints
.
map
(
datapoint
=>
datapoint
.
color
);
const
total
=
sum
(
data
)
||
1
;
const
percents
=
data
.
map
((
item
:
number
)
=>
(
item
/
total
)
*
100
);
const
width
=
this
.
containerElement
.
offsetWidth
;
const
height
=
this
.
containerElement
.
offsetHeight
;
const
radius
=
Math
.
min
(
width
,
height
)
/
2
;
...
...
@@ -91,8 +95,7 @@ export class PieChart extends PureComponent<Props> {
.
style
(
'stroke-width'
,
`
${
strokeWidth
}
px`
)
.
on
(
'mouseover'
,
(
d
:
any
,
idx
:
any
)
=>
{
select
(
this
.
tooltipElement
).
style
(
'opacity'
,
1
);
// TODO: show percents
select
(
this
.
tooltipValueElement
).
text
(
`
${
names
[
idx
]}
(
${
data
[
idx
]}
)`
);
select
(
this
.
tooltipValueElement
).
text
(
`
${
names
[
idx
]}
(
${
percents
[
idx
].
toFixed
(
2
)}
%)`
);
})
.
on
(
'mousemove'
,
()
=>
{
select
(
this
.
tooltipElement
)
...
...
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