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
4cd91ff9
Commit
4cd91ff9
authored
Mar 06, 2019
by
corpglory-dev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render svg instead of canvas
parent
d2843879
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
28 deletions
+32
-28
packages/grafana-ui/src/components/Piechart/Piechart.tsx
+31
-27
public/sass/components/_panel_piechart.scss
+1
-1
No files found.
packages/grafana-ui/src/components/Piechart/Piechart.tsx
View file @
4cd91ff9
...
...
@@ -26,7 +26,7 @@ export interface Props extends Themeable {
}
export
class
Piechart
extends
PureComponent
<
Props
>
{
c
anvas
Element
:
any
;
c
ontainer
Element
:
any
;
static
defaultProps
=
{
pieType
:
'pie'
,
...
...
@@ -50,46 +50,51 @@ export class Piechart extends PureComponent<Props> {
const
data
=
datapoints
.
map
(
datapoint
=>
datapoint
.
value
);
const
colors
=
datapoints
.
map
(
datapoint
=>
datapoint
.
color
);
const
width
=
this
.
c
anvasElement
.
w
idth
;
const
height
=
this
.
c
anvasElement
.
h
eight
;
const
width
=
this
.
c
ontainerElement
.
offsetW
idth
;
const
height
=
this
.
c
ontainerElement
.
offsetH
eight
;
const
radius
=
Math
.
min
(
width
,
height
)
/
2
;
const
innerRadius
=
pieType
===
PiechartType
.
PIE
?
0
:
radius
;
const
context
=
this
.
canvasElement
.
getContext
(
'2d'
);
context
.
translate
(
width
/
2
,
height
/
2
);
context
.
globalAlpha
=
0.5
;
const
pie
=
d3
.
pie
();
d3
.
select
(
'.piechart-container svg'
).
remove
();
const
svg
=
d3
.
select
(
'.piechart-container'
)
.
append
(
'svg'
)
.
attr
(
'width'
,
width
)
.
attr
(
'height'
,
height
)
.
attr
(
'class'
,
'shadow'
)
.
append
(
'g'
)
.
attr
(
'transform'
,
`translate(
${
width
/
2
}
,
${
height
/
2
}
)`
);
const
arcs
=
pie
(
data
);
const
arc
=
d3
.
arc
()
.
outerRadius
(
radius
-
10
)
.
innerRadius
(
innerRadius
)
.
padAngle
(
0.03
)
.
context
(
context
);
arcs
.
forEach
((
d
,
idx
)
=>
{
context
.
beginPath
();
arc
(
d
as
any
);
context
.
fillStyle
=
colors
[
idx
];
context
.
fill
();
});
context
.
globalAlpha
=
1
;
context
.
beginPath
();
arcs
.
forEach
(
arc
as
any
);
context
.
lineWidth
=
strokeWidth
;
context
.
stroke
();
.
padAngle
(
0
);
const
pie
=
d3
.
pie
();
svg
.
selectAll
(
'path'
)
.
data
(
pie
(
data
))
.
enter
()
.
append
(
'path'
)
.
attr
(
'd'
,
arc
as
any
)
.
attr
(
'fill'
,
(
d
:
any
,
i
:
any
)
=>
{
return
colors
[
i
];
})
.
style
(
'fill-opacity'
,
0.15
)
.
style
(
'stroke'
,
(
d
:
any
,
i
:
any
)
=>
{
return
colors
[
i
];
})
.
style
(
'stroke-width'
,
`
${
strokeWidth
}
px`
);
}
render
()
{
const
{
height
,
width
}
=
this
.
props
;
return
(
<
div
className=
"piechart-panel"
>
<
div
className=
'piechart-panel'
>
<
div
ref=
{
element
=>
(
this
.
containerElement
=
element
)
}
className=
'piechart-container'
style=
{
{
height
:
`${height * 0.9}px`
,
width
:
`${Math.min(width, height * 1.3)}px`
,
...
...
@@ -97,7 +102,6 @@ export class Piechart extends PureComponent<Props> {
margin
:
'auto'
,
}
}
>
<
canvas
ref=
{
element
=>
(
this
.
canvasElement
=
element
)
}
/>
</
div
>
</
div
>
);
...
...
public/sass/components/_panel_piechart.scss
View file @
4cd91ff9
...
...
@@ -4,7 +4,7 @@
width
:
100%
;
height
:
100%
;
canvas
{
svg
{
width
:
100%
;
height
:
100%
;
}
...
...
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