• Stars
    star
    157
  • Rank 238,399 (Top 5 %)
  • Language
    HTML
  • License
    BSD 3-Clause "New...
  • Created about 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Draw tube maps in the style of the London Underground using d3

d3-tube-map

Build Status

Draw tube maps in the style of the London Underground using d3.

See a demo on bl.ocks.org or Observable.

Screenshot

A word of warning. This was created to scratch my own itch (Cambridge Pub Map). It works, but can be difficult to work with. That said, here are examples of other people creating awesome visualizations:

Installing

If you use NPM, npm install d3-tube-map. Otherwise, download the latest release. AMD, CommonJS, and vanilla environments are supported. In vanilla, a d3 global is exported:

<script src="https://d3js.org/d3.v6.js"></script>
<script src="../dist/d3-tube-map.js"></script>

<script>
  var container = d3.select("#tube-map");

  var width = 1600;
  var height = 1024;

  var map = d3
    .tubeMap()
    .width(width)
    .height(height)
    .margin({
      top: height / 50,
      right: width / 7,
      bottom: height / 10,
      left: width / 7,
    });

  d3.json("./pubs.json").then(function (data) {
    container.datum(data).call(map);
  });
</script>

API Reference

# d3.tubeMap() <>

Constructs a new tube map generator with the default settings.

# tubeMap(selection) <>

Render the tube map to the given selection, which is a selection.

# tubeMap.width(w) <>

Sets the width of the viewbox the map is rendered to.

# tubeMap.height(h) <>

Sets the height of the viewbox the map is rendered to.

# tubeMap.margin(m) <>

Sets the margin around the map. Takes an object of the following form:

{ top: 10, right: 20, bottom: 10, left: 20 }

Input Data Format

The data passed to the tube map should have the following properties: stations, lines and optionally river. A minimal example is shown below.

{
  "stations": {
    "StationA": {
      "label": "Station A"
    },
    "StationB": {
      "label": "Station B"
    }
  },
  "lines": [
    {
      "name": "LineA",
      "color": "#FF0000",
      "shiftCoords": [0, 0],
      "nodes": [
        {
          "coords": [23, -4],
          "name": "StationA",
          "labelPos": "N"
        },
        {
          "coords": [30, -4]
        },
        {
          "coords": [31, -3],
        },
        {
          "coords": [31, 2],
          "name": "StationB",
          "labelPos": "E"
        }
      ]
    }
  ]
}

stations is an object where each property is a a station with the key being a unique identifier and the value being an object with a label property. The label is the display friendly text that will be rendered to the screen.

lines is an array of line objects. Each line must have the following:

  • name will be used as the id of the svg path element
  • color is simply the color of the line
  • shiftCoords will translate the whole line in the x and y directions
  • nodes is an array of nodes which define the layout of the line

A line may optionally also define:

  • shiftNormal will offset the line along the direction of its normal vector

Each node must have the following:

  • coords is the position of the node. Must be integer values
  • name should be present if the node represents a station. It should match a station defined in the top-level stations property
  • labelPos should be present if the node represents a station. It is a compass direction and determines where the label is positioned relative to the node, e.g. NE would place the label up and to the right of the node

Corners

Two types of corner are supported: a 90 degree turn and a 45 degree turn. The latter is recognised when the position of a node differs from the position of the previous node by either:

  • 1 in the x direction and 2 in the y direction
  • 2 in the x direction and 1 in the y direction

For example:

[
  {
    "coords": [-27, -11]
  },
  {
    "coords": [-26, -9]
  }
]

A 90 degree turn is recognised when the position of a node differs from the position of the previous node by:

  • 1 in the x direction and 1 in the y direction

For example:

[
  {
    "coords": [0, 2]
  },
  {
    "coords": [1, 1],
  }
]

More Repositories

1

allotment

A React component for resizable split views
TypeScript
673
star
2

d3-simple-slider

A simple interactive SVG slider
JavaScript
91
star
3

compare-image-slider

Compare two images with a slider
TypeScript
15
star
4

d3-bumps-chart

A d3 plugin for visualizing bumps charts
JavaScript
14
star
5

bumps-results

Cambridge and Oxford Bumps results
4
star
6

react-bumps-chart

Rowing Bumps charts
JavaScript
4
star
7

risk-jargon-generator

Risk jargon generator
JavaScript
3
star
8

react-rowing-blades

Library of rowing clubs' blades
TypeScript
2
star
9

bumps

Website for www.cambridgebumps.com
JavaScript
2
star
10

vsts-publish-html-artifact

Publish any HTML artifact in VSTS or TFS
JavaScript
2
star
11

jargon-generator

Jargon generator
JavaScript
2
star
12

react-pub-map

Map of pubs in Cambridge in the style of the iconic London Underground map
JavaScript
2
star
13

coxing-recordings

Coxing recordings
TypeScript
1
star
14

Penny

Thought record
JavaScript
1
star
15

data-viz-resources

Data visualization resources
1
star
16

hacker-news

Android and ios clients for Hacker News
JavaScript
1
star
17

coxswain-simulator-2012

JavaScript
1
star
18

bumps-results-tools

Tools for working with bumps results data
JavaScript
1
star
19

provision-octopus-deploy

Provision a sample Octopus Deploy server and tentacle
C#
1
star
20

react-native-tony-facts

Tony Facts
JavaScript
1
star
21

strokeme

Basic rowing stroke-rate app for Android
Java
1
star
22

deadweight-python

Web page which tells you how much time any deadweight in our boat is costing you
Python
1
star
23

johnwalley-wordpress-theme

Wordpress theme for www.walley.org.uk
PHP
1
star
24

inspector-oars

Rowing blade quiz
JavaScript
1
star
25

matlab-examples

MATLAB examples
MATLAB
1
star
26

www-walley-org-uk

My Website
CSS
1
star
27

johnwalley.github.com

Homepage
CSS
1
star
28

cambridgebumps.com

JavaScript
1
star
29

pub-tube-map

Map of pubs in Cambridge in the style of the iconic London Underground map
JavaScript
1
star
30

cambridge-bumps-website

Website for Cambridge and Oxford bumps results
JavaScript
1
star