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

Heatmap implementation for perspective-viewer-highcharts plugin #46

Merged
merged 8 commits into from
Feb 14, 2018
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"scripts": {
"start": "lerna run start ${PACKAGE:+--scope=@jpmorganchase/${PACKAGE}} --stream",
"travis_start": "lerna run start ${PACKAGE:+--scope=@jpmorganchase/${PACKAGE}} --stream && lerna run compile_test --stream",
"puppeteer": "docker run -it --rm --shm-size=2g -u root -e WRITE_TESTS=${WRITE_TESTS} -v $(pwd):/src -w /src/packages/${PACKAGE} zenato/puppeteer ./node_modules/.bin/jest --runInBand",
"puppeteer": "docker run -it --rm --shm-size=2g -u root -e WRITE_TESTS=${WRITE_TESTS} -v $(pwd):/src -w /src/packages/${PACKAGE} perspective/puppeteer ./node_modules/.bin/jest --silent --runInBand",
"postinstall": "lerna bootstrap --hoist",
"test": "lerna run compile_test && npm run test_perspective && npm run test_viewer && npm run test_hypergrid && npm run test_highcharts",
"test": "lerna run compile_test --stream && npm run test_perspective && npm run test_viewer && npm run test_hypergrid && npm run test_highcharts",
"test_perspective": "PACKAGE=perspective npm run puppeteer",
"test_viewer": "PACKAGE=perspective-viewer npm run puppeteer",
"test_hypergrid": "PACKAGE=perspective-viewer-hypergrid npm run puppeteer",
"test_highcharts": "PACKAGE=perspective-viewer-highcharts npm run puppeteer",
"write_tests": "WRITE_TESTS=1 npm run test",
"travis_test": "docker run -it --rm --shm-size=2g -u root -e WRITE_TESTS=${WRITE_TESTS} -v $(pwd):/src -w /src/ zenato/puppeteer ./node_modules/.bin/lerna run test"
"travis_test": "docker run -it --rm --shm-size=2g -u root -e WRITE_TESTS=${WRITE_TESTS} -v $(pwd):/src -w /src/ perspective/puppeteer ./node_modules/.bin/lerna run test"
}
}
8 changes: 4 additions & 4 deletions packages/perspective-examples/src/html/superstore.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<body>

<perspective-viewer
view="vertical"
row-pivots='["Category","Region","Segment"]'
column-pivots='["Sub-Category"]'
columns='["Sales"]'>
view="heatmap"
row-pivots='["Region","Segment"]'
column-pivots='["Ship Mode","Category"]'
columns='["Profit"]'>

</perspective-viewer>

