grommet 2.32.2 → 2.33.1

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 (63) 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/DataTableColumns/DataTableColumns.js +2 -2
  22. package/components/DateInput/DateInput.js +22 -2
  23. package/components/Footer/stories/DoubleFooter.js +6 -2
  24. package/components/Footer/stories/Sitemap.js +0 -2
  25. package/components/Footer/stories/Social.js +2 -2
  26. package/components/Menu/Menu.js +9 -6
  27. package/components/Select/Select.js +1 -1
  28. package/components/SelectMultiple/SelectMultipleContainer.js +5 -5
  29. package/components/Tabs/Tabs.js +2 -1
  30. package/es6/all/stories/CustomThemed/ExtendTheme.tsx +2 -4
  31. package/es6/components/Chart/Chart.js +20 -20
  32. package/es6/components/Chart/calcs.js +164 -93
  33. package/es6/components/Chart/index.d.ts +10 -4
  34. package/es6/components/Chart/propTypes.js +10 -1
  35. package/es6/components/Chart/stories/{Vertical.js → Horizontal.js} +32 -4
  36. package/es6/components/Chart/utils.js +66 -63
  37. package/es6/components/DataChart/DataChart.js +115 -69
  38. package/es6/components/DataChart/Detail.js +55 -21
  39. package/es6/components/DataChart/XAxis.js +33 -6
  40. package/es6/components/DataChart/XGuide.js +14 -1
  41. package/es6/components/DataChart/YAxis.js +59 -40
  42. package/es6/components/DataChart/YGuide.js +13 -10
  43. package/es6/components/DataChart/index.d.ts +2 -0
  44. package/es6/components/DataChart/propTypes.js +3 -1
  45. package/es6/components/DataChart/stories/Horizontal.js +57 -0
  46. package/es6/components/DataChart/utils.js +22 -0
  47. package/es6/components/DataFilter/DataFilter.js +27 -3
  48. package/es6/components/DataSort/DataSort.js +1 -1
  49. package/es6/components/DataTable/buildState.js +6 -1
  50. package/es6/components/DataTableColumns/DataTableColumns.js +2 -2
  51. package/es6/components/DateInput/DateInput.js +22 -2
  52. package/es6/components/Footer/stories/DoubleFooter.js +6 -2
  53. package/es6/components/Footer/stories/Sitemap.js +0 -2
  54. package/es6/components/Footer/stories/Social.js +2 -2
  55. package/es6/components/Menu/Menu.js +9 -6
  56. package/es6/components/Select/Select.js +1 -1
  57. package/es6/components/SelectMultiple/SelectMultipleContainer.js +5 -5
  58. package/es6/components/Tabs/Tabs.js +2 -1
  59. package/es6/themes/base.d.ts +5 -1
  60. package/grommet.min.js +1 -1
  61. package/grommet.min.js.map +1 -1
  62. package/package.json +37 -40
  63. package/themes/base.d.ts +5 -1
@@ -1,6 +1,19 @@
1
1
  import React from 'react';
2
2
  import { Box, Chart } from 'grommet';
3
- export var Vertical = function Vertical() {
3
+ var gradient = [{
4
+ value: 0,
5
+ color: 'status-ok'
6
+ }, {
7
+ value: 25,
8
+ color: 'status-ok'
9
+ }, {
10
+ value: 27,
11
+ color: 'status-warning'
12
+ }, {
13
+ value: 30,
14
+ color: 'status-critical'
15
+ }];
16
+ export var Horizontal = function Horizontal() {
4
17
  return (
5
18
  /*#__PURE__*/
6
19
  // Uncomment <Grommet> lines when using outside of storybook
@@ -14,7 +27,7 @@ export var Vertical = function Vertical() {
14
27
  key: type,
15
28
  direction: "row",
16
29
  gap: "medium"
17
- }, ['horizontal', 'vertical'].map(function (direction) {
30
+ }, ['vertical', 'horizontal'].map(function (direction) {
18
31
  return /*#__PURE__*/React.createElement(Box, {
19
32
  key: direction,
20
33
  border: true
@@ -25,11 +38,26 @@ export var Vertical = function Vertical() {
25
38
  values: [[10, 20], [20, 30], [30, 15]]
26
39
  }));
27
40
  }));
28
- }))
41
+ }), /*#__PURE__*/React.createElement(Box, {
42
+ direction: "row",
43
+ gap: "medium"
44
+ }, ['vertical', 'horizontal'].map(function (direction) {
45
+ return /*#__PURE__*/React.createElement(Box, {
46
+ key: direction,
47
+ border: true
48
+ }, /*#__PURE__*/React.createElement(Chart, {
49
+ id: direction,
50
+ type: "line",
51
+ direction: direction,
52
+ color: gradient,
53
+ values: [20, 30, 15],
54
+ size: "small"
55
+ }));
56
+ })))
29
57
  // </Grommet>
