npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphpaper-ui

v42.2.0

Published

[![CircleCI](https://circleci.com/gh/aautar/graphpaper.svg?style=svg)](https://circleci.com/gh/aautar/graphpaper)

Downloads

318

Readme

GraphPaper

CircleCI

GraphPaper is a library for creating 2D interactive workspaces in web application. It isn't an out-of-the-box solution, a lot of implementation details are pushed to consumers. GraphPaper serves as a foundation for handling user interactions and transformation of objects, but markup and styling of those objects are left to the caller whenever possible.

GraphPaper was an offshoot of ScratchGraph, and is one of its core dependencies.

GraphPaper is very much a work-in-progress, expect major, breaking, changes to the public API. That said, releases are semantically versioned, with major releases are tagged appropriately, so things should not unexpectedly break if consumed appropiately.

Documentation

Concepts

Working with Sheets

Entities

Connectors

  • Connectors (TBD)

Clusters

  • Clusters (TBD)

Quick Start: Sheets & Entities

Sheets are workspaces. Entities are things that live and can be manipulated within Sheets.

graphpaper-connector

Create a Sheet

Everything GraphPaper deals with is encapsulated on a Sheet. A sheet is a surface where GraphPaper entities can be added and actions on those entities can be performed.

To create a Sheet, we'll first need a DOM element with some basic styling:

<!DOCTYPE html>
<html>
    <head>
        <title>GraphPaper Demo</title>
        <script src="../dist/graphpaper.js" type="text/javascript"></script>
        <style type="text/css">
            * { margin:0; padding:0; font-family:LatoRegular; font-size:14px; font-weight:normal; box-sizing:border-box; }
            html, body { width:100%; height:100%; }
            body { background:#fff; }

            #sheet {
                border:0px solid #f00; 
                width:1000px; 
                height:1000px; 
                overflow:hidden; 
                position:relative; 
                transform-origin:0 0;
            }

        </style>
    </head>

    <body>
        <div id="sheet"></div>
    </body>
</html>

Now we can create the GraphPaper.Sheet object:

const sheet = new GraphPaper.Sheet(
    document.getElementById('sheet'),   // DOM element of the Sheet
    window                              // parent window 
);

The sheet will be created with the default, 12x12, dotted grid (note that this is one instance where GraphPaper does take control of some styling, as the grid requires dynamic generation of an SVG image).

The sheet will be created and rendered. Now we can add entities to the sheet.

Create an entity

Entities are things which live on the sheet. GraphPaper can handle interactions with entities, taking responsibility for transformations, computing and rendering connectors between entities, selecting and transforming a set of entities, etc.

Let's create a simple entity that we can translate on the sheet. We'll update the page to add a <div> for the entity, another <div> that'll serve as a handle (the thing you click on and drag to move the entity) for translation, and some styles for both.

<!DOCTYPE html>
<html>
    <head>
        <title>GraphPaper Demo</title>
        <script src="../dist/graphpaper.js" type="text/javascript"></script>
        <style type="text/css">
            * { margin:0; padding:0; font-family:LatoRegular; font-size:14px; font-weight:normal; box-sizing:border-box; }
            html, body { width:100%; height:100%; }
            body { background:#fff; }

            #sheet {
                border:0px solid #f00; 
                width:1000px; 
                height:1000px; 
                overflow:hidden; 
                position:relative; 
                transform-origin:0 0;
            }

            #entity1 { 
                display:flex; 
                align-items:center; 
                justify-content:center; 
                position:absolute; 
                width:52px; 
                height:52px; 
                background:#fff; 
                border:1px solid #0094ff; 
                border-radius:4px; 
            }

            #translateHandle { 
                cursor:move; 
                display:block; 
                width:12px; 
                height:12px; 
                background:#0094ff; 
                border-radius:12px; 
            }

        </style>
    </head>

    <body>
        <div id="sheet">
            <div id="entity1">
                <div id="translateHandle"></div>
            </div>
        </div>
    </body>
</html>

Now let's create the GraphPaper.Entity object (note that units for size and positioning are CSS pixels) :

const entity = new GraphPaper.Entity(
    'gp-entity-001',                                    // id
    0,                                                  // x        
    0,                                                  // y
    44,                                                 // width
    44,                                                 // height
    sheet,                                              // parent GraphPaper.Sheet
    document.getElementById('entity1'),                 // DOM element for the entity
    [document.getElementById('translateHandle')],       // DOM elements for the object's translation handles
    []                                                  // DOM elements for the object's resize handles
);

... and add this entity to our sheet:

sheet.addEntity(entity);

The translate handle won't do anything yet. There's one final step, we need to tell the sheet that it should listen for and handle transformations, this is done via:

sheet.initTransformationHandlers();

Now you can drag the entity around the canvas by dragging translateHandle, either via a mouse or touch interaction. The entity will automatically snap to the grid on the sheet.