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
React
,
{
PureComponent
}
from
'react'
;
import
*
as
d3
from
'd3'
;
import
{
select
,
pie
,
arc
,
event
}
from
'd3'
;
import
{
GrafanaThemeType
}
from
'../../types'
;
import
{
GrafanaThemeType
}
from
'../../types'
;
import
{
Themeable
}
from
'../../index'
;
import
{
Themeable
}
from
'../../index'
;
...
@@ -58,9 +58,8 @@ export class Piechart extends PureComponent<Props> {
...
@@ -58,9 +58,8 @@ export class Piechart extends PureComponent<Props> {
const
outerRadius
=
radius
-
radius
/
10
;
const
outerRadius
=
radius
-
radius
/
10
;
const
innerRadius
=
pieType
===
PiechartType
.
PIE
?
0
:
radius
-
radius
/
3
;
const
innerRadius
=
pieType
===
PiechartType
.
PIE
?
0
:
radius
-
radius
/
3
;
d3
.
select
(
'.piechart-container svg'
).
remove
();
select
(
'.piechart-container svg'
).
remove
();
const
svg
=
d3
const
svg
=
select
(
'.piechart-container'
)
.
select
(
'.piechart-container'
)
.
append
(
'svg'
)
.
append
(
'svg'
)
.
attr
(
'width'
,
width
)
.
attr
(
'width'
,
width
)
.
attr
(
'height'
,
height
)
.
attr
(
'height'
,
height
)
...
@@ -68,42 +67,38 @@ export class Piechart extends PureComponent<Props> {
...
@@ -68,42 +67,38 @@ export class Piechart extends PureComponent<Props> {
.
append
(
'g'
)
.
append
(
'g'
)
.
attr
(
'transform'
,
`translate(
${
width
/
2
}
,
${
height
/
2
}
)`
);
.
attr
(
'transform'
,
`translate(
${
width
/
2
}
,
${
height
/
2
}
)`
);
const
arc
=
d3
const
pieChart
=
pie
();
.
arc
()
const
customArc
=
arc
()
.
outerRadius
(
outerRadius
)
.
outerRadius
(
outerRadius
)
.
innerRadius
(
innerRadius
)
.
innerRadius
(
innerRadius
)
.
padAngle
(
0
);
.
padAngle
(
0
);
const
pie
=
d3
.
pie
();
svg
svg
.
selectAll
(
'path'
)
.
selectAll
(
'path'
)
.
data
(
pie
(
data
))
.
data
(
pie
Chart
(
data
))
.
enter
()
.
enter
()
.
append
(
'path'
)
.
append
(
'path'
)
.
attr
(
'd'
,
arc
as
any
)
.
attr
(
'd'
,
customArc
as
any
)
.
attr
(
'fill'
,
(
d
:
any
,
idx
:
number
)
=>
{
.
attr
(
'fill'
,
(
d
:
any
,
idx
:
number
)
=>
colors
[
idx
])
return
colors
[
idx
];
})
.
style
(
'fill-opacity'
,
0.15
)
.
style
(
'fill-opacity'
,
0.15
)
.
style
(
'stroke'
,
(
d
:
any
,
idx
:
number
)
=>
{
.
style
(
'stroke'
,
(
d
:
any
,
idx
:
number
)
=>
colors
[
idx
])
return
colors
[
idx
];
})
.
style
(
'stroke-width'
,
`
${
strokeWidth
}
px`
)
.
style
(
'stroke-width'
,
`
${
strokeWidth
}
px`
)
.
on
(
'mouseover'
,
(
d
:
any
,
idx
:
any
)
=>
{
.
on
(
'mouseover'
,
(
d
:
any
,
idx
:
any
)
=>
{
d3
.
select
(
'#tooltip'
)
select
(
'#tooltip'
)
.
style
(
'opacity'
,
1
)
.
style
(
'opacity'
,
1
)
.
select
(
'#tooltip-value'
)
.
select
(
'#tooltip-value'
)
// TODO: show percents
// TODO: show percents
.
text
(
`
${
names
[
idx
]}
(
${
data
[
idx
]}
)`
);
.
text
(
`
${
names
[
idx
]}
(
${
data
[
idx
]}
)`
);
})
})
.
on
(
'mousemove'
,
()
=>
{
.
on
(
'mousemove'
,
()
=>
{
d3
.
select
(
'#tooltip'
)
select
(
'#tooltip'
)
.
style
(
'top'
,
d3
.
event
.
pageY
-
10
+
'px'
)
// TODO: right position
.
style
(
'left'
,
d3
.
event
.
pageX
+
10
+
'px'
);
.
style
(
'top'
,
`
${
event
.
pageY
}
px`
)
.
style
(
'left'
,
`
${
event
.
pageX
}
px`
);
})
})
.
on
(
'mouseout'
,
()
=>
{
.
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