Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 954f0a1

Browse files
tharun571BLNDLYBLVbestinbthomas
authored
Update graph in leaderboard (#70)
* Update graph in leaderboard * Fix leaderboard graphs UI * Hide Extra markers/Show total points only * Remove markers in X-Axis * Alphabetize code, Change var to let * Aligned leaderboard elements and added winning streak * Change color of Graph, Icons * Aligned name coloumn to left and made page more responsive * Update package.json * Update config.yml * Update Register.tsx * fixed react-flags-select * Update config.yml * Fix react-flags-select package related errors Co-authored-by: Sriram <sriram01201@gmail.com> Co-authored-by: Bestin B Thomas <Bestinbthomas@gmail.com>
1 parent dd45d36 commit 954f0a1

File tree

10 files changed

+216
-141
lines changed

10 files changed

+216
-141
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
command: cp ./src/config/config.example.ts ./src/config/config.ts
5252
- run:
5353
name: build
54-
command: npm run build
54+
command: mkdir build && npm run build
5555

5656
workflows:
5757
version: 2

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
"react-bootstrap": "^0.32.4",
153153
"react-country-flag": "^1.0.1",
154154
"react-dom": "^16.5.2",
155-
"react-flags-select": "^1.1.10",
155+
"react-flags-select": "2.1.2",
156156
"react-ga": "^2.7.0",
157157
"react-google-recaptcha": "^1.0.5",
158158
"react-joyride": "^2.2.1",

src/app/components/Authentication/Register.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import * as React from 'react';
1313
import { Col, Row } from 'react-bootstrap';
1414
// tslint:disable-next-line:import-name
1515
import ReactFlagsSelect from 'react-flags-select';
16-
import 'react-flags-select/css/react-flags-select.css';
1716
// tslint:disable-next-line:import-name
1817
import ReCAPTCHA from 'react-google-recaptcha';
1918
import { NavLink, Redirect } from 'react-router-dom';
@@ -350,10 +349,10 @@ export class Register extends React.Component<RegisterInterfaces.Props, Register
350349
<div className={classnames(authStyles['login-label'])}> Your country </div>
351350
<div className={classnames(registerStyles['input-group'])}>
352351
<ReactFlagsSelect
352+
selected="IN"
353353
searchable={true}
354354
placeholder="Search for a country"
355355
className={classnames(authStyles.customFlag)}
356-
defaultCountry="IN"
357356
onSelect={this.onSelectFlag}
358357
/>
359358

src/app/components/Leaderboard/IconElement.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import * as React from 'react';
1212
// tslint:disable-next-line
1313
export const IconsComponent = ({ player }: any) => {
1414
return (
15-
<div style={{ fontSize: '1.5rem' }}>
15+
<div style={{ fontSize: '1.5rem', color: 'light-gray' }}>
1616
<div
1717
className={classnames(styles['leader-score_title'])}
1818
style={{
19-
color: 'gray',
19+
color: 'light-gray',
2020
display: 'block',
2121
fontSize: '26px',
2222
left: '35%',
23+
lineHeight: '2',
2324
marginTop: '5px',
2425
position: 'absolute',
2526
textAlign: 'center',
@@ -41,26 +42,29 @@ export const IconsComponent = ({ player }: any) => {
4142
icon={faTrophy}
4243
className={classnames(styles.trophy)}
4344
aria-hidden="true"
45+
color="#00e396"
4446
/>
45-
<p style={{ color: 'grey' }}>{player.wins}</p>
47+
<p style={{ color: 'light-gray' }}>{player.wins}</p>
4648
</div>
4749
<div style={{ position: 'absolute', left: '68%', top: '15px', textAlign: 'center' }}>
4850
<FontAwesomeIcon
4951
title="Tied"
5052
icon={faHandshake}
5153
className={classnames(styles.handshake)}
5254
aria-hidden="true"
55+
color="#008ffb"
5356
/>
54-
<p style={{ color: 'grey' }}>{player.ties}</p>
57+
<p style={{ color: 'light-gray' }}>{player.ties}</p>
5558
</div>
5659
<div style={{ position: 'absolute', left: '85%', top: '15px', textAlign: 'center' }}>
5760
<FontAwesomeIcon
5861
title="Lost"
5962
icon={faThumbsDown}
6063
className={classnames(styles.thumbdown)}
6164
aria-hidden="true"
65+
color="#feb019"
6266
/>
63-
<p style={{ color: 'grey' }}>{player.losses}</p>
67+
<p style={{ color: 'light-gray' }}>{player.losses}</p>
6468
</div>
6569
</div>
6670
);

src/app/components/Leaderboard/LeaderboardElement.tsx

+102-72
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Avatar, avatarName } from 'app/types/Authentication/Register';
66
import { Request } from 'app/types/code/Submission';
77
import * as LeaderboardInterfaces from 'app/types/Leaderboard';
88
import classnames from 'classnames';
9+
// import { type } from 'os';
910
import * as React from 'react';
1011
/* tslint:disable-next-line:import-name */
1112
import Chart from 'react-apexcharts';
@@ -22,8 +23,6 @@ export class LeaderboardElement extends React.Component<
2223
isModelOpen: boolean;
2324
onHover: boolean;
2425
optionsPie: object;
25-
optionsLine: object;
26-
series: object;
2726
}
2827
> {
2928
// tslint:disable-next-line
@@ -32,41 +31,7 @@ export class LeaderboardElement extends React.Component<
3231
this.state = {
3332
isModelOpen: false,
3433
onHover: false,
35-
optionsLine: {
36-
chart: {
37-
foreColor: 'gray',
38-
height: 40,
39-
id: 'basic-bar',
40-
toolbar: {
41-
show: false,
42-
},
43-
zoom: {
44-
enabled: false,
45-
},
46-
},
47-
dataLabels: {
48-
enabled: false,
49-
markers: {
50-
colors: ['rgb(0, 143, 251)', 'rgb(0, 227, 150)', 'rgb(254, 176, 25)'],
51-
},
52-
style: {
53-
colors: ['#000000', '#000000', '#000000'],
54-
},
55-
},
56-
markers: {
57-
hover: {
58-
size: '5',
59-
sizeOffset: '0',
60-
},
61-
size: '5',
62-
},
63-
stroke: {
64-
curve: 'smooth',
65-
},
66-
xaxis: {
67-
categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998],
68-
},
69-
},
34+
7035
optionsPie: {
7136
chart: {
7237
foreColor: 'gray',
@@ -98,33 +63,9 @@ export class LeaderboardElement extends React.Component<
9863
},
9964
},
10065
},
101-
series: {
102-
data: [30, 40, 45, 50, 49, 60, 70, 91],
103-
name: 'series-1',
104-
},
10566
};
10667
}
10768

108-
public componentDidMount() {
109-
const { player } = this.props;
110-
const ratingArray: number[] = [];
111-
const labelArray: string[] = [];
112-
player.rating.forEach((element) => {
113-
ratingArray.push(Math.round(element.rating * 100) / 100);
114-
const dateobj = new Date(element.validFrom);
115-
labelArray.push(dateobj.toLocaleDateString('en-GB').substr(0, 5));
116-
});
117-
this.setState((prevState) => ({ series: { ...prevState.series, data: ratingArray } }));
118-
this.setState((prevState) => ({
119-
optionsLine: {
120-
...prevState.optionsLine,
121-
xaxis: {
122-
categories: labelArray,
123-
},
124-
},
125-
}));
126-
}
127-
12869
public handleOnClick = () => {
12970
this.setState((prevState, props) => ({
13071
isModelOpen: !prevState.isModelOpen,
@@ -152,6 +93,92 @@ export class LeaderboardElement extends React.Component<
15293
updatePlayerId2,
15394
updateRequest,
15495
} = this.props;
96+
const ratingArray: number[] = [];
97+
const labelArray: string[] = [];
98+
let tempDate = '';
99+
let prevRate = 0;
100+
let maxWinningStreak = 0;
101+
let curWinningStreak = 0;
102+
let currentRate = 0;
103+
player.rating.forEach((element) => {
104+
currentRate = Math.round(element.rating * 100) / 100;
105+
ratingArray.push(currentRate);
106+
107+
if (currentRate > prevRate) {
108+
curWinningStreak += 1;
109+
} else {
110+
if (curWinningStreak > maxWinningStreak) {
111+
maxWinningStreak = curWinningStreak;
112+
curWinningStreak = 0;
113+
}
114+
}
115+
prevRate = currentRate;
116+
117+
let realDate = '';
118+
const dateobj = new Date(element.validFrom);
119+
realDate = dateobj.toLocaleDateString('en-GB').substr(0, 5);
120+
if (realDate === tempDate) {
121+
labelArray.push(' ');
122+
} else {
123+
tempDate = realDate;
124+
labelArray.push(realDate);
125+
}
126+
});
127+
const series = { data: ratingArray, name: 'Points' };
128+
const optionsLine = {
129+
chart: {
130+
foreColor: 'gray',
131+
height: 40,
132+
id: 'basic-bar',
133+
toolbar: {
134+
show: false,
135+
},
136+
zoom: {
137+
enabled: false,
138+
},
139+
},
140+
dataLabels: {
141+
enabled: false,
142+
markers: {
143+
colors: ['rgb(0, 143, 251)', 'rgb(0, 227, 150)', 'rgb(254, 176, 25)'],
144+
},
145+
style: {
146+
colors: ['#000000', '#000000', '#000000'],
147+
},
148+
},
149+
markers: {
150+
hover: {
151+
size: '0',
152+
sizeOffset: '0',
153+
},
154+
size: '0',
155+
},
156+
stroke: {
157+
curve: 'smooth',
158+
},
159+
xaxis: {
160+
axisBorder: {
161+
color: '#000',
162+
show: true,
163+
},
164+
axisTicks: {
165+
show: false,
166+
},
167+
categories: labelArray,
168+
labels: {
169+
style: {
170+
colors: 'rgb(255,255,255)',
171+
},
172+
},
173+
},
174+
yaxis: {
175+
labels: {
176+
style: {
177+
colors: 'rgb(255,255,255)',
178+
},
179+
},
180+
},
181+
};
155182
return (
156183
<Col
157184
md={26}
@@ -193,6 +220,7 @@ export class LeaderboardElement extends React.Component<
193220
style={{
194221
color: colors[player.rank],
195222
marginLeft: '4px',
223+
marginRight: '0px',
196224
position: 'relative',
197225
top: '20%',
198226
}}
@@ -210,7 +238,7 @@ export class LeaderboardElement extends React.Component<
210238
marginLeft: '4px',
211239
}}
212240
className={classnames(
213-
player.rank <= 10 ? styles['leader-ava'] : styles['leader-ava-l'],
241+
player.rank <= 9 ? styles['leader-ava'] : styles['leader-ava-l'],
214242
)}
215243
>
216244
{player.rank}
@@ -279,6 +307,10 @@ export class LeaderboardElement extends React.Component<
279307
width={30}
280308
height={30}
281309
className="mr-3"
310+
style={{
311+
filter:
312+
' invert(14%) sepia(3%) saturate(68960%) hue-rotate(320deg) brightness(102%) contrast(110%)',
313+
}}
282314
onClickCapture={async (e) => {
283315
// hello
284316
e.stopPropagation();
@@ -303,26 +335,24 @@ export class LeaderboardElement extends React.Component<
303335
>
304336
{this.state.isModelOpen ? (
305337
<div
306-
className="row justify-content-center"
338+
className={classnames(styles.chart_holder, 'row', 'justify-content-center')}
307339
onClick={(event) => {
308340
event.stopPropagation();
309341
}}
310342
>
311-
<div className={classnames(styles.chart_div, 'col col-lg-5')}>
343+
<div className={classnames(styles.chart_div, styles.pie_chart)}>
312344
<Chart
313345
options={this.state.optionsPie}
314346
series={[player.ties, player.wins, player.losses]}
315347
type="donut"
316-
width="380"
348+
width="400"
317349
/>
350+
<div className={classnames(styles.winning_streak)}>
351+
Highest winning streak: {maxWinningStreak}
352+
</div>
318353
</div>
319-
<div className={classnames(styles.chart_div, 'col-lg-5')}>
320-
<Chart
321-
options={this.state.optionsLine}
322-
series={[this.state.series]}
323-
type="line"
324-
width="500"
325-
/>
354+
<div className={classnames(styles.chart_div)}>
355+
<Chart options={optionsLine} series={[series]} type="line" width="760" />
326356
</div>
327357
</div>
328358
) : null}

0 commit comments

Comments
 (0)