@redsift/charts 7.6.0 → 7.7.0-alpha.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/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { scaleOrdinal, select, axisBottom, scaleLinear, sum, pie, arc } from 'd3';
2
2
  import React, { forwardRef, useRef, useEffect, useId } from 'react';
3
3
  import styled, { css } from 'styled-components';
4
+ import { Text, Number as Number$1 } from '@redsift/design-system';
4
5
  import { Tooltip } from '@redsift/popovers';
5
6
 
6
7
  const ColorTheme = {
@@ -206,6 +207,301 @@ const HorizontalBarChartTooltipVariant = {
206
207
  percent: 'percent'
207
208
  };
208
209
 
210
+ var classnamesExports = {};
211
+ var classnames = {
212
+ get exports(){ return classnamesExports; },
213
+ set exports(v){ classnamesExports = v; },
214
+ };
215
+
216
+ /*!
217
+ Copyright (c) 2018 Jed Watson.
218
+ Licensed under the MIT License (MIT), see
219
+ http://jedwatson.github.io/classnames
220
+ */
221
+
222
+ (function (module) {
223
+ /* global define */
224
+
225
+ (function () {
226
+
227
+ var hasOwn = {}.hasOwnProperty;
228
+
229
+ function classNames() {
230
+ var classes = [];
231
+
232
+ for (var i = 0; i < arguments.length; i++) {
233
+ var arg = arguments[i];
234
+ if (!arg) continue;
235
+
236
+ var argType = typeof arg;
237
+
238
+ if (argType === 'string' || argType === 'number') {
239
+ classes.push(arg);
240
+ } else if (Array.isArray(arg)) {
241
+ if (arg.length) {
242
+ var inner = classNames.apply(null, arg);
243
+ if (inner) {
244
+ classes.push(inner);
245
+ }
246
+ }
247
+ } else if (argType === 'object') {
248
+ if (arg.toString === Object.prototype.toString) {
249
+ for (var key in arg) {
250
+ if (hasOwn.call(arg, key) && arg[key]) {
251
+ classes.push(key);
252
+ }
253
+ }
254
+ } else {
255
+ classes.push(arg.toString());
256
+ }
257
+ }
258
+ }
259
+
260
+ return classes.join(' ');
261
+ }
262
+
263
+ if (module.exports) {
264
+ classNames.default = classNames;
265
+ module.exports = classNames;
266
+ } else {
267
+ window.classNames = classNames;
268
+ }
269
+ }());
270
+ } (classnames));
271
+
272
+ var classNames = classnamesExports;
273
+
274
+ const baseLayout = css`
275
+ ${_ref => {
276
+ let {
277
+ flex,
278
+ flexGrow,
279
+ flexShrink,
280
+ flexBasis,
281
+ alignSelf,
282
+ justifySelf,
283
+ order,
284
+ gridArea,
285
+ gridColumn,
286
+ gridRow,
287
+ gridColumnStart,
288
+ gridColumnEnd,
289
+ gridRowStart,
290
+ gridRowEnd
291
+ } = _ref;
292
+ return css`
293
+ ${flex ? `flex: ${flex};` : ''}
294
+ ${flexGrow !== undefined ? `flex-grow: ${flexGrow};` : ''}
295
+ ${flexShrink !== undefined ? `flex-shrink: ${flexShrink};` : ''}
296
+ ${flexBasis ? `flex-basis: ${flexBasis};` : ''}
297
+ ${alignSelf ? `align-self: ${alignSelf};` : ''}
298
+ ${justifySelf ? `justify-self: ${justifySelf};` : ''}
299
+ ${order !== undefined ? `order: ${order};` : ''}
300
+ ${gridArea ? `grid-area: ${gridArea};` : ''}
301
+ ${gridColumn ? `grid-column: ${gridColumn};` : ''}
302
+ ${gridRow ? `grid-row: ${gridRow};` : ''}
303
+ ${gridColumnStart ? `grid-column-start: ${gridColumnStart};` : ''}
304
+ ${gridColumnEnd ? `grid-column-end: ${gridColumnEnd};` : ''}
305
+ ${gridRowStart ? `grid-row-start: ${gridRowStart};` : ''}
306
+ ${gridRowEnd ? `grid-row-end: ${gridRowEnd};` : ''}
307
+ `;
308
+ }}
309
+ `;
310
+ const baseSpacing = css`
311
+ ${_ref2 => {
312
+ let {
313
+ margin,
314
+ marginBottom,
315
+ marginLeft,
316
+ marginRight,
317
+ marginTop
318
+ } = _ref2;
319
+ return css`
320
+ ${margin ? `margin: ${margin};` : ''}
321
+ ${marginBottom ? `margin-bottom: ${marginBottom};` : ''}
322
+ ${marginLeft ? `margin-left: ${marginLeft};` : ''}
323
+ ${marginRight ? `margin-right: ${marginRight};` : ''}
324
+ ${marginTop ? `margin-top: ${marginTop};` : ''}
325
+ `;
326
+ }}
327
+ `;
328
+ const baseInternalSpacing = css`
329
+ ${_ref3 => {
330
+ let {
331
+ padding,
332
+ paddingBottom,
333
+ paddingLeft,
334
+ paddingRight,
335
+ paddingTop
336
+ } = _ref3;
337
+ return css`
338
+ ${padding ? `padding: ${padding};` : ''}
339
+ ${paddingBottom ? `padding-bottom: ${paddingBottom};` : ''}
340
+ ${paddingLeft ? `padding-left: ${paddingLeft};` : ''}
341
+ ${paddingRight ? `padding-right: ${paddingRight};` : ''}
342
+ ${paddingTop ? `padding-top: ${paddingTop};` : ''}
343
+ `;
344
+ }}
345
+ `;
346
+ const baseSizing = css`
347
+ ${_ref4 => {
348
+ let {
349
+ height,
350
+ maxHeight,
351
+ maxWidth,
352
+ minHeight,
353
+ minWidth,
354
+ width
355
+ } = _ref4;
356
+ return css`
357
+ ${height !== undefined ? `height: ${typeof height === 'number' ? `${height}px` : height};` : ''}
358
+ ${maxHeight ? `max-height: ${maxHeight};` : ''}
359
+ ${maxWidth ? `max-width: ${maxWidth};` : ''}
360
+ ${minHeight ? `min-height: ${minHeight};` : ''}
361
+ ${minWidth ? `min-width: ${minWidth};` : ''}
362
+ ${width !== undefined ? `width: ${typeof width === 'number' ? `${width}px` : width};` : ''}
363
+ `;
364
+ }}
365
+ `;
366
+ const basePositioning = css`
367
+ ${_ref5 => {
368
+ let {
369
+ position,
370
+ top,
371
+ bottom,
372
+ left,
373
+ right,
374
+ zIndex
375
+ } = _ref5;
376
+ return css`
377
+ ${position ? `position: ${position};` : ''}
378
+ ${top ? `top: ${top};` : ''}
379
+ ${bottom ? `bottom: ${bottom};` : ''}
380
+ ${left ? `left: ${left};` : ''}
381
+ ${right ? `right: ${right};` : ''}
382
+ ${zIndex ? `z-index: ${zIndex};` : ''}
383
+ `;
384
+ }}
385
+ `;
386
+ const baseFlexbox = css`
387
+ ${_ref6 => {
388
+ let {
389
+ alignContent,
390
+ alignItems,
391
+ flexDirection,
392
+ flexWrap,
393
+ gap,
394
+ justifyContent
395
+ } = _ref6;
396
+ return css`
397
+ ${alignContent ? `align-content: ${alignContent};` : ''}
398
+ ${alignItems ? `align-items: ${alignItems};` : ''}
399
+ ${flexDirection ? `flex-direction: ${flexDirection};` : ''}
400
+ ${flexWrap ? `flex-wrap: ${flexWrap};` : ''}
401
+ gap: ${gap};
402
+ ${justifyContent ? `justify-content: ${justifyContent};` : ''}
403
+ `;
404
+ }}
405
+ `;
406
+ const baseGrid = css`
407
+ ${_ref7 => {
408
+ let {
409
+ alignContent,
410
+ alignItems,
411
+ gap,
412
+ gridAutoColumns,
413
+ gridAutoRows,
414
+ gridTemplateAreas,
415
+ gridTemplateColumns,
416
+ gridTemplateRows,
417
+ justifyContent,
418
+ justifyItems
419
+ } = _ref7;
420
+ return css`
421
+ ${alignContent ? `align-content: ${alignContent};` : ''}
422
+ ${alignItems ? `align-items: ${alignItems};` : ''}
423
+ ${gap ? `gap: ${gap};` : ''}
424
+ ${gridAutoColumns ? `grid-auto-columns: ${gridAutoColumns};` : ''}
425
+ ${gridAutoRows ? `grid-auto-rows: ${gridAutoRows};` : ''}
426
+ ${gridTemplateAreas ? `grid-template-areas: ${gridTemplateAreas};` : ''}
427
+ ${gridTemplateColumns ? `grid-template-columns: ${gridTemplateColumns};` : ''}
428
+ ${gridTemplateRows ? `grid-template-rows: ${gridTemplateRows};` : ''}
429
+ ${justifyContent ? `justify-content: ${justifyContent};` : ''}
430
+ ${justifyItems ? `justify-items: ${justifyItems};` : ''}
431
+ `;
432
+ }}
433
+ `;
434
+ const baseStyling = css`
435
+ font-family: var(--redsift-typography-body-font-family);
436
+ font-size: var(--redsift-typography-body-font-size);
437
+ font-weight: var(--redsift-typography-body-font-weight);
438
+ line-height: var(--redsift-typography-body-line-height);
439
+ color: var(--redsift-color-neutral-black);
440
+
441
+ ${baseLayout}
442
+ ${baseSpacing}
443
+ ${baseSizing}
444
+ ${basePositioning}
445
+ `;
446
+ css`
447
+ ${_ref8 => {
448
+ let {
449
+ display
450
+ } = _ref8;
451
+ return display ? `display: ${display};` : '';
452
+ }}
453
+ font-family: var(--redsift-typography-body-font-family);
454
+ font-size: var(--redsift-typography-body-font-size);
455
+ font-weight: var(--redsift-typography-body-font-weight);
456
+ line-height: var(--redsift-typography-body-line-height);
457
+ color: var(--redsift-color-neutral-black);
458
+
459
+ ${baseInternalSpacing}
460
+ ${baseFlexbox}
461
+ ${baseGrid}
462
+ `;
463
+
464
+ /**
465
+ * Component style.
466
+ */
467
+ const StyledFlexbox = styled.div`
468
+ display: ${_ref => {
469
+ let {
470
+ inline
471
+ } = _ref;
472
+ return inline ? 'inline-flex' : 'flex';
473
+ }};
474
+
475
+ ${baseStyling}
476
+ ${baseInternalSpacing}
477
+ ${baseFlexbox}
478
+ `;
479
+
480
+ const _excluded$5 = ["children", "className"];
481
+ const COMPONENT_NAME$5 = 'Flexbox';
482
+ const CLASSNAME$5 = 'redsift-flex-box';
483
+ const DEFAULT_PROPS$5 = {
484
+ gap: '16px'
485
+ };
486
+
487
+ /**
488
+ * The Flexbox component.
489
+ */
490
+ const Flexbox = /*#__PURE__*/forwardRef((props, ref) => {
491
+ const {
492
+ children,
493
+ className
494
+ } = props,
495
+ forwardedProps = _objectWithoutProperties(props, _excluded$5);
496
+ return /*#__PURE__*/React.createElement(StyledFlexbox, _extends({}, forwardedProps, {
497
+ className: classNames(Flexbox.className, className),
498
+ ref: ref
499
+ }), children);
500
+ });
501
+ Flexbox.className = CLASSNAME$5;
502
+ Flexbox.defaultProps = DEFAULT_PROPS$5;
503
+ Flexbox.displayName = COMPONENT_NAME$5;
504
+
209
505
  /**
210
506
  * Component style.
211
507
  */
@@ -236,7 +532,7 @@ const StyledHorizontalBarChart = styled.div`
236
532
  }
237
533
  }
238
534
  `;
239
- const StyledHorizontalBarChartTitle = styled.div`
535
+ const StyledHorizontalBarChartTitle = styled(Flexbox)`
240
536
  font-family: var(--redsift-typography-h4-font-family);
241
537
  font-size: var(--redsift-typography-h4-font-size);
242
538
  font-weight: var(--redsift-typography-h4-font-weight);
@@ -382,10 +678,24 @@ const HorizontalBarChartBar = /*#__PURE__*/forwardRef((props, ref) => {
382
678
  "aria-hidden": true
383
679
  }, data.name), !showTooltip && !isEmpty && /*#__PURE__*/React.createElement("title", null, `${data.name}: ${data.value}`));
