Skip to content

Commit

Permalink
improve agreement and add agreement circle to UI (#188)
Browse files Browse the repository at this point in the history
* improve agreement calculation and add agreement circle indicator to ui

* update node

* change participant filter pipe to layout players differently

* update images in readme

* update images in readme
  • Loading branch information
philmtd authored Nov 27, 2023
1 parent ec9e4eb commit c8e934a
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 88 deletions.
Binary file modified docs/results-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/results-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/voting-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/voting-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 32 additions & 31 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@angular/compiler-cli": "^17.0.4",
"@ngxs/devtools-plugin": "3.8.1",
"@types/jasmine": "~5.1.2",
"@types/node": "^20.9.4",
"@types/node": "^20.10.0",
"@types/qrcode": "^1.5.5",
"gzipper": "7.2.0",
"jasmine-core": "~5.1.1",
Expand Down
64 changes: 33 additions & 31 deletions frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {TranslateHttpLoader} from "@ngx-translate/http-loader";
import {TranslateMessageFormatCompiler} from "ngx-translate-messageformat-compiler";
import {QRCodeModule} from "angularx-qrcode";
import {SettingsState} from "./store/settings/settings.state";
import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";

export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, '/assets/i18n/', '.json');
Expand All @@ -60,37 +61,38 @@ export function HttpLoaderFactory(http: HttpClient) {
ThemeSwitcherComponent,
FractionFilterPipe
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
MatDialogModule,
MatInputModule,
MatSelectModule,
MatOptionModule,
MatButtonModule,
FormsModule,
HttpClientModule,
NgxsModule.forRoot(appStates, {developmentMode: !environment.production}),
NgxsStoragePluginModule.forRoot({key: [UserState, ThemingState, SettingsState]}),
NgxsReduxDevtoolsPluginModule.forRoot(),
NgxsLoggerPluginModule.forRoot(),
MatIconModule,
MatMenuModule,
MatTooltipModule,
QRCodeModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
},
compiler: {
provide: TranslateCompiler,
useClass: TranslateMessageFormatCompiler
}
})
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
MatDialogModule,
MatInputModule,
MatSelectModule,
MatOptionModule,
MatButtonModule,
FormsModule,
HttpClientModule,
NgxsModule.forRoot(appStates, {developmentMode: !environment.production}),
NgxsStoragePluginModule.forRoot({key: [UserState, ThemingState, SettingsState]}),
NgxsReduxDevtoolsPluginModule.forRoot(),
NgxsLoggerPluginModule.forRoot(),
MatIconModule,
MatMenuModule,
MatTooltipModule,
QRCodeModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
},
compiler: {
provide: TranslateCompiler,
useClass: TranslateMessageFormatCompiler
}
}),
MatProgressSpinnerModule
],
providers: [
{provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {appearance: 'outline'}},
{
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/game/game/agreement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function calculateAgreementInternal(numbers: number[]): number | null {
const votedValueRange: number = Math.max(...numbers) - Math.min(...numbers);
const minMaxDeviationPercentage: number = 10;
const maxDeviationScalingFactor: number = 5;
const maxDeviationPercentage: number = Math.max(minMaxDeviationPercentage, 70 - (votedValueRange / maxDeviationScalingFactor));
const maxDeviationPercentage: number = Math.max(minMaxDeviationPercentage, 70 - (votedValueRange * maxDeviationScalingFactor));
const maxDeviation: number = (maxDeviationPercentage / 100) * consensus;
return Math.max(0, (1 - averageDeviation / maxDeviation) * 100);
}
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/app/game/game/fraction-filter.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ export function transformToFraction(v: number | undefined): string | undefined {
return '⅛';
} else if (v == 0.25) {
return '¼';
} else if (v.toFixed(2) === '0.33') {
return '⅓';
} else if (v == 0.5) {
return '½';
} else if (v.toFixed(2) === '0.66') {
return '⅔';
} else if (v == 0.75) {
return '¾';
} else if (v > 1 && v%1 > 0) {
let fraction = transformToFraction(v%1) || ''
let utf8Fractions = ['⅛', '¼', '½', '¾']
let utf8Fractions = ['⅛', '¼', '⅓', '½', '⅔', '¾']
let isUtf8Fraction = utf8Fractions.includes(fraction)
return `${Math.trunc(v)}${isUtf8Fraction ? '' : '.'}${isUtf8Fraction ? fraction : Math.trunc(v%1*10)}`
} else {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/game/game/game.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<strong class="large">{{ game.voteCount }}</strong>
</div>
<div class="agreement fx-layout-column fx-align--center-x fx-align--x-center fx-gap--1em" *ngIf="game.agreement != null">
<mat-spinner mode="determinate" [value]="100-game.agreement"></mat-spinner>
<mat-spinner mode="determinate" [value]="game.agreement"></mat-spinner>
<span class="gray">{{ 'game.agreement' | translate }}</span>
<strong class="large">{{ game.agreementEmoji }}</strong>
</div>
Expand Down
17 changes: 5 additions & 12 deletions frontend/src/app/game/game/game.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,11 @@
font-size: 2em;
}
.agreement {
.agreement-circle {
height: 96px;
width: 96px;
position: relative;
span {
display: block;
font-size: 48px;
margin: 0;
position: absolute;
top: calc(50% - 12px);
left: calc(50% - 24px);
}
mat-spinner {
position: absolute;
height: 3rem !important;
width: 3rem !important;
top: 3rem;
}
}
}
14 changes: 14 additions & 0 deletions frontend/src/app/game/game/game.component.theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,18 @@
}
}

