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

rulez-fork

v0.3.8

Published

Javascript library for showing svg customizable rulers

Downloads

9

Readme

#Rulez.js Tihs is fork of rulez.js Rulez.js is a javascript library for showing svg based customizable rulers. It generates divisions and texts once and only for visible area.

The only difference: duplicating gaps are not stacked, the higher the element, the higher the priority

##Instalation

npm install rulez-fork

##Usage

###Basic usage

Horizontal ruler

var someSvgElement = document.getElementById('someSvgElementId');
var rulez = new Rulez({
    element: someSvgElement,
});
rulez.render();

Vertical ruler

var someSvgElement = document.getElementById('someSvgElementId');
var rulez = new Rulez({
    element: someSvgElement,
    layout: 'vertical'
});
rulez.render();

###Alignment

Every horizontal ruler can be aligned to top or bottom (default is 'top'):

var someSvgElement = document.getElementById('someSvgElementId');
var rulez = new Rulez({
    element: someSvgElement,
    alignment: 'bottom'
});
rulez.render();

Every vertical ruler can be aligned to left or right (default is 'left'):

var someSvgElement = document.getElementById('someSvgElementId');
var rulez = new Rulez({
    element: someSvgElement,
    layout: 'vertical'
    alignment: 'left'
});
rulez.render();

###Customizing rulers Internally rulez.js use default config, but you can override it by passing more parameters in constructor. There is only one limitation to remember : maximum pixelGap used for divisions must be dividable by all other pixelGaps (pixelGaps of texts are included also). For example, next config is ok:

var rulez = new Rulez({
    ...
    divisions: [
        {
            pixelGap: 25,
            lineLength: 10
        },
        {
            pixelGap: 100,
            lineLength: 20
        }
    ],
    texts: [
        {
            pixelGap: 5
        },
        {
            pixelGap: 25
        },
        {
            pixelGap: 50
        }
    ]
});

max pixelGap of divisions is 100 and it's dividable by every other pixelGap used in config(25, 5, 25, 50). Ruler with the next one config may be rendered incorrectly if scrollTo method is used:

var rulez = new Rulez({
    ...
    divisions: [
        {
            pixelGap: 25,
            lineLength: 10
        },
        {
            pixelGap: 100,
            lineLength: 20
        }
    ],
    texts: [
        {
            pixelGap: 6
        },
        {
            pixelGap: 25
        },
        {
            pixelGap: 50
        }
    ]
});

max pixelGap of divisions is 100 and it's NOT dividable by 6.

####Specifying units By default rulez.js uses 'user' units(px). This can be changed by specifying units param in config. Possible values for units: 'em', 'ex', 'px', 'pt', 'pc', 'cm', 'mm', 'in' and ''(user units) svg units spec. Note that those units will be used for all params for divisions and texts(pixelGap, lineLength, strokeWidth, etc).

var rulez = new Rulez({
    units: 'pt'
});

Units conversion rate (how many pixels is in one specified unit) can be retrieved using method getUnitConversionRate

var rulez = new Rulez({
    units: 'pt'
});
var unitsConversionRate = rulez.getUnitConversionRate();

####Customizing divisions Divisions can be changed by providing array of divisions config objects

var rulez = new Rulez({
    ...
    divisions: [
        {
            pixelGap: 25,
            lineLength: 10
        },
        {
            pixelGap: 100,
            lineLength: 20
        }
    ]
});

The code above means that ruler will be created with two different division types:

  1. Long ones(20px) with big gap between them(100px).
  2. Short ones(10px) with small gap between them(25px)

Other parameters that can be changed are

    strokeWidth : 1,// width of division
    className: 'someClassName',// css class applied to every division
    type: 'rect',// 'rect' or 'line': type of svg element used to render division
    renderer: function(division){// function that is called when division is added to ruler
      division.doSomething();
    }

####Customizing texts

Texts can be changed by providing array of texts config objects

var rulez = new Rulez({
    ...
    texts: [
        {
            pixelGap: 50
        },
        {
            pixelGap: 100
        }
    ]
});

The code above means that ruler will be created with two different texts types:

  1. Texts with big gap between them(100px).
  2. Texts with smaller gap between them(50px)

Other parameters that can be changed are

className: 'someClassName'// css class applied to every text
offset: 20,//offsets of texts in pixels
rotation:90,//rotation in degrees of texts
showUnits:true,//Wherever to show or not to show units alongside text
renderer: function(text){// function that is called when text is added to ruler
  text.doSomething();
}

####Default configs It's possible to use default configs that will used for all texts and divisions if they not specify parameters on their own. Any parameters that can be used for divisions or texts are also applicable for default configs.

divisionDefaults: {
    strokeWidth: 1,
    type: 'rect',
    className: 'rulez-rect'
},
textDefaults: {
    rotation: 0,
    offset: 25,
    className: 'rulez-text'
}

###Scrolling rullers to a specific position Every ruller can be scrolled to a specific position by using

ruler.scrollTo(<left (top for vertical rulers) position in pixels>, {boolean} useUnits);
/* example */
ruler.scrollTo(100);

###Resizing If width(height for vertical) is increased you'll need to resize ruler by calling resize method.

ruler.resize();

###Scaling For scaling of ruler method setScale can be used. Internally it multiples text's value by provided scaleValue.

ruler.setScale(<left (top for vertical rulers) position in pixels>);
/* example */
ruler.setScale(100);

###Text centering Starting from v0.1.0 text elements are centered by default.

textDefaults: {
    rotation: 0,
    offset: 25,
    className: 'rulez-text',
    centerText: true
}

Possible values for 'by':

  • 'width' - calculations are made by accessing textElement.getBoundingClientRect().width property
  • 'height' - calculations are made by accessing textElement.getBoundingClientRect().height property Possible values for 'operation':
  • 'sum' textElement.getBoundingClientRect()[by]/2 will be added to original position
  • 'sub' textElement.getBoundingClientRect()[by]/2 will be subtracted from original position

###Saving as image Ruler can be saved as image(png base64)

rulezH.saveAsImage(function(resultImg){
    var img = new Image();
    img.src = resultImg;
    document.body.appendChild(img);
});

MIT License.