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

@websy/tubemap-viz

v1.0.0

Published

The map is a work in progress but feel free to use, abuse and contribute. Enjoy.

Downloads

2

Readme

tubemap-viz

An HTML5 Canvas based visualisation that lets you represent data in the style of a Tube/Metro map.

The map is a work in progress but feel free to use, abuse and contribute. Enjoy.

Example:

alt text

Setup

Load the TubeMapViz library into your webpage

<script src='https://rawgit.com/websy85/tubemap-viz/master/dist/tube-map-viz.js'></script>

Example Usage

Create an element to use as the map parent

<div id="mapContainer" style="width:800; height:600px;"></div>

Create a new instance of TubeMapViz

var myTubeMap = new TubeMapViz();

Using the sample data provided, call the render() function to draw the map

myTubeMap.render(myTubeMap.sampleData, document.getElementById("mapContainer"));

Data Structure

The data expected by the map is an array of objects structured like this

{
  "name": String, (required)
  "colour": String, //if set overrides the colours property in the map options
  "stations": Array (required) [
    {
      "name": String (required),
      "status": Number, //1 - default || 0 - draws an inactive line either side of the station using the specified 'inactiveColour'
      "distanceToNext": Number, //if set is used to determine the distance between this and the next station. a scale is created using the min and max values.
      "custom": {
        "fill": String, //overrides the station fill colour
        "stroke": String, //overrides the station stroke colour
        "scale": Number, //scales the station by the specified scale
        "image": String, (url) //allows an image to be used to represent the station
        "imageSize": Number, //specifies the diameter of the image used
        "drawLabel": Boolean  //if true then the label for the station is not drawn
      }
    }
  ]
}

Options

When creating a new instance of TubeMapViz a configuration object can be passed in.

var options = {
  fontSize: 14
}
var myTubeMap = new TubeMapViz(options);

Options can also be set after creation

myTubeMap.fontSize = 14;

The following is a list of available options

{
  "debug": Boolean, //defaults to false;
  "disableHighlighting": Boolean, //defaults to false. if true stations will not 'popout' on mouseover;
  "padding": Number,  //defaults to 30;
  "stationRadius": Number,  //defaults to 8;
  "lineWidth": Number,  //defaults to 5;
  "lineSpacing": Number,  //defaults to 5;
  "colours": Array, // defaults to ["#ff7373","#ffd546","#d47dbe","#68b5de","#86ae22"].
  "labelLineHeight": Number,  //defaults to 13;
  "labelColour": String,  //defaults to "black";
  "labelWrapThreshold": Number, //defaults to 4 cells. cell size is equal to 2 x stationRadius;
  "fontSize": Number, //defaults to 10;
  "fontFamily": String, //defaults to "Arial";
  "fontWeight": String, //defaults to "Normal";
  "highlightScale": Number, //defaults to 1.3;
  "inactiveColour": String, //defaults to "#DDDDDD";
  "stationColour": String,  //defaults to "black";
  "stationThickness": Number, //defaults to lineWidth;
  "stationClicked": Function, //
  "showLegend": Boolean,  //defaults to true;
  "customLegend": Array [ //allows you to provide a custom legend
    {
      "name": String,
      "colour": String
    }
  ],
  "legendFontSize": Number, //defaults to fontSize;
  "legendFontWeight": String, //defaults to fontWeight;
  "legendFontColour": String, //defaults to labelColour;
  "legendBackgroundColour": String, //defaults to "rgba(255,255,255,0.7)";
  "zoomControlBackgroundColour": String,  //defaults to "#888";
  "allowZoom": Boolean, //defaults to true. if true zoom controls are visible;
  "zoomToFit": Boolean //defaults to true. only active if allowZoom is also true;
}

Methods

stationClicked: function(station){
  //allows you to add custom behaviour to the stationClicked event
  //the supplied station object has the following properties
  {
    "name": String, 
    "status": Number, 
    "mode": String
  } 
}

Rendering Logic

*To calculate station positions a virtual grid is created where the size of a cell is equal to 2 * stationRadius *Lines are drawn in the same order they are provided *Lines will always draw from left to right *Where a line cannot continue in a given horizontal direction it will look for an alternative vertical route, starting in a downward direction *Lines are only drawn horizontally and vertically *Multiple lines that share 2 or more consecutive stations will be drawn parallel *Lines do not pass through reserved space (e.g. labels, stations and other lines)