Skip to content

Commit 2d75b27

Browse files
committed
chore: backup old files, will be removed them when final version be ready
1 parent bccae41 commit 2d75b27

File tree

4 files changed

+349
-0
lines changed

4 files changed

+349
-0
lines changed

__old/.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"plugins": ["prettier"],
3+
"rules": {
4+
"prettier/prettier": "error"
5+
}
6+
}

__old/ChartBarSimple.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import { getColor } from '@coreui/utils'
4+
import { CChartBar } from '@coreui/react-chartjs'
5+
6+
const ChartBarSimple = (props) => {
7+
const {
8+
backgroundColor,
9+
pointHoverBackgroundColor,
10+
dataPoints,
11+
label,
12+
pointed,
13+
...attributes
14+
} = props
15+
16+
const defaultDatasets = {
17+
data: dataPoints,
18+
backgroundColor: getColor(backgroundColor),
19+
pointHoverBackgroundColor: getColor(pointHoverBackgroundColor),
20+
label: label,
21+
barPercentage: 0.5,
22+
categoryPercentage: 1,
23+
}
24+
25+
const defaultOptions = {
26+
maintainAspectRatio: false,
27+
plugins: {
28+
legend: {
29+
display: false,
30+
},
31+
},
32+
scales: {
33+
x: {
34+
grid: {
35+
display: false,
36+
drawTicks: false,
37+
},
38+
ticks: {
39+
display: false,
40+
},
41+
},
42+
y: {
43+
grid: {
44+
display: false,
45+
drawBorder: false,
46+
drawTicks: false,
47+
},
48+
ticks: {
49+
display: false,
50+
},
51+
},
52+
},
53+
}
54+
55+
// render
56+
return (
57+
<CChartBar
58+
{...attributes}
59+
data={defaultDatasets}
60+
// options={defaultOptions}
61+
// labels={label}
62+
/>
63+
)
64+
}
65+
66+
ChartBarSimple.propTypes = {
67+
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
68+
className: PropTypes.string,
69+
//
70+
backgroundColor: PropTypes.string,
71+
pointHoverBackgroundColor: PropTypes.string,
72+
dataPoints: PropTypes.array,
73+
label: PropTypes.string,
74+
pointed: PropTypes.bool,
75+
}
76+
77+
ChartBarSimple.defaultProps = {
78+
backgroundColor: 'rgba(0,0,0,.2)',
79+
dataPoints: [10, 22, 34, 46, 58, 70, 46, 23, 45, 78, 34, 12],
80+
label: 'Sales',
81+
}
82+
83+
export default ChartBarSimple

__old/ChartLineSimple.js

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import { getColor, getStyle, hexToRgba, deepObjectsMerge } from '@coreui/utils'
4+
5+
import { CChartLine } from '@coreui/react-chartjs'
6+
7+
const brandSuccess = getStyle('success') || '#4dbd74'
8+
const brandInfo = getStyle('info') || '#20a8d8'
9+
const brandDanger = getStyle('danger') || '#f86c6b'
10+
11+
const ChartLineSimple = (props) => {
12+
const {
13+
borderColor,
14+
backgroundColor,
15+
pointHoverBackgroundColor,
16+
dataPoints,
17+
label,
18+
pointed,
19+
...attributes
20+
} = props
21+
22+
const pointHoverColor = (() => {
23+
if (pointHoverBackgroundColor) {
24+
return pointHoverBackgroundColor
25+
} else if (backgroundColor !== 'transparent') {
26+
return backgroundColor
27+
}
28+
return borderColor
29+
})()
30+
31+
const defaultDatasets = (() => {
32+
return [
33+
{
34+
data: dataPoints,
35+
borderColor: getColor(borderColor),
36+
backgroundColor: getColor(backgroundColor),
37+
pointBackgroundColor: getColor(pointHoverColor),
38+
pointHoverBackgroundColor: getColor(pointHoverColor),
39+
label,
40+
},
41+
]
42+
})()
43+
44+
const pointedOptions = (() => {
45+
return {
46+
plugins: {
47+
legend: {
48+
display: false,
49+
},
50+
},
51+
maintainAspectRatio: false,
52+
scales: {
53+
x: {
54+
grid: {
55+
display: false,
56+
drawBorder: false,
57+
},
58+
ticks: {
59+
display: false,
60+
},
61+
},
62+
y: {
63+
display: false,
64+
grid: {
65+
display: false,
66+
},
67+
ticks: {
68+
display: false,
69+
},
70+
},
71+
},
72+
elements: {
73+
line: {
74+
borderWidth: 1,
75+
tension: 0.4,
76+
},
77+
point: {
78+
radius: 4,
79+
hitRadius: 10,
80+
hoverRadius: 4,
81+
},
82+
},
83+
}
84+
})()
85+
86+
const straightOptions = (() => {
87+
return {
88+
plugins: {
89+
legend: {
90+
display: false,
91+
},
92+
},
93+
maintainAspectRatio: false,
94+
scales: {
95+
x: {
96+
display: false,
97+
},
98+
y: {
99+
display: false,
100+
},
101+
},
102+
elements: {
103+
line: {
104+
borderWidth: 2,
105+
tension: 0.4,
106+
},
107+
point: {
108+
radius: 0,
109+
hitRadius: 10,
110+
hoverRadius: 4,
111+
},
112+
},
113+
}
114+
})()
115+
116+
const defaultOptions = (() => {
117+
const options = pointed ? pointedOptions : straightOptions
118+
return Object.assign({}, options, {
119+
maintainAspectRatio: false,
120+
legend: {
121+
display: false,
122+
},
123+
})
124+
})()
125+
126+
const computedDatasets = (() => {
127+
return deepObjectsMerge(defaultDatasets, attributes.datasets || {})
128+
})()
129+
130+
const computedOptions = (() => {
131+
return deepObjectsMerge(defaultOptions, attributes.options || {})
132+
})()
133+
134+
// render
135+
136+
return (
137+
<CChartLine
138+
{...attributes}
139+
datasets={computedDatasets}
140+
options={computedOptions}
141+
labels={label}
142+
/>
143+
)
144+
}
145+
146+
ChartLineSimple.propTypes = {
147+
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
148+
className: PropTypes.string,
149+
//
150+
borderColor: PropTypes.string,
151+
backgroundColor: PropTypes.string,
152+
pointHoverBackgroundColor: PropTypes.string,
153+
dataPoints: PropTypes.array,
154+
label: PropTypes.string,
155+
pointed: PropTypes.bool,
156+
}
157+
158+
ChartLineSimple.defaultProps = {
159+
borderColor: 'rgba(255,255,255,.55)',
160+
backgroundColor: 'transparent',
161+
dataPoints: [10, 22, 34, 46, 58, 70, 46, 23, 45, 78, 34, 12],
162+
label: 'Sales',
163+
}
164+
165+
export default ChartLineSimple

