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
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pad a number with zeros on the left (e.g. 5 becomes 05 with 2 digit padding)
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
* @param num the number to pad
|
|
5
|
+
* @param numDigits the minimum number of digits before the decimal
|
|
6
|
+
* @returns padded number
|
|
7
|
+
*/
|
|
8
|
+
const padZerosLeft = (num: number, numDigits: number): string => {
|
|
9
|
+
// Convert to string
|
|
10
|
+
let out = String(num);
|
|
11
|
+
|
|
12
|
+
// Add zeros
|
|
13
|
+
while (out.split('.')[0].length < numDigits) {
|
|
14
|
+
out = `0${out}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Return
|
|
18
|
+
return out;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default padZerosLeft;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Round a number to a certain number of decimals
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
* @param num the number to round
|
|
5
|
+
* @param numDecimals the number of decimals to round to
|
|
6
|
+
* @returns rounded number
|
|
7
|
+
*/
|
|
8
|
+
const roundToNumDecimals = (num: number, numDecimals: number): number => {
|
|
9
|
+
const rounder = 10 ** numDecimals;
|
|
10
|
+
return (Math.round(num * rounder) / rounder);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default roundToNumDecimals;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sum the numbers in an array
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
* @param nums the numbers to sum
|
|
5
|
+
* @returns the sum of the numbers
|
|
6
|
+
*/
|
|
7
|
+
const sum = (nums: number[]): number => {
|
|
8
|
+
return nums.reduce(
|
|
9
|
+
(a: number, b: number) => {
|
|
10
|
+
return (a + b);
|
|
11
|
+
},
|
|
12
|
+
0,
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default sum;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Initialize caccl
|
|
2
|
+
import { sendRequest } from 'caccl/client';
|
|
3
|
+
|
|
4
|
+
// Import custom error
|
|
5
|
+
import ErrorWithCode from '../errors/ErrorWithCode';
|
|
6
|
+
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Visit an endpoint on the server
|
|
10
|
+
* @author Gabe Abrams
|
|
11
|
+
* @param opts object containing all arguments
|
|
12
|
+
* @param opts.path - the path of the server endpoint
|
|
13
|
+
* @param [opts.method=GET] - the method of the endpoint
|
|
14
|
+
* @param [opts.params] - query/body parameters to include
|
|
15
|
+
* @returns response from server
|
|
16
|
+
*/
|
|
17
|
+
const visitServerEndpoint = async (
|
|
18
|
+
opts: {
|
|
19
|
+
path: string,
|
|
20
|
+
method?: ('GET' | 'POST' | 'DELETE' | 'PUT'),
|
|
21
|
+
params?: { [key in string]: any },
|
|
22
|
+
},
|
|
23
|
+
): Promise<any> => {
|
|
24
|
+
// Send the request
|
|
25
|
+
const response = await sendRequest({
|
|
26
|
+
path: opts.path,
|
|
27
|
+
method: opts.method,
|
|
28
|
+
params: opts.params,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Check for failure
|
|
32
|
+
if (!response || !response.body) {
|
|
33
|
+
throw new ErrorWithCode(
|
|
34
|
+
'We didn\'t get a response from the server. Please check your internet connection.',
|
|
35
|
+
ReactKitErrorCode.NoResponse,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (!response.body.success) {
|
|
39
|
+
// Other errors
|
|
40
|
+
throw new ErrorWithCode(
|
|
41
|
+
(
|
|
42
|
+
response.body.message
|
|
43
|
+
|| 'An unknown error occurred. Please contact an admin.'
|
|
44
|
+
),
|
|
45
|
+
(
|
|
46
|
+
response.body.code
|
|
47
|
+
|| ReactKitErrorCode.NoCode
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Success! Extract the body
|
|
53
|
+
const { body } = response.body;
|
|
54
|
+
|
|
55
|
+
// Return
|
|
56
|
+
return body;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default visitServerEndpoint;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bootstrap variants
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
*/
|
|
5
|
+
enum Variant {
|
|
6
|
+
Primary = 'primary',
|
|
7
|
+
Secondary = 'secondary',
|
|
8
|
+
Success = 'success',
|
|
9
|
+
Warning = 'warning',
|
|
10
|
+
Info = 'info',
|
|
11
|
+
Danger = 'danger',
|
|
12
|
+
Light = 'light',
|
|
13
|
+
Dark = 'dark',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default Variant;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"noImplicitAny": true,
|
|
6
|
+
"noEmitOnError": true,
|
|
7
|
+
"removeComments": false,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"target": "es5",
|
|
11
|
+
"jsx": "react-jsx",
|
|
12
|
+
"lib": [
|
|
13
|
+
"es2015",
|
|
14
|
+
"dom"
|
|
15
|
+
],
|
|
16
|
+
"outDir": "./lib"
|
|
17
|
+
},
|
|
18
|
+
"include": [
|
|
19
|
+
"./src"
|
|
20
|
+
],
|
|
21
|
+
"ts-node": {
|
|
22
|
+
"files": true
|
|
23
|
+
}
|
|
24
|
+
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
throw new Error('Do not import dce-reactkit directly. Import components individually. View the docs for more information: https://harvard-edtech.github.io/dce-reactkit/');
|
package/lib/Bar.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
|
|
4
|
-
// Import rechart components
|
|
5
|
-
import { ResponsiveContainer, BarChart as BarChartRechart, 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
|
-
/* Bar Chart Component */
|
|
17
|
-
class BarChart extends Component {
|
|
18
|
-
render() {
|
|
19
|
-
// Deconstruct props (see propTypes below for detailed information)
|
|
20
|
-
const {
|
|
21
|
-
title,
|
|
22
|
-
color,
|
|
23
|
-
width,
|
|
24
|
-
height,
|
|
25
|
-
nameLabel,
|
|
26
|
-
nameUnit,
|
|
27
|
-
valueLabel,
|
|
28
|
-
valueUnit,
|
|
29
|
-
data,
|
|
30
|
-
horizontal,
|
|
31
|
-
noTooltipOnHover,
|
|
32
|
-
noDownload,
|
|
33
|
-
showLegend
|
|
34
|
-
} = this.props;
|
|
35
|
-
|
|
36
|
-
// Generate csv contents if they weren't included
|
|
37
|
-
let { csvContents } = this.props;
|
|
38
|
-
if (!noDownload && !csvContents) {
|
|
39
|
-
// Create the name column using the label and unit (if it's included)
|
|
40
|
-
const nameField = `${nameLabel}${nameUnit ? ' (' + nameUnit + ')' : ''}`;
|
|
41
|
-
// Create the value column using the label and unit (if it's included)
|
|
42
|
-
const valueField = `${valueLabel}${valueUnit ? ' (' + valueUnit + ')' : ''}`;
|
|
43
|
-
// Build the csv data object
|
|
44
|
-
const csv = {
|
|
45
|
-
fields: [nameField, valueField],
|
|
46
|
-
data: data.map(datum => {
|
|
47
|
-
return [datum.name, datum.value];
|
|
48
|
-
})
|
|
49
|
-
};
|
|
50
|
-
// Turn the csv object into a string
|
|
51
|
-
csvContents = csvToString(csv);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Render the component
|
|
55
|
-
return React.createElement(
|
|
56
|
-
Holder,
|
|
57
|
-
{
|
|
58
|
-
title: title,
|
|
59
|
-
width: width,
|
|
60
|
-
height: height,
|
|
61
|
-
xLabel: horizontal ? valueLabel : nameLabel,
|
|
62
|
-
xUnit: horizontal ? valueUnit : nameUnit,
|
|
63
|
-
yLabel: horizontal ? nameLabel : valueLabel,
|
|
64
|
-
yUnit: horizontal ? nameUnit : valueUnit,
|
|
65
|
-
csvContents: csvContents
|
|
66
|
-
},
|
|
67
|
-
React.createElement(
|
|
68
|
-
ResponsiveContainer,
|
|
69
|
-
{
|
|
70
|
-
width: '100%',
|
|
71
|
-
height: '100%'
|
|
72
|
-
},
|
|
73
|
-
React.createElement(
|
|
74
|
-
BarChartRechart,
|
|
75
|
-
{
|
|
76
|
-
data: data.map(datum => {
|
|
77
|
-
return {
|
|
78
|
-
name: datum.name,
|
|
79
|
-
[valueLabel]: datum.value
|
|
80
|
-
};
|
|
81
|
-
}),
|
|
82
|
-
layout: horizontal ? 'vertical' : 'horizontal'
|
|
83
|
-
},
|
|
84
|
-
React.createElement(CartesianGrid, { strokeDasharray: '3 3' }),
|
|
85
|
-
React.createElement(XAxis, {
|
|
86
|
-
type: horizontal ? 'number' : 'category',
|
|
87
|
-
dataKey: horizontal ? null : 'name'
|
|
88
|
-
}),
|
|
89
|
-
React.createElement(YAxis, {
|
|
90
|
-
type: horizontal ? 'category' : 'number',
|
|
91
|
-
dataKey: horizontal ? 'name' : null
|
|
92
|
-
}),
|
|
93
|
-
!noTooltipOnHover && React.createElement(Tooltip, null),
|
|
94
|
-
showLegend && React.createElement(Legend, null),
|
|
95
|
-
React.createElement(Bar, { dataKey: valueLabel, fill: color })
|
|
96
|
-
)
|
|
97
|
-
)
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
BarChart.propTypes = {
|
|
103
|
-
// Title of the chart
|
|
104
|
-
title: PropTypes.string,
|
|
105
|
-
// Default CSS color (#123456 or 'white') for bars (can be overridden)
|
|
106
|
-
color: PropTypes.string,
|
|
107
|
-
// Width ('100%' or 50)
|
|
108
|
-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
109
|
-
// Height ('100%' or 50)
|
|
110
|
-
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
111
|
-
// Label for the name axis
|
|
112
|
-
nameLabel: PropTypes.string,
|
|
113
|
-
// Unit for the name axis
|
|
114
|
-
nameUnit: PropTypes.string,
|
|
115
|
-
// Label for the value axis
|
|
116
|
-
valueLabel: PropTypes.string,
|
|
117
|
-
// Unit for the value axis
|
|
118
|
-
valueUnit: PropTypes.string,
|
|
119
|
-
// The data/bars
|
|
120
|
-
data: PropTypes.arrayOf(PropTypes.shape({
|
|
121
|
-
// Name of the bar
|
|
122
|
-
name: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
123
|
-
// Value of the bar
|
|
124
|
-
value: PropTypes.number.isRequired,
|
|
125
|
-
// Color of the bar (overrides props.color)
|
|
126
|
-
color: PropTypes.string
|
|
127
|
-
})).isRequired,
|
|
128
|
-
// If true, bar chart is a horizontal bar chart
|
|
129
|
-
horizontal: PropTypes.bool,
|
|
130
|
-
// If true, no tooltip is shown on hover
|
|
131
|
-
noTooltipOnHover: PropTypes.bool,
|
|
132
|
-
// If true, legend is included
|
|
133
|
-
showLegend: PropTypes.bool,
|
|
134
|
-
// If true, no download button is shown
|
|
135
|
-
noDownload: PropTypes.bool,
|
|
136
|
-
// The contents of the csv file to download (auto-generated if not included)
|
|
137
|
-
csvContents: PropTypes.string
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
BarChart.defaultProps = {
|
|
141
|
-
// No title for chart by default
|
|
142
|
-
title: null,
|
|
143
|
-
// Bars are a neutral blue by default
|
|
144
|
-
color: colors.defaultBlue,
|
|
145
|
-
// Chart takes up whole parent width by default
|
|
146
|
-
width: '100%',
|
|
147
|
-
// Chart is 500 pixels tall by default
|
|
148
|
-
height: '500px',
|
|
149
|
-
// Name axis is labeled 'Name' by default
|
|
150
|
-
nameLabel: 'Name',
|
|
151
|
-
// Name axis has no label by default
|
|
152
|
-
nameUnit: null,
|
|
153
|
-
// Value axis is labeled 'Value' by default
|
|
154
|
-
valueLabel: 'Value',
|
|
155
|
-
// Value axis has no label by default
|
|
156
|
-
valueUnit: null,
|
|
157
|
-
// The bar chart is a vertical bar chart by default
|
|
158
|
-
horizontal: false,
|
|
159
|
-
// Tooltips are displayed by defaults
|
|
160
|
-
noTooltipOnHover: false,
|
|
161
|
-
// No legend is shown by default
|
|
162
|
-
showLegend: false,
|
|
163
|
-
// A download button is added by default
|
|
164
|
-
noDownload: false,
|
|
165
|
-
// We auto-generate the csv contents by default
|
|
166
|
-
csvContents: null
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
export default BarChart;
|
package/lib/Donut.js
DELETED
|
@@ -1,145 +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 { ResponsiveContainer, PieChart, Pie, Cell, Legend, Tooltip } from 'recharts';
|
|
7
|
-
|
|
8
|
-
// Import other components
|
|
9
|
-
import Holder from './common/chart/Holder';
|
|
10
|
-
|
|
11
|
-
// Import default colors
|
|
12
|
-
import colors from './common/chart/colors';
|
|
13
|
-
|
|
14
|
-
// Import helpers
|
|
15
|
-
import csvToString from './common/csvToString';
|
|
16
|
-
|
|
17
|
-
/* Donut Chart Component */
|
|
18
|
-
class DonutChart extends Component {
|
|
19
|
-
render() {
|
|
20
|
-
// Deconstruct props (see propTypes below for detailed information)
|
|
21
|
-
const {
|
|
22
|
-
title,
|
|
23
|
-
color,
|
|
24
|
-
width,
|
|
25
|
-
height,
|
|
26
|
-
data,
|
|
27
|
-
noTooltipOnHover,
|
|
28
|
-
noDownload,
|
|
29
|
-
showLegend
|
|
30
|
-
} = this.props;
|
|
31
|
-
|
|
32
|
-
// Generate csv contents for the download
|
|
33
|
-
let csvContents;
|
|
34
|
-
if (!noDownload) {
|
|
35
|
-
const csv = {
|
|
36
|
-
fields: ['Name', 'Value'],
|
|
37
|
-
data: data.map(datum => {
|
|
38
|
-
return [datum.name, datum.value];
|
|
39
|
-
})
|
|
40
|
-
};
|
|
41
|
-
csvContents = csvToString(csv);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return React.createElement(
|
|
45
|
-
Holder,
|
|
46
|
-
{
|
|
47
|
-
title: title,
|
|
48
|
-
width: width,
|
|
49
|
-
height: height,
|
|
50
|
-
csvContents: csvContents
|
|
51
|
-
},
|
|
52
|
-
React.createElement(
|
|
53
|
-
ResponsiveContainer,
|
|
54
|
-
{
|
|
55
|
-
width: '100%',
|
|
56
|
-
height: '100%'
|
|
57
|
-
},
|
|
58
|
-
React.createElement(
|
|
59
|
-
PieChart,
|
|
60
|
-
null,
|
|
61
|
-
showLegend && React.createElement(Legend, null),
|
|
62
|
-
React.createElement(
|
|
63
|
-
Pie,
|
|
64
|
-
{
|
|
65
|
-
data: data,
|
|
66
|
-
dataKey: 'value',
|
|
67
|
-
innerRadius: '60%',
|
|
68
|
-
outerRadius: '100%',
|
|
69
|
-
fill: color
|
|
70
|
-
},
|
|
71
|
-
data.map((item, index) => {
|
|
72
|
-
// Get the item's default color
|
|
73
|
-
let itemColor = item.color ? item.color : color;
|
|
74
|
-
|
|
75
|
-
// If individual item doesn't have an override color and we
|
|
76
|
-
// are using a color assortment, choose the next color
|
|
77
|
-
if (itemColor === 'assortment' && !item.color) {
|
|
78
|
-
itemColor = colors.assortment[index % colors.assortment.length];
|
|
79
|
-
// Don't let two adjacent slices have the same color
|
|
80
|
-
// (this math ensures that if the first and last slice are
|
|
81
|
-
// not the same color)
|
|
82
|
-
if ((data.length - 1) % colors.assortment.length === 0 && index === data.length - 1) {
|
|
83
|
-
itemColor = colors.assortment[(index + Math.floor(colors.assortment.length / 2)) % colors.assortment.length];
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Return the cell corresponding to this donut slice
|
|
88
|
-
return React.createElement(Cell, {
|
|
89
|
-
key: genUUID(),
|
|
90
|
-
fill: itemColor
|
|
91
|
-
});
|
|
92
|
-
})
|
|
93
|
-
),
|
|
94
|
-
!noTooltipOnHover && React.createElement(Tooltip, null)
|
|
95
|
-
)
|
|
96
|
-
)
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
DonutChart.propTypes = {
|
|
102
|
-
// Title of the chart
|
|
103
|
-
title: PropTypes.string,
|
|
104
|
-
// Default CSS color (#123456 or 'white') for slices (can be overridden)
|
|
105
|
-
// OR 'assortment' for random colors
|
|
106
|
-
color: PropTypes.string,
|
|
107
|
-
// Width ('100%' or 50)
|
|
108
|
-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
109
|
-
// Height ('100%' or 50)
|
|
110
|
-
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
111
|
-
// The data/slices
|
|
112
|
-
data: PropTypes.arrayOf(PropTypes.shape({
|
|
113
|
-
// Name of the slice
|
|
114
|
-
name: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
115
|
-
// Value of the slice (size)
|
|
116
|
-
value: PropTypes.number.isRequired,
|
|
117
|
-
// Color of the slice (overrides props.color)
|
|
118
|
-
color: PropTypes.string
|
|
119
|
-
})).isRequired,
|
|
120
|
-
// If true, no tooltip is shown on hover
|
|
121
|
-
noTooltipOnHover: PropTypes.bool,
|
|
122
|
-
// If true, legend is included
|
|
123
|
-
showLegend: PropTypes.bool,
|
|
124
|
-
// If true, no download button is shown
|
|
125
|
-
noDownload: PropTypes.bool
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
DonutChart.defaultProps = {
|
|
129
|
-
// Chart has no title by default
|
|
130
|
-
title: null,
|
|
131
|
-
// Donut slices get an assortment of colors by default
|
|
132
|
-
color: 'assortment',
|
|
133
|
-
// Chart takes up full parent width by default
|
|
134
|
-
width: '100%',
|
|
135
|
-
// Chart's height is 500px by default
|
|
136
|
-
height: '500px',
|
|
137
|
-
// Tooltips are displayed by default
|
|
138
|
-
noTooltipOnHover: false,
|
|
139
|
-
// No legend is included by default
|
|
140
|
-
showLegend: false,
|
|
141
|
-
// A download button is added by default
|
|
142
|
-
noDownload: false
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export default DonutChart;
|
package/lib/DownloadButton.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
|
|
4
|
-
// Import file download button
|
|
5
|
-
import DownloadLink from 'react-download-link';
|
|
6
|
-
|
|
7
|
-
// Import glyphs
|
|
8
|
-
import Download from './glyph/Download';
|
|
9
|
-
|
|
10
|
-
// Import bootstrap stylesheet
|
|
11
|
-
import 'bootstrap/dist/css/bootstrap.min.css';
|
|
12
|
-
|
|
13
|
-
/* Download Button Component */
|
|
14
|
-
class DownloadButton extends Component {
|
|
15
|
-
// Deconstruct props (see propTypes below for detailed information)
|
|
16
|
-
render() {
|
|
17
|
-
const {
|
|
18
|
-
text,
|
|
19
|
-
filename,
|
|
20
|
-
contents,
|
|
21
|
-
large,
|
|
22
|
-
marginLeft,
|
|
23
|
-
marginRight,
|
|
24
|
-
marginTop,
|
|
25
|
-
marginBottom
|
|
26
|
-
} = this.props;
|
|
27
|
-
|
|
28
|
-
// Render the component
|
|
29
|
-
return React.createElement(DownloadLink, {
|
|
30
|
-
filename: filename,
|
|
31
|
-
exportFile: () => {
|
|
32
|
-
return contents;
|
|
33
|
-
},
|
|
34
|
-
label: React.createElement(
|
|
35
|
-
'span',
|
|
36
|
-
null,
|
|
37
|
-
React.createElement(Download, { className: 'mr-2' }),
|
|
38
|
-
text
|
|
39
|
-
),
|
|
40
|
-
tagName: 'div',
|
|
41
|
-
className: `btn btn-dark text-white${large ? ' btn-lg' : ''}`,
|
|
42
|
-
style: {
|
|
43
|
-
textDecoration: 'none !important',
|
|
44
|
-
marginLeft,
|
|
45
|
-
marginRight,
|
|
46
|
-
marginTop,
|
|
47
|
-
marginBottom
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
DownloadButton.propTypes = {
|
|
54
|
-
// The title of the button
|
|
55
|
-
text: PropTypes.string,
|
|
56
|
-
// The filename of the download (the name the contents are downloaded as)
|
|
57
|
-
filename: PropTypes.string.isRequired,
|
|
58
|
-
// The contents of the file
|
|
59
|
-
contents: PropTypes.string.isRequired,
|
|
60
|
-
// If true, the button is a bootstrap large button
|
|
61
|
-
large: PropTypes.bool,
|
|
62
|
-
// Margins for the button
|
|
63
|
-
marginLeft: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
64
|
-
marginRight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
65
|
-
marginTop: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
66
|
-
marginBottom: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
DownloadButton.defaultProps = {
|
|
70
|
-
// Title of the button is 'Download' by default
|
|
71
|
-
text: 'Download',
|
|
72
|
-
// Button is a normal sized bootstrap button by default
|
|
73
|
-
large: false,
|
|
74
|
-
// Button has no margins by default
|
|
75
|
-
marginLeft: null,
|
|
76
|
-
marginRight: null,
|
|
77
|
-
marginTop: null,
|
|
78
|
-
marginBottom: null
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export default DownloadButton;
|