apmtools 0.2.23__tar.gz → 0.2.24__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: apmtools
3
- Version: 0.2.023
3
+ Version: 0.2.024
4
4
  Summary: A collection of tools for processing air pollution monitoring data
5
5
  Project-URL: Homepage, https://github.com/federlorenz/apmtools
6
6
  Author-email: Federico Lorenzetti <lorenzetti.federico@gmail.com>
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "apmtools"
7
- version = "0.2.023"
7
+ version = "0.2.024"
8
8
  authors = [
9
9
  { name="Federico Lorenzetti", email="lorenzetti.federico@gmail.com" },
10
10
  ]
@@ -528,7 +528,8 @@ def create_summary_app(
528
528
  .summary-plot-container {
529
529
  width: 100%;
530
530
  max-width: none;
531
- aspect-ratio: 2 / 1;
531
+ /* Height is set from actual rendered width by ResizeObserver. */
532
+ height: 500px;
532
533
  min-width: 0;
533
534
  min-height: 0;
534
535
  padding: 0;
@@ -544,32 +545,46 @@ def create_summary_app(
544
545
  }
545
546
  """),
546
547
  ui.tags.script("""
547
- // Plotly sometimes retains the pixel width measured before the
548
- // Shiny sidebar and widget have finished laying out.
549
548
  (() => {
550
- function resizePlot() {
549
+ // Calculate the actual height in pixels from the rendered width.
550
+ // CSS aspect-ratio alone does not reliably size shinywidgets.
551
+ const install = () => {
551
552
  const container = document.querySelector('.summary-plot-container');
552
- if (!container || !window.Plotly) return;
553
- const graph = container.querySelector('.js-plotly-plot');
554
- if (graph) window.Plotly.Plots.resize(graph);
555
- }
556
- const observer = new ResizeObserver(resizePlot);
557
- const attach = () => {
558
- const container = document.querySelector('.summary-plot-container');
559
- if (!container) return false;
553
+ if (!container || container.dataset.aspectObserverInstalled) return !!container;
554
+ container.dataset.aspectObserverInstalled = '1';
555
+ let previousWidth = 0;
556
+ const resize = () => {
557
+ const width = container.getBoundingClientRect().width;
558
+ if (width <= 0) return;
559
+ const height = Math.round(width / 2);
560
+ if (width === previousWidth && container.style.height === `${height}px`) return;
561
+ previousWidth = width;
562
+ container.style.height = `${height}px`;
563
+ const widget = container.querySelector('#plot');
564
+ if (widget) {
565
+ widget.style.width = '100%';
566
+ widget.style.height = `${height}px`;
567
+ }
568
+ const graph = container.querySelector('.js-plotly-plot');
569
+ if (graph && window.Plotly) {
570
+ // Plotly sometimes retains a previous fixed pixel height.
571
+ window.Plotly.relayout(graph, {width: Math.round(width), height: height});
572
+ }
573
+ };
574
+ const observer = new ResizeObserver(resize);
560
575
  observer.observe(container);
561
- resizePlot();
576
+ window.addEventListener('resize', resize);
577
+ // React to Shiny rendering a new Plotly graph.
578
+ const mutation = new MutationObserver(() => requestAnimationFrame(resize));
579
+ mutation.observe(container, {childList: true, subtree: false});
580
+ requestAnimationFrame(resize);
562
581
  return true;
563
582
  };
564
- document.addEventListener('DOMContentLoaded', attach);
565
- window.addEventListener('resize', resizePlot);
566
- if (!attach()) {
583
+ if (!install()) {
567
584
  const startup = new MutationObserver((_, watcher) => {
568
- if (attach()) watcher.disconnect();
569
- });
570
- startup.observe(document.documentElement, {
571
- childList: true, subtree: true
585
+ if (install()) watcher.disconnect();
572
586
  });
587
+ startup.observe(document.documentElement, {childList: true, subtree: true});
573
588
  }
574
589
  })();
575
590
  """),
File without changes
File without changes
File without changes