384
680
  if (showTooltip) {
385
- const tooltipValue = tooltipPercent !== null ? `${tooltipPercent}%` : data.value;
386
681
  return /*#__PURE__*/React.createElement(Tooltip, {
387
682
  placement: "right"
388
- }, /*#__PURE__*/React.createElement(Tooltip.Trigger, null, Bar), /*#__PURE__*/React.createElement(Tooltip.Content, null, `${data.name}${tooltipLabelOnly ? '' : ` - ${tooltipValue}`}`));
683
+ }, /*#__PURE__*/React.createElement(Tooltip.Trigger, null, Bar), /*#__PURE__*/React.createElement(Tooltip.Content, null, tooltipLabelOnly ? /*#__PURE__*/React.createElement(Text, {
684
+ variant: "caption"
685
+ }, data.name) : tooltipPercent !== null ? /*#__PURE__*/React.createElement(Text, {
686
+ variant: "caption"
687
+ }, data.name, " -", ' ', /*#__PURE__*/React.createElement(Number$1, {
688
+ value: tooltipPercent,
689
+ type: "percent",
690
+ variant: "caption",
691
+ maximumFractionDigits: 2
692
+ })) : /*#__PURE__*/React.createElement(Text, {
693
+ variant: "caption"
694
+ }, data.name, " -", ' ', /*#__PURE__*/React.createElement(Number$1, {
695
+ value: data.value,
696
+ variant: "caption",
697
+ maximumFractionDigits: 2
698
+ }))));
389
699
  }
