Skip to content
pobchPublic

About

A diagram drawing web-app, built by React.js and HTML canvas

Topics

Resources

Stars

10 stars

Watchers

1 watching

Forks

Repository files navigation

Diaglam

A diagram drawing application which is demonstrating how we can utilize React.js and HTML <canvas/> to create an interactive drawing.

Application URL

https://draw.crispyscript.com (works best in desktop)

Demo

Demo.mp4

Feature Roadmap

  • Line drawing tool
  • Rectangle drawing tool
  • Pencil drawing tool(free-hand)
  • Selection tool for moving and resizing a single element
  • Undo/Redo/Clear
  • Text tool
  • Support deleting a selected element
  • Arrow drawing tool
  • Pan
  • Zoom
  • CSS & Styling
  • Mobile & Resizing friendly
  • Multi-select elements
  • Support uploading an image
  • Duplicate elements
  • Send to back/front
  • Save and import diagrams, including images, as .diaglam files
  • Limit max history stack to ~50 items
  • Export canvas to png/jpeg
  • Rotate
  • Keyboard shortcut
  • Setting stroke color
  • Setting stroke width
  • Filled rectangle
  • Copy & Paste elements (upgrade "Duplicate" feature)

Developer Notes

Start the app locally

Use Node.js 22.12+ and pnpm.

  1. Run pnpm install to install dependencies.
  2. Run pnpm run dev to start the app at http://localhost:3000.

Build and preview

Run pnpm run build to check TypeScript and create the production files in dist/.

Run pnpm run preview to serve the build locally at http://localhost:3000. Stop the development server first.

For a deployment under a subpath, use pnpm run build --base=/your-path/.

Run pnpm run typecheck to check TypeScript without a build.

Lint

Run pnpm run lint to check JavaScript, TypeScript, React, React Hooks, and Cypress code with Oxlint.

Run pnpm run lint:fix to apply available safe fixes.

Type-aware Oxlint rules need additional setup and are not enabled. pnpm run typecheck remains the TypeScript check.

Environment variables

.env sets the canonical URL and social metadata in index.html.

In application code, access client variables with import.meta.env.VITE_NAME.

Vite exposes variables with the VITE_ prefix to the browser. Do not put secrets in these variables.

Visual regression tests

The Cypress specs in cypress/e2e use cypress-visual-regression to compare screenshots.

Baselines are stored in cypress/snapshots/base/ (the last known good state).

Actual are stored in cypress/snapshots/actual/ (the result of the current test run).

Failed tests produce images in cypress/snapshots/diff/ (the differences between the baseline and actual).

  1. Start the app with pnpm run dev and leave it running at http://localhost:3000.

  2. In another terminal:

    # Compare the current app against the saved baselines.
    pnpm visual:test
  3. If the test fails, review the differences in cypress/snapshots/diff/

  4. If the changes are intentional, update the baselines. Pass --spec to replace only the baselines produced by that specific .cy.js file:

    pnpm run visual:baseline --spec cypress/e2e/rectangle.cy.js

    This replaces all snapshots captured by tests in rectangle.cy.js and leaves baselines for other spec files unchanged. If a spec contains multiple tests and you want to replace the snapshots for just one test, temporarily change that test's it(...) to it.only(...), run the command above for its spec, then remove .only before committing.

To test an app running at a different URL or test a single .cy.js file, pass --config baseUrl=<url> and/or --spec <file>:

pnpm run visual:test --config baseUrl=http://localhost:3001 --spec cypress/e2e/rectangle.cy.js

To replace ALL baselines after reviewing an intentional change:

# WARNING: We will lose all previous baselines!!
pnpm run visual:baseline

To open Cypress for interactive debugging (defaults to regression mode):

pnpm run cypress:open

Note:

  • Generate and compare baselines on the same OS and Cypress version to keep the rendering consistent.
  • Regression mode fails on missing baselines or visual differences and does not update baselines.

Icons

https://phosphoricons.com/

Naming Confusion

  • Most of x, y value are in scene coordinate (i.e. canvas coord, not viewport coord). They are inconsistency in naming. For example,
    // All of these variable names are in `scene` coord
    let sceneX, x1, x2, pointerX
  • However, the viewport coordinate is more consistency in naming.
    // There always be `viewport` keyword in `viewport` coord
    let viewportX

About

A diagram drawing web-app, built by React.js and HTML canvas

Topics

Resources

Stars

10 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages