category couplet count plot fix
This commit is contained in:
parent
f15bf951bf
commit
cf295d3083
@ -2541,29 +2541,39 @@ function plotChart(tableId, maxCols = 9) {
|
|||||||
let table = document.getElementById(tableId);
|
let table = document.getElementById(tableId);
|
||||||
if (!table) return;
|
if (!table) return;
|
||||||
|
|
||||||
let labels = [];
|
|
||||||
let values = [];
|
|
||||||
|
|
||||||
let headerCols = table.querySelector("thead tr").children;
|
let headerCols = table.querySelector("thead tr").children;
|
||||||
let xTitle = headerCols[1].innerText.trim();
|
let xTitle = headerCols[1].innerText.trim();
|
||||||
let yTitle = headerCols[2].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 => {
|
table.querySelectorAll("tbody tr").forEach(row => {
|
||||||
let cols = row.querySelectorAll("td");
|
let cols = row.querySelectorAll("td");
|
||||||
if (cols.length >= 3) {
|
if (cols.length >= 3) {
|
||||||
if (values.length > maxCols) return;
|
|
||||||
let rowNumber = persianToEnglishNumber(cols[0].innerText.trim());
|
let rowNumber = persianToEnglishNumber(cols[0].innerText.trim());
|
||||||
if (rowNumber === "0") return; // Ignore rows with row number ۰
|
if (rowNumber === "0") return; // Ignore rows with row number ۰
|
||||||
|
|
||||||
let xValue = persianToEnglishNumber(cols[1].innerText.trim());
|
let xValue = persianToEnglishNumber(cols[1].innerText.trim());
|
||||||
let yValue = persianToEnglishNumber(cols[2].innerText.trim());
|
let yValue = persianToEnglishNumber(cols[2].innerText.trim());
|
||||||
|
|
||||||
labels.push(xValue);
|
rows.push({ label: xValue, value: parseInt(yValue) });
|
||||||
values.push(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 <table> 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}`);
|
let existingCanvas = document.getElementById(`chart-${tableId}`);
|
||||||
if (existingCanvas) {
|
if (existingCanvas) {
|
||||||
existingCanvas.remove();
|
existingCanvas.remove();
|
||||||
|
|||||||
@ -788,7 +788,11 @@ namespace RMuseum.Services.Implementation
|
|||||||
htmlText += " (بخشهایی که در این جدول نیامدهاند فاقد شعر بودهاند)";
|
htmlText += " (بخشهایی که در این جدول نیامدهاند فاقد شعر بودهاند)";
|
||||||
}
|
}
|
||||||
htmlText += $":</p>{Environment.NewLine}";
|
htmlText += $":</p>{Environment.NewLine}";
|
||||||
htmlText += $"<table class=\"stats\" id=\"cats-stats\">{Environment.NewLine}<thead>{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 += $"<table class=\"stats\" id=\"cats-stats\" data-chart-sort=\"value-desc\">{Environment.NewLine}<thead>{Environment.NewLine}" +
|
||||||
$"<tr class=\"h\">{Environment.NewLine}" +
|
$"<tr class=\"h\">{Environment.NewLine}" +
|
||||||
$"<td class=\"c1\">ردیف</td>{Environment.NewLine}" +
|
$"<td class=\"c1\">ردیف</td>{Environment.NewLine}" +
|
||||||
$"<td class=\"c2\">بخش</td>{Environment.NewLine}" +
|
$"<td class=\"c2\">بخش</td>{Environment.NewLine}" +
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user