__old/MainChartExample.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React from 'react'
2+
import { CChartLine } from '@coreui/react-chartjs'
3+
import { getStyle, hexToRgba } from '@coreui/utils'
4+
5+
const brandSuccess = getStyle('success') || '#4dbd74'
6+
const brandInfo = getStyle('info') || '#20a8d8'
7+
const brandDanger = getStyle('danger') || '#f86c6b'
8+
9+
const MainChartExample = (attributes) => {
10+
const random = (min, max) => {
11+
return Math.floor(Math.random() * (max - min + 1) + min)
12+
}
13+
14+
let elements = 27
15+
const data1 = []
16+
const data2 = []
17+
const data3 = []
18+
19+
for (let i = 0; i <= elements; i++) {
20+
data1.push(random(50, 200))
21+
data2.push(random(80, 100))
22+
data3.push(65)
23+
}
24+
25+
const data = {
26+
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
27+
datasets: [
28+
{
29+
label: 'My First dataset',
30+
backgroundColor: hexToRgba(brandInfo, 10),
31+
borderColor: brandInfo,
32+
pointHoverBackgroundColor: brandInfo,
33+
borderWidth: 2,
34+
data: data1,
35+
fill: true,
36+
},
37+
{
38+
label: 'My Second dataset',
39+
backgroundColor: 'transparent',
40+
borderColor: brandSuccess,
41+
pointHoverBackgroundColor: brandSuccess,
42+
borderWidth: 2,
43+
data: data2,
44+
},
45+
{
46+
label: 'My Third dataset',
47+
backgroundColor: 'transparent',
48+
borderColor: brandDanger,
49+
pointHoverBackgroundColor: brandDanger,
50+
borderWidth: 1,
51+
borderDash: [8, 5],
52+
data: data3,
53+
},
54+
],
55+
}
56+
57+
const options = {
58+
maintainAspectRatio: false,
59+
plugins: {
60+
legend: {
61+
display: false,
62+
},
63+
},
64+
scales: {
65+
x: {
66+
grid: {
67+
drawOnChartArea: false,
68+
},
69+
},
70+
y: {
71+
ticks: {
72+
beginAtZero: true,
73+
maxTicksLimit: 5,
74+
stepSize: Math.ceil(250 / 5),
75+
max: 250,
76+
},
77+
},
78+
},
79+
elements: {
80+
line: {
81+
tension: 0.4,
82+
},
83+
point: {
84+
radius: 0,
85+
hitRadius: 10,
86+
hoverRadius: 4,
87+
hoverBorderWidth: 3,
88+
},
89+
},
90+
}
91+
92+
return <CChartLine data={data} options={options} {...attributes} />
93+
}
94+
95+
export default MainChartExample

0 commit comments

Comments
 (0)