Expand Down
2 changes: 1 addition & 1 deletion packages/perspective-viewer-highcharts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"highcharts": "webpack --config src/config/highcharts.plugin.config.js",
"start": "npm run highcharts",
"compile_test": "cp test/html/* build",
"test": "jest --runInBand 2>&1",
"test": "jest --silent --runInBand 2>&1",
"clean": "find build -mindepth 1 -delete"
},
"jest": {
Expand Down
98 changes: 97 additions & 1 deletion packages/perspective-viewer-highcharts/src/js/highcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function _make_series(js, pivots, col_pivots, mode, hidden) {
for (let prop of columns) {
var sname = prop.split(',');
var gname = sname[sname.length - 1];
sname = sname.slice(0, sname.length - 1).join(", ") || " ";
sname = sname.slice(0, sname.length - 1).join(",") || " ";
var s;
if (prev === undefined) prev = sname;
for (var sidx = 0; sidx < series.length; sidx++) {
Expand Down Expand Up @@ -250,6 +250,8 @@ export function draw(mode) {
} else {
type = 'bubble';
}
} else if (mode === 'heatmap') {
type = 'heatmap';
}

let new_radius = 0;
Expand Down Expand Up @@ -397,6 +399,88 @@ export function draw(mode) {
labels: {overflow: 'justify'}
}
});
} else if (mode == 'heatmap') {
// Need to slightly repivot data
let data = [];
for (let i=0; i<series[0].data.length; ++i) {
for (let j=0; j<series.length; ++j) {
let val = series[j].data[i];
data.push([i, j, val]);
colorRange[0] = Math.min(colorRange[0], val);
colorRange[1] = Math.max(colorRange[1], val);
}
}
let cmax = Math.max(Math.abs(colorRange[0]), Math.abs(colorRange[1]));
colorRange = [-cmax, cmax];

// Calculate ylabel nesting
let ylabels = series.map(function (s) { return s.name.split(','); })
let ytop = {name: null, depth: 0, categories: []};

let maxdepth = ylabels[0].length;

for (let i=0; i<ylabels.length; ++i) {
let ylabel = ylabels[i];
let parent = ytop;

for (let depth=0; depth<ylabel.length; ++depth) {
let label = ylabel[depth]
if (depth === maxdepth - 1) {
parent.categories.push(label);
} else {
let l = parent.categories.length;
if (l > 0 && parent.categories[l-1].name == label) {
parent = parent.categories[l-1];
} else {
let cat = {name: label, depth: depth+1, categories: []};
parent.categories.push(cat);
parent = cat;
}
}
}
}

Object.assign(config, {
series: [{
name: null,
data: data,
nullColor: '#999'
}],
colorAxis: {
min: colorRange[0],
max: colorRange[1],
minColor: '#c4463a',
maxColor: '#3060cf',
stops: [
[0, '#c4463a'],
[0.1, '#c4463a'],
[0.5, '#fffbbc'],
[1, '#3060cf']
],
startOnTick: false,
endOnTick: false,
},
xAxis: {
categories: top.categories,
labels: {
enabled: (top.categories.length > 0),
padding: 0,
autoRotation: [-10, -20, -30, -40, -50, -60, -70, -80, -90],
},
},
yAxis: {
categories: ytop.categories,
title: null,
tickWidth: 1,
reversed: true,
labels: {
padding: 0,
step: 1
}
}
});
config['chart']['marginRight'] = 75;
delete config["legend"]["width"];
} else if (mode.indexOf('line') !== -1) {
Object.assign(config, {
colors: colors,
Expand Down Expand Up @@ -543,6 +627,18 @@ global.registerPlugin("horizontal", {
delete: delete_chart
});

global.registerPlugin("heatmap", {
name: "Heatmap",
create: draw("heatmap"),
resize: resize,
initial: {
"type": "number",
"count": 1
},
selectMode: "select",
delete: delete_chart
});

global.registerPlugin("line", {
name: "Line Chart",
create: draw("line"),
Expand Down
41 changes: 41 additions & 0 deletions packages/perspective-viewer-highcharts/test/html/heatmap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--

Copyright (c) 2017, the Perspective Authors.

This file is part of the Perspective library, distributed under the terms of
the Apache License 2.0. The full license can be found in the LICENSE file.

-->

<!DOCTYPE html>
<html>
<head>

<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<script src="perspective.view.js"></script>
<script src="highcharts.plugin.js"></script>

<link rel='stylesheet' href="demo.css">

</head>
<body>

<perspective-viewer
view='heatmap'
columns='["Sales"]'>

</perspective-viewer>

<script>

var xhr = new XMLHttpRequest();
xhr.open('GET', 'superstore.csv', true);
xhr.onload = function () {
document.getElementsByTagName('perspective-viewer')[0].load(xhr.response);
}
xhr.send(null);

</script>

</body>
</html>
23 changes: 23 additions & 0 deletions packages/perspective-viewer-highcharts/test/js/heatmap.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/******************************************************************************
*
* Copyright (c) 2017, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/

const utils = require('@jpmorganchase/perspective-viewer/test/js/utils.js');

const simple_tests = require('@jpmorganchase/perspective-viewer/test/js/simple_tests.js');


utils.with_server({}, () => {

describe.page("heatmap.html", () => {

simple_tests.default();

});

});
26 changes: 18 additions & 8 deletions packages/perspective-viewer-highcharts/test/results/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
"scatter.html/pivots by two rows and two columns.": "354a7997f29cd2127dbf926147231b68",
"scatter.html/sorts by a numeric column.": "dbf5084214566ad89e370946ab2e22ae",
"scatter.html/sorts by an alpha column.": "c99d3e45821f5164be094ba55c8e92bc",
"scatter.html/displays visible columns.": "7a919ee86624d9b91c6c494214a9f3f1",
"scatter.html/displays visible columns.": "50a1a81821d968c1e427f8527c6eb7aa",
"bar.html/shows a grid without any settings applied.": "fa9f33409c8409155b403c30e97b9397",
"bar.html/pivots by a row.": "c408dea96a066ce835cdef3cf638fb40",
"bar.html/pivots by two rows.": "3d6656beee9cf67a555d06aba9af55de",
"bar.html/pivots by two rows.": "a1c30e83774a8baa3f152413ab7dae6b",
"bar.html/pivots by a row and a column.": "515f267997a4c3233123d9029c2fbd64",
"bar.html/pivots by two rows and two columns.": "7ae9f8a50fbde09fa1b49e538bd674d5",
"bar.html/pivots by two rows and two columns.": "2a78d5ef47246b8481ca348074d5d6d1",
"bar.html/sorts by a numeric column.": "8fc90a250b5630a920d1a803be36cdf7",
"bar.html/sorts by an alpha column.": "90a49c6afcbeed7823d4232f2682ee12",
"line.html/shows a grid without any settings applied.": "5c7d75d2872635968019ef08bc505ff3",
"line.html/pivots by a row.": "5cf7ac2df52667f39249fab16041b46b",
"line.html/pivots by a row.": "a8ed89e4a4c1b4d4ac10a36ba937f525",
"line.html/pivots by two rows.": "1aff8c733eb543d17f0c0eca57b369b7",
"line.html/pivots by a row and a column.": "e5f9f8f1bdbfb718509e120b3bc8c70c",
"line.html/pivots by two rows and two columns.": "9b509fd18c1477b89db4ea79b04a1c95",
"line.html/pivots by a row and a column.": "995fc8a3dc4d2dad98a31ba59c77cecd",
"line.html/pivots by two rows and two columns.": "6dd751b246c8c77c50d59e0b8ba210cb",
"line.html/sorts by a numeric column.": "bb0d7bfc8797eca2000d85f9f5814828",
"line.html/sorts by an alpha column.": "bca50c1e2a5048a0ea23e3627de96e26",
"line.html/displays visible columns.": "80d6712db433c15efe24d43d32987b9c",
Expand All @@ -35,6 +35,16 @@
"line.html/sorts by a hidden column.": "80db1e392602e53a502b97ab8f573249",
"bar.html/sorts by a hidden column.": "73a2f920448908ad25f6e0d6770f1638",
"scatter.html/filters by a numeric column.": "1b2ab6ae89954e2ab9847b339e1cdef0",
"line.html/filters by a numeric column.": "d31caeb32416183156202bd7033c5a1b",
"bar.html/filters by a numeric column.": "cf01072c9e326a20d22eb908eed1263c"
"line.html/filters by a numeric column.": "94f197a7ffe45530a58026303ebac5a2",
"bar.html/filters by a numeric column.": "cf01072c9e326a20d22eb908eed1263c",
"heatmap.html/shows a grid without any settings applied.": "4f67e3da9aec1fe59d204e4be8c9c592",
"heatmap.html/pivots by a row.": "c8a96913a20943908282f4c64ff99637",
"heatmap.html/pivots by two rows.": "7cabb978cea6054d2e8e670c4f88c2b7",
"heatmap.html/pivots by a row and a column.": "ca56f4dd1bc369688e1608cd4773662c",
"heatmap.html/pivots by two rows and two columns.": "1b56a5913c14bd16d24489dfd6734ebb",
"heatmap.html/sorts by a hidden column.": "d5736676d62d0eeb581918c840d87774",
"heatmap.html/sorts by a numeric column.": "75a6f82e97d78b9aa05d50905129e8ce",
"heatmap.html/filters by a numeric column.": "ca2c6f5818a143430ded8020d2d7ac65",
"heatmap.html/sorts by an alpha column.": "d16361be937ac2d1364454cf5b75f517",
"heatmap.html/displays visible columns.": "cc0bd9b36c119d7fae2daf18b6191d2e"
}
2 changes: 1 addition & 1 deletion packages/perspective-viewer-hypergrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"hypergrid": "webpack --config src/config/hypergrid.plugin.config.js",
"start": "npm run hypergrid",
"compile_test": "cp test/html/* build",
"test": "jest --runInBand 2>&1",
"test": "jest --silent --runInBand 2>&1",
"clean": "find build -mindepth 1 -delete"
},
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion packages/perspective-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"view": "webpack --config src/config/view.config.js",
"start": "npm run view",
"compile_test": "cp test/html/* build && cp test/csv/* build && cp test/css/* build",
"test": "jest --runInBand 2>&1",
"test": "jest --silent --runInBand 2>&1",
"clean": "find build -mindepth 1 -delete"
},
"publishConfig": {
Expand Down