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.
- 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/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/Menu/Menu.js +9 -6
- package/components/Select/Select.js +1 -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/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/Menu/Menu.js +9 -6
- package/es6/components/Select/Select.js +1 -1
- package/es6/themes/base.d.ts +5 -1
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/package.json +37 -37
- 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
|
|
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
|
|
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
|
};
|
|
@@ -24,7 +24,8 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
24
24
|
boundsProp = _ref.bounds,
|
|
25
25
|
color = _ref.color,
|
|
26
26
|
dash = _ref.dash,
|
|
27
|
-
direction = _ref.direction,
|
|
27
|
+
_ref$direction = _ref.direction,
|
|
28
|
+
direction = _ref$direction === void 0 ? 'vertical' : _ref$direction,
|
|
28
29
|
gap = _ref.gap,
|
|
29
30
|
id = _ref.id,
|
|
30
31
|
onClick = _ref.onClick,
|
|
@@ -36,8 +37,7 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
36
37
|
pattern = _ref.pattern,
|
|
37
38
|
point = _ref.point,
|
|
38
39
|
round = _ref.round,
|
|
39
|
-
|
|
40
|
-
sizeProp = _ref$size === void 0 ? defaultSize : _ref$size,
|
|
40
|
+
sizeProp = _ref.size,
|
|
41
41
|
_ref$thickness = _ref.thickness,
|
|
42
42
|
thickness = _ref$thickness === void 0 ? 'medium' : _ref$thickness,
|
|
43
43
|
_ref$type = _ref.type,
|
|
@@ -50,11 +50,11 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
50
50
|
var values = useMemo(function () {
|
|
51
51
|
return normalizeValues(valuesProp);
|
|
52
52
|
}, [valuesProp]);
|
|
53
|
-
var
|
|
54
|
-
return direction === '
|
|
53
|
+
var horizontal = useMemo(function () {
|
|
54
|
+
return direction === 'horizontal';
|
|
55
55
|
}, [direction]);
|
|
56
56
|
|
|
57
|
-
// bounds is { x: { min, max }, y: { min, max } }
|
|
57
|
+
// bounds is { x: { min, max }, y: { min, max } }
|
|
58
58
|
var bounds = useMemo(function () {
|
|
59
59
|
return normalizeBounds(boundsProp, values, direction);
|
|
60
60
|
}, [direction, boundsProp, values]);
|
|
@@ -120,7 +120,7 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
120
120
|
|
|
121
121
|
// autoSize is how wide or tall we'd pefer based on the number of values
|
|
122
122
|
var autoSize = strokeWidth * values.length + (values.length - 1) * gapWidth;
|
|
123
|
-
var sizeWidth = typeof sizeProp === 'string' ? sizeProp : sizeProp.width || defaultSize.width;
|
|
123
|
+
var sizeWidth = typeof sizeProp === 'string' ? sizeProp : (sizeProp == null ? void 0 : sizeProp.width) || horizontal && defaultSize.height || defaultSize.width;
|
|
124
124
|
var width;
|
|
125
125
|
if (sizeWidth === 'full' || sizeWidth === 'fill') {
|
|
126
126
|
width = containerSize[0];
|
|
@@ -129,7 +129,7 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
129
129
|
} else {
|
|
130
130
|
width = parseMetricToNum(theme.global.size[sizeWidth] || sizeWidth);
|
|
131
131
|
}
|
|
132
|
-
var sizeHeight = typeof sizeProp === 'string' ? sizeProp : sizeProp.height || defaultSize.height;
|
|
132
|
+
var sizeHeight = typeof sizeProp === 'string' ? sizeProp : (sizeProp == null ? void 0 : sizeProp.height) || horizontal && defaultSize.width || defaultSize.height;
|
|
133
133
|
var height;
|
|
134
134
|
if (sizeHeight === 'full' || sizeHeight === 'fill') {
|
|
135
135
|
height = containerSize[1];
|
|
@@ -142,7 +142,7 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
142
142
|
width: width,
|
|
143
143
|
height: height
|
|
144
144
|
};
|
|
145
|
-
}, [containerSize, gap, sizeProp, strokeWidth, theme.global.edgeSize, theme.global.size, values]);
|
|
145
|
+
}, [containerSize, gap, horizontal, sizeProp, strokeWidth, theme.global.edgeSize, theme.global.size, values]);
|
|
146
146
|
|
|
147
147
|
// scale is { x, y }
|
|
148
148
|
var scale = useMemo(function () {
|
|
@@ -193,7 +193,7 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
193
193
|
// rendering helpers, to make rendering code easier to understand
|
|
194
194
|
|
|
195
195
|
var valueCoords = function valueCoords(x, y) {
|
|
196
|
-
return
|
|
196
|
+
return horizontal ? [y, x] : [x, y];
|
|
197
197
|
};
|
|
198
198
|
|
|
199
199
|
// Converts values to drawing coordinates.
|
|
@@ -201,8 +201,8 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
201
201
|
var valueToCoordinate = function valueToCoordinate(xValue, yValue) {
|
|
202
202
|
var y = (yValue - bounds.y.min) * scale.y + inset.top;
|
|
203
203
|
return [(xValue - bounds.x.min) * scale.x + inset.left,
|
|
204
|
-
//
|
|
205
|
-
|
|
204
|
+
// horizontal grows y top down, vertical grows y bottom up
|
|
205
|
+
horizontal ? y : size.height - y];
|
|
206
206
|
};
|
|
207
207
|
var useGradient = color && Array.isArray(color);
|
|
208
208
|
var patternId;
|
|
@@ -225,10 +225,10 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
225
225
|
valueRest = _objectWithoutPropertiesLoose(valueArg, _excluded2);
|
|
226
226
|
var key = "p-" + index;
|
|
227
227
|
// Math.min/max are to handle negative values
|
|
228
|
-
var _valueCoords = valueCoords(value[0], value.length === 2 ? Math.min(Math.max(0,
|
|
228
|
+
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])),
|
|
229
229
|
startX = _valueCoords[0],
|
|
230
230
|
startY = _valueCoords[1];
|
|
231
|
-
var _valueCoords2 = valueCoords(value[0], value.length === 2 ? Math.max(Math.min(0,
|
|
231
|
+
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])),
|
|
232
232
|
endX = _valueCoords2[0],
|
|
233
233
|
endY = _valueCoords2[1];
|
|
234
234
|
var d = "M " + valueToCoordinate(startX, startY).join(',') + (" L " + valueToCoordinate(endX, endY).join(','));
|
|
@@ -331,7 +331,7 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
331
331
|
var value = _ref8.value;
|
|
332
332
|
var _valueCoords6 = valueCoords(value[0],
|
|
333
333
|
// Math.max() is to account for value[1] being negative
|
|
334
|
-
value.length === 2 ? Math.max(0,
|
|
334
|
+
value.length === 2 ? Math.max(0, horizontal ? bounds.x.min : bounds.y.min) : value[1]),
|
|
335
335
|
x = _valueCoords6[0],
|
|
336
336
|
y = _valueCoords6[1];
|
|
337
337
|
d += " L " + valueToCoordinate(x, y).join(',');
|
|
@@ -468,7 +468,7 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
468
468
|
}, contents);
|
|
469
469
|
var defs = [];
|
|
470
470
|
var gradientRect;
|
|
471
|
-
if (useGradient && size.height) {
|
|
471
|
+
if (useGradient && (horizontal && size.width || size.height)) {
|
|
472
472
|
var uniqueGradientId = color.map(function (element) {
|
|
473
473
|
return element.color;
|
|
474
474
|
}).join('-');
|
|
@@ -479,16 +479,16 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
479
479
|
id: gradientId,
|
|
480
480
|
x1: 0,
|
|
481
481
|
y1: 0,
|
|
482
|
-
x2: 0,
|
|
483
|
-
y2: 1
|
|
482
|
+
x2: horizontal ? 1 : 0,
|
|
483
|
+
y2: horizontal ? 0 : 1
|
|
484
484
|
}, color.slice(0).sort(function (c1, c2) {
|
|
485
|
-
return c2.value - c1.value;
|
|
485
|
+
return horizontal ? c1.value - c2.value : c2.value - c1.value;
|
|
486
486
|
}).map(function (_ref10) {
|
|
487
487
|
var value = _ref10.value,
|
|
488
488
|
gradientColor = _ref10.color;
|
|
489
489
|
return /*#__PURE__*/React.createElement("stop", {
|
|
490
490
|
key: value,
|
|
491
|
-
offset: (size.height - (value - bounds.y.min) * scale.y) / size.height,
|
|
491
|
+
offset: horizontal ? (value - bounds.x.min) * scale.x / size.width : (size.height - (value - bounds.y.min) * scale.y) / size.height,
|
|
492
492
|
stopColor: normalizeColor(gradientColor, theme)
|
|
493
493
|
});
|
|
494
494
|
})));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeValues } from './utils';
|
|
1
|
+
import { calcMinMax, normalizeValues } from './utils';
|
|
2
2
|
var thicknessPad = {
|
|
3
3
|
xlarge: 'large',
|
|
4
4
|
large: 'medium',
|
|
@@ -9,6 +9,37 @@ var thicknessPad = {
|
|
|
9
9
|
export var round = function round(value, decimals) {
|
|
10
10
|
return Number(Math.round(value + "e" + decimals) + "e-" + decimals);
|
|
11
11
|
};
|
|
12
|
+
|
|
13
|
+
// Normalize coarseness to an object.
|
|
14
|
+
// Backwards compatible has no coarseness for x-axis.
|
|
15
|
+
var normalizeCoarseness = function normalizeCoarseness(coarseness, direction) {
|
|
16
|
+
var result;
|
|
17
|
+
if (Array.isArray(coarseness)) result = {
|
|
18
|
+
x: coarseness[0],
|
|
19
|
+
y: coarseness[1]
|
|
20
|
+
};else if (typeof coarseness === 'object') result = coarseness;else if (coarseness) result = {
|
|
21
|
+
x: undefined,
|
|
22
|
+
y: coarseness
|
|
23
|
+
};else result = direction === 'horizontal' ? {
|
|
24
|
+
x: 5,
|
|
25
|
+
y: undefined
|
|
26
|
+
} : {
|
|
27
|
+
x: undefined,
|
|
28
|
+
y: 5
|
|
29
|
+
};
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var normalizeSteps = function normalizeSteps(steps) {
|
|
33
|
+
var result;
|
|
34
|
+
if (Array.isArray(steps)) result = {
|
|
35
|
+
x: steps[0],
|
|
36
|
+
y: steps[1]
|
|
37
|
+
};else if (typeof steps === 'object') result = steps;else result = {
|
|
38
|
+
x: 1,
|
|
39
|
+
y: 1
|
|
40
|
+
};
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
12
43
|
var alignMax = function alignMax(value, interval) {
|
|
13
44
|
if (value > 0) return value - value % interval + interval;
|
|
14
45
|
if (value < 0) return value + value % interval;
|
|
@@ -19,56 +50,60 @@ var alignMin = function alignMin(value, interval) {
|
|
|
19
50
|
if (value < 0) return value - value % interval - interval;
|
|
20
51
|
return value;
|
|
21
52
|
};
|
|
22
|
-
|
|
53
|
+
var adjustToShowZero = function adjustToShowZero(minArg, maxArg, steps) {
|
|
54
|
+
var min = minArg;
|
|
55
|
+
var max = maxArg;
|
|
56
|
+
if (min < 0 && max > 0 && Math.abs(min) !== Math.abs(max)) {
|
|
57
|
+
// Adjust min and max when crossing 0 to ensure 0 will be shown on
|
|
58
|
+
// the axis based on the number of steps.
|
|
59
|
+
if (steps === 1) {
|
|
60
|
+
var largest = Math.max(Math.abs(min), Math.abs(max));
|
|
61
|
+
min = -largest;
|
|
62
|
+
max = largest;
|
|
63
|
+
} else {
|
|
64
|
+
var stepInterval = (max - min) / steps;
|
|
65
|
+
var minSteps = min / stepInterval;
|
|
66
|
+
var maxSteps = max / stepInterval;
|
|
67
|
+
if (Math.abs(minSteps) < Math.abs(maxSteps)) {
|
|
68
|
+
// more above than below
|
|
69
|
+
stepInterval = max / Math.floor(maxSteps);
|
|
70
|
+
max = stepInterval * Math.floor(maxSteps);
|
|
71
|
+
min = stepInterval * Math.floor(minSteps);
|
|
72
|
+
} else {
|
|
73
|
+
// more below than above
|
|
74
|
+
stepInterval = Math.abs(min / Math.ceil(minSteps));
|
|
75
|
+
min = stepInterval * Math.ceil(minSteps);
|
|
76
|
+
max = stepInterval * Math.ceil(maxSteps);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return [min, max];
|
|
81
|
+
};
|
|
82
|
+
export var calcBounds = function calcBounds(valuesArg, options) {
|
|
23
83
|
if (options === void 0) {
|
|
24
84
|
options = {};
|
|
25
85
|
}
|
|
26
86
|
// coarseness influences the rounding of the bounds, the smaller the
|
|
27
|
-
// number, the more the bounds will be rounded. e.g. 111 -> 110 -> 100
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
coarseY = coarseness[1];
|
|
32
|
-
// the number of steps is one less than the number of labels
|
|
33
|
-
var steps = options.steps || [1, 1];
|
|
34
|
-
var stepsY = steps[1];
|
|
35
|
-
var calcValues = normalizeValues(values || []);
|
|
36
|
-
|
|
37
|
-
// min and max values
|
|
38
|
-
var minX;
|
|
39
|
-
var maxX;
|
|
40
|
-
var minY;
|
|
41
|
-
var maxY;
|
|
42
|
-
if (calcValues.length) {
|
|
43
|
-
// Calculate the max and min values.
|
|
44
|
-
calcValues.filter(function (value) {
|
|
45
|
-
return value !== undefined;
|
|
46
|
-
}).forEach(function (value) {
|
|
47
|
-
var x = value.value[0];
|
|
48
|
-
if (x !== undefined) {
|
|
49
|
-
minX = minX === undefined ? x : Math.min(minX, x);
|
|
50
|
-
maxX = maxX === undefined ? x : Math.max(maxX, x);
|
|
51
|
-
}
|
|
52
|
-
var y = value.value[1];
|
|
53
|
-
if (y !== undefined) {
|
|
54
|
-
minY = minY === undefined ? y : Math.min(minY, y);
|
|
55
|
-
maxY = maxY === undefined ? y : Math.max(maxY, y);
|
|
56
|
-
}
|
|
57
|
-
// handle ranges of values
|
|
58
|
-
var y2 = value.value[2];
|
|
59
|
-
if (y2 !== undefined) {
|
|
60
|
-
minY = Math.min(minY, y2);
|
|
61
|
-
maxY = Math.max(maxY, y2);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
87
|
+
// number, the more the bounds will be rounded. e.g. 111 -> 110 -> 100.
|
|
88
|
+
var _normalizeCoarseness = normalizeCoarseness(options.coarseness, options.direction),
|
|
89
|
+
coarseX = _normalizeCoarseness.x,
|
|
90
|
+
coarseY = _normalizeCoarseness.y;
|
|
64
91
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
92
|
+
// the number of steps is one less than the number of labels
|
|
93
|
+
var _normalizeSteps = normalizeSteps(options.steps),
|
|
94
|
+
stepsX = _normalizeSteps.x,
|
|
95
|
+
stepsY = _normalizeSteps.y;
|
|
96
|
+
var values = normalizeValues(valuesArg || []);
|
|
97
|
+
var result;
|
|
98
|
+
if (values.length) {
|
|
99
|
+
// min and max values
|
|
100
|
+
var _calcMinMax = calcMinMax(values, options.direction),
|
|
101
|
+
_calcMinMax$x = _calcMinMax.x,
|
|
102
|
+
minX = _calcMinMax$x.min,
|
|
103
|
+
maxX = _calcMinMax$x.max,
|
|
104
|
+
_calcMinMax$y = _calcMinMax.y,
|
|
105
|
+
minY = _calcMinMax$y.min,
|
|
106
|
+
maxY = _calcMinMax$y.max;
|
|
72
107
|
|
|
73
108
|
// Calculate some reasonable bounds based on the max and min values.
|
|
74
109
|
// This is so values like 87342.12 don't end up being displayed as the
|
|
@@ -85,35 +120,41 @@ export var calcBounds = function calcBounds(values, options) {
|
|
|
85
120
|
minY = alignMin(minY, intervalY);
|
|
86
121
|
maxY = alignMax(maxY, intervalY);
|
|
87
122
|
}
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var stepInterval = (maxY - minY) / stepsY;
|
|
97
|
-
var minSteps = minY / stepInterval;
|
|
98
|
-
var maxSteps = maxY / stepInterval;
|
|
99
|
-
if (Math.abs(minSteps) < Math.abs(maxSteps)) {
|
|
100
|
-
// more above than below
|
|
101
|
-
stepInterval = maxY / Math.floor(maxSteps);
|
|
102
|
-
maxY = stepInterval * Math.floor(maxSteps);
|
|
103
|
-
minY = stepInterval * Math.floor(minSteps);
|
|
104
|
-
} else {
|
|
105
|
-
// more below than above
|
|
106
|
-
stepInterval = Math.abs(minY / Math.ceil(minSteps));
|
|
107
|
-
minY = stepInterval * Math.ceil(minSteps);
|
|
108
|
-
maxY = stepInterval * Math.ceil(maxSteps);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
123
|
+
if (options.direction === 'horizontal') {
|
|
124
|
+
var _adjustToShowZero = adjustToShowZero(minX, maxX, stepsX);
|
|
125
|
+
minX = _adjustToShowZero[0];
|
|
126
|
+
maxX = _adjustToShowZero[1];
|
|
127
|
+
} else {
|
|
128
|
+
var _adjustToShowZero2 = adjustToShowZero(minY, maxY, stepsY);
|
|
129
|
+
minY = _adjustToShowZero2[0];
|
|
130
|
+
maxY = _adjustToShowZero2[1];
|
|
111
131
|
}
|
|
132
|
+
|
|
133
|
+
// if options.direction is present, the results are delivered in { x, y }
|
|
134
|
+
// object structure. If options.direction is not present, the results are
|
|
135
|
+
// delivered in [x, y] array structure, for backwards compatibility
|
|
136
|
+
result = options.direction ? {
|
|
137
|
+
x: {
|
|
138
|
+
min: minX,
|
|
139
|
+
max: maxX
|
|
140
|
+
},
|
|
141
|
+
y: {
|
|
142
|
+
min: minY,
|
|
143
|
+
max: maxY
|
|
144
|
+
}
|
|
145
|
+
} : [[minX, maxX], [minY, maxY]];
|
|
146
|
+
} else {
|
|
147
|
+
result = options.direction ? {
|
|
148
|
+
x: {},
|
|
149
|
+
y: {}
|
|
150
|
+
} : [[], []];
|
|
112
151
|
}
|
|
113
|
-
|
|
114
|
-
if (calcValues.length) bounds = [[minX, maxX], [minY, maxY]];else bounds = [[], []];
|
|
115
|
-
return bounds;
|
|
152
|
+
return result;
|
|
116
153
|
};
|
|
154
|
+
|
|
155
|
+
// if options.direction is present, the results are delivered in { x, y }
|
|
156
|
+
// object structure. If options.direction is not present, the results are
|
|
157
|
+
// delivered in [x, y] array structure, for backwards compatibility
|
|
117
158
|
export var calcs = function calcs(values, options) {
|
|
118
159
|
if (values === void 0) {
|
|
119
160
|
values = [];
|
|
@@ -121,37 +162,64 @@ export var calcs = function calcs(values, options) {
|
|
|
121
162
|
if (options === void 0) {
|
|
122
163
|
options = {};
|
|
123
164
|
}
|
|
165
|
+
var horizontal = options.direction === 'horizontal';
|
|
166
|
+
|
|
124
167
|
// the number of steps is one less than the number of labels
|
|
125
|
-
var
|
|
126
|
-
|
|
127
|
-
stepsY =
|
|
168
|
+
var _normalizeSteps2 = normalizeSteps(options.steps),
|
|
169
|
+
stepsX = _normalizeSteps2.x,
|
|
170
|
+
stepsY = _normalizeSteps2.y;
|
|
171
|
+
|
|
172
|
+
// bounds is { x: { min, max }, y: { min, max } } when options.direction is
|
|
173
|
+
// present and [[min, max], [min, max]] if not, for backwards compatibility
|
|
128
174
|
var bounds = options.bounds || calcBounds(values, options);
|
|
129
|
-
if (options.min !== undefined)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
175
|
+
if (options.min !== undefined) {
|
|
176
|
+
if (options.direction) {
|
|
177
|
+
if (horizontal) bounds.x.min = options.min;else bounds.y.min = options.min;
|
|
178
|
+
} else bounds[1][0] = options.min;
|
|
179
|
+
}
|
|
180
|
+
if (options.max !== undefined) {
|
|
181
|
+
if (options.direction) {
|
|
182
|
+
if (horizontal) bounds.y.max = options.max;else bounds.x.max = options.max;
|
|
183
|
+
} else bounds[1][1] = options.max;
|
|
184
|
+
}
|
|
185
|
+
var _ref = options.direction ? bounds : {
|
|
186
|
+
x: {
|
|
187
|
+
min: bounds[0][0],
|
|
188
|
+
max: bounds[0][1]
|
|
189
|
+
},
|
|
190
|
+
y: {
|
|
191
|
+
min: bounds[1][0],
|
|
192
|
+
max: bounds[1][1]
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
_ref$x = _ref.x,
|
|
196
|
+
minX = _ref$x.min,
|
|
197
|
+
maxX = _ref$x.max,
|
|
198
|
+
_ref$y = _ref.y,
|
|
199
|
+
minY = _ref$y.min,
|
|
200
|
+
maxY = _ref$y.max;
|
|
201
|
+
var width = round(maxX - minX, 2);
|
|
202
|
+
var height = round(maxY - minY, 2);
|
|
203
|
+
var dimensions = options.direction ? {
|
|
204
|
+
width: width,
|
|
205
|
+
height: height
|
|
206
|
+
} : [width, height];
|
|
140
207
|
|
|
141
208
|
// Calculate x and y axis values across the specfied number of steps.
|
|
142
209
|
var yAxis = [];
|
|
143
|
-
var y =
|
|
210
|
+
var y = maxY;
|
|
144
211
|
// To deal with javascript math limitations, round the step with 4 decimal
|
|
145
212
|
// places and then push the values with 2 decimal places
|
|
146
|
-
var yStepInterval = round(
|
|
147
|
-
while (round(y, 2) >=
|
|
213
|
+
var yStepInterval = round(height / stepsY, 4);
|
|
214
|
+
while (round(y, 2) >= minY) {
|
|
148
215
|
yAxis.push(round(y, 2));
|
|
149
216
|
y -= yStepInterval;
|
|
150
217
|
}
|
|
218
|
+
if (horizontal) yAxis.reverse();
|
|
151
219
|
var xAxis = [];
|
|
152
|
-
var x =
|
|
153
|
-
var xStepInterval = round(
|
|
154
|
-
while (round(x, 2) <=
|
|
220
|
+
var x = minX;
|
|
221
|
+
var xStepInterval = round(width / stepsX, 4);
|
|
222
|
+
while (round(x, 2) <= maxX) {
|
|
155
223
|
xAxis.push(round(x, 2));
|
|
156
224
|
x += xStepInterval;
|
|
157
225
|
}
|
|
@@ -178,7 +246,10 @@ export var calcs = function calcs(values, options) {
|
|
|
178
246
|
}
|
|
179
247
|
var pad = thicknessPad[thickness];
|
|
180
248
|
return {
|
|
181
|
-
axis:
|
|
249
|
+
axis: options.direction ? {
|
|
250
|
+
x: xAxis,
|
|
251
|
+
y: yAxis
|
|
252
|
+
} : [xAxis, yAxis],
|
|
182
253
|
bounds: bounds,
|
|
183
254
|
dimensions: dimensions,
|
|
184
255
|
pad: pad,
|
|
@@ -16,7 +16,10 @@ export interface ChartProps {
|
|
|
16
16
|
animate?: boolean;
|
|
17
17
|
gridArea?: GridAreaType;
|
|
18
18
|
margin?: MarginType;
|
|
19
|
-
|
|
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 =
|
|
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
|
}
|
|
@@ -6,7 +6,16 @@ var PropType = {};
|
|
|
6
6
|
if (process.env.NODE_ENV !== 'production') {
|
|
7
7
|
PropType = _extends({}, genericProps, {
|
|
8
8
|
animate: PropTypes.bool,
|
|
9
|
-
bounds: PropTypes.
|
|
9
|
+
bounds: PropTypes.oneOfType([PropTypes.shape({
|
|
10
|
+
x: PropTypes.shape({
|
|
11
|
+
min: PropTypes.number,
|
|
12
|
+
max: PropTypes.number
|
|
13
|
+
}),
|
|
14
|
+
y: PropTypes.shape({
|
|
15
|
+
min: PropTypes.number,
|
|
16
|
+
max: PropTypes.number
|
|
17
|
+
})
|
|
18
|
+
}), PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number))]),
|
|
10
19
|
color: PropTypes.oneOfType([colorPropType, PropTypes.shape({
|
|
11
20
|
color: colorPropType,
|
|
12
21
|
// deprecated, use top level 'opacity'
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Box, Chart } from 'grommet';
|
|
3
|
-
|
|
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
|
-
}, ['
|
|
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/
|
|
62
|
+
title: 'Visualizations/Chart/Horizontal'
|
|
35
63
|
};
|