Skip to content

Commit

Permalink
remove old parser that converted to rows, refactor to use columns only
Browse files Browse the repository at this point in the history
  • Loading branch information
sc1f committed Sep 7, 2018
1 parent 8a4b5e6 commit 583028d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 55 deletions.
4 changes: 2 additions & 2 deletions packages/perspective-viewer-highcharts/src/js/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "../less/highcharts.less";

import {COLORS_10, COLORS_20} from "./externals.js";
import {color_axis} from "./color_axis.js";
import {make_tree_data, make_y_data, make_y_columnar_data, make_xy_data, make_xyz_data} from "./series.js";
import {make_tree_data, make_y_data, make_xy_data, make_xyz_data} from "./series.js";
import {set_boost, set_axis, set_category_axis, set_both_axis, default_config, set_tick_size} from "./config.js";

export const draw = (mode) => async function (el, view, task) {
Expand Down Expand Up @@ -122,7 +122,7 @@ export const draw = (mode) => async function (el, view, task) {
set_both_axis(config, 'yAxis', yaxis_name, yaxis_type, yaxis_type, ytop);
} else {
let config = configs[0] = default_config.call(this, aggregates, mode, js, col_pivots);
let [series, top, ] = make_y_columnar_data(cols, row_pivots, hidden);
let [series, top, ] = make_y_data(cols, row_pivots, hidden);
config.series = series;
config.colors = series.length <= 10 ? COLORS_10 : COLORS_20;
config.legend.enabled = col_pivots.length > 0 || series.length > 1;
Expand Down
61 changes: 9 additions & 52 deletions packages/perspective-viewer-highcharts/src/js/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
*/

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

function row_to_series(series, sname, gname) {
let s;
let sidx = 0;
for (sidx; sidx < series.length; sidx++) {
let is_group = typeof gname === "undefined" || series[sidx].stack === gname;
if (series[sidx].name == sname && is_group) {
//console.log(series[sidx], sidx, series);
s = series[sidx];
break;
}
Expand Down Expand Up @@ -49,7 +47,7 @@ function column_to_series(data, sname, gname) {
return s;
}

// preserve for backwards compatibility
// Row-based axis generator
class TreeAxisIterator {

constructor(depth, json) {
Expand Down Expand Up @@ -80,6 +78,7 @@ class TreeAxisIterator {
}

*[Symbol.iterator]() {
// Recursively map and generate axis labels
let label = this.top;
for (let row of this.json) {
let path = row.__ROW_PATH__ || [''];
Expand All @@ -93,7 +92,7 @@ class TreeAxisIterator {
}
}

// new columnar parsing
// Column-based axis generator
class ColumnarAxisIterator extends TreeAxisIterator {

constructor(depth, columns) {
Expand All @@ -102,7 +101,7 @@ class ColumnarAxisIterator extends TreeAxisIterator {
this.fill_axis();
}

// recursively generate axis categories from column
// No need for custom iterator - call on instantiation
fill_axis() {
let label = this.top;

Expand All @@ -121,7 +120,6 @@ class ColumnarAxisIterator extends TreeAxisIterator {
}
}

// preserve for backwards-compatibility
class RowIterator {

constructor(rows, hidden) {
Expand All @@ -148,9 +146,8 @@ class RowIterator {
}
}

// new columnar parsing
class ColumnToRowIterator {

class ColumnarIterator {

constructor(columns, hidden, pivot_length) {
this.columns = columns;
this.hidden = [...hidden, "hidden", "column_names"];
Expand All @@ -167,28 +164,10 @@ class ColumnToRowIterator {
this.pivot_length = pivot_length;
}

*[Symbol.iterator]() {
// convert columnar data to row
let i = 0;
for (i; i < this.columns[this.column_names[0]].length; i++) {
let row = {};
// TODO: fix the total row problem at source
if (this.columns.__ROW_PATH__) {
if (this.columns.__ROW_PATH__[i].length !== this.pivot_length) continue;
}
for (let name of this.column_names) {
row[name] = this.columns[name][i];
}
yield row;
}
}
}

// columnar without row conversion
class ColumarIterator extends ColumnToRowIterator {
*[Symbol.iterator]() {
for (let name of this.column_names) {
let data = this.columns[name];
// Manually remove total columns, remove once fix is complete on engine
if (this.columns.__ROW_PATH__) {
data = data.filter((val, idx) =>
this.columns.__ROW_PATH__[idx].length === this.pivot_length);
Expand All @@ -201,29 +180,7 @@ class ColumarIterator extends ColumnToRowIterator {
export function make_y_data(cols, pivots, hidden) {
let series = [];
let axis = new ColumnarAxisIterator(pivots.length, cols);
let row_data = new ColumnToRowIterator(cols, hidden, pivots.length);
for (let row of row_data) {
for (let name of Object.keys(row)) {
let sname = name.split(COLUMN_SEPARATOR_STRING);
let gname = sname[sname.length - 1];
if (row_data.is_stacked) {
sname = sname.join(", ") || gname;
} else {
sname = sname.slice(0, sname.length - 1).join(", ") || " ";
}
let s = row_to_series(series, sname, gname);
let val = row[name];
val = (val === undefined || val === "" ? null : val)
s.data.push(val);
}
}
return [series, axis.top];
}

export function make_y_columnar_data(cols, pivots, hidden) {
let series = [];
let axis = new ColumnarAxisIterator(pivots.length, cols);
let columns = new ColumarIterator(cols, hidden, pivots.length);
let columns = new ColumnarIterator(cols, hidden, pivots.length);
for (let col of columns) {
let sname = col.name.split(COLUMN_SEPARATOR_STRING);
let gname = sname[sname.length - 1];
Expand All @@ -239,7 +196,7 @@ export function make_y_columnar_data(cols, pivots, hidden) {
return [series, axis.top];
}

// preserve old behavior for heatmaps
// Preserve old behavior for heatmaps
export function make_y_heatmap_data(js, pivots, hidden) {
let rows = new TreeAxisIterator(pivots.length, js);
let rows2 = new RowIterator(rows, hidden);
Expand Down
1 change: 0 additions & 1 deletion packages/perspective-viewer/src/js/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ class Row extends HTMLElement {

let sort_order = this.querySelector('#sort_order');
sort_order.addEventListener('click', event => {
// TODO: event loop optimizations to prevent hang on large graph redraws?
const current = this.getAttribute('sort-order');
const order = (perspective.SORT_ORDERS.indexOf(current) + 1) % 5;
this.setAttribute('sort-order', perspective.SORT_ORDERS[order]);
Expand Down

0 comments on commit 583028d

Please sign in to comment.