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
81c140b4
Commit
81c140b4
authored
Feb 27, 2019
by
corpglory-dev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial rendering
parent
b48f8bcf
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
4 deletions
+59
-4
packages/grafana-ui/src/components/Piechart/Piechart.tsx
+47
-4
public/sass/_grafana.scss
+1
-0
public/sass/components/_panel_piechart.scss
+11
-0
No files found.
packages/grafana-ui/src/components/Piechart/Piechart.tsx
View file @
81c140b4
import
React
,
{
PureComponent
}
from
'react'
;
import
React
,
{
PureComponent
}
from
'react'
;
import
*
as
d3
from
'd3'
;
import
{
GrafanaThemeType
}
from
'../../types'
;
import
{
GrafanaThemeType
}
from
'../../types'
;
import
{
Themeable
}
from
'../../index'
;
import
{
Themeable
}
from
'../../index'
;
export
enum
PiechartType
{
PIE
=
'pie'
,
DONUT
=
'donut'
}
export
interface
PiechartDataPoint
{
export
interface
PiechartDataPoint
{
value
:
number
;
value
:
number
;
name
:
string
;
name
:
string
;
...
@@ -15,7 +22,7 @@ export interface Props extends Themeable {
...
@@ -15,7 +22,7 @@ export interface Props extends Themeable {
datapoints
:
PiechartDataPoint
[];
datapoints
:
PiechartDataPoint
[];
unit
:
string
;
unit
:
string
;
pieType
:
string
;
pieType
:
PiechartType
;
strokeWidth
:
number
;
strokeWidth
:
number
;
}
}
...
@@ -39,7 +46,42 @@ export class Piechart extends PureComponent<Props> {
...
@@ -39,7 +46,42 @@ export class Piechart extends PureComponent<Props> {
}
}
draw
()
{
draw
()
{
// const { width, height, theme, value } = this.props;
const
{
datapoints
,
pieType
,
strokeWidth
}
=
this
.
props
;
const
data
=
datapoints
.
map
(
datapoint
=>
datapoint
.
value
);
const
colors
=
datapoints
.
map
(
datapoint
=>
datapoint
.
color
);
const
width
=
this
.
canvasElement
.
width
;
const
height
=
this
.
canvasElement
.
height
;
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
();
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
();
}
}
render
()
{
render
()
{
...
@@ -54,8 +96,9 @@ export class Piechart extends PureComponent<Props> {
...
@@ -54,8 +96,9 @@ export class Piechart extends PureComponent<Props> {
top
:
'10px'
,
top
:
'10px'
,
margin
:
'auto'
,
margin
:
'auto'
,
}
}
}
}
ref=
{
element
=>
(
this
.
canvasElement
=
element
)
}
>
/>
<
canvas
ref=
{
element
=>
(
this
.
canvasElement
=
element
)
}
/>
</
div
>
</
div
>
</
div
>
);
);
}
}
...
...
public/sass/_grafana.scss
View file @
81c140b4
...
@@ -54,6 +54,7 @@
...
@@ -54,6 +54,7 @@
@import
'components/panel_alertlist'
;
@import
'components/panel_alertlist'
;
@import
'components/panel_dashlist'
;
@import
'components/panel_dashlist'
;
@import
'components/panel_gettingstarted'
;
@import
'components/panel_gettingstarted'
;
@import
'components/panel_piechart'
;
@import
'components/panel_pluginlist'
;
@import
'components/panel_pluginlist'
;
@import
'components/panel_singlestat'
;
@import
'components/panel_singlestat'
;
@import
'components/panel_table'
;
@import
'components/panel_table'
;
...
...
public/sass/components/_panel_piechart.scss
0 → 100644
View file @
81c140b4
.piechart-panel
{
position
:
relative
;
display
:
table
;
width
:
100%
;
height
:
100%
;
canvas
{
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