Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5e4e5ca

Browse files
committed
refactor(CCharts): cleanup
1 parent35a26d7 commit5e4e5ca

File tree

2 files changed

+47
-114
lines changed

2 files changed

+47
-114
lines changed

‎src/CCharts.js‎

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import'react-app-polyfill/ie11';// For IE 11 support
2-
import'react-app-polyfill/stable';
3-
importReact,{useState,useEffect,useRef,useMemo}from'react';
1+
importReact,{useState,useEffect,useRef,useMemo}from'react';
42
importPropTypesfrom'prop-types';
5-
importChartfrom'chart.js'
6-
import{customTooltipsascuiCustomTooltips}from'@coreui/chartjs'
7-
import"@coreui/chartjs/dist/css/coreui-chartjs.css";
3+
importChartfrom'chart.js';
4+
import{customTooltipsascuiCustomTooltips}from'@coreui/chartjs';
5+
import'@coreui/chartjs/dist/css/coreui-chartjs.css';
86

97
//component - CoreUI / CCharts
108

11-
constCCharts=props=>{
9+
constCCharts=props=>{
1210

1311
const{
1412
//
@@ -23,7 +21,7 @@ const CCharts = props=>{
2321

2422
//console.log(Chart);
2523

26-
constcompData=useRef({firstRun:true}).current;
24+
constcompData=useRef({firstRun:true}).current;
2725
const[chart,setChart]=useState();
2826
constref=useRef();
2927

@@ -32,58 +30,58 @@ const CCharts = props=>{
3230

3331
// methods
3432

35-
constrenderChart=()=>{
36-
destroyChart()
33+
constrenderChart=()=>{
34+
destroyChart();
3735
setChart(newChart(
3836
ref.current.getContext('2d'),
3937
chartConfig
40-
))
41-
}
42-
constupdateChart=()=>{
43-
Object.assign(chart,chartConfig)
44-
chart.update()
45-
}
46-
constdestroyChart=()=>{
38+
));
39+
};
40+
constupdateChart=()=>{
41+
Object.assign(chart,chartConfig);
42+
chart.update();
43+
};
44+
constdestroyChart=()=>{
4745
if(chart){
48-
chart.destroy()
46+
chart.destroy();
4947
}
50-
}
48+
};
5149

5250
// vars
5351

5452
const_uid='';
55-
constsafeId=(()=>{
53+
constsafeId=(()=>{
5654
// as long as this._uid() works there is no need to generate the key
57-
constkey=()=>Math.random().toString(36).replace('0.','')
58-
return'__safe_id__'+(_uid||key())
55+
constkey=()=>Math.random().toString(36).replace('0.','');
56+
return'__safe_id__'+(_uid||key());
5957
})();
60-
constcomputedDatasets=(()=>{
61-
returndatasets
58+
constcomputedDatasets=(()=>{
59+
returndatasets;
6260
})();
6361
//
64-
constcomputedLabels=(()=>{
62+
constcomputedLabels=(()=>{
6563
if(labels&&typeoflabels!=='string'){
66-
returnlabels
64+
returnlabels;
6765
}elseif(!datasets||!datasets[0]||!datasets[0].data){
68-
return[]
66+
return[];
6967
}
70-
constemptyLabels=Array(datasets[0].data.length).fill('')
68+
constemptyLabels=Array(datasets[0].data.length).fill('');
7169
if(labels==='indexes'){
72-
returnemptyLabels.map((u,i)=>i+1)
70+
returnemptyLabels.map((u,i)=>i+1);
7371
}elseif(labels==='months'){
74-
returnemptyLabels.map((u,i)=>months[i%12])
72+
returnemptyLabels.map((u,i)=>months[i%12]);
7573
}
76-
returnemptyLabels
74+
returnemptyLabels;
7775
})();
78-
constcomputedData=(()=>{
76+
constcomputedData=(()=>{
7977
return{
8078
datasets:computedDatasets,
8179
labels:computedLabels
82-
}
80+
};
8381
})();
84-
constcustomTooltips=(()=>{
82+
constcustomTooltips=(()=>{
8583
if(options&&options.tooltips){
86-
return
84+
return;
8785
}
8886
return{
8987
tooltips:{
@@ -95,52 +93,52 @@ const CCharts = props=>{
9593
callbacks:{
9694
labelColor(tooltipItem,chart){
9795
functiongetValue(prop){
98-
returntypeofprop==='object' ?prop[tooltipItem.index] :prop
96+
returntypeofprop==='object' ?prop[tooltipItem.index] :prop;
9997
}
100-
constdataset=chart.data.datasets[tooltipItem.datasetIndex]
98+
99+
constdataset=chart.data.datasets[tooltipItem.datasetIndex];
101100
//tooltipLabelColor is coreUI custom prop used only here
102101
constbackgroundColor=getValue(
103102
dataset.tooltipLabelColor||
104103
dataset.pointHoverBackgroundColor||
105104
dataset.borderColor||
106105
dataset.backgroundColor
107-
)
106+
);
108107
return{
109108
backgroundColor
110-
}
109+
};
111110
}
112111
}
113112
}
114-
}
113+
};
115114
})();
116-
constcomputedOptions=(()=>{
117-
returnObject.assign({},options,customTooltips||{})
115+
constcomputedOptions=(()=>{
116+
returnObject.assign({},options,customTooltips||{});
118117
})();
119-
constchartConfig=(()=>{
118+
constchartConfig=(()=>{
120119
return{
121120
type:type,
122121
data:computedData,
123122
options:computedOptions||options,
124123
plugins:plugins
125-
}
124+
};
126125
})();
127126

128127
//watch
129128

130129
//chartConfig
131-
useMemo(()=>{
130+
useMemo(()=>{
132131
if(compData.firstRun)return;
133132
updateChart();
134133
},[chartConfig]);
135134

136-
137135
// effect
138136

139137
useEffect(()=>{
140138
renderChart();
141139
compData.firstRun=false;
142140
return()=>{
143-
destroyChart()
141+
destroyChart();
144142
};
145143
},[]);
146144

@@ -152,7 +150,7 @@ const CCharts = props=>{
152150
</div>
153151
);
154152

155-
}
153+
};
156154

157155
CCharts.propTypes={
158156
//
@@ -164,7 +162,6 @@ CCharts.propTypes = {
164162
type:PropTypes.string
165163
};
166164

167-
CCharts.defaultProps={
168-
};
165+
CCharts.defaultProps={};
169166

170167
exportdefaultCCharts;

‎src/CCharts2.js‎

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp