MCPcopy Create free account
hub / github.com/plotly/plotly.js / addPt

Function addPt

src/traces/scatter/line_points.js:284–358  ·  view source on GitHub ↗
(pt)

Source from the content-addressed store, hash-verified

282 var arrayMarker = Lib.isArrayOrTypedArray(marker);
283
284 function addPt(pt) {
285 if(pt && backoff) {
286 pt.i = i;
287 pt.d = d;
288 pt.trace = trace;
289 pt.marker = arrayMarker ? marker[pt.i] : marker;
290 pt.backoff = backoff;
291 }
292
293 latestXFrac = pt[0] / xLen;
294 latestYFrac = pt[1] / yLen;
295 // Are we more than maxScreensAway off-screen any direction?
296 // if so, clip to this box, but in such a way that on-screen
297 // drawing is unchanged
298 xEdge = (pt[0] < xEdge0) ? xEdge0 : (pt[0] > xEdge1) ? xEdge1 : 0;
299 yEdge = (pt[1] < yEdge0) ? yEdge0 : (pt[1] > yEdge1) ? yEdge1 : 0;
300 if(xEdge || yEdge) {
301 if(!pti) {
302 // to get fills right - if first point is far, push it toward the
303 // screen in whichever direction(s) are far
304
305 pts[pti++] = [xEdge || pt[0], yEdge || pt[1]];
306 } else if(lastFarPt) {
307 // both this point and the last are outside the nearby region
308 // check if we're crossing the nearby region
309 var intersections = getEdgeIntersections(lastFarPt, pt);
310 if(intersections.length > 1) {
311 updateEdgesForReentry(intersections[0]);
312 pts[pti++] = intersections[1];
313 }
314 } else {
315 // we're leaving the nearby region - add the point where we left it
316
317 edgePt = getEdgeIntersections(pts[pti - 1], pt)[0];
318 pts[pti++] = edgePt;
319 }
320
321 var lastPt = pts[pti - 1];
322 if(xEdge && yEdge && (lastPt[0] !== xEdge || lastPt[1] !== yEdge)) {
323 // we've gone out beyond a new corner: add the corner too
324 // so that the next point will take the right winding
325 if(lastFarPt) {
326 if(lastXEdge !== xEdge && lastYEdge !== yEdge) {
327 if(lastXEdge && lastYEdge) {
328 // we've gone around to an opposite corner - we
329 // need to add the correct extra corner
330 // in order to get the right winding
331 updateEdge(getClosestCorner(lastFarPt, pt));
332 } else {
333 // we're coming from a far edge - the extra corner
334 // we need is determined uniquely by the sectors
335 updateEdge([lastXEdge || xEdge, lastYEdge || yEdge]);
336 }
337 } else if(lastXEdge && lastYEdge) {
338 updateEdge([lastXEdge, lastYEdge]);
339 }
340 }
341 updateEdge([xEdge, yEdge]);

Callers 1

line_points.jsFile · 0.70

Calls 3

updateEdgesForReentryFunction · 0.85
updateEdgeFunction · 0.85
getClosestCornerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…