30
58
  );
31
59
  };
32
60
 
33
61
  export default {
34
- title: 'Visualizations/Chart/Vertical'
62
+ title: 'Visualizations/Chart/Horizontal'
35
63
  };
@@ -12,72 +12,75 @@ export var normalizeValues = function normalizeValues(values) {
12
12
  };
13
13
  });
14
14
  };
15
+ export var calcMinMax = function calcMinMax(values, direction) {
16
+ var _ref, _ref2, _ref3, _ref4;
17
+ if (values === void 0) {
18
+ values = [];
19
+ }
20
+ // We default to 0 minimum as that's typically what's wanted.
21
+ // If callers want a narrower band, they can pass bounds explicitly.
22
+ var min0 = (_ref = direction && 0) != null ? _ref : undefined;
23
+ var max0 = (_ref2 = direction && 1) != null ? _ref2 : undefined;
24
+ var min1 = (_ref3 = direction && 0) != null ? _ref3 : undefined;
25
+ var max1 = (_ref4 = direction && 1) != null ? _ref4 : undefined;
26
+ values.forEach(function (value) {
27
+ var _value$value = value.value,
28
+ val0 = _value$value[0],
29
+ val1 = _value$value[1],
30
+ val2 = _value$value[2];
31
+ if (val0 !== undefined) {
32
+ min0 = min0 === undefined ? val0 : Math.min(min0, val0);
33
+ max0 = max0 === undefined ? val0 : Math.max(max0, val0);
34
+ }
35
+ if (val1 !== undefined) {
36
+ min1 = min1 === undefined ? val1 : Math.min(min1, val1);
37
+ max1 = max1 === undefined ? val1 : Math.max(max1, val1);
38
+ }
39
+ if (val2 !== undefined) {
40
+ min1 = min1 === undefined ? val2 : Math.min(min1, val2);
41
+ max1 = max1 === undefined ? val2 : Math.max(max1, val2);
42
+ }
43
+ });
44
+
45
+ // when max === min, offset them so we can show something
46
+ if (max0 === min0) {
47
+ if (max0 > 0) min0 = max0 - 1;else max0 = min0 + 1;
48
+ }
49
+ if (max1 === min1) {
50
+ if (max1 > 0) min1 = max1 - 1;else max1 = min1 + 1;
51
+ }
52
+ return direction === 'horizontal' ? {
53
+ x: {
54
+ min: min1,
55
+ max: max1
56
+ },
57
+ y: {
58
+ min: min0,
59
+ max: max0
60
+ }
61
+ } : {
62
+ x: {
63
+ min: min0,
64
+ max: max0
65
+ },
66
+ y: {
67
+ min: min1,
68
+ max: max1
69
+ }
70
+ };
71
+ };
15
72
  export var normalizeBounds = function normalizeBounds(boundsProp, values, direction) {
16
- var vertical = direction === 'vertical';
17
73
  var result;
18
- if (boundsProp) {
19
- if (vertical) result = {
20
- x: {
21
- min: boundsProp[1][0],
22
- max: boundsProp[1][1]
23
- },
24
- y: {
25
- min: boundsProp[0][0],
26
- max: boundsProp[0][1]
27
- }
28
- };else result = {
29
- x: {
30
- min: boundsProp[0][0],
31
- max: boundsProp[0][1]
32
- },
33
- y: {
34
- min: boundsProp[1][0],
35
- max: boundsProp[1][1]
36
- }
37
- };
38
- } else {
39
- var min0 = 0;
40
- var max0 = 1;
41
- var min1 = 0;
42
- var max1 = 1;
43
- (values || []).forEach(function (value) {
44
- if (value.value[0] !== undefined) {
45
- min0 = Math.min(min0, value.value[0]);
46
- max0 = Math.max(max0, value.value[0]);
47
- }
48
- if (value.value[1] !== undefined) {
49
- min1 = Math.min(min1, value.value[1]);
50
- max1 = Math.max(max1, value.value[1]);
51
- }
52
- if (value.value[2] !== undefined) {
53
- min1 = Math.min(min1, value.value[2]);
54
- max1 = Math.max(max1, value.value[2]);
55
- }
56
- });
57
- if (vertical) {
58
- result = {
59
- x: {
60
- min: min1,
61
- max: max1
62
- },
63
- y: {
64
- min: min0,
65
- max: max0
66
- }
67
- };
68
- } else {
69
- result = {
70
- x: {
71
- min: min0,
72
- max: max0
73
- },
74
- y: {
75
- min: min1,
76
- max: max1
77
- }
78
- };
74
+ if (Array.isArray(boundsProp)) result = {
75
+ x: {
76
+ min: boundsProp[0][0],
77
+ max: boundsProp[0][1]
78
+ },
79
+ y: {
80
+ min: boundsProp[1][0],
81
+ max: boundsProp[1][1]
79
82
  }
80
- }
83
+ };else if (typeof boundsProp === 'object') result = boundsProp;else result = calcMinMax(values, direction);
81
84
  return result;
82
85
  };
83
86
  export var areNormalizedValuesEquals = function areNormalizedValuesEquals(valuesX, valuesY) {
@@ -1,4 +1,4 @@
1
- var _excluded = ["a11yTitle", "axis", "bounds", "chart", "data", "detail", "gap", "guide", "legend", "offset", "placeholder", "pad", "series", "size"],
1
+ var _excluded = ["a11yTitle", "axis", "bounds", "chart", "data", "detail", "direction", "gap", "guide", "legend", "offset", "placeholder", "pad", "series", "size"],
2
2
  _excluded2 = ["property"],
3
3
  _excluded3 = ["property", "type", "x", "y"],
4
4
  _excluded4 = ["property"];
@@ -18,7 +18,7 @@ import { XAxis } from './XAxis';
18
18
  import { YAxis } from './YAxis';
19
19
  import { XGuide } from './XGuide';
20
20
  import { YGuide } from './YGuide';
21
- import { createDateFormat, halfPad, heightYGranularity, largestSize, points } from './utils';
21
+ import { createDateFormat, halfPad, heightYGranularity, largestSize, maximum, minimum, points } from './utils';
22
22
  import { DataChartPropTypes } from './propTypes';
23
23
  var stackedChartType = {
24
24
  areas: 'area',
@@ -33,7 +33,7 @@ var stackedChartType = {
33
33
  // normalize and automatically handle whatever the caller didn't specify.
34
34
 
35
35
  var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
36
- var _boundsProp$y;
36
+ var _boundsProp$x, _boundsProp$y;
37
37
  var a11yTitle = _ref.a11yTitle,
38
38
  _ref$axis = _ref.axis,
39
39
  axisProp = _ref$axis === void 0 ? true : _ref$axis,
@@ -43,6 +43,8 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
43
43
  _ref$data = _ref.data,
44
44
  data = _ref$data === void 0 ? [] : _ref$data,
45
45
  detail = _ref.detail,
46
+ _ref$direction = _ref.direction,
47
+ direction = _ref$direction === void 0 ? 'vertical' : _ref$direction,
46
48
  _ref$gap = _ref.gap,
47
49
  gap = _ref$gap === void 0 ? 'small' : _ref$gap,
48
50
  guideProp = _ref.guide,
@@ -59,6 +61,9 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
59
61
  var _useState = useState(),
60
62
  activeProperty = _useState[0],
61
63
  setActiveProperty = _useState[1];
64
+ var horizontal = useMemo(function () {
65
+ return direction === 'horizontal';
66
+ }, [direction]);
62
67
 
63
68
  // normalize seriesProp to an array of objects, one per property
64
69
  var series = useMemo(function () {
@@ -208,20 +213,25 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
208
213
  var steps = data.length - 1;
209
214
  // special case property driven point charts
210
215
  if (charts[0] && typeof charts[0].property === 'object') medium = 3;else if (steps < 4) medium = data.length;else if (steps === 4) medium = 3;else if (steps % 4 === 0) medium = 5;else if (steps % 3 === 0) medium = 4;else if (steps % 2 === 0) medium = 3;else medium = 2;
211
- return {
212
- x: {
213
- coarse: Math.min(data.length, 2),
214
- fine: data.length,
215
- medium: medium
216
- },
217
- y: _extends({}, heightYGranularity[size && size.height || 'small'] || {
218
- fine: 5,
219
- medium: 3
220
- }, {
221
- coarse: 2
222
- })
216
+ var granularity0 = {
217
+ coarse: Math.min(data.length, 2),
218
+ fine: data.length,
219
+ medium: medium
223
220
  };
224
- }, [charts, data.length, size]);
221
+ var granularity1 = _extends({}, heightYGranularity[size && size.height || 'small'] || {
222
+ fine: 5,
223
+ medium: 3
224
+ }, {
225
+ coarse: 2
226
+ });
227
+ return horizontal ? {
228
+ x: granularity1,
229
+ y: granularity0
230
+ } : {
231
+ x: granularity0,
232
+ y: granularity1
233
+ };
234
+ }, [charts, data.length, horizontal, size]);
225
235
 
226
236
  // normalize axis to objects, convert granularity to a number
227
237
  var axis = useMemo(function () {
@@ -238,16 +248,23 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
238
248
  if (result.x) {
239
249
  if (!result.x.property) {
240
250
  // see if we have a point chart that has an x property
241
- if (data && data[0]) {
251
+ if (horizontal) {
252
+ if (charts[0]) result.x.property = charts[0].property.x || charts[0].property;
253
+ } else if (data && data[0]) {
242
254
  if (data[0].date) result.x.property = 'date';else if (data[0].time) result.x.property = 'time';
243
255
  }
244
256
  }
245
257
  if (!result.x.granularity) result.x.granularity = 'coarse';
246
258
  }
247
259
  if (result.y) {
248
- if (!result.y.property && charts[0])
249
- // see if we have a point chart that has an x property
250
- result.y.property = charts[0].property.y || charts[0].property;
260
+ if (!result.y.property) {
261
+ // see if we have a point chart that has an y property
262
+ if (horizontal) {
263
+ if (data && data[0]) {
264
+ if (data[0].date) result.y.property = 'date';else if (data[0].time) result.y.property = 'time';
265
+ }
266
+ } else if (charts[0]) result.y.property = charts[0].property.y || charts[0].property;
267
+ }
251
268
  if (!result.y.granularity) result.y.granularity = 'coarse';
252
269
  }
253
270
 
@@ -263,22 +280,22 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
263
280
  result.y.count = granularities.y[_granularity];
264
281
  }
265
282
  return result;
266
- }, [axisProp, data, charts, granularities]);
283
+ }, [axisProp, data, charts, granularities, horizontal]);
267
284
 
268
285
  // calculate axis, bounds, and thickness for each chart
269
286
  var chartProps = useMemo(function () {
270
- var steps = [];
271
- var coarseness = [undefined, 5];
287
+ var steps = {};
288
+ var coarseness = horizontal ? [5, undefined] : [undefined, 5];
272
289
  if (axis && axis.x) {
273
290
  var _axis$x$granularity = axis.x.granularity,
274
291
  granularity = _axis$x$granularity === void 0 ? 'coarse' : _axis$x$granularity;
275
- steps[0] = granularities.x[granularity] - 1;
276
- } else steps[0] = data.length - 1;
292
+ steps.x = granularities.x[granularity] - 1;
293
+ } else steps.x = horizontal ? 1 : data.length - 1;
277
294
  if (axis && axis.y) {
278
295
  var _axis$y$granularity = axis.y.granularity,
279
296
  _granularity2 = _axis$y$granularity === void 0 ? 'coarse' : _axis$y$granularity;
280
- steps[1] = granularities.y[_granularity2] - 1;
281
- } else steps[1] = 1;
297
+ steps.y = granularities.y[_granularity2] - 1;
298
+ } else steps.y = horizontal ? data.length - 1 : 1;
282
299
  var chartBounds = chartValues.map(function (_, index) {
283
300
  var type = charts[index].type;
284
301
  if (stackedChartType[type]) {
@@ -296,32 +313,35 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
296
313
  });
297
314
  return calcBounds(mergedValues, {
298
315
  coarseness: coarseness,
316
+ direction: direction,
299
317
  steps: steps
300
318
  });
301
319
  }
302
320
  // if this is a data driven x chart, set coarseness for x
303
321
  return calcBounds(chartValues[index], {
304
- coarseness: charts[index].property.x ? [5, 5] : coarseness,
322
+ coarseness: charts[index].property.x ? {
323
+ x: 5,
324
+ y: 5
325
+ } : coarseness,
326
+ direction: direction,
305
327
  steps: steps
306
328
  });
307
329
  });
