Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Height of plot is 0 until resize after changing layout input #276

Open
@jakehockey10

Description

@jakehockey10

Hello,

I'm having a bit of trouble with my charts in a dashboard. I've implemented theme switching in my application using system variables and Angular Material. I'm able to change my chart's look and feel according to the colors of my theme. However, the container will collapse when I switch to a new theme because the plotly-plot element has a height of 0 until I resize the window.

Injectable

import{DOCUMENT}from'@angular/common';import{computed,effect,inject,InjectionToken,signal,}from'@angular/core';import{WA_WINDOW}from'@ng-web-apis/common';exportconstTHEME=newInjectionToken('Theme',{factory:()=>{constw=inject(WA_WINDOW);constd=inject(DOCUMENT);constdarkMode=signal(true);constsetDarkMode=effect(()=>d.documentElement.classList.toggle('light',!darkMode()));return{      darkMode,textColor:computed(()=>{darkMode();returngetComputedStyle(d.documentElement).getPropertyValue('--mat-app-text-color');}),};},});

Component

...readonly #theme=inject(THEME);readonlyageGenderChartLayout=computed<Partial<Plotly.Layout>>(()=>({barmode:'stack',autosize:true,margin:{l:60,r:50,b:100,t:50,pad:4,},title:'People by Age',paper_bgcolor:'rgba(255,255,255,0)',plot_bgcolor:'rgba(255,255,255,0)',font:{color:this.#theme.textColor(),},}));...

Template

<mat-card><mat-card-content>    @if (mapData$ | async; as mapData) {<plotly-plot[data]="mapData"[layout]="mapLayout()"[config]="{responsive: true, mapboxAccessToken: mapboxToken, displaylogo: false, modeBarButtonsToRemove: ['toImage']}"/>    } @else {<mat-spinnerstyle="margin: auto;"></mat-spinner>    }</mat-card-content></mat-card>

Before switching themes:
Image

After switching themes (which updates the layout input of the plotly-plot component):
Image

How can I have responsive charts while still have their containers "see" their actual height? is this a Plotly chart issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp