From 26fa13981136a146cf378e01fdb3fd7157c0c913 Mon Sep 17 00:00:00 2001 From: cholt0425 Date: Wed, 27 Dec 2017 18:09:20 -0500 Subject: [PATCH 1/2] Added ability to draw a point as an inverted triangle. Added ability to draw a point as an inverted triangle as it is useful for showing progress along a bar, line, or scale. --- docs/configuration/elements.md | 1 + src/helpers/helpers.canvas.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/docs/configuration/elements.md b/docs/configuration/elements.md index 5375a7e9f1f..81060da9bf8 100644 --- a/docs/configuration/elements.md +++ b/docs/configuration/elements.md @@ -39,6 +39,7 @@ The following values are supported: - `'rectRot'` - `'star'` - `'triangle'` +- `'triangleInv'` If the value is an image, that image is drawn on the canvas using [drawImage](https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D/drawImage). diff --git a/src/helpers/helpers.canvas.js b/src/helpers/helpers.canvas.js index 13b110268b9..27342b611a0 100644 --- a/src/helpers/helpers.canvas.js +++ b/src/helpers/helpers.canvas.js @@ -77,6 +77,16 @@ var exports = module.exports = { ctx.closePath(); ctx.fill(); break; + case 'triangleInv': + ctx.beginPath(); + edgeLength = 3 * radius / Math.sqrt(3); + height = edgeLength * Math.sqrt(3) / 2; + ctx.moveTo(x - edgeLength / 2, y - height / 3); + ctx.lineTo(x + edgeLength / 2, y - height / 3); + ctx.lineTo(x, y + 2 * height / 3); + ctx.closePath(); + ctx.fill(); + break; case 'rect': size = 1 / Math.SQRT2 * radius; ctx.beginPath(); From eacc3b44579bec311d90ce102f9f19efdad69ad8 Mon Sep 17 00:00:00 2001 From: cholt0425 Date: Thu, 28 Dec 2017 09:31:30 -0500 Subject: [PATCH 2/2] Added triangleInv unit test Added a unit test to test out that having a point with style "triangleInv" draws and inverted triangle. --- test/specs/element.point.tests.js | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/specs/element.point.tests.js b/test/specs/element.point.tests.js index f09b912d3c0..996aa7e391d 100644 --- a/test/specs/element.point.tests.js +++ b/test/specs/element.point.tests.js @@ -181,6 +181,42 @@ describe('Point element tests', function() { args: [] }]); + mockContext.resetCalls(); + point._view.pointStyle = 'triangleInv'; + point.draw(); + + expect(mockContext.getCalls()).toEqual([{ + name: 'setStrokeStyle', + args: ['rgba(1, 2, 3, 1)'] + }, { + name: 'setLineWidth', + args: [6] + }, { + name: 'setFillStyle', + args: ['rgba(0, 255, 0)'] + }, { + name: 'beginPath', + args: [] + }, { + name: 'moveTo', + args: [10 - 3 * 2 / Math.sqrt(3) / 2, 15 - 3 * 2 / Math.sqrt(3) * Math.sqrt(3) / 2 / 3] + }, { + name: 'lineTo', + args: [10 + 3 * 2 / Math.sqrt(3) / 2, 15 - 3 * 2 / Math.sqrt(3) * Math.sqrt(3) / 2 / 3], + }, { + name: 'lineTo', + args: [10, 15 + 2 * 3 * 2 / Math.sqrt(3) * Math.sqrt(3) / 2 / 3], + }, { + name: 'closePath', + args: [], + }, { + name: 'fill', + args: [], + }, { + name: 'stroke', + args: [] + }]); + mockContext.resetCalls(); point._view.pointStyle = 'rect'; point.draw();