308
330
  if (boundsProp === 'align' && chartBounds.length) {
309
- var alignedBounds = [].concat(chartBounds[0]);
331
+ var alignedBounds = {
332
+ x: {},
333
+ y: {}
334
+ };
310
335
  chartBounds.forEach(function (bounds) {
311
- alignedBounds[0][0] = Math.min(alignedBounds[0][0], bounds[0][0]);
312
- alignedBounds[0][1] = Math.max(alignedBounds[0][1], bounds[0][1]);
313
- alignedBounds[1][0] = Math.min(alignedBounds[1][0], bounds[1][0]);
314
- alignedBounds[1][1] = Math.max(alignedBounds[1][1], bounds[1][1]);
336
+ alignedBounds.x.min = minimum(alignedBounds.x.min, bounds.x.min);
337
+ alignedBounds.x.max = maximum(alignedBounds.x.max, bounds.x.max);
338
+ alignedBounds.y.min = minimum(alignedBounds.y.min, bounds.y.min);
339
+ alignedBounds.y.max = maximum(alignedBounds.y.max, bounds.y.max);
315
340
  });
316
341
  chartBounds = chartBounds.map(function () {
317
342
  return alignedBounds;
318
343
  });
319
344
  }
320
- if (typeof boundsProp === 'object') {
321
- if (boundsProp.y) chartBounds = chartBounds.map(function (b) {
322
- return [b[0], [].concat(boundsProp.y)];
323
- });
324
- }
325
345
  return chartValues.map(function (values, index) {
326
346
  var _charts$index = charts[index],
327
347
  thickness = _charts$index.thickness,
@@ -329,11 +349,12 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
329
349
  var calcValues = stackedChartType[type] ? values[0] : values;
330
350
  return calcs(calcValues, {
331
351
  bounds: chartBounds[index],
352
+ direction: direction,
332
353
  steps: steps,
333
354
  thickness: thickness
334
355
  });
335
356
  });
