Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/configuration/elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
10 changes: 10 additions & 0 deletions src/helpers/helpers.canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
36 changes: 36 additions & 0 deletions test/specs/element.point.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down