@windborne/grapher 1.0.1 → 1.0.2

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.1",
3
+ "version": "1.0.2",
4
4
  "description": "Graphing library",
5
5
  "main": "bundle.js",
6
6
  "publishConfig": {},
package/readme.md CHANGED
@@ -98,6 +98,7 @@ The `series` prop requires an array of objects, where each object represents a d
98
98
  - **zeroLineWidth**: Width of the zero line, only applies to bar and area rendering (number)
99
99
  - **zeroLineColor**: Color of the zero line, only applies to bar and area rendering (string)
100
100
  - **pointRadius**: Radius of points, only applies to area rendering (number)
101
+ - **tooltipWidth**: Expected width of the tooltip (number). Will make the tooltip switch sides when this width plus the tooltip left position is greater than the graph width.
101
102
 
102
103
  #### Series Data Formats
103
104
  Grapher supports multiple data formats within a series:
@@ -41,7 +41,7 @@ export default class ContextMenu extends React.PureComponent {
41
41
 
42
42
  const style = { left: x, top: y, width: '150px'};
43
43
 
44
- if (!showing || !value || value.toLocaleString() === 'Invalid Date') {
44
+ if (!showing || !value || value.toLocaleString() === 'Invalid Date' || isNaN(x) || isNaN(y)) {
45
45
  return null;
46
46
  }
47
47
 
@@ -61,9 +61,9 @@ export default class ContextMenu extends React.PureComponent {
61
61
 
62
62
  ContextMenu.propTypes = {
63
63
  contextMenu: PropTypes.shape({
64
- x: PropTypes.number.isRequired,
65
- y: PropTypes.number.isRequired,
66
- showing: PropTypes.bool.isRequired,
64
+ x: PropTypes.number,
65
+ y: PropTypes.number,
66
+ showing: PropTypes.bool,
67
67
  value: PropTypes.oneOfType([
68
68
  PropTypes.instanceOf(Date),
69
69
  PropTypes.number,
@@ -25,6 +25,10 @@ function getYLabelContent({ yLabel, y, fullYPrecision}) {
25
25
  }
26
26
  }
27
27
 
28
+ if (typeof yLabel === 'object') {
29
+ return formatY(y);
30
+ }
31
+
28
32
  return yLabel || formatY(y);
29
33
  }
30
34
 
@@ -112,7 +116,10 @@ export default class Tooltip extends React.PureComponent {
112
116
  const { x, y, pixelY, pixelX, series, index, xLabel, yLabel, fullYPrecision } = tooltip;
113
117
 
114
118
  const axisLabel = (series.name || series.yKey || index).toString();
115
- const width = Math.max(axisLabel.length, (xLabel || formatX(x, formatXOptions)).length + 4, getYLabelContent({ yLabel, y, fullYPrecision}).length + 4) * 7.5;
119
+ let width = Math.max(axisLabel.length, (xLabel || formatX(x, formatXOptions)).length + 4, getYLabelContent({ yLabel, y, fullYPrecision}).length + 4) * 7.5;
120
+ if (series.tooltipWidth) {
121
+ width = series.tooltipWidth;
122
+ }
116
123
 
117
124
  let fixedPosition = this.props.elementWidth < (width + 2*caretSize + 2*caretPadding);
118
125
 
@@ -220,7 +227,7 @@ export default class Tooltip extends React.PureComponent {
220
227
  for (let group of groupedTooltips) {
221
228
  if (Math.abs(group.pixelX - tooltip.pixelX) <= combinationThreshold) {
222
229
  group.tooltips.push(tooltip);
223
- if (tooltip.pixelX < group.pixelX) {
230
+ if (tooltip.pixelX > group.pixelX) {
224
231
  group.pixelX = tooltip.pixelX;
225
232
  group.multiplier = tooltip.multiplier;
226
233
  }
@@ -375,7 +382,7 @@ Tooltip.propTypes = {
375
382
  pixelY: PropTypes.number,
376
383
  color: PropTypes.string,
377
384
  xLabel: PropTypes.string,
378
- yLabel: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
385
+ yLabel: PropTypes.any,
379
386
  fullYPrecision: PropTypes.bool
380
387
  })),
381
388
  axisCount: PropTypes.number.isRequired,
@@ -70,7 +70,8 @@ const SingleSeries = PropTypes.shape({
70
70
  gradient: PropTypes.array, // only applies to area
71
71
  zeroLineWidth: PropTypes.number, // only applies to bar and area
72
72
  zeroLineColor: PropTypes.string, // only applies to bar and area
73
- pointRadius: PropTypes.number // only applies to area
73
+ pointRadius: PropTypes.number, // only applies to area
74
+ tooltipWidth: PropTypes.number
74
75
  });
75
76
 
76
77
  const Series = PropTypes.arrayOf(SingleSeries);