tooltip.draw();
expect(mockContext.getCalls()).toEqual(Array.prototype.concat(drawBody, [
+ {name: 'setTextAlign', args: ['left']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['title', 105, 105]},
+ {name: 'setTextAlign', args: ['left']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['label', 105, 123]},
+ {name: 'setTextAlign', args: ['left']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['footer', 105, 141]},
{name: 'restore', args: []}
tooltip.draw();
expect(mockContext.getCalls()).toEqual(Array.prototype.concat(drawBody, [
+ {name: 'setTextAlign', args: ['right']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['title', 195, 105]},
+ {name: 'setTextAlign', args: ['right']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['label', 195, 123]},
+ {name: 'setTextAlign', args: ['right']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['footer', 195, 141]},
{name: 'restore', args: []}
tooltip.draw();
expect(mockContext.getCalls()).toEqual(Array.prototype.concat(drawBody, [
+ {name: 'setTextAlign', args: ['center']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['title', 150, 105]},
+ {name: 'setTextAlign', args: ['center']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['label', 150, 123]},
+ {name: 'setTextAlign', args: ['center']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['footer', 150, 141]},
{name: 'restore', args: []}
tooltip.draw();
expect(mockContext.getCalls()).toEqual(Array.prototype.concat(drawBody, [
+ {name: 'setTextAlign', args: ['right']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['title', 195, 105]},
+ {name: 'setTextAlign', args: ['center']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['label', 150, 123]},
+ {name: 'setTextAlign', args: ['left']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'fillText', args: ['footer', 105, 141]},
{name: 'restore', args: []}
expect(radToNearestDegree(chart.scale.getIndexAngle(x))).toBe((slice * x));
}
});
+
+ it('should correctly get the correct label alignment for all points', function() {
+ var chart = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [10, 5, 0, 25, 78]
+ }],
+ labels: ['label1', 'label2', 'label3', 'label4', 'label5']
+ },
+ options: {
+ scale: {
+ pointLabels: {
+ callback: function(value, index) {
+ return index.toString();
+ }
+ },
+ ticks: {
+ display: false
+ }
+ }
+ }
+ });
+
+ var scale = chart.scale;
+
+ [{
+ startAngle: 30,
+ textAlign: ['right', 'right', 'left', 'left', 'left'],
+ y: [82, 366, 506, 319, 53]
+ }, {
+ startAngle: -30,
+ textAlign: ['right', 'right', 'left', 'left', 'right'],
+ y: [319, 506, 366, 82, 53]
+ }, {
+ startAngle: 750,
+ textAlign: ['right', 'right', 'left', 'left', 'left'],
+ y: [82, 366, 506, 319, 53]
+ }].forEach(function(expected) {
+ chart.options.startAngle = expected.startAngle;
+ chart.update();
+
+ scale.ctx = window.createMockContext();
+ chart.draw();
+
+ scale.ctx.getCalls().filter(function(x) {
+ return x.name === 'setTextAlign';
+ }).forEach(function(x, i) {
+ expect(x.args[0]).toBe(expected.textAlign[i]);
+ });
+
+ scale.ctx.getCalls().filter(function(x) {
+ return x.name === 'fillText';
+ }).map(function(x, i) {
+ expect(x.args[2]).toBeCloseToPixel(expected.y[i]);
+ });
+ });
+ });
});