336
- }, [axis, boundsProp, charts, chartValues, data, granularities]);
357
+ }, [axis, boundsProp, charts, chartValues, data, direction, granularities, horizontal]);
337
358
 
338
359
  // normalize how we style data properties for use by Legend and Detail
339
360
  var seriesStyles = useMemo(function () {
@@ -423,15 +444,22 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
423
444
  // except when using offset, then add even more horizontal pad
424
445
  var pad = useMemo(function () {
425
446
  if (padProp !== undefined) return padProp;
426
- var result = {};
447
+ var pad0;
448
+ var pad1;
427
449
  charts.forEach(function (_ref7, index) {
428
450
  var type = _ref7.type;
429
451
  var thickness = chartProps[index].thickness;
430
- result.horizontal = largestSize(result.horizontal, halfPad[thickness]);
431
- if (type && type !== 'bar') result.vertical = largestSize(result.vertical, halfPad[thickness]);
452
+ pad0 = largestSize(pad0, halfPad[thickness]);
453
+ if (type && type !== 'bar') pad1 = largestSize(pad1, halfPad[thickness]);
432
454
  });
433
- return result;
434
- }, [chartProps, charts, padProp]);
455
+ return horizontal ? {
456
+ horizontal: pad1,
457
+ vertical: pad0
458
+ } : {
459
+ horizontal: pad0,
460
+ vertical: pad1
461
+ };
462
+ }, [chartProps, charts, horizontal, padProp]);
435
463
 
