Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | import d3 from 'd3' /** * Scales for utility functions to use */ const zoomScale = d3.scale.linear().domain([0.25, 1, 4]) const strokeScale = d3.scale.linear().domain([0.25, 1, 4]).range([5, 12, 19]) const fontScale = d3.scale.linear().domain([0.25, 1, 4]).range([10, 14, 18]) const notFocusedColor = '#e0e0e0' /** * Expose `utils` for the style functions to use */ const utils = { defineSegmentCircleMarker: function (display, segment, radius, fillColor) { const markerId = 'circleMarker-' + segment.getId() display.svg .append('defs') .append('svg:marker') .attr('id', markerId) .attr('refX', radius) .attr('refY', radius) .attr('markerWidth', radius * 2) .attr('markerHeight', radius * 2) .attr('markerUnits', 'userSpaceOnUse') .append('svg:circle') .attr('cx', radius) .attr('cy', radius) .attr('r', radius) .attr('fill', segment.focused ? fillColor : notFocusedColor) return 'url(#' + markerId + ')' }, fontSize: function (display) { return Math.floor(fontScale(display.scale)) }, pixels: function (zoom, min, normal, max) { return zoomScale.range([min, normal, max])(zoom) }, strokeWidth: function (display) { return strokeScale(display.scale) } } /** * Default Wireframe Edge/Vertex Rules */ const wireframeVertices = { cx: 0, cy: 0, fill: '#000', r: 3 } const wireframeEdges = { fill: 'none', stroke: '#444', 'stroke-dasharray': '3px 2px', 'stroke-width': 2 } /** * Default Merged Stops Rules */ const stopsMerged = { fill: function (display, point, index, utils) { return '#fff' }, /** * Transitive-specific attribute specifying any additional padding, in pixels, * to apply to main stop marker. A value of zero (default) results in a that * marker is flush to the edges of the pattern segment(s) the point is set against. * A value greater than zero creates a marker that is larger than the width of * the segments(s). */ 'marker-padding': 3, /** * Transitive-specific attribute specifying the shape of the main stop marker. * Can be 'roundedrect', 'rectangle' or 'circle' */ 'marker-type': [ 'circle', function (display, data, index, utils) { const point = data.owner if ( (point.containsBoardPoint() || point.containsAlightPoint()) && !point.containsTransferPoint() ) return 'circle' } ], r: function (display, point, index, utils) { return utils.pixels(display.scale, 8, 12, 16) }, stroke: function (display, point, index, utils) { if (!point.isFocused()) return notFocusedColor return '#000' }, 'stroke-width': function (display, point, index, utils) { return 2 }, visibility: (display, data) => { if (!data.owner.containsSegmentEndPoint()) return 'hidden' } } /** * Stops Along a Pattern */ const stopsPattern = { cx: 0, cy: 0, r: [ 4, (display, data, index, utils) => { return utils.pixels(display.scale, 1, 2, 4) }, (display, data, index, utils) => { const point = data.owner let busOnly = true point.getPatterns().forEach((pattern) => { if (pattern.route && pattern.route.route_type !== 3) busOnly = false }) if (busOnly && !point.containsSegmentEndPoint()) { return 0.5 * utils.pixels(display.scale, 2, 4, 6.5) } } ], stroke: 'none', visibility: (display, data) => { if (display.scale < 1.5) return 'hidden' if (data.owner.containsSegmentEndPoint()) return 'hidden' } } /** * Default place rules */ const places = { cx: 0, cy: 0, fill: '#fff', r: 14, stroke: '#000', 'stroke-width': '2px' } /** * Default MultiPoint rules -- based on Stop rules */ const multipointsMerged = Object.assign({}, stopsMerged) multipointsMerged.visibility = true /** * Default Multipoint Stops along a pattern */ const multipointsPattern = Object.assign({}, stopsPattern) /** * Default label rules */ const labels = { 'font-family': 'sans-serif', 'font-size': 15, /* 'font-weight': function (display, data, index, utils) { var point = data.owner.parent if (point.containsBoardPoint() || point.containsAlightPoint()) return 'bold' }, */ /** * 'orientations' is a transitive-specific attribute used to specify allowable * label placement orientations expressed as one of eight compass directions * relative to the point being labeled: * * 'N' * 'NW' | 'NE' * \ | / * 'W' -- O -- 'E' * / | \ * 'SW' | 'SE' * 'S * * Labels oriented 'E' or 'W' are rendered horizontally, 'N' and 'S' vertically, * and all others at a 45-degree angle. * * Returns an array of allowed orientation codes in the order that they will be * tried by the labeler. */ orientations: [['E', 'W']] } const segmentLabels = { background: [ '#008', // Background color falls back on dark blue. function (display, segment) { if (segment.type === 'TRANSIT') { if (segment.patterns) { if (patternIsDcCirculatorBusRoute(segment.patterns[0])) return '#f00' return segment.patterns[0].route.getColor() } } } ], color: [ '#fff', // Text color falls back on white. function (display, segment) { if (segment.type === 'TRANSIT') { if (segment.patterns) { if (patternIsDcCirculatorBusRoute(segment.patterns[0])) return '#fff' return segment.patterns[0].route.getTextColor() } } } ], 'font-family': 'sans-serif', 'font-size': 15 } /** * All path segments * TODO: update old route-pattern-specific code below */ const segments = { envelope: [ function (display, data, index, utils) { const segment = data if (segment.type !== 'TRANSIT') { return '8px' } if (segment.mode === 3) { return utils.pixels(display.scale, 4, 6, 10) + 'px' } return utils.pixels(display.scale, 6, 10, 14) + 'px' } ], stroke: [ '#008', // Dark blue function (display, segment) { if (!segment.focused) return notFocusedColor if (segment.type === 'TRANSIT') { if (segment.patterns) { if (patternIsDcCirculatorBusRoute(segment.patterns[0])) return '#f00' return segment.patterns[0].route.getColor() } } else if (segment.type === 'CAR') { return '#888' } else if (segment.type.startsWith('BICYCLE')) { return '#f00' } else if ( segment.type.startsWith('MICROMOBILITY') || segment.type.startsWith('SCOOTER') ) { return '#f5a729' } else if (segment.type === 'WALK') { return '#86cdf9' } } ], 'stroke-dasharray': [ false, function (display, data) { const segment = data if (segment.type === 'WALK') return '0, 8' if ( segment.type.startsWith('BICYCLE') || segment.type.startsWith('CAR') || segment.type.startsWith('MICROMOBILITY') || segment.type.startsWith('SCOOTER') ) { return '8, 3' } if (segment.frequency && segment.frequency.average < 12) { if (segment.frequency.average > 6) return '12, 12' return '12, 2' } } ], 'stroke-linecap': [ 'butt', (display, segment) => { if (segment.type === 'WALK') return 'round' } ], 'stroke-width': [ 10, function (display, segment, index, utils) { if (segment.type === 'WALK') return 6 if (segment.type.startsWith('BICYCLE')) return 4 if (segment.type.startsWith('CAR')) return 4 if (segment.type.startsWith('MICROMOBILITY')) return 4 if (segment.type.startsWith('SCOOTER')) return 4 if (segment.mode === 3) return 6 // Buses } ] } /** * Segments Front */ const segmentsFront = { display: [ 'none', function (display, data, index, utils) { if (patternIsDcCirculatorBusRoute(data.pattern)) { return 'inline' } } ], fill: 'none', stroke: '#008', 'stroke-width': function (display, data, index, utils) { return utils.pixels(display.scale, 3, 6, 10) / 2 + 'px' } } /** * Segments Halo */ const segmentsHalo = { fill: 'none', stroke: '#fff', 'stroke-linecap': 'round', 'stroke-width': function (display, data, index, utils) { return data.computeLineWidth(display) + 8 } } /** * Label Containers */ const segmentLabelContainers = { fill: function (display, data) { if (!data.isFocused()) return notFocusedColor }, rx: 3, ry: 3, 'stroke-width': function (display, data) { if (patternIsDcCirculatorBusRoute(data.parent.pattern)) return 1 return 0 } } /** * Checks that a pattern runs a DC Bus Circulator route. This check dates back * to https://github.com/conveyal/transitive.js/commit/b1561dcb6d864fbe6b01de11aa13d06761e1cefd * and was likely added to support CarFreeAtoZ (Arlington, VA). However, this may * need to be removed because Arlington no longer runs this service. Also, it * appears to be hyper-specific to this one implementation. */ function patternIsDcCirculatorBusRoute(pattern) { if (!pattern) return false const { route } = pattern const hasShortName = route && route.route_short_name const isBus = route && route.route_type === 3 return ( hasShortName && isBus && route.route_short_name.toLowerCase().substring(0, 2) === 'dc' ) } export default { labels, multipoints_merged: multipointsMerged, multipoints_pattern: multipointsPattern, places, segment_label_containers: segmentLabelContainers, segment_labels: segmentLabels, segments, segments_front: segmentsFront, segments_halo: segmentsHalo, stops_merged: stopsMerged, stops_pattern: stopsPattern, utils, wireframe_edges: wireframeEdges, wireframe_vertices: wireframeVertices } |