From cf295d308319335cad98742992aec767d791466d Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sun, 4 Oct 2026 17:17:38 +0330 Subject: [PATCH] category couplet count plot fix --- GanjooRazor/wwwroot/js/bk.js | 26 +++++++++++++------ .../GanjoorService-Stats.cs | 6 ++++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/GanjooRazor/wwwroot/js/bk.js b/GanjooRazor/wwwroot/js/bk.js index 9ef87e54..ccadf727 100644 --- a/GanjooRazor/wwwroot/js/bk.js +++ b/GanjooRazor/wwwroot/js/bk.js @@ -2541,29 +2541,39 @@ function plotChart(tableId, maxCols = 9) { let table = document.getElementById(tableId); if (!table) return; - let labels = []; - let values = []; - let headerCols = table.querySelector("thead tr").children; let xTitle = headerCols[1].innerText.trim(); let yTitle = headerCols[2].innerText.trim(); + + // collect every eligible row first - a table's own displayed row order can be meaningful on + // the page itself (e.g. sub-categories kept in their natural/defined order rather than sorted + // by count), so that order is never disturbed here; sorting/truncating for the chart only + // happens below, on a separate copy + let rows = []; table.querySelectorAll("tbody tr").forEach(row => { let cols = row.querySelectorAll("td"); if (cols.length >= 3) { - if (values.length > maxCols) return; let rowNumber = persianToEnglishNumber(cols[0].innerText.trim()); if (rowNumber === "0") return; // Ignore rows with row number ۰ let xValue = persianToEnglishNumber(cols[1].innerText.trim()); let yValue = persianToEnglishNumber(cols[2].innerText.trim()); - labels.push(xValue); - values.push(parseInt(yValue)); - - + rows.push({ label: xValue, value: parseInt(yValue) }); } }); + // a table opts into charting its top values by count - rather than whatever its own row order + // happens to be - via data-chart-sort="value-desc" on the itself + if (table.dataset.chartSort === "value-desc") { + rows.sort((a, b) => b.value - a.value); + } + + rows = rows.slice(0, maxCols + 1); + + let labels = rows.map(r => r.label); + let values = rows.map(r => r.value); + let existingCanvas = document.getElementById(`chart-${tableId}`); if (existingCanvas) { existingCanvas.remove(); diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs index 7d487714..2fc54fab 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Stats.cs @@ -788,7 +788,11 @@ namespace RMuseum.Services.Implementation htmlText += " (بخش‌هایی که در این جدول نیامده‌اند فاقد شعر بوده‌اند)"; } htmlText += $":

{Environment.NewLine}"; - htmlText += $"
{Environment.NewLine}{Environment.NewLine}" + + // this table's own row order is intentionally the sub-categories' natural/defined + // order, not sorted by couplet count like the other stats tables on this page - so + // the generic plotChart() in bk.js is told (via data-chart-sort) to sort by value + // before charting, without touching the table's own displayed row order + htmlText += $"
{Environment.NewLine}{Environment.NewLine}" + $"{Environment.NewLine}" + $"{Environment.NewLine}" + $"{Environment.NewLine}" +
ردیفبخش