From 3c7f82b1ae5ded7db2a23302300318110217e4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacek=20Fefli=C5=84ski?= Date: Wed, 22 Apr 2026 14:04:56 +0200 Subject: [PATCH] Genetrowanie PNG --- includes/admin/pages/page-infographic.php | 67 ++++++++++++++++++----- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/includes/admin/pages/page-infographic.php b/includes/admin/pages/page-infographic.php index be8b4f9..543a2af 100644 --- a/includes/admin/pages/page-infographic.php +++ b/includes/admin/pages/page-infographic.php @@ -71,6 +71,7 @@ function statpress_infographic_page() { // Włączenie skryptów dla Chart.js wp_enqueue_script( 'chart-js', 'https://cdn.jsdelivr.net/npm/chart.js', array(), null, true ); + wp_enqueue_script( 'html2canvas', 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js', array(), null, true ); wp_register_script( 'statpress-infographic-chart-loader', false ); wp_enqueue_script( 'statpress-infographic-chart-loader' ); wp_add_inline_script( @@ -101,6 +102,36 @@ function statpress_infographic_page() { } } }); + + // Logika eksportu PNG + const exportBtn = document.getElementById("statpress-export-btn"); + if (exportBtn) { + exportBtn.addEventListener("click", function() { + const originalText = exportBtn.innerText; + exportBtn.innerText = "Generowanie obrazu..."; + exportBtn.disabled = true; + + const exportArea = document.getElementById("statpress-export-area"); + html2canvas(exportArea, { + scale: 2, // 2x lepsza rozdzielczość obrazka (Retina) + backgroundColor: "#f0f0f1", // Domyślne tło WP Admin + onclone: function(clonedDoc) { + // Pokazujemy nasz ukryty tytuł i dodajemy marginesy tylko na obrazku + const brand = clonedDoc.getElementById("statpress-export-brand"); + if (brand) brand.style.display = "block"; + clonedDoc.getElementById("statpress-export-area").style.padding = "24px"; + } + }).then(canvas => { + let link = document.createElement("a"); + link.download = "statpress-podsumowanie-' . esc_js( $current_year ) . '.png"; + link.href = canvas.toDataURL("image/png"); + link.click(); + + exportBtn.innerText = originalText; + exportBtn.disabled = false; + }); + }); + } }); ' ); @@ -110,7 +141,7 @@ function statpress_infographic_page() {

Infografika Statystyk Sportowych


-
+
@@ -121,6 +152,7 @@ function statpress_infographic_page() { 'margin: 0;' ) ); ?>
+
@@ -133,21 +165,28 @@ function statpress_infographic_page() {
-
-

Statystyki dla

-
-

Dystans

total_distance, 2, ',', ' ' ); ?> km

-

Czas

total_duration ); ?>

-

Wznios

total_elevation_gain, 0, ',', ' ' ); ?> m

-

Aktywności

total_activities, 0, ',', ' ' ); ?>

+
+ -
-
-

Rozkład Dystansu wg Kategorii w

-
-
- +
+

Statystyki dla

+
+

Dystans

total_distance, 2, ',', ' ' ); ?> km

+

Czas

total_duration ); ?>

+

Wznios

total_elevation_gain, 0, ',', ' ' ); ?> m

+

Aktywności

total_activities, 0, ',', ' ' ); ?>

+
+
+ +
+

Rozkład Dystansu wg Kategorii w

+
+
+ +