Improved the strange resizing issues for the main chart on new Dashboard

This commit is contained in:
James Morris 2022-07-14 16:00:12 +01:00
parent 8aeb5c181e
commit db0929d07a
3 changed files with 40 additions and 6 deletions

View File

@ -35,11 +35,13 @@
<div class="gh-loading-spinner"></div> <div class="gh-loading-spinner"></div>
</div> </div>
{{else}} {{else}}
<EmberChart <div class="gh-dashboard-fader">
@type={{this.chartType}} <EmberChart
@data={{this.chartData}} @type={{this.chartType}}
@options={{this.chartOptions}} @data={{this.chartData}}
@height={{200}} /> @options={{this.chartOptions}}
@height={{200}} />
</div>
{{/if}} {{/if}}
</div> </div>
<div id="gh-dashboard-anchor-tooltip" class="gh-dashboard-tooltip"> <div id="gh-dashboard-anchor-tooltip" class="gh-dashboard-tooltip">

View File

@ -51,13 +51,32 @@ export default class Anchor extends Component {
@service dashboardStats; @service dashboardStats;
@service feature; @service feature;
@tracked chartDisplay = 'total'; @tracked chartDisplay = 'total';
@tracked resizing = false;
@tracked resizeTimer = null;
displayOptions = DISPLAY_OPTIONS; displayOptions = DISPLAY_OPTIONS;
willDestroy(...args) {
super.willDestroy(...args);
window.removeEventListener('resize', this.resizer, false);
}
// this helps with ChartJS resizing stretching bug when resizing
resizer = () => {
this.resizing = true;
clearTimeout(this.resizeTimer); // this uses a trick to trigger only when resize is done
this.resizeTimer = setTimeout(() => {
this.resizing = false;
}, 500);
};
@action @action
loadCharts() { loadCharts() {
this.dashboardStats.loadMemberCountStats(); this.dashboardStats.loadMemberCountStats();
window.addEventListener('resize', this.resizer, false);
if (this.hasPaidTiers) { if (this.hasPaidTiers) {
this.dashboardStats.loadMrrStats(); this.dashboardStats.loadMrrStats();
} }
@ -73,7 +92,7 @@ export default class Anchor extends Component {
} }
get loading() { get loading() {
return this.dashboardStats.memberCountStats === null; return this.dashboardStats.memberCountStats === null || this.resizing;
} }
get totalMembers() { get totalMembers() {

View File

@ -787,6 +787,15 @@ Dashboard Overview */
/* --------------------------------- /* ---------------------------------
Dashboard Anchor */ Dashboard Anchor */
@keyframes chartFadeIn {
0% {
opacity: 0;
}
100% {
opacity: 100;
}
}
.gh-dashboard-anchor { .gh-dashboard-anchor {
position: relative; position: relative;
} }
@ -1849,6 +1858,10 @@ Dashboard Tooltips */
margin-top: 24px; margin-top: 24px;
} }
.gh-dashboard-fader {
animation: chartFadeIn 150ms;
}
.gh-dashboard-totals .gh-dashboard-loading, .gh-dashboard-totals .gh-dashboard-loading,
.gh-dashboard-totals .gh-dashboard-chart-container { .gh-dashboard-totals .gh-dashboard-chart-container {
height: 200px; height: 200px;