dce-reactkit 1.0.20 → 2.0.2
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/.eslintrc.js +95 -0
- package/lib/components/LoadingSpinner.d.ts +6 -0
- package/lib/components/LoadingSpinner.js +41 -0
- package/lib/components/LoadingSpinner.js.map +1 -0
- package/lib/components/Modal.d.ts +69 -0
- package/lib/components/Modal.js +315 -0
- package/lib/components/Modal.js.map +1 -0
- package/lib/errors/ErrorWithCode.d.ts +9 -0
- package/lib/errors/ErrorWithCode.js +33 -0
- package/lib/errors/ErrorWithCode.js.map +1 -0
- package/lib/helpers/abbreviate.d.ts +9 -0
- package/lib/helpers/abbreviate.js +21 -0
- package/lib/helpers/abbreviate.js.map +1 -0
- package/lib/helpers/avg.d.ts +8 -0
- package/lib/helpers/avg.js +24 -0
- package/lib/helpers/avg.js.map +1 -0
- package/lib/helpers/ceilToNumDecimals.d.ts +9 -0
- package/lib/helpers/ceilToNumDecimals.js +15 -0
- package/lib/helpers/ceilToNumDecimals.js.map +1 -0
- package/lib/helpers/floorToNumDecimals.d.ts +9 -0
- package/lib/helpers/floorToNumDecimals.js +15 -0
- package/lib/helpers/floorToNumDecimals.js.map +1 -0
- package/lib/helpers/forceNumIntoBounds.d.ts +10 -0
- package/lib/helpers/forceNumIntoBounds.js +15 -0
- package/lib/helpers/forceNumIntoBounds.js.map +1 -0
- package/lib/helpers/padDecimalZeros.d.ts +10 -0
- package/lib/helpers/padDecimalZeros.js +30 -0
- package/lib/helpers/padDecimalZeros.js.map +1 -0
- package/lib/helpers/padZerosLeft.d.ts +9 -0
- package/lib/helpers/padZerosLeft.js +21 -0
- package/lib/helpers/padZerosLeft.js.map +1 -0
- package/lib/helpers/roundToNumDecimals.d.ts +9 -0
- package/lib/helpers/roundToNumDecimals.js +15 -0
- package/lib/helpers/roundToNumDecimals.js.map +1 -0
- package/lib/helpers/sum.d.ts +8 -0
- package/lib/helpers/sum.js +15 -0
- package/lib/helpers/sum.js.map +1 -0
- package/lib/helpers/visitServerEndpoint.d.ts +17 -0
- package/lib/helpers/visitServerEndpoint.js +84 -0
- package/lib/helpers/visitServerEndpoint.js.map +1 -0
- package/lib/helpers/waitMs.d.ts +7 -0
- package/lib/helpers/waitMs.js +55 -0
- package/lib/helpers/waitMs.js.map +1 -0
- package/lib/types/ReactKitErrorCode.d.ts +9 -0
- package/lib/types/ReactKitErrorCode.js +14 -0
- package/lib/types/ReactKitErrorCode.js.map +1 -0
- package/lib/types/Variant.d.ts +15 -0
- package/lib/types/Variant.js +19 -0
- package/lib/types/Variant.js.map +1 -0
- package/package.json +22 -40
- package/src/components/LoadingSpinner.tsx +105 -0
- package/src/components/Modal.tsx +447 -0
- package/src/errors/ErrorWithCode.tsx +15 -0
- package/src/helpers/abbreviate.tsx +23 -0
- package/src/helpers/avg.tsx +22 -0
- package/src/helpers/ceilToNumDecimals.tsx +13 -0
- package/src/helpers/floorToNumDecimals.tsx +13 -0
- package/src/helpers/forceNumIntoBounds.tsx +19 -0
- package/src/helpers/padDecimalZeros.tsx +32 -0
- package/src/helpers/padZerosLeft.tsx +21 -0
- package/src/helpers/roundToNumDecimals.tsx +13 -0
- package/src/helpers/sum.tsx +16 -0
- package/src/helpers/visitServerEndpoint.tsx +59 -0
- package/src/helpers/waitMs.tsx +12 -0
- package/src/types/ReactKitErrorCode.tsx +12 -0
- package/src/types/Variant.tsx +16 -0
- package/tsconfig.json +24 -0
- package/index.js +0 -1
- package/lib/Bar.js +0 -169
- package/lib/Donut.js +0 -145
- package/lib/DownloadButton.js +0 -81
- package/lib/Histogram.js +0 -193
- package/lib/Scatter.js +0 -162
- package/lib/StackedBar.js +0 -243
- package/lib/common/chart/Holder/index.js +0 -182
- package/lib/common/chart/Holder/style.css +0 -41
- package/lib/common/chart/colors.js +0 -12
- package/lib/common/csvToString.js +0 -23
- package/lib/common/isFloat.js +0 -14
- package/lib/common/isInteger.js +0 -24
- package/lib/common/math.js +0 -21
- package/lib/common/validators.js +0 -18
- package/lib/glyph/Adjust.js +0 -13
- package/lib/glyph/Angle.js +0 -44
- package/lib/glyph/Archive.js +0 -13
- package/lib/glyph/Arrow.js +0 -49
- package/lib/glyph/ArrowsHorizontal.js +0 -13
- package/lib/glyph/ArrowsVertical.js +0 -13
- package/lib/glyph/Award.js +0 -13
- package/lib/glyph/Ban.js +0 -13
- package/lib/glyph/Barcode.js +0 -13
- package/lib/glyph/Bed.js +0 -13
- package/lib/glyph/Bell.js +0 -35
- package/lib/glyph/Bolt.js +0 -13
- package/lib/glyph/Bookmark.js +0 -37
- package/lib/glyph/Bug.js +0 -13
- package/lib/glyph/Calendar.js +0 -13
- package/lib/glyph/Check.js +0 -36
- package/lib/glyph/Checkbox.js +0 -40
- package/lib/glyph/Chevron.js +0 -63
- package/lib/glyph/Circle.js +0 -15
- package/lib/glyph/Cog.js +0 -13
- package/lib/glyph/DoubleAngle.js +0 -45
- package/lib/glyph/Download.js +0 -13
- package/lib/glyph/Ellipsis.js +0 -36
- package/lib/glyph/Envelope.js +0 -13
- package/lib/glyph/File.js +0 -37
- package/lib/glyph/IdCard.js +0 -13
- package/lib/glyph/Menu.js +0 -13
- package/lib/glyph/Minus.js +0 -13
- package/lib/glyph/Move.js +0 -13
- package/lib/glyph/Plus.js +0 -13
- package/lib/glyph/Square.js +0 -47
- package/lib/glyph/Teacher.js +0 -13
- package/lib/glyph/TextAlign.js +0 -53
- package/lib/glyph/Times.js +0 -36
- package/lib/glyph/WarningTriangle.js +0 -13
- package/lib/index.js +0 -1
- package/src-old/common/csvToString.js +0 -5
- package/src-old/common/isFloat.js +0 -3
- package/src-old/common/isInteger.js +0 -14
- package/src-old/common/math.js +0 -16
- package/src-old/common/validators.js +0 -14
- package/src-old/components/Alert.js +0 -79
- package/src-old/components/Button.js +0 -64
- package/src-old/components/CSV/autoMatch.js +0 -174
- package/src-old/components/CSV/getNumCols.js +0 -15
- package/src-old/components/CSV/index.js +0 -743
- package/src-old/components/Card.js +0 -64
- package/src-old/components/Chart/Bar.js +0 -169
- package/src-old/components/Chart/Donut.js +0 -160
- package/src-old/components/Chart/Histogram.js +0 -189
- package/src-old/components/Chart/Scatter.js +0 -162
- package/src-old/components/Chart/colors.js +0 -20
- package/src-old/components/Checkbox/index.js +0 -106
- package/src-old/components/Checkbox/style.css +0 -11
- package/src-old/components/DatePicker.js +0 -59
- package/src-old/components/DownloadButton.js +0 -72
- package/src-old/components/Dropdown.js +0 -120
- package/src-old/components/Layout/LeftAddon.js +0 -63
- package/src-old/components/Layout/RightAddon.js +0 -64
- package/src-old/components/Layout/TwoCol.js +0 -67
- package/src-old/components/Modal.js +0 -161
- package/src-old/components/PhotoRoster.js +0 -152
- package/src-old/components/Pills.js +0 -117
- package/src-old/components/Radio.js +0 -94
- package/src-old/components/Splash/Error.js +0 -62
- package/src-old/components/Splash/Load/index.js +0 -32
- package/src-old/components/Splash/Load/style.css +0 -51
- package/src-old/components/Stat/General.js +0 -252
- package/src-old/components/Stat/helpers/calcAverage.js +0 -20
- package/src-old/components/Stat/helpers/calcExtremes.js +0 -27
- package/src-old/components/Stat/helpers/calcMedian.js +0 -32
- package/src-old/components/Stat/helpers/calcStdDev.js +0 -30
- package/src-old/components/Stat/helpers/calcSum.js +0 -8
- package/src-old/components/UserProfile/index.js +0 -151
- package/src-old/components/UserProfile/style.css +0 -33
- package/src-old/components/Well.js +0 -28
- package/src-old/components/Wizard/Question/CSV.js +0 -307
- package/src-old/components/Wizard/Question/Chooser/Assignment.js +0 -108
- package/src-old/components/Wizard/Question/Chooser/Course.js +0 -214
- package/src-old/components/Wizard/Question/Chooser/helpers/divideIntoSections.js +0 -16
- package/src-old/components/Wizard/Question/Chooser/helpers/genGetItemsPromise.js +0 -20
- package/src-old/components/Wizard/Question/Chooser/helpers/preprocessSections.js +0 -36
- package/src-old/components/Wizard/Question/Chooser/index.js +0 -306
- package/src-old/components/Wizard/Question/Form/Field/CheckableItem.js +0 -155
- package/src-old/components/Wizard/Question/Form/Field/Input.js +0 -149
- package/src-old/components/Wizard/Question/Form/Field/NumberItem.js +0 -374
- package/src-old/components/Wizard/Question/Form/Field/index.js +0 -34
- package/src-old/components/Wizard/Question/Form/Field/readme.md +0 -7
- package/src-old/components/Wizard/Question/Form/index.js +0 -175
- package/src-old/components/Wizard/Question/Form/style.css +0 -3
- package/src-old/components/Wizard/Question/OneButton.js +0 -80
- package/src-old/components/Wizard/Question/index.js +0 -46
- package/src-old/components/Wizard/Question/readme.md +0 -10
- package/src-old/components/Wizard/QuestionGroup/AnswerAll.js +0 -126
- package/src-old/components/Wizard/QuestionGroup/AnswerAny.js +0 -60
- package/src-old/components/Wizard/index.js +0 -233
- package/src-old/components/Wizard/style.css +0 -21
- package/src-old/glyphs/Adjust.js +0 -13
- package/src-old/glyphs/Angle.js +0 -57
- package/src-old/glyphs/Archive.js +0 -13
- package/src-old/glyphs/Arrow.js +0 -85
- package/src-old/glyphs/ArrowsHorizontal.js +0 -13
- package/src-old/glyphs/ArrowsVertical.js +0 -13
- package/src-old/glyphs/Award.js +0 -13
- package/src-old/glyphs/Ban.js +0 -13
- package/src-old/glyphs/Barcode.js +0 -13
- package/src-old/glyphs/Bed.js +0 -13
- package/src-old/glyphs/Bell.js +0 -34
- package/src-old/glyphs/Bolt.js +0 -13
- package/src-old/glyphs/Bookmark.js +0 -36
- package/src-old/glyphs/Bug.js +0 -13
- package/src-old/glyphs/Calendar.js +0 -13
- package/src-old/glyphs/Check.js +0 -34
- package/src-old/glyphs/Checkbox.js +0 -42
- package/src-old/glyphs/Chevron.js +0 -88
- package/src-old/glyphs/Circle.js +0 -16
- package/src-old/glyphs/Cog.js +0 -13
- package/src-old/glyphs/DoubleAngle.js +0 -58
- package/src-old/glyphs/Download.js +0 -13
- package/src-old/glyphs/Ellipsis.js +0 -35
- package/src-old/glyphs/Envelope.js +0 -13
- package/src-old/glyphs/File.js +0 -40
- package/src-old/glyphs/IdCard.js +0 -13
- package/src-old/glyphs/Menu.js +0 -13
- package/src-old/glyphs/Minus.js +0 -13
- package/src-old/glyphs/Move.js +0 -13
- package/src-old/glyphs/Plus.js +0 -13
- package/src-old/glyphs/Square.js +0 -48
- package/src-old/glyphs/Teacher.js +0 -13
- package/src-old/glyphs/TextAlign.js +0 -58
- package/src-old/glyphs/Times.js +0 -34
- package/src-old/glyphs/WarningTriangle.js +0 -13
- package/src-old/index.js +0 -1
package/lib/Histogram.js
DELETED
|
@@ -1,193 +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 './common/chart/colors';
|
|
9
|
-
|
|
10
|
-
// Import helpers
|
|
11
|
-
import csvToString from './common/csvToString';
|
|
12
|
-
|
|
13
|
-
/* Histogram Chart Component */
|
|
14
|
-
class Histogram extends Component {
|
|
15
|
-
render() {
|
|
16
|
-
// Deconstruct props (see propTypes below for detailed information)
|
|
17
|
-
const {
|
|
18
|
-
title,
|
|
19
|
-
color,
|
|
20
|
-
width,
|
|
21
|
-
height,
|
|
22
|
-
startValue,
|
|
23
|
-
numBuckets,
|
|
24
|
-
numDecimals,
|
|
25
|
-
bucketLabel,
|
|
26
|
-
bucketUnit,
|
|
27
|
-
valueLabel,
|
|
28
|
-
valueUnit,
|
|
29
|
-
data,
|
|
30
|
-
noTooltipOnHover,
|
|
31
|
-
noDownload,
|
|
32
|
-
showLegend
|
|
33
|
-
} = this.props;
|
|
34
|
-
|
|
35
|
-
// Choose end value (if none included, use largest value)
|
|
36
|
-
let { endValue } = this.props;
|
|
37
|
-
if (endValue === undefined || endValue === null) {
|
|
38
|
-
endValue = Math.max(...data);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Divide data into buckets
|
|
42
|
-
const buckets = [];
|
|
43
|
-
const epsilon = numDecimals === 0 ? 1 : parseFloat(`0.${'0'.repeat(numDecimals - 1)}1`);
|
|
44
|
-
// Dynamically choose the bucket width
|
|
45
|
-
const bucketWidth = (endValue - startValue) / numBuckets;
|
|
46
|
-
// Set up each bucket
|
|
47
|
-
for (let i = 0; i < numBuckets; i++) {
|
|
48
|
-
// Define bucket start and end
|
|
49
|
-
const bucketStart = startValue + bucketWidth * i; // inclusive
|
|
50
|
-
const bucketEnd = startValue + bucketWidth * (i + 1); // exclusive
|
|
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 = lastBucket ? bucketEnd.toFixed(numDecimals) : (parseFloat(bucketEnd.toFixed(numDecimals)) - epsilon).toFixed(numDecimals);
|
|
61
|
-
if (bucketEndName === '0.0') {
|
|
62
|
-
bucketEndName = '0';
|
|
63
|
-
} else if (bucketEndName.startsWith('0.')) {
|
|
64
|
-
bucketEndName = bucketEndName.substring(1);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Create a bucket object {name, start, end}
|
|
68
|
-
buckets.push({
|
|
69
|
-
name: `${bucketStartName}-${bucketEndName}`,
|
|
70
|
-
start: bucketStart,
|
|
71
|
-
end: bucketEnd,
|
|
72
|
-
value: 0
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Put data into buckets
|
|
77
|
-
data.forEach(value => {
|
|
78
|
-
for (let i = 0; i < buckets.length; i++) {
|
|
79
|
-
// If this is the last bucket, allow value to equal the end value
|
|
80
|
-
// (inclusive)
|
|
81
|
-
const lastBucket = i === buckets.length - 1;
|
|
82
|
-
|
|
83
|
-
// Check if this value falls in this bucket
|
|
84
|
-
if (value >= buckets[i].start && (lastBucket ? value <= buckets[i].end : value < buckets[i].end)) {
|
|
85
|
-
// Found the correct bucket! Add another item to this bucket
|
|
86
|
-
buckets[i].value += 1;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// Generate the downloadable csv if we have a download button
|
|
93
|
-
let csvContents;
|
|
94
|
-
if (!noDownload) {
|
|
95
|
-
const bucketField = `${bucketLabel}${bucketUnit ? ' (' + bucketUnit + ')' : ''}`;
|
|
96
|
-
const valueField = `${valueLabel}${valueUnit ? ' (' + valueUnit + ')' : ''}`;
|
|
97
|
-
const csv = {
|
|
98
|
-
fields: [bucketField, valueField],
|
|
99
|
-
data: buckets.map(bucket => {
|
|
100
|
-
return [bucket.name, bucket.value];
|
|
101
|
-
})
|
|
102
|
-
};
|
|
103
|
-
csvContents = csvToString(csv);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Render the component (it's just a bar chart)
|
|
107
|
-
return React.createElement(BarChart, {
|
|
108
|
-
title: title,
|
|
109
|
-
color: color,
|
|
110
|
-
width: width,
|
|
111
|
-
height: height,
|
|
112
|
-
nameLabel: bucketLabel,
|
|
113
|
-
nameUnit: bucketUnit,
|
|
114
|
-
valueLabel: valueLabel,
|
|
115
|
-
valueUnit: valueUnit,
|
|
116
|
-
noTooltipOnHover: noTooltipOnHover,
|
|
117
|
-
showLegend: showLegend,
|
|
118
|
-
noDownload: noDownload,
|
|
119
|
-
csvContents: csvContents,
|
|
120
|
-
data: buckets
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
Histogram.propTypes = {
|
|
126
|
-
// Title of the chart
|
|
127
|
-
title: PropTypes.string,
|
|
128
|
-
// Default CSS color (#123456 or 'white') for slices (can be overridden)
|
|
129
|
-
color: PropTypes.string,
|
|
130
|
-
// Width ('100%' or 50)
|
|
131
|
-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
132
|
-
// Height ('100%' or 50)
|
|
133
|
-
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
134
|
-
// The lowest value to start at (beginning of first bucket)
|
|
135
|
-
startValue: PropTypes.number,
|
|
136
|
-
// The highest value to count (ending of the last bucket)
|
|
137
|
-
endValue: PropTypes.number,
|
|
138
|
-
// The number of buckets
|
|
139
|
-
numBuckets: PropTypes.number,
|
|
140
|
-
// The number of decimals to display on the bucket axis
|
|
141
|
-
numDecimals: PropTypes.number,
|
|
142
|
-
// Label for the bucket axis
|
|
143
|
-
bucketLabel: PropTypes.string,
|
|
144
|
-
// Unit for the bucket axis
|
|
145
|
-
bucketUnit: PropTypes.string,
|
|
146
|
-
// Label for the value axis
|
|
147
|
-
valueLabel: PropTypes.string,
|
|
148
|
-
// Unit for the value axis
|
|
149
|
-
valueUnit: PropTypes.string,
|
|
150
|
-
// The numbers to chart in the histogram
|
|
151
|
-
data: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
152
|
-
// If true, no tooltip is shown on hover
|
|
153
|
-
noTooltipOnHover: PropTypes.bool,
|
|
154
|
-
// If true, legend is included
|
|
155
|
-
showLegend: PropTypes.bool,
|
|
156
|
-
// If true, no download button is shown
|
|
157
|
-
noDownload: PropTypes.bool
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
Histogram.defaultProps = {
|
|
161
|
-
// Chart has no title by default
|
|
162
|
-
title: null,
|
|
163
|
-
// Bars are neutral blue by default
|
|
164
|
-
color: colors.defaultBlue,
|
|
165
|
-
// Chart takes up full parent width by default
|
|
166
|
-
width: '100%',
|
|
167
|
-
// Chart's height is 500px by default
|
|
168
|
-
height: '500px',
|
|
169
|
-
// First bucket starts at 0 by default
|
|
170
|
-
startValue: 0,
|
|
171
|
-
// Last bucket takes on the highest value in the dataset by default
|
|
172
|
-
endValue: null,
|
|
173
|
-
// The data is divided into 10 buckets by default
|
|
174
|
-
numBuckets: 10,
|
|
175
|
-
// The bucket labels include one decimal
|
|
176
|
-
numDecimals: 1,
|
|
177
|
-
// The bucket axis is called 'Bucket' by default
|
|
178
|
-
bucketLabel: 'Bucket',
|
|
179
|
-
// The bucket axis has no unit by default
|
|
180
|
-
bucketUnit: null,
|
|
181
|
-
// The value axis is called 'Num in Bucket' by default
|
|
182
|
-
valueLabel: 'Num in Bucket',
|
|
183
|
-
// The value axis has no unit by default
|
|
184
|
-
valueUnit: null,
|
|
185
|
-
// Tooltips are shown by default
|
|
186
|
-
noTooltipOnHover: false,
|
|
187
|
-
// No legend is included by default
|
|
188
|
-
showLegend: false,
|
|
189
|
-
// A download button is included by default
|
|
190
|
-
noDownload: false
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
export default Histogram;
|
package/lib/Scatter.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
|
|
4
|
-
// Import rechart components
|
|
5
|
-
import { ResponsiveContainer, ScatterChart, Scatter as ScatterLib, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts';
|
|
6
|
-
|
|
7
|
-
// Import helpers
|
|
8
|
-
import csvToString from './common/csvToString';
|
|
9
|
-
|
|
10
|
-
// Import other components
|
|
11
|
-
import Holder from './common/chart/Holder';
|
|
12
|
-
|
|
13
|
-
// Import default colors
|
|
14
|
-
import colors from './common/chart/colors';
|
|
15
|
-
|
|
16
|
-
/* Scatter Chart Component */
|
|
17
|
-
class Scatter extends Component {
|
|
18
|
-
render() {
|
|
19
|
-
// Deconstruct props (see propTypes below for detailed information)
|
|
20
|
-
const {
|
|
21
|
-
title,
|
|
22
|
-
color,
|
|
23
|
-
width,
|
|
24
|
-
height,
|
|
25
|
-
xLabel,
|
|
26
|
-
xUnit,
|
|
27
|
-
yLabel,
|
|
28
|
-
yUnit,
|
|
29
|
-
data,
|
|
30
|
-
noTooltipOnHover,
|
|
31
|
-
noDownload,
|
|
32
|
-
showLegend,
|
|
33
|
-
seriesName
|
|
34
|
-
} = this.props;
|
|
35
|
-
|
|
36
|
-
// Generate csv contents if we have a download button
|
|
37
|
-
let csvContents;
|
|
38
|
-
if (!noDownload) {
|
|
39
|
-
// Create x and y column labels dynamically
|
|
40
|
-
const xField = `${xLabel}${xUnit ? ' (' + xUnit + ')' : ''}`;
|
|
41
|
-
const yField = `${yLabel}${yUnit ? ' (' + yUnit + ')' : ''}`;
|
|
42
|
-
// Create the csv content object
|
|
43
|
-
const csv = {
|
|
44
|
-
fields: [xField, yField],
|
|
45
|
-
data: data.map(datum => {
|
|
46
|
-
return [datum.x, datum.y];
|
|
47
|
-
})
|
|
48
|
-
};
|
|
49
|
-
// Create the csv string
|
|
50
|
-
csvContents = csvToString(csv);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Render the component
|
|
54
|
-
return React.createElement(
|
|
55
|
-
Holder,
|
|
56
|
-
{
|
|
57
|
-
title: title,
|
|
58
|
-
xLabel: xLabel,
|
|
59
|
-
xUnit: xUnit,
|
|
60
|
-
yLabel: yLabel,
|
|
61
|
-
yUnit: yUnit,
|
|
62
|
-
width: width,
|
|
63
|
-
height: height,
|
|
64
|
-
csvContents: csvContents
|
|
65
|
-
},
|
|
66
|
-
React.createElement(
|
|
67
|
-
ResponsiveContainer,
|
|
68
|
-
{
|
|
69
|
-
width: '100%',
|
|
70
|
-
height: '100%'
|
|
71
|
-
},
|
|
72
|
-
React.createElement(
|
|
73
|
-
ScatterChart,
|
|
74
|
-
null,
|
|
75
|
-
React.createElement(CartesianGrid, null),
|
|
76
|
-
React.createElement(YAxis, {
|
|
77
|
-
dataKey: 'y',
|
|
78
|
-
type: 'number',
|
|
79
|
-
name: yLabel
|
|
80
|
-
}),
|
|
81
|
-
React.createElement(XAxis, {
|
|
82
|
-
dataKey: 'x',
|
|
83
|
-
type: 'number',
|
|
84
|
-
name: xLabel
|
|
85
|
-
}),
|
|
86
|
-
!noTooltipOnHover && React.createElement(Tooltip, {
|
|
87
|
-
cursor: {
|
|
88
|
-
strokeDasharray: '3 3'
|
|
89
|
-
}
|
|
90
|
-
}),
|
|
91
|
-
showLegend && React.createElement(Legend, null),
|
|
92
|
-
React.createElement(ScatterLib, {
|
|
93
|
-
name: seriesName,
|
|
94
|
-
data: data,
|
|
95
|
-
fill: color
|
|
96
|
-
})
|
|
97
|
-
)
|
|
98
|
-
)
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
Scatter.propTypes = {
|
|
104
|
-
// Title of the chart
|
|
105
|
-
title: PropTypes.string,
|
|
106
|
-
// CSS color (#123456 or 'white') for the points
|
|
107
|
-
color: PropTypes.string,
|
|
108
|
-
// Width ('100%' or 50)
|
|
109
|
-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
110
|
-
// Height ('100%' or 50)
|
|
111
|
-
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
112
|
-
// Label for the x axis
|
|
113
|
-
xLabel: PropTypes.string,
|
|
114
|
-
// Unit for the x axis
|
|
115
|
-
xUnit: PropTypes.string,
|
|
116
|
-
// Label for the y axis
|
|
117
|
-
yLabel: PropTypes.string,
|
|
118
|
-
// Unit for the y axis
|
|
119
|
-
yUnit: PropTypes.string,
|
|
120
|
-
// Array of data objects
|
|
121
|
-
data: PropTypes.arrayOf(PropTypes.shape({
|
|
122
|
-
x: PropTypes.number,
|
|
123
|
-
y: PropTypes.number
|
|
124
|
-
})).isRequired,
|
|
125
|
-
// If true, no tooltip is shown when hovering over a point
|
|
126
|
-
noTooltipOnHover: PropTypes.bool,
|
|
127
|
-
// If true, no download button is shown
|
|
128
|
-
noDownload: PropTypes.bool,
|
|
129
|
-
// Name of the series (included and required for legend)
|
|
130
|
-
seriesName: PropTypes.string,
|
|
131
|
-
// If true, legend is included
|
|
132
|
-
showLegend: PropTypes.bool
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
Scatter.defaultProps = {
|
|
136
|
-
// Chart has no title by default
|
|
137
|
-
title: null,
|
|
138
|
-
// Scatter dots are neutral blue by default
|
|
139
|
-
color: colors.defaultBlue,
|
|
140
|
-
// Chart takes up full width of parent by default
|
|
141
|
-
width: '100%',
|
|
142
|
-
// Chart's height is 500px by default
|
|
143
|
-
height: '500px',
|
|
144
|
-
// Label for x axis is 'x-axis' by default
|
|
145
|
-
xLabel: 'x-axis',
|
|
146
|
-
// X axis has no unit by default
|
|
147
|
-
xUnit: null,
|
|
148
|
-
// Label for y axis is 'y-axis' by default
|
|
149
|
-
yLabel: 'y-axis',
|
|
150
|
-
// Y axis has no unit by default
|
|
151
|
-
yUnit: null,
|
|
152
|
-
// Scatter series is 'Chart' by default (for the legend)
|
|
153
|
-
seriesName: 'Chart',
|
|
154
|
-
// Tooltips are displayed by default
|
|
155
|
-
noTooltipOnHover: false,
|
|
156
|
-
// Download button is added by default
|
|
157
|
-
noDownload: false,
|
|
158
|
-
// No legend is included by default
|
|
159
|
-
showLegend: false
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
export default Scatter;
|
package/lib/StackedBar.js
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
|
|
4
|
-
// Import chart components
|
|
5
|
-
import { ResponsiveContainer, BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts';
|
|
6
|
-
|
|
7
|
-
// Import other components
|
|
8
|
-
import Holder from './common/chart/Holder';
|
|
9
|
-
|
|
10
|
-
// Import default colors
|
|
11
|
-
import colors from './common/chart/colors';
|
|
12
|
-
|
|
13
|
-
// Import helpers
|
|
14
|
-
import csvToString from './common/csvToString';
|
|
15
|
-
|
|
16
|
-
/* Stacked Bar Chart Component */
|
|
17
|
-
class StackedBar extends Component {
|
|
18
|
-
render() {
|
|
19
|
-
// Deconstruct props (see propTypes below for detailed information)
|
|
20
|
-
const {
|
|
21
|
-
title,
|
|
22
|
-
width,
|
|
23
|
-
height,
|
|
24
|
-
valueColors,
|
|
25
|
-
nameLabel,
|
|
26
|
-
nameUnit,
|
|
27
|
-
valuesLabel,
|
|
28
|
-
valuesUnit,
|
|
29
|
-
valueLabels,
|
|
30
|
-
valueUnits,
|
|
31
|
-
data,
|
|
32
|
-
horizontal,
|
|
33
|
-
noTooltipOnHover,
|
|
34
|
-
noDownload,
|
|
35
|
-
showLegend
|
|
36
|
-
} = this.props;
|
|
37
|
-
|
|
38
|
-
// Pre-process the values
|
|
39
|
-
// Collect all the value names
|
|
40
|
-
let valueNames = {}; // valueName => true
|
|
41
|
-
data.forEach(datum => {
|
|
42
|
-
if (datum.values) {
|
|
43
|
-
Object.keys(datum.values).forEach(valueName => {
|
|
44
|
-
valueNames[valueName] = true;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
valueNames = Object.keys(valueNames);
|
|
49
|
-
// Put together value objects
|
|
50
|
-
const valueObjects = {}; // valueName => { valueName, label, unit, color }
|
|
51
|
-
let nextAssortmentColorIndex = 0;
|
|
52
|
-
valueNames.forEach(valueName => {
|
|
53
|
-
// Get the color
|
|
54
|
-
let color;
|
|
55
|
-
if (colors === 'assortment' || !valueColors[valueName]) {
|
|
56
|
-
color = colors.assortment[nextAssortmentColorIndex % colors.assortment.length];
|
|
57
|
-
nextAssortmentColorIndex += 1;
|
|
58
|
-
} else {
|
|
59
|
-
color = valueColors[valueName];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Create a value object
|
|
63
|
-
const valueObject = {
|
|
64
|
-
valueName,
|
|
65
|
-
color,
|
|
66
|
-
label: valueLabels[valueName] || valueName,
|
|
67
|
-
unit: valueUnits[valueName] || null
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// Save the value object
|
|
71
|
-
valueObjects[valueName] = valueObject;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// Pre-process the data
|
|
75
|
-
const newData = []; // Array of { name, valueName: value, ...}
|
|
76
|
-
data.forEach(datum => {
|
|
77
|
-
const newDatum = {
|
|
78
|
-
name: datum.name
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// Add all values, set the number to zero if it wasn't defined
|
|
82
|
-
valueNames.forEach(valueName => {
|
|
83
|
-
newDatum[valueName] = datum.value[valueName] || 0;
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// Save to newData
|
|
87
|
-
newData.push(newDatum);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Generate csv contents if they weren't included
|
|
91
|
-
let { csvContents } = this.props;
|
|
92
|
-
if (!noDownload && !csvContents) {
|
|
93
|
-
const fields = [];
|
|
94
|
-
|
|
95
|
-
// Create the name column using the label and unit (if it's included)
|
|
96
|
-
fields.push(`${nameLabel}${nameUnit ? ' (' + nameUnit + ')' : ''}`);
|
|
97
|
-
|
|
98
|
-
// Create the value columns using the label and unit (if it's included)
|
|
99
|
-
valueNames.forEach(valueName => {
|
|
100
|
-
const valueObject = valueObjects[valueName];
|
|
101
|
-
fields.push(`${valueObject.label}${valueObject.unit ? ' (' + valueObject.unit + ')' : ''}`);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// Build the csv data object
|
|
105
|
-
const csv = {
|
|
106
|
-
fields,
|
|
107
|
-
data: newData.map(datum => {
|
|
108
|
-
return valueNames.map(valueName => {
|
|
109
|
-
return datum[valueName];
|
|
110
|
-
});
|
|
111
|
-
})
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
// Turn the csv object into a string
|
|
115
|
-
csvContents = csvToString(csv);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Create the bars
|
|
119
|
-
const bars = valueNames.map(valueName => {
|
|
120
|
-
return React.createElement(Bar, {
|
|
121
|
-
dataKey: valueName,
|
|
122
|
-
stackId: 'a',
|
|
123
|
-
fill: valueObjects[valueName].color
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Render the component
|
|
128
|
-
return React.createElement(
|
|
129
|
-
Holder,
|
|
130
|
-
{
|
|
131
|
-
title: title,
|
|
132
|
-
width: width,
|
|
133
|
-
height: height,
|
|
134
|
-
xLabel: horizontal ? valuesLabel : nameLabel,
|
|
135
|
-
xUnit: horizontal ? valuesUnit : nameUnit,
|
|
136
|
-
yLabel: horizontal ? nameLabel : valuesLabel,
|
|
137
|
-
yUnit: horizontal ? nameUnit : valuesUnit,
|
|
138
|
-
csvContents: csvContents
|
|
139
|
-
},
|
|
140
|
-
React.createElement(
|
|
141
|
-
ResponsiveContainer,
|
|
142
|
-
{
|
|
143
|
-
width: '100%',
|
|
144
|
-
height: '100%'
|
|
145
|
-
},
|
|
146
|
-
React.createElement(
|
|
147
|
-
BarChart,
|
|
148
|
-
{
|
|
149
|
-
data: newData,
|
|
150
|
-
layout: horizontal ? 'vertical' : 'horizontal'
|
|
151
|
-
},
|
|
152
|
-
React.createElement(CartesianGrid, { strokeDasharray: '3 3' }),
|
|
153
|
-
React.createElement(XAxis, {
|
|
154
|
-
type: horizontal ? 'number' : 'category',
|
|
155
|
-
dataKey: horizontal ? null : 'name'
|
|
156
|
-
}),
|
|
157
|
-
React.createElement(YAxis, {
|
|
158
|
-
type: horizontal ? 'category' : 'number',
|
|
159
|
-
dataKey: horizontal ? 'name' : null
|
|
160
|
-
}),
|
|
161
|
-
!noTooltipOnHover && React.createElement(Tooltip, null),
|
|
162
|
-
showLegend && React.createElement(Legend, null),
|
|
163
|
-
bars
|
|
164
|
-
)
|
|
165
|
-
)
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
StackedBar.propTypes = {
|
|
171
|
-
// Title of the chart
|
|
172
|
-
title: PropTypes.string,
|
|
173
|
-
// Default CSS colors (#123456 or 'white') for each bar (can be overridden)
|
|
174
|
-
valueColors: PropTypes.objectOf(PropTypes.string),
|
|
175
|
-
// Width ('100%' or 50)
|
|
176
|
-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
177
|
-
// Height ('100%' or 50)
|
|
178
|
-
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
179
|
-
// Label for the name axis
|
|
180
|
-
nameLabel: PropTypes.string,
|
|
181
|
-
// Unit for the name axis
|
|
182
|
-
nameUnit: PropTypes.string,
|
|
183
|
-
// The label for the stacked bar axis
|
|
184
|
-
valuesLabel: PropTypes.string,
|
|
185
|
-
// The unit for the stcked bar axis
|
|
186
|
-
valuesUnit: PropTypes.string,
|
|
187
|
-
// Labels for the values
|
|
188
|
-
valueLabels: PropTypes.objectOf(PropTypes.string),
|
|
189
|
-
// Units for the values
|
|
190
|
-
valueUnits: PropTypes.objectOf(PropTypes.string),
|
|
191
|
-
// The data/bars
|
|
192
|
-
data: PropTypes.arrayOf(PropTypes.shape({
|
|
193
|
-
// Name of the bar
|
|
194
|
-
name: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
195
|
-
// Values of each bar
|
|
196
|
-
values: PropTypes.object
|
|
197
|
-
})).isRequired,
|
|
198
|
-
// If true, bar chart is a horizontal bar chart
|
|
199
|
-
horizontal: PropTypes.bool,
|
|
200
|
-
// If true, no tooltip is shown on hover
|
|
201
|
-
noTooltipOnHover: PropTypes.bool,
|
|
202
|
-
// If true, legend is included
|
|
203
|
-
showLegend: PropTypes.bool,
|
|
204
|
-
// If true, no download button is shown
|
|
205
|
-
noDownload: PropTypes.bool,
|
|
206
|
-
// The contents of the csv file to download (auto-generated if not included)
|
|
207
|
-
csvContents: PropTypes.string
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
StackedBar.defaultProps = {
|
|
211
|
-
// No title for chart by default
|
|
212
|
-
title: null,
|
|
213
|
-
// By default, we use an assortment of colors, one for each value
|
|
214
|
-
valueColors: 'assorted',
|
|
215
|
-
// Chart takes up whole parent width by default
|
|
216
|
-
width: '100%',
|
|
217
|
-
// Chart is 500 pixels tall by default
|
|
218
|
-
height: '500px',
|
|
219
|
-
// Name axis is labeled 'Name' by default
|
|
220
|
-
nameLabel: 'Name',
|
|
221
|
-
// Name axis has no unit by default
|
|
222
|
-
nameUnit: null,
|
|
223
|
-
// The stacked bar axis is labeled 'Value' by default
|
|
224
|
-
valuesLabel: 'Value',
|
|
225
|
-
// The stacked bar axis has no unit by default
|
|
226
|
-
valuesUnit: null,
|
|
227
|
-
// Values are labeled by their property names by default
|
|
228
|
-
valueLabels: {},
|
|
229
|
-
// Values have no units by default
|
|
230
|
-
valueUnits: {},
|
|
231
|
-
// The bar chart is a vertical bar chart by default
|
|
232
|
-
horizontal: false,
|
|
233
|
-
// Tooltips are displayed by defaults
|
|
234
|
-
noTooltipOnHover: false,
|
|
235
|
-
// No legend is shown by default
|
|
236
|
-
showLegend: false,
|
|
237
|
-
// A download button is added by default
|
|
238
|
-
noDownload: false,
|
|
239
|
-
// We auto-generate the csv contents by default
|
|
240
|
-
csvContents: null
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
export default StackedBar;
|