Better Responsiveness

This commit is contained in:
2023-12-28 23:52:40 -03:00
parent 250720de1e
commit c1b8b651e0
3 changed files with 27 additions and 9 deletions

View File

@@ -81,7 +81,7 @@
} }
/* COMPUTER FORMAT */ /* COMPUTER FORMAT */
@media only screen and (min-width: 712px) { @media only screen and (min-width: 770px) {
.card-languages { .card-languages {
margin: 0; margin: 0;
} }

View File

@@ -7,7 +7,7 @@
<p class="card-text">{{project.description}}</p> <p class="card-text">{{project.description}}</p>
</div> </div>
<div class="card-content-f row"> <div class="card-content-f row">
<div class="card-languages col-sm-9" *ngIf="hasLanguage" id="language-chart"> <div class="card-languages col-md-9" *ngIf="hasLanguage" id="language-chart">
<apx-chart *ngIf="chartOptions !== undefined" <apx-chart *ngIf="chartOptions !== undefined"
[series]="chartOptions.series" [series]="chartOptions.series"
[colors]="chartOptions.colors" [colors]="chartOptions.colors"
@@ -18,7 +18,7 @@
[dataLabels]="chartOptions.dataLabels"> [dataLabels]="chartOptions.dataLabels">
</apx-chart> </apx-chart>
</div> </div>
<div class="card-stats" [ngClass]="hasLanguage ? 'col-sm-3' : 'stats-inline'"> <div class="card-stats" [ngClass]="hasLanguage ? 'col-md-3' : 'stats-inline'">
<div class="stat-item" *ngIf="hasLicense"> <div class="stat-item" *ngIf="hasLicense">
<div class="stat-icon"> <div class="stat-icon">
<fa-icon [icon]="faLicense"></fa-icon> <fa-icon [icon]="faLicense"></fa-icon>

View File

@@ -1,4 +1,4 @@
import {Component, Input, OnInit, ViewChild} from '@angular/core'; import {Component, HostListener, Input, OnInit, ViewChild} from '@angular/core';
import { faCodeFork, faEye, faStar } from '@fortawesome/free-solid-svg-icons'; import { faCodeFork, faEye, faStar } from '@fortawesome/free-solid-svg-icons';
import {Language, Project} from "../../shared/model/project/project.model"; import {Language, Project} from "../../shared/model/project/project.model";
import {faScaleBalanced} from "@fortawesome/free-solid-svg-icons/faScaleBalanced"; import {faScaleBalanced} from "@fortawesome/free-solid-svg-icons/faScaleBalanced";
@@ -46,13 +46,28 @@ export class ProjectCardComponent implements OnInit {
faEye = faEye; faEye = faEye;
private windowResizeTimeout: any;
ngOnInit() { ngOnInit() {
if (!!this.project.languages) { if (!!this.project.languages) {
this.chartOptions = this.generateChart(this.project.languages); const windowWidth = window.innerWidth;
this.chartOptions = this.generateChart(this.project.languages, windowWidth);
} }
} }
@HostListener('window:resize', ['$event'])
getScreenSize(event: Event) {
clearTimeout(this.windowResizeTimeout);
this.windowResizeTimeout = setTimeout(() => {
if (!this.project.languages) return;
this.chartOptions = this.generateChart(
this.project.languages, window.innerWidth
);
}, 100);
}
get hasLicense(): boolean { get hasLicense(): boolean {
return this.project.license !== undefined; return this.project.license !== undefined;
} }
@@ -62,7 +77,10 @@ export class ProjectCardComponent implements OnInit {
this.project.languages?.length > 0; this.project.languages?.length > 0;
} }
private generateChart(languages: Language[]): ChartOptions { private generateChart(languages: Language[], windowWidth: number): ChartOptions {
const responsiveWindowWidth = windowWidth >= 530 ?
300 : (windowWidth*.8 - 80);
return { return {
series: languages.map(value => value.percentage), series: languages.map(value => value.percentage),
colors: languages.map(value => value.color), colors: languages.map(value => value.color),
@@ -73,10 +91,10 @@ export class ProjectCardComponent implements OnInit {
labels: languages.map(value => value.name), labels: languages.map(value => value.name),
responsive: [ responsive: [
{ {
breakpoint: 480, breakpoint: 530,
options: { options: {
chart: { chart: {
width: 300 width: responsiveWindowWidth
}, },
legend: { legend: {
position: "bottom" position: "bottom"
@@ -87,7 +105,7 @@ export class ProjectCardComponent implements OnInit {
plotOptions: { plotOptions: {
pie: { pie: {
expandOnClick: true, expandOnClick: true,
} }
}, },
dataLabels: { dataLabels: {