dce-reactkit 1.0.20 → 2.0.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.
Files changed (205) hide show
  1. package/.eslintrc.js +95 -0
  2. package/lib/components/LoadingSpinner.d.ts +7 -0
  3. package/lib/components/LoadingSpinner.js +39 -0
  4. package/lib/components/LoadingSpinner.js.map +1 -0
  5. package/lib/components/Modal.d.ts +69 -0
  6. package/lib/components/Modal.js +311 -0
  7. package/lib/components/Modal.js.map +1 -0
  8. package/lib/helpers/abbreviate.d.ts +9 -0
  9. package/lib/helpers/abbreviate.js +21 -0
  10. package/lib/helpers/abbreviate.js.map +1 -0
  11. package/lib/helpers/avg.d.ts +8 -0
  12. package/lib/helpers/avg.js +24 -0
  13. package/lib/helpers/avg.js.map +1 -0
  14. package/lib/helpers/ceilToNumDecimals.d.ts +9 -0
  15. package/lib/helpers/ceilToNumDecimals.js +15 -0
  16. package/lib/helpers/ceilToNumDecimals.js.map +1 -0
  17. package/lib/helpers/floorToNumDecimals.d.ts +9 -0
  18. package/lib/helpers/floorToNumDecimals.js +15 -0
  19. package/lib/helpers/floorToNumDecimals.js.map +1 -0
  20. package/lib/helpers/forceNumIntoBounds.d.ts +10 -0
  21. package/lib/helpers/forceNumIntoBounds.js +15 -0
  22. package/lib/helpers/forceNumIntoBounds.js.map +1 -0
  23. package/lib/helpers/padDecimalZeros.d.ts +10 -0
  24. package/lib/helpers/padDecimalZeros.js +30 -0
  25. package/lib/helpers/padDecimalZeros.js.map +1 -0
  26. package/lib/helpers/padZerosLeft.d.ts +9 -0
  27. package/lib/helpers/padZerosLeft.js +21 -0
  28. package/lib/helpers/padZerosLeft.js.map +1 -0
  29. package/lib/helpers/roundToNumDecimals.d.ts +9 -0
  30. package/lib/helpers/roundToNumDecimals.js +15 -0
  31. package/lib/helpers/roundToNumDecimals.js.map +1 -0
  32. package/lib/helpers/sum.d.ts +8 -0
  33. package/lib/helpers/sum.js +15 -0
  34. package/lib/helpers/sum.js.map +1 -0
  35. package/lib/helpers/waitMs.d.ts +7 -0
  36. package/lib/helpers/waitMs.js +55 -0
  37. package/lib/helpers/waitMs.js.map +1 -0
  38. package/lib/types/Variant.d.ts +15 -0
  39. package/lib/types/Variant.js +19 -0
  40. package/lib/types/Variant.js.map +1 -0
  41. package/package.json +22 -40
  42. package/src/components/LoadingSpinner.scss +50 -0
  43. package/src/components/LoadingSpinner.tsx +50 -0
  44. package/src/components/Modal.scss +48 -0
  45. package/src/components/Modal.tsx +391 -0
  46. package/src/helpers/abbreviate.tsx +23 -0
  47. package/src/helpers/avg.tsx +22 -0
  48. package/src/helpers/ceilToNumDecimals.tsx +13 -0
  49. package/src/helpers/floorToNumDecimals.tsx +13 -0
  50. package/src/helpers/forceNumIntoBounds.tsx +19 -0
  51. package/src/helpers/padDecimalZeros.tsx +32 -0
  52. package/src/helpers/padZerosLeft.tsx +21 -0
  53. package/src/helpers/roundToNumDecimals.tsx +13 -0
  54. package/src/helpers/sum.tsx +16 -0
  55. package/src/helpers/waitMs.tsx +12 -0
  56. package/src/types/Variant.tsx +16 -0
  57. package/tsconfig.json +24 -0
  58. package/index.js +0 -1
  59. package/lib/Bar.js +0 -169
  60. package/lib/Donut.js +0 -145
  61. package/lib/DownloadButton.js +0 -81
  62. package/lib/Histogram.js +0 -193
  63. package/lib/Scatter.js +0 -162
  64. package/lib/StackedBar.js +0 -243
  65. package/lib/common/chart/Holder/index.js +0 -182
  66. package/lib/common/chart/Holder/style.css +0 -41
  67. package/lib/common/chart/colors.js +0 -12
  68. package/lib/common/csvToString.js +0 -23
  69. package/lib/common/isFloat.js +0 -14
  70. package/lib/common/isInteger.js +0 -24
  71. package/lib/common/math.js +0 -21
  72. package/lib/common/validators.js +0 -18
  73. package/lib/glyph/Adjust.js +0 -13
  74. package/lib/glyph/Angle.js +0 -44
  75. package/lib/glyph/Archive.js +0 -13
  76. package/lib/glyph/Arrow.js +0 -49
  77. package/lib/glyph/ArrowsHorizontal.js +0 -13
  78. package/lib/glyph/ArrowsVertical.js +0 -13
  79. package/lib/glyph/Award.js +0 -13
  80. package/lib/glyph/Ban.js +0 -13
  81. package/lib/glyph/Barcode.js +0 -13
  82. package/lib/glyph/Bed.js +0 -13
  83. package/lib/glyph/Bell.js +0 -35
  84. package/lib/glyph/Bolt.js +0 -13
  85. package/lib/glyph/Bookmark.js +0 -37
  86. package/lib/glyph/Bug.js +0 -13
  87. package/lib/glyph/Calendar.js +0 -13
  88. package/lib/glyph/Check.js +0 -36
  89. package/lib/glyph/Checkbox.js +0 -40
  90. package/lib/glyph/Chevron.js +0 -63
  91. package/lib/glyph/Circle.js +0 -15
  92. package/lib/glyph/Cog.js +0 -13
  93. package/lib/glyph/DoubleAngle.js +0 -45
  94. package/lib/glyph/Download.js +0 -13
  95. package/lib/glyph/Ellipsis.js +0 -36
  96. package/lib/glyph/Envelope.js +0 -13
  97. package/lib/glyph/File.js +0 -37
  98. package/lib/glyph/IdCard.js +0 -13
  99. package/lib/glyph/Menu.js +0 -13
  100. package/lib/glyph/Minus.js +0 -13
  101. package/lib/glyph/Move.js +0 -13
  102. package/lib/glyph/Plus.js +0 -13
  103. package/lib/glyph/Square.js +0 -47
  104. package/lib/glyph/Teacher.js +0 -13
  105. package/lib/glyph/TextAlign.js +0 -53
  106. package/lib/glyph/Times.js +0 -36
  107. package/lib/glyph/WarningTriangle.js +0 -13
  108. package/lib/index.js +0 -1
  109. package/src-old/common/csvToString.js +0 -5
  110. package/src-old/common/isFloat.js +0 -3
  111. package/src-old/common/isInteger.js +0 -14
  112. package/src-old/common/math.js +0 -16
  113. package/src-old/common/validators.js +0 -14
  114. package/src-old/components/Alert.js +0 -79
  115. package/src-old/components/Button.js +0 -64
  116. package/src-old/components/CSV/autoMatch.js +0 -174
  117. package/src-old/components/CSV/getNumCols.js +0 -15
  118. package/src-old/components/CSV/index.js +0 -743
  119. package/src-old/components/Card.js +0 -64
  120. package/src-old/components/Chart/Bar.js +0 -169
  121. package/src-old/components/Chart/Donut.js +0 -160
  122. package/src-old/components/Chart/Histogram.js +0 -189
  123. package/src-old/components/Chart/Scatter.js +0 -162
  124. package/src-old/components/Chart/colors.js +0 -20
  125. package/src-old/components/Checkbox/index.js +0 -106
  126. package/src-old/components/Checkbox/style.css +0 -11
  127. package/src-old/components/DatePicker.js +0 -59
  128. package/src-old/components/DownloadButton.js +0 -72
  129. package/src-old/components/Dropdown.js +0 -120
  130. package/src-old/components/Layout/LeftAddon.js +0 -63
  131. package/src-old/components/Layout/RightAddon.js +0 -64
  132. package/src-old/components/Layout/TwoCol.js +0 -67
  133. package/src-old/components/Modal.js +0 -161
  134. package/src-old/components/PhotoRoster.js +0 -152
  135. package/src-old/components/Pills.js +0 -117
  136. package/src-old/components/Radio.js +0 -94
  137. package/src-old/components/Splash/Error.js +0 -62
  138. package/src-old/components/Splash/Load/index.js +0 -32
  139. package/src-old/components/Splash/Load/style.css +0 -51
  140. package/src-old/components/Stat/General.js +0 -252
  141. package/src-old/components/Stat/helpers/calcAverage.js +0 -20
  142. package/src-old/components/Stat/helpers/calcExtremes.js +0 -27
  143. package/src-old/components/Stat/helpers/calcMedian.js +0 -32
  144. package/src-old/components/Stat/helpers/calcStdDev.js +0 -30
  145. package/src-old/components/Stat/helpers/calcSum.js +0 -8
  146. package/src-old/components/UserProfile/index.js +0 -151
  147. package/src-old/components/UserProfile/style.css +0 -33
  148. package/src-old/components/Well.js +0 -28
  149. package/src-old/components/Wizard/Question/CSV.js +0 -307
  150. package/src-old/components/Wizard/Question/Chooser/Assignment.js +0 -108
  151. package/src-old/components/Wizard/Question/Chooser/Course.js +0 -214
  152. package/src-old/components/Wizard/Question/Chooser/helpers/divideIntoSections.js +0 -16
  153. package/src-old/components/Wizard/Question/Chooser/helpers/genGetItemsPromise.js +0 -20
  154. package/src-old/components/Wizard/Question/Chooser/helpers/preprocessSections.js +0 -36
  155. package/src-old/components/Wizard/Question/Chooser/index.js +0 -306
  156. package/src-old/components/Wizard/Question/Form/Field/CheckableItem.js +0 -155
  157. package/src-old/components/Wizard/Question/Form/Field/Input.js +0 -149
  158. package/src-old/components/Wizard/Question/Form/Field/NumberItem.js +0 -374
  159. package/src-old/components/Wizard/Question/Form/Field/index.js +0 -34
  160. package/src-old/components/Wizard/Question/Form/Field/readme.md +0 -7
  161. package/src-old/components/Wizard/Question/Form/index.js +0 -175
  162. package/src-old/components/Wizard/Question/Form/style.css +0 -3
  163. package/src-old/components/Wizard/Question/OneButton.js +0 -80
  164. package/src-old/components/Wizard/Question/index.js +0 -46
  165. package/src-old/components/Wizard/Question/readme.md +0 -10
  166. package/src-old/components/Wizard/QuestionGroup/AnswerAll.js +0 -126
  167. package/src-old/components/Wizard/QuestionGroup/AnswerAny.js +0 -60
  168. package/src-old/components/Wizard/index.js +0 -233
  169. package/src-old/components/Wizard/style.css +0 -21
  170. package/src-old/glyphs/Adjust.js +0 -13
  171. package/src-old/glyphs/Angle.js +0 -57
  172. package/src-old/glyphs/Archive.js +0 -13
  173. package/src-old/glyphs/Arrow.js +0 -85
  174. package/src-old/glyphs/ArrowsHorizontal.js +0 -13
  175. package/src-old/glyphs/ArrowsVertical.js +0 -13
  176. package/src-old/glyphs/Award.js +0 -13
  177. package/src-old/glyphs/Ban.js +0 -13
  178. package/src-old/glyphs/Barcode.js +0 -13
  179. package/src-old/glyphs/Bed.js +0 -13
  180. package/src-old/glyphs/Bell.js +0 -34
  181. package/src-old/glyphs/Bolt.js +0 -13
  182. package/src-old/glyphs/Bookmark.js +0 -36
  183. package/src-old/glyphs/Bug.js +0 -13
  184. package/src-old/glyphs/Calendar.js +0 -13
  185. package/src-old/glyphs/Check.js +0 -34
  186. package/src-old/glyphs/Checkbox.js +0 -42
  187. package/src-old/glyphs/Chevron.js +0 -88
  188. package/src-old/glyphs/Circle.js +0 -16
  189. package/src-old/glyphs/Cog.js +0 -13
  190. package/src-old/glyphs/DoubleAngle.js +0 -58
  191. package/src-old/glyphs/Download.js +0 -13
  192. package/src-old/glyphs/Ellipsis.js +0 -35
  193. package/src-old/glyphs/Envelope.js +0 -13
  194. package/src-old/glyphs/File.js +0 -40
  195. package/src-old/glyphs/IdCard.js +0 -13
  196. package/src-old/glyphs/Menu.js +0 -13
  197. package/src-old/glyphs/Minus.js +0 -13
  198. package/src-old/glyphs/Move.js +0 -13
  199. package/src-old/glyphs/Plus.js +0 -13
  200. package/src-old/glyphs/Square.js +0 -48
  201. package/src-old/glyphs/Teacher.js +0 -13
  202. package/src-old/glyphs/TextAlign.js +0 -58
  203. package/src-old/glyphs/Times.js +0 -34
  204. package/src-old/glyphs/WarningTriangle.js +0 -13
  205. package/src-old/index.js +0 -1
