Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0a9b19c

Browse filesBrowse files
authored
Merge pull request plotly#2072 from plotly/table-1d-header
Allow 1D header in `table`
2 parents adf3b03 + 37ba12a commit 0a9b19c
Copy full SHA for 0a9b19c

File tree

Expand file treeCollapse file tree

2 files changed

+10
-7
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-7
lines changed

‎src/traces/table/data_preparation_helper.js

Copy file name to clipboardExpand all lines: src/traces/table/data_preparation_helper.js
+9-6Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ var extendFlat = require('../../lib/extend').extendFlat;
1313

1414
// pure functions, don't alter but passes on `gd` and parts of `trace` without deep copying
1515
module.exports = function calc(gd, trace) {
16+
var headerValues = trace.header.values.map(function(c) {
17+
return Array.isArray(c) ? c : [c];
18+
});
1619
var domain = trace.domain;
1720
var groupWidth = Math.floor(gd._fullLayout._size.w * (domain.x[1] - domain.x[0]));
1821
var groupHeight = Math.floor(gd._fullLayout._size.h * (domain.y[1] - domain.y[0]));
19-
var headerRowHeights = trace.header.values[0].map(function() {return trace.header.height;});
22+
var headerRowHeights = headerValues[0].map(function() {return trace.header.height;});
2023
var rowHeights = trace.cells.values[0].map(function() {return trace.cells.height;});
2124
var headerHeight = headerRowHeights.reduce(function(a, b) {return a + b;}, 0);
2225
var scrollHeight = groupHeight - headerHeight;
@@ -27,7 +30,7 @@ module.exports = function calc(gd, trace) {
2730
var rowBlocks = makeRowBlock(anchorToRowBlock, headerRowBlocks);
2831
var uniqueKeys = {};
2932
var columnOrder = trace._fullInput.columnorder;
30-
var columnWidths = trace.header.values.map(function(d, i) {
33+
var columnWidths = headerValues.map(function(d, i) {
3134
return Array.isArray(trace.columnwidth) ?
3235
trace.columnwidth[Math.min(i, trace.columnwidth.length - 1)] :
3336
isFinite(trace.columnwidth) && trace.columnwidth !== null ? trace.columnwidth : 1;
@@ -50,12 +53,12 @@ module.exports = function calc(gd, trace) {
5053
headerRowBlocks: headerRowBlocks,
5154
scrollY: 0, // will be mutated on scroll
5255
cells: trace.cells,
53-
headerCells: trace.header,
54-
gdColumns: trace.header.values.map(function(d) {return d[0];}),
55-
gdColumnsOriginalOrder: trace.header.values.map(function(d) {return d[0];}),
56+
headerCells: extendFlat({}, trace.header, {values: headerValues}),
57+
gdColumns: headerValues.map(function(d) {return d[0];}),
58+
gdColumnsOriginalOrder: headerValues.map(function(d) {return d[0];}),
5659
prevPages: [0, 0],
5760
scrollbarState: {scrollbarScrollInProgress: false},
58-
columns: trace.header.values.map(function(label, i) {
61+
columns: headerValues.map(function(label, i) {
5962
var foundKey = uniqueKeys[label];
6063
uniqueKeys[label] = (foundKey || 0) + 1;
6164
var key = label + '__' + uniqueKeys[label];

‎test/image/mocks/table_latex_multitrace.json

Copy file name to clipboardExpand all lines: test/image/mocks/table_latex_multitrace.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"columnorder": [0, 1, 2],
2020

2121
"header": {
22-
"values": [["<b>#</b>"], ["Half-angle form"], ["Equivalent"]],
22+
"values": ["<b>#</b>", "Half-angle form", "Equivalent"],
2323
"align": ["right", "center", "center"],
2424
"line": {"width": 0.0},
2525
"fill": {"color": ["dimgray", "grey"]},

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.