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.
- package/.eslintrc.js +95 -0
- package/lib/components/LoadingSpinner.d.ts +7 -0
- package/lib/components/LoadingSpinner.js +39 -0
- package/lib/components/LoadingSpinner.js.map +1 -0
- package/lib/components/Modal.d.ts +69 -0
- package/lib/components/Modal.js +311 -0
- package/lib/components/Modal.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/waitMs.d.ts +7 -0
- package/lib/helpers/waitMs.js +55 -0
- package/lib/helpers/waitMs.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.scss +50 -0
- package/src/components/LoadingSpinner.tsx +50 -0
- package/src/components/Modal.scss +48 -0
- package/src/components/Modal.tsx +391 -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/waitMs.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/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;
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
|
|
4
|
-
// Import other components
|
|
5
|
-
import DownloadButton from '../../../DownloadButton';
|
|
6
|
-
|
|
7
|
-
// Import custom styles
|
|
8
|
-
import './style.css';
|
|
9
|
-
|
|
10
|
-
/* Holder Component */
|
|
11
|
-
class Holder extends Component {
|
|
12
|
-
render() {
|
|
13
|
-
// Deconstruct props (see propTypes below for detailed information)
|
|
14
|
-
const {
|
|
15
|
-
title,
|
|
16
|
-
xLabel,
|
|
17
|
-
xUnit,
|
|
18
|
-
yLabel,
|
|
19
|
-
yUnit,
|
|
20
|
-
width,
|
|
21
|
-
height,
|
|
22
|
-
csvContents,
|
|
23
|
-
children
|
|
24
|
-
} = this.props;
|
|
25
|
-
|
|
26
|
-
// Calculate dimensions of the holder
|
|
27
|
-
// > Chart height depends on if the title is included
|
|
28
|
-
const chartHeight = `calc(${height}${title ? ' - 2.5em' : ''}${xLabel ? ' - 1.5em' : ''})`;
|
|
29
|
-
// > Chart width depends on if there is a y axis label
|
|
30
|
-
const chartWidth = `calc(${width}${yLabel ? ' - 1.5em' : ''})`;
|
|
31
|
-
|
|
32
|
-
// The many parts of this component look like this:
|
|
33
|
-
// |""""""""""""""""""""""""""""""""""""""""""|
|
|
34
|
-
// | Chart title [Download] | <- title content
|
|
35
|
-
// """"""""""""""""""""""""""""""""""""""""""""
|
|
36
|
-
// |"""""|""""""""""""""""""""""""""""""""""""|
|
|
37
|
-
// | Y | |
|
|
38
|
-
// | L | |
|
|
39
|
-
// | A | |
|
|
40
|
-
// | B | Chart Here | <- top content
|
|
41
|
-
// | E | |
|
|
42
|
-
// | L | |
|
|
43
|
-
// | | |
|
|
44
|
-
// """"""""""""""""""""""""""""""""""""""""""""
|
|
45
|
-
// |""""""""""""""""""""""""""""""""""""""""""|
|
|
46
|
-
// | X LABEL | <- bottom content
|
|
47
|
-
// """"""""""""""""""""""""""""""""""""""""""""
|
|
48
|
-
|
|
49
|
-
// Create the title content (if there's a tite)
|
|
50
|
-
const titleContent = title ? React.createElement(
|
|
51
|
-
'div',
|
|
52
|
-
{
|
|
53
|
-
style: {
|
|
54
|
-
height: '2.5em'
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
React.createElement(
|
|
58
|
-
'h4',
|
|
59
|
-
{ className: 'text-center' },
|
|
60
|
-
title,
|
|
61
|
-
csvContents && React.createElement(DownloadButton, {
|
|
62
|
-
text: 'CSV',
|
|
63
|
-
filename: `${title}.csv`,
|
|
64
|
-
contents: csvContents,
|
|
65
|
-
marginLeft: '5px'
|
|
66
|
-
})
|
|
67
|
-
)
|
|
68
|
-
) : null;
|
|
69
|
-
|
|
70
|
-
// Create the top content
|
|
71
|
-
// (includes the y-axis label and the chart, side by side)
|
|
72
|
-
const topContent = React.createElement(
|
|
73
|
-
'div',
|
|
74
|
-
null,
|
|
75
|
-
yLabel && React.createElement(
|
|
76
|
-
'div',
|
|
77
|
-
{
|
|
78
|
-
className: 'y-label-container',
|
|
79
|
-
style: {
|
|
80
|
-
height: chartHeight
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
React.createElement(
|
|
84
|
-
'div',
|
|
85
|
-
{
|
|
86
|
-
style: {
|
|
87
|
-
width: chartHeight
|
|
88
|
-
},
|
|
89
|
-
className: 'y-label-text label-text'
|
|
90
|
-
},
|
|
91
|
-
yLabel,
|
|
92
|
-
yUnit && React.createElement(
|
|
93
|
-
'span',
|
|
94
|
-
{ className: 'unit' },
|
|
95
|
-
'(',
|
|
96
|
-
yUnit,
|
|
97
|
-
')'
|
|
98
|
-
)
|
|
99
|
-
)
|
|
100
|
-
),
|
|
101
|
-
React.createElement(
|
|
102
|
-
'div',
|
|
103
|
-
{
|
|
104
|
-
className: 'd-inline-block',
|
|
105
|
-
style: {
|
|
106
|
-
width: chartWidth,
|
|
107
|
-
height: chartHeight
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
children
|
|
111
|
-
)
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
// Create the bottom if there's an x label
|
|
115
|
-
// (includes the x label below the chart)
|
|
116
|
-
const bottomContent = xLabel ? React.createElement(
|
|
117
|
-
'div',
|
|
118
|
-
{ className: 'x-label-text label-text' },
|
|
119
|
-
xLabel,
|
|
120
|
-
xUnit && React.createElement(
|
|
121
|
-
'span',
|
|
122
|
-
{ className: 'unit' },
|
|
123
|
-
'(',
|
|
124
|
-
xUnit,
|
|
125
|
-
')'
|
|
126
|
-
)
|
|
127
|
-
) : null;
|
|
128
|
-
|
|
129
|
-
// Put all the pieces together into one component
|
|
130
|
-
return React.createElement(
|
|
131
|
-
'div',
|
|
132
|
-
{ className: 'mb-4' },
|
|
133
|
-
React.createElement(
|
|
134
|
-
'div',
|
|
135
|
-
{
|
|
136
|
-
className: 'outer-container',
|
|
137
|
-
style: {
|
|
138
|
-
width,
|
|
139
|
-
height
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
titleContent,
|
|
143
|
-
topContent,
|
|
144
|
-
bottomContent
|
|
145
|
-
)
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
Holder.propTypes = {
|
|
151
|
-
// Title of the chart
|
|
152
|
-
title: PropTypes.string,
|
|
153
|
-
// Label of the x axis
|
|
154
|
-
xLabel: PropTypes.string,
|
|
155
|
-
// Units on the x axis
|
|
156
|
-
xUnit: PropTypes.string,
|
|
157
|
-
// Label of the y axis
|
|
158
|
-
yLabel: PropTypes.string,
|
|
159
|
-
// Units on the y axis
|
|
160
|
-
yUnit: PropTypes.string,
|
|
161
|
-
// Width of the chart (does not include the title)
|
|
162
|
-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
163
|
-
// Height of the chart (does not include the title)
|
|
164
|
-
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
165
|
-
// The chart object (should be set to fill 100% width an height)
|
|
166
|
-
children: PropTypes.node.isRequired,
|
|
167
|
-
// File contents to download
|
|
168
|
-
csvContents: PropTypes.string
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
Holder.defaultProps = {
|
|
172
|
-
title: null,
|
|
173
|
-
xLabel: null,
|
|
174
|
-
xUnit: null,
|
|
175
|
-
yLabel: null,
|
|
176
|
-
yUnit: null,
|
|
177
|
-
width: '100%',
|
|
178
|
-
height: '500px',
|
|
179
|
-
csvContents: null
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
export default Holder;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/* the outermost container of the holder */
|
|
2
|
-
.outer-container {
|
|
3
|
-
display: inline-block;
|
|
4
|
-
vertical-align: middle;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/* container for the y label - automatically moves to the left of the chart */
|
|
8
|
-
.y-label-container {
|
|
9
|
-
display: inline-block;
|
|
10
|
-
width: 1.5em;
|
|
11
|
-
float: left;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/* text of the y label - text is centered, vertical, and rotated */
|
|
15
|
-
.y-label-text {
|
|
16
|
-
display: inline-block;
|
|
17
|
-
height: 1.5em;
|
|
18
|
-
float: left;
|
|
19
|
-
transform: rotate(90deg);
|
|
20
|
-
transform-origin: 0.75em;
|
|
21
|
-
text-align: center;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/* text of the x label - text is centered */
|
|
25
|
-
.x-label-text {
|
|
26
|
-
height: 1.5em;
|
|
27
|
-
text-align: center;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/* styles shared between both x and y labels - bold, slightly larger text*/
|
|
31
|
-
.label-text {
|
|
32
|
-
font-size: 1.1em;
|
|
33
|
-
font-weight: bold;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/* axis unit style */
|
|
37
|
-
.unit {
|
|
38
|
-
margin-left: 5px;
|
|
39
|
-
font-style: italic;
|
|
40
|
-
font-weight: normal;
|
|
41
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/* Default colors for use in charts, etc */
|
|
2
|
-
export default {
|
|
3
|
-
// A pretty neutral blue to use as a default color
|
|
4
|
-
defaultBlue: '#419bf7',
|
|
5
|
-
|
|
6
|
-
// A simple assortment of 14 colors
|
|
7
|
-
assortment: [
|
|
8
|
-
// First 10:
|
|
9
|
-
'#ec4f6a', '#f19542', '#f6c353', '#61cbcc', '#419bf7', '#005392', '#7d5297', '#d261ab', '#7edfcf', '#5eac88',
|
|
10
|
-
// Last 4:
|
|
11
|
-
'#f4ce63', '#929000', '#5e5e5e', '#008e00']
|
|
12
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import CSVParser from 'papaparse';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Function for turning a csv object into a csv string
|
|
5
|
-
* @param {string[]} [csv.fields] - an array of field names. These will be used
|
|
6
|
-
* generate the header row of the csv
|
|
7
|
-
* @param {string[][]} [csv.data] - an array of csv rows, where each row is an
|
|
8
|
-
* array of strings that correspond to the cells of the row
|
|
9
|
-
* @return {string} the csv file contents
|
|
10
|
-
*/
|
|
11
|
-
export default (csv => {
|
|
12
|
-
return CSVParser.unparse(csv);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
// Example:
|
|
16
|
-
// const fields = ['Name', 'Age'];
|
|
17
|
-
// const data = [['Divardo', '19'], ['Calicci', '22']];
|
|
18
|
-
// const csv = { fields, data}
|
|
19
|
-
//
|
|
20
|
-
// Calling csvToString(csv) results in the following csv file:
|
|
21
|
-
// Name, Age
|
|
22
|
-
// Divardo, 19
|
|
23
|
-
// Calicci, 22
|
package/lib/common/isFloat.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns true if a string is a float (not an integer)
|
|
3
|
-
* @param {string} str - the string to check
|
|
4
|
-
* @return {boolean} whether or not the string represents a float
|
|
5
|
-
*/
|
|
6
|
-
export default (str => {
|
|
7
|
-
const match = String(str).match(/^-?\d*(\.\d+)?$/);
|
|
8
|
-
// If no matches at all, this is not a float
|
|
9
|
-
if (!match || match.length < 2) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
// We found a match. Make sure it's a float
|
|
13
|
-
return !!match[1];
|
|
14
|
-
});
|