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
ef37e95b
Commit
ef37e95b
authored
Mar 08, 2019
by
corpglory-dev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import only what is used from d3
parent
0f9253fe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
21 deletions
+16
-21
packages/grafana-ui/src/components/Piechart/Piechart.tsx
+16
-21
No files found.
packages/grafana-ui/src/components/Piechart/Piechart.tsx
View file @
ef37e95b
import
React
,
{
PureComponent
}
from
'react'
;
import
*
as
d3
from
'd3'
;
import
{
select
,
pie
,
arc
,
event
}
from
'd3'
;
import
{
GrafanaThemeType
}
from
'../../types'
;
import
{
Themeable
}
from
'../../index'
;
...
...
@@ -58,9 +58,8 @@ export class Piechart extends PureComponent<Props> {
const
outerRadius
=
radius
-
radius
/
10
;
const
innerRadius
=
pieType
===
PiechartType
.
PIE
?
0
:
radius
-
radius
/
3
;
d3
.
select
(
'.piechart-container svg'
).
remove
();
const
svg
=
d3
.
select
(
'.piechart-container'
)
select
(
'.piechart-container svg'
).
remove
();
const
svg
=
select
(
'.piechart-container'
)
.
append
(
'svg'
)
.
attr
(
'width'
,
width
)
.
attr
(
'height'
,
height
)
...
...
@@ -68,42 +67,38 @@ export class Piechart extends PureComponent<Props> {
.
append
(
'g'
)
.
attr
(
'transform'
,
`translate(
${
width
/
2
}
,
${
height
/
2
}
)`
);
const
arc
=
d3
.
arc
()
const
pieChart
=
pie
();
const
customArc
=
arc
()
.
outerRadius
(
outerRadius
)
.
innerRadius
(
innerRadius
)
.
padAngle
(
0
);
const
pie
=
d3
.
pie
();
svg
.
selectAll
(
'path'
)
.
data
(
pie
(
data
))
.
data
(
pie
Chart
(
data
))
.
enter
()
.
append
(
'path'
)
.
attr
(
'd'
,
arc
as
any
)
.
attr
(
'fill'
,
(
d
:
any
,
idx
:
number
)
=>
{
return
colors
[
idx
];
})
.
attr
(
'd'
,
customArc
as
any
)
.
attr
(
'fill'
,
(
d
:
any
,
idx
:
number
)
=>
colors
[
idx
])
.
style
(
'fill-opacity'
,
0.15
)
.
style
(
'stroke'
,
(
d
:
any
,
idx
:
number
)
=>
{
return
colors
[
idx
];
})
.
style
(
'stroke'
,
(
d
:
any
,
idx
:
number
)
=>
colors
[
idx
])
.
style
(
'stroke-width'
,
`
${
strokeWidth
}
px`
)
.
on
(
'mouseover'
,
(
d
:
any
,
idx
:
any
)
=>
{
d3
.
select
(
'#tooltip'
)
select
(
'#tooltip'
)
.
style
(
'opacity'
,
1
)
.
select
(
'#tooltip-value'
)
// TODO: show percents
.
text
(
`
${
names
[
idx
]}
(
${
data
[
idx
]}
)`
);
})
.
on
(
'mousemove'
,
()
=>
{
d3
.
select
(
'#tooltip'
)
.
style
(
'top'
,
d3
.
event
.
pageY
-
10
+
'px'
)
.
style
(
'left'
,
d3
.
event
.
pageX
+
10
+
'px'
);
select
(
'#tooltip'
)
// TODO: right position
.
style
(
'top'
,
`
${
event
.
pageY
}
px`
)
.
style
(
'left'
,
`
${
event
.
pageX
}
px`
);
})
.
on
(
'mouseout'
,
()
=>
{
d3
.
select
(
'#tooltip'
).
style
(
'opacity'
,
0
);
select
(
'#tooltip'
).
style
(
'opacity'
,
0
);
});
}
...
...
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