Commit 4f31aaf
authored
Feature/speed up plotting (#586)
* _style_area_as_bar() helper:
- Classifies traces by analyzing y-values: positive, negative, mixed, zero
- Sets stackgroup='positive' or stackgroup='negative' for proper separate stacking
- Mixed values shown as dashed lines (no fill)
- Opaque fills, no line borders, hv line shape
Performance:
┌────────────────────────┬───────┐
│ Method │ Time │
├────────────────────────┼───────┤
│ .plotly.bar() + update │ 0.14s │
├────────────────────────┼───────┤
│ .plotly.area() + style │ 0.10s │
├────────────────────────┼───────┤
│ Speedup │ ~1.4x │
└────────────────────────┴───────┘
* New Helper Functions
# Iterate over all traces (main + animation frames)
def _iter_all_traces(fig: go.Figure):
yield from fig.data
for frame in getattr(fig, 'frames', []) or []:
yield from frame.data
# Apply unified hover styling (works with any plot type)
def _apply_unified_hover(fig: go.Figure, unit: str = '', decimals: int = 1):
# Sets: <b>name</b>: value unit
# + hovermode='x unified' + spike lines
Updated Methods
┌───────────────────┬──────────────────────────────────────────────┐
│ Method │ Changes │
├───────────────────┼──────────────────────────────────────────────┤
│ balance() │ + _apply_unified_hover(fig, unit=unit_label) │
├───────────────────┼──────────────────────────────────────────────┤
│ carrier_balance() │ + _apply_unified_hover(fig, unit=unit_label) │
├───────────────────┼──────────────────────────────────────────────┤
│ storage() │ + _apply_unified_hover(fig, unit=unit_label) │
└───────────────────┴──────────────────────────────────────────────┘
Result
- Hover format: <b>Solar</b>: 45.3 kW
- Hovermode: x unified (single tooltip for all traces)
- Spikes: Gray vertical line at cursor
* 1. _style_area_as_bar (lines 183-221): The class_map is now built by aggregating sign info across all traces returned by _iter_all_traces(fig), including animation frames.
The color_map is still derived from fig.data. The implementation uses a sign_flags dictionary to incrementally update has_pos/has_neg flags for each trace.name, then
computes class_map from those aggregated flags.
2. _apply_unified_hover (lines 271-274): Replaced the fig.update_layout(xaxis_showspikes=..., ...) with a single fig.update_xaxes(showspikes=True, spikecolor='gray',
spikethickness=1) call so spike settings apply to all x-axes (xaxis, xaxis2, xaxis3, ...) in faceted plots.
* Update plotting deps
* Update plotting deps and use xarray-plotly for fast_bar
* Removed both redundant line_shape='hv' parameters - fast_bar() handles that internally
* Update CHANGELOG.md1 parent b39ab03 commit 4f31aaf
3 files changed
Lines changed: 8 additions & 115 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
| 304 | + | |
304 | 305 | | |
305 | 306 | | |
306 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | 150 | | |
252 | 151 | | |
253 | 152 | | |
| |||
264 | 163 | | |
265 | 164 | | |
266 | 165 | | |
267 | | - | |
268 | | - | |
269 | | - | |
| 166 | + | |
| 167 | + | |
270 | 168 | | |
271 | 169 | | |
272 | 170 | | |
| |||
1650 | 1548 | | |
1651 | 1549 | | |
1652 | 1550 | | |
1653 | | - | |
| 1551 | + | |
1654 | 1552 | | |
1655 | | - | |
1656 | 1553 | | |
1657 | 1554 | | |
1658 | 1555 | | |
1659 | | - | |
1660 | 1556 | | |
1661 | 1557 | | |
1662 | 1558 | | |
| |||
1775 | 1671 | | |
1776 | 1672 | | |
1777 | 1673 | | |
1778 | | - | |
| 1674 | + | |
1779 | 1675 | | |
1780 | | - | |
1781 | 1676 | | |
1782 | 1677 | | |
1783 | 1678 | | |
1784 | | - | |
1785 | 1679 | | |
1786 | 1680 | | |
1787 | 1681 | | |
| |||
2380 | 2274 | | |
2381 | 2275 | | |
2382 | 2276 | | |
2383 | | - | |
| 2277 | + | |
2384 | 2278 | | |
2385 | | - | |
2386 | 2279 | | |
2387 | 2280 | | |
2388 | 2281 | | |
2389 | | - | |
2390 | 2282 | | |
2391 | 2283 | | |
2392 | 2284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
0 commit comments