
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
scrawl-canvas
Advanced tools
Version: 8.0.5 - 11 April 2020.
Scrawl-canvas website: scrawl.rikweb.org.uk.
Do you want to contribute? I've been developing this project for too long by myself, and would really welcome contributions from - even collaboration with - people who can bring a different perspective and a fresh set of eyes to the work.
Scrawl-canvas is a JavaScript library for working with the HTML5 <canvas> element. The library:
There are a number of other Javascript libraries available, each with their strengths and weaknesses. Some have been designed to make the production of charts and other data visualisations easier. Some focus on game development, others on making videos interactive. Libraries which attempt to emulate Flash/Actionscript animations have been developed, as have libraries whose aim is to combine 2D, 3D and even SVG graphics into a usable whole. Speed is a key goal for some of the best libraries, while ease-of-use is an objective for many others.
Working with the native Canvas API is hard work - particularly when the desired result is more complex than a couple of coloured boxes in a static display.
But the benefits of using canvases for graphical displays and animations are also great: canvases are part of the DOM (unlike Flash); they are natively wired for events and user interactions; they use immediate mode redering (which makes them very quick); and the canvas-related APIs are designed to be used with Javascript.
Yet these advantages are also significant barriers:
Yes, Scrawl-canvas aims to be fast, and developer-friendly. It also aims to be broadly focussed, suitable for building infographics, games, interactive videos - whatever we can imagine for a 2D graphical presentation.
But the main purpose of Scrawl-canvas is to make the <canvas> element, and the parts that make up its displays and animations, responsive, interactive, linkable, trackable. And accessible!
There are two main ways to include Scrawl-canvas in your project:
Alternatively, a zip package of the v8.0.4 files can be downloaded from this link: scrawl.rikweb.org.uk/downloads/scrawl-canvas_8-0-4.zip - this package only includes the minified files.
<!-- Hello world -->
<!DOCTYPE html>
<html>
<head>
<title>Scrawl-canvas Hello World</title>
</head>
<body>
<canvas id="mycanvas"></canvas>
<!-- The library is entirely modular and needs to be imported into a module script -->
<script type="module">
import scrawl from './relative-or-absolute/path/to/scrawl-canvas/min/scrawl.js';
// Get a handle to the canvas element
let canvas = scrawl.library.canvas.mycanvas;
// Setup the scene to be displayed in the canvas
scrawl.makePhrase({
name: 'hello',
text: 'Hello, World!',
width: '100%',
startX: 20,
startY: 20,
font: 'bold 40px Garamond, serif',
});
// Render the canvas scene once
canvas.render()
.catch(err => {});
</script>
</body>
</html>
This approach is still experimental: Scrawl-canvas has been designed for use in the browser, not server-side. Add the library to a React/Vue/Svelte/etc project at your own risk - your mileage may vary!
// either
$> npm install scrawl-canvas
// or
$> yarn add scrawl-canvas
// then in your script file
import scrawl from 'scrawl-canvas';
// Scrawl-canvas has no dependencies
// - it can be used as-is, with no further installation steps required
After downloading the library and unzipping it into a directory or folder, cd into that folder on the command line and start a local server. For instance if you have http-server installed:
$> cd ./path/to/Scrawl-canvas
$> http-server
Starting up http-server, serving ./
Available on:
http://127.0.0.1:8080
http://192.168.0.4:8080
Hit CTRL-C to stop the server
Navigate to http://localhost:8080 to access the documentation and demo tests.
The code base does not include any unit testing frameworks. Instead, we rely on a set of Demo tests which allow us to perform integration testing and user interface testing.
Why this approach? Because most of the Scrawl-canvas functionality revolves around various forms of animation, which requires visual inspection of the Demo tests to check that the canvas display - and thus, by inference, the underlying code - performs as expected.
Most Demos include some form of user interaction, which allows us to test specific aspects of the code base.
The source code has been extensively commented. We generate documentation from that code using Docco - which has not been included in the GitHub repository and thus needs to be installed separately if you want to regenerate the documentation after making local changes to the source code.
We minify the source code using a small shell script, nothing more. When the library is added to a project using NPM or Yarn, the import statement will use the minified module files.
Developed by Rik Roots: rik.roots@rikworks.co.uk
FAQs
Responsive, interactive and more accessible HTML5 canvas elements. Scrawl-canvas is a JavaScript library designed to make using the HTML5 canvas element easier, and more fun
The npm package scrawl-canvas receives a total of 1,633 weekly downloads. As such, scrawl-canvas popularity was classified as popular.
We found that scrawl-canvas demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.