diff --git a/src/app/components/shared/tag-cloud/tag-cloud.component.html b/src/app/components/shared/tag-cloud/tag-cloud.component.html index b6bae1c3cd2ecc2b44335b5e6ab48b2a68bed950..13c428466dbd4286488f8d0e93d140b52981e44b 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.component.html +++ b/src/app/components/shared/tag-cloud/tag-cloud.component.html @@ -19,20 +19,18 @@ </ars-row> <ars-fill ars-flex-box style="width:100%;height:100%;"> - <angular-tag-cloud + class="spacyTagCloud" [data]="data" [width]="options.width" [height]="options.height" [overflow]="options.overflow" [zoomOnHover]="zoomOnHoverOptions" + [realignOnResize]="true" [log]='"debug"'> </angular-tag-cloud> - </ars-fill> - - <ars-row [height]="100"> </ars-row> diff --git a/src/app/components/shared/tag-cloud/tag-cloud.component.scss b/src/app/components/shared/tag-cloud/tag-cloud.component.scss index 9273ec3e3173bc3cd329c4fb61e4d1f59c4da2c4..3520bd22be8fb8bd3be3c52a59aa8e0a2a1aeecd 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.component.scss +++ b/src/app/components/shared/tag-cloud/tag-cloud.component.scss @@ -14,4 +14,50 @@ margin-left: 16px; display: inline; } -} \ No newline at end of file +} + +::ng-deep .spacyTagCloud > span { + &.w10 { + color: brown !important; + font-size: 380% !important; + } + &.w9 { + color: white !important; + font-size: 330% !important; + } + &.w8 { + color: tomato !important; + font-size: 280% !important; + } + &.w7 { + color: lightgreen !important; + font-size: 240% !important; + } + &.w6 { + color: gray !important; + font-size: 210% !important; + } + &.w5 { + color: pink !important; + font-size: 180% !important; + } + &.w4 { + color: orange !important; + font-size: 160% !important; + } + &.w3 { + color: yellow !important; + font-size: 140% !important; + } + &.w2 { + color: green !important; + font-size: 120% !important; + } + &.w1 { + color: lightblue !important; + font-size: 100% !important; + } + &:hover { + color: greenyellow !important; + } +} diff --git a/src/app/components/shared/tag-cloud/tag-cloud.component.ts b/src/app/components/shared/tag-cloud/tag-cloud.component.ts index fbffc1c86c7eaed1ff77e0bfe3e6fd951faedde0..fb8e5e78065ab4196baa9b8ce34ed2b71635855d 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.component.ts +++ b/src/app/components/shared/tag-cloud/tag-cloud.component.ts @@ -1,9 +1,18 @@ import {Component, OnInit, ViewChild} from '@angular/core'; -import {CloudData, CloudOptions, Position, ZoomOnHoverOptions} from 'angular-tag-cloud-module'; +import { + CloudData, + CloudOptions, + Position, + ZoomOnHoverOptions, + TagCloudComponent as TCloudComponent +} from 'angular-tag-cloud-module'; import {CommentService} from '../../../services/http/comment.service'; import {Result, SpacyService} from '../../../services/http/spacy.service'; import {Comment} from '../../../models/comment'; +import {LanguageService} from "../../../services/util/language.service"; +import {TranslateService} from "@ngx-translate/core"; +import {QuestionWallComment} from "../questionwall/QuestionWallComment"; class TagComment implements CloudData { @@ -19,17 +28,17 @@ class TagComment implements CloudData { } const weight2color = { - 1: "blue", - 2: "green", - 3: "yellow", - 4: "orange", - 5: "pink", - 6: "gray", - 7: "lightgreen", - 8: "tomato", - 9: "white", - 10: "brown" -} + 1: 'blue', + 2: 'green', + 3: 'yellow', + 4: 'orange', + 5: 'pink', + 6: 'gray', + 7: 'lightgreen', + 8: 'tomato', + 9: 'white', + 10: 'brown' +}; @Component({ selector: 'app-tag-cloud', @@ -38,7 +47,7 @@ const weight2color = { }) export class TagCloudComponent implements OnInit { - @ViewChild(TagCloudComponent, {static: false}) child: TagCloudComponent; + @ViewChild(TCloudComponent, {static: false}) child: TCloudComponent; roomId: string; options: CloudOptions = { // if width is between 0 and 1 it will be set to the width of the upper element multiplied by the value @@ -46,24 +55,30 @@ export class TagCloudComponent implements OnInit { // if height is between 0 and 1 it will be set to the height of the upper element multiplied by the value height: 1, overflow: false, - font: "Georgia" // not working + font: 'Georgia' // not working }; zoomOnHoverOptions: ZoomOnHoverOptions = { scale: 1.3, // Elements will become 130 % of current size on hover transitionTime: 0.6, // it will take 0.6 seconds until the zoom level defined in scale property has been reached delay: 0.4,// Zoom will take affect after 0.4 seconds - color: "red" + color: 'red' }; data: CloudData[] = []; constructor(private commentService: CommentService, - private spacyService: SpacyService) { + private spacyService: SpacyService, + private langService: LanguageService, + private translateService: TranslateService) { this.roomId = localStorage.getItem('roomId'); + this.langService.langEmitter.subscribe(lang => { + this.translateService.use(lang); + }); } ngOnInit(): void { + this.translateService.use(localStorage.getItem('currentLang')); this.commentService.getAckComments(this.roomId).subscribe((comments: Comment[]) => { this.analyse(comments); }); @@ -73,18 +88,27 @@ export class TagCloudComponent implements OnInit { const commentsConcatenated = comments.map(c => c.body).join(' '); this.spacyService.analyse(commentsConcatenated, 'de').subscribe((res: Result) => { - - this.data = res.words.filter(w => ['NE', 'NN', 'NMP', 'NNE'].indexOf(w.tag) >= 0).map(w => { - const weight = 5 + Math.floor(Math.random() * 4 + 1); - const color = weight2color[weight]; - return new TagComment(color, + const map = new Map<string, number>(); + let maxCount = 0; + res.words.filter(w => ['NE', 'NN', 'NMP', 'NNE'].indexOf(w.tag) >= 0).forEach(elem => { + const count = (map.get(elem.text) || 0) + 1; + if (count > maxCount) { + maxCount = count; + } + map.set(elem.text, count); + }); + this.data.length = 0; // Clear array + map.forEach((val, key) => { + const weight = 9 * val / maxCount + 1; + console.log(weight + ' ' + typeof weight); + this.data.push(new TagComment(null, true, null, null, - /*Math.floor(Math.random() * 30 - 15)*/0, w.text, - 'TODO', weight); + /*Math.floor(Math.random() * 30 - 15)*/0, key, + 'TODO', weight)); } - ) - }) - + ); + this.child.reDraw(); + }); } } diff --git a/src/theme/arsnova-theme.const.ts b/src/theme/arsnova-theme.const.ts index c765fd37dd3627bdcb9f9353d32d3d99874f7465..2e8e37fbef4e181805e3ac45f661e52090dc5066 100644 --- a/src/theme/arsnova-theme.const.ts +++ b/src/theme/arsnova-theme.const.ts @@ -5,10 +5,10 @@ import { purple, purple_meta } from './purple-theme/purpleTheme.const'; import { highcontrast, highcontrast_meta } from './high-contrast-theme/highContrastTheme.const'; export const themes = { - arsnova: arsnova, - dark: dark, + arsnova, + dark, projector: purple, - highcontrast: highcontrast + highcontrast }; export const themes_meta = {