diff --git a/cpp/perspective/src/cpp/context_two.cpp b/cpp/perspective/src/cpp/context_two.cpp index 365ec845c2..308441998b 100644 --- a/cpp/perspective/src/cpp/context_two.cpp +++ b/cpp/perspective/src/cpp/context_two.cpp @@ -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 { @@ -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(), @@ -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(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; @@ -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); @@ -892,6 +892,9 @@ t_ctx2::notify(const t_data_table& flattened) { std::vector(), flattened, m_config, *m_state); } } + if (!m_sortby.empty()) { + sort_by(m_sortby); + } } void diff --git a/cpp/perspective/src/include/perspective/context_two.h b/cpp/perspective/src/include/perspective/context_two.h index 0edc5247a5..95aded54a3 100644 --- a/cpp/perspective/src/include/perspective/context_two.h +++ b/cpp/perspective/src/include/perspective/context_two.h @@ -77,7 +77,6 @@ class PERSPECTIVE_EXPORT t_ctx2 : public t_ctxbase { std::vector m_sortby; bool m_rows_changed; std::vector> m_trees; - std::vector m_row_sortby; std::vector m_column_sortby; t_depth m_row_depth; bool m_row_depth_set; diff --git a/packages/perspective/test/js/clear.js b/packages/perspective/test/js/clear.js index 5221510bb6..87f5a80fd0 100644 --- a/packages/perspective/test/js/clear.js +++ b/packages/perspective/test/js/clear.js @@ -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(); + }); }); };