Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Giehl <stefan@matomo.org>2022-07-25 12:07:06 +0300
committerGitHub <noreply@github.com>2022-07-25 12:07:06 +0300
commiteeb20ec4eb3ad3d0ac5c4ec952852cdde3ffad38 (patch)
tree495b1f1dfe5c6e84f1ab4e2a84a54bb2000836ea /plugins/CoreHome/javascripts
parent6cc723685d3c1c9b399b09e9b691b9f2dba80bce (diff)
Fix sizing of subtables with different column count (#19540)
* Don't try to align column width of subtables where column count differs from base table * Improve fix and avoid table resizes when not needed * fix tests * updates expected test files * [TEMP] submodule update * add some comments
Diffstat (limited to 'plugins/CoreHome/javascripts')
-rw-r--r--plugins/CoreHome/javascripts/dataTable.js58
1 files changed, 49 insertions, 9 deletions
diff --git a/plugins/CoreHome/javascripts/dataTable.js b/plugins/CoreHome/javascripts/dataTable.js
index 253a942fc4..95444fa5df 100644
--- a/plugins/CoreHome/javascripts/dataTable.js
+++ b/plugins/CoreHome/javascripts/dataTable.js
@@ -542,19 +542,21 @@ $.extend(DataTable.prototype, UIControl.prototype, {
var paddingLeft = elem.css('paddingLeft');
paddingLeft = paddingLeft ? Math.round(parseFloat(paddingLeft)) : 0;
var paddingRight = elem.css('paddingRight');
- paddingRight = paddingRight ? Math.round(parseFloat(paddingLeft)) : 0;
+ paddingRight = paddingRight ? Math.round(parseFloat(paddingRight)) : 0;
- labelWidth = labelWidth - paddingLeft - paddingRight;
+ if (elem.find('.prefix-numeral').length) {
+ labelWidth -= Math.round(parseFloat(elem.find('.prefix-numeral').outerWidth()));
+ }
- return labelWidth;
+ return labelWidth - paddingLeft - paddingRight;
}
setMaxTableWidthIfNeeded(domElem, 1200);
- var isTableVisualization = this.jsViewDataTable
- && typeof this.jsViewDataTable === 'string'
- && typeof this.jsViewDataTable.indexOf === 'function'
- && this.jsViewDataTable.indexOf('table') !== -1;
+ var isTableVisualization = this.param.viewDataTable
+ && typeof this.param.viewDataTable === 'string'
+ && typeof this.param.viewDataTable.indexOf === 'function'
+ && this.param.viewDataTable.indexOf('table') !== -1;
if (isTableVisualization) {
// we do this only for html tables
@@ -569,9 +571,41 @@ $.extend(DataTable.prototype, UIControl.prototype, {
labelColumnWidth = labelColumnMaxWidth;
}
+ // special handling if the loaded datatable is a subtable
+ if ($(domElem).closest('.subDataTableContainer').length) {
+ var parentTable = $(domElem).closest('table.dataTable');
+ var tableColumns = $('table:eq(0)>thead th', domElem).length;
+ var parentTableColumns = $('>thead th', parentTable).length;
+ var labelColumn = $('>tbody td.label:eq(0)', parentTable);
+ var labelWidthParentTable = labelColumn.outerWidth();
+
+ // if the subtable has the same column count as the main table, we rearrange all tables
+ if (parentTableColumns === tableColumns) {
+ labelColumnWidth = Math.min(labelColumnWidth, labelWidthParentTable);
+
+ // rearrange base table labels, so the tables are displayed aligned
+ $('>tbody>tr:not(.subDataTableContainer)>td.label', parentTable).each(function() {
+ $(this).css({
+ width: removePaddingFromWidth($(this), labelColumnWidth) + 'px'
+ });
+ });
+
+ // rearrange all subtables having the same column count
+ $('>tbody>tr.subDataTableContainer', parentTable).each(function() {
+ if ($('table:eq(0)>thead th', this).length === parentTableColumns) {
+ $(this).css({
+ width: removePaddingFromWidth($(this), labelColumnWidth) + 'px'
+ });
+ }
+ });
+ }
+ }
+
if (labelColumnWidth) {
$('td.label', domElem).each(function() {
- $(this).width(removePaddingFromWidth($(this), labelColumnWidth));
+ $(this).css({
+ width: removePaddingFromWidth($(this), labelColumnWidth) + 'px'
+ });
});
}
@@ -583,8 +617,13 @@ $.extend(DataTable.prototype, UIControl.prototype, {
// on resize of the window we re-calculate everything.
var timeout = null;
+ var windowWidth = 0;
var resizeDataTable = function() {
+ if (windowWidth === $(window).width()) {
+ return; // only resize a data table if the width changes
+ }
+
if (timeout) {
clearTimeout(timeout);
}
@@ -598,6 +637,7 @@ $.extend(DataTable.prototype, UIControl.prototype, {
$('td.label', domElem).width('');
}
self.setFixWidthToMakeEllipsisWork(domElem);
+ windowWidth = $(window).width();
} else {
$(window).off('resize', resizeDataTable);
}
@@ -1446,7 +1486,7 @@ $.extend(DataTable.prototype, UIControl.prototype, {
var self = this;
// highlight all columns on hover
- $(domElem).on('mouseenter', 'td', function (e) {
+ $(domElem).on('mouseenter', 'td:not(.cellSubDataTable)', function (e) {
e.stopPropagation();
var $this = $(e.target);
if ($this.hasClass('label')) {