Skip to content

Commit

Permalink
char colors fix
Browse files Browse the repository at this point in the history
  • Loading branch information
furknyavuz committed Aug 29, 2021
1 parent 8d4aab6 commit 8d372ef
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class CreateEventComponent implements OnInit {
searchedEvents = [];

defaultCategory: any = {
category: { name: 'Teaching & Academics', id: 13 },
subCategory: { name: 'Online Education', id: 5 },
category: { name: 'Development', id: 1 },
subCategory: { name: 'Web Development', id: 1 },
leafCategory: undefined
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<br/>
<ngx-charts-bar-horizontal
[gradient]="gradient"
[customColors]="barCustomColors(lessonsInfo)"
[customColors]="colors"
[animations]="false"
[legend]="showLegend"
[results]="eventsInfo"
Expand Down Expand Up @@ -167,7 +167,7 @@ <h3 class="dim">No results found</h3>
<br/>
<ngx-charts-bar-horizontal
[gradient]="gradient"
[customColors]="barCustomColors(eventsInfo)"
[customColors]="colors"
[animations]="false"
[legend]="showLegend"
[results]="eventsInfo"
Expand Down
66 changes: 24 additions & 42 deletions src/app/page/dashboard-layout/my-profile/my-profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import { ThemeService } from '../../../service/theme/theme.service';
import { UserActivityService } from '../../../service/user-activity/user-activity.service';
import { PROFILE_IMG, URLS } from '../../../util/constant';

@Component({
@Component( {
selector: 'app-my-profile',
templateUrl: './my-profile.component.html',
styleUrls: ['./my-profile.component.scss']
})
styleUrls: [ './my-profile.component.scss' ]
} )
export class MyProfileComponent implements OnDestroy {

currentUser: AuthToken;
Expand All @@ -31,7 +31,6 @@ export class MyProfileComponent implements OnDestroy {
loadingCount = false;
loadingLessonsTaken = false;
userInterests = [];
attendedEvents;
numberOfEventsMade: number;
numberOfEventsTaken: number;
topContributor: number;
Expand All @@ -47,6 +46,7 @@ export class MyProfileComponent implements OnDestroy {

eventsInfo: any[] = [];
lessonsInfo: any[] = [];
colors: any[] = [];

showXAxis = true;
showYAxis = true;
Expand All @@ -55,20 +55,13 @@ export class MyProfileComponent implements OnDestroy {
showXAxisLabel = true;
showYAxisLabel = false;

colorScheme = {
domain: [
''
]
};

eventsTakenXAxisLabel = '# of events taken';

eventsXAxisLabel = '# of events.ts';

eduMailPattern = '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-.]+\.edu\.[a-z]{2}$'
eduMailPattern = '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-.]+\.edu\.[a-z]{2}$';

formattedRateNumber: string;
numberOfRate: number;

constructor(
private router: Router,
Expand All @@ -82,9 +75,9 @@ export class MyProfileComponent implements OnDestroy {
private followeeService: FolloweeService,
private eventService: EventService,
private themeService: ThemeService,
private userActivityService: UserActivityService) {
private userActivityService: UserActivityService ) {
this.loadingCount = true;
this.loadingLessonsTaken = true
this.loadingLessonsTaken = true;

this.authenticationService.currentUser.subscribe( currentUser => {
this.currentUser = currentUser;
Expand All @@ -103,14 +96,15 @@ export class MyProfileComponent implements OnDestroy {

if ( userInfo?.username ) {
this.eventService.countUserEvents( userInfo.username ).subscribe( eventList => {
this.eventsInfo = eventList
this.eventsInfo = eventList;
this.loadingCount = false;
} )
} );

this.userActivityService.getEventsTaken( userInfo.username ).subscribe( eventList => {
this.lessonsInfo = eventList
this.loadingLessonsTaken = false
} )
this.lessonsInfo = eventList;
this.loadingLessonsTaken = false;
this.colors = this.themeService.barCustomColors( this.lessonsInfo );
} );

this.followerService.count( userInfo.username ).subscribe( followerCount => {
this.followerCount = followerCount[ 0 ].count;
Expand All @@ -121,32 +115,32 @@ export class MyProfileComponent implements OnDestroy {
} );

this.userActivityService.getNumberOfEventsTaken( userInfo.username ).subscribe( result => {
this.numberOfEventsTaken = result[0].numberOfEventsTaken
})
this.numberOfEventsTaken = result[ 0 ].numberOfEventsTaken;
} );

if ( userInfo.payload?.userProfileActivated ) {
this.userActivityService.getNumberOfEventsMade( userInfo.username ).subscribe( result => {
this.numberOfEventsMade = result.numberOfEventsMade
} )
this.numberOfEventsMade = result.numberOfEventsMade;
} );

this.userActivityService.getContributorRate( userInfo.username ).subscribe( rate => {
this.rateObject = {
userRating: rate.userRating,
numberOfRates: rate.numberOfRates
}
})
};
} );

this.userActivityService.getTopContributors().subscribe( topContributors => {
topContributors.forEach( ( value, index ) => {
if( value.username === userInfo.username ) {
if ( value.username === userInfo.username ) {
this.topContributor = index;
}
} );
})
} );
} else {
this.numberOfEventsMade = undefined
this.rateObject = undefined
this.topContributor = undefined
this.numberOfEventsMade = undefined;
this.rateObject = undefined;
this.topContributor = undefined;
}

this.categoryService.getCategoriesFromId( this.userInfo.payload?.interests ).subscribe( result => {
Expand All @@ -171,16 +165,4 @@ export class MyProfileComponent implements OnDestroy {
goToUrl( url: string ) {
window.open( url, '_blank' );
}

barCustomColors( array: any[] ) {
const result: any[] = [];
const style = getComputedStyle( document.body )

for (let i = 0; i < array.length; i++) {
result.push({name: array[i].name, value: style
.getPropertyValue( this.themeService.colors[ Math.floor( i / 2 ) ] )});
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<br/>
<ngx-charts-bar-horizontal
[gradient]="gradient"
[customColors]="barCustomColors(lessonsInfo)"
[customColors]="colors"
[animations]="false"
[legend]="showLegend"
[results]="lessonsInfo"
Expand Down Expand Up @@ -173,7 +173,7 @@ <h3 class="dim">No results found</h3>
<br/>
<ngx-charts-bar-horizontal
[gradient]="gradient"
[customColors]="barCustomColors(eventsInfo)"
[customColors]="colors"
[animations]="false"
[legend]="showLegend"
[results]="eventsInfo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class PublicProfileComponent implements OnInit, OnDestroy {
loading = false;
loadingCount = false;
loadingLessonsTaken = false;
colors: any[] = [];

isPublic = false;
URLS = URLS;
Expand Down Expand Up @@ -212,16 +213,4 @@ export class PublicProfileComponent implements OnInit, OnDestroy {
} );
} );
}

barCustomColors( array: any[] ) {
const result: any[] = [];
const style = getComputedStyle( document.body )

for (let i = 0; i < array.length; i++) {
result.push({name: array[i].name, value: style
.getPropertyValue( this.themeService.colors[ Math.floor( i / 2 ) ] )});
}

return result;
}
}
4 changes: 2 additions & 2 deletions src/app/service/event/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export class EventService {
countUserEvents( username: string, isPastOnly: string = 'true' ) {
if ( environment.mockDataEnabled ) {
const countData = [
{ _id:{category:13,subCategory:5},count:27},
{ _id:{category:11,subCategory:5, leafCategory: 3},count:10}
{ _id:{category:1,subCategory:1},count:27},
{ _id:{category:1,subCategory:2, leafCategory: 1},count:10}
] as CountModel[]

return of(this.countUserEventsProcess(countData))
Expand Down
19 changes: 19 additions & 0 deletions src/app/service/theme/theme.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,23 @@ export class ThemeService {
this.themeColorSettingSubject.next( 'default' );
this.sideNavClosedSubject.next( 'false' );
}

barCustomColors( array: any[] ) {
const result: any[] = [];

for ( let i = 0; i < array.length; i++ ) {
let value;
if ( i >= this.colors.length ) {
value = 'var(' + this.colors[ length - 1 ] + ')';
} else {
value = 'var(' + this.colors[ i ] + ')';
}

result.push( {
name: array[ i ].name, value
} );
}

return result;
}
}
8 changes: 3 additions & 5 deletions src/app/service/user-activity/user-activity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class UserActivityService {
if ( environment.mockDataEnabled ) {
const eventsTaken = [
{ _id:{category:1,subCategory:1},count:7},
{ _id:{category:1,subCategory:3, leafCategory: 3},count: 5}
{ _id:{category:1,subCategory:2, leafCategory: 1},count: 5}
] as any

return of(this.getEventsTakenProcess( eventsTaken ))
Expand All @@ -34,10 +34,8 @@ export class UserActivityService {

getEventsTakenProcess( eventsTaken: any ) {
eventsTaken.map( categories => {
const categoryResult = this.categoryService.getCategoryFromId( categories._id.category,
categories._id.subCategory, categories._id.leafCategory );

categories._id = categoryResult
categories._id = this.categoryService.getCategoryFromId( categories._id.category,
categories._id.subCategory, categories._id.leafCategory )
} );

const newEventsList = []
Expand Down

0 comments on commit 8d372ef

Please sign in to comment.