grommet 2.32.2 → 2.33.0

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.
Files changed (57) hide show
  1. package/all/stories/CustomThemed/ExtendTheme.tsx +2 -4
  2. package/components/Chart/Chart.js +20 -20
  3. package/components/Chart/calcs.js +163 -92
  4. package/components/Chart/index.d.ts +10 -4
  5. package/components/Chart/propTypes.js +10 -1
  6. package/components/Chart/stories/{Vertical.js → Horizontal.js} +34 -6
  7. package/components/Chart/utils.js +68 -64
  8. package/components/DataChart/DataChart.js +114 -68
  9. package/components/DataChart/Detail.js +55 -21
  10. package/components/DataChart/XAxis.js +33 -6
  11. package/components/DataChart/XGuide.js +14 -1
  12. package/components/DataChart/YAxis.js +58 -39
  13. package/components/DataChart/YGuide.js +13 -10
  14. package/components/DataChart/index.d.ts +2 -0
  15. package/components/DataChart/propTypes.js +3 -1
  16. package/components/DataChart/stories/Horizontal.js +63 -0
  17. package/components/DataChart/utils.js +27 -2
  18. package/components/DataFilter/DataFilter.js +25 -2
  19. package/components/DataSort/DataSort.js +1 -1
  20. package/components/DataTable/buildState.js +6 -1
  21. package/components/DateInput/DateInput.js +22 -2
  22. package/components/Footer/stories/DoubleFooter.js +6 -2
  23. package/components/Footer/stories/Sitemap.js +0 -2
  24. package/components/Footer/stories/Social.js +2 -2
  25. package/components/Menu/Menu.js +9 -6
  26. package/components/Select/Select.js +1 -1
  27. package/es6/all/stories/CustomThemed/ExtendTheme.tsx +2 -4
  28. package/es6/components/Chart/Chart.js +20 -20
  29. package/es6/components/Chart/calcs.js +164 -93
  30. package/es6/components/Chart/index.d.ts +10 -4
  31. package/es6/components/Chart/propTypes.js +10 -1
  32. package/es6/components/Chart/stories/{Vertical.js → Horizontal.js} +32 -4
  33. package/es6/components/Chart/utils.js +66 -63
  34. package/es6/components/DataChart/DataChart.js +115 -69
  35. package/es6/components/DataChart/Detail.js +55 -21
  36. package/es6/components/DataChart/XAxis.js +33 -6
  37. package/es6/components/DataChart/XGuide.js +14 -1
  38. package/es6/components/DataChart/YAxis.js +59 -40
  39. package/es6/components/DataChart/YGuide.js +13 -10
  40. package/es6/components/DataChart/index.d.ts +2 -0
  41. package/es6/components/DataChart/propTypes.js +3 -1
  42. package/es6/components/DataChart/stories/Horizontal.js +57 -0
  43. package/es6/components/DataChart/utils.js +22 -0
  44. package/es6/components/DataFilter/DataFilter.js +27 -3
  45. package/es6/components/DataSort/DataSort.js +1 -1
  46. package/es6/components/DataTable/buildState.js +6 -1
  47. package/es6/components/DateInput/DateInput.js +22 -2
  48. package/es6/components/Footer/stories/DoubleFooter.js +6 -2
  49. package/es6/components/Footer/stories/Sitemap.js +0 -2
  50. package/es6/components/Footer/stories/Social.js +2 -2
  51. package/es6/components/Menu/Menu.js +9 -6
  52. package/es6/components/Select/Select.js +1 -1
  53. package/es6/themes/base.d.ts +5 -1
  54. package/grommet.min.js +1 -1
  55. package/grommet.min.js.map +1 -1
  56. package/package.json +37 -37
  57. package/themes/base.d.ts +5 -1
@@ -13,7 +13,7 @@ const custom: ThemeType = {
13
13
  },
