Skip to content
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
8 changes: 4 additions & 4 deletions cpp/perspective/src/cpp/emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ EMSCRIPTEN_BINDINGS(perspective) {
.function("schema", &View<t_ctxunit>::schema)
.function("expression_schema", &View<t_ctxunit>::expression_schema)
.function("column_names", &View<t_ctxunit>::column_names)
.function("column_paths", &View<t_ctxunit>::column_paths)
.function("column_paths", &View<t_ctxunit>::column_paths_string)
.function("_get_deltas_enabled", &View<t_ctxunit>::_get_deltas_enabled)
.function("_set_deltas_enabled", &View<t_ctxunit>::_set_deltas_enabled)
.function(
Expand Down Expand Up @@ -2172,7 +2172,7 @@ EMSCRIPTEN_BINDINGS(perspective) {
.function("schema", &View<t_ctx0>::schema)
.function("expression_schema", &View<t_ctx0>::expression_schema)
.function("column_names", &View<t_ctx0>::column_names)
.function("column_paths", &View<t_ctx0>::column_paths)
.function("column_paths", &View<t_ctx0>::column_paths_string)
.function("_get_deltas_enabled", &View<t_ctx0>::_get_deltas_enabled)
.function("_set_deltas_enabled", &View<t_ctx0>::_set_deltas_enabled)
.function(
Expand Down Expand Up @@ -2207,7 +2207,7 @@ EMSCRIPTEN_BINDINGS(perspective) {
.function("schema", &View<t_ctx1>::schema)
.function("expression_schema", &View<t_ctx1>::expression_schema)
.function("column_names", &View<t_ctx1>::column_names)
.function("column_paths", &View<t_ctx1>::column_paths)
.function("column_paths", &View<t_ctx1>::column_paths_string)
.function("_get_deltas_enabled", &View<t_ctx1>::_get_deltas_enabled)
.function("_set_deltas_enabled", &View<t_ctx1>::_set_deltas_enabled)
.function(
Expand Down Expand Up @@ -2241,7 +2241,7 @@ EMSCRIPTEN_BINDINGS(perspective) {
.function("schema", &View<t_ctx2>::schema)
.function("expression_schema", &View<t_ctx2>::expression_schema)
.function("column_names", &View<t_ctx2>::column_names)
.function("column_paths", &View<t_ctx2>::column_paths)
.function("column_paths", &View<t_ctx2>::column_paths_string)
.function("_get_deltas_enabled", &View<t_ctx2>::_get_deltas_enabled)
.function("_set_deltas_enabled", &View<t_ctx2>::_set_deltas_enabled)
.function(
Expand Down
19 changes: 19 additions & 0 deletions cpp/perspective/src/cpp/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,25 @@ View<CTX_T>::column_paths() const {
return names;
}

template <typename CTX_T>
std::vector<std::vector<std::string>>
View<CTX_T>::column_paths_string() const {
auto paths = column_paths();
std::vector<std::vector<std::string>> out;
out.reserve(paths.size());
for (const auto& path : paths) {
std::vector<std::string> row;
row.reserve(path.size());
for (const auto& c : path) {
row.push_back(c.to_string());
}

out.push_back(row);
}

return out;
}

template <typename CTX_T>
std::map<std::string, std::string>
View<CTX_T>::schema() const {
Expand Down
2 changes: 2 additions & 0 deletions cpp/perspective/src/include/perspective/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class PERSPECTIVE_EXPORT View {
*/
std::vector<std::vector<t_tscalar>> column_paths() const;

std::vector<std::vector<std::string>> column_paths_string() const;

/**
* @brief
*
Expand Down
26 changes: 26 additions & 0 deletions packages/perspective-viewer-datagrid/test/js/superstore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,30 @@ test.describe("Datagrid with superstore data set", () => {
"row-headers-are-printed-correctly"
);
});

test("Column headers are printed correctly, split_by a date column", async ({
page,
}) => {
await page.goto("/tools/perspective-test/src/html/basic-test.html");
await page.evaluate(async () => {
while (!window["__TEST_PERSPECTIVE_READY__"]) {
await new Promise((x) => setTimeout(x, 10));
}
});

await page.evaluate(async () => {
await document.querySelector("perspective-viewer").restore({
plugin: "Datagrid",
columns: ["Sales", "Profit"],
group_by: ["State"],
split_by: ["New Col"],
expressions: { "New Col": "bucket(\"Order Date\",'Y')" },
});
});

compareContentsToSnapshot(
await getDatagridContents(page),
"column-headers-are-printed-correctly-split-by-a-date-column"
);
});
});
21 changes: 20 additions & 1 deletion packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,25 @@ export default function (Module) {
return extracted;
};

const extract_vector_string = function (vector) {
// handles deletion already - do not call delete() on the input vector
// again
let extracted = [];
for (let i = 0; i < vector.size(); i++) {
let item = vector.get(i);
let row = [];
for (let i = 0; i < item.size(); i++) {
let s = item.get(i);
row.push(s);
}

item.delete();
extracted.push(row);
}
vector.delete();
return extracted;
};

/**
* The schema of this {@link module:perspective~view}.
*
Expand Down Expand Up @@ -420,7 +439,7 @@ export default function (Module) {
* @returns {Array<String>} an Array of Strings containing the column paths.
*/
view.prototype.column_paths = function () {
return extract_vector_scalar(this._View.column_paths()).map((x) =>
return extract_vector_string(this._View.column_paths()).map((x) =>
x.join(defaults.COLUMN_SEPARATOR_STRING)
);
};
Expand Down
27 changes: 27 additions & 0 deletions packages/perspective/test/js/pivots.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3082,5 +3082,32 @@ const std = (nums) => {
view.delete();
table.delete();
});

test("Should format date columns in split_by", async function () {
const table = await perspective.table({
w: "float",
x: "integer",
y: "string",
z: "date",
});

await table.update(data_8);
const view = await table.view({ group_by: ["y"], split_by: ["z"] });
const paths = await view.column_paths();
expect(paths).toEqual([
"__ROW_PATH__",
"2019-04-11|w",
"2019-04-11|x",
"2019-04-11|y",
"2019-04-11|z",
"2019-04-13|w",
"2019-04-13|x",
"2019-04-13|y",
"2019-04-13|z",
]);

view.delete();
table.delete();
});
});
})(perspective);
Binary file modified tools/perspective-test/results.tar.gz
Binary file not shown.