@windborne/grapher 1.0.36 → 1.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windborne/grapher",
3
- "version": "1.0.36",
3
+ "version": "1.0.37",
4
4
  "description": "Graphing library",
5
5
  "main": "src/index.js",
6
6
  "module": "dist/bundle.esm.js",
@@ -351,9 +351,27 @@ export default function drawLine(dataInRenderSpace, {
351
351
  if (showIndividualPoints) {
352
352
  const individualPoints = getIndividualPoints();
353
353
 
354
- if (renderCutoffGradient && cutoffIndex !== undefined && originalData) {
354
+ if (renderCutoffGradient && cutoffIndex !== undefined && originalData && selectionBounds) {
355
+ const visibleBounds = selectionBounds;
356
+ let firstTime, lastTime;
357
+
358
+ if (visibleBounds && visibleBounds.minX !== undefined && visibleBounds.maxX !== undefined) {
359
+ firstTime = visibleBounds.minX instanceof Date ? visibleBounds.minX.getTime() : visibleBounds.minX;
360
+ lastTime = visibleBounds.maxX instanceof Date ? visibleBounds.maxX.getTime() : visibleBounds.maxX;
361
+ } else {
362
+ const firstItem = originalData[0];
363
+ const lastItem = originalData[originalData.length - 1];
364
+ const firstX = firstItem[0];
365
+ const lastX = lastItem[0];
366
+
367
+ firstTime = firstX instanceof Date ? firstX.getTime() : firstX;
368
+ lastTime = lastX instanceof Date ? lastX.getTime() : lastX;
369
+ }
370
+
355
371
  let cutoffTime;
356
- if (typeof originalData[0] === 'object' && originalData[0].length === 2) {
372
+ if (typeof cutoffIndex === 'string' && cutoffIndex === 'now') {
373
+ cutoffTime = Date.now();
374
+ } else if (typeof originalData[0] === 'object' && originalData[0].length === 2) {
357
375
  const baseIndex = Math.floor(cutoffIndex);
358
376
  const fraction = cutoffIndex - baseIndex;
359
377
 
@@ -371,6 +389,38 @@ export default function drawLine(dataInRenderSpace, {
371
389
  cutoffTime = cutoffIndex;
372
390
  }
373
391
 
392
+ if (cutoffTime !== null) {
393
+ const timeDiff = cutoffTime - firstTime;
394
+ const totalTime = lastTime - firstTime;
395
+ const timeRatio = timeDiff / totalTime;
396
+
397
+ if (timeRatio > 1) {
398
+ const spacedPoints = applyPointSpacing(individualPoints, minPointSpacing);
399
+ for (let i = 0; i < spacedPoints.length; i++) {
400
+ const [x, y] = spacedPoints[i];
401
+
402
+ let pointColor = color;
403
+ if (negativeColor && hasNegatives) {
404
+ if (y === zero && zeroColor) {
405
+ pointColor = zeroColor;
406
+ } else if (y < zero) {
407
+ pointColor = color;
408
+ } else {
409
+ pointColor = negativeColor;
410
+ }
411
+ }
412
+
413
+ const { applyReducedOpacity } = require("../helpers/colors");
414
+ const reducedOpacityColor = applyReducedOpacity(pointColor, cutoffOpacity);
415
+ context.fillStyle = reducedOpacityColor;
416
+ context.beginPath();
417
+ context.arc(x, y, pointRadius || 8, 0, 2 * Math.PI, false);
418
+ context.fill();
419
+ }
420
+ return;
421
+ }
422
+ }
423
+
374
424
  if (isPreview) {
375
425
  const visibleMinTime = selectionBounds.minX instanceof Date ? selectionBounds.minX.getTime() : selectionBounds.minX;
376
426
  const visibleMaxTime = selectionBounds.maxX instanceof Date ? selectionBounds.maxX.getTime() : selectionBounds.maxX;
@@ -417,7 +467,6 @@ export default function drawLine(dataInRenderSpace, {
417
467
  for (let i = 0; i < spacedPoints.length; i++) {
418
468
  const [x, y] = spacedPoints[i];
419
469
 
420
- // Determine point color based on position relative to zero
421
470
  let pointColor = color;
422
471
  if (negativeColor && hasNegatives) {
423
472
  if (y === zero && zeroColor) {
@@ -612,6 +612,19 @@ export default class GraphBodyRenderer extends Eventable {
612
612
  zeroColor: singleSeries.zeroLineColor
613
613
  };
614
614
 
615
+ if (this._webgl && singleSeries.rendering === 'shadow' && singleSeries.cutoffTime && (width > 0 || shouldShowIndividualPoints)) {
616
+ drawParams.cutoffIndex = cutoffIndex;
617
+ drawParams.cutoffOpacity = singleSeries.cutoffOpacity !== undefined ? singleSeries.cutoffOpacity : 0.35;
618
+ drawParams.originalData = cutoffData;
619
+ drawParams.renderCutoffGradient = cutoffIndex >= 0;
620
+
621
+ const selection = this === this._stateController.rangeGraphRenderer
622
+ ? this._stateController._bounds
623
+ : (this._stateController._selection || this._stateController._bounds);
624
+ drawParams.selectionBounds = selection || bounds;
625
+ drawParams.currentBounds = bounds;
626
+ }
627
+
615
628
 
616
629
  if (!inRenderSpace) {
617
630
  console.error('inRenderSpace is null for line rendering');