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

drawbetween

v1.0.1

Published

Draw images and shapes on the specified line segment

Downloads

93

Readme

drawbetween.js

A JavaScript library for drawing images and shapes on the specified line segment.

NPM Version Downloads Stats

Demo

https://higuri.github.io/drawbetween.js/sample/

Installation

via NPM

npm install drawbetween
# or...
yarn add drawbetween

CommonJS

const DrawBetween = require('drawbetween');

ES Module

import DrawBetween from 'drawbetween';

via CDN

<script scr="https://unpkg.com/drawbetween"></script>

Usage Example

HTML

<div id="canvas" style="width:300px; height:150px"></div>

JavaScript

const canvas = document.querySelector('#canvas');
const draw = new DrawBetween(canvas);

// draw images between (0,0) and (250,0).
const imageUrl = 'YOUR_IMAGE_URL';
draw.images({x: 0, y: 0}, {x: 250, y: 0}, imageUrl);

// draw rects with default options.
draw.rects({x: 0, y: 40}, {x: 250, y: 40});

// draw cross marks with custom options.
draw.crossMarks({x: 10, y: 80}, {x: 260, y: 80}, {
  minInterval: 40,
  strokeColor: '#f00',
  strokeWidth: 3
});

// draw custom paths.
const drawer = (ctx, p) => {
  ctx.beginPath();
  ctx.arc(p.x, p.y, 10, 0, 2 * Math.PI);
  ctx.fillStyle = '#0af';
  ctx.fill();
};
draw.withDrawer({x: 10, y: 110}, {x: 260, y: 110}, drawer, {
  minInterval: 35
});

CodePen

https://codepen.io/higuri/pen/jJNNmB

API

new DrawBetween(targetDiv)

Create a new DrawBetween object.

  • targetDiv: Element - a reference to <div> to be drawn.

line(p0, p1, options)

Draw a straight line between p0 and p1.

  • p0: {x: number, y: number} - a start point of line.
  • p1: {x: number, y: number} - an end point of line.
  • options:
    • width: number - line width. <default: 1>
    • strokeColor: string - line color. <default: '#000'>
    • lineDash: number[] - distances to alternately draw a line and a gap. See CanvasRenderingContext2D.setLineDash() for details. <default: [0, 0]>

images(p0, p1, imageUrl, options)

Draw images on the specified line segment.

  • p0: {x: number, y: number} - a start point of the line segment.
  • p1: {x: number, y: number} - an end point of the line segment.
  • imageUrl: string - a full URL of image to draw.
  • options:
    • width: 'original' | number - image width. <default: 'original'>
    • height: 'original' | number - image height. <default: 'original'>
    • rotate: 'auto' | number - rotation andgle in radians. <default: 'auto'>
    • minInterval: number - minimum spacing between adjacent images. <default: 0>
    • borderColor: string - border color of image. <default: '#000'>
    • borderWidth: number - border width of image. <default: 0>

rects(p0, p1, options)

Draw rectangles on the specified line segment.

  • p0: {x: number, y: number} - a start point of the line segment.
  • p1: {x: number, y: number} - an end point of the line segment.
  • options:
    • width: number - rectangle width. <default: 20>
    • height: number - rectangle height. <default: 20>
    • rotate: 'auto' | number - rotation andgle in radians. <default: 'auto'>
    • minInterval: number - minimum spacing between adjacent rectangles. <default: 0>
    • strokeColor: string - stroke color of rectangle. <default: '#000'>
    • strokeWidth: number - stroke width of rectangle. <default: 0>
    • fillColor: string - fill color of rectangle. <default: '#000'>

circles(p0, p1, options)

Draw circles on the specified line segment.

  • p0: {x: number, y: number} - a start point of the line segment.
  • p1: {x: number, y: number} - an end point of the line segment.
  • options:
    • radius: number - circle radius. <default: 10>
    • minInterval: number - minimum spacing between adjacent circles. <default: 0>
    • strokeColor: string - stroke color of circle. <default: '#000'>
    • strokeWidth: number - stroke width of circle. <default: 0>
    • fillColor: string - fill color of circle. <default: '#000'>

crossMarks(p0, p1, options)

Draw cross marks on the specified line segment.

  • p0: {x: number, y: number} - a start point of the line segment.
  • p1: {x: number, y: number} - an end point of the line segment.
  • options:
    • lineLength: number - line length of cross mark. <default: 20>
    • rotate: 'auto' | number - rotation andgle in radians. <default: 'auto'>
    • minInterval: number - minimum spacing between adjacent cross marks. <default: 0>
    • strokeColor: string - stroke color of cross mark. <default: '#000'>
    • strokeWidth: number - stroke width of cross mark. <default: 0>

triangles(p0, p1, options)

Draw triangles on the specified line segment.

  • p0: {x: number, y: number} - a start point of the line segment.
  • p1: {x: number, y: number} - an end point of the line segment.
  • options:
    • edgeLength: number - edge length of triangle. <default: 20>
    • rotate: 'auto' | number - rotation andgle in radians. <default: 'auto'>
    • minInterval: number - minimum spacing between adjacent triangles. <default: 0>
    • strokeColor: string - stroke color of triangle. <default: '#000'>
    • strokeWidth: number - stroke width of triangle. <default: 0>
    • fillColor: string - fill color of triangle. <default: '#000'>

withDrawer(p0, p1, drawer, options)

Draw specified paths on the specified line segment.

  • p0: {x: number, y: number} - a start point of the line segment.
  • p1: {x: number, y: number} - an end point of the line segment.
  • drawer: ((ctx: CanvasRenderingContext2D, p: {x: number, y: number}) => void) - drawing function.
  • option:
    • minInterval: number - minimum spacing between adjacent paths. <default: 0>

clear()

Clear all drawings of the instance.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.