Skip to content

Allow 1D header in table #2072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/traces/table/data_preparation_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ var extendFlat = require('../../lib/extend').extendFlat;

// pure functions, don't alter but passes on `gd` and parts of `trace` without deep copying
module.exports = function calc(gd, trace) {
var headerValues = trace.header.values.map(function(c) {
return Array.isArray(c) ? c : [c];
});
var domain = trace.domain;
var groupWidth = Math.floor(gd._fullLayout._size.w * (domain.x[1] - domain.x[0]));
var groupHeight = Math.floor(gd._fullLayout._size.h * (domain.y[1] - domain.y[0]));
var headerRowHeights = trace.header.values[0].map(function() {return trace.header.height;});
var headerRowHeights = headerValues[0].map(function() {return trace.header.height;});
var rowHeights = trace.cells.values[0].map(function() {return trace.cells.height;});
var headerHeight = headerRowHeights.reduce(function(a, b) {return a + b;}, 0);
var scrollHeight = groupHeight - headerHeight;
Expand All @@ -27,7 +30,7 @@ module.exports = function calc(gd, trace) {
var rowBlocks = makeRowBlock(anchorToRowBlock, headerRowBlocks);
var uniqueKeys = {};
var columnOrder = trace._fullInput.columnorder;
var columnWidths = trace.header.values.map(function(d, i) {
var columnWidths = headerValues.map(function(d, i) {
return Array.isArray(trace.columnwidth) ?
trace.columnwidth[Math.min(i, trace.columnwidth.length - 1)] :
isFinite(trace.columnwidth) && trace.columnwidth !== null ? trace.columnwidth : 1;
Expand All @@ -50,12 +53,12 @@ module.exports = function calc(gd, trace) {
headerRowBlocks: headerRowBlocks,
scrollY: 0, // will be mutated on scroll
cells: trace.cells,
headerCells: trace.header,
gdColumns: trace.header.values.map(function(d) {return d[0];}),
gdColumnsOriginalOrder: trace.header.values.map(function(d) {return d[0];}),
headerCells: extendFlat({}, trace.header, {values: headerValues}),
gdColumns: headerValues.map(function(d) {return d[0];}),
gdColumnsOriginalOrder: headerValues.map(function(d) {return d[0];}),
prevPages: [0, 0],
scrollbarState: {scrollbarScrollInProgress: false},
columns: trace.header.values.map(function(label, i) {
columns: headerValues.map(function(label, i) {
var foundKey = uniqueKeys[label];
uniqueKeys[label] = (foundKey || 0) + 1;
var key = label + '__' + uniqueKeys[label];
Expand Down
2 changes: 1 addition & 1 deletion test/image/mocks/table_latex_multitrace.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"columnorder": [0, 1, 2],

"header": {
"values": [["<b>#</b>"], ["Half-angle form"], ["Equivalent"]],
"values": ["<b>#</b>", "Half-angle form", "Equivalent"],
"align": ["right", "center", "center"],
"line": {"width": 0.0},
"fill": {"color": ["dimgray", "grey"]},
Expand Down