plotly / plotly/angular-plotly.js
Height of plot is 0 until resize after changing layout input
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- TypeScript
- Star
- 242
- Fork
- 81
- Merge trung bình
- 8 giờ 48 phút
- Pull request đã merge (30 ngày)
- 18
Mô tả
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?
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với component trong Angular template và layout input được cập nhật bởi theme signal. Tái hiện việc chuyển theme, sau đó so sánh chiều cao của chart container trước và sau khi cập nhật mà không thay đổi kích thước cửa sổ. Hoàn tất khi các responsive chart giữ nguyên chiều cao container thực tế ngay sau khi layout thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- angular, typescript
- Lĩnh vực
- frontend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 38/100