14
14
  anchor: {
15
15
  extend: (props) => css`
16
- color: ${props.href ? 'green' : 'red'};
16
+ color: ${props['href'] ? 'green' : 'red'};
17
17
  `,
18
18
  },
19
19
  button: {
@@ -44,7 +44,7 @@ const custom: ThemeType = {
44
44
 
45
45
  // Type annotations can only be used in TypeScript files.
46
46
  // Remove ': TReact.FC' is you are not using TypeScript.
47
- const ExtendTheme: React.FC = () => {
47
+ export const Extend = () => {
48
48
  return (
49
49
  <Grommet theme={custom}>
50
50
  <Box pad="small" gap="medium" width="medium">
@@ -62,8 +62,6 @@ const ExtendTheme: React.FC = () => {
62
62
  );
63
63
  };
64
64
 
65
- export const Extend = () => <ExtendTheme />;
66
-
67
65
  export default {
68
66
  title: 'Utilities/Theme/Custom Themed/Extend',
69
67
  };
@@ -30,7 +30,8 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
30
30
  boundsProp = _ref.bounds,
31
31
  color = _ref.color,
32
32
  dash = _ref.dash,
33
- direction = _ref.direction,
33
+ _ref$direction = _ref.direction,
34
+ direction = _ref$direction === void 0 ? 'vertical' : _ref$direction,
34
35
  gap = _ref.gap,
35
36
  id = _ref.id,
36
37
  onClick = _ref.onClick,
@@ -42,8 +43,7 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
42
43
  pattern = _ref.pattern,
43
44
  point = _ref.point,
44
45
  round = _ref.round,
45
- _ref$size = _ref.size,
46
- sizeProp = _ref$size === void 0 ? defaultSize : _ref$size,
46
+ sizeProp = _ref.size,
47
47
  _ref$thickness = _ref.thickness,
48
48
  thickness = _ref$thickness === void 0 ? 'medium' : _ref$thickness,
49
49
  _ref$type = _ref.type,
@@ -56,11 +56,11 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
56
56
  var values = (0, _react.useMemo)(function () {
57
57
  return (0, _utils2.normalizeValues)(valuesProp);
58
58
  }, [valuesProp]);
59
- var vertical = (0, _react.useMemo)(function () {
60
- return direction === 'vertical';
59
+ var horizontal = (0, _react.useMemo)(function () {
60
+ return direction === 'horizontal';
61
61
  }, [direction]);
62
62
 
63
- // bounds is { x: { min, max }, y: { min, max } }, accounting for direction
63
+ // bounds is { x: { min, max }, y: { min, max } }
64
64
  var bounds = (0, _react.useMemo)(function () {
65
65
  return (0, _utils2.normalizeBounds)(boundsProp, values, direction);
66
66
  }, [direction, boundsProp, values]);
@@ -126,7 +126,7 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
126
126
 
127
127
  // autoSize is how wide or tall we'd pefer based on the number of values
128
128
  var autoSize = strokeWidth * values.length + (values.length - 1) * gapWidth;
129
- var sizeWidth = typeof sizeProp === 'string' ? sizeProp : sizeProp.width || defaultSize.width;
129
+ var sizeWidth = typeof sizeProp === 'string' ? sizeProp : (sizeProp == null ? void 0 : sizeProp.width) || horizontal && defaultSize.height || defaultSize.width;
130
130
  var width;
131
131
  if (sizeWidth === 'full' || sizeWidth === 'fill') {
132
132
  width = containerSize[0];
@@ -135,7 +135,7 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
135
135
  } else {
136
136
  width = (0, _utils.parseMetricToNum)(theme.global.size[sizeWidth] || sizeWidth);
137
137
  }
138
- var sizeHeight = typeof sizeProp === 'string' ? sizeProp : sizeProp.height || defaultSize.height;
138
+ var sizeHeight = typeof sizeProp === 'string' ? sizeProp : (sizeProp == null ? void 0 : sizeProp.height) || horizontal && defaultSize.width || defaultSize.height;
139
139
  var height;
140
140
  if (sizeHeight === 'full' || sizeHeight === 'fill') {
141
141
  height = containerSize[1];
@@ -148,7 +148,7 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
148
148
  width: width,
149
149
  height: height
150
150
  };
151
- }, [containerSize, gap, sizeProp, strokeWidth, theme.global.edgeSize, theme.global.size, values]);
151
+ }, [containerSize, gap, horizontal, sizeProp, strokeWidth, theme.global.edgeSize, theme.global.size, values]);
152
152
 
153
153
  // scale is { x, y }
154
154
  var scale = (0, _react.useMemo)(function () {
@@ -199,7 +199,7 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
199
199
  // rendering helpers, to make rendering code easier to understand
200
200
 
201
201
  var valueCoords = function valueCoords(x, y) {
202
- return vertical ? [y, x] : [x, y];
202
+ return horizontal ? [y, x] : [x, y];
203
203
  };
204
204
 
205
205
  // Converts values to drawing coordinates.
@@ -207,8 +207,8 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
207
207
  var valueToCoordinate = function valueToCoordinate(xValue, yValue) {
208
208
  var y = (yValue - bounds.y.min) * scale.y + inset.top;
209
209
  return [(xValue - bounds.x.min) * scale.x + inset.left,
210
- // vertical grows y top down, horizontal grows y bottom up
211
- vertical ? y : size.height - y];
210
+ // horizontal grows y top down, vertical grows y bottom up
211
+ horizontal ? y : size.height - y];
212
212
  };
213
213
  var useGradient = color && Array.isArray(color);
214
214
  var patternId;
@@ -231,10 +231,10 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
231
231
  valueRest = _objectWithoutPropertiesLoose(valueArg, _excluded2);
232
232
  var key = "p-" + index;
233
233
  // Math.min/max are to handle negative values
234
- var _valueCoords = valueCoords(value[0], value.length === 2 ? Math.min(Math.max(0, vertical ? bounds.x.min : bounds.y.min), value[1]) : Math.min(value[1], value[2])),
234
+ var _valueCoords = valueCoords(value[0], value.length === 2 ? Math.min(Math.max(0, horizontal ? bounds.x.min : bounds.y.min), value[1]) : Math.min(value[1], value[2])),
235
235
  startX = _valueCoords[0],
236
236
  startY = _valueCoords[1];
237
- var _valueCoords2 = valueCoords(value[0], value.length === 2 ? Math.max(Math.min(0, vertical ? bounds.x.max : bounds.y.max), value[1]) : Math.max(value[1], value[2])),
237
+ var _valueCoords2 = valueCoords(value[0], value.length === 2 ? Math.max(Math.min(0, horizontal ? bounds.x.max : bounds.y.max), value[1]) : Math.max(value[1], value[2])),
238
238
  endX = _valueCoords2[0],
239
239
  endY = _valueCoords2[1];
240
240
  var d = "M " + valueToCoordinate(startX, startY).join(',') + (" L " + valueToCoordinate(endX, endY).join(','));
@@ -337,7 +337,7 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
337
337
  var value = _ref8.value;
338
338
  var _valueCoords6 = valueCoords(value[0],
339
339
  // Math.max() is to account for value[1] being negative
340
- value.length === 2 ? Math.max(0, vertical ? bounds.x.min : bounds.y.min) : value[1]),
340
+ value.length === 2 ? Math.max(0, horizontal ? bounds.x.min : bounds.y.min) : value[1]),
341
341
  x = _valueCoords6[0],
342
342
  y = _valueCoords6[1];
343
343
  d += " L " + valueToCoordinate(x, y).join(',');
@@ -474,7 +474,7 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
474
474
  }, contents);
