plotly / plotly/angular-plotly.js

Height of plot is 0 until resize after changing layout input

未关闭
#276 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
TypeScript
星标
242
派生
81
平均合并
8 小时 48 分钟
30 天内合并 PR
18

描述

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:
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?

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Angular 模板的  组件以及由主题信号更新的布局输入开始。重现主题切换,然后在不调整窗口大小的情况下,比较更新前后的图表容器高度。完成标准是:responsive 图表在布局更改后立即保持其实际容器高度。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
frontend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。