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 {
...
@@ -26,7 +26,7 @@ export interface Props extends Themeable {
}
}
export
class
Piechart
extends
PureComponent
<
Props
>
{
export
class
Piechart
extends
PureComponent
<
Props
>
{
c
anvas
Element
:
any
;
c
ontainer
Element
:
any
;
static
defaultProps
=
{
static
defaultProps
=
{
pieType
:
'pie'
,
pieType
:
'pie'
,
...
@@ -50,46 +50,51 @@ export class Piechart extends PureComponent<Props> {
...
@@ -50,46 +50,51 @@ export class Piechart extends PureComponent<Props> {
const
data
=
datapoints
.
map
(
datapoint
=>
datapoint
.
value
);
const
data
=
datapoints
.
map
(
datapoint
=>
datapoint
.
value
);
const
colors
=
datapoints
.
map
(
datapoint
=>
datapoint
.
color
);
const
colors
=
datapoints
.
map
(
datapoint
=>
datapoint
.
color
);
const
width
=
this
.
c
anvasElement
.
w
idth
;
const
width
=
this
.
c
ontainerElement
.
offsetW
idth
;
const
height
=
this
.
c
anvasElement
.
h
eight
;
const
height
=
this
.
c
ontainerElement
.
offsetH
eight
;
const
radius
=
Math
.
min
(
width
,
height
)
/
2
;
const
radius
=
Math
.
min
(
width
,
height
)
/
2
;
const
innerRadius
=
pieType
===
PiechartType
.
PIE
?
0
:
radius
;
const
innerRadius
=
pieType
===
PiechartType
.
PIE
?
0
:
radius
;
const
context
=
this
.
canvasElement
.
getContext
(
'2d'
);
d3
.
select
(
'.piechart-container svg'
).
remove
();
context
.
translate
(
width
/
2
,
height
/
2
);
const
svg
=
d3
.
select
(
'.piechart-container'
)
context
.
globalAlpha
=
0.5
;
.
append
(
'svg'
)
.
attr
(
'width'
,
width
)
const
pie
=
d3
.
pie
();
.
attr
(
'height'
,
height
)
.
attr
(
'class'
,
'shadow'
)
.
append
(
'g'
)
.
attr
(
'transform'
,
`translate(
${
width
/
2
}
,
${
height
/
2
}
)`
);
const
arcs
=
pie
(
data
);
const
arc
=
d3
const
arc
=
d3
.
arc
()
.
arc
()
.
outerRadius
(
radius
-
10
)
.
outerRadius
(
radius
-
10
)
.
innerRadius
(
innerRadius
)
.
innerRadius
(
innerRadius
)
.
padAngle
(
0.03
)
.
padAngle
(
0
);
.
context
(
context
);
const
pie
=
d3
.
pie
();
arcs
.
forEach
((
d
,
idx
)
=>
{
context
.
beginPath
();
svg
.
selectAll
(
'path'
)
arc
(
d
as
any
);
.
data
(
pie
(
data
))
context
.
fillStyle
=
colors
[
idx
];
.
enter
()
context
.
fill
();
.
append
(
'path'
)
});
.
attr
(
'd'
,
arc
as
any
)
.
attr
(
'fill'
,
(
d
:
any
,
i
:
any
)
=>
{
context
.
globalAlpha
=
1
;
return
colors
[
i
];
context
.
beginPath
();
})
arcs
.
forEach
(
arc
as
any
);
.
style
(
'fill-opacity'
,
0.15
)
context
.
lineWidth
=
strokeWidth
;
.
style
(
'stroke'
,
(
d
:
any
,
i
:
any
)
=>
{
context
.
stroke
();
return
colors
[
i
];
})
.
style
(
'stroke-width'
,
`
${
strokeWidth
}
px`
);
}
}
render
()
{
render
()
{
const
{
height
,
width
}
=
this
.
props
;
const
{
height
,
width
}
=
this
.
props
;
return
(
return
(
<
div
className=
"piechart-panel"
>
<
div
className=
'piechart-panel'
>
<
div
<
div
ref=
{
element
=>
(
this
.
containerElement
=
element
)
}
className=
'piechart-container'
style=
{
{
style=
{
{
height
:
`${height * 0.9}px`
,
height
:
`${height * 0.9}px`
,
width
:
`${Math.min(width, height * 1.3)}px`
,
width
:
`${Math.min(width, height * 1.3)}px`
,
...
@@ -97,7 +102,6 @@ export class Piechart extends PureComponent<Props> {
...
@@ -97,7 +102,6 @@ export class Piechart extends PureComponent<Props> {
margin
:
'auto'
,
margin
:
'auto'
,
}
}
}
}
>
>
<
canvas
ref=
{
element
=>
(
this
.
canvasElement
=
element
)
}
/>
</
div
>
</
div
>
</
div
>
</
div
>
);
);
...
...
public/sass/components/_panel_piechart.scss
View file @
4cd91ff9
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
width
:
100%
;
width
:
100%
;
height
:
100%
;
height
:
100%
;
canvas
{
svg
{
width
:
100%
;
width
:
100%
;
height
:
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