8000 Table view - squashed by monfera · Pull Request #2052 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 44 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c4244db
table - initial commit (squashed feature branch)
monfera Oct 3, 2017
865e444
adding birds mock
monfera Oct 3, 2017
2648e51
minor mock change
monfera Oct 3, 2017
1922721
avoid crispEdges in cell contents and scrollbar; minor mock change
monfera Oct 3, 2017
30cbaa0
doc change
monfera Oct 3, 2017
aa0c116
fewer accessor uses
monfera Oct 3, 2017
c0ac213
doc update
monfera Oct 3, 2017
732bd46
more idiomatic D3
monfera Oct 3, 2017
22e23e3
no prefixing with window
monfera Oct 3, 2017
9571be3
amending document
monfera Oct 3, 2017
345b027
switched off bounciness
monfera Oct 3, 2017
ff3c8f6
minor mock fix
monfera Oct 3, 2017
b9c8de6
staying valign for the moment
monfera Oct 4, 2017
c1d19b4
fixes non-wrapping wrappable case by including it in the `alignment-b…
monfera Oct 4, 2017
f8e7647
mock update - showing text wrapping
monfera Oct 4, 2017
7186527
separate mock for wrapped text; fixing a scrolling issue
monfera Oct 4, 2017
e96c3c4
adding editType (for now, conservatively)
monfera Oct 4, 2017
5336725
new mock
monfera Oct 4, 2017
6f21697
adding multitrace latex mock; fixing multitrace drag bug
monfera Oct 4, 2017
f3f1a5d
fixing multitrace drag bug 2
monfera Oct 4, 2017
9574099
fixing multitrace drag bug 3
monfera Oct 4, 2017
5a59e04
fixing multitrace drag bug 4
monfera Oct 4, 2017
dd5841d
multitrace mock with scrollers to show trace independence
monfera Oct 4, 2017
9b60156
new mock: adding scatter plot to trace
monfera Oct 4, 2017
309c8bb
moving functionality from `calc.js` to a helper file
monfera Oct 4, 2017
78cb5ec
moving functionality from `plot.js` to the data split file
monfera Oct 4, 2017
b14f6c6
mock JSON consolidated to fewer items
monfera Oct 5, 2017
2be591f
removed clipView debug option
monfera Oct 5, 2017
addb85b
allow cell text selection
monfera Oct 5, 2017
c2f251f
fixing server image gen issue - thanks Étienne - and removing the pos…
monfera Oct 5, 2017
3cab51d
adding baselines
monfera Oct 5, 2017
fa84c68
globally safe clipPath #1
monfera Oct 5, 2017
465b45b
use overrideAll in table attributes
etpinard Oct 5, 2017
0fa1cc8
globally safe clipPath #2
monfera Oct 5, 2017
cd0578d
Merge branch 'table-squashed' of https://github.com/plotly/plotly.js …
monfera Oct 5, 2017
a6c4935
add baselines
etpinard Oct 5, 2017
0ad1a0c
preparing for user-specified stroke/stroke-opacity, fill/fill-opacity…
monfera Oct 5, 2017
1254c9f
user-specified stroke/stroke-opacity, fill/fill-opacity setting via C…
monfera Oct 5, 2017
e38b7cf
Merge branch 'table-squashed' of https://github.com/plotly/plotly.js …
monfera Oct 5, 2017
94338f4
Merge branch 'table-textselect' into table-squashed
monfera Oct 5, 2017
6288559
minor simplification before rewiring event handlers to enable text copy
monfera Oct 5, 2017
154ab24
allow both dragging and text cell copying
monfera Oct 5, 2017
9402020
disable visible scrollbar on initial load
monfera Oct 5, 2017
d4f0ed7
updating other mocks
monfera Oct 5, 2017
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
Prev Previous commit
Next Next commit
moving functionality from calc.js to a helper file
  • Loading branch information
monfera committed Oct 4, 2017
commit 309c8bb14aafe72ad7f12095ef31adf42ec45524
118 changes: 1 addition & 117 deletions src/traces/table/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,124 +8,8 @@

'use strict';

var c = require('./constants');
var wrap = require('../../lib/gup').wrap;
var extendFlat = require('../../lib/extend').extendFlat;

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 wrap(calcdata);
return wrap(trace);
};

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: []
};
}
131 changes: 131 additions & 0 deletions src/traces/table/data_preparation_helper.js
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: []
};
}
19 changes: 12 additions & 7 deletions src/traces/table/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

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.

Copy link
Contributor Author

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

}

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();

Expand Down Expand Up @@ -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;}));
})
);

Expand Down Expand Up @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... with corresponding event data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... as reordering columns (I hope) can be done via Plotly.restyle too

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 .exit().remove() to yColumn if not done yet, so let me check.

}
Expand Down
0