grommet 2.32.1 → 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.
- package/all/stories/CustomThemed/ExtendTheme.tsx +2 -4
- package/components/Chart/Chart.js +20 -20
- package/components/Chart/calcs.js +163 -92
- package/components/Chart/index.d.ts +10 -4
- package/components/Chart/propTypes.js +10 -1
- package/components/Chart/stories/{Vertical.js → Horizontal.js} +34 -6
- package/components/Chart/utils.js +68 -64
- package/components/CheckBox/StyledCheckBox.js +2 -2
- package/components/DataChart/DataChart.js +114 -68
- package/components/DataChart/Detail.js +55 -21
- package/components/DataChart/XAxis.js +33 -6
- package/components/DataChart/XGuide.js +14 -1
- package/components/DataChart/YAxis.js +58 -39
- package/components/DataChart/YGuide.js +13 -10
- package/components/DataChart/index.d.ts +2 -0
- package/components/DataChart/propTypes.js +3 -1
- package/components/DataChart/stories/Horizontal.js +63 -0
- package/components/DataChart/utils.js +27 -2
- package/components/DataFilter/DataFilter.js +25 -2
- package/components/DataSort/DataSort.js +1 -1
- package/components/DataTable/buildState.js +6 -1
- package/components/DateInput/DateInput.js +22 -2
- package/components/Footer/stories/DoubleFooter.js +6 -2
- package/components/Footer/stories/Sitemap.js +0 -2
- package/components/Footer/stories/Social.js +2 -2
- package/components/Layer/LayerContainer.js +1 -1
- package/components/Menu/Menu.js +9 -6
- package/components/Meter/Bar.js +5 -2
- package/components/Meter/Meter.js +11 -3
- package/components/Meter/StyledMeter.js +3 -1
- package/components/Meter/index.d.ts +1 -0
- package/components/Meter/propTypes.js +1 -0
- package/components/Meter/stories/ReverseBar.js +29 -0
- package/components/Pagination/Pagination.js +3 -1
- package/components/Select/EmptySearchOption.js +3 -9
- package/components/Select/Select.js +1 -1
- package/components/Select/SelectContainer.js +4 -4
- package/components/Select/index.d.ts +1 -1
- package/components/Select/propTypes.js +1 -1
- package/components/SelectMultiple/SelectMultipleContainer.js +4 -4
- package/components/Text/Text.js +3 -1
- package/es6/all/stories/CustomThemed/ExtendTheme.tsx +2 -4
- package/es6/components/Chart/Chart.js +20 -20
- package/es6/components/Chart/calcs.js +164 -93
- package/es6/components/Chart/index.d.ts +10 -4
- package/es6/components/Chart/propTypes.js +10 -1
- package/es6/components/Chart/stories/{Vertical.js → Horizontal.js} +32 -4
- package/es6/components/Chart/utils.js +66 -63
- package/es6/components/CheckBox/StyledCheckBox.js +2 -2
- package/es6/components/DataChart/DataChart.js +115 -69
- package/es6/components/DataChart/Detail.js +55 -21
- package/es6/components/DataChart/XAxis.js +33 -6
- package/es6/components/DataChart/XGuide.js +14 -1
- package/es6/components/DataChart/YAxis.js +59 -40
- package/es6/components/DataChart/YGuide.js +13 -10
- package/es6/components/DataChart/index.d.ts +2 -0
- package/es6/components/DataChart/propTypes.js +3 -1
- package/es6/components/DataChart/stories/Horizontal.js +57 -0
- package/es6/components/DataChart/utils.js +22 -0
- package/es6/components/DataFilter/DataFilter.js +27 -3
- package/es6/components/DataSort/DataSort.js +1 -1
- package/es6/components/DataTable/buildState.js +6 -1
- package/es6/components/DateInput/DateInput.js +22 -2
- package/es6/components/Footer/stories/DoubleFooter.js +6 -2
- package/es6/components/Footer/stories/Sitemap.js +0 -2
- package/es6/components/Footer/stories/Social.js +2 -2
- package/es6/components/Layer/LayerContainer.js +1 -1
- package/es6/components/Menu/Menu.js +9 -6
- package/es6/components/Meter/Bar.js +5 -2
- package/es6/components/Meter/Meter.js +12 -4
- package/es6/components/Meter/StyledMeter.js +3 -1
- package/es6/components/Meter/index.d.ts +1 -0
- package/es6/components/Meter/propTypes.js +1 -0
- package/es6/components/Meter/stories/ReverseBar.js +23 -0
- package/es6/components/Pagination/Pagination.js +3 -1
- package/es6/components/Select/EmptySearchOption.js +3 -9
- package/es6/components/Select/Select.js +1 -1
- package/es6/components/Select/SelectContainer.js +4 -4
- package/es6/components/Select/index.d.ts +1 -1
- package/es6/components/Select/propTypes.js +1 -1
- package/es6/components/SelectMultiple/SelectMultipleContainer.js +4 -4
- package/es6/components/Text/Text.js +3 -1
- package/es6/themes/base.d.ts +9 -1
- package/es6/themes/base.js +4 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/package.json +39 -39
- package/themes/base.d.ts +9 -1
- package/themes/base.js +4 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.normalizeValues = exports.normalizeBounds = exports.areNormalizedValuesEquals = exports.areNormalizedBoundsEquals = void 0;
|
|
4
|
+
exports.normalizeValues = exports.normalizeBounds = exports.calcMinMax = exports.areNormalizedValuesEquals = exports.areNormalizedBoundsEquals = void 0;
|
|
5
5
|
var normalizeValues = function normalizeValues(values) {
|
|
6
6
|
return (values || []).map(function (value, index) {
|
|
7
7
|
if (value === undefined) return {
|
|
@@ -17,72 +17,76 @@ var normalizeValues = function normalizeValues(values) {
|
|
|
17
17
|
});
|
|
18
18
|
};
|
|
19
19
|
exports.normalizeValues = normalizeValues;
|
|
20
|
+
var calcMinMax = function calcMinMax(values, direction) {
|
|
21
|
+
var _ref, _ref2, _ref3, _ref4;
|
|
22
|
+
if (values === void 0) {
|
|
23
|
+
values = [];
|
|
24
|
+
}
|
|
25
|
+
// We default to 0 minimum as that's typically what's wanted.
|
|
26
|
+
// If callers want a narrower band, they can pass bounds explicitly.
|
|
27
|
+
var min0 = (_ref = direction && 0) != null ? _ref : undefined;
|
|
28
|
+
var max0 = (_ref2 = direction && 1) != null ? _ref2 : undefined;
|
|
29
|
+
var min1 = (_ref3 = direction && 0) != null ? _ref3 : undefined;
|
|
30
|
+
var max1 = (_ref4 = direction && 1) != null ? _ref4 : undefined;
|
|
31
|
+
values.forEach(function (value) {
|
|
32
|
+
var _value$value = value.value,
|
|
33
|
+
val0 = _value$value[0],
|
|
34
|
+
val1 = _value$value[1],
|
|
35
|
+
val2 = _value$value[2];
|
|
36
|
+
if (val0 !== undefined) {
|
|
37
|
+
min0 = min0 === undefined ? val0 : Math.min(min0, val0);
|
|
38
|
+
max0 = max0 === undefined ? val0 : Math.max(max0, val0);
|
|
39
|
+
}
|
|
40
|
+
if (val1 !== undefined) {
|
|
41
|
+
min1 = min1 === undefined ? val1 : Math.min(min1, val1);
|
|
42
|
+
max1 = max1 === undefined ? val1 : Math.max(max1, val1);
|
|
43
|
+
}
|
|
44
|
+
if (val2 !== undefined) {
|
|
45
|
+
min1 = min1 === undefined ? val2 : Math.min(min1, val2);
|
|
46
|
+
max1 = max1 === undefined ? val2 : Math.max(max1, val2);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// when max === min, offset them so we can show something
|
|
51
|
+
if (max0 === min0) {
|
|
52
|
+
if (max0 > 0) min0 = max0 - 1;else max0 = min0 + 1;
|
|
53
|
+
}
|
|
54
|
+
if (max1 === min1) {
|
|
55
|
+
if (max1 > 0) min1 = max1 - 1;else max1 = min1 + 1;
|
|
56
|
+
}
|
|
57
|
+
return direction === 'horizontal' ? {
|
|
58
|
+
x: {
|
|
59
|
+
min: min1,
|
|
60
|
+
max: max1
|
|
61
|
+
},
|
|
62
|
+
y: {
|
|
63
|
+
min: min0,
|
|
64
|
+
max: max0
|
|
65
|
+
}
|
|
66
|
+
} : {
|
|
67
|
+
x: {
|
|
68
|
+
min: min0,
|
|
69
|
+
max: max0
|
|
70
|
+
},
|
|
71
|
+
y: {
|
|
72
|
+
min: min1,
|
|
73
|
+
max: max1
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
exports.calcMinMax = calcMinMax;
|
|
20
78
|
var normalizeBounds = function normalizeBounds(boundsProp, values, direction) {
|
|
21
|
-
var vertical = direction === 'vertical';
|
|
22
79
|
var result;
|
|
23
|
-
if (boundsProp) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
max: boundsProp[0][1]
|
|
32
|
-
}
|
|
33
|
-
};else result = {
|
|
34
|
-
x: {
|
|
35
|
-
min: boundsProp[0][0],
|
|
36
|
-
max: boundsProp[0][1]
|
|
37
|
-
},
|
|
38
|
-
y: {
|
|
39
|
-
min: boundsProp[1][0],
|
|
40
|
-
max: boundsProp[1][1]
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
} else {
|
|
44
|
-
var min0 = 0;
|
|
45
|
-
var max0 = 1;
|
|
46
|
-
var min1 = 0;
|
|
47
|
-
var max1 = 1;
|
|
48
|
-
(values || []).forEach(function (value) {
|
|
49
|
-
if (value.value[0] !== undefined) {
|
|
50
|
-
min0 = Math.min(min0, value.value[0]);
|
|
51
|
-
max0 = Math.max(max0, value.value[0]);
|
|
52
|
-
}
|
|
53
|
-
if (value.value[1] !== undefined) {
|
|
54
|
-
min1 = Math.min(min1, value.value[1]);
|
|
55
|
-
max1 = Math.max(max1, value.value[1]);
|
|
56
|
-
}
|
|
57
|
-
if (value.value[2] !== undefined) {
|
|
58
|
-
min1 = Math.min(min1, value.value[2]);
|
|
59
|
-
max1 = Math.max(max1, value.value[2]);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
if (vertical) {
|
|
63
|
-
result = {
|
|
64
|
-
x: {
|
|
65
|
-
min: min1,
|
|
66
|
-
max: max1
|
|
67
|
-
},
|
|
68
|
-
y: {
|
|
69
|
-
min: min0,
|
|
70
|
-
max: max0
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
} else {
|
|
74
|
-
result = {
|
|
75
|
-
x: {
|
|
76
|
-
min: min0,
|
|
77
|
-
max: max0
|
|
78
|
-
},
|
|
79
|
-
y: {
|
|
80
|
-
min: min1,
|
|
81
|
-
max: max1
|
|
82
|
-
}
|
|
83
|
-
};
|
|
80
|
+
if (Array.isArray(boundsProp)) result = {
|
|
81
|
+
x: {
|
|
82
|
+
min: boundsProp[0][0],
|
|
83
|
+
max: boundsProp[0][1]
|
|
84
|
+
},
|
|
85
|
+
y: {
|
|
86
|
+
min: boundsProp[1][0],
|
|
87
|
+
max: boundsProp[1][1]
|
|
84
88
|
}
|
|
85
|
-
}
|
|
89
|
+
};else if (typeof boundsProp === 'object') result = boundsProp;else result = calcMinMax(values, direction);
|
|
86
90
|
return result;
|
|
87
91
|
};
|
|
88
92
|
exports.normalizeBounds = normalizeBounds;
|
|
@@ -11,7 +11,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
11
11
|
// added to it to simplify its logic. If this is ever reused somewhere else,
|
|
12
12
|
// consider the need of separating those once again.
|
|
13
13
|
var fillStyle = function fillStyle() {
|
|
14
|
-
return "\n width:
|
|
14
|
+
return "\n width: auto;\n height: 100%;\n max-width: none;\n flex: 1 0 auto;\n justify-content: space-between;\n ";
|
|
15
15
|
};
|
|
16
16
|
var disabledStyle = "\n opacity: 0.5;\n cursor: default;\n";
|
|
17
17
|
var hoverStyle = (0, _styledComponents.css)([":hover input:not([disabled]) + div,:hover input:not([disabled]) + span{border-color:", ";", "}:hover{background-color:", ";}"], function (props) {
|
|
@@ -56,7 +56,7 @@ var StyledCheckBoxContainer = _styledComponents["default"].label.withConfig({
|
|
|
56
56
|
return !props.disabled && 'cursor: pointer;';
|
|
57
57
|
}, hoverStyle, function (props) {
|
|
58
58
|
var _props$theme$checkBox6, _props$theme$checkBox7, _props$theme$checkBox8, _props$theme$checkBox9;
|
|
59
|
-
return props.focus && !props.focusIndicator && "\n input:not([disabled]) + div,\n input:not([disabled]) + span {\n border-color: " + (0, _utils.normalizeColor)((_props$theme$checkBox6 = props.theme.checkBox.hover) == null ? void 0 : (_props$theme$checkBox7 = _props$theme$checkBox6.border) == null ? void 0 : _props$theme$checkBox7.color, props.theme) + ";\n }\n
|
|
59
|
+
return props.focus && !props.focusIndicator && "\n input:not([disabled]) + div,\n input:not([disabled]) + span {\n border-color: " + (0, _utils.normalizeColor)((_props$theme$checkBox6 = props.theme.checkBox.hover) == null ? void 0 : (_props$theme$checkBox7 = _props$theme$checkBox6.border) == null ? void 0 : _props$theme$checkBox7.color, props.theme) + ";\n }\n\n background-color: " + (0, _utils.normalizeColor)(!props.disabled && ((_props$theme$checkBox8 = props.theme.checkBox.hover) == null ? void 0 : (_props$theme$checkBox9 = _props$theme$checkBox8.background) == null ? void 0 : _props$theme$checkBox9.color), props.theme) + ";";
|
|
60
60
|
}, function (props) {
|
|
61
61
|
return props.theme.checkBox.extend;
|
|
62
62
|
});
|
|
@@ -18,7 +18,7 @@ var _XGuide = require("./XGuide");
|
|
|
18
18
|
var _YGuide = require("./YGuide");
|
|
19
19
|
var _utils2 = require("./utils");
|
|
20
20
|
var _propTypes = require("./propTypes");
|
|
21
|
-
var _excluded = ["a11yTitle", "axis", "bounds", "chart", "data", "detail", "gap", "guide", "legend", "offset", "placeholder", "pad", "series", "size"],
|
|
21
|
+
var _excluded = ["a11yTitle", "axis", "bounds", "chart", "data", "detail", "direction", "gap", "guide", "legend", "offset", "placeholder", "pad", "series", "size"],
|
|
22
22
|
_excluded2 = ["property"],
|
|
23
23
|
_excluded3 = ["property", "type", "x", "y"],
|
|
24
24
|
_excluded4 = ["property"];
|
|
@@ -39,7 +39,7 @@ var stackedChartType = {
|
|
|
39
39
|
// normalize and automatically handle whatever the caller didn't specify.
|
|
40
40
|
|
|
41
41
|
var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
42
|
-
var _boundsProp$y;
|
|
42
|
+
var _boundsProp$x, _boundsProp$y;
|
|
43
43
|
var a11yTitle = _ref.a11yTitle,
|
|
44
44
|
_ref$axis = _ref.axis,
|
|
45
45
|
axisProp = _ref$axis === void 0 ? true : _ref$axis,
|
|
@@ -49,6 +49,8 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
49
49
|
_ref$data = _ref.data,
|
|
50
50
|
data = _ref$data === void 0 ? [] : _ref$data,
|
|
51
51
|
detail = _ref.detail,
|
|
52
|
+
_ref$direction = _ref.direction,
|
|
53
|
+
direction = _ref$direction === void 0 ? 'vertical' : _ref$direction,
|
|
52
54
|
_ref$gap = _ref.gap,
|
|
53
55
|
gap = _ref$gap === void 0 ? 'small' : _ref$gap,
|
|
54
56
|
guideProp = _ref.guide,
|
|
@@ -65,6 +67,9 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
65
67
|
var _useState = (0, _react.useState)(),
|
|
66
68
|
activeProperty = _useState[0],
|
|
67
69
|
setActiveProperty = _useState[1];
|
|
70
|
+
var horizontal = (0, _react.useMemo)(function () {
|
|
71
|
+
return direction === 'horizontal';
|
|
72
|
+
}, [direction]);
|
|
68
73
|
|
|
69
74
|
// normalize seriesProp to an array of objects, one per property
|
|
70
75
|
var series = (0, _react.useMemo)(function () {
|
|
@@ -214,20 +219,25 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
214
219
|
var steps = data.length - 1;
|
|
215
220
|
// special case property driven point charts
|
|
216
221
|
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;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
medium: medium
|
|
222
|
-
},
|
|
223
|
-
y: _extends({}, _utils2.heightYGranularity[size && size.height || 'small'] || {
|
|
224
|
-
fine: 5,
|
|
225
|
-
medium: 3
|
|
226
|
-
}, {
|
|
227
|
-
coarse: 2
|
|
228
|
-
})
|
|
222
|
+
var granularity0 = {
|
|
223
|
+
coarse: Math.min(data.length, 2),
|
|
224
|
+
fine: data.length,
|
|
225
|
+
medium: medium
|
|
229
226
|
};
|
|
230
|
-
|
|
227
|
+
var granularity1 = _extends({}, _utils2.heightYGranularity[size && size.height || 'small'] || {
|
|
228
|
+
fine: 5,
|
|
229
|
+
medium: 3
|
|
230
|
+
}, {
|
|
231
|
+
coarse: 2
|
|
232
|
+
});
|
|
233
|
+
return horizontal ? {
|
|
234
|
+
x: granularity1,
|
|
235
|
+
y: granularity0
|
|
236
|
+
} : {
|
|
237
|
+
x: granularity0,
|
|
238
|
+
y: granularity1
|
|
239
|
+
};
|
|
240
|
+
}, [charts, data.length, horizontal, size]);
|
|
231
241
|
|
|
232
242
|
// normalize axis to objects, convert granularity to a number
|
|
233
243
|
var axis = (0, _react.useMemo)(function () {
|
|
@@ -244,16 +254,23 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
244
254
|
if (result.x) {
|
|
245
255
|
if (!result.x.property) {
|
|
246
256
|
// see if we have a point chart that has an x property
|
|
247
|
-
if (
|
|
257
|
+
if (horizontal) {
|
|
258
|
+
if (charts[0]) result.x.property = charts[0].property.x || charts[0].property;
|
|
259
|
+
} else if (data && data[0]) {
|
|
248
260
|
if (data[0].date) result.x.property = 'date';else if (data[0].time) result.x.property = 'time';
|
|
249
261
|
}
|
|
250
262
|
}
|
|
251
263
|
if (!result.x.granularity) result.x.granularity = 'coarse';
|
|
252
264
|
}
|
|
253
265
|
if (result.y) {
|
|
254
|
-
if (!result.y.property
|
|
255
|
-
// see if we have a point chart that has an
|
|
256
|
-
|
|
266
|
+
if (!result.y.property) {
|
|
267
|
+
// see if we have a point chart that has an y property
|
|
268
|
+
if (horizontal) {
|
|
269
|
+
if (data && data[0]) {
|
|
270
|
+
if (data[0].date) result.y.property = 'date';else if (data[0].time) result.y.property = 'time';
|
|
271
|
+
}
|
|
272
|
+
} else if (charts[0]) result.y.property = charts[0].property.y || charts[0].property;
|
|
273
|
+
}
|
|
257
274
|
if (!result.y.granularity) result.y.granularity = 'coarse';
|
|
258
275
|
}
|
|
259
276
|
|
|
@@ -269,22 +286,22 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
269
286
|
result.y.count = granularities.y[_granularity];
|
|
270
287
|
}
|
|
271
288
|
return result;
|
|
272
|
-
}, [axisProp, data, charts, granularities]);
|
|
289
|
+
}, [axisProp, data, charts, granularities, horizontal]);
|
|
273
290
|
|
|
274
291
|
// calculate axis, bounds, and thickness for each chart
|
|
275
292
|
var chartProps = (0, _react.useMemo)(function () {
|
|
276
|
-
var steps =
|
|
277
|
-
var coarseness = [undefined, 5];
|
|
293
|
+
var steps = {};
|
|
294
|
+
var coarseness = horizontal ? [5, undefined] : [undefined, 5];
|
|
278
295
|
if (axis && axis.x) {
|
|
279
296
|
var _axis$x$granularity = axis.x.granularity,
|
|
280
297
|
granularity = _axis$x$granularity === void 0 ? 'coarse' : _axis$x$granularity;
|
|
281
|
-
steps
|
|
282
|
-
} else steps
|
|
298
|
+
steps.x = granularities.x[granularity] - 1;
|
|
299
|
+
} else steps.x = horizontal ? 1 : data.length - 1;
|
|
283
300
|
if (axis && axis.y) {
|
|
284
301
|
var _axis$y$granularity = axis.y.granularity,
|
|
285
302
|
_granularity2 = _axis$y$granularity === void 0 ? 'coarse' : _axis$y$granularity;
|
|
286
|
-
steps
|
|
287
|
-
} else steps
|
|
303
|
+
steps.y = granularities.y[_granularity2] - 1;
|
|
304
|
+
} else steps.y = horizontal ? data.length - 1 : 1;
|
|
288
305
|
var chartBounds = chartValues.map(function (_, index) {
|
|
289
306
|
var type = charts[index].type;
|
|
290
307
|
if (stackedChartType[type]) {
|
|
@@ -302,32 +319,35 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
302
319
|
});
|
|
303
320
|
return (0, _Chart.calcBounds)(mergedValues, {
|
|
304
321
|
coarseness: coarseness,
|
|
322
|
+
direction: direction,
|
|
305
323
|
steps: steps
|
|
306
324
|
});
|
|
307
325
|
}
|
|
308
326
|
// if this is a data driven x chart, set coarseness for x
|
|
309
327
|
return (0, _Chart.calcBounds)(chartValues[index], {
|
|
310
|
-
coarseness: charts[index].property.x ?
|
|
328
|
+
coarseness: charts[index].property.x ? {
|
|
329
|
+
x: 5,
|
|
330
|
+
y: 5
|
|
331
|
+
} : coarseness,
|
|
332
|
+
direction: direction,
|
|
311
333
|
steps: steps
|
|
312
334
|
});
|
|
313
335
|
});
|
|
314
336
|
if (boundsProp === 'align' && chartBounds.length) {
|
|
315
|
-
var alignedBounds =
|
|
337
|
+
var alignedBounds = {
|
|
338
|
+
x: {},
|
|
339
|
+
y: {}
|
|
340
|
+
};
|
|
316
341
|
chartBounds.forEach(function (bounds) {
|
|
317
|
-
alignedBounds
|
|
318
|
-
alignedBounds
|
|
319
|
-
alignedBounds
|
|
320
|
-
alignedBounds
|
|
342
|
+
alignedBounds.x.min = (0, _utils2.minimum)(alignedBounds.x.min, bounds.x.min);
|
|
343
|
+
alignedBounds.x.max = (0, _utils2.maximum)(alignedBounds.x.max, bounds.x.max);
|
|
344
|
+
alignedBounds.y.min = (0, _utils2.minimum)(alignedBounds.y.min, bounds.y.min);
|
|
345
|
+
alignedBounds.y.max = (0, _utils2.maximum)(alignedBounds.y.max, bounds.y.max);
|
|
321
346
|
});
|
|
322
347
|
chartBounds = chartBounds.map(function () {
|
|
323
348
|
return alignedBounds;
|
|
324
349
|
});
|
|
325
350
|
}
|
|
326
|
-
if (typeof boundsProp === 'object') {
|
|
327
|
-
if (boundsProp.y) chartBounds = chartBounds.map(function (b) {
|
|
328
|
-
return [b[0], [].concat(boundsProp.y)];
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
351
|
return chartValues.map(function (values, index) {
|
|
332
352
|
var _charts$index = charts[index],
|
|
333
353
|
thickness = _charts$index.thickness,
|
|
@@ -335,11 +355,12 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
335
355
|
var calcValues = stackedChartType[type] ? values[0] : values;
|
|
336
356
|
return (0, _Chart.calcs)(calcValues, {
|
|
337
357
|
bounds: chartBounds[index],
|
|
358
|
+
direction: direction,
|
|
338
359
|
steps: steps,
|
|
339
360
|
thickness: thickness
|
|
340
361
|
});
|
|
341
362
|
});
|
|
342
|
-
}, [axis, boundsProp, charts, chartValues, data, granularities]);
|
|
363
|
+
}, [axis, boundsProp, charts, chartValues, data, direction, granularities, horizontal]);
|
|
343
364
|
|
|
344
365
|
// normalize how we style data properties for use by Legend and Detail
|
|
345
366
|
var seriesStyles = (0, _react.useMemo)(function () {
|
|
@@ -429,15 +450,22 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
429
450
|
// except when using offset, then add even more horizontal pad
|
|
430
451
|
var pad = (0, _react.useMemo)(function () {
|
|
431
452
|
if (padProp !== undefined) return padProp;
|
|
432
|
-
var
|
|
453
|
+
var pad0;
|
|
454
|
+
var pad1;
|
|
433
455
|
charts.forEach(function (_ref7, index) {
|
|
434
456
|
var type = _ref7.type;
|
|
435
457
|
var thickness = chartProps[index].thickness;
|
|
436
|
-
|
|
437
|
-
if (type && type !== 'bar')
|
|
458
|
+
pad0 = (0, _utils2.largestSize)(pad0, _utils2.halfPad[thickness]);
|
|
459
|
+
if (type && type !== 'bar') pad1 = (0, _utils2.largestSize)(pad1, _utils2.halfPad[thickness]);
|
|
438
460
|
});
|
|
439
|
-
return
|
|
440
|
-
|
|
461
|
+
return horizontal ? {
|
|
462
|
+
horizontal: pad1,
|
|
463
|
+
vertical: pad0
|
|
464
|
+
} : {
|
|
465
|
+
horizontal: pad0,
|
|
466
|
+
vertical: pad1
|
|
467
|
+
};
|
|
468
|
+
}, [chartProps, charts, horizontal, padProp]);
|
|
441
469
|
|
|
442
470
|
// calculate the thickness in pixels of each chart
|
|
443
471
|
var thicknesses = (0, _react.useMemo)(function () {
|
|
@@ -495,47 +523,60 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
495
523
|
});
|
|
496
524
|
return result;
|
|
497
525
|
}, [axis, data, series]);
|
|
498
|
-
var renderValue = function renderValue(serie,
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (serie && serie.render) return serie.render(valueArg);
|
|
502
|
-
value = valueArg;
|
|
503
|
-
} else {
|
|
504
|
-
var datum = data[dataIndex];
|
|
505
|
-
value = datum[serie.property];
|
|
506
|
-
if (serie && serie.render) return serie.render(value, datum, serie.property);
|
|
526
|
+
var renderValue = function renderValue(serie, axisValue, y) {
|
|
527
|
+
if (serie === void 0) {
|
|
528
|
+
serie = {};
|
|
507
529
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
530
|
+
var _serie = serie,
|
|
531
|
+
prefix = _serie.prefix,
|
|
532
|
+
property = _serie.property,
|
|
533
|
+
render = _serie.render,
|
|
534
|
+
suffix = _serie.suffix;
|
|
535
|
+
var value = axisValue;
|
|
536
|
+
if (value !== undefined) {
|
|
537
|
+
if (!property || !horizontal && y || horizontal && !y) {
|
|
538
|
+
if (render) return render(value);
|
|
539
|
+
} else {
|
|
540
|
+
var datum = data[axisValue];
|
|
541
|
+
value = datum[property];
|
|
542
|
+
if (render) return render(value, datum, property);
|
|
543
|
+
}
|
|
544
|
+
if (property) {
|
|
545
|
+
var dateFormat = dateFormats[property];
|
|
546
|
+
if (dateFormat) return dateFormat(new Date(value));
|
|
547
|
+
if (prefix) value = "" + prefix + value;
|
|
548
|
+
if (suffix) value = "" + value + suffix;
|
|
549
|
+
}
|
|
513
550
|
}
|
|
514
551
|
return value;
|
|
515
552
|
};
|
|
516
553
|
|
|
517
554
|
// TODO: revisit how x/y axis are hooked up to charts and series
|
|
518
555
|
|
|
519
|
-
var xAxisElement = axis && axis.x && chartProps.length ? /*#__PURE__*/_react["default"].createElement(_XAxis.XAxis, {
|
|
556
|
+
var xAxisElement = axis && axis.x && (chartProps.length || boundsProp != null && boundsProp.x) ? /*#__PURE__*/_react["default"].createElement(_XAxis.XAxis, {
|
|
520
557
|
axis: axis,
|
|
521
|
-
values: (Array.isArray(chartProps[0]) ? chartProps[0][0] : chartProps[0]).axis
|
|
522
|
-
pad: offsetPad ? _extends({}, pad, {
|
|
558
|
+
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,
|
|
559
|
+
pad: !horizontal && offsetPad ? _extends({}, pad, {
|
|
523
560
|
end: offsetPad
|
|
524
561
|
}) : pad,
|
|
525
562
|
renderValue: renderValue,
|
|
526
|
-
thickness: segmentThickness,
|
|
527
563
|
serie: axis.x.property && getPropertySeries(axis.x.property),
|
|
528
564
|
style: offsetPad ? {
|
|
529
565
|
transform: "translate(" + offsets[Math.floor(offsets.length / 2)] + "px, 0px)"
|
|
530
566
|
} : {},
|
|
567
|
+
thickness: horizontal ? undefined : segmentThickness,
|
|
531
568
|
theme: theme
|
|
532
569
|
}) : null;
|
|
533
570
|
var yAxisElement = axis && axis.y && (chartProps.length || boundsProp != null && boundsProp.y) ? /*#__PURE__*/_react["default"].createElement(_YAxis.YAxis, {
|
|
534
571
|
axis: axis,
|
|
535
|
-
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
|
|
536
|
-
pad: pad,
|
|
572
|
+
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,
|
|
573
|
+
pad: horizontal && offsetPad ? _extends({}, pad, {
|
|
574
|
+
bottom: offsetPad
|
|
575
|
+
}) : pad,
|
|
537
576
|
renderValue: renderValue,
|
|
538
|
-
serie: axis.y.property && getPropertySeries(axis.y.property)
|
|
577
|
+
serie: axis.y.property && getPropertySeries(axis.y.property),
|
|
578
|
+
thickness: horizontal ? segmentThickness : undefined,
|
|
579
|
+
theme: theme
|
|
539
580
|
}) : null;
|
|
540
581
|
var stackFill = (0, _react.useMemo)(function () {
|
|
541
582
|
if (size === 'fill' || size && size.width === 'fill' && size.height === 'fill') return true;
|
|
@@ -555,10 +596,12 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
555
596
|
fill: stackFill
|
|
556
597
|
}, guide && guide.x && /*#__PURE__*/_react["default"].createElement(_XGuide.XGuide, {
|
|
557
598
|
guide: guide,
|
|
558
|
-
pad: pad
|
|
599
|
+
pad: pad,
|
|
600
|
+
thickness: horizontal
|
|
559
601
|
}), guide && guide.y && /*#__PURE__*/_react["default"].createElement(_YGuide.YGuide, {
|
|
560
602
|
guide: guide,
|
|
561
|
-
pad: pad
|
|
603
|
+
pad: pad,
|
|
604
|
+
thickness: !horizontal
|
|
562
605
|
}), charts.map(function (_ref9, i) {
|
|
563
606
|
var prop = _ref9.property,
|
|
564
607
|
type = _ref9.type,
|
|
@@ -592,7 +635,8 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
592
635
|
// when property name isn't valid, send empty array
|
|
593
636
|
,
|
|
594
637
|
values: chartValues[i][j] || [],
|
|
595
|
-
overflow: true
|
|
638
|
+
overflow: true,
|
|
639
|
+
direction: direction
|
|
596
640
|
}, seriesStyles[pProp], chartProps[i], chartRest, propRest, offsetProps, {
|
|
597
641
|
type: stackedChartType[type] || type,
|
|
598
642
|
size: size,
|
|
@@ -605,7 +649,8 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
605
649
|
, _extends({
|
|
606
650
|
key: i,
|
|
607
651
|
values: chartValues[i],
|
|
608
|
-
overflow: true
|
|
652
|
+
overflow: true,
|
|
653
|
+
direction: direction
|
|
609
654
|
}, seriesStyles[prop], chartProps[i], chartRest, offsetProps, {
|
|
610
655
|
type: type,
|
|
611
656
|
size: size,
|
|
@@ -626,6 +671,7 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
626
671
|
activeProperty: activeProperty,
|
|
627
672
|
axis: axis,
|
|
628
673
|
data: data,
|
|
674
|
+
horizontal: horizontal,
|
|
629
675
|
pad: pad,
|
|
630
676
|
series: series,
|
|
631
677
|
seriesStyles: seriesStyles,
|
|
@@ -13,6 +13,7 @@ var _utils = require("../../utils");
|
|
|
13
13
|
var _Swatch = require("./Swatch");
|
|
14
14
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
15
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
16
|
+
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); }
|
|
16
17
|
var DetailControl = (0, _styledComponents["default"])(_Box.Box).withConfig({
|
|
17
18
|
displayName: "Detail__DetailControl",
|
|
18
19
|
componentId: "sc-huiwg9-0"
|
|
@@ -21,6 +22,7 @@ var Detail = function Detail(_ref) {
|
|
|
21
22
|
var activeProperty = _ref.activeProperty,
|
|
22
23
|
axis = _ref.axis,
|
|
23
24
|
data = _ref.data,
|
|
25
|
+
horizontalProp = _ref.horizontal,
|
|
24
26
|
padProp = _ref.pad,
|
|
25
27
|
series = _ref.series,
|
|
26
28
|
seriesStyles = _ref.seriesStyles,
|
|
@@ -58,6 +60,21 @@ var Detail = function Detail(_ref) {
|
|
|
58
60
|
setDetailIndex(undefined);
|
|
59
61
|
}
|
|
60
62
|
}, []);
|
|
63
|
+
var dropAlign = (0, _react.useMemo)(function () {
|
|
64
|
+
var res;
|
|
65
|
+
if (detailIndex > data.length / 2) {
|
|
66
|
+
if (horizontalProp) res = {
|
|
67
|
+
bottom: 'top'
|
|
68
|
+
};else res = {
|
|
69
|
+
right: 'left'
|
|
70
|
+
};
|
|
71
|
+
} else if (horizontalProp) res = {
|
|
72
|
+
top: 'bottom'
|
|
73
|
+
};else res = {
|
|
74
|
+
left: 'right'
|
|
75
|
+
};
|
|
76
|
+
return res;
|
|
77
|
+
}, [data.length, detailIndex, horizontalProp]);
|
|
61
78
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Keyboard.Keyboard, {
|
|
62
79
|
onLeft: function onLeft() {
|
|
63
80
|
if (detailIndex === undefined) setDetailIndex(data.length - 1);else if (detailIndex > 0) setDetailIndex(detailIndex - 1);
|
|
@@ -65,26 +82,38 @@ var Detail = function Detail(_ref) {
|
|
|
65
82
|
onRight: function onRight() {
|
|
66
83
|
if (detailIndex === undefined) setDetailIndex(0);else if (detailIndex < data.length - 1) setDetailIndex(detailIndex + 1);
|
|
67
84
|
}
|
|
68
|
-
}, /*#__PURE__*/_react["default"].createElement(DetailControl, {
|
|
85
|
+
}, /*#__PURE__*/_react["default"].createElement(DetailControl, _extends({
|
|
69
86
|
key: "band",
|
|
70
87
|
tabIndex: 0,
|
|
71
|
-
direction: "row",
|
|
72
88
|
fill: true,
|
|
73
|
-
pad: pad,
|
|
74
89
|
justify: "between",
|
|
75
|
-
responsive: false
|
|
90
|
+
responsive: false
|
|
91
|
+
}, horizontalProp ? {
|
|
92
|
+
direction: 'column'
|
|
93
|
+
} : {
|
|
94
|
+
direction: 'row',
|
|
95
|
+
pad: pad
|
|
96
|
+
}, {
|
|
76
97
|
onFocus: function onFocus() {},
|
|
77
98
|
onBlur: function onBlur() {
|
|
78
99
|
return setDetailIndex(undefined);
|
|
79
100
|
}
|
|
80
|
-
}, data.map(function (_, i) {
|
|
101
|
+
}), data.map(function (_, i) {
|
|
102
|
+
var ref = function ref(c) {
|
|
103
|
+
detailRefs[i] = c;
|
|
104
|
+
};
|
|
81
105
|
return /*#__PURE__*/_react["default"].createElement(_Box.Box
|
|
82
106
|
// eslint-disable-next-line react/no-array-index-key
|
|
83
|
-
, {
|
|
107
|
+
, _extends({
|
|
84
108
|
key: i,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
109
|
+
responsive: false
|
|
110
|
+
}, horizontalProp ? {
|
|
111
|
+
justify: 'center',
|
|
112
|
+
height: thickness
|
|
113
|
+
} : {
|
|
114
|
+
align: 'center',
|
|
115
|
+
width: thickness
|
|
116
|
+
}, {
|
|
88
117
|
onMouseOver: function onMouseOver(event) {
|
|
89
118
|
activeIndex.current = event.currentTarget;
|
|
90
119
|
setDetailIndex(i);
|
|
@@ -92,21 +121,25 @@ var Detail = function Detail(_ref) {
|
|
|
92
121
|
onMouseLeave: onMouseLeave,
|
|
93
122
|
onFocus: function onFocus() {},
|
|
94
123
|
onBlur: function onBlur() {}
|
|
95
|
-
}, /*#__PURE__*/_react["default"].createElement(_Box.Box
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
124
|
+
}), /*#__PURE__*/_react["default"].createElement(_Box.Box
|
|
125
|
+
// for horizontal, ref will be placed on child box so
|
|
126
|
+
// drop is restricted to drop dimensions as opposed
|
|
127
|
+
// to filling the chart width
|
|
128
|
+
, _extends({}, horizontalProp ? {
|
|
129
|
+
fill: 'horizontal'
|
|
130
|
+
} : {
|
|
131
|
+
ref: ref,
|
|
132
|
+
fill: 'vertical'
|
|
133
|
+
}, {
|
|
100
134
|
border: detailIndex === i ? true : undefined
|
|
101
|
-
})
|
|
135
|
+
}), horizontalProp ? /*#__PURE__*/_react["default"].createElement(_Box.Box, {
|
|
136
|
+
alignSelf: "center",
|
|
137
|
+
ref: ref
|
|
138
|
+
}) : null));
|
|
102
139
|
}))), detailIndex !== undefined && detailRefs[detailIndex] && /*#__PURE__*/_react["default"].createElement(_Drop.Drop, {
|
|
103
140
|
key: "drop",
|
|
104
141
|
target: detailRefs[detailIndex],
|
|
105
|
-
align:
|
|
106
|
-
right: 'left'
|
|
107
|
-
} : {
|
|
108
|
-
left: 'right'
|
|
109
|
-
},
|
|
142
|
+
align: dropAlign,
|
|
110
143
|
plain: true,
|
|
111
144
|
onMouseLeave: onMouseLeave
|
|
112
145
|
}, /*#__PURE__*/_react["default"].createElement(_Box.Box, {
|
|
@@ -124,6 +157,7 @@ var Detail = function Detail(_ref) {
|
|
|
124
157
|
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;
|
|
125
158
|
}).map(function (serie) {
|
|
126
159
|
var propertyStyle = seriesStyles[serie.property];
|
|
160
|
+
var axisValue = horizontalProp ? data[detailIndex][serie.property] : detailIndex;
|
|
127
161
|
return /*#__PURE__*/_react["default"].createElement(_react.Fragment, {
|
|
128
162
|
key: serie.property
|
|
129
163
|
}, propertyStyle ? /*#__PURE__*/_react["default"].createElement(_Swatch.Swatch, propertyStyle) : /*#__PURE__*/_react["default"].createElement("span", null), /*#__PURE__*/_react["default"].createElement(_Text.Text, {
|
|
@@ -131,7 +165,7 @@ var Detail = function Detail(_ref) {
|
|
|
131
165
|
}, serie.label || serie.property), /*#__PURE__*/_react["default"].createElement(_Text.Text, {
|
|
132
166
|
size: "small",
|
|
133
167
|
weight: "bold"
|
|
134
|
-
}, renderValue(serie,
|
|
168
|
+
}, renderValue(serie, axisValue)));
|
|
135
169
|
})))));
|
|
136
170
|
};
|
|
137
171
|
exports.Detail = Detail;
|