Skip to content

Commit 6f1dee3

Browse files
committed
v2 initial commit
1 parent 1b458a6 commit 6f1dee3

21 files changed

+10386
-14231
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = false
12+
insert_final_newline = false

.eslinignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"ignorePatterns": [".eslintrc.js", ".docz/**/*"]
3+
}

.eslintrc.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
3+
parserOptions: {
4+
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
5+
sourceType: 'module', // Allows for the use of imports
6+
ecmaFeatures: {
7+
jsx: true, // Allows for the parsing of JSX
8+
},
9+
},
10+
settings: {
11+
react: {
12+
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
13+
},
14+
},
15+
extends: [
16+
'plugin:jsdoc/recommended',
17+
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
18+
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
19+
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
20+
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
21+
],
22+
plugins: ['jsdoc', '@typescript-eslint', 'react', 'react-hooks'],
23+
// rules: {
24+
// // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
25+
// // e.g. "@typescript-eslint/explicit-function-return-type": "off",
26+
// 'react/prop-types': 'off',
27+
// },
28+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ node_modules
1111
/coverage
1212

1313
# production
14+
/dist
1415
/es
1516
/lib
1617
/umd

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

.prettierrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
semi: false,
3+
trailingComma: "all",
4+
singleQuote: true,
5+
printWidth: 100,
6+
tabWidth: 2
7+
};

NWB.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

