plotly / plotly/angular-plotly.js
Height of plot is 0 until resize after changing layout input
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- TypeScript
- Estrelas
- 242
- Forks
- 81
- Merge médio
- 8h 48min
- PRs com merge (30d)
- 18
Descrição
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';
export const THEME = new InjectionToken('Theme', {
factory: () => {
const w = inject(WA_WINDOW);
const d = inject(DOCUMENT);
const darkMode = signal(true);
const setDarkMode = effect(() =>
d.documentElement.classList.toggle('light', !darkMode())
);
return {
darkMode,
textColor: computed(() => {
darkMode();
return getComputedStyle(d.documentElement).getPropertyValue(
'--mat-app-text-color'
);
}),
};
},
});
Component
...
readonly #theme = inject(THEME);
readonly ageGenderChartLayout = 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-spinner style="margin: auto;"></mat-spinner>
}
</mat-card-content>
</mat-card>
Before switching themes:
After switching themes (which updates the layout input of the plotly-plot component):
How can I have responsive charts while still have their containers "see" their actual height? is this a Plotly chart issue?
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pelo componente do template do Angular e pelo input de layout atualizado pelo signal de tema. Reproduza uma troca de tema e compare a altura do contêiner do gráfico antes e depois da atualização, sem redimensionar a janela. Está concluído quando os gráficos responsive mantêm a altura real do contêiner imediatamente após as alterações no layout.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- angular, typescript
- Domínio
- frontend
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 38/100