390
700
  return Bar;
391
701
  });
@@ -549,6 +859,7 @@ const HorizontalBarChart = /*#__PURE__*/forwardRef((props, ref) => {
549
859
  className: className
550
860
  }), title ? /*#__PURE__*/React.createElement(StyledHorizontalBarChartTitle, {
551
861
  className: `${HorizontalBarChart.className}__title`,
862
+ alignItems: "center",
552
863
  id: `id${id}__title`
553
864
  }, title) : null, /*#__PURE__*/React.createElement("div", {
554
865
  className: `${HorizontalBarChart.className}__container`
@@ -574,7 +885,7 @@ const HorizontalBarChart = /*#__PURE__*/forwardRef((props, ref) => {
574
885
  value,
575
886
  name
576
887
  } = _ref2;
577
- const percent = (value / total * 100).toFixed(2);
888
+ const percent = value / total;
578
889
  return /*#__PURE__*/React.createElement(HorizontalBarChartBar, {
579
890
  chartId: id,
580
891
  color: d3colors(name),
@@ -668,7 +979,7 @@ const StyledPieChart = styled.div`
668
979
  display: block;
669
980
  }
670
981
  `;
671
- const StyledPieChartTitle = styled.div`
982
+ const StyledPieChartTitle = styled(Flexbox)`
672
983
  font-family: var(--redsift-typography-h4-font-family);
673
984
  font-size: var(--redsift-typography-h4-font-size);
674
985
  font-weight: var(--redsift-typography-h4-font-weight);
@@ -823,8 +1134,6 @@ const StyledPieChartLabel = styled.li`
823
1134
  gap: 8px;
824
1135
  width: 100%;
825
1136
  max-width: 262px;
826
- font-family: var(--redsift-typography-font-family-raleway);
827
- font-weight: var(--redsift-typography-font-weight-regular);
828
1137
  font-size: var(--redsift-typography-caption-font-size);
829
1138
 
830
1139
  > div {
@@ -838,12 +1147,6 @@ const StyledPieChartLabel = styled.li`
838
1147
  return $color;
839
1148
  }};
840
1149
  }
841
-
842
- > b {
843
- font-family: var(--redsift-typography-font-family-source-code-pro);
844
- font-weight: var(--redsift-typography-font-weight-bold);
845
- font-size: var(--redsift-typography-caption-font-size);
846
- }
847
1150
  `;
848
1151
  const StyledPieChartArc = styled.g`
849
1152
  ${_ref15 => {
@@ -930,10 +1233,24 @@ const PieChartArc = /*#__PURE__*/forwardRef((props, ref) => {
930
1233
  id: `id${chartId}__slice-${index}-title`
931
1234
  }, `${data.name}: ${data.value}`) : null);
932
1235
  if (showTooltip) {
933
- const tooltipValue = tooltipPercent !== null ? `${tooltipPercent}%` : data.value;
934
1236
  return /*#__PURE__*/React.createElement(Tooltip, {
935
1237
  placement: "right"
936
- }, /*#__PURE__*/React.createElement(Tooltip.Trigger, null, Arc), /*#__PURE__*/React.createElement(Tooltip.Content, null, `${data.name}${tooltipLabelOnly ? '' : ` - ${tooltipValue}`}`));
1238
+ }, /*#__PURE__*/React.createElement(Tooltip.Trigger, null, Arc), /*#__PURE__*/React.createElement(Tooltip.Content, null, tooltipLabelOnly ? /*#__PURE__*/React.createElement(Text, {
1239
+ variant: "caption"
1240
+ }, data.name) : tooltipPercent !== null ? /*#__PURE__*/React.createElement(Text, {
1241
+ variant: "caption"
1242
+ }, data.name, " -", ' ', /*#__PURE__*/React.createElement(Number$1, {
1243
+ maximumFractionDigits: 2,
1244
+ type: "percent",
1245
+ value: tooltipPercent,
1246
+ variant: "caption"
1247
+ })) : /*#__PURE__*/React.createElement(Text, {
1248
+ variant: "caption"
1249
+ }, data.name, " -", ' ', /*#__PURE__*/React.createElement(Number$1, {
1250
+ maximumFractionDigits: 2,
1251
+ value: data.value,
1252
+ variant: "caption"
1253
+ }))));
937
1254
  }
938
1255
  return Arc;
939
1256
  });