__old/CChart.js

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
import React, { useState, useEffect, useRef, useMemo } from "react";
2+
import PropTypes from "prop-types";
3+
import {
4+
Chart,
5+
ArcElement,
6+
LineElement,
7+
BarElement,
8+
PointElement,
9+
BarController,
10+
BubbleController,
11+
DoughnutController,
12+
LineController,
13+
PieController,
14+
PolarAreaController,
15+
RadarController,
16+
ScatterController,
17+
CategoryScale,
18+
LinearScale,
19+
LogarithmicScale,
20+
RadialLinearScale,
21+
TimeScale,
22+
TimeSeriesScale,
23+
Decimation,
24+
Filler,
25+
Legend,
26+
Title,
27+
Tooltip,
28+
} from "chart.js";
29+
import { customTooltips as cuiCustomTooltips } from "@coreui/chartjs";
30+
import "@coreui/chartjs/dist/css/coreui-chartjs.css";
31+
32+
Chart.register(
33+
ArcElement,
34+
LineElement,
35+
BarElement,
36+
PointElement,
37+
BarController,
38+
BubbleController,
39+
DoughnutController,
40+
LineController,
41+
PieController,
42+
PolarAreaController,
43+
RadarController,
44+
ScatterController,
45+
CategoryScale,
46+
LinearScale,
47+
LogarithmicScale,
48+
RadialLinearScale,
49+
TimeScale,
50+
TimeSeriesScale,
51+
Decimation,
52+
Filler,
53+
Legend,
54+
Title,
55+
Tooltip
56+
);
57+
58+
const months = [
59+
"January",
60+
"February",
61+
"March",
62+
"April",
63+
"May",
64+
"June",
65+
"July",
66+
"August",
67+
"September",
68+
"October",
69+
"November",
70+
"December",
71+
];
72+
const key = () => Math.random().toString(36).replace("0.", "");
73+
74+
//component - CoreUI / CChart
75+
const CChart = (props) => {
76+
const {
77+
innerRef,
78+
datasets,
79+
labels,
80+
options,
81+
plugins,
82+
type,
83+
...attributes
84+
} = props;
85+
86+
const compData = useRef({ firstRun: true }).current;
87+
const [chart, setChart] = useState();
88+
const ref = useRef();
89+
const safeId = useState("safe_id_" + key())[0];
90+
91+
// methods
92+
const renderChart = () => {
93+
destroyChart();
94+
setChart(new Chart(ref.current.getContext("2d"), chartConfig));
95+
};
96+
97+
const updateChart = () => {
98+
Object.assign(chart, chartConfig);
99+
chart.update();
100+
};
101+
102+
const destroyChart = () => chart && chart.destroy();
103+
104+
const dataset = (datasets && datasets[0] && datasets[0].data) || [];
105+
106+
const computedLabels = useMemo(() => {
107+
if (labels && typeof labels !== "string") {
108+
return labels;
109+
}
110+
const emptyLabels = Array(dataset.length).fill("");
111+
if (labels === "indexes") {
112+
return emptyLabels.map((u, i) => i + 1);
113+
} else if (labels === "months") {
114+
return emptyLabels.map((u, i) => months[i % 12]);
115+
}
116+
return emptyLabels;
117+
}, [JSON.stringify(labels), dataset.length]);
118+
119+
const customTooltips = (() => {
120+
if (options && options.tooltips) {
121+
return;
122+
}
123+
return {
124+
tooltips: {
125+
enabled: false,
126+
custom: cuiCustomTooltips,
127+
intersect: true,
128+
mode: "index",
129+
position: "nearest",
130+
callbacks: {
131+
labelColor(tooltipItem, chart) {
132+
function getValue(prop) {
133+
return typeof prop === "object" ? prop[tooltipItem.index] : prop;
134+
}
135+
136+
const dataset = chart.data.datasets[tooltipItem.datasetIndex];
137+
//tooltipLabelColor is coreUI custom prop used only here
138+
const backgroundColor = getValue(
139+
dataset.tooltipLabelColor ||
140+
dataset.pointHoverBackgroundColor ||
141+
dataset.borderColor ||
142+
dataset.backgroundColor
143+
);
144+
return {
145+
backgroundColor,
146+
};
147+
},
148+
},
149+
},
150+
};
151+
})();
152+
153+
const computedOptions = (() => {
154+
return Object.assign({}, options, customTooltips || {});
155+
})();
156+
157+
const chartConfig = {
158+
type,
159+
data: {
160+
datasets,
161+
labels: computedLabels,
162+
},
163+
options: computedOptions,
164+
plugins,
165+
};
166+
167+
useEffect(() => {
168+
if (compData.firstRun) return;
169+
updateChart();
170+
}, [chartConfig]);
171+
172+
useEffect(() => {
173+
renderChart();
174+
compData.firstRun = false;
175+
return () => destroyChart();
176+
}, []);
177+
178+
return (
179+
<div {...attributes} ref={innerRef}>
180+
<canvas id={safeId} ref={ref} />
181+
</div>
182+
);
183+
};
184+
185+
CChart.propTypes = {
186+
innerRef: PropTypes.oneOfType([
187+
PropTypes.object,
188+
PropTypes.func,
189+
PropTypes.string,
190+
]),
191+
datasets: PropTypes.array,
192+
labels: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
193+
options: PropTypes.object,
194+
plugins: PropTypes.array,
195+
type: PropTypes.string,
196+
};
197+
198+
const CChartBar = (props) => <CChart {...props} type="bar" />;
199+
const CChartHorizontalBar = (props) => (
200+
<CChart {...props} type="horizontalBar" />
201+
);
202+
const CChartLine = (props) => <CChart {...props} type="line" />;
203+
const CChartDoughnut = (props) => <CChart {...props} type="doughnut" />;
204+
const CChartRadar = (props) => <CChart {...props} type="radar" />;
205+
const CChartPie = (props) => <CChart {...props} type="pie" />;
206+
const CChartPolarArea = (props) => <CChart {...props} type="polarArea" />;
207+
const CCharts = (props) => {
208+
console.warn(
209+
"<CCharts> component has been deprecated. Use <CChart> or <CChart{type}> instead"
210+
);
211+
return <CChart {...props} />;
212+
};
213+
214+
export {
215+
CChart,
216+
CCharts,
217+
CChartBar,
218+
CChartHorizontalBar,
219+
CChartLine,
220+
CChartDoughnut,
221+
CChartRadar,
222+
CChartPie,
223+
CChartPolarArea,
224+
};
File renamed without changes.
File renamed without changes.

link.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

nwb.config.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)