Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
d5ec0924
Commit
d5ec0924
authored
Dec 08, 2017
by
AlasdairSwan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LEARNER-3376 Added Learner Analytics Dashboard React app to Course Dashboard
parent
171e6715
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
0 deletions
+150
-0
lms/static/js/learner_analytics_dashboard/CircleChart.jsx
+116
-0
lms/static/js/learner_analytics_dashboard/CircleChartLegend.jsx
+34
-0
No files found.
lms/static/js/learner_analytics_dashboard/CircleChart.jsx
0 → 100644
View file @
d5ec0924
import
React
from
'react'
;
import
classNames
from
'classnames'
;
import
PropTypes
from
'prop-types'
;
const
size
=
100
;
const
radCircumference
=
Math
.
PI
*
2
;
const
center
=
size
/
2
;
const
radius
=
center
-
1
;
// padding to prevent clipping
// Based on https://github.com/brigade/react-simple-pie-chart
class
CircleChart
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
this
.
getCenter
=
this
.
getCenter
.
bind
(
this
);
this
.
getSlices
=
this
.
getSlices
.
bind
(
this
);
}
getCenter
()
{
const
{
centerHole
,
sliceBorder
}
=
this
.
props
;
if
(
centerHole
)
{
const
size
=
center
/
2
;
return
(
<
circle
cx=
{
center
}
cy=
{
center
}
r=
{
size
}
fill=
{
sliceBorder
.
strokeColor
}
/>
);
}
}
getSlices
(
slices
,
sliceBorder
)
{
const
total
=
slices
.
reduce
((
totalValue
,
{
value
})
=>
totalValue
+
value
,
0
);
const
{
strokeColor
,
strokeWidth
}
=
sliceBorder
;
let
radSegment
=
0
;
let
lastX
=
radius
;
let
lastY
=
0
;
// Reverse a copy of the array so order start at 12 o'clock
return
slices
.
slice
(
0
).
reverse
().
map
(({
color
,
value
},
index
)
=>
{
// Should we just draw a circle?
if
(
value
===
total
)
{
return
(
<
circle
r=
{
radius
}
cx=
{
center
}
cy=
{
center
}
fill=
{
color
}
key=
{
index
}
/>
);
}
if
(
value
===
0
)
{
return
;
}
const
valuePercentage
=
value
/
total
;
// Should the arc go the long way round?
const
longArc
=
(
valuePercentage
<=
0.5
)
?
0
:
1
;
radSegment
+=
valuePercentage
*
radCircumference
;
const
nextX
=
Math
.
cos
(
radSegment
)
*
radius
;
const
nextY
=
Math
.
sin
(
radSegment
)
*
radius
;
/**
* d is a string that describes the path of the slice.
* The weirdly placed minus signs [eg, (-(lastY))] are due to the fact
* that our calculations are for a graph with positive Y values going up,
* but on the screen positive Y values go down.
*/
const
d
=
[
`M
${
center
}
,
${
center
}
`
,
`l
${
lastX
}
,
${
-
lastY
}
`
,
`a
${
radius
}
,
${
radius
}
`
,
'0'
,
`
${
longArc
}
,0`
,
`
${
nextX
-
lastX
}
,
${
-
(
nextY
-
lastY
)}
`
,
'z'
,
].
join
(
' '
);
lastX
=
nextX
;
lastY
=
nextY
;
return
<
path
d=
{
d
}
fill=
{
color
}
key=
{
index
}
stroke=
{
strokeColor
}
strokeWidth=
{
strokeWidth
}
/>;
});
}
render
()
{
const
{
slices
,
sliceBorder
}
=
this
.
props
;
return
(
<
svg
viewBox=
{
`0 0 ${size} ${size}`
}
>
<
g
transform=
{
`rotate(-90 ${center} ${center})`
}
>
{
this
.
getSlices
(
slices
,
sliceBorder
)
}
</
g
>
{
this
.
getCenter
()
}
</
svg
>
);
}
}
CircleChart
.
defaultProps
=
{
sliceBorder
:
{
strokeColor
:
'#fff'
,
strokeWidth
:
0
}
};
CircleChart
.
propTypes
=
{
slices
:
PropTypes
.
array
.
isRequired
,
centerHole
:
PropTypes
.
boolean
,
sliceBorder
:
PropTypes
.
object
};
export
default
CircleChart
;
lms/static/js/learner_analytics_dashboard/CircleChartLegend.jsx
0 → 100644
View file @
d5ec0924
import
React
from
'react'
;
import
classNames
from
'classnames'
;
import
PropTypes
from
'prop-types'
;
class
CircleChartLegend
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
}
getList
()
{
const
{
data
}
=
this
.
props
;
return
data
.
map
(({
color
,
value
,
label
})
=>
{
const
style
=
{
backgroundColor
:
color
}
return
(
<
li
className=
"legend-item"
>
<
div
className=
"color-swatch"
style=
{
style
}
aria
-
hidden=
"true"
></
div
>
<
span
className=
"label"
>
{
label
}
</
span
>
<
span
className=
"percentage"
>
{
value
}
%
</
span
>
</
li
>
);
});
}
CircleChartLegend
.
propTypes
=
{
data
:
PropTypes
.
array
.
isRequired
};
export
default
CircleChartLegend
;
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