@windborne/grapher 1.0.47 → 1.0.49

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.47",
3
+ "version": "1.0.49",
4
4
  "description": "Graphing library",
5
5
  "main": "src/index.js",
6
6
  "module": "dist/bundle.esm.js",
@@ -141,56 +141,6 @@ export default function drawArea(
141
141
  for (let pathI = 0; pathI < areaPaths.length; pathI++) {
142
142
  const path = areaPaths[pathI];
143
143
  const areaBottomPath = areaBottomPaths && areaBottomPaths[pathI];
144
-
145
- // Determine if this path segment is positive or negative for gradient application
146
- let isPositive = true;
147
- if (hasNegatives && negativeGradient && path.length > 0) {
148
- // Check the average Y position of the path to determine if it's above or below zero
149
- let sumY = 0;
150
- for (let i = 0; i < path.length; i++) {
151
- sumY += path[i][1];
152
- }
153
- const avgY = sumY / path.length;
154
- isPositive = avgY <= zero; // In screen coordinates, smaller Y is higher up (positive)
155
- }
156
-
157
- // Set the fill style based on whether this is a positive or negative segment
158
- if (hasNegatives && negativeGradient) {
159
- if (isPositive) {
160
- // Use the original gradient or color for positive areas
161
- if (gradient && gradient.length >= 2) {
162
- const globalGradient = context.createLinearGradient(0, 0, 0, sizing.renderHeight);
163
- for (let i = 0; i < gradient.length; i++) {
164
- const value = gradient[i];
165
- if (Array.isArray(value)) {
166
- globalGradient.addColorStop(value[0], value[1]);
167
- } else {
168
- globalGradient.addColorStop(i / (gradient.length - 1), value);
169
- }
170
- }
171
- context.fillStyle = globalGradient;
172
- } else {
173
- context.fillStyle = color;
174
- }
175
- } else {
176
- // Use negativeGradient for negative areas
177
- if (negativeGradient.length >= 2) {
178
- const negGradient = context.createLinearGradient(0, 0, 0, sizing.renderHeight);
179
- for (let i = 0; i < negativeGradient.length; i++) {
180
- const value = negativeGradient[i];
181
- if (Array.isArray(value)) {
182
- negGradient.addColorStop(value[0], value[1]);
183
- } else {
184
- negGradient.addColorStop(i / (negativeGradient.length - 1), value);
185
- }
186
- }
187
- context.fillStyle = negGradient;
188
- } else {
189
- context.fillStyle = negativeColor || color;
190
- }
191
- }
192
- }
193
-
194
144
  context.beginPath();
195
145
 
196
146
  const [firstX, _startY] = path[0];
@@ -361,7 +311,6 @@ function drawAreaWithCutoff(
361
311
  shadowBlur,
362
312
  inRenderSpaceAreaBottom,
363
313
  cutoffIndex,
364
- cutoffTimeValue,
365
314
  cutoffOpacity,
366
315
  originalData,
367
316
  selectionBounds,
@@ -369,9 +318,7 @@ function drawAreaWithCutoff(
369
318
  }
370
319
  ) {
371
320
  let cutoffTime;
372
- if (cutoffTimeValue !== undefined && cutoffTimeValue !== null) {
373
- cutoffTime = cutoffTimeValue;
374
- } else if (typeof originalData[0] === "object" && originalData[0].length === 2) {
321
+ if (typeof originalData[0] === "object" && originalData[0].length === 2) {
375
322
  const baseIndex = Math.floor(cutoffIndex);
376
323
  const fraction = cutoffIndex - baseIndex;
377
324
 
@@ -2,8 +2,8 @@ function finalizeBounds(bounds, { dates }) {
2
2
  const initial = (bounds.minX === null && bounds.maxX === null) || bounds.minY === null || bounds.maxY === null;
3
3
 
4
4
  for (let key of Object.keys(bounds)) {
5
- if (typeof bounds[key] !== 'number') {
6
- bounds[key] = 0;
5
+ if (typeof bounds[key] !== 'number' && bounds[key] !== null) {
6
+ bounds[key] = null;
7
7
  }
8
8
  }
9
9
 
@@ -73,6 +73,10 @@ export default function calculateDataBounds(inDataSpace, {percentile=100, percen
73
73
  let prevX = null;
74
74
 
75
75
  for (let [x, y] of inDataSpace) {
76
+ if (x === null) {
77
+ continue;
78
+ }
79
+
76
80
  if (x instanceof Date) {
77
81
  x = x.valueOf();
78
82
  dates = true;
@@ -118,6 +122,5 @@ export default function calculateDataBounds(inDataSpace, {percentile=100, percen
118
122
  }
119
123
  }
120
124
 
121
-
122
125
  return finalizeBounds(bounds, {dates});
123
126
  }
@@ -31,9 +31,6 @@ export default function expandBounds(bounds, {expandYWith = [], extendXForNBars=
31
31
 
32
32
  const range = expandedBounds.maxY - expandedBounds.minY;
33
33
  const midpoint = expandedBounds.minY + range/2;
34
- const padding = 0.05 * range / 2;
35
- const beforeMin = expandedBounds.minY;
36
- const beforeMax = expandedBounds.maxY;
37
34
  expandedBounds.minY = Math.min(expandedBounds.minY, midpoint - 1.05*range/2);
38
35
  expandedBounds.maxY = Math.max(expandedBounds.maxY, midpoint + 1.05*range/2);
39
36
 
@@ -19,23 +19,23 @@ export default function mergeBounds(boundsList) {
19
19
  }
20
20
  mergedBounds.initial = false;
21
21
 
22
- if (mergedBounds.minX === null || minX < mergedBounds.minX) {
22
+ if (minX !== null && (mergedBounds.minX === null || minX < mergedBounds.minX)) {
23
23
  mergedBounds.minX = minX;
24
24
  }
25
25
 
26
- if (mergedBounds.maxX === null || maxX > mergedBounds.maxX) {
26
+ if (maxX !== null && (mergedBounds.maxX === null || maxX > mergedBounds.maxX)) {
27
27
  mergedBounds.maxX = maxX;
28
28
  }
29
29
 
30
- if (mergedBounds.closestSpacing === null || closestSpacing < mergedBounds.closestSpacing) {
30
+ if (closestSpacing !== null && (mergedBounds.closestSpacing === null || closestSpacing < mergedBounds.closestSpacing)) {
31
31
  mergedBounds.closestSpacing = closestSpacing;
32
32
  }
33
33
 
34
- if (mergedBounds.minY === null || minY < mergedBounds.minY) {
34
+ if (minY !== null && (mergedBounds.minY === null || minY < mergedBounds.minY)) {
35
35
  mergedBounds.minY = minY;
36
36
  }
37
37
 
38
- if (mergedBounds.maxY === null || maxY > mergedBounds.maxY) {
38
+ if (maxY !== null && (mergedBounds.maxY === null || maxY > mergedBounds.maxY)) {
39
39
  mergedBounds.maxY = maxY;
40
40
  }
41
41
  }
@@ -802,15 +802,27 @@ export default class StateController extends Eventable {
802
802
  const expandYWith = [];
803
803
  for (let singleSeries of axis.series) {
804
804
  if (singleSeries._rangeValues && singleSeries._rangeValues.length > 0) {
805
- const visibleDataPoints = singleSeries.inDataSpace.filter(([x, y]) =>
806
- axis.targetBounds.minX <= x && x <= axis.targetBounds.maxX
807
- );
808
-
809
805
  const visibleRangeValues = [];
810
- for (let i = 0; i < visibleDataPoints.length; i++) {
811
- const dataPointIndex = singleSeries.inDataSpace.indexOf(visibleDataPoints[i]);
812
- if (dataPointIndex >= 0) {
813
- const rangeIndex = dataPointIndex * 2;
806
+
807
+ for (let i = 0; i < singleSeries.inDataSpace.length; i++) {
808
+ const [x, y] = singleSeries.inDataSpace[i];
809
+ let xValue = x;
810
+ let minXValue = axis.targetBounds.minX;
811
+ let maxXValue = axis.targetBounds.maxX;
812
+
813
+ if (x instanceof Date) {
814
+ xValue = x.valueOf();
815
+ }
816
+ if (minXValue instanceof Date) {
817
+ minXValue = minXValue.valueOf();
818
+ }
819
+ if (maxXValue instanceof Date) {
820
+ maxXValue = maxXValue.valueOf();
821
+ }
822
+
823
+ if (minXValue !== null && maxXValue !== null &&
824
+ xValue >= minXValue && xValue <= maxXValue) {
825
+ const rangeIndex = i * 2;
814
826
  if (rangeIndex < singleSeries._rangeValues.length) {
815
827
  visibleRangeValues.push(singleSeries._rangeValues[rangeIndex]);
816
828
  if (rangeIndex + 1 < singleSeries._rangeValues.length) {
@@ -854,15 +866,27 @@ export default class StateController extends Eventable {
854
866
  }
855
867
 
856
868
  if (singleSeries._rangeValues && singleSeries._rangeValues.length > 0) {
857
- const visibleDataPoints = singleSeries.inDataSpace.filter(([x, y]) =>
858
- singleSeries.selectedBounds.minX <= x && x <= singleSeries.selectedBounds.maxX
859
- );
860
-
861
869
  const visibleRangeValues = [];
862
- for (let i = 0; i < visibleDataPoints.length; i++) {
863
- const dataPointIndex = singleSeries.inDataSpace.indexOf(visibleDataPoints[i]);
864
- if (dataPointIndex >= 0) {
865
- const rangeIndex = dataPointIndex * 2;
870
+
871
+ for (let i = 0; i < singleSeries.inDataSpace.length; i++) {
872
+ const [x, y] = singleSeries.inDataSpace[i];
873
+ let xValue = x;
874
+ let minXValue = singleSeries.selectedBounds.minX;
875
+ let maxXValue = singleSeries.selectedBounds.maxX;
876
+
877
+ if (x instanceof Date) {
878
+ xValue = x.valueOf();
879
+ }
880
+ if (minXValue instanceof Date) {
881
+ minXValue = minXValue.valueOf();
882
+ }
883
+ if (maxXValue instanceof Date) {
884
+ maxXValue = maxXValue.valueOf();
885
+ }
886
+
887
+ if (minXValue !== null && maxXValue !== null &&
888
+ xValue >= minXValue && xValue <= maxXValue) {
889
+ const rangeIndex = i * 2;
866
890
  if (rangeIndex < singleSeries._rangeValues.length) {
867
891
  visibleRangeValues.push(singleSeries._rangeValues[rangeIndex]);
868
892
  if (rangeIndex + 1 < singleSeries._rangeValues.length) {