grommet 2.20.1 → 2.21.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/components/Button/Button.js +2 -3
- package/components/Chart/Chart.js +14 -6
- package/components/DataChart/DataChart.js +84 -21
- package/components/DataChart/Detail.js +8 -0
- package/components/DataChart/XAxis.js +19 -10
- package/components/DataChart/index.d.ts +10 -2
- package/components/DataChart/propTypes.js +2 -1
- package/components/DataChart/stories/Offset.js +82 -0
- package/components/DataChart/stories/StackedAreas.js +77 -0
- package/components/DataChart/stories/StackedLines.js +73 -0
- package/components/DateInput/DateInput.js +21 -9
- package/components/DateInput/index.d.ts +1 -0
- package/components/DateInput/propTypes.js +1 -0
- package/components/List/List.js +11 -2
- package/components/List/index.d.ts +1 -0
- package/components/List/propTypes.js +1 -0
- package/components/Markdown/Markdown.js +4 -2
- package/components/Menu/Menu.js +39 -12
- package/components/Notification/Notification.js +17 -6
- package/components/Notification/index.d.ts +7 -1
- package/components/Notification/propTypes.js +4 -1
- package/components/RangeInput/StyledRangeInput.js +1 -1
- package/components/RangeInput/stories/SimpleRange.js +2 -6
- package/components/Select/Select.js +44 -12
- package/components/Select/SelectContainer.js +22 -6
- package/components/Select/stories/ChildrenRender.js +37 -33
- package/components/Select/stories/Clear.js +7 -3
- package/components/Select/stories/Controlled.js +32 -28
- package/components/Select/stories/{CustomSearch.js → CustomThemed/CustomSearch.js} +2 -2
- package/components/Select/stories/Disabled.js +29 -25
- package/components/Select/stories/InsideFormField.js +29 -27
- package/components/Select/stories/LazyLoadingOptions.js +27 -25
- package/components/Select/stories/ManyOptions.js +47 -43
- package/components/Select/stories/Multiple.js +25 -21
- package/components/Select/stories/ObjectOptions.js +27 -25
- package/components/Select/stories/Search.js +62 -58
- package/components/Select/stories/Simple.js +26 -22
- package/components/Select/stories/Uncontrolled.js +24 -20
- package/components/Select/stories/ValueLabel.js +40 -36
- package/components/Select/stories/typescript/CreateOption.tsx +34 -30
- package/components/Sidebar/stories/Labels.js +25 -19
- package/components/Sidebar/stories/typescript/Simple.tsx +17 -12
- package/components/SkipLinks/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/components/SkipLinks/stories/Simple.js +82 -78
- package/components/Tab/Tab.js +6 -1
- package/components/Table/stories/Default.js +30 -28
- package/components/Table/stories/InfiniteScrollInTable.js +39 -35
- package/components/Table/stories/MeterInTable.js +26 -24
- package/components/Tag/Tag.js +17 -6
- package/components/Tag/index.d.ts +8 -0
- package/components/Tag/propTypes.js +2 -1
- package/components/Tag/stories/Size.js +45 -0
- package/components/TextArea/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/components/TextArea/stories/Fill.js +18 -16
- package/components/TextArea/stories/InsideFormField.js +43 -41
- package/components/TextArea/stories/NonResizable.js +13 -11
- package/components/TextArea/stories/Simple.js +13 -11
- package/components/TextInput/TextInput.js +5 -8
- package/{es6/components/TextInput/stories/typescript → components/TextInput/stories/CustomThemed}/CustomSuggestions.tsx +1 -1
- package/components/TextInput/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/components/TextInput/stories/DefaultSuggestion.js +20 -19
- package/components/TextInput/stories/Icon.js +22 -21
- package/components/TextInput/stories/InsideFormField.js +32 -30
- package/components/TextInput/stories/OnSelect.js +20 -19
- package/components/TextInput/stories/Password.js +30 -29
- package/components/TextInput/stories/Simple.js +17 -16
- package/components/TextInput/stories/StyledPlaceholder.js +10 -9
- package/components/TextInput/stories/Suggestions.js +19 -18
- package/components/TextInput/stories/Uncontrolled.js +18 -17
- package/components/TextInput/stories/WithTags.js +19 -18
- package/components/Tip/stories/Caret.js +37 -31
- package/components/Tip/stories/{ResponsiveTip.js → CustomThemed/ResponsiveTip.js} +1 -1
- package/components/Tip/stories/{SidebarTip.js → CustomThemed/SidebarTip.js} +1 -1
- package/components/Tip/stories/{typescript → CustomThemed}/Themed.tsx +1 -1
- package/components/Tip/stories/HeaderActions.js +66 -60
- package/components/Tip/stories/InfoTip.js +59 -56
- package/components/Tip/stories/typescript/Animated.tsx +26 -21
- package/components/Tip/stories/typescript/Children.tsx +52 -51
- package/components/Tip/stories/typescript/Simple.tsx +12 -7
- package/es6/components/Button/Button.js +2 -3
- package/es6/components/Chart/Chart.js +14 -6
- package/es6/components/DataChart/DataChart.js +84 -21
- package/es6/components/DataChart/Detail.js +7 -0
- package/es6/components/DataChart/XAxis.js +19 -10
- package/es6/components/DataChart/index.d.ts +10 -2
- package/es6/components/DataChart/propTypes.js +2 -1
- package/es6/components/DataChart/stories/Offset.js +70 -0
- package/es6/components/DataChart/stories/StackedAreas.js +65 -0
- package/es6/components/DataChart/stories/StackedLines.js +61 -0
- package/es6/components/DateInput/DateInput.js +21 -9
- package/es6/components/DateInput/index.d.ts +1 -0
- package/es6/components/DateInput/propTypes.js +1 -0
- package/es6/components/List/List.js +11 -2
- package/es6/components/List/index.d.ts +1 -0
- package/es6/components/List/propTypes.js +1 -0
- package/es6/components/Markdown/Markdown.js +4 -2
- package/es6/components/Menu/Menu.js +40 -13
- package/es6/components/Notification/Notification.js +18 -7
- package/es6/components/Notification/index.d.ts +7 -1
- package/es6/components/Notification/propTypes.js +4 -1
- package/es6/components/RangeInput/StyledRangeInput.js +1 -1
- package/es6/components/RangeInput/stories/SimpleRange.js +3 -6
- package/es6/components/Select/Select.js +44 -12
- package/es6/components/Select/SelectContainer.js +22 -6
- package/es6/components/Select/stories/ChildrenRender.js +38 -33
- package/es6/components/Select/stories/Clear.js +8 -4
- package/es6/components/Select/stories/Controlled.js +33 -28
- package/es6/components/Select/stories/{CustomSearch.js → CustomThemed/CustomSearch.js} +2 -2
- package/es6/components/Select/stories/Disabled.js +30 -25
- package/es6/components/Select/stories/InsideFormField.js +30 -27
- package/es6/components/Select/stories/LazyLoadingOptions.js +28 -25
- package/es6/components/Select/stories/ManyOptions.js +48 -43
- package/es6/components/Select/stories/Multiple.js +26 -21
- package/es6/components/Select/stories/ObjectOptions.js +28 -25
- package/es6/components/Select/stories/Search.js +63 -58
- package/es6/components/Select/stories/Simple.js +27 -22
- package/es6/components/Select/stories/Uncontrolled.js +25 -20
- package/es6/components/Select/stories/ValueLabel.js +41 -36
- package/es6/components/Select/stories/typescript/CreateOption.tsx +34 -30
- package/es6/components/Sidebar/stories/Labels.js +26 -20
- package/es6/components/Sidebar/stories/typescript/Simple.tsx +17 -12
- package/es6/components/SkipLinks/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/es6/components/SkipLinks/stories/Simple.js +83 -79
- package/es6/components/Tab/Tab.js +6 -1
- package/es6/components/Table/stories/Default.js +31 -28
- package/es6/components/Table/stories/InfiniteScrollInTable.js +40 -36
- package/es6/components/Table/stories/MeterInTable.js +27 -24
- package/es6/components/Tag/Tag.js +17 -6
- package/es6/components/Tag/index.d.ts +8 -0
- package/es6/components/Tag/propTypes.js +2 -1
- package/es6/components/Tag/stories/Size.js +33 -0
- package/es6/components/TextArea/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/es6/components/TextArea/stories/Fill.js +19 -16
- package/es6/components/TextArea/stories/InsideFormField.js +44 -41
- package/es6/components/TextArea/stories/NonResizable.js +14 -11
- package/es6/components/TextArea/stories/Simple.js +14 -11
- package/es6/components/TextInput/TextInput.js +5 -8
- package/{components/TextInput/stories/typescript → es6/components/TextInput/stories/CustomThemed}/CustomSuggestions.tsx +1 -1
- package/es6/components/TextInput/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
- package/es6/components/TextInput/stories/DefaultSuggestion.js +21 -19
- package/es6/components/TextInput/stories/Icon.js +23 -21
- package/es6/components/TextInput/stories/InsideFormField.js +33 -30
- package/es6/components/TextInput/stories/OnSelect.js +21 -19
- package/es6/components/TextInput/stories/Password.js +31 -29
- package/es6/components/TextInput/stories/Simple.js +18 -16
- package/es6/components/TextInput/stories/StyledPlaceholder.js +11 -9
- package/es6/components/TextInput/stories/Suggestions.js +20 -18
- package/es6/components/TextInput/stories/Uncontrolled.js +19 -17
- package/es6/components/TextInput/stories/WithTags.js +20 -18
- package/es6/components/Tip/stories/Caret.js +38 -32
- package/es6/components/Tip/stories/{ResponsiveTip.js → CustomThemed/ResponsiveTip.js} +1 -1
- package/es6/components/Tip/stories/{SidebarTip.js → CustomThemed/SidebarTip.js} +1 -1
- package/es6/components/Tip/stories/{typescript → CustomThemed}/Themed.tsx +1 -1
- package/es6/components/Tip/stories/HeaderActions.js +67 -61
- package/es6/components/Tip/stories/InfoTip.js +60 -57
- package/es6/components/Tip/stories/typescript/Animated.tsx +26 -21
- package/es6/components/Tip/stories/typescript/Children.tsx +52 -51
- package/es6/components/Tip/stories/typescript/Simple.tsx +12 -7
- package/es6/languages/default.json +2 -1
- package/es6/themes/base.d.ts +34 -1
- package/es6/themes/base.js +39 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/languages/default.json +2 -1
- package/package.json +4 -4
- package/themes/base.d.ts +34 -1
- package/themes/base.js +39 -0
|
@@ -3,58 +3,59 @@ import React from 'react';
|
|
|
3
3
|
import { grommet, Box, Button, Grommet, Text, Tip } from 'grommet';
|
|
4
4
|
|
|
5
5
|
export const Children = () => (
|
|
6
|
-
<Grommet
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
</
|
|
14
|
-
}
|
|
15
|
-
>
|
|
16
|
-
String Child
|
|
17
|
-
</Tip>
|
|
18
|
-
<Tip
|
|
19
|
-
plain
|
|
20
|
-
dropProps={{ align: { right: 'left' } }}
|
|
21
|
-
content={
|
|
22
|
-
<Box
|
|
23
|
-
animation="slideLeft"
|
|
24
|
-
align="center"
|
|
25
|
-
background="light-4"
|
|
26
|
-
round={{ size: 'medium', corner: 'left' }}
|
|
27
|
-
pad="small"
|
|
28
|
-
margin="small"
|
|
29
|
-
>
|
|
30
|
-
<Text color="brand">Tooltip</Text>
|
|
31
|
-
</Box>
|
|
32
|
-
}
|
|
33
|
-
>
|
|
34
|
-
<Box background="brand" pad="small" flex={false}>
|
|
35
|
-
Box Child
|
|
6
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
7
|
+
// <Grommet theme={...}>
|
|
8
|
+
<Box align="center" pad="xlarge" gap="xlarge" fill>
|
|
9
|
+
<Text>Tooltip will be displayed once hovering on the Tip child</Text>
|
|
10
|
+
<Tip
|
|
11
|
+
content={
|
|
12
|
+
<Box align="center">
|
|
13
|
+
<Text>Hello</Text>
|
|
36
14
|
</Box>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
15
|
+
}
|
|
16
|
+
>
|
|
17
|
+
String Child
|
|
18
|
+
</Tip>
|
|
19
|
+
<Tip
|
|
20
|
+
plain
|
|
21
|
+
dropProps={{ align: { right: 'left' } }}
|
|
22
|
+
content={
|
|
23
|
+
<Box
|
|
24
|
+
animation="slideLeft"
|
|
25
|
+
align="center"
|
|
26
|
+
background="light-4"
|
|
27
|
+
round={{ size: 'medium', corner: 'left' }}
|
|
28
|
+
pad="small"
|
|
29
|
+
margin="small"
|
|
30
|
+
>
|
|
31
|
+
<Text color="brand">Tooltip</Text>
|
|
32
|
+
</Box>
|
|
33
|
+
}
|
|
34
|
+
>
|
|
35
|
+
<Box background="brand" pad="small" flex={false}>
|
|
36
|
+
Box Child
|
|
37
|
+
</Box>
|
|
38
|
+
</Tip>
|
|
39
|
+
<Tip
|
|
40
|
+
plain
|
|
41
|
+
dropProps={{ align: { left: 'right' } }}
|
|
42
|
+
content={
|
|
43
|
+
<Box
|
|
44
|
+
align="center"
|
|
45
|
+
background="accent-1"
|
|
46
|
+
margin="xsmall"
|
|
47
|
+
pad="xsmall"
|
|
48
|
+
round="medium"
|
|
49
|
+
flex={false}
|
|
50
|
+
>
|
|
51
|
+
<Text color="brand">Tooltip</Text>
|
|
52
|
+
</Box>
|
|
53
|
+
}
|
|
54
|
+
>
|
|
55
|
+
<Button label="Button Child" />
|
|
56
|
+
</Tip>
|
|
57
|
+
</Box>
|
|
58
|
+
// </Grommet>
|
|
58
59
|
);
|
|
59
60
|
|
|
60
61
|
Children.parameters = {
|
|
@@ -3,15 +3,20 @@ import React from 'react';
|
|
|
3
3
|
import { grommet, Box, Button, Grommet, Tip } from 'grommet';
|
|
4
4
|
|
|
5
5
|
export const Simple = () => (
|
|
6
|
-
<Grommet
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
</
|
|
12
|
-
</
|
|
6
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
7
|
+
// <Grommet theme={...}>
|
|
8
|
+
<Box align="center" justify="center" fill>
|
|
9
|
+
<Tip content="action info">
|
|
10
|
+
<Button label="action" />
|
|
11
|
+
</Tip>
|
|
12
|
+
</Box>
|
|
13
|
+
//</Grommet>
|
|
13
14
|
);
|
|
14
15
|
|
|
16
|
+
Simple.args = {
|
|
17
|
+
full: true,
|
|
18
|
+
};
|
|
19
|
+
|
|
15
20
|
Simple.parameters = {
|
|
16
21
|
chromatic: { disable: true },
|
|
17
22
|
};
|
|
@@ -119,8 +119,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
119
119
|
icon = _ref.icon,
|
|
120
120
|
_ref$focusIndicator = _ref.focusIndicator,
|
|
121
121
|
focusIndicator = _ref$focusIndicator === void 0 ? true : _ref$focusIndicator,
|
|
122
|
-
|
|
123
|
-
gap = _ref$gap === void 0 ? 'small' : _ref$gap,
|
|
122
|
+
gap = _ref.gap,
|
|
124
123
|
fill = _ref.fill,
|
|
125
124
|
href = _ref.href,
|
|
126
125
|
justify = _ref.justify,
|
|
@@ -265,7 +264,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
265
264
|
direction: "row",
|
|
266
265
|
align: "center",
|
|
267
266
|
justify: justify || (align === 'center' ? 'center' : 'between'),
|
|
268
|
-
gap: gap,
|
|
267
|
+
gap: gap || theme.button.gap,
|
|
269
268
|
responsive: false
|
|
270
269
|
}, first, second);
|
|
271
270
|
} else if (typeof children === 'function') {
|
|
@@ -64,16 +64,24 @@ var Chart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
64
64
|
|
|
65
65
|
if (pad) {
|
|
66
66
|
if (pad.horizontal) {
|
|
67
|
-
var padSize = parseMetricToNum(theme.global.edgeSize[pad.horizontal]);
|
|
68
|
-
result[0]
|
|
69
|
-
result[2]
|
|
67
|
+
var padSize = parseMetricToNum(theme.global.edgeSize[pad.horizontal] || pad.horizontal);
|
|
68
|
+
result[0] = padSize;
|
|
69
|
+
result[2] = padSize;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (pad.vertical) {
|
|
73
|
-
var _padSize = parseMetricToNum(theme.global.edgeSize[pad.vertical]);
|
|
73
|
+
var _padSize = parseMetricToNum(theme.global.edgeSize[pad.vertical] || pad.vertical);
|
|
74
74
|
|
|
75
|
-
result[1]
|
|
76
|
-
result[3]
|
|
75
|
+
result[1] = _padSize;
|
|
76
|
+
result[3] = _padSize;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (pad.start) {
|
|
80
|
+
result[0] = parseMetricToNum(theme.global.edgeSize[pad.start] || pad.start);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (pad.end) {
|
|
84
|
+
result[2] = parseMetricToNum(theme.global.edgeSize[pad.end] || pad.end);
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
if (typeof pad === 'string') {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
var _excluded = ["a11yTitle", "axis", "bounds", "chart", "data", "detail", "gap", "guide", "legend", "pad", "series", "size"],
|
|
2
|
-
_excluded2 = ["property", "type", "x", "y"]
|
|
1
|
+
var _excluded = ["a11yTitle", "axis", "bounds", "chart", "data", "detail", "gap", "guide", "legend", "offset", "pad", "series", "size"],
|
|
2
|
+
_excluded2 = ["property", "type", "x", "y"],
|
|
3
|
+
_excluded3 = ["property"];
|
|
3
4
|
|
|
4
5
|
function _extends() { _extends = Object.assign || 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); }
|
|
5
6
|
|
|
@@ -20,7 +21,12 @@ import { YAxis } from './YAxis';
|
|
|
20
21
|
import { XGuide } from './XGuide';
|
|
21
22
|
import { YGuide } from './YGuide';
|
|
22
23
|
import { createDateFormat, halfPad, heightYGranularity, points } from './utils';
|
|
23
|
-
import { DataChartPropTypes } from './propTypes';
|
|
24
|
+
import { DataChartPropTypes } from './propTypes';
|
|
25
|
+
var stackedChartType = {
|
|
26
|
+
areas: 'area',
|
|
27
|
+
bars: 'bar',
|
|
28
|
+
lines: 'line'
|
|
29
|
+
}; // DataChart takes a generic data array of objects plus as few properties
|
|
24
30
|
// as possible, and creates a Stack of Charts with x and y axes, a legend,
|
|
25
31
|
// and interactive detail.
|
|
26
32
|
// Much of the code here-in involves the "few properties" aspect where we
|
|
@@ -40,6 +46,7 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
40
46
|
gap = _ref$gap === void 0 ? 'small' : _ref$gap,
|
|
41
47
|
guideProp = _ref.guide,
|
|
42
48
|
legend = _ref.legend,
|
|
49
|
+
offset = _ref.offset,
|
|
43
50
|
padProp = _ref.pad,
|
|
44
51
|
seriesProp = _ref.series,
|
|
45
52
|
size = _ref.size,
|
|
@@ -77,7 +84,7 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
77
84
|
});
|
|
78
85
|
}; // Normalize chart to an array of objects.
|
|
79
86
|
// Each chart has one or more properties associated with it.
|
|
80
|
-
// A stacked bar chart has an array of properties.
|
|
87
|
+
// A stacked bar or area chart has an array of properties.
|
|
81
88
|
// A point chart can have x, y, thickness, and color each driven
|
|
82
89
|
// by a separate property.
|
|
83
90
|
|
|
@@ -135,10 +142,11 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
135
142
|
|
|
136
143
|
if (property) {
|
|
137
144
|
if (Array.isArray(property)) {
|
|
138
|
-
// A range chart or a stacked bar chart
|
|
145
|
+
// A range chart or a stacked bar or area chart has multiple
|
|
146
|
+
// properties.
|
|
139
147
|
// In this case, this returns an array of values,
|
|
140
148
|
// one per property.
|
|
141
|
-
if (type
|
|
149
|
+
if (stackedChartType[type]) {
|
|
142
150
|
// Further down, where we render, each property is rendered
|
|
143
151
|
// using a separate Chart component and the values are stacked
|
|
144
152
|
// such that they line up appropriately.
|
|
@@ -152,6 +160,7 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
152
160
|
return values.map(function (v, i) {
|
|
153
161
|
var base = totals[i] || 0;
|
|
154
162
|
totals[i] = base + v;
|
|
163
|
+
if (type === 'lines') return [i, base + v];
|
|
155
164
|
return [i, base, base + v];
|
|
156
165
|
});
|
|
157
166
|
});
|
|
@@ -287,15 +296,20 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
287
296
|
} else steps[1] = 1;
|
|
288
297
|
|
|
289
298
|
var chartBounds = chartValues.map(function (_, index) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
299
|
+
var type = charts[index].type;
|
|
300
|
+
|
|
301
|
+
if (stackedChartType[type]) {
|
|
302
|
+
var _chartValues$index, _chartValues$index$;
|
|
303
|
+
|
|
304
|
+
// merge values for bars, areas, and lines cases
|
|
305
|
+
var mergedValues = ((_chartValues$index = chartValues[index]) == null ? void 0 : (_chartValues$index$ = _chartValues$index[0]) == null ? void 0 : _chartValues$index$.slice(0)) || [];
|
|
306
|
+
chartValues[index].slice(1) // skip first index as that is the x value
|
|
307
|
+
.filter(function (values) {
|
|
294
308
|
return values;
|
|
295
309
|
}) // property name isn't valid
|
|
296
310
|
.forEach(function (values) {
|
|
297
311
|
mergedValues = mergedValues.map(function (__, i) {
|
|
298
|
-
return [i, Math.min(mergedValues[i][1], values[i][1]), Math.max(mergedValues[i][2], values[i][2])];
|
|
312
|
+
return type === 'lines' ? [i, Math.min(mergedValues[i][1], values[i][1]), Math.max(mergedValues[i][1], values[i][1])] : [i, Math.min(mergedValues[i][1], values[i][1]), Math.max(mergedValues[i][2], values[i][2])];
|
|
299
313
|
});
|
|
300
314
|
});
|
|
301
315
|
return calcBounds(mergedValues, {
|
|
@@ -325,10 +339,14 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
325
339
|
}
|
|
326
340
|
|
|
327
341
|
return chartValues.map(function (values, index) {
|
|
328
|
-
var
|
|
342
|
+
var _charts$index = charts[index],
|
|
343
|
+
thickness = _charts$index.thickness,
|
|
344
|
+
type = _charts$index.type;
|
|
345
|
+
var calcValues = stackedChartType[type] ? values[0] : values;
|
|
329
346
|
return calcs(calcValues, {
|
|
330
347
|
bounds: chartBounds[index],
|
|
331
|
-
steps: steps
|
|
348
|
+
steps: steps,
|
|
349
|
+
thickness: thickness
|
|
332
350
|
});
|
|
333
351
|
});
|
|
334
352
|
}, [axis, boundsProp, charts, chartValues, data, granularities]); // normalize how we style data properties for use by Legend and Detail
|
|
@@ -418,6 +436,7 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
418
436
|
|
|
419
437
|
return result;
|
|
420
438
|
}, [axis, granularities, guideProp]); // set the pad to half the thickness, based on the chart types
|
|
439
|
+
// except when using offset, then add even more horizontal pad
|
|
421
440
|
|
|
422
441
|
var pad = useMemo(function () {
|
|
423
442
|
if (padProp !== undefined) return padProp;
|
|
@@ -429,7 +448,31 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
429
448
|
if (type && type !== 'bar') result.vertical = halfPad[thickness];
|
|
430
449
|
});
|
|
431
450
|
return result;
|
|
432
|
-
}, [chartProps, charts, padProp]); //
|
|
451
|
+
}, [chartProps, charts, padProp]); // calculate the thickness in pixels of each chart
|
|
452
|
+
|
|
453
|
+
var thicknesses = useMemo(function () {
|
|
454
|
+
return offset ? charts.map(function (_, index) {
|
|
455
|
+
var thickness = chartProps[index].thickness;
|
|
456
|
+
return parseMetricToNum(theme.global.edgeSize[thickness] || thickness);
|
|
457
|
+
}) : undefined;
|
|
458
|
+
}, [charts, chartProps, offset, theme]); // calculate the offset for each chart, which is a sum of the thicknesses
|
|
459
|
+
// that preceded it
|
|
460
|
+
|
|
461
|
+
var offsets = useMemo(function () {
|
|
462
|
+
return offset ? thicknesses.map(function (t, i) {
|
|
463
|
+
return thicknesses.slice(0, i).reduce(function (a, b) {
|
|
464
|
+
return a + b;
|
|
465
|
+
}, 0);
|
|
466
|
+
}) : undefined;
|
|
467
|
+
}, [offset, thicknesses]); // Calculate the total pad we should add to the end of each chart.
|
|
468
|
+
// We do this to shrink the width of each chart so we can shift them
|
|
469
|
+
// via `translate` and have them take up the right amount of width.
|
|
470
|
+
|
|
471
|
+
var offsetPad = useMemo(function () {
|
|
472
|
+
return offset ? thicknesses.reduce(function (a, b) {
|
|
473
|
+
return a + b;
|
|
474
|
+
}, 0) + "px" : undefined;
|
|
475
|
+
}, [offset, thicknesses]); // The thickness of the Detail segments. We need to convert to numbers
|
|
433
476
|
// to be able to compare across charts where some might be using T-shirt
|
|
434
477
|
// labels and others might be pixel values.
|
|
435
478
|
|
|
@@ -493,7 +536,7 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
493
536
|
ref: xRef,
|
|
494
537
|
axis: axis,
|
|
495
538
|
chartProps: chartProps,
|
|
496
|
-
|
|
539
|
+
pad: pad,
|
|
497
540
|
renderValue: renderValue,
|
|
498
541
|
serie: axis.x.property && getPropertySeries(axis.x.property)
|
|
499
542
|
}) : null;
|
|
@@ -533,20 +576,39 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
533
576
|
y = _ref9.y,
|
|
534
577
|
chartRest = _objectWithoutPropertiesLoose(_ref9, _excluded2);
|
|
535
578
|
|
|
536
|
-
|
|
579
|
+
// When we offset, we increase the padding on the end for all charts
|
|
580
|
+
// by the same amount and we shift each successive chart to the
|
|
581
|
+
// right by an offset for that chart. The last chart's right side
|
|
582
|
+
// will end up aligning with where the charts would have been
|
|
583
|
+
// had we not padded their ends.
|
|
584
|
+
var chartPad = offsetPad ? _extends({}, pad, {
|
|
585
|
+
end: offsetPad
|
|
586
|
+
}) : pad;
|
|
587
|
+
var offsetProps = offsetPad ? {
|
|
588
|
+
style: {
|
|
589
|
+
transform: "translate(" + offsets[i] + "px, 0px)"
|
|
590
|
+
}
|
|
591
|
+
} : {};
|
|
592
|
+
|
|
593
|
+
if (stackedChartType[type]) {
|
|
537
594
|
// reverse to ensure area Charts are stacked in the right order
|
|
538
595
|
return prop.map(function (cProp, j) {
|
|
539
596
|
var pProp = cProp.property || cProp;
|
|
597
|
+
|
|
598
|
+
var _ref10 = typeof cProp === 'object' ? cProp : {},
|
|
599
|
+
property = _ref10.property,
|
|
600
|
+
propRest = _objectWithoutPropertiesLoose(_ref10, _excluded3);
|
|
601
|
+
|
|
540
602
|
return /*#__PURE__*/React.createElement(Chart // eslint-disable-next-line react/no-array-index-key
|
|
541
603
|
, _extends({
|
|
542
604
|
key: j // when property name isn't valid, send empty array
|
|
543
605
|
,
|
|
544
606
|
values: chartValues[i][j] || [],
|
|
545
607
|
overflow: true
|
|
546
|
-
}, seriesStyles[pProp], chartProps[i], chartRest, {
|
|
547
|
-
type:
|
|
608
|
+
}, seriesStyles[pProp], chartProps[i], chartRest, propRest, offsetProps, {
|
|
609
|
+
type: stackedChartType[type] || type,
|
|
548
610
|
size: size,
|
|
549
|
-
pad:
|
|
611
|
+
pad: chartPad
|
|
550
612
|
}));
|
|
551
613
|
}).reverse();
|
|
552
614
|
}
|
|
@@ -556,15 +618,16 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
556
618
|
key: i,
|
|
557
619
|
values: chartValues[i],
|
|
558
620
|
overflow: true
|
|
559
|
-
}, seriesStyles[prop], chartProps[i], chartRest, {
|
|
621
|
+
}, seriesStyles[prop], chartProps[i], chartRest, offsetProps, {
|
|
560
622
|
type: type,
|
|
561
623
|
size: size,
|
|
562
|
-
pad:
|
|
624
|
+
pad: chartPad
|
|
563
625
|
}));
|
|
564
626
|
}), detail && /*#__PURE__*/React.createElement(Detail, {
|
|
565
627
|
activeProperty: activeProperty,
|
|
566
628
|
axis: axis,
|
|
567
629
|
data: data,
|
|
630
|
+
pad: pad,
|
|
568
631
|
series: series,
|
|
569
632
|
seriesStyles: seriesStyles,
|
|
570
633
|
renderValue: renderValue,
|
|
@@ -6,6 +6,7 @@ import { Grid } from '../Grid';
|
|
|
6
6
|
import { Keyboard } from '../Keyboard';
|
|
7
7
|
import { Text } from '../Text';
|
|
8
8
|
import { focusStyle, unfocusStyle } from '../../utils';
|
|
9
|
+
import { halfPad } from './utils';
|
|
9
10
|
import { Swatch } from './Swatch';
|
|
10
11
|
var DetailControl = styled(Box).withConfig({
|
|
11
12
|
displayName: "Detail__DetailControl",
|
|
@@ -16,6 +17,7 @@ var Detail = function Detail(_ref) {
|
|
|
16
17
|
var activeProperty = _ref.activeProperty,
|
|
17
18
|
axis = _ref.axis,
|
|
18
19
|
data = _ref.data,
|
|
20
|
+
pad = _ref.pad,
|
|
19
21
|
series = _ref.series,
|
|
20
22
|
seriesStyles = _ref.seriesStyles,
|
|
21
23
|
renderValue = _ref.renderValue,
|
|
@@ -52,6 +54,11 @@ var Detail = function Detail(_ref) {
|
|
|
52
54
|
tabIndex: 0,
|
|
53
55
|
direction: "row",
|
|
54
56
|
fill: true,
|
|
57
|
+
pad: // ensure the hit targets and center lines align with
|
|
58
|
+
// the data/guide lines
|
|
59
|
+
(pad == null ? void 0 : pad.horizontal) && halfPad[pad.horizontal] && {
|
|
60
|
+
horizontal: halfPad[pad.horizontal]
|
|
61
|
+
} || pad,
|
|
55
62
|
justify: "between",
|
|
56
63
|
responsive: false,
|
|
57
64
|
onFocus: function onFocus() {},
|
|
@@ -1,29 +1,38 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || 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); }
|
|
2
|
+
|
|
1
3
|
import React, { forwardRef } from 'react';
|
|
2
4
|
import { Box } from '../Box';
|
|
3
5
|
var XAxis = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
4
6
|
var chartProps = _ref.chartProps,
|
|
5
|
-
|
|
7
|
+
pad = _ref.pad,
|
|
6
8
|
renderValue = _ref.renderValue,
|
|
7
9
|
serie = _ref.serie;
|
|
8
10
|
// pull the x-axis values from the first chart, all should have the same
|
|
9
11
|
var _axis = (Array.isArray(chartProps[0]) ? chartProps[0][0] : chartProps[0]).axis,
|
|
10
|
-
axisValues = _axis[0];
|
|
12
|
+
axisValues = _axis[0]; // When there are only labels at the end of the axis, let them take as much
|
|
13
|
+
// space as they like. If there are more, align their container to the
|
|
14
|
+
// data/guide lines and then let their content overflow that.
|
|
15
|
+
|
|
16
|
+
var itemProps = axisValues.length === 2 ? {} : {
|
|
17
|
+
width: '1px',
|
|
18
|
+
overflow: 'visible',
|
|
19
|
+
align: 'center'
|
|
20
|
+
};
|
|
11
21
|
return /*#__PURE__*/React.createElement(Box, {
|
|
12
22
|
ref: ref,
|
|
13
23
|
gridArea: "xAxis",
|
|
14
24
|
direction: "row",
|
|
15
|
-
justify: "between"
|
|
25
|
+
justify: "between",
|
|
26
|
+
pad: pad != null && pad.horizontal ? {
|
|
27
|
+
horizontal: pad.horizontal
|
|
28
|
+
} : undefined
|
|
16
29
|
}, axisValues.map(function (dataIndex, i) {
|
|
17
|
-
var align;
|
|
18
|
-
if (axisValues.length === data.length) align = 'center';else if (i === 0) align = 'start';else if (i === axisValues.length - 1) align = 'end';else align = 'center';
|
|
19
30
|
return (
|
|
20
31
|
/*#__PURE__*/
|
|
21
32
|
// eslint-disable-next-line react/no-array-index-key
|
|
22
|
-
React.createElement(Box, {
|
|
23
|
-
key: i
|
|
24
|
-
|
|
25
|
-
align: align
|
|
26
|
-
}, serie ? renderValue(serie, dataIndex) : dataIndex)
|
|
33
|
+
React.createElement(Box, _extends({
|
|
34
|
+
key: i
|
|
35
|
+
}, itemProps), serie ? renderValue(serie, dataIndex) : dataIndex)
|
|
27
36
|
);
|
|
28
37
|
}));
|
|
29
38
|
});
|
|
@@ -14,7 +14,12 @@ type ChartType =
|
|
|
14
14
|
property:
|
|
15
15
|
| string
|
|
16
16
|
| string[]
|
|
17
|
-
| {
|
|
17
|
+
| {
|
|
18
|
+
property: string;
|
|
19
|
+
color?: string;
|
|
20
|
+
opacity?: string;
|
|
21
|
+
thickness?: string;
|
|
22
|
+
}[]
|
|
18
23
|
| {
|
|
19
24
|
color?:
|
|
20
25
|
| string
|
|
@@ -33,7 +38,7 @@ type ChartType =
|
|
|
33
38
|
};
|
|
34
39
|
round?: ChartProps['round']; // defaults to undefined
|
|
35
40
|
thickness?: ChartProps['thickness']; // defaults to auto assigned based on available space and amount of data
|
|
36
|
-
type?: ChartProps['type'] | 'bars'; // defaults to 'bar',
|
|
41
|
+
type?: ChartProps['type'] | 'bars' | 'areas' | 'lines'; // defaults to 'bar',
|
|
37
42
|
};
|
|
38
43
|
|
|
39
44
|
type SeriesType =
|
|
@@ -87,6 +92,9 @@ export interface DataChartProps {
|
|
|
87
92
|
};
|
|
88
93
|
// legend - when true, { side: 'bottom' }
|
|
89
94
|
legend?: boolean | { side: 'left' | 'right' | 'bottom' };
|
|
95
|
+
// offset - whether to shift the charts to reveal them all, mostly useful
|
|
96
|
+
// for bar charts
|
|
97
|
+
offset?: boolean;
|
|
90
98
|
// pad - padding around the guides/visuals
|
|
91
99
|
// defaults to what's needed based on axis and chart types
|
|
92
100
|
pad?: GridProps['pad'];
|
|
@@ -29,7 +29,7 @@ var chartType = PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
|
|
|
29
29
|
point: pointPropType,
|
|
30
30
|
round: PropTypes.bool,
|
|
31
31
|
thickness: thicknessType,
|
|
32
|
-
type: PropTypes.oneOf(['bar', 'bars', 'line', 'area', 'point'])
|
|
32
|
+
type: PropTypes.oneOf(['bar', 'bars', 'line', 'area', 'areas', 'lines', 'point'])
|
|
33
33
|
})]);
|
|
34
34
|
var seriesType = PropTypes.oneOfType([PropTypes.string, // property
|
|
35
35
|
PropTypes.shape({
|
|
@@ -68,6 +68,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
68
68
|
})])
|
|
69
69
|
})]),
|
|
70
70
|
legend: PropTypes.bool,
|
|
71
|
+
offset: PropTypes.bool,
|
|
71
72
|
pad: padPropType,
|
|
72
73
|
series: PropTypes.oneOfType([seriesType, PropTypes.arrayOf(seriesType)]),
|
|
73
74
|
size: PropTypes.oneOfType([PropTypes.oneOf(['fill']), PropTypes.shape({
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, DataChart, Text } from 'grommet';
|
|
3
|
+
var data = [];
|
|
4
|
+
|
|
5
|
+
for (var i = 0; i < 7; i += 1) {
|
|
6
|
+
data.push({
|
|
7
|
+
date: "2020-07-" + (i % 31 + 1).toString().padStart(2, 0),
|
|
8
|
+
usage: Math.floor(Math.abs(Math.sin(i / 2.0) * 100)),
|
|
9
|
+
bonus: Math.floor(Math.abs(Math.cos(i / 2.0) * 100)),
|
|
10
|
+
over: Math.floor(Math.abs(Math.sin(i / 2.0) * 50))
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export var Offset = function Offset() {
|
|
15
|
+
return (
|
|
16
|
+
/*#__PURE__*/
|
|
17
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
18
|
+
// <Grommet theme={grommet}>
|
|
19
|
+
React.createElement(Box, {
|
|
20
|
+
align: "center",
|
|
21
|
+
justify: "start",
|
|
22
|
+
pad: "large"
|
|
23
|
+
}, /*#__PURE__*/React.createElement(DataChart, {
|
|
24
|
+
data: data,
|
|
25
|
+
series: [{
|
|
26
|
+
property: 'date',
|
|
27
|
+
render: function render(date) {
|
|
28
|
+
return /*#__PURE__*/React.createElement(Text, {
|
|
29
|
+
margin: {
|
|
30
|
+
horizontal: 'xsmall'
|
|
31
|
+
}
|
|
32
|
+
}, new Date(date).toLocaleDateString('en-US', {
|
|
33
|
+
month: 'numeric',
|
|
34
|
+
day: 'numeric'
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
}, 'usage', 'bonus', 'over'],
|
|
38
|
+
chart: [{
|
|
39
|
+
property: 'usage',
|
|
40
|
+
type: 'bar',
|
|
41
|
+
thickness: 'small'
|
|
42
|
+
}, {
|
|
43
|
+
property: 'bonus',
|
|
44
|
+
type: 'bar',
|
|
45
|
+
thickness: 'small'
|
|
46
|
+
}, {
|
|
47
|
+
property: 'over',
|
|
48
|
+
type: 'bar',
|
|
49
|
+
thickness: 'small'
|
|
50
|
+
}],
|
|
51
|
+
offset: true,
|
|
52
|
+
axis: {
|
|
53
|
+
x: {
|
|
54
|
+
property: 'date',
|
|
55
|
+
granularity: 'fine'
|
|
56
|
+
},
|
|
57
|
+
y: true
|
|
58
|
+
},
|
|
59
|
+
guide: {
|
|
60
|
+
y: true
|
|
61
|
+
},
|
|
62
|
+
legend: true
|
|
63
|
+
})) // </Grommet>
|
|
64
|
+
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
Offset.storyName = 'Offset';
|
|
68
|
+
export default {
|
|
69
|
+
title: 'Visualizations/DataChart/Offset'
|
|
70
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, DataChart, Text } from 'grommet';
|
|
3
|
+
var data = [];
|
|
4
|
+
|
|
5
|
+
for (var i = 0; i < 7; i += 1) {
|
|
6
|
+
data.push({
|
|
7
|
+
date: "2020-07-" + (i % 31 + 1).toString().padStart(2, 0),
|
|
8
|
+
usage: Math.floor(Math.abs(Math.sin(i / 2.0) * 100)),
|
|
9
|
+
bonus: Math.floor(Math.abs(Math.cos(i / 2.0) * 100))
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export var StackedAreas = function StackedAreas() {
|
|
14
|
+
return (
|
|
15
|
+
/*#__PURE__*/
|
|
16
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
17
|
+
// <Grommet theme={grommet}>
|
|
18
|
+
React.createElement(Box, {
|
|
19
|
+
align: "center",
|
|
20
|
+
justify: "start",
|
|
21
|
+
pad: "large"
|
|
22
|
+
}, /*#__PURE__*/React.createElement(DataChart, {
|
|
23
|
+
data: data,
|
|
24
|
+
series: [{
|
|
25
|
+
property: 'date',
|
|
26
|
+
render: function render(date) {
|
|
27
|
+
return /*#__PURE__*/React.createElement(Text, {
|
|
28
|
+
margin: {
|
|
29
|
+
horizontal: 'xsmall'
|
|
30
|
+
}
|
|
31
|
+
}, new Date(date).toLocaleDateString('en-US', {
|
|
32
|
+
month: 'numeric',
|
|
33
|
+
day: 'numeric'
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
}, 'usage', 'bonus'],
|
|
37
|
+
chart: [{
|
|
38
|
+
property: [{
|
|
39
|
+
property: 'usage',
|
|
40
|
+
opacity: 'strong'
|
|
41
|
+
}, 'bonus'],
|
|
42
|
+
type: 'areas',
|
|
43
|
+
thickness: 'hair'
|
|
44
|
+
}],
|
|
45
|
+
axis: {
|
|
46
|
+
x: {
|
|
47
|
+
property: 'date',
|
|
48
|
+
granularity: 'fine'
|
|
49
|
+
},
|
|
50
|
+
y: true
|
|
51
|
+
},
|
|
52
|
+
guide: {
|
|
53
|
+
y: {
|
|
54
|
+
granularity: 'medium'
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
legend: true
|
|
58
|
+
})) // </Grommet>
|
|
59
|
+
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
StackedAreas.storyName = 'Stacked areas';
|
|
63
|
+
export default {
|
|
64
|
+
title: 'Visualizations/DataChart/Stacked areas'
|
|
65
|
+
};
|