436
464
  // calculate the thickness in pixels of each chart
437
465
  var thicknesses = useMemo(function () {
@@ -489,47 +517,60 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
489
517
  });
490
518
  return result;
491
519
  }, [axis, data, series]);
492
- var renderValue = function renderValue(serie, dataIndex, valueArg) {
493
- var value;
494
- if (valueArg !== undefined) {
495
- if (serie && serie.render) return serie.render(valueArg);
496
- value = valueArg;
497
- } else {
498
- var datum = data[dataIndex];
499
- value = datum[serie.property];
500
- if (serie && serie.render) return serie.render(value, datum, serie.property);
520
+ var renderValue = function renderValue(serie, axisValue, y) {
521
+ if (serie === void 0) {
522
+ serie = {};
501
523
  }
502
- if (serie) {
503
- var dateFormat = dateFormats[serie.property];
504
- if (dateFormat) return dateFormat(new Date(value));
505
- if (serie.prefix) value = "" + serie.prefix + value;
506
- if (serie.suffix) value = "" + value + serie.suffix;
524
+ var _serie = serie,
525
+ prefix = _serie.prefix,
526
+ property = _serie.property,
527
+ render = _serie.render,
528
+ suffix = _serie.suffix;
529
+ var value = axisValue;
530
+ if (value !== undefined) {
531
+ if (!property || !horizontal && y || horizontal && !y) {
532
+ if (render) return render(value);
533
+ } else {
534
+ var datum = data[axisValue];
535
+ value = datum[property];
536
+ if (render) return render(value, datum, property);
537
+ }
538
+ if (property) {
539
+ var dateFormat = dateFormats[property];
540
+ if (dateFormat) return dateFormat(new Date(value));
541
+ if (prefix) value = "" + prefix + value;
542
+ if (suffix) value = "" + value + suffix;
543
+ }
507
544
  }
508
545
  return value;
509
546
  };
510
547
 
511
548
  // TODO: revisit how x/y axis are hooked up to charts and series
512
549
 
513
- var xAxisElement = axis && axis.x && chartProps.length ? /*#__PURE__*/React.createElement(XAxis, {
550
+ var xAxisElement = axis && axis.x && (chartProps.length || boundsProp != null && boundsProp.x) ? /*#__PURE__*/React.createElement(XAxis, {
514
551
  axis: axis,
515
- values: (Array.isArray(chartProps[0]) ? chartProps[0][0] : chartProps[0]).axis[0],
516
- pad: offsetPad ? _extends({}, pad, {
552
+ values: (boundsProp == null ? void 0 : (_boundsProp$x = boundsProp.x) == null ? void 0 : _boundsProp$x.slice(0)) || (Array.isArray(chartProps[0]) ? chartProps[0][0] : chartProps[0]).axis.x,
553
+ pad: !horizontal && offsetPad ? _extends({}, pad, {
517
554
  end: offsetPad
518
555
  }) : pad,
519
556
  renderValue: renderValue,
520
- thickness: segmentThickness,
521
557
  serie: axis.x.property && getPropertySeries(axis.x.property),
522
558
  style: offsetPad ? {
523
559
  transform: "translate(" + offsets[Math.floor(offsets.length / 2)] + "px, 0px)"
524
560
  } : {},
561
+ thickness: horizontal ? undefined : segmentThickness,
525
562
  theme: theme
526
563
  }) : null;
527
564
  var yAxisElement = axis && axis.y && (chartProps.length || boundsProp != null && boundsProp.y) ? /*#__PURE__*/React.createElement(YAxis, {
528
565
  axis: axis,
529
- values: (boundsProp == null ? void 0 : (_boundsProp$y = boundsProp.y) == null ? void 0 : _boundsProp$y.slice(0).reverse()) || (Array.isArray(chartProps[0]) ? chartProps[0][0] : chartProps[0]).axis[1],
530
- pad: pad,
566
+ values: (boundsProp == null ? void 0 : (_boundsProp$y = boundsProp.y) == null ? void 0 : _boundsProp$y.slice(0).reverse()) || (Array.isArray(chartProps[0]) ? chartProps[0][0] : chartProps[0]).axis.y,
567
+ pad: horizontal && offsetPad ? _extends({}, pad, {
568
+ bottom: offsetPad
569
+ }) : pad,
531
570
  renderValue: renderValue,
532
- serie: axis.y.property && getPropertySeries(axis.y.property)
571
+ serie: axis.y.property && getPropertySeries(axis.y.property),
572
+ thickness: horizontal ? segmentThickness : undefined,
573
+ theme: theme
533
574
  }) : null;
534
575
  var stackFill = useMemo(function () {
535
576
  if (size === 'fill' || size && size.width === 'fill' && size.height === 'fill') return true;
@@ -549,10 +590,12 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
549
590
  fill: stackFill
550
591
  }, guide && guide.x && /*#__PURE__*/React.createElement(XGuide, {
551
592
  guide: guide,
552
- pad: pad
593
+ pad: pad,
594
+ thickness: horizontal
553
595
  }), guide && guide.y && /*#__PURE__*/React.createElement(YGuide, {
554
596
  guide: guide,
555
- pad: pad
597
+ pad: pad,
598
+ thickness: !horizontal
556
599
  }), charts.map(function (_ref9, i) {
557
600
  var prop = _ref9.property,
558
601
  type = _ref9.type,
@@ -586,7 +629,8 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
586
629
  // when property name isn't valid, send empty array
587
630
  ,
588
631
  values: chartValues[i][j] || [],
589
- overflow: true
632
+ overflow: true,
633
+ direction: direction
590
634
  }, seriesStyles[pProp], chartProps[i], chartRest, propRest, offsetProps, {
591
635
  type: stackedChartType[type] || type,
592
636
  size: size,
@@ -599,7 +643,8 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
599
643
  , _extends({
600
644
  key: i,
601
645
  values: chartValues[i],
602
- overflow: true
646
+ overflow: true,
647
+ direction: direction
603
648
  }, seriesStyles[prop], chartProps[i], chartRest, offsetProps, {
604
649
  type: type,
605
650
  size: size,
@@ -620,6 +665,7 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
620
665
  activeProperty: activeProperty,
621
666
  axis: axis,
622
667
  data: data,
668
+ horizontal: horizontal,
623
669
  pad: pad,
624
670
  series: series,
625
671
  seriesStyles: seriesStyles,
@@ -1,3 +1,4 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1
2
  import React, { Fragment, useCallback, useContext, useMemo, useRef, useState } from 'react';
2
3
  import styled, { ThemeContext } from 'styled-components';
3
4
  import { Box } from '../Box';
@@ -15,6 +16,7 @@ var Detail = function Detail(_ref) {
15
16
  var activeProperty = _ref.activeProperty,
16
17
  axis = _ref.axis,
17
18
  data = _ref.data,
19
+ horizontalProp = _ref.horizontal,
18
20
  padProp = _ref.pad,
19
21
  series = _ref.series,
20
22
  seriesStyles = _ref.seriesStyles,
@@ -52,6 +54,21 @@ var Detail = function Detail(_ref) {
52
54
  setDetailIndex(undefined);
53
55
  }
54
56
  }, []);
57
+ var dropAlign = useMemo(function () {
58
+ var res;
59
+ if (detailIndex > data.length / 2) {
60
+ if (horizontalProp) res = {
61
+ bottom: 'top'
62
+ };else res = {
63
+ right: 'left'
64
+ };
65
+ } else if (horizontalProp) res = {
66
+ top: 'bottom'
67
+ };else res = {
68
+ left: 'right'
69
+ };
70
+ return res;
71
+ }, [data.length, detailIndex, horizontalProp]);
55
72
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Keyboard, {
56
73
  onLeft: function onLeft() {
57
74
  if (detailIndex === undefined) setDetailIndex(data.length - 1);else if (detailIndex > 0) setDetailIndex(detailIndex - 1);
@@ -59,26 +76,38 @@ var Detail = function Detail(_ref) {
59
76
  onRight: function onRight() {
60
77
  if (detailIndex === undefined) setDetailIndex(0);else if (detailIndex < data.length - 1) setDetailIndex(detailIndex + 1);
61
78
  }
62
- }, /*#__PURE__*/React.createElement(DetailControl, {
79
+ }, /*#__PURE__*/React.createElement(DetailControl, _extends({
63
80
  key: "band",
64
81
  tabIndex: 0,
65
- direction: "row",
66
82
  fill: true,
67
- pad: pad,
68
83
  justify: "between",
69
- responsive: false,
84
+ responsive: false
85
+ }, horizontalProp ? {
86
+ direction: 'column'
87
+ } : {
88
+ direction: 'row',
89
+ pad: pad
90
+ }, {
70
91
  onFocus: function onFocus() {},
71
92
  onBlur: function onBlur() {
72
93
  return setDetailIndex(undefined);
73
94
  }
74
- }, data.map(function (_, i) {
95
+ }), data.map(function (_, i) {
96
+ var ref = function ref(c) {
97
+ detailRefs[i] = c;
98
+ };
75
99
  return /*#__PURE__*/React.createElement(Box
76
100
  // eslint-disable-next-line react/no-array-index-key
77
- , {
101
+ , _extends({
78
102
  key: i,
79
- align: "center",
80
- responsive: false,
81
- width: thickness,
103
+ responsive: false
104
+ }, horizontalProp ? {
105
+ justify: 'center',
106
+ height: thickness
107
+ } : {
108
+ align: 'center',
109
+ width: thickness
110
+ }, {
82
111
  onMouseOver: function onMouseOver(event) {
83
112
  activeIndex.current = event.currentTarget;
84
113
  setDetailIndex(i);
@@ -86,21 +115,25 @@ var Detail = function Detail(_ref) {
86
115
  onMouseLeave: onMouseLeave,
87
116
  onFocus: function onFocus() {},
88
117
  onBlur: function onBlur() {}
89
- }, /*#__PURE__*/React.createElement(Box, {
90
- ref: function ref(c) {
91
- detailRefs[i] = c;
92
- },
93
- fill: "vertical",
118
+ }), /*#__PURE__*/React.createElement(Box
119
+ // for horizontal, ref will be placed on child box so
120
+ // drop is restricted to drop dimensions as opposed
121
+ // to filling the chart width
122
+ , _extends({}, horizontalProp ? {
123
+ fill: 'horizontal'
124
+ } : {
125
+ ref: ref,
126
+ fill: 'vertical'
127
+ }, {
94
128
  border: detailIndex === i ? true : undefined
95
- }));
129
+ }), horizontalProp ? /*#__PURE__*/React.createElement(Box, {
130
+ alignSelf: "center",
131
+ ref: ref
132
+ }) : null));
96
133
  }))), detailIndex !== undefined && detailRefs[detailIndex] && /*#__PURE__*/React.createElement(Drop, {
97
134
  key: "drop",
98
135
  target: detailRefs[detailIndex],
99
- align: detailIndex > data.length / 2 ? {
100
- right: 'left'
101
- } : {
102
- left: 'right'
103
- },
136
+ align: dropAlign,
104
137
  plain: true,
105
138
  onMouseLeave: onMouseLeave
106
139
  }, /*#__PURE__*/React.createElement(Box, {
@@ -118,6 +151,7 @@ var Detail = function Detail(_ref) {
118
151
  return (!activeProperty || activeProperty === property) && (data == null ? void 0 : (_data$detailIndex = data[detailIndex]) == null ? void 0 : _data$detailIndex[property]) !== undefined || axis && axis.x && axis.x.property === property;
119
152
  }).map(function (serie) {
120
153
  var propertyStyle = seriesStyles[serie.property];
154
+ var axisValue = horizontalProp ? data[detailIndex][serie.property] : detailIndex;
121
155
  return /*#__PURE__*/React.createElement(Fragment, {
122
156
  key: serie.property
123
157
  }, propertyStyle ? /*#__PURE__*/React.createElement(Swatch, propertyStyle) : /*#__PURE__*/React.createElement("span", null), /*#__PURE__*/React.createElement(Text, {
@@ -125,7 +159,7 @@ var Detail = function Detail(_ref) {
125
159
  }, serie.label || serie.property), /*#__PURE__*/React.createElement(Text, {
126
160
  size: "small",
127
161
  weight: "bold"
128
- }, renderValue(serie, detailIndex)));
162
+ }, renderValue(serie, axisValue)));
129
163
  })))));
130
164
  };
131
165
  export { Detail };