@@ -6,22 +6,15 @@ import { PieChartComp, BarChartComp } from "../components/charts/";
66import { ResponsiveContainer } from "recharts" ;
77import { mockRepoData } from "../mock" ;
88import { langColors } from "../util" ;
9- // import { error } from "console";
10- // const Charts = ({ repostarChartData }) => {
11-
12- // Create Most Starred chart
139
1410const Charts = ( { repoData } ) => {
1511 // const Charts = () => {
1612 const ChartWidth = 300 ;
1713 const ChartHeight = 300 ;
18- // const [starChartData, setStarChartData] = useState([{}]);
1914 const [ starChartConfig , setStarChartConfig ] = useState ( { } ) ;
20- // const [langChartData, setLangChartData] = useState([{}]);
2115 const [ langChartConfig , setLangChartConfig ] = useState ( { } ) ;
2216 const [ langStarChartConfig , setLangStarChartConfig ] = useState ( { } ) ;
2317
24- // const repoData = mockRepoData;
2518 const initStarChart = ( ) => {
2619 const LIMIT = 5 ;
2720 const sortProperty = "stargazers_count" ;
@@ -36,9 +29,6 @@ const Charts = ({ repoData }) => {
3629 data . push ( { name : labels [ i ] , stars : stars [ i ] } ) ;
3730 }
3831
39- console . log ( data ) ;
40- // setStarChartData(data);
41-
4232 if ( data . length > 0 ) {
4333 const width = ChartWidth ;
4434 const height = ChartHeight ;
@@ -63,10 +53,7 @@ const Charts = ({ repoData }) => {
6353 YKey,
6454 BarTPColor,
6555 } ;
66- console . log ( starBarChartConfig ) ;
6756 setStarChartConfig ( starBarChartConfig ) ;
68- console . log ( starBarChartConfig ) ;
69- // console.log(starBarChartConfig);
7057 }
7158 } ;
7259
@@ -124,15 +111,6 @@ const Charts = ({ repoData }) => {
124111 } ;
125112
126113 const colorsArr = ( langData ) => {
127- // let colors = Array.from(langData, ({ key, value, color }) => color);
128- // colors = colors.map(v => (v === undefined ? getRandomColor() : v));
129- // colors = colors.filter(x => x !== undefined);
130- // colors = colors.map(color => {
131- // var len = color == null ? 0 : color.length;
132- // if (len > 0) {
133- // return `#${len > 4 ? color.slice(1) : color.slice(1).repeat(2)}FF`;
134- // }
135- // });
136114 return Array . from ( langData , ( { key, value, color } ) => color )
137115 . map ( ( v ) => ( v === undefined ? getRandomColor ( ) : v ) )
138116 . filter ( ( x ) => x !== undefined )
@@ -146,20 +124,9 @@ const Charts = ({ repoData }) => {
146124
147125 const initLangChart = ( ) => {
148126 const langData = getLangData ( repoData ) ;
149- // setLangChartData(langData);
150127 const labels = langData . map ( ( lang ) => lang . label ) ;
151128 const data = langData ;
152- // const borderColor = labels.map((label) => {
153- // if (langColors[label.toLowerCase()] !== undefined) {
154- // return langColors[label.toLowerCase()];
155- // } else {
156- // return getRandomColor();
157- // }
158- // });
159- // const sectorColors = borderColor.map((color) => `${color}FF`);
160-
161129 const sectorColors = colorsArr ( langData ) ;
162- // setLangChartData(data);
163130
164131 if ( data . length > 0 ) {
165132 const width = ChartWidth ;
@@ -198,10 +165,7 @@ const Charts = ({ repoData }) => {
198165 }
199166 } ;
200167
201- // Create Stars per language chart
202- // const [thirdChartData, setThirdChartData] = useState(null);
203168 const initLangStarChart = ( ) => {
204- // const ctx = document.getElementById("thirdChart");
205169 const filteredRepos = repoData . filter (
206170 ( repo ) => ! repo . fork && repo . stargazers_count > 0
207171 ) ;
@@ -214,15 +178,6 @@ const Charts = ({ repoData }) => {
214178 return { lang : lang , repos : starSum } ;
215179 } ) ;
216180
217- // const langData = getLangData(repoData);
218- // setLangChartData(langData);
219- // const labels = langData.map((lang) => lang.label);
220- // const data = langData;
221- // const sectorColors = colorsArr(langData);
222- // setLangChartData(data);
223-
224- // setThirdChartData(data);
225-
226181 if ( data . length > 0 ) {
227182 console . log ( "third chart data:" , data ) ;
228183 const borderColor = labels . map ( ( label ) => {
@@ -263,22 +218,8 @@ const Charts = ({ repoData }) => {
263218 label,
264219 sectorColors,
265220 } ;
266- // console.log("langChartConfig - ", pieChartConfig);
221+
267222 setLangStarChartConfig ( pieChartConfig ) ;
268- // console.log("langChartConfig - ", pieChartConfig);
269- // console.log(backgroundColor)
270- // const config = {
271- // ctx,
272- // chartType,
273- // labels,
274- // data,
275- // backgroundColor,
276- // borderColor,
277- // axes,
278- // legend,
279- // };
280- // console.log(config);
281- // buildChart(config);
282223 }
283224 } ;
284225
@@ -287,9 +228,6 @@ const Charts = ({ repoData }) => {
287228 initStarChart ( ) ;
288229 initLangChart ( ) ;
289230 initLangStarChart ( ) ;
290- // console.log(starChartData);
291- // console.log(langChartData);
292- // initThirdChart();
293231 }
294232 } , [ ] ) ;
295233
@@ -328,14 +266,8 @@ const Charts = ({ repoData }) => {
328266 </ header >
329267
330268 < div className = "chart-container" >
331- { /* <BarChartComp config={starBarChartConfig} /> */ }
332- { /* {starBarChartConfig.starChartData && ( */ }
333269 { starChartError && < p > Not Enough Data!</ p > }
334270 < BarChartComp config = { starChartConfig } />
335- { /* )} */ }
336-
337- { /* {langChartError && <p>Nothing to see here!</p>} */ }
338- { /* <canvas id="langChart" width={chartSize} height={chartSize} /> */ }
339271 </ div >
340272 </ div >
341273 < div className = "chart" >
@@ -344,12 +276,8 @@ const Charts = ({ repoData }) => {
344276 </ header >
345277
346278 < div className = "chart-container" >
347- { /* <PieChartComp /> */ }
348279 { langChartError && < p > Not Enough Data!</ p > }
349280 < PieChartComp config = { langStarChartConfig } />
350-
351- { /* {langChartError && <p>Nothing to see here!</p>} */ }
352- { /* <canvas id="langChart" width={chartSize} height={chartSize} /> */ }
353281 </ div >
354282 </ div >
355283 </ ChartsStyles >
0 commit comments