Skip to content
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

Two sided sort fixes #805

Merged
merged 2 commits into from
Nov 10, 2019
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
13 changes: 8 additions & 5 deletions cpp/perspective/src/cpp/context_two.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ t_ctx2::open(t_header header, t_index idx) {
return 0;
m_row_depth_set = false;
m_row_depth = 0;
if (m_row_sortby.empty()) {
if (m_sortby.empty()) {
retval = m_rtraversal->expand_node(idx);
} else {
retval = m_rtraversal->expand_node(m_row_sortby, idx);
retval = m_rtraversal->expand_node(m_sortby, idx);
}
m_rows_changed = (retval > 0);
} else {
Expand Down Expand Up @@ -370,7 +370,7 @@ t_ctx2::notify(const t_data_table& flattened, const t_data_table& delta,
for (t_uindex tree_idx = 0, loop_end = m_trees.size(); tree_idx < loop_end; ++tree_idx) {
if (is_rtree_idx(tree_idx)) {
notify_sparse_tree(rtree(), m_rtraversal, true, m_config.get_aggregates(),
m_config.get_sortby_pairs(), m_row_sortby, flattened, delta, prev, current,
m_config.get_sortby_pairs(), m_sortby, flattened, delta, prev, current,
transitions, existed, m_config, *m_state);
} else if (is_ctree_idx(tree_idx)) {
notify_sparse_tree(ctree(), m_ctraversal, true, m_config.get_aggregates(),
Expand Down Expand Up @@ -630,7 +630,7 @@ t_ctx2::set_depth(t_header header, t_depth depth) {
if (m_config.get_num_rpivots() == 0)
return;
new_depth = std::min<t_depth>(m_config.get_num_rpivots() - 1, depth);
m_rtraversal->set_depth(m_row_sortby, new_depth);
m_rtraversal->set_depth(m_sortby, new_depth);
m_row_depth = new_depth;
m_row_depth_set = true;
} break;
Expand Down Expand Up @@ -882,7 +882,7 @@ t_ctx2::notify(const t_data_table& flattened) {
for (t_uindex tree_idx = 0, loop_end = m_trees.size(); tree_idx < loop_end; ++tree_idx) {
if (is_rtree_idx(tree_idx)) {
notify_sparse_tree(rtree(), m_rtraversal, true, m_config.get_aggregates(),
m_config.get_sortby_pairs(), m_row_sortby, flattened, m_config, *m_state);
m_config.get_sortby_pairs(), m_sortby, flattened, m_config, *m_state);
} else if (is_ctree_idx(tree_idx)) {
notify_sparse_tree(ctree(), m_ctraversal, true, m_config.get_aggregates(),
m_config.get_sortby_pairs(), m_column_sortby, flattened, m_config, *m_state);
Expand All @@ -892,6 +892,9 @@ t_ctx2::notify(const t_data_table& flattened) {
std::vector<t_sortspec>(), flattened, m_config, *m_state);
}
}
if (!m_sortby.empty()) {
sort_by(m_sortby);
}
}

void
Expand Down
1 change: 0 additions & 1 deletion cpp/perspective/src/include/perspective/context_two.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class PERSPECTIVE_EXPORT t_ctx2 : public t_ctxbase<t_ctx2> {
std::vector<t_sortspec> m_sortby;
bool m_rows_changed;
std::vector<std::shared_ptr<t_stree>> m_trees;
std::vector<t_sortspec> m_row_sortby;
std::vector<t_sortspec> m_column_sortby;
t_depth m_row_depth;
bool m_row_depth_set;
Expand Down
13 changes: 13 additions & 0 deletions packages/perspective/test/js/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,18 @@ module.exports = perspective => {
view.delete();
table.delete();
});

it("Preserves sort order with 2-sided pivot", async function() {
const input = [{x: 1, y: 7, z: "a"}, {x: 1, y: 6, z: "b"}, {x: 2, y: 5, z: "a"}, {x: 2, y: 4, z: "b"}, {x: 3, y: 3, z: "a"}, {x: 3, y: 2, z: "b"}];
const table = perspective.table(input);
const view = table.view({row_pivots: ["z"], column_pivots: ["x"], sort: [["y", "asc"]], columns: ["y"]});
setTimeout(() => table.replace(input));
let json = await view.to_json();
await new Promise(setTimeout);
let json2 = await view.to_json();
expect(json).toEqual(json2);
view.delete();
table.delete();
});
});
};