.agreement {
mat-spinner {
&:first-of-type {
transform: scaleX(-1);
circle {
@if($isDark) {
stroke: desaturate(darken(mat.get-color-from-palette($primary, 50), 70%), 75%);
} @else {
stroke: mat.get-color-from-palette($primary, 50);
}
}
}
}
}
}
4 changes: 3 additions & 1 deletion frontend/src/app/game/game/game.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ export class GameComponent {
return '🤩'
} else if (agreement >= 50) {
return '🙂'
} else if (agreement >= 25) {
} else if (agreement >= 30) {
return '😐'
} else if (agreement >= 15) {
return '😕'
} else {
return '😡'
Expand Down
21 changes: 11 additions & 10 deletions frontend/src/app/game/game/participant-filter.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ type PARTICIPANT_ROW = 'top' | 'left' | 'bottom_left' | 'bottom_right' | 'right'
})
export class ParticipantFilterPipe implements PipeTransform {

// top: 0, 3, 5, 7, 9
// left: 1
// right: 2
// bottom_left: 4, 8
// bottom_right: 6, 10
// top: 0, 1, 3, 7, 9, 11, 13, ...
// left: 5
// right: 6
// bottom_left: 2, 8, 12, ...
// "bottom_middle": self
// bottom_right: 4, 10, 14, ...
transform(value: Array<ParticipantModel>, row?: PARTICIPANT_ROW): Array<ParticipantModel> {
if (!row || !value) {
return value;
}

if (row == "top") {
return value.filter((p, idx) => idx == 0 || (idx >= 3 && (idx - 3) % 2 == 0));
return value.filter((p, idx) => idx == 0 || idx == 1 || idx == 3 || (idx >= 7 && (idx - 7) % 2 == 0));
} else if (row == "left") {
return value.filter((p, idx) => idx == 1);
return value.filter((p, idx) => idx == 5);
} else if (row == "bottom_left") {
return value.filter((p, idx) => idx >= 4 && (idx - 4) % 4 == 0);
return value.filter((p, idx) => idx == 2 || idx >= 8 && (idx - 4) % 4 == 0);
} else if (row == "bottom_right") {
return value.filter((p, idx) => idx >= 6 && (idx - 6) % 4 == 0);
return value.filter((p, idx) => idx == 4 || idx >= 10 && (idx - 6) % 4 == 0);
} else if (row == "right") {
return value.filter((p, idx) => idx == 2);
return value.filter((p, idx) => idx == 6);
}

return value;
Expand Down

0 comments on commit c8e934a

Please sign in to comment.