Commit 021bf1e6 by AlasdairSwan

Using real data for the pie chart

parent b66810c8
...@@ -34,14 +34,14 @@ class CircleChart extends React.Component { ...@@ -34,14 +34,14 @@ class CircleChart extends React.Component {
let lastY = 0; let lastY = 0;
// Reverse a copy of the array so order start at 12 o'clock // Reverse a copy of the array so order start at 12 o'clock
return slices.slice(0).reverse().map(({ color, value }, index) => { return slices.map(({ value }, index) => {
// Should we just draw a circle? // Should we just draw a circle?
if (value === total) { if (value === total) {
return ( return (
<circle r={radius} <circle r={radius}
cx={center} cx={center}
cy={center} cy={center}
fill={color} className="slice-1"
key={index} /> key={index} />
); );
} }
...@@ -77,9 +77,10 @@ class CircleChart extends React.Component { ...@@ -77,9 +77,10 @@ class CircleChart extends React.Component {
lastX = nextX; lastX = nextX;
lastY = nextY; lastY = nextY;
const sliceNumber = index + 1;
return <path d={d} return <path d={d}
fill={color} className={`slice-${sliceNumber}`}
key={index} key={index}
stroke={strokeColor} stroke={strokeColor}
strokeWidth={strokeWidth} />; strokeWidth={strokeWidth} />;
......
...@@ -10,15 +10,14 @@ class CircleChartLegend extends React.Component { ...@@ -10,15 +10,14 @@ class CircleChartLegend extends React.Component {
getList() { getList() {
const {data} = this.props; const {data} = this.props;
return data.map(({ color, value, label }) => { return data.map(({ value, label }) => {
const style = { // const style = {
backgroundColor: color // backgroundColor: color
} // }
return ( return (
<li className="legend-item"> <li className="legend-item">
<div className="color-swatch" <div className="color-swatch"
style={style}
aria-hidden="true"></div> aria-hidden="true"></div>
<span className="label">{label}</span> <span className="label">{label}</span>
<span className="percentage">{this.getPercentage(value)}</span> <span className="percentage">{this.getPercentage(value)}</span>
......
...@@ -8,29 +8,36 @@ import CircleChartLegend from './CircleChartLegend'; ...@@ -8,29 +8,36 @@ import CircleChartLegend from './CircleChartLegend';
import Table from './Table'; import Table from './Table';
export function LearnerAnalyticsDashboard(props) { export function LearnerAnalyticsDashboard(props) {
console.log('props: ', props); console.log('props: ', props);
const data = [ const {grading_policy} = props;
{ const gradeBreakdown = grading_policy.GRADER.map(({type, weight}) => {
color: '#386F77', return {
value: 0.15, value: weight,
label: 'Chucky' label: type
}, }
{ });
color: '#1ABC9C', // const data = [
value: 0.25, // {
label: 'Michael Myers' // color: '#386F77',
}, // value: 0.15,
{ // label: 'Chucky'
color: '#92C9D3', // },
value: 0.3, // {
label: 'Freddy Krueger' // color: '#1ABC9C',
}, // value: 0.25,
{ // label: 'Michael Myers'
color: '#73bde7', // },
value: 0.3, // {
label: 'Jason Vorhees' // color: '#92C9D3',
} // value: 0.3,
]; // label: 'Freddy Krueger'
// },
// {
// color: '#73bde7',
// value: 0.3,
// label: 'Jason Vorhees'
// }
// ];
const tableHeadings = ['Assessment', 'Passing', 'You']; const tableHeadings = ['Assessment', 'Passing', 'You'];
const tableData = [ const tableData = [
...@@ -62,7 +69,7 @@ export function LearnerAnalyticsDashboard(props) { ...@@ -62,7 +69,7 @@ export function LearnerAnalyticsDashboard(props) {
<div className="grading-weight-wrapper"> <div className="grading-weight-wrapper">
<div className="chart-wrapper"> <div className="chart-wrapper">
<CircleChart <CircleChart
slices={data} slices={gradeBreakdown}
centerHole={true} centerHole={true}
sliceBorder={{ sliceBorder={{
strokeColor: '#fff', strokeColor: '#fff',
...@@ -70,7 +77,7 @@ export function LearnerAnalyticsDashboard(props) { ...@@ -70,7 +77,7 @@ export function LearnerAnalyticsDashboard(props) {
}} }}
/> />
</div> </div>
<CircleChartLegend data={data} /> <CircleChartLegend data={gradeBreakdown} />
</div> </div>
<h3>Graded Assessments</h3> <h3>Graded Assessments</h3>
......
$slices: #386F77, #1ABC9C, #386F77, #1ABC9C, #386F77, #1ABC9C;
.content-wrapper {
.page-content.learner-analytics-dashboard-wrapper {
flex-direction: column;
}
}
.learner-analytics-dashboard { .learner-analytics-dashboard {
.grading-weight-wrapper {
display: flex;
flex-direction: column;
.chart-wrapper {
width: 90px;
height: 90px;
.slice-1 {
fill: nth($slices, 1);
}
.slice-2 {
fill: nth($slices, 2);
}
.slice-3 {
fill: nth($slices, 3);
}
.slice-4 {
fill: nth($slices, 4);
}
.slice-5 {
fill: nth($slices, 5);
}
.slice-6 {
fill: nth($slices, 6);
}
}
}
.legend {
.legend-list {
list-style: none;
padding: 0;
margin: 20px;
width: 250px;
}
.legend-item {
display: flex;
align-items: center;
margin-bottom: 10px;
.color-swatch {
width: 45px;
height: 45px;
border-radius: 25%;
margin-right: 20px;
}
.percentage {
margin-left: auto;
}
&:nth-of-type(1) {
.color-swatch {
background-color: nth($slices, 1);
}
}
&:nth-of-type(2) {
.color-swatch {
background-color: nth($slices, 2);
}
}
&:nth-of-type(3) {
.color-swatch {
background-color: nth($slices, 3);
}
}
&:nth-of-type(4) {
.color-swatch {
background-color: nth($slices, 4);
}
}
&:nth-of-type(5) {
.color-swatch {
background-color: nth($slices, 5);
}
}
&:nth-of-type(6) {
.color-swatch {
background-color: nth($slices, 6);
}
}
}
}
} }
...@@ -52,13 +52,12 @@ from openedx.features.course_experience import course_home_page_title ...@@ -52,13 +52,12 @@ from openedx.features.course_experience import course_home_page_title
</nav> </nav>
</div> </div>
</header> </header>
<div class="page-content"> <div class="page-content learner-analytics-dashboard-wrapper">
<div id="root" class="learner-analytics-dashboard"> <div class="learner-analytics-dashboard">
${static.renderReact( ${static.renderReact(
component="LearnerAnalyticsDashboard", component="LearnerAnalyticsDashboard",
id="react-learner-analytics-dashboard", id="react-learner-analytics-dashboard",
props={ props={
'data': 'data',
'schedule': assignment_schedule, 'schedule': assignment_schedule,
'grading_policy': grading_policy, 'grading_policy': grading_policy,
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment