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