@@ -1,64 +0,0 @@
1
- import React, { Component } from 'react';
2
- import PropTypes from 'prop-types';
3
-
4
- // Import bootstrap components
5
- import {
6
- Card as BootstrapCard,
7
- CardHeader,
8
- CardBody,
9
- CardTitle,
10
- CardSubtitle,
11
- } from 'reactstrap';
12
- // Import bootstrap stylesheet
13
- import 'bootstrap/dist/css/bootstrap.min.css';
14
-
15
- class Card extends Component {
16
- render() {
17
- // Extract properties
18
- const {
19
- title,
20
- subtitle,
21
- children,
22
- ...props
23
- } = this.props;
24
-
25
- return (
26
- <BootstrapCard {...props}>
27
- {title && (
28
- <CardHeader>
29
- <CardTitle className="mb-0">
30
- {title}
31
- </CardTitle>
32
- {subtitle && (
33
- <CardSubtitle className="mt-1">
34
- {subtitle}
35
- </CardSubtitle>
36
- )}
37
- </CardHeader>
38
- )}
39
- <CardBody>
40
- {children}
41
- </CardBody>
42
- </BootstrapCard>
43
- );
44
- }
45
- }
46
-
47
- Card.propTypes = {
48
- /* The title of the card */
49
- title: PropTypes.string,
50
- /* The subtitle of the card */
51
- subtitle: PropTypes.string,
52
- /* Children/body of the card */
53
- children: PropTypes.oneOfType([
54
- PropTypes.arrayOf(PropTypes.node),
55
- PropTypes.node,
56
- ]).isRequired,
57
- };
58
-
59
- Card.defaultProps = {
60
- title: null,
61
- subtitle: null,
62
- };
63
-
64
- export default Card;
@@ -1,169 +0,0 @@
1
- import React, { Component } from 'react';
2
- import PropTypes from 'prop-types';
3
-
4
- // Import rechart components
5
- import {
6
- ResponsiveContainer,
7
- BarChart as BarChartRechart,
8
- Bar,
9
- XAxis,
10
- YAxis,
11
- CartesianGrid,
12
- Tooltip,
13
- Legend,
14
- } from 'recharts';
15
-
16
- // Import other components
17
- import Holder from './Holder';
18
-
19
- // Import default colors
20
- import colors from './colors';
21
-
22
- // Import helpers
23
- import csvToString from '../../common/csvToString';
24
-
25
- class BarChart extends Component {
26
- render() {
27
- // Deconstruct props
28
- const {
29
- title,
30
- color,
31
- width,
32
- height,
33
- nameLabel,
34
- nameUnit,
35
- valueLabel,
36
- valueUnit,
37
- data,
38
- horizontal,
39
- noTooltipOnHover,
40
- noDownload,
41
- showLegend,
42
- } = this.props;
43
-
44
- let { csvContents } = this.props;
45
- if (!noDownload && !csvContents) {
46
- const nameField = `${nameLabel}${nameUnit ? ' (' + nameUnit + ')' : ''}`;
47
- const valueField = `${valueLabel}${valueUnit ? ' (' + valueUnit + ')' : ''}`;
48
- const csv = {
49
- fields: [nameField, valueField],
50
- data: data.map((datum) => {
51
- return [datum.name, datum.value];
52
- }),
53
- };
54
- csvContents = csvToString(csv);
55
- }
56
-
57
- return (
58
- <Holder
59
- title={title}
60
- width={width}
61
- height={height}
62
- xLabel={horizontal ? valueLabel : nameLabel}
63
- xUnit={horizontal ? valueUnit : nameUnit}
64
- yLabel={horizontal ? nameLabel : valueLabel}
65
- yUnit={horizontal ? nameUnit : valueUnit}
66
- csvContents={csvContents}
67
- >
68
- <ResponsiveContainer
69
- width="100%"
70
- height="100%"
71
- >
72
- <BarChartRechart
73
- data={data.map((datum) => {
74
- return {
75
- name: datum.name,
76
- [valueLabel]: datum.value,
77
- };
78
- })}
79
- layout={horizontal ? 'vertical' : 'horizontal'}
80
- >
81
- <CartesianGrid strokeDasharray="3 3" />
82
- <XAxis
83
- type={horizontal ? 'number' : 'category'}
84
- dataKey={horizontal ? null : 'name'}
85
- />
86
- <YAxis
87
- type={horizontal ? 'category' : 'number'}
88
- dataKey={horizontal ? 'name' : null}
89
- />
90
- {!noTooltipOnHover && (
91
- <Tooltip />
92
- )}
93
- {showLegend && (
94
- <Legend />
95
- )}
96
- <Bar dataKey={valueLabel} fill={color} />
97
- </BarChartRechart>
98
- </ResponsiveContainer>
99
- </Holder>
100
- );
101
- }
102
- }
103
-
104
- BarChart.propTypes = {
105
- // Title of the chart
106
- title: PropTypes.string,
107
- // Default CSS color (#123456 or 'white') for bars (can be overridden)
108
- color: PropTypes.string,
109
- // Width ('100%' or 50)
110
- width: PropTypes.oneOfType([
111
- PropTypes.string,
112
- PropTypes.number,
113
- ]),
114
- // Height ('100%' or 50)
115
- height: PropTypes.oneOfType([
116
- PropTypes.string,
117
- PropTypes.number,
118
- ]),
119
- // Label for the name axis
120
- nameLabel: PropTypes.string,
121
- // Unit for the name axis
122
- nameUnit: PropTypes.string,
123
- // Label for the value axis
124
- valueLabel: PropTypes.string,
125
- // Unit for the value axis
126
- valueUnit: PropTypes.string,
127
- // The data/bars
128
- data: PropTypes.arrayOf(
129
- PropTypes.shape({
130
- // Name of the bar
131
- name: PropTypes.oneOfType([
132
- PropTypes.string,
133
- PropTypes.number,
134
- ]).isRequired,
135
- // Value of the slice (size)
136
- value: PropTypes.number.isRequired,
137
- // Color of the slice (overrides props.color)
138
- color: PropTypes.string,
139
- })
140
- ).isRequired,
141
- // If true, bar chart is a horizontal bar chart
142
- horizontal: PropTypes.bool,
143
- // If true, no tooltip is shown on hover
144
- noTooltipOnHover: PropTypes.bool,
145
- // If true, legend is included
146
- showLegend: PropTypes.bool,
147
- // If true, no download button is shown
148
- noDownload: PropTypes.bool,
149
- // The contents of the csv file to download (auto-generated if not included)
150
- csvContents: PropTypes.string,
151
- };
152
-
153
- BarChart.defaultProps = {
154
- title: null,
155
- color: colors.defaultBlue,
156
- width: '100%',
157
- height: '500px',
158
- nameLabel: 'Name',
159
- nameUnit: null,
160
- valueLabel: 'Value',
161
- valueUnit: null,
162
- horizontal: false,
163
- noTooltipOnHover: false,
164
- showLegend: false,
165
- noDownload: false,
166
- csvContents: null,
167
- };
168
-
169
- export default BarChart;
@@ -1,160 +0,0 @@
1
- import React, { Component } from 'react';
2
- import PropTypes from 'prop-types';
3
- import genUUID from 'uuid/v1';
4
-
5
- // Import rechart components
6
- import {
7
- ResponsiveContainer,
8
- PieChart,
9
- Pie,
10
- Cell,
11
- Legend,
12
- Tooltip,
13
- } from 'recharts';
14
-
15
- // Import other components
16
- import Holder from './Holder';
17
-
18
- // Import default colors
19
- import colors from './colors';
20
-
21
- // Import helpers
22
- import csvToString from '../../common/csvToString';
23
-
24
- class DonutChart extends Component {
25
- render() {
26
- // Deconstruct props
27
- const {
28
- title,
29
- color,
30
- width,
31
- height,
32
- data,
33
- noTooltipOnHover,
34
- noDownload,
35
- showLegend,
36
- } = this.props;
37
-
38
- let csvContents;
39
- if (!noDownload) {
40
- const csv = {
41
- fields: ['Name', 'Value'],
42
- data: data.map((datum) => {
43
- return [datum.name, datum.value];
44
- }),
45
- };
46
- csvContents = csvToString(csv);
47
- }
48
-
49
- return (
50
- <Holder
51
- title={title}
52
- width={width}
53
- height={height}
54
- csvContents={csvContents}
55
- >
56
- <ResponsiveContainer
57
- width="100%"
58
- height="100%"
59
- >
60
- <PieChart>
61
- {showLegend && (
62
- <Legend />
63
- )}
64
- <Pie
65
- data={data}
66
- dataKey="value"
67
- innerRadius="60%"
68
- outerRadius="100%"
69
- fill={color}
70
- >
71
- {
72
- data.map((item, index) => {
73
- let itemColor = (
74
- item.color
75
- ? item.color
76
- : color
77
- );
78
- if (itemColor === 'assortment') {
79
- itemColor = colors.assortment[
80
- index % colors.assortment.length
81
- ];
82
- // Don't let two adjacent slices have the same color
83
- if (
84
- (data.length - 1) % colors.assortment.length === 0
85
- && index === data.length - 1
86
- ) {
87
- itemColor = colors.assortment[
88
- (index + Math.floor(colors.assortment.length / 2))
89
- % colors.assortment.length
90
- ];
91
- }
92
- }
93
- return (
94
- <Cell
95
- key={genUUID()}
96
- fill={itemColor}
97
- />
98
- );
99
- })
100
- }
101
- </Pie>
102
- {!noTooltipOnHover && (
103
- <Tooltip />
104
- )}
105
- </PieChart>
106
- </ResponsiveContainer>
107
- </Holder>
108
- );
109
- }
110
- }
111
-
112
- DonutChart.propTypes = {
113
- // Title of the chart
114
- title: PropTypes.string,
115
- // Default CSS color (#123456 or 'white') for slices (can be overridden)
116
- // OR 'assortment' for random colors
117
- color: PropTypes.string,
118
- // Width ('100%' or 50)
119
- width: PropTypes.oneOfType([
120
- PropTypes.string,
121
- PropTypes.number,
122
- ]),
123
- // Height ('100%' or 50)
124
- height: PropTypes.oneOfType([
125
- PropTypes.string,
126
- PropTypes.number,
127
- ]),
128
- // The data/slices
129
- data: PropTypes.arrayOf(
130
- PropTypes.shape({
131
- // Name of the slice
132
- name: PropTypes.oneOfType([
133
- PropTypes.string,
134
- PropTypes.number,
135
- ]).isRequired,
136
- // Value of the slice (size)
137
- value: PropTypes.number.isRequired,
138
- // Color of the slice (overrides props.color)
139
- color: PropTypes.string,
140
- })
141
- ).isRequired,
142
- // If true, no tooltip is shown on hover
143
- noTooltipOnHover: PropTypes.bool,
144
- // If true, legend is included
145
- showLegend: PropTypes.bool,
146
- // If true, no download button is shown
147
- noDownload: PropTypes.bool,
148
- };
149
-
150
- DonutChart.defaultProps = {
151
- title: null,
152
- color: 'assortment',
153
- width: '100%',
154
- height: '500px',
155
- noTooltipOnHover: false,
156
- showLegend: false,
157
- noDownload: false,
158
- };
159
-
160
- export default DonutChart;
@@ -1,189 +0,0 @@
1
- import React, { Component } from 'react';
2
- import PropTypes from 'prop-types';
3
-
4
- // Import other components
5
- import BarChart from './Bar';
6
-
7
- // Import default colors
8
- import colors from './colors';
9
-
10
- // Import helpers
11
- import csvToString from '../../common/csvToString';
12
-
13
- class Histogram extends Component {
14
- render() {
15
- // Deconstruct props
16
- const {
17
- title,
18
- color,
19
- width,
20
- height,
21
- startValue,
22
- numBuckets,
23
- numDecimals,
24
- bucketLabel,
25
- bucketUnit,
26
- valueLabel,
27
- valueUnit,
28
- data,
29
- noTooltipOnHover,
30
- noDownload,
31
- showLegend,
32
- } = this.props;
33
-
34
- // Choose end value (if none included, use largest value)
35
- let { endValue } = this.props;
36
- if (endValue === undefined || endValue === null) {
37
- endValue = Math.max(...data);
38
- }
39
-
40
- // Divide data into buckets
41
- const buckets = [];
42
- const epsilon = (
43
- numDecimals === 0
44
- ? 1
45
- : parseFloat(`0.${'0'.repeat(numDecimals - 1)}1`)
46
- );
47
- const bucketWidth = (endValue - startValue) / numBuckets;
48
- for (let i = 0; i < numBuckets; i++) {
49
- const bucketStart = startValue + bucketWidth * i;
50
- const bucketEnd = startValue + bucketWidth * (i + 1);
51
-
52
- // Generate start/end labels for the bucket
53
- const lastBucket = (i === numBuckets - 1);
54
- let bucketStartName = bucketStart.toFixed(numDecimals);
55
- if (bucketStartName === '0.0') {
56
- bucketStartName = '0';
57
- } else if (bucketStartName.startsWith('0.')) {
58
- bucketStartName = bucketStartName.substring(1);
59
- }
60
- let bucketEndName = (
61
- lastBucket
62
- ? bucketEnd.toFixed(numDecimals)
63
- : (
64
- (parseFloat(bucketEnd.toFixed(numDecimals)) - epsilon)
65
- .toFixed(numDecimals)
66
- )
67
- );
68
- if (bucketEndName === '0.0') {
69
- bucketEndName = '0';
70
- } else if (bucketEndName.startsWith('0.')) {
71
- bucketEndName = bucketEndName.substring(1);
72
- }
73
- buckets.push({
74
- name: `${bucketStartName}-${bucketEndName}`,
75
- start: bucketStart,
76
- end: bucketEnd,
77
- value: 0,
78
- });
79
- }
80
-
81
- // Put data into buckets
82
- data.forEach((value) => {
83
- for (let i = 0; i < buckets.length; i++) {
84
- // If this the last bucket, allow value to equal the end value
85
- const lastBucket = (i === buckets.length - 1);
86
- if (
87
- value >= buckets[i].start
88
- && (lastBucket ? value <= buckets[i].end : value < buckets[i].end)
89
- ) {
90
- // Found the correct bucket!
91
- buckets[i].value += 1;
92
- break;
93
- }
94
- }
95
- });
96
-
97
- let csvContents;
98
- if (!noDownload) {
99
- const bucketField = `${bucketLabel}${bucketUnit ? ' (' + bucketUnit + ')' : ''}`;
100
- const valueField = `${valueLabel}${valueUnit ? ' (' + valueUnit + ')' : ''}`;
101
- const csv = {
102
- fields: [bucketField, valueField],
103
- data: buckets.map((bucket) => {
104
- return [bucket.name, bucket.value];
105
- }),
106
- };
107
- csvContents = csvToString(csv);
108
- }
109
-
110
- return (
111
- <BarChart
112
- title={title}
113
- color={color}
114
- width={width}
115
- height={height}
116
- nameLabel={bucketLabel}
117
- nameUnit={bucketUnit}
118
- valueLabel={valueLabel}
119
- valueUnit={valueUnit}
120
- noTooltipOnHover={noTooltipOnHover}
121
- showLegend={showLegend}
122
- noDownload={noDownload}
123
- csvContents={csvContents}
124
- data={buckets}
125
- />
126
- );
127
- }
128
- }
129
-
130
- Histogram.propTypes = {
131
- // Title of the chart
132
- title: PropTypes.string,
133
- // Default CSS color (#123456 or 'white') for slices (can be overridden)
134
- color: PropTypes.string,
135
- // Width ('100%' or 50)
136
- width: PropTypes.oneOfType([
137
- PropTypes.string,
138
- PropTypes.number,
139
- ]),
140
- // Height ('100%' or 50)
141
- height: PropTypes.oneOfType([
142
- PropTypes.string,
143
- PropTypes.number,
144
- ]),
145
- // The lowest value to start at (beginning of first bucket)
146
- startValue: PropTypes.number,
147
- // The highest value to count (ending of the last bucket)
148
- endValue: PropTypes.number,
149
- // The number of buckets
150
- numBuckets: PropTypes.number,
151
- // The number of decimals to display on the bucket axis
152
- numDecimals: PropTypes.number,
153
- // Label for the bucket axis
154
- bucketLabel: PropTypes.string,
155
- // Unit for the bucket axis
156
- bucketUnit: PropTypes.string,
157
- // Label for the value axis
158
- valueLabel: PropTypes.string,
159
- // Unit for the value axis
160
- valueUnit: PropTypes.string,
161
- // The numbers to chart in the histogram
162
- data: PropTypes.arrayOf(PropTypes.number).isRequired,
163
- // If true, no tooltip is shown on hover
164
- noTooltipOnHover: PropTypes.bool,
165
- // If true, legend is included
166
- showLegend: PropTypes.bool,
167
- // If true, no download button is shown
168
- noDownload: PropTypes.bool,
169
- };
170
-
171
- Histogram.defaultProps = {
172
- title: null,
173
- color: colors.defaultBlue,
174
- width: '100%',
175
- height: '500px',
176
- startValue: 0,
177
- endValue: null,
178
- numBuckets: 10,
179
- numDecimals: 1,
180
- bucketLabel: 'Bucket',
181
- bucketUnit: null,
182
- valueLabel: 'Num in Bucket',
183
- valueUnit: null,
184
- noTooltipOnHover: false,
185
- showLegend: false,
186
- noDownload: false,
187
- };
188
-
189
- export default Histogram;