475
475
  var defs = [];
476
476
  var gradientRect;
477
- if (useGradient && size.height) {
477
+ if (useGradient && (horizontal && size.width || size.height)) {
478
478
  var uniqueGradientId = color.map(function (element) {
479
479
  return element.color;
480
480
  }).join('-');
@@ -485,16 +485,16 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
485
485
  id: gradientId,
486
486
  x1: 0,
487
487
  y1: 0,
488
- x2: 0,
489
- y2: 1
488
+ x2: horizontal ? 1 : 0,
489
+ y2: horizontal ? 0 : 1
490
490
  }, color.slice(0).sort(function (c1, c2) {
491
- return c2.value - c1.value;
491
+ return horizontal ? c1.value - c2.value : c2.value - c1.value;
492
492
  }).map(function (_ref10) {
493
493
  var value = _ref10.value,
494
494
  gradientColor = _ref10.color;
495
495
  return /*#__PURE__*/_react["default"].createElement("stop", {
496
496
  key: value,
497
- offset: (size.height - (value - bounds.y.min) * scale.y) / size.height,
497
+ offset: horizontal ? (value - bounds.x.min) * scale.x / size.width : (size.height - (value - bounds.y.min) * scale.y) / size.height,
498
498
  stopColor: (0, _utils.normalizeColor)(gradientColor, theme)
499
499
  });
500
500
  })));
