-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Table view - squashed #2052
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
Table view - squashed #2052
Changes from 1 commit
c4244db
865e444
2648e51
1922721
30cbaa0
aa0c116
c0ac213
732bd46
22e23e3
9571be3
345b027
ff3c8f6
b9c8de6
c1d19b4
f8e7647
7186527
e96c3c4
5336725
6f21697
f3f1a5d
9574099
5a59e04
dd5841d
9b60156
309c8bb
78cb5ec
b14f6c6
2be591f
addb85b
c2f251f
3cab51d
fa84c68
465b45b
0fa1cc8
cd0578d
a6c4935
0ad1a0c
1254c9f
e38b7cf
94338f4
6288559
154ab24
9402020
d4f0ed7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
calc.js
to a helper file
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/** | ||
* Copyright 2012-2017, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var c = require('./constants'); | ||
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 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 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; | ||
var minimumFillHeight = scrollHeight + c.uplift; | ||
var anchorToRowBlock = makeAnchorToRowBlock(rowHeights, minimumFillHeight); | ||
var anchorToHeaderRowBlock = makeAnchorToRowBlock(headerRowHeights, headerHeight); | ||
var headerRowBlocks = makeRowBlock(anchorToHeaderRowBlock, []); | ||
var rowBlocks = makeRowBlock(anchorToRowBlock, headerRowBlocks); | ||
var uniqueKeys = {}; | ||
var columnOrder = trace._fullInput.columnorder; | ||
var columnWidths = trace.header.values.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; | ||
}); | ||
var totalColumnWidths = columnWidths.reduce(function(p, n) {return p + n;}, 0); | ||
|
||
// fit columns in the available vertical space as there's no vertical scrolling now | ||
columnWidths = columnWidths.map(function(d) {return d / totalColumnWidths * groupWidth;}); | ||
|
||
var calcdata = { | ||
key: trace.index, | ||
translateX: domain.x[0] * gd._fullLayout._size.w, | ||
translateY: gd._fullLayout._size.h * (1 - domain.y[1]), | ||
size: gd._fullLayout._size, | ||
width: groupWidth, | ||
height: groupHeight, | ||
columnOrder: columnOrder, // will be mutated on column move, todo use in callback | ||
groupHeight: groupHeight, | ||
rowBlocks: rowBlocks, | ||
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];}), | ||
prevPages: [0, 0], | ||
scrollbarState: {scrollbarScrollInProgress: false}, | ||
columns: trace.header.values.map(function(label, i) { | ||
var foundKey = uniqueKeys[label]; | ||
uniqueKeys[label] = (foundKey || 0) + 1; | ||
var key = label + '__' + uniqueKeys[label]; | ||
return { | ||
key: key, | ||
label: label, | ||
specIndex: i, | ||
xIndex: columnOrder[i], | ||
xScale: xScale, | ||
x: undefined, // initialized below | ||
calcdata: undefined, // initialized below | ||
columnWidth: columnWidths[i] | ||
}; | ||
}) | ||
}; | ||
|
||
calcdata.columns.forEach(function(col) { | ||
col.calcdata = calcdata; | ||
col.x = xScale(col); | ||
}); | ||
|
||
return calcdata; | ||
}; | ||
|
||
function xScale(d) { | ||
return d.calcdata.columns.reduce(function(prev, next) { | ||
return next.xIndex < d.xIndex ? prev + next.columnWidth : prev; | ||
}, 0); | ||
} | ||
|
||
function makeRowBlock(anchorToRowBlock, auxiliary) { | ||
var blockAnchorKeys = Object.keys(anchorToRowBlock); | ||
return blockAnchorKeys.map(function(k) {return extendFlat({}, anchorToRowBlock[k], {auxiliaryBlocks: auxiliary});}); | ||
} | ||
|
||
function makeAnchorToRowBlock(rowHeights, minimumFillHeight) { | ||
|
||
var anchorToRowBlock = {}; | ||
var currentRowHeight; | ||
var currentAnchor = 0; | ||
var currentBlockHeight = 0; | ||
var currentBlock = makeIdentity(); | ||
var currentFirstRowIndex = 0; | ||
var blockCounter = 0; | ||
for(var i = 0; i < rowHeights.length; i++) { | ||
currentRowHeight = rowHeights[i]; | ||
currentBlock.rows.push({ | ||
rowIndex: i, | ||
rowHeight: currentRowHeight | ||
}); | ||
currentBlockHeight += currentRowHeight; | ||
if(currentBlockHeight >= minimumFillHeight || i === rowHeights.length - 1) { | ||
anchorToRowBlock[currentAnchor] = currentBlock; | ||
currentBlock.key = blockCounter++; | ||
currentBlock.firstRowIndex = currentFirstRowIndex; | ||
currentBlock.lastRowIndex = i; | ||
currentBlock = makeIdentity(); | ||
currentAnchor += currentBlockHeight; | ||
currentFirstRowIndex = i + 1; | ||
currentBlockHeight = 0; | ||
} | ||
} | ||
|
||
return anchorToRowBlock; | ||
} | ||
|
||
function makeIdentity() { | ||
return { | ||
firstRowIndex: null, | ||
lastRowIndex: null, | ||
rows: [] | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,20 @@ var extendFlat = require('../../lib/extend').extendFlat; | |
var svgUtil = require('../../lib/svg_text_utils'); | ||
var raiseToTop = require('../../lib').raiseToTop; | ||
var cancelEeaseColumn = require('../../lib').cancelTransition; | ||
var prepareData = require('./data_preparation_helper'); | ||
|
||
module.exports = function plot(gd, calcdata) { | ||
module.exports = function plot(gd, wrappedTraceHolders) { | ||
|
||
if(c.clipView) { | ||
gd._fullLayout._paper.attr('height', 2000); | ||
} | ||
|
||
var table = gd._fullLayout._paper.selectAll('.table') | ||
.data(calcdata.map(gup.unwrap), gup.keyFun); | ||
.data(wrappedTraceHolders.map(function(wrappedTraceHolder) { | ||
var traceHolder = gup.unwrap(wrappedTraceHolder); | ||
var trace = traceHolder.trace; | ||
return prepareData(gd, trace); | ||
}), gup.keyFun); | ||
|
||
table.exit().remove(); | ||
|
||
|
@@ -130,7 +135,7 @@ module.exports = function plot(gd, calcdata) { | |
d.x = d.xScale(d); | ||
d.calcdata.columnDragInProgress = false; | ||
easeColumn(movedColumn, d, 0); | ||
columnMoved(gd, calcdata, p.key, p.columns.map(function(dd) {return dd.xIndex;})); | ||
columnMoved(gd, p, p.columns.map(function(dd) {return dd.xIndex;})); | ||
}) | ||
); | ||
|
||
|
@@ -557,13 +562,13 @@ function isLatex(content) { | |
|
||
function hasWrapCharacter(text) {return text.indexOf(c.wrapSplitCharacter) !== -1;} | ||
|
||
function columnMoved(gd, calcdata, i, indices) { | ||
var o = calcdata[i][0].gdColumnsOriginalOrder; | ||
calcdata[i][0].gdColumns.sort(function(a, b) { | ||
function columnMoved(gd, calcdata, indices) { | ||
var o = calcdata.gdColumnsOriginalOrder; | ||
calcdata.gdColumns.sort(function(a, b) { | ||
return indices[o.indexOf(a)] - indices[o.indexOf(b)]; | ||
}); | ||
|
||
calcdata[i][0].columnorder = indices; | ||
calcdata.columnorder = indices; | ||
|
||
gd.emit('plotly_restyle'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... with corresponding event data. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... as reordering columns (I hope) can be done via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, although I haven't yet tested it and maybe it'll need an |
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clipView: false
in constants.js. So is this block only useful for debugging? It so, 🔪 please.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, invaluable for development even to the last touches, planning to 🔪 it just before the merge