grommet 2.25.0 → 2.25.3
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/Anchor/Anchor.js +14 -1
- package/components/Button/Button.js +81 -8
- package/components/Button/StyledButtonKind.js +9 -3
- package/components/Button/index.d.ts +1 -1
- package/components/Button/propTypes.js +1 -1
- package/components/Calendar/Calendar.js +232 -292
- package/components/Calendar/utils.js +16 -129
- package/components/Chart/calcs.js +44 -27
- package/components/Chart/stories/Scan.js +11 -9
- package/components/Chart/stories/data.js +16 -17
- package/components/CheckBox/CheckBox.js +3 -2
- package/components/DataChart/DataChart.js +14 -28
- package/components/DataChart/Detail.js +18 -11
- package/components/DataChart/XAxis.js +29 -18
- package/components/DataChart/stories/Pad.js +54 -0
- package/components/DataTable/DataTable.js +13 -9
- package/components/DataTable/buildState.js +2 -2
- package/components/DataTable/index.d.ts +4 -1
- package/components/DataTable/stories/SpaceX.js +3 -1
- package/components/DataTable/stories/SpaceXUngrouped.js +6 -2
- package/components/DateInput/DateInput.js +60 -68
- package/components/DateInput/utils.js +30 -5
- package/components/FileInput/FileInput.js +2 -1
- package/components/FileInput/StyledFileInput.js +1 -1
- package/components/Form/Form.js +78 -5
- package/components/FormField/FormField.js +29 -29
- package/components/Grommet/Grommet.js +7 -2
- package/components/Grommet/index.d.ts +1 -0
- package/components/Grommet/propTypes.js +2 -1
- package/components/Heading/Heading.js +4 -2
- package/components/Heading/StyledHeading.js +1 -1
- package/components/Heading/index.d.ts +1 -0
- package/components/Heading/propTypes.js +2 -1
- package/components/Image/Image.js +4 -2
- package/components/Layer/LayerContainer.js +25 -0
- package/components/List/List.js +17 -0
- package/components/Menu/Menu.js +7 -4
- package/components/Menu/index.d.ts +2 -2
- package/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
- package/components/Meter/Circle.js +5 -1
- package/components/PageHeader/PageHeader.js +22 -13
- package/components/PageHeader/index.d.ts +10 -1
- package/components/PageHeader/propTypes.js +1 -0
- package/components/PageHeader/stories/Size.js +55 -0
- package/components/Select/SelectContainer.js +96 -75
- package/components/Select/stories/Clear.js +7 -1
- package/components/Select/utils.js +1 -0
- package/components/Spinner/Spinner.js +1 -0
- package/components/Tab/Tab.js +1 -1
- package/components/Tabs/Tabs.js +11 -2
- package/components/Video/StyledVideo.js +2 -2
- package/contexts/AnalyticsContext/AnalyticsContext.js +65 -0
- package/contexts/AnalyticsContext/index.d.ts +7 -0
- package/contexts/AnalyticsContext/index.js +11 -0
- package/contexts/index.js +8 -0
- package/es6/components/Anchor/Anchor.js +15 -3
- package/es6/components/Button/Button.js +83 -11
- package/es6/components/Button/StyledButtonKind.js +9 -3
- package/es6/components/Button/index.d.ts +1 -1
- package/es6/components/Button/propTypes.js +1 -1
- package/es6/components/Calendar/Calendar.js +230 -292
- package/es6/components/Calendar/utils.js +13 -114
- package/es6/components/Chart/calcs.js +44 -27
- package/es6/components/Chart/stories/Scan.js +10 -9
- package/es6/components/Chart/stories/data.js +16 -17
- package/es6/components/CheckBox/CheckBox.js +3 -2
- package/es6/components/DataChart/DataChart.js +15 -28
- package/es6/components/DataChart/Detail.js +20 -10
- package/es6/components/DataChart/XAxis.js +29 -19
- package/es6/components/DataChart/stories/Pad.js +42 -0
- package/es6/components/DataTable/DataTable.js +13 -9
- package/es6/components/DataTable/buildState.js +2 -2
- package/es6/components/DataTable/index.d.ts +4 -1
- package/es6/components/DataTable/stories/SpaceX.js +3 -1
- package/es6/components/DataTable/stories/SpaceXUngrouped.js +6 -2
- package/es6/components/DateInput/DateInput.js +57 -64
- package/es6/components/DateInput/utils.js +29 -7
- package/es6/components/FileInput/FileInput.js +2 -1
- package/es6/components/FileInput/StyledFileInput.js +1 -1
- package/es6/components/Form/Form.js +76 -5
- package/es6/components/FormField/FormField.js +29 -30
- package/es6/components/Grommet/Grommet.js +6 -2
- package/es6/components/Grommet/index.d.ts +1 -0
- package/es6/components/Grommet/propTypes.js +2 -1
- package/es6/components/Heading/Heading.js +4 -2
- package/es6/components/Heading/StyledHeading.js +1 -1
- package/es6/components/Heading/index.d.ts +1 -0
- package/es6/components/Heading/propTypes.js +2 -1
- package/es6/components/Image/Image.js +4 -2
- package/es6/components/Layer/LayerContainer.js +24 -0
- package/es6/components/List/List.js +16 -0
- package/es6/components/Menu/Menu.js +7 -4
- package/es6/components/Menu/index.d.ts +2 -2
- package/es6/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
- package/es6/components/Meter/Circle.js +5 -1
- package/es6/components/PageHeader/PageHeader.js +24 -14
- package/es6/components/PageHeader/index.d.ts +10 -1
- package/es6/components/PageHeader/propTypes.js +1 -0
- package/es6/components/PageHeader/stories/Size.js +43 -0
- package/es6/components/Select/SelectContainer.js +96 -77
- package/es6/components/Select/stories/Clear.js +7 -1
- package/es6/components/Select/utils.js +1 -0
- package/es6/components/Spinner/Spinner.js +1 -0
- package/es6/components/Tab/Tab.js +1 -1
- package/es6/components/Tabs/Tabs.js +10 -2
- package/es6/components/Video/StyledVideo.js +2 -2
- package/es6/contexts/AnalyticsContext/AnalyticsContext.js +47 -0
- package/es6/contexts/AnalyticsContext/index.d.ts +7 -0
- package/es6/contexts/AnalyticsContext/index.js +1 -0
- package/es6/contexts/index.js +1 -0
- package/es6/themes/base.d.ts +51 -33
- package/es6/themes/base.js +49 -1
- package/es6/utils/DOM.js +4 -0
- package/es6/utils/mixins.js +3 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/package.json +56 -48
- package/themes/base.d.ts +51 -33
- package/themes/base.js +49 -1
- package/tools/pack.js +20 -13
- package/tools/release-stable.js +2 -4
- package/utils/DOM.js +9 -2
- package/utils/mixins.js +7 -1
|
@@ -55,11 +55,6 @@ export var sameDayOrBefore = function sameDayOrBefore(date1, date2) {
|
|
|
55
55
|
};
|
|
56
56
|
export var daysApart = function daysApart(date1, date2) {
|
|
57
57
|
return Math.floor((date1.getTime() - date2.getTime()) / DAY_MILLISECONDS);
|
|
58
|
-
};
|
|
59
|
-
export var formatToLocalYYYYMMDD = function formatToLocalYYYYMMDD(date, normalize) {
|
|
60
|
-
var adjustedDate = new Date(date);
|
|
61
|
-
var nextDate = normalize ? new Date(adjustedDate.getTime() - adjustedDate.getTimezoneOffset() * 60000) : new Date(adjustedDate.getTime());
|
|
62
|
-
return nextDate.toISOString().split('T')[0];
|
|
63
58
|
}; // betweenDates takes an array of two elements and checks if the
|
|
64
59
|
// supplied date lies between them, inclusive.
|
|
65
60
|
// returns 2 if exact match to one end, 1 if between, undefined otherwise
|
|
@@ -68,11 +63,11 @@ export var betweenDates = function betweenDates(date, dates) {
|
|
|
68
63
|
var result;
|
|
69
64
|
|
|
70
65
|
if (dates) {
|
|
71
|
-
var
|
|
66
|
+
var _ref = Array.isArray(dates) ? dates.map(function (d) {
|
|
72
67
|
return d ? new Date(d) : undefined;
|
|
73
|
-
}),
|
|
74
|
-
from =
|
|
75
|
-
to =
|
|
68
|
+
}) : [dates, undefined],
|
|
69
|
+
from = _ref[0],
|
|
70
|
+
to = _ref[1];
|
|
76
71
|
|
|
77
72
|
if (from && sameDay(date, from) || to && sameDay(date, to)) {
|
|
78
73
|
result = 2;
|
|
@@ -95,8 +90,8 @@ export var withinDates = function withinDates(date, dates) {
|
|
|
95
90
|
if (dates) {
|
|
96
91
|
if (Array.isArray(dates)) {
|
|
97
92
|
dates.some(function (d) {
|
|
98
|
-
if (
|
|
99
|
-
if (sameDay(date,
|
|
93
|
+
if (d instanceof Date) {
|
|
94
|
+
if (sameDay(date, d)) {
|
|
100
95
|
result = 2;
|
|
101
96
|
}
|
|
102
97
|
} else {
|
|
@@ -105,114 +100,18 @@ export var withinDates = function withinDates(date, dates) {
|
|
|
105
100
|
|
|
106
101
|
return result;
|
|
107
102
|
});
|
|
108
|
-
} else if (sameDay(date,
|
|
103
|
+
} else if (sameDay(date, dates)) {
|
|
109
104
|
result = 2;
|
|
110
105
|
}
|
|
111
106
|
}
|
|
112
107
|
|
|
113
108
|
return result;
|
|
114
109
|
};
|
|
115
|
-
export var
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}; // Checks if daylight savings is in effect for a timezone and date
|
|
120
|
-
// Reference: https://stackoverflow.com/questions/11887934/how-to-check-if-dst-daylight-saving-time-is-in-effect-and-if-so-the-offset
|
|
121
|
-
|
|
122
|
-
var inDaylightSavings = function inDaylightSavings(day) {
|
|
123
|
-
var jan = new Date(day.getFullYear(), 0, 1).getTimezoneOffset();
|
|
124
|
-
var july = new Date(day.getFullYear(), 6, 1).getTimezoneOffset();
|
|
125
|
-
return Math.max(jan, july) !== day.getTimezoneOffset();
|
|
126
|
-
}; // Adjust for differences between timestamp on value and
|
|
127
|
-
// local timezone of user. Internal Calendar logic relies
|
|
128
|
-
// on Javascript date contructor which translates the provided
|
|
129
|
-
// date into the equivalent moment for the user's timezone, which
|
|
130
|
-
// can create undesired results. The standardizes the input value
|
|
131
|
-
// for internal calculations
|
|
132
|
-
// Reference: https://www.ursahealth.com/new-insights/dates-and-timezones-in-javascript
|
|
133
|
-
// If normalize is false just convert the value toISOString(),
|
|
134
|
-
// valueOffset/localOffset will be 0.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
export var normalizeForTimezone = function normalizeForTimezone(value, timestamp, normalize) {
|
|
138
|
-
if (normalize === void 0) {
|
|
139
|
-
normalize = true;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
var adjustedDate;
|
|
143
|
-
var hourDelta = 0;
|
|
144
|
-
var valueOffset = 0;
|
|
145
|
-
var localOffset = 0;
|
|
146
|
-
|
|
147
|
-
if (normalize) {
|
|
148
|
-
if (timestamp && typeof timestamp === 'string') {
|
|
149
|
-
hourDelta = parseInt(timestamp == null ? void 0 : timestamp.split(':')[0], 10);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
var today = new Date();
|
|
153
|
-
adjustedDate = value && (Array.isArray(value) ? value : [value]).map(function (v) {
|
|
154
|
-
var day = new Date(v); // If one of the days either day or today is in daylight savings and the
|
|
155
|
-
// other is not the timezoneOffset will be different. If they are both
|
|
156
|
-
// in or out of daylight savings the timezoneOffset will be the same.
|
|
157
|
-
|
|
158
|
-
if (day && !inDaylightSavings(day) && day.getTimezoneOffset() > today.getTimezoneOffset()) {
|
|
159
|
-
// today is in daylight savings but the selected day is not
|
|
160
|
-
hourDelta -= 1;
|
|
161
|
-
} else if (day && inDaylightSavings(day) && day.getTimezoneOffset() < today.getTimezoneOffset()) {
|
|
162
|
-
// the selected day is in daylight savings but today is not
|
|
163
|
-
hourDelta += 1;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
valueOffset = hourDelta === 0 ? 0 : hourDelta * 60 * 60 * 1000;
|
|
167
|
-
localOffset = new Date().getTimezoneOffset() * 60 * 1000;
|
|
168
|
-
return new Date(new Date(v).getTime() - valueOffset + localOffset).toISOString();
|
|
169
|
-
});
|
|
170
|
-
} else {
|
|
171
|
-
adjustedDate = value && (Array.isArray(value) ? value : [value]).map(function (v) {
|
|
172
|
-
return new Date(new Date(v).getTime()).toISOString();
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (typeof value === 'string') {
|
|
177
|
-
var _adjustedDate = adjustedDate;
|
|
178
|
-
adjustedDate = _adjustedDate[0];
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return adjustedDate;
|
|
182
|
-
}; // format the date to align with date format caller passed in
|
|
183
|
-
|
|
184
|
-
export var formatDateToPropStructure = function formatDateToPropStructure(date, timestamp, normalize) {
|
|
185
|
-
var adjustedDate;
|
|
186
|
-
|
|
187
|
-
if (date) {
|
|
188
|
-
if (timestamp) {
|
|
189
|
-
adjustedDate = formatToLocalYYYYMMDD(date, normalize).split('T')[0] + "T" + timestamp;
|
|
190
|
-
} else if (timestamp === false) {
|
|
191
|
-
var _formatToLocalYYYYMMD = formatToLocalYYYYMMDD(date, normalize).split('T');
|
|
192
|
-
|
|
193
|
-
adjustedDate = _formatToLocalYYYYMMD[0];
|
|
194
|
-
} else adjustedDate = date;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return adjustedDate;
|
|
198
|
-
};
|
|
199
|
-
export var getFormattedDate = function getFormattedDate(nextDate, nextDates, normalize, range, timestamp) {
|
|
200
|
-
var adjustedDate;
|
|
201
|
-
var adjustedDates;
|
|
202
|
-
|
|
203
|
-
if (nextDates && Array.isArray(nextDates[0]) && (!nextDates[0][0] || !nextDates[0][1]) && range === true) {
|
|
204
|
-
// return string for backwards compatibility
|
|
205
|
-
var _nextDates$0$filter = nextDates[0].filter(function (d) {
|
|
206
|
-
return d;
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
adjustedDates = _nextDates$0$filter[0];
|
|
210
|
-
adjustedDates = formatDateToPropStructure(adjustedDates, timestamp, normalize);
|
|
211
|
-
} else if (nextDates) {
|
|
212
|
-
adjustedDates = [[formatDateToPropStructure(nextDates[0][0], timestamp, normalize), formatDateToPropStructure(nextDates[0][1], timestamp, normalize)]];
|
|
213
|
-
} else {
|
|
214
|
-
adjustedDate = formatDateToPropStructure(nextDate, timestamp, normalize);
|
|
215
|
-
}
|
|
110
|
+
export var handleOffset = function handleOffset(date) {
|
|
111
|
+
var normalizedDate = new Date(date);
|
|
112
|
+
var offset = normalizedDate.getTimezoneOffset();
|
|
113
|
+
var hour = normalizedDate.getHours(); // add back offset
|
|
216
114
|
|
|
217
|
-
|
|
115
|
+
normalizedDate.setHours(hour, offset < 0 ? -offset : offset);
|
|
116
|
+
return normalizedDate;
|
|
218
117
|
};
|
|
@@ -30,9 +30,12 @@ export var calcBounds = function calcBounds(values, options) {
|
|
|
30
30
|
// coarseness influences the rounding of the bounds, the smaller the
|
|
31
31
|
// number, the more the bounds will be rounded. e.g. 111 -> 110 -> 100
|
|
32
32
|
// Normalize to an array. Backwards compatible has no coarseness for x-axis
|
|
33
|
-
var coarseness = Array.isArray(options.coarseness) && options.coarseness || options.coarseness && [undefined, options.coarseness] || [undefined, 5];
|
|
33
|
+
var coarseness = Array.isArray(options.coarseness) && options.coarseness || options.coarseness && [undefined, options.coarseness] || [undefined, 5];
|
|
34
|
+
var coarseX = coarseness[0],
|
|
35
|
+
coarseY = coarseness[1]; // the number of steps is one less than the number of labels
|
|
34
36
|
|
|
35
37
|
var steps = options.steps || [1, 1];
|
|
38
|
+
var stepsY = steps[1];
|
|
36
39
|
var calcValues = normalizeValues(values || []); // min and max values
|
|
37
40
|
|
|
38
41
|
var minX;
|
|
@@ -79,19 +82,16 @@ export var calcBounds = function calcBounds(values, options) {
|
|
|
79
82
|
// graph axis labels.
|
|
80
83
|
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
cY = coarseness[1];
|
|
84
|
-
|
|
85
|
-
if (cX) {
|
|
85
|
+
if (coarseX) {
|
|
86
86
|
var deltaX = maxX - minX;
|
|
87
|
-
var intervalX = Number.parseFloat((deltaX /
|
|
87
|
+
var intervalX = Number.parseFloat((deltaX / coarseX).toPrecision(1));
|
|
88
88
|
minX = alignMin(minX, intervalX);
|
|
89
89
|
maxX = alignMax(maxX, intervalX);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
if (
|
|
92
|
+
if (coarseY) {
|
|
93
93
|
var deltaY = maxY - minY;
|
|
94
|
-
var intervalY = Number.parseFloat((deltaY /
|
|
94
|
+
var intervalY = Number.parseFloat((deltaY / coarseY).toPrecision(1));
|
|
95
95
|
minY = alignMin(minY, intervalY);
|
|
96
96
|
maxY = alignMax(maxY, intervalY);
|
|
97
97
|
}
|
|
@@ -99,19 +99,26 @@ export var calcBounds = function calcBounds(values, options) {
|
|
|
99
99
|
if (minY < 0 && maxY > 0 && Math.abs(minY) !== Math.abs(maxY)) {
|
|
100
100
|
// Adjust min and max when crossing 0 to ensure 0 will be shown on
|
|
101
101
|
// the Y axis based on the number of steps.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (Math.abs(minSteps) < Math.abs(maxSteps)) {
|
|
108
|
-
stepInterval = maxY / Math.floor(maxSteps);
|
|
109
|
-
maxY = stepInterval * Math.floor(maxSteps);
|
|
110
|
-
minY = stepInterval * Math.floor(minSteps);
|
|
102
|
+
if (stepsY === 1) {
|
|
103
|
+
var largest = Math.max(Math.abs(minY), Math.abs(maxY));
|
|
104
|
+
minY = -largest;
|
|
105
|
+
maxY = largest;
|
|
111
106
|
} else {
|
|
112
|
-
stepInterval =
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
var stepInterval = (maxY - minY) / stepsY;
|
|
108
|
+
var minSteps = minY / stepInterval;
|
|
109
|
+
var maxSteps = maxY / stepInterval;
|
|
110
|
+
|
|
111
|
+
if (Math.abs(minSteps) < Math.abs(maxSteps)) {
|
|
112
|
+
// more above than below
|
|
113
|
+
stepInterval = maxY / Math.floor(maxSteps);
|
|
114
|
+
maxY = stepInterval * Math.floor(maxSteps);
|
|
115
|
+
minY = stepInterval * Math.floor(minSteps);
|
|
116
|
+
} else {
|
|
117
|
+
// more below than above
|
|
118
|
+
stepInterval = Math.abs(minY / Math.ceil(minSteps));
|
|
119
|
+
minY = stepInterval * Math.ceil(minSteps);
|
|
120
|
+
maxY = stepInterval * Math.ceil(maxSteps);
|
|
121
|
+
}
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
}
|
|
@@ -131,27 +138,37 @@ export var calcs = function calcs(values, options) {
|
|
|
131
138
|
|
|
132
139
|
// the number of steps is one less than the number of labels
|
|
133
140
|
var steps = options.steps || [1, 1];
|
|
141
|
+
var stepsX = steps[0],
|
|
142
|
+
stepsY = steps[1];
|
|
134
143
|
var bounds = options.bounds || calcBounds(values, options);
|
|
135
144
|
if (options.min !== undefined) bounds[1][0] = options.min;
|
|
136
145
|
if (options.max !== undefined) bounds[1][1] = options.max;
|
|
137
|
-
var
|
|
146
|
+
var boundsX = bounds[0],
|
|
147
|
+
boundsY = bounds[1];
|
|
148
|
+
var boundsXmin = boundsX[0],
|
|
149
|
+
boundsXmax = boundsX[1];
|
|
150
|
+
var boundsYmin = boundsY[0],
|
|
151
|
+
boundsYmax = boundsY[1];
|
|
152
|
+
var dimensions = [round(boundsXmax - boundsXmin, 2), round(boundsYmax - boundsYmin, 2)];
|
|
153
|
+
var dimensionsX = dimensions[0],
|
|
154
|
+
dimensionsY = dimensions[1]; // Calculate x and y axis values across the specfied number of steps.
|
|
138
155
|
|
|
139
156
|
var yAxis = [];
|
|
140
|
-
var y =
|
|
157
|
+
var y = boundsYmax; // To deal with javascript math limitations, round the step with 4 decimal
|
|
141
158
|
// places and then push the values with 2 decimal places
|
|
142
159
|
|
|
143
|
-
var yStepInterval = round(
|
|
160
|
+
var yStepInterval = round(dimensionsY / stepsY, 4);
|
|
144
161
|
|
|
145
|
-
while (round(y, 2) >=
|
|
162
|
+
while (round(y, 2) >= boundsYmin) {
|
|
146
163
|
yAxis.push(round(y, 2));
|
|
147
164
|
y -= yStepInterval;
|
|
148
165
|
}
|
|
149
166
|
|
|
150
167
|
var xAxis = [];
|
|
151
|
-
var x =
|
|
152
|
-
var xStepInterval = round(
|
|
168
|
+
var x = boundsXmin;
|
|
169
|
+
var xStepInterval = round(dimensionsX / stepsX, 4);
|
|
153
170
|
|
|
154
|
-
while (round(x, 2) <=
|
|
171
|
+
while (round(x, 2) <= boundsXmax) {
|
|
155
172
|
xAxis.push(round(x, 2));
|
|
156
173
|
x += xStepInterval;
|
|
157
174
|
}
|
|
@@ -2,24 +2,28 @@ import React, { useMemo, useState } from 'react';
|
|
|
2
2
|
import { Box, Chart, Keyboard, Stack, Text } from 'grommet';
|
|
3
3
|
import { calcs } from '../calcs';
|
|
4
4
|
import { generateData } from './data';
|
|
5
|
+
var count = 30,
|
|
6
|
+
max = 100,
|
|
7
|
+
min = 0;
|
|
5
8
|
|
|
6
|
-
var ScanChart = function ScanChart(
|
|
9
|
+
var ScanChart = function ScanChart() {
|
|
7
10
|
var _useState = useState(undefined),
|
|
8
11
|
active = _useState[0],
|
|
9
12
|
setActive = _useState[1];
|
|
10
13
|
|
|
11
|
-
var data =
|
|
12
|
-
|
|
14
|
+
var data = useMemo(function () {
|
|
15
|
+
return generateData(count, max, min);
|
|
16
|
+
}, []);
|
|
13
17
|
var values = data.map(function (d) {
|
|
14
18
|
return [d.time, d.value];
|
|
15
19
|
});
|
|
16
20
|
|
|
17
21
|
var _useMemo = useMemo(function () {
|
|
18
22
|
return calcs(values, {
|
|
19
|
-
min:
|
|
23
|
+
min: min,
|
|
20
24
|
max: max
|
|
21
25
|
});
|
|
22
|
-
}, [values
|
|
26
|
+
}, [values]),
|
|
23
27
|
axis = _useMemo.axis,
|
|
24
28
|
bounds = _useMemo.bounds,
|
|
25
29
|
pad = _useMemo.pad,
|
|
@@ -145,10 +149,7 @@ var ScanChart = function ScanChart(props) {
|
|
|
145
149
|
};
|
|
146
150
|
|
|
147
151
|
export var Scan = function Scan() {
|
|
148
|
-
return /*#__PURE__*/React.createElement(ScanChart,
|
|
149
|
-
data: generateData(30, 100),
|
|
150
|
-
max: 100
|
|
151
|
-
});
|
|
152
|
+
return /*#__PURE__*/React.createElement(ScanChart, null);
|
|
152
153
|
};
|
|
153
154
|
Scan.parameters = {
|
|
154
155
|
chromatic: {
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
// generate a data set
|
|
2
2
|
var dataSet = {
|
|
3
|
-
generateData: function generateData(count, max) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var date = new Date();
|
|
3
|
+
generateData: function generateData(count, max, min) {
|
|
4
|
+
if (count === void 0) {
|
|
5
|
+
count = 5;
|
|
6
|
+
}
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
if (max === void 0) {
|
|
9
|
+
max = 100;
|
|
10
|
+
}
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} else {
|
|
17
|
-
value -= value % Math.ceil((data.length % (max / 4) + 1) / 2);
|
|
12
|
+
if (min === void 0) {
|
|
13
|
+
min = 0;
|
|
14
|
+
}
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
16
|
+
var data = [];
|
|
17
|
+
var date = new Date();
|
|
18
|
+
var span = max - min;
|
|
23
19
|
|
|
20
|
+
while (data.length < count) {
|
|
21
|
+
var s = Math.sin(data.length / 2.0);
|
|
22
|
+
var value = s * (span / 2) + (span / 2 + min);
|
|
24
23
|
var nextDay = date.getDate() - 1;
|
|
25
24
|
date = new Date(date);
|
|
26
25
|
date.setDate(nextDay);
|
|
@@ -151,7 +151,9 @@ var CheckBox = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
151
151
|
align: "center",
|
|
152
152
|
justify: "center",
|
|
153
153
|
margin: label && (_ref2 = {}, _ref2[side] = theme.checkBox.gap || 'small', _ref2)
|
|
154
|
-
}, themeableProps), /*#__PURE__*/React.createElement(StyledCheckBoxInput, _extends({
|
|
154
|
+
}, themeableProps), /*#__PURE__*/React.createElement(StyledCheckBoxInput, _extends({
|
|
155
|
+
"aria-label": ariaLabel || a11yTitle
|
|
156
|
+
}, rest, {
|
|
155
157
|
ref: ref,
|
|
156
158
|
type: "checkbox"
|
|
157
159
|
}, removeUndefined({
|
|
@@ -180,7 +182,6 @@ var CheckBox = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
180
182
|
var first = reverse ? normalizedLabel : checkBoxNode;
|
|
181
183
|
var second = reverse ? checkBoxNode : normalizedLabel;
|
|
182
184
|
return /*#__PURE__*/React.createElement(StyledCheckBoxContainer, _extends({
|
|
183
|
-
"aria-label": ariaLabel || a11yTitle,
|
|
184
185
|
fillProp: fill,
|
|
185
186
|
reverse: reverse
|
|
186
187
|
}, removeUndefined({
|
|
@@ -6,9 +6,8 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
6
6
|
|
|
7
7
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
8
8
|
|
|
9
|
-
import React, { forwardRef, useContext, useMemo,
|
|
9
|
+
import React, { forwardRef, useContext, useMemo, useState } from 'react';
|
|
10
10
|
import { ThemeContext } from 'styled-components';
|
|
11
|
-
import { useLayoutEffect } from '../../utils/use-isomorphic-layout-effect';
|
|
12
11
|
import { Box } from '../Box';
|
|
13
12
|
import { Chart, calcs, calcBounds } from '../Chart';
|
|
14
13
|
import { Grid } from '../Grid';
|
|
@@ -60,12 +59,9 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
60
59
|
|
|
61
60
|
var _useState = useState(),
|
|
62
61
|
activeProperty = _useState[0],
|
|
63
|
-
setActiveProperty = _useState[1]; //
|
|
62
|
+
setActiveProperty = _useState[1]; // normalize seriesProp to an array of objects, one per property
|
|
64
63
|
|
|
65
64
|
|
|
66
|
-
var xRef = useRef();
|
|
67
|
-
var spacerRef = useRef(); // normalize seriesProp to an array of objects, one per property
|
|
68
|
-
|
|
69
65
|
var series = useMemo(function () {
|
|
70
66
|
if (Array.isArray(seriesProp)) return seriesProp.filter(function (s) {
|
|
71
67
|
return s.property || typeof s === 'string';
|
|
@@ -493,22 +489,18 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
493
489
|
|
|
494
490
|
var offsetPad = useMemo(function () {
|
|
495
491
|
return offsets ? offsets[offsets.length - 1] + thicknesses[thicknesses.length - 1] + "px" : undefined;
|
|
496
|
-
}, [offsets, thicknesses]); // The thickness of the
|
|
492
|
+
}, [offsets, thicknesses]); // The thickness of the segments. We need to convert to numbers
|
|
497
493
|
// to be able to compare across charts where some might be using T-shirt
|
|
498
494
|
// labels and others might be pixel values.
|
|
499
495
|
|
|
500
|
-
var
|
|
496
|
+
var segmentThickness = useMemo(function () {
|
|
501
497
|
var result = 0;
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
result = Math.max(result, parseMetricToNum(theme.global.edgeSize[thickness] || thickness));
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
|
|
498
|
+
charts.forEach(function (_, index) {
|
|
499
|
+
var thickness = chartProps[index].thickness;
|
|
500
|
+
result = Math.max(result, parseMetricToNum(theme.global.edgeSize[thickness] || thickness));
|
|
501
|
+
});
|
|
510
502
|
return result + "px";
|
|
511
|
-
}, [charts, chartProps,
|
|
503
|
+
}, [charts, chartProps, theme]);
|
|
512
504
|
var dateFormats = useMemo(function () {
|
|
513
505
|
var result = {};
|
|
514
506
|
var full = axis && axis.x && axis.x.granularity === 'coarse';
|
|
@@ -521,14 +513,7 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
521
513
|
}
|
|
522
514
|
});
|
|
523
515
|
return result;
|
|
524
|
-
}, [axis, data, series]);
|
|
525
|
-
|
|
526
|
-
useLayoutEffect(function () {
|
|
527
|
-
if (xRef.current && spacerRef.current) {
|
|
528
|
-
var rect = xRef.current.getBoundingClientRect();
|
|
529
|
-
spacerRef.current.style.height = rect.height + "px";
|
|
530
|
-
}
|
|
531
|
-
}, []);
|
|
516
|
+
}, [axis, data, series]);
|
|
532
517
|
|
|
533
518
|
var renderValue = function renderValue(serie, dataIndex, valueArg) {
|
|
534
519
|
var value;
|
|
@@ -554,17 +539,18 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
554
539
|
|
|
555
540
|
|
|
556
541
|
var xAxisElement = axis && axis.x && chartProps.length ? /*#__PURE__*/React.createElement(XAxis, {
|
|
557
|
-
ref: xRef,
|
|
558
542
|
axis: axis,
|
|
559
543
|
values: (Array.isArray(chartProps[0]) ? chartProps[0][0] : chartProps[0]).axis[0],
|
|
560
544
|
pad: offsetPad ? _extends({}, pad, {
|
|
561
545
|
end: offsetPad
|
|
562
546
|
}) : pad,
|
|
563
547
|
renderValue: renderValue,
|
|
548
|
+
thickness: segmentThickness,
|
|
564
549
|
serie: axis.x.property && getPropertySeries(axis.x.property),
|
|
565
550
|
style: offsetPad ? {
|
|
566
551
|
transform: "translate(" + offsets[Math.floor(offsets.length / 2)] + "px, 0px)"
|
|
567
|
-
} : {}
|
|
552
|
+
} : {},
|
|
553
|
+
theme: theme
|
|
568
554
|
}) : null;
|
|
569
555
|
var yAxisElement = axis && axis.y && (chartProps.length || boundsProp != null && boundsProp.y) ? /*#__PURE__*/React.createElement(YAxis, {
|
|
570
556
|
axis: axis,
|
|
@@ -664,10 +650,11 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
664
650
|
activeProperty: activeProperty,
|
|
665
651
|
axis: axis,
|
|
666
652
|
data: data,
|
|
653
|
+
pad: pad,
|
|
667
654
|
series: series,
|
|
668
655
|
seriesStyles: seriesStyles,
|
|
669
656
|
renderValue: renderValue,
|
|
670
|
-
thickness:
|
|
657
|
+
thickness: segmentThickness
|
|
671
658
|
}));
|
|
672
659
|
var legendElement = legend ? /*#__PURE__*/React.createElement(Legend, {
|
|
673
660
|
series: series,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import React, { Fragment, useCallback, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import styled from 'styled-components';
|
|
1
|
+
import React, { Fragment, useCallback, useContext, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import styled, { ThemeContext } from 'styled-components';
|
|
3
3
|
import { Box } from '../Box';
|
|
4
4
|
import { Drop } from '../Drop';
|
|
5
5
|
import { Grid } from '../Grid';
|
|
6
6
|
import { Keyboard } from '../Keyboard';
|
|
7
7
|
import { Text } from '../Text';
|
|
8
|
-
import { focusStyle, unfocusStyle } from '../../utils';
|
|
9
|
-
import { halfPad } from './utils';
|
|
8
|
+
import { focusStyle, parseMetricToNum, unfocusStyle } from '../../utils';
|
|
10
9
|
import { Swatch } from './Swatch';
|
|
11
10
|
var DetailControl = styled(Box).withConfig({
|
|
12
11
|
displayName: "Detail__DetailControl",
|
|
@@ -17,11 +16,12 @@ var Detail = function Detail(_ref) {
|
|
|
17
16
|
var activeProperty = _ref.activeProperty,
|
|
18
17
|
axis = _ref.axis,
|
|
19
18
|
data = _ref.data,
|
|
20
|
-
|
|
19
|
+
padProp = _ref.pad,
|
|
21
20
|
series = _ref.series,
|
|
22
21
|
seriesStyles = _ref.seriesStyles,
|
|
23
22
|
renderValue = _ref.renderValue,
|
|
24
23
|
thickness = _ref.thickness;
|
|
24
|
+
var theme = useContext(ThemeContext) || defaultProps.theme;
|
|
25
25
|
|
|
26
26
|
var _useState = useState(),
|
|
27
27
|
detailIndex = _useState[0],
|
|
@@ -31,6 +31,20 @@ var Detail = function Detail(_ref) {
|
|
|
31
31
|
var detailRefs = useMemo(function () {
|
|
32
32
|
return [];
|
|
33
33
|
}, []);
|
|
34
|
+
var pad = useMemo(function () {
|
|
35
|
+
// ensure the hit targets and center lines align with
|
|
36
|
+
// the data/guide lines
|
|
37
|
+
var horizontal = (padProp == null ? void 0 : padProp.horizontal) || typeof padProp === 'string' && padProp || 0;
|
|
38
|
+
horizontal = theme.global.edgeSize[horizontal] || horizontal;
|
|
39
|
+
horizontal = parseMetricToNum(horizontal);
|
|
40
|
+
var vertical = (padProp == null ? void 0 : padProp.vertical) || typeof padProp === 'string' && padProp || 0;
|
|
41
|
+
vertical = theme.global.edgeSize[vertical] || vertical;
|
|
42
|
+
vertical = parseMetricToNum(vertical);
|
|
43
|
+
return {
|
|
44
|
+
horizontal: horizontal - parseMetricToNum(thickness) / 2 + "px",
|
|
45
|
+
vertical: vertical + "px"
|
|
46
|
+
};
|
|
47
|
+
}, [padProp, theme.global.edgeSize, thickness]);
|
|
34
48
|
var onMouseLeave = useCallback(function (event) {
|
|
35
49
|
// Only remove detail if the mouse isn't over the active index.
|
|
36
50
|
// This helps distinguish leaving the drop on the edge where it is
|
|
@@ -54,11 +68,7 @@ var Detail = function Detail(_ref) {
|
|
|
54
68
|
tabIndex: 0,
|
|
55
69
|
direction: "row",
|
|
56
70
|
fill: true,
|
|
57
|
-
pad:
|
|
58
|
-
// the data/guide lines
|
|
59
|
-
(pad == null ? void 0 : pad.horizontal) && halfPad[pad.horizontal] && {
|
|
60
|
-
horizontal: halfPad[pad.horizontal]
|
|
61
|
-
} || pad,
|
|
71
|
+
pad: pad,
|
|
62
72
|
justify: "between",
|
|
63
73
|
responsive: false,
|
|
64
74
|
onFocus: function onFocus() {},
|
|
@@ -1,47 +1,57 @@
|
|
|
1
|
-
var _excluded = ["values", "pad", "renderValue", "serie"];
|
|
1
|
+
var _excluded = ["values", "pad", "renderValue", "serie", "theme", "thickness"];
|
|
2
2
|
|
|
3
3
|
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); }
|
|
4
4
|
|
|
5
5
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
6
|
|
|
7
|
-
import React, { forwardRef } from 'react';
|
|
7
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
8
|
+
import { edgeToNum } from '../../utils';
|
|
8
9
|
import { Box } from '../Box';
|
|
9
10
|
var XAxis = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
10
11
|
var values = _ref.values,
|
|
11
|
-
|
|
12
|
+
padProp = _ref.pad,
|
|
12
13
|
renderValue = _ref.renderValue,
|
|
13
14
|
serie = _ref.serie,
|
|
15
|
+
theme = _ref.theme,
|
|
16
|
+
thickness = _ref.thickness,
|
|
14
17
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
15
18
|
|
|
16
|
-
//
|
|
17
|
-
//
|
|
19
|
+
// pad to the edge of the thickness, for when padding is more than half
|
|
20
|
+
// the thickness
|
|
21
|
+
var pad = useMemo(function () {
|
|
22
|
+
return {
|
|
23
|
+
start: edgeToNum(padProp.start || padProp.horizontal, theme) - edgeToNum(thickness, theme) / 2 + "px",
|
|
24
|
+
end: edgeToNum(padProp.end || padProp.horizontal, theme) - edgeToNum(thickness, theme) / 2 + "px"
|
|
25
|
+
};
|
|
26
|
+
}, [padProp, theme, thickness]); // When there are only labels at the end of the axis and there isn't
|
|
27
|
+
// much space for them, let them take as much space as they like
|
|
28
|
+
// flowing in from the edges.
|
|
29
|
+
// Otherwise, align their container to the
|
|
18
30
|
// data/guide lines and then let their content overflow that.
|
|
19
|
-
var itemProps = values.length === 2 ? {} : {
|
|
20
|
-
width: '1px',
|
|
21
|
-
overflow: 'visible',
|
|
22
|
-
align: 'center'
|
|
23
|
-
};
|
|
24
|
-
var horizontal = pad.horizontal,
|
|
25
|
-
start = pad.start,
|
|
26
|
-
end = pad.end; // ignore vertical parts
|
|
27
31
|
|
|
32
|
+
var labelContainerProps = useMemo(function () {
|
|
33
|
+
// 24px was chosen empirically as 48px is enough to show some simple text
|
|
34
|
+
var centered = values.length !== 2 || edgeToNum(padProp.start || padProp.horizontal, theme) >= 24;
|
|
35
|
+
if (centered) return {
|
|
36
|
+
width: thickness,
|
|
37
|
+
overflow: 'visible',
|
|
38
|
+
align: 'center'
|
|
39
|
+
};
|
|
40
|
+
return {};
|
|
41
|
+
}, [padProp, theme, thickness, values]);
|
|
28
42
|
return /*#__PURE__*/React.createElement(Box, _extends({
|
|
29
43
|
ref: ref,
|
|
30
44
|
gridArea: "xAxis",
|
|
31
45
|
direction: "row",
|
|
32
46
|
justify: "between",
|
|
33
|
-
pad:
|
|
34
|
-
horizontal: horizontal,
|
|
35
|
-
start: start,
|
|
36
|
-
end: end
|
|
37
|
-
}
|
|
47
|
+
pad: pad
|
|
38
48
|
}, rest), values.map(function (dataIndex, i) {
|
|
39
49
|
return (
|
|
40
50
|
/*#__PURE__*/
|
|
41
51
|
// eslint-disable-next-line react/no-array-index-key
|
|
42
52
|
React.createElement(Box, _extends({
|
|
43
53
|
key: i
|
|
44
|
-
},
|
|
54
|
+
}, labelContainerProps), serie ? renderValue(serie, dataIndex) : dataIndex)
|
|
45
55
|
);
|
|
46
56
|
}));
|
|
47
57
|
});
|