Skip to content

Commit f78e3f2

Browse files
authored
Merge pull request #48 from conveyal/dev
Next release
2 parents 4ba541f + 6da5f26 commit f78e3f2

33 files changed

+12720
-5995
lines changed

.travis.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
sudo: false
22
language: node_js
33
cache:
4-
directories:
5-
- ~/.yarn-cache
4+
yarn: true
65
notifications:
76
email: false
87
node_js:
9-
- '6'
10-
before_install:
11-
- npm i -g yarn codecov
8+
- '10'
129
install:
1310
- yarn
1411
script:
1512
- npm run lint
1613
- npm run cover
17-
- codecov
1814
after_success:
19-
- yarn run semantic-release
15+
- bash <(curl -s https://codecov.io/bash)
16+
- semantic-release
2017
branches:
2118
except:
2219
- /^v\d+\.\d+\.\d+$/

lib/core/network.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const debug = require('debug')('transitive:network')
2-
31
import { forEach } from 'lodash'
42
import Emitter from 'component-emitter'
53

@@ -15,6 +13,8 @@ import Graph from '../graph/graph'
1513
import Polyline from '../util/polyline.js'
1614
import { sm } from '../util'
1715

16+
const debug = require('debug')('transitive:network')
17+
1818
/**
1919
* Network
2020
*/

lib/core/path.js

-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import d3 from 'd3'
2-
3-
import interpolateLine from '../util/interpolate-line'
4-
51
/**
62
* A path through the network graph. Composed of PathSegments (which
73
* are in turn composed of a sequence of graph edges)
@@ -34,27 +30,6 @@ export default class NetworkPath {
3430
}, this)
3531
}
3632

37-
/** highlight **/
38-
39-
drawHighlight (display, capExtension) {
40-
this.line = d3.svg.line() // the line translation function
41-
.x(function (pointInfo, i) {
42-
return display.xScale(pointInfo.x) + (pointInfo.offsetX || 0)
43-
})
44-
.y(function (pointInfo, i) {
45-
return display.yScale(pointInfo.y) - (pointInfo.offsetY || 0)
46-
})
47-
.interpolate(interpolateLine.bind(this))
48-
49-
this.lineGraph = display.svg.append('path')
50-
.attr('id', 'transitive-path-highlight-' + this.parent.getElementId())
51-
.attr('class', 'transitive-path-highlight')
52-
.style('stroke-width', 24).style('stroke', '#ff4')
53-
.style('fill', 'none')
54-
.style('visibility', 'hidden')
55-
.data([this])
56-
}
57-
5833
getRenderedSegments () {
5934
var renderedSegments = []
6035
this.segments.forEach(function (pathSegment) {

lib/display/canvas-display.js

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import roundedRect from 'rounded-rect'
2+
3+
import Display from './display'
4+
5+
export default class CanvasDisplay extends Display {
6+
constructor (transitive) {
7+
super(transitive)
8+
9+
const { el, canvas } = transitive.options
10+
11+
// Handle case of externally-provided canvas
12+
if (canvas) {
13+
// Set internal dimensions to match those of canvas
14+
this.setDimensions(canvas.width, canvas.height)
15+
this.setCanvas(canvas)
16+
17+
// We have a DOM element; create canvas
18+
} else if (el) {
19+
this.setDimensions(el.clientWidth, el.clientHeight)
20+
21+
const canvas = document.createElement('canvas')
22+
canvas.width = el.clientWidth
23+
canvas.height = el.clientHeight
24+
el.appendChild(canvas)
25+
26+
// Check for Hi-PPI display
27+
if (window.devicePixelRatio > 1) makeCanvasHiPPI(canvas)
28+
29+
this.setCanvas(canvas)
30+
}
31+
}
32+
33+
setCanvas (canvas) {
34+
this.canvas = canvas
35+
this.ctx = this.canvas.getContext('2d')
36+
}
37+
38+
clear () {
39+
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
40+
}
41+
42+
drawRect (upperLeft, attrs) {
43+
this.ctx.strokeStyle = attrs['stroke']
44+
this.ctx.lineWidth = attrs['stroke-width']
45+
this.ctx.fillStyle = attrs['fill']
46+
47+
this.ctx.beginPath()
48+
if (attrs.rx && attrs.ry && attrs.rx === attrs.ry) {
49+
roundedRect(this.ctx, upperLeft.x, upperLeft.y, attrs.width, attrs.height, attrs.rx)
50+
// TODO: handle case where rx != ry
51+
} else { // ordinary rectangle
52+
this.ctx.rect(upperLeft.x, upperLeft.y, attrs.width, attrs.height)
53+
}
54+
this.ctx.closePath()
55+
56+
if (attrs['fill']) this.ctx.fill()
57+
if (attrs['stroke']) this.ctx.stroke()
58+
}
59+
60+
drawCircle (center, attrs) {
61+
this.ctx.beginPath()
62+
this.ctx.arc(center.x, center.y, attrs.r, 0, Math.PI * 2, true)
63+
this.ctx.closePath()
64+
65+
if (attrs['fill']) {
66+
this.ctx.fillStyle = attrs['fill']
67+
this.ctx.fill()
68+
}
69+
if (attrs['stroke']) {
70+
this.ctx.strokeStyle = attrs['stroke']
71+
this.ctx.lineWidth = attrs['stroke-width'] || 1
72+
this.ctx.stroke()
73+
}
74+
}
75+
76+
drawEllipse (center, attrs) {
77+
// TODO: implement
78+
}
79+
80+
drawPath (renderData, attrs) {
81+
if (!renderData || renderData.length === 0) return
82+
83+
// Apply stroke/width styles
84+
this.ctx.strokeStyle = attrs['stroke']
85+
this.ctx.lineWidth = attrs['stroke-width']
86+
87+
// Apply line-dash style, if present
88+
if (attrs['stroke-dasharray']) {
89+
const arr = attrs['stroke-dasharray'].split(',').map(str => parseFloat(str.trim()))
90+
this.ctx.setLineDash(arr)
91+
}
92+
93+
// Apply linecap style
94+
this.ctx.lineCap = attrs['stroke-linecap'] || 'butt'
95+
96+
// Draw the path
97+
this.ctx.beginPath()
98+
this.ctx.moveTo(renderData[0].x, renderData[0].y)
99+
for (let i = 1; i < renderData.length; i++) {
100+
const rd = renderData[i]
101+
if (rd.arc) this.ctx.arcTo(rd.ex, rd.ey, rd.x, rd.y, rd.radius)
102+
else this.ctx.lineTo(rd.x, rd.y)
103+
}
104+
this.ctx.stroke()
105+
106+
// Revert line-dash style to default
107+
if (attrs['stroke-dasharray']) this.ctx.setLineDash([])
108+
}
109+
110+
drawText (text, anchor, attrs) {
111+
// For equivalence w/ SVG text rendering
112+
this.ctx.textBaseline = 'top'
113+
114+
this.ctx.font = `${attrs.fontSize || '14px'} ${attrs.fontFamily || 'sans-serif'}`
115+
if (attrs['text-anchor']) this.ctx.textAlign = attrs['text-anchor']
116+
117+
if (attrs['stroke']) {
118+
this.ctx.strokeStyle = attrs['stroke']
119+
if (attrs['stroke-opacity']) this.ctx.globalAlpha = attrs['stroke-opacity']
120+
this.ctx.lineWidth = attrs['stroke-width'] || 1
121+
this.ctx.strokeText(text, anchor.x, anchor.y)
122+
}
123+
if (attrs['fill']) {
124+
this.ctx.fillStyle = attrs['fill']
125+
if (attrs['fill-opacity']) this.ctx.globalAlpha = attrs['fill-opacity']
126+
this.ctx.fillText(text, anchor.x, anchor.y)
127+
}
128+
129+
this.ctx.textAlign = 'start'
130+
this.ctx.globalAlpha = 1
131+
}
132+
}
133+
134+
// Utility function to support HiPPI displays (e.g. Retina)
135+
function makeCanvasHiPPI (canvas) {
136+
const PIXEL_RATIO = 2
137+
canvas.style.width = canvas.width + 'px'
138+
canvas.style.height = canvas.height + 'px'
139+
140+
canvas.width *= PIXEL_RATIO
141+
canvas.height *= PIXEL_RATIO
142+
143+
var context = canvas.getContext('2d')
144+
context.scale(PIXEL_RATIO, PIXEL_RATIO)
145+
}

lib/display/d3.geo.tile.js

-57
This file was deleted.

0 commit comments

Comments
 (0)