@@ -1084,6 +1401,7 @@ const PieChart = /*#__PURE__*/forwardRef((props, ref) => {
1084
1401
  className: className
1085
1402
  }), title ? /*#__PURE__*/React.createElement(StyledPieChartTitle, {
1086
1403
  className: `${PieChart.className}__title`,
1404
+ alignItems: "center",
1087
1405
  id: `id${id}__title`
1088
1406
  }, title) : null, /*#__PURE__*/React.createElement("div", {
1089
1407
  className: `${PieChart.className}__container`
@@ -1107,7 +1425,7 @@ const PieChart = /*#__PURE__*/forwardRef((props, ref) => {
1107
1425
  }, /*#__PURE__*/React.createElement("g", {
1108
1426
  className: "pie-slice-group"
1109
1427
  }, pieData.map((datum, index) => {
1110
- const percent = (datum.data.value / total * 100).toFixed(2);
1428
+ const percent = datum.data.value / total;
1111
1429
  return /*#__PURE__*/React.createElement(PieChartArc, {
1112
1430
  chartId: id,
1113
1431
  color: d3colors(datum.data.name),
@@ -1141,7 +1459,24 @@ const PieChart = /*#__PURE__*/forwardRef((props, ref) => {
1141
1459
  return /*#__PURE__*/React.createElement(StyledPieChartLabel, {
1142
1460
  key: `pie-external-label _${index}`,
1143
1461
  $color: d3colors(name)
1144
- }, /*#__PURE__*/React.createElement("div", null), labelVariant === PieChartLabelVariant.externalLabelValue ? /*#__PURE__*/React.createElement("b", null, value) : labelVariant === PieChartLabelVariant.externalLabelPercent ? /*#__PURE__*/React.createElement("b", null, `${(value * 100 / total).toFixed(2)}%`) : null, /*#__PURE__*/React.createElement("span", null, name));
1462
+ }, /*#__PURE__*/React.createElement("div", null), labelVariant === PieChartLabelVariant.externalLabelValue ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Number$1, {
1463
+ as: "b",
1464
+ maximumFractionDigits: 2,
1465
+ value: value,
1466
+ variant: "inherit"
1467
+ }), /*#__PURE__*/React.createElement(Text, {
1468
+ variant: "caption"
1469
+ }, name)) : labelVariant === PieChartLabelVariant.externalLabelPercent ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Number$1, {
1470
+ as: "b",
1471
+ maximumFractionDigits: 2,
1472
+ type: "percent",
1473
+ value: value / total,
1474
+ variant: "inherit"
1475
+ }), /*#__PURE__*/React.createElement(Text, {
1476
+ variant: "caption"
1477
+ }, name)) : /*#__PURE__*/React.createElement(Text, {
1478
+ variant: "caption"
1479
+ }, name));
1145
1480
  })) : null), caption ? /*#__PURE__*/React.createElement(StyledPieChartCaption, {
1146
1481
  className: `${PieChart.className}__caption`
1147
1482
  }, caption) : null);