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 | import { forEach } from 'lodash' import PointLabel from '../labeler/pointlabel' export default class Point { constructor(data) { for (const key in data) { this[key] = data[key] } this.paths = [] this.renderData = [] this.label = new PointLabel(this) this.renderLabel = true this.focused = true this.sortableType = 'POINT' this.placeOffsets = { x: 0, y: 0 } this.zIndex = 10000 } /** * Get unique ID for point -- must be defined by subclass */ getId() { throw new Error('method not defined by subclass!') } getElementId() { return this.getType().toLowerCase() + '-' + this.getId() } /** * Get Point type -- must be defined by subclass */ getType() { throw new Error('method not defined by subclass!') } /** * Get Point name */ getName() { return `${this.getType()} point (ID=${this.getId()})` } /** * Get latitude */ getLat() { return 0 } /** * Get longitude */ getLon() { return 0 } containsSegmentEndPoint() { return false } containsBoardPoint() { return false } containsAlightPoint() { return false } containsTransferPoint() { return false } getPatterns() { return [] } /** * Draw the point * * @param {Display} display */ // eslint-disable-next-line @typescript-eslint/no-empty-function render(display) {} /** * Does not need to be implemented by subclass */ // eslint-disable-next-line @typescript-eslint/no-empty-function addRenderData() {} /** * Does not need to be implemented by subclass */ // eslint-disable-next-line @typescript-eslint/no-empty-function clearRenderData() {} containsFromPoint() { return false } containsToPoint() { return false } //* * Shared geom utility functions **// constructMergedMarker(display) { const dataArray = this.getRenderDataArray() const xValues = [] const yValues = [] dataArray.forEach(function (data) { const x = data.x const y = data.y xValues.push(x) yValues.push(y) }) const minX = Math.min.apply(Math, xValues) const minY = Math.min.apply(Math, yValues) const maxX = Math.max.apply(Math, xValues) const maxY = Math.max.apply(Math, yValues) // retrieve marker type and radius from the styler const markerType = display.styler.compute( display.styler.stops_merged['marker-type'], display, { owner: this } ) const stylerRadius = display.styler.compute( display.styler.stops_merged.r, display, { owner: this } ) let width let height let r // if this is a circle marker w/ a styler-defined fixed radius, use that if (markerType === 'circle' && stylerRadius) { width = height = stylerRadius * 2 r = stylerRadius // otherwise, this is a dynamically-sized marker } else { const dx = maxX - minX const dy = maxY - minY const markerPadding = display.styler.compute( display.styler.stops_merged['marker-padding'], display, { owner: this } ) || 0 const patternRadius = display.styler.compute( display.styler[this.patternStylerKey].r, display, { owner: this } ) r = parseFloat(patternRadius) + markerPadding if (markerType === 'circle') { width = height = Math.max(dx, dy) + 2 * r r = width / 2 } else { width = dx + 2 * r height = dy + 2 * r if (markerType === 'rectangle') r = 0 } } return { height: height, rx: r, ry: r, width: width, x: (minX + maxX) / 2 - width / 2, y: (minY + maxY) / 2 - height / 2 } } initMarkerData(display) { if (this.getType() !== 'STOP' && this.getType() !== 'MULTI') return this.mergedMarkerData = this.constructMergedMarker(display) this.placeOffsets = { x: 0, y: 0 } if (this.adjacentPlace) { const placeR = display.styler.compute(display.styler.places.r, display, { owner: this.adjacentPlace }) const placeX = display.xScale.compute(this.adjacentPlace.worldX) const placeY = display.yScale.compute(this.adjacentPlace.worldY) const thisR = this.mergedMarkerData.width / 2 const thisX = this.mergedMarkerData.x + thisR const thisY = this.mergedMarkerData.y + thisR const dx = thisX - placeX const dy = thisY - placeY const dist = Math.sqrt(dx * dx + dy * dy) if (placeR + thisR > dist) { const f = (placeR + thisR) / dist this.placeOffsets = { x: dx * f - dx, y: dy * f - dy } this.mergedMarkerData.x += this.placeOffsets.x this.mergedMarkerData.y += this.placeOffsets.y forEach(this.graphVertex.incidentEdges(), (edge) => { forEach(edge.renderSegments, (segment) => { segment.refreshRenderData(display) }) }) } } } getMarkerBBox() { return this.markerBBox } setFocused(focused) { this.focused = focused } isFocused() { return this.focused === true } /** * Does not need to be implemented by subclass */ // eslint-disable-next-line @typescript-eslint/no-empty-function runFocusTransition(display, callback) {} /** * Does not need to be implemented by subclass */ // eslint-disable-next-line @typescript-eslint/no-empty-function setAllPatternsFocused() {} getZIndex() { return this.zIndex } getAverageCoord() { const dataArray = this.getRenderDataArray() let xTotal = 0 let yTotal = 0 forEach(dataArray, (data) => { xTotal += data.x yTotal += data.y }) return { x: xTotal / dataArray.length, y: yTotal / dataArray.length } } hasRenderData() { const dataArray = this.getRenderDataArray() return dataArray && dataArray.length > 0 } /** * Does not need to be implemented by subclass */ // eslint-disable-next-line @typescript-eslint/no-empty-function makeDraggable(transitive) {} toString() { return `${this.getType()} point: ${this.getId()} (${this.getName()})` } } |