At Ideas2IT, we love getting our hands dirty to explore tech stacks and what we could do with them. Think of it as internal PoCs that we do all the time for fun! Very recently, we caught ourselves wondering if Paper.JS could be used for plotting graphs. Here’s what we found out.
What is Paper.JS?
Paper.js is an open-source vector graphics scripting framework that runs on top of the HTML5 Canvas. Rather than being a simple wrapper around the Canvas, it offers much more:
- A Scene Graph / Document Object Model for vector graphics: Works with nested layers, groups, paths, compound paths, rasters, symbols, etc.
- The handling and drawing of these graphic items is automatic and optimized, allowing you to construct or modify your items and styles and leave the drawing commands to Paper.js.
- A well-designed and battle-hardened Application Programming Interface (API).
- PaperScript, a simple extension of JavaScript, allows the scoped execution of scripts without polluting the global scope, the execution of multiple scripts per page in their separate sand-boxed scopes while sharing the library code and adding support for operator overloading to any object.
- There is a good reason for the word Vector in Vector Graphics. Paper.js treats Vector Mathematics as a first-class citizen by making working with vectors and geometries as simple as possible through its core types such as Point, Size, and Rectangle. The manipulation of Point and Size objects is further simplified in PaperScript, where direct math operations using normal operator syntax are possible on such objects as if they were plain numbers.
- Construct paths and manipulate their curves and segments in very convenient and fine-grained ways.
- Inspect and manipulate the precise bounding box of any item, supporting complicated stroke styles with different stroke ends and miter limits.
- Smoothen curves, and simplify path segments by fitting curves through points.
- Simulate dashed strokes that are currently lacking from the Canvas object, at near-native drawing speed.
- Most blend modes known from Illustrator and Photoshop are supported through emulation in JavaScript: multiply, screen, overlay, soft-light, hard-light, color-dodge, color-burn, darken, lighten, difference, exclusion, hue, saturation, luminosity, color, add, subtract, average & negation.
- To start working with Paper.js, check this >> http://paperjs.org/tutorials/getting-started/working-with-paper-js/
What is JSXGraph?
JSXGraph is a cross-browser JavaScript library for interactive geometry, function plotting, charting, and data visualization in the web browser. JSXGraph is implemented in pure JavaScript, does not rely on any other library, and uses SVG, VML, or canvas. JSXGraph is easy to embed and has a small footprint: approx. 160 KByte if embedded in a web page. No plug-ins are required! Special care has been taken to optimize the performance. JSXGraph supports multi-touch events and runs on all major browsers, even on very old IEs. To try out JSXGraph, check this link >>https://github.com/jsxgraph/jsxgraph
JSXGraph vs Paper.js
Functionality
JSXGraph can perform dynamic mathematics with JavaScript. While Paper.js offers a lot of powerful functionalities to create and work with vector graphics and bezier curves.
UI-UX Form Factor
JSXGraph is a simulation of graph paper with interaction.This contains all mathematics methods to plot a graph with accurate values. Eg: Parallel, Perpendicular, Axis, Curve, and Ellipse.
Paper.js is a simulation of the Adobe Illustrator app with interaction. It does not have methods for complex mathematic operations.
Functionality
- JSXGraph is a good tool for complex graph plotting.
- It contains all mathematical methods to plot a graph with accurate values. Eg: Parallel, Perpendicular, Axis, Curve, and Ellipse.
- It does not have complex animation functionality, or blend modes features.
- Paper.js on the other hand is ideal for 2D Illustrations with interactions.
- It does not have methods for complex mathematic operations.
- Like Adobe Illustrator, Paper.js contains many features for vectors like blend mode, curves, etc
Our Verdict on their Graph Plotting Capabilities
Usually, graph plotting requires a tech stack to support complex mathematic operations.In Paper.js, the coordinate system keeps changing dynamically. Making it difficult to plot graphs accurately. Paper.js does not have built-in methods for many operations.Whereas JSXGraph seems to be the tool built for the purpose.
Love our technical blogs?
Here are a few more for you to much on.
- Step-by-step guide to set up a comprehensive Playwright Test Automation Framework using Page Object model
- How to implement Fillable PDF in Web applications using Java & Angular
- How to delete records from MongoDB using Glue Job
- Use Spring Cloud Config to centralize your Spring applications
About Ideas2IT,
Are you looking to build a great product or service? Do you foresee technical challenges? If you answered yes to the above questions, then you must talk to us. We are a world-class custom .NET development company. We take up projects that are in our area of expertise. We know what we are good at and more importantly what we are not. We carefully choose projects where we strongly believe that we can add value. And not just in engineering but also in terms of how well we understand the domain. Book a free consultation with us today. Let’s work together.