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

Computed columns with multiple parameters #223

Merged
merged 10 commits into from
Sep 3, 2018
Merged
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,4 @@ website/i18n/*

.idea
cmake-build-debug
.ipynb_checkpoints
8 changes: 3 additions & 5 deletions packages/perspective-viewer-highcharts/src/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function default_config(aggregates, mode) {
const that = this,
config = that._view._config;

const axis_titles = get_axis_titles(config.aggregate, config.sort);
const axis_titles = get_axis_titles(config.aggregate);
const pivot_titles = get_pivot_titles(config.row_pivot, config.column_pivot);

return {
Expand Down Expand Up @@ -248,14 +248,12 @@ export function default_config(aggregates, mode) {
}
}

function get_axis_titles(aggs, sort) {
const sort_titles = sort.map(row => row[0]);
function get_axis_titles(aggs) {
let titles = [];

for (let i = 0; i < aggs.length; i++) {
let axis_title = aggs[i].column;
if(!sort_titles.includes(axis_title))
titles.push(aggs[i].column);
titles.push(axis_title);
}
return titles;
}
Expand Down
19 changes: 8 additions & 11 deletions packages/perspective-viewer-highcharts/src/js/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
*
*/

/******************************************************************************
*
* Y
*/
import {COLUMN_SEPARATOR_STRING} from "@jpmorganchase/perspective/src/js/defaults.js";

function row_to_series(series, sname, gname) {
let s;
Expand Down Expand Up @@ -89,12 +86,12 @@ class ColumnsIterator {
for (let row of this.rows) {
if (this.columns === undefined) {
this.columns = Object.keys(row).filter(prop => {
let cname = prop.split(',');
let cname = prop.split(COLUMN_SEPARATOR_STRING);
cname = cname[cname.length - 1];
return prop !== "__ROW_PATH__" && this.hidden.indexOf(cname) === -1;
});
this.is_stacked = this.columns.map(value =>
value.substr(value.lastIndexOf(',') + 1, value.length)
value.substr(value.lastIndexOf(COLUMN_SEPARATOR_STRING) + 1, value.length)
).filter((value, index, self) =>
self.indexOf(value) === index
).length > 1;
Expand All @@ -111,7 +108,7 @@ export function make_y_data(js, pivots, hidden) {

for (let row of rows2) {
for (let prop of rows2.columns) {
let sname = prop.split(',');
let sname = prop.split(COLUMN_SEPARATOR_STRING);
let gname = sname[sname.length - 1];
if (rows2.is_stacked) {
sname = sname.join(", ") || gname;
Expand Down Expand Up @@ -226,12 +223,12 @@ export function make_xy_data(js, schema, columns, pivots, col_pivots, hidden) {
} else {
let prev, group = [], s;
let cols = Object.keys(js[0]).filter(prop => {
let cname = prop.split(',');
let cname = prop.split(COLUMN_SEPARATOR_STRING);
cname = cname[cname.length - 1];
return prop !== "__ROW_PATH__" && hidden.indexOf(cname) === -1;
});
for (let prop of cols) {
let column_levels = prop.split(',');
let column_levels = prop.split(COLUMN_SEPARATOR_STRING);
let group_name = column_levels.slice(0, column_levels.length - 1).join(",") || " ";
if (prev === undefined) {
prev = group_name;
Expand Down Expand Up @@ -382,7 +379,7 @@ function make_levels(row_pivots) {
function make_configs(series, levels) {
let configs = [];
for (let data of series) {
let title = data.name.split(',');
let title = data.name.split(COLUMN_SEPARATOR_STRING);
configs.push({
layoutAlgorithm: 'squarified',
allowDrillToNode: true,
Expand All @@ -409,7 +406,7 @@ export function make_tree_data(js, row_pivots, hidden, aggregates, leaf_only) {

for (let idx = 0; idx < rows2.columns.length; idx++) {
let prop = rows2.columns[idx];
let sname = prop.split(',');
let sname = prop.split(COLUMN_SEPARATOR_STRING);
let gname = sname[sname.length - 1];
sname = sname.slice(0, sname.length - 1).join(", ") || " ";
if (idx % aggregates.length === 0) {
Expand Down
9 changes: 9 additions & 0 deletions packages/perspective-viewer-highcharts/src/js/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,19 @@ export function format_tooltip(context, type, schema, axis_titles, pivot_titles)
function collate_single_value(title, raw_value, schema) {
const type = get_axis_type(title, schema);
const formatted_value = format_value(raw_value, type);

/* columns in aggregate AND in sort need to show up, but
* columns not in aggregate but NOT in sort need to hide */
if (formatted_value === 'NaN' || formatted_value === null || formatted_value === undefined)
return '';

return `<span>${ title }: <b>${ formatted_value }</b></span><br/>`;
}

function collate_multiple_values(titles, values) {
if (values.length <= 0)
return '';

let output = [];
for (let i = 0; i < titles.length; i++) {
output.push(`<span>${ titles[i] }: <b>${ values[i] }</b></span><br/>`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
*
*/

import {COLUMN_SEPARATOR_STRING} from "@jpmorganchase/perspective/src/js/defaults.js";

const TREE_COLUMN_INDEX = require('fin-hypergrid/src/behaviors/Behavior').prototype.treeColumnIndex;

function filter_hidden(hidden, json) {
for (let key of Object.keys(json)) {
const split_key = key.split(',');
const split_key = key.split(COLUMN_SEPARATOR_STRING);
if (hidden.indexOf(split_key[split_key.length - 1].trim()) >= 0) {
delete json[key];
}
Expand All @@ -36,7 +38,7 @@ function psp2hypergrid(data, hidden, schema, tschema, row_pivots) {
var is_tree = !!row_pivots.length;

var flat_columns = Object.keys(data).filter(row => row !== '__ROW_PATH__');
var columnPaths = flat_columns.map(row => row.split(','));
var columnPaths = flat_columns.map(row => row.split(COLUMN_SEPARATOR_STRING));

let rows = [];

Expand Down
9 changes: 5 additions & 4 deletions packages/perspective-viewer/src/html/computed_column.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@
<span id="psp-cc__mode"></span>
</div>
<div class="psp-cc__container" style="margin-top:-7px;">
<div id="psp-cc-computation">
<div class="psp-cc__content">
<div id="psp-cc-computation__type"></div>
<span contentEditable=true type="text" required maxlength="25" size="10" autocomplete="off" id="psp-cc-name" ondragover="disallowDrop(event)"/>
</div>
</div>
<div class="psp-cc__container">
<div id="psp-cc-computation">
<div class="psp-cc__content">
<select id="psp-cc-computation__select">
</select>
</div>
</div>
<div class="psp-cc__container" style="margin-top:-12px;">
<span id="psp-cc__error--input" class="psp-cc__label psp-cc__error"></span>
<div id="psp-cc-computation__input-column" drop-target ondragenter="dragEnter(event)"></div>
<div id="psp-cc-computation__drop-target-hover"></div>
<div id="psp-cc-computation-inputs">
<!--<div class="psp-cc-computation__input-column" drop-target ondragenter="dragEnter(event)"></div>-->
</div>
</div>
<div class="psp-cc__container">
<span id="psp-cc__error--save" class="psp-cc__label psp-cc__error"></span>
Expand Down
Loading