Skip to content

Commit

Permalink
SAK-41400 remove rounding on gradebook charts (sakaiproject#6605)
Browse files Browse the repository at this point in the history
* #3432 Make sure mapped grades are not null when they are collected.

Mapped grades will be null if the student doesn't have a course grade yet.

* SAK-41400 Remove custom chart drawing as we no longer want rounded corners
  • Loading branch information
amiedavis authored and steveswinsburg committed Mar 4, 2019
1 parent 64f57e0 commit fd33c73
Showing 1 changed file with 0 additions and 104 deletions.
104 changes: 0 additions & 104 deletions gradebookng/tool/src/webapp/scripts/gradebook-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,109 +6,6 @@
* Draws charts using ChartJS.
*/


/**
* Custom chart drawing, to enable us to have rounded corners
*
* Based on code by Jed Trow
* https://github.com/jedtrow/Chart.js-Rounded-Bar-Charts/blob/master/Chart.roundedBarCharts.js
*
* Updated to remove unnecessary code and only round the top corners
*
* NOTE: This code should be removed as soon as rounded corners are added as a feature to Chartjs.
* It is only a stopgap solution.
*/

Chart.elements.Rectangle.prototype.draw = function() {

var ctx = this._chart.ctx;
var vm = this._view;
var left, right, top, bottom, signX, signY, borderSkipped, cornerRadius;
var borderWidth = vm.borderWidth;

if (!vm.horizontal) {
// bar
left = vm.x - vm.width / 2;
right = vm.x + vm.width / 2;
top = vm.y;
bottom = vm.base;
signX = 1;
signY = bottom > top? 1: -1;
borderSkipped = vm.borderSkipped || 'bottom';
} else {
// horizontal bar
left = vm.base;
right = vm.x;
top = vm.y - vm.height / 2;
bottom = vm.y + vm.height / 2;
signX = right > left? 1: -1;
signY = 1;
borderSkipped = vm.borderSkipped || 'left';
}

// Canvas doesn't allow us to stroke inside the width so we can
// adjust the sizes to fit if we're setting a stroke on the line
if (borderWidth) {
// borderWidth should be less than bar width and bar height.
var barSize = Math.min(Math.abs(left - right), Math.abs(top - bottom));
borderWidth = borderWidth > barSize? barSize: borderWidth;
var halfStroke = borderWidth / 2;
// Adjust borderWidth when bar top position is near vm.base (zero)
var borderLeft = left + (borderSkipped !== 'left'? halfStroke * signX: 0);
var borderRight = right + (borderSkipped !== 'right'? -halfStroke * signX: 0);
var borderTop = top + (borderSkipped !== 'top'? halfStroke * signY: 0);
var borderBottom = bottom + (borderSkipped !== 'bottom'? -halfStroke * signY: 0);
// not become a vertical line?
if (borderLeft !== borderRight) {
top = borderTop;
bottom = borderBottom;
}
// not become a horizontal line?
if (borderTop !== borderBottom) {
left = borderLeft;
right = borderRight;
}
}

width = right - left;
height = bottom - top;

// Set the corner radius to be half the width or height (whichever is smaller)
if (this._chart.config.options.roundedCorners) {
cornerRadius = (Math.abs(height) < Math.abs(width)) ? Math.floor(Math.abs(height)/2) : Math.floor(Math.abs(width)/2);
} else {
cornerRadius = 0;
}

// Draw the rectangle
ctx.beginPath();
ctx.fillStyle = vm.backgroundColor;
ctx.strokeStyle = vm.borderColor;
ctx.lineWidth = borderWidth;
var x = left, y = top;
if (!vm.horizontal) {
ctx.moveTo(x, y + height);
ctx.lineTo(x, y + cornerRadius);
ctx.quadraticCurveTo(x, y, x + cornerRadius, y);
ctx.lineTo(x + width - cornerRadius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + cornerRadius);
ctx.lineTo(x + width, y + height);
ctx.lineTo(x, y + height);
} else {
ctx.moveTo(x, y);
ctx.lineTo(x + width - cornerRadius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + cornerRadius);
ctx.lineTo(x + width, y + height - cornerRadius);
ctx.quadraticCurveTo(x + width, y + height, x + width - cornerRadius, y + height);
ctx.lineTo(x, y + height);
ctx.lineTo(x, y);
}
ctx.fill();
if (borderWidth) {
ctx.stroke();
}
};

/**
* Render the chart from the given dataset.
* @param gbChartData the data for the chart. Must be a GbChartData object serialised to JSON.
Expand Down Expand Up @@ -147,7 +44,6 @@ function renderChart(gbChartData) {
}]
},
options: {
roundedCorners: true,
title: {
display: true,
text: chartTitle,
Expand Down

0 comments on commit fd33c73

Please sign in to comment.