Konva – HTML5 Canvas text measuring

A quick run through of some of the principles of working with text and breaking away from relying on textOut and Text object from the Konva HTML5 canvas library. I’m assuming you’ll know enough JavaScript to follow along. For dealing with text in the context of the HTML5 canvas there are two points to beContinue reading “Konva – HTML5 Canvas text measuring”

Konva – HTML5 Canvas viewport optimisation

When trying to squeeze every last morsel of optimisation out of a canvas app, we need to be concerned about NOT drawing anything we don’t need to. This means anything that the user cannot possibly see should not be drawn. I’ll be showing how to know a node is offscreen using the Konva HTML5 canvasContinue reading “Konva – HTML5 Canvas viewport optimisation”

Konva – HTML5 canvas coin spin effect

This is something I made for fun when I was learning about Konva tweens and animation, and posted as a self-answered question on StackOverflow. The coin spin effect is done by scaling the X axis of the circle from 1 to 0 to 1 in a loop. The human brain is defeated by the simpleContinue reading “Konva – HTML5 canvas coin spin effect”

Konva – HTML5 canvas manual route drawing solution

This is from a StackOverflow answer I made in response to a request for a way to show a route on a map with bends. In essence this is manipulation of the points array for a Konva Line object. The user selects a point via a mouse click and that point goes into the pointsContinue reading “Konva – HTML5 canvas manual route drawing solution”

Konva – HTML5 Canvas text on a path

The canvas does not yet provide the same level of character manipulation and measuring functions as we might find in the Windows GDI or similar. But it does give us canvas.measureText() to measure character size. Combine that with path.getPointAtLength() and we can fit text to a path. Measuring Text To have any chance to fitContinue reading “Konva – HTML5 Canvas text on a path”

Konva – HTML5 Canvas bottoms-up

Or, how to get the Y-axis to go bottom-up when the normal situation is for it to increase from the top-down. While we are at it, we’ll develop the bones of a plotting class. I’ll be developing my code with the use of the Konva JS canvas library which is a wrapper for the HTML5Continue reading “Konva – HTML5 Canvas bottoms-up”

Konva – shape transform sharing is simple

So you have a shape with some transforms applied – you need to apply the same transforms to another shape. How do you do that ? It turns out that Konva gives us a simple means to accomplish the challenge. We can get the first shapes transform with the shape.getTransform() method, then with a littleContinue reading “Konva – shape transform sharing is simple”

Konva – using a shape’s transform to rotate points

The Konva HTML5 canvas lib has a very useful feature that can spit out the transform applied to a shape, and which we can borrow to rotate points without math. The example below illustrates the use of rect’s transform to position the corner circles. Codepen here. What is a transform ? I couldn’t find aContinue reading “Konva – using a shape’s transform to rotate points”