@@ -13,7 +13,38 @@ var thicknessPad = {
13
13
  var round = function round(value, decimals) {
14
14
  return Number(Math.round(value + "e" + decimals) + "e-" + decimals);
15
15
  };
16
+
17
+ // Normalize coarseness to an object.
18
+ // Backwards compatible has no coarseness for x-axis.
16
19
  exports.round = round;
20
+ var normalizeCoarseness = function normalizeCoarseness(coarseness, direction) {
21
+ var result;
22
+ if (Array.isArray(coarseness)) result = {
23
+ x: coarseness[0],
24
+ y: coarseness[1]
25
+ };else if (typeof coarseness === 'object') result = coarseness;else if (coarseness) result = {
26
+ x: undefined,
27
+ y: coarseness
28
+ };else result = direction === 'horizontal' ? {
29
+ x: 5,
30
+ y: undefined
31
+ } : {
32
+ x: undefined,
33
+ y: 5
34
+ };
35
+ return result;
36
+ };
37
+ var normalizeSteps = function normalizeSteps(steps) {
38
+ var result;
39
+ if (Array.isArray(steps)) result = {
40
+ x: steps[0],
41
+ y: steps[1]
42
+ };else if (typeof steps === 'object') result = steps;else result = {
43
+ x: 1,
44
+ y: 1
45
+ };
46
+ return result;
47
+ };
17
48
  var alignMax = function alignMax(value, interval) {
18
49
  if (value > 0) return value - value % interval + interval;
19
50
  if (value < 0) return value + value % interval;
@@ -24,56 +55,60 @@ var alignMin = function alignMin(value, interval) {
24
55
  if (value < 0) return value - value % interval - interval;
25
56
  return value;
26
57
  };
27
- var calcBounds = function calcBounds(values, options) {
58
+ var adjustToShowZero = function adjustToShowZero(minArg, maxArg, steps) {
59
+ var min = minArg;
60
+ var max = maxArg;
61
+ if (min < 0 && max > 0 && Math.abs(min) !== Math.abs(max)) {
62
+ // Adjust min and max when crossing 0 to ensure 0 will be shown on
63
+ // the axis based on the number of steps.
64
+ if (steps === 1) {
65
+ var largest = Math.max(Math.abs(min), Math.abs(max));
66
+ min = -largest;
67
+ max = largest;
68
+ } else {
69
+ var stepInterval = (max - min) / steps;
70
+ var minSteps = min / stepInterval;
71
+ var maxSteps = max / stepInterval;
72
+ if (Math.abs(minSteps) < Math.abs(maxSteps)) {
73
+ // more above than below
74
+ stepInterval = max / Math.floor(maxSteps);
75
+ max = stepInterval * Math.floor(maxSteps);
76
+ min = stepInterval * Math.floor(minSteps);
77
+ } else {
78
+ // more below than above
79
+ stepInterval = Math.abs(min / Math.ceil(minSteps));
80
+ min = stepInterval * Math.ceil(minSteps);
81
+ max = stepInterval * Math.ceil(maxSteps);
82
+ }
83
+ }
84
+ }
85
+ return [min, max];
86
+ };
87
+ var calcBounds = function calcBounds(valuesArg, options) {
28
88
  if (options === void 0) {
29
89
  options = {};
30
90
  }
31
91
  // coarseness influences the rounding of the bounds, the smaller the
32
- // number, the more the bounds will be rounded. e.g. 111 -> 110 -> 100
33
- // Normalize to an array. Backwards compatible has no coarseness for x-axis
34
- var coarseness = Array.isArray(options.coarseness) && options.coarseness || options.coarseness && [undefined, options.coarseness] || [undefined, 5];
35
- var coarseX = coarseness[0],
36
- coarseY = coarseness[1];
37
- // the number of steps is one less than the number of labels
38
- var steps = options.steps || [1, 1];
39
- var stepsY = steps[1];
40
- var calcValues = (0, _utils.normalizeValues)(values || []);
41
-
42
- // min and max values
43
- var minX;
44
- var maxX;
45
- var minY;
46
- var maxY;
47
- if (calcValues.length) {
48
- // Calculate the max and min values.
49
- calcValues.filter(function (value) {
50
- return value !== undefined;
51
- }).forEach(function (value) {
52
- var x = value.value[0];
53
- if (x !== undefined) {
54
- minX = minX === undefined ? x : Math.min(minX, x);
55
- maxX = maxX === undefined ? x : Math.max(maxX, x);
56
- }
57
- var y = value.value[1];
58
- if (y !== undefined) {
59
- minY = minY === undefined ? y : Math.min(minY, y);
60
- maxY = maxY === undefined ? y : Math.max(maxY, y);
61
- }
62
- // handle ranges of values
63
- var y2 = value.value[2];
64
- if (y2 !== undefined) {
65
- minY = Math.min(minY, y2);
66
- maxY = Math.max(maxY, y2);
67
- }
68
- });
92
+ // number, the more the bounds will be rounded. e.g. 111 -> 110 -> 100.
93
+ var _normalizeCoarseness = normalizeCoarseness(options.coarseness, options.direction),
94
+ coarseX = _normalizeCoarseness.x,
95
+ coarseY = _normalizeCoarseness.y;
69
96
 
70
- // when max === min, offset them so we can show something
71
- if (maxX === minX) {
72
- if (maxX > 0) minX = maxX - 1;else maxX = minX + 1;
73
- }
74
- if (maxY === minY) {
75
- if (maxY > 0) minY = maxY - 1;else maxY = minY + 1;
76
- }
97
+ // the number of steps is one less than the number of labels
98
+ var _normalizeSteps = normalizeSteps(options.steps),
99
+ stepsX = _normalizeSteps.x,
100
+ stepsY = _normalizeSteps.y;
101
+ var values = (0, _utils.normalizeValues)(valuesArg || []);
102
+ var result;
103
+ if (values.length) {
104
+ // min and max values
105
+ var _calcMinMax = (0, _utils.calcMinMax)(values, options.direction),
106
+ _calcMinMax$x = _calcMinMax.x,
107
+ minX = _calcMinMax$x.min,
108
+ maxX = _calcMinMax$x.max,
109
+ _calcMinMax$y = _calcMinMax.y,
110
+ minY = _calcMinMax$y.min,
111
+ maxY = _calcMinMax$y.max;
77
112
 
78
113
  // Calculate some reasonable bounds based on the max and min values.
79
114
  // This is so values like 87342.12 don't end up being displayed as the
@@ -90,35 +125,41 @@ var calcBounds = function calcBounds(values, options) {
90
125
  minY = alignMin(minY, intervalY);
91
126
  maxY = alignMax(maxY, intervalY);
92
127
  }
93
- if (minY < 0 && maxY > 0 && Math.abs(minY) !== Math.abs(maxY)) {
94
- // Adjust min and max when crossing 0 to ensure 0 will be shown on
95
- // the Y axis based on the number of steps.
96
- if (stepsY === 1) {
97
- var largest = Math.max(Math.abs(minY), Math.abs(maxY));
98
- minY = -largest;
99
- maxY = largest;
100
- } else {
101
- var stepInterval = (maxY - minY) / stepsY;
102
- var minSteps = minY / stepInterval;
103
- var maxSteps = maxY / stepInterval;
104
- if (Math.abs(minSteps) < Math.abs(maxSteps)) {
105
- // more above than below
106
- stepInterval = maxY / Math.floor(maxSteps);
107
- maxY = stepInterval * Math.floor(maxSteps);
108
- minY = stepInterval * Math.floor(minSteps);
109
- } else {
110
- // more below than above
111
- stepInterval = Math.abs(minY / Math.ceil(minSteps));
112
- minY = stepInterval * Math.ceil(minSteps);
113
- maxY = stepInterval * Math.ceil(maxSteps);
114
- }
115
- }
128
+ if (options.direction === 'horizontal') {
129
+ var _adjustToShowZero = adjustToShowZero(minX, maxX, stepsX);
130
+ minX = _adjustToShowZero[0];
131
+ maxX = _adjustToShowZero[1];
132
+ } else {
133
+ var _adjustToShowZero2 = adjustToShowZero(minY, maxY, stepsY);
134
+ minY = _adjustToShowZero2[0];
135
+ maxY = _adjustToShowZero2[1];
116
136
  }
137
+
138
+ // if options.direction is present, the results are delivered in { x, y }
139
+ // object structure. If options.direction is not present, the results are
140
+ // delivered in [x, y] array structure, for backwards compatibility
141
+ result = options.direction ? {
142
+ x: {
143
+ min: minX,
144
+ max: maxX
145
+ },
146
+ y: {
147
+ min: minY,
148
+ max: maxY
149
+ }
150
+ } : [[minX, maxX], [minY, maxY]];
151
+ } else {
152
+ result = options.direction ? {
153
+ x: {},
154
+ y: {}
155
+ } : [[], []];
117
156
  }
118
- var bounds;
119
- if (calcValues.length) bounds = [[minX, maxX], [minY, maxY]];else bounds = [[], []];
120
- return bounds;
157
+ return result;
121
158
  };
159
+
160
+ // if options.direction is present, the results are delivered in { x, y }
161
+ // object structure. If options.direction is not present, the results are
162
+ // delivered in [x, y] array structure, for backwards compatibility
122
163
  exports.calcBounds = calcBounds;
123
164
  var calcs = function calcs(values, options) {
124
165
  if (values === void 0) {
@@ -127,37 +168,64 @@ var calcs = function calcs(values, options) {
127
168
  if (options === void 0) {
128
169
  options = {};
129
170
  }
171
+ var horizontal = options.direction === 'horizontal';
172
+
130
173
  // the number of steps is one less than the number of labels
131
- var steps = options.steps || [1, 1];
132
- var stepsX = steps[0],
133
- stepsY = steps[1];
174
+ var _normalizeSteps2 = normalizeSteps(options.steps),
175
+ stepsX = _normalizeSteps2.x,
176
+ stepsY = _normalizeSteps2.y;
177
+
178
+ // bounds is { x: { min, max }, y: { min, max } } when options.direction is
179
+ // present and [[min, max], [min, max]] if not, for backwards compatibility
134
180
  var bounds = options.bounds || calcBounds(values, options);
135
- if (options.min !== undefined) bounds[1][0] = options.min;
136
- if (options.max !== undefined) bounds[1][1] = options.max;
137
- var boundsX = bounds[0],
138
- boundsY = bounds[1];
139
- var boundsXmin = boundsX[0],
140
- boundsXmax = boundsX[1];
141
- var boundsYmin = boundsY[0],
142
- boundsYmax = boundsY[1];
143
- var dimensions = [round(boundsXmax - boundsXmin, 2), round(boundsYmax - boundsYmin, 2)];
144
- var dimensionsX = dimensions[0],
145
- dimensionsY = dimensions[1];
181
+ if (options.min !== undefined) {
182
+ if (options.direction) {
183
+ if (horizontal) bounds.x.min = options.min;else bounds.y.min = options.min;
184
+ } else bounds[1][0] = options.min;
185
+ }
186
+ if (options.max !== undefined) {
187
+ if (options.direction) {
188
+ if (horizontal) bounds.y.max = options.max;else bounds.x.max = options.max;
189
+ } else bounds[1][1] = options.max;
190
+ }
191
+ var _ref = options.direction ? bounds : {
192
+ x: {
193
+ min: bounds[0][0],
194
+ max: bounds[0][1]
195
+ },
196
+ y: {
197
+ min: bounds[1][0],
198
+ max: bounds[1][1]
199
+ }
200
+ },
201
+ _ref$x = _ref.x,
202
+ minX = _ref$x.min,
203
+ maxX = _ref$x.max,
204
+ _ref$y = _ref.y,
205
+ minY = _ref$y.min,
206
+ maxY = _ref$y.max;
207
+ var width = round(maxX - minX, 2);
208
+ var height = round(maxY - minY, 2);
209
+ var dimensions = options.direction ? {
210
+ width: width,
211
+ height: height
212
+ } : [width, height];
146
213
 
147
214
  // Calculate x and y axis values across the specfied number of steps.
148
215
  var yAxis = [];
149
- var y = boundsYmax;
216
+ var y = maxY;
150
217
  // To deal with javascript math limitations, round the step with 4 decimal
151
218
  // places and then push the values with 2 decimal places
152
- var yStepInterval = round(dimensionsY / stepsY, 4);
153
- while (round(y, 2) >= boundsYmin) {
219
+ var yStepInterval = round(height / stepsY, 4);
220
+ while (round(y, 2) >= minY) {
154
221
  yAxis.push(round(y, 2));
155
222
  y -= yStepInterval;
156
223
  }
224
+ if (horizontal) yAxis.reverse();
157
225
  var xAxis = [];
158
- var x = boundsXmin;
159
- var xStepInterval = round(dimensionsX / stepsX, 4);
160
- while (round(x, 2) <= boundsXmax) {
226
+ var x = minX;
227
+ var xStepInterval = round(width / stepsX, 4);
228
+ while (round(x, 2) <= maxX) {
161
229
  xAxis.push(round(x, 2));
162
230
  x += xStepInterval;
163
231
  }
@@ -184,7 +252,10 @@ var calcs = function calcs(values, options) {
184
252
  }
185
253
  var pad = thicknessPad[thickness];
186
254
  return {
187
- axis: [xAxis, yAxis],
255
+ axis: options.direction ? {
256
+ x: xAxis,
257
+ y: yAxis
258
+ } : [xAxis, yAxis],
188
259
  bounds: bounds,
189
260
  dimensions: dimensions,
190
261
  pad: pad,
@@ -16,7 +16,10 @@ export interface ChartProps {
16
16
  animate?: boolean;
17
17
  gridArea?: GridAreaType;
18
18
  margin?: MarginType;
19
- bounds?: number[][];
19
+ // caller must align with direction
20
+ bounds?:
21
+ | { x: { min: number; max: number }; y: { min: number; max: number } }
22
+ | number[][];
20
23
  color?:
21
24
  | ColorType
22
25
  | { color: ColorType; value: number | number[] }[]
@@ -105,12 +108,15 @@ export interface ChartExtendedProps
105
108
 
106
109
  declare const Chart: React.FC<ChartExtendedProps>;
107
110
 
108
- type Bounds = [[number, number], [number, number]] | [[], []];
111
+ type Bounds =
112
+ | { x: { min: number; max: number }; y: { min: number; max: number } }
113
+ | [[number, number], [number, number]]
114
+ | [[], []];
109
115
 
110
116
  interface CalcsResult {
111
- axis: [number[], number[]];
117
+ axis: { x: number[]; y: number[] } | [number[], number[]];
112
118
  bounds: Bounds;
113
- dimensions: [number, number];
119
+ dimensions: { width: number; height: number } | [number, number];
114
120
  pad: string;
115
121
  thickness: string;
116
122
  }
@@ -11,7 +11,16 @@ var PropType = {};
11
11
  if (process.env.NODE_ENV !== 'production') {
12
12
  PropType = _extends({}, _generalPropTypes.genericProps, {
13
13
  animate: _propTypes["default"].bool,
14
- bounds: _propTypes["default"].arrayOf(_propTypes["default"].arrayOf(_propTypes["default"].number)),
14
+ bounds: _propTypes["default"].oneOfType([_propTypes["default"].shape({
15
+ x: _propTypes["default"].shape({
16
+ min: _propTypes["default"].number,
17
+ max: _propTypes["default"].number
18
+ }),
19
+ y: _propTypes["default"].shape({
20
+ min: _propTypes["default"].number,
21
+ max: _propTypes["default"].number
22
+ })
23
+ }), _propTypes["default"].arrayOf(_propTypes["default"].arrayOf(_propTypes["default"].number))]),
15
24
  color: _propTypes["default"].oneOfType([_generalPropTypes.colorPropType, _propTypes["default"].shape({
16
25
  color: _generalPropTypes.colorPropType,
17
26
  // deprecated, use top level 'opacity'
@@ -1,11 +1,24 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports["default"] = exports.Vertical = void 0;
4
+ exports["default"] = exports.Horizontal = void 0;
5
5
  var _react = _interopRequireDefault(require("react"));
6
6
  var _grommet = require("grommet");
7
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8
- var Vertical = function Vertical() {
8
+ var gradient = [{
9
+ value: 0,
10
+ color: 'status-ok'
11
+ }, {
12
+ value: 25,
13
+ color: 'status-ok'
14
+ }, {
15
+ value: 27,
16
+ color: 'status-warning'
17
+ }, {
18
+ value: 30,
19
+ color: 'status-critical'
20
+ }];
21
+ var Horizontal = function Horizontal() {
9
22
  return (
10
23
  /*#__PURE__*/
11
24
  // Uncomment <Grommet> lines when using outside of storybook
@@ -19,7 +32,7 @@ var Vertical = function Vertical() {
19
32
  key: type,
20
33
  direction: "row",
21
34
  gap: "medium"
22
- }, ['horizontal', 'vertical'].map(function (direction) {
35
+ }, ['vertical', 'horizontal'].map(function (direction) {
23
36
  return /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
24
37
  key: direction,
25
38
  border: true
@@ -30,12 +43,27 @@ var Vertical = function Vertical() {
30
43
  values: [[10, 20], [20, 30], [30, 15]]
31
44
  }));
32
45
  }));
33
- }))
46
+ }), /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
47
+ direction: "row",
48
+ gap: "medium"
49
+ }, ['vertical', 'horizontal'].map(function (direction) {
50
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
51
+ key: direction,
52
+ border: true
53
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.Chart, {
54
+ id: direction,
55
+ type: "line",
56
+ direction: direction,
57
+ color: gradient,
58
+ values: [20, 30, 15],
59
+ size: "small"
60
+ }));
61
+ })))
34
62
  // </Grommet>
35
63
  );
36
64
  };
37
- exports.Vertical = Vertical;
65
+ exports.Horizontal = Horizontal;
38
66
  var _default = {
39
- title: 'Visualizations/Chart/Vertical'
67
+ title: 'Visualizations/Chart/Horizontal'
40
68
  };
41
69
  exports["default"] = _default;