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

Add eslint-prettier #242

Merged
merged 10 commits into from
Sep 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
autofix javascript code
  • Loading branch information
LukeSheard committed Sep 18, 2018
commit babb8673a626b2e324a073e3d898173196448e11
70 changes: 23 additions & 47 deletions packages/perspective-examples/src/js/node_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,35 @@
*
*/

const http = require('http');
const queryString = require('query-string');
const http = require("http");
const queryString = require("query-string");

var SECURITIES = [
"AAPL.N",
"AMZN.N",
"QQQ.N",
"NVDA.N",
"TSLA.N",
"FB.N",
"MSFT.N",
"TLT.N",
"XIV.N",
"YY.N",
"CSCO.N",
"GOOGL.N",
"PCLN.N"
];
var SECURITIES = ["AAPL.N", "AMZN.N", "QQQ.N", "NVDA.N", "TSLA.N", "FB.N", "MSFT.N", "TLT.N", "XIV.N", "YY.N", "CSCO.N", "GOOGL.N", "PCLN.N"];

var CLIENTS = [
"Homer",
"Marge",
"Bart",
"Lisa",
"Maggie",
"Moe",
"Lenny",
"Carl",
"Krusty",
]
var CLIENTS = ["Homer", "Marge", "Bart", "Lisa", "Maggie", "Moe", "Lenny", "Carl", "Krusty"];

function newRow() {
return {
name: SECURITIES[Math.floor(Math.random() * SECURITIES.length)],
client: CLIENTS[Math.floor(Math.random() * CLIENTS.length)],
lastUpdate: new Date(),
chg: Math.random() * 20 - 10,
bid: Math.random() * 10 + 90,
ask: Math.random() * 10 + 100,
vol: Math.random() * 10 + 100,
id: Math.floor(Math.random() * 500)
};
return {
name: SECURITIES[Math.floor(Math.random() * SECURITIES.length)],
client: CLIENTS[Math.floor(Math.random() * CLIENTS.length)],
lastUpdate: new Date(),
chg: Math.random() * 20 - 10,
bid: Math.random() * 10 + 90,
ask: Math.random() * 10 + 100,
vol: Math.random() * 10 + 100,
id: Math.floor(Math.random() * 500)
};
}

function postrow() {
var url = 'http://localhost:3000/?' + queryString.stringify(newRow());
console.log(url);
http.get(url, res => {
res.on('data', () => {})
res.on("end", () =>{
postrow();
})
})
var url = "http://localhost:3000/?" + queryString.stringify(newRow());
console.log(url);
http.get(url, res => {
res.on("data", () => {});
res.on("end", () => {
postrow();
});
});
}

postrow();
postrow();
16 changes: 9 additions & 7 deletions packages/perspective-examples/src/js/node_git_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
*
*/

const {WebSocketHost} = require("@jpmorganchase/perspective/build/perspective.node.js");
const exec = require('child_process').exec;
const { WebSocketHost } = require("@jpmorganchase/perspective/build/perspective.node.js");
const exec = require("child_process").exec;

function execute(command, callback){
exec(command, function(error, stdout){ callback(stdout); });
};
function execute(command, callback) {
exec(command, function(error, stdout) {
callback(stdout);
});
}

execute(`git log --date=iso --pretty=format:'"%h","%an","%aD","%s","%ae"'`, log => {
const host = new WebSocketHost({rootDir: __dirname});
host.open("data_source_one", "Hash,Name,Date,Message,Email\n" + log);
const host = new WebSocketHost({ rootDir: __dirname });
host.open("data_source_one", "Hash,Name,Date,Message,Email\n" + log);
});
8 changes: 4 additions & 4 deletions packages/perspective-examples/src/js/node_remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*
*/

const {WebSocketHost} = require("@jpmorganchase/perspective/build/perspective.node.js");
const { WebSocketHost } = require("@jpmorganchase/perspective/build/perspective.node.js");
const fs = require("fs");

const host = new WebSocketHost({rootDir: __dirname});
const arr = fs.readFileSync(__dirname + '/superstore.arrow');
const host = new WebSocketHost({ rootDir: __dirname });
const arr = fs.readFileSync(__dirname + "/superstore.arrow");

host.open("data_source_one", arr);
host.open("data_source_one", arr);
106 changes: 53 additions & 53 deletions packages/perspective-examples/src/js/node_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*
*/

const perspective = require('./perspective.node.js');
const WebSocket = require('ws');
const http = require('http');
const queryString = require('query-string');
const perspective = require("./perspective.node.js");
const WebSocket = require("ws");
const http = require("http");
const queryString = require("query-string");

/******************************************************************************
*
Expand All @@ -19,21 +19,21 @@ const queryString = require('query-string');
*/

const schema = {
name: "string",
client: "string",
lastUpdate: "date",
chg: "float",
bid: "float",
ask: "float",
vol: "float",
id: "integer"
name: "string",
client: "string",
lastUpdate: "date",
chg: "float",
bid: "float",
ask: "float",
vol: "float",
id: "integer"
};

const table = perspective.table(schema, {index: "id"});
const table = perspective.table(schema, { index: "id" });

const view = table.view({
row_pivot: ["name"],
aggregate: Object.keys(schema).map(col => ({op: "last", column: col}))
row_pivot: ["name"],
aggregate: Object.keys(schema).map(col => ({ op: "last", column: col }))
});

/******************************************************************************
Expand All @@ -42,39 +42,39 @@ const view = table.view({
*
*/

const wss = new WebSocket.Server({port: 8080});
const wss = new WebSocket.Server({ port: 8080 });

wss.broadcast = function broadcast(data) {
wss.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(data);
}
});
wss.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(data);
}
});
};

wss.on('connection', function connection(ws) {
view.to_json().then(data => {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(data));
}
});
ws.on('error', console.error);
wss.on("connection", function connection(ws) {
view.to_json().then(data => {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(data));
}
});
ws.on("error", console.error);
});

let requests = 0;

view.on_update(data => {
requests++;
var data = JSON.stringify(data);
wss.broadcast(data);
requests++;
var data = JSON.stringify(data);
wss.broadcast(data);
});

function logTime() {
if (requests > 0) {
console.log(`Processing ${requests / 10}reqs/s`);
}
requests = 0;
setTimeout(logTime, 10000);
if (requests > 0) {
console.log(`Processing ${requests / 10}reqs/s`);
}
requests = 0;
setTimeout(logTime, 10000);
}

setTimeout(logTime, 10000);
Expand All @@ -86,23 +86,23 @@ setTimeout(logTime, 10000);
*/

const server = http.createServer((request, response) => {
var tick = request.url.split("?");
if (!tick[1]) return;
var tick = queryString.parse(tick[1].trim());
for (var key of Object.keys(tick)) {
if (schema[key] === "float" || schema[key === "integer"]) {
tick[key] = Number.parseFloat(tick[key]);
}
var tick = request.url.split("?");
if (!tick[1]) return;
var tick = queryString.parse(tick[1].trim());
for (var key of Object.keys(tick)) {
if (schema[key] === "float" || schema[key === "integer"]) {
tick[key] = Number.parseFloat(tick[key]);
}
delete tick[''];
table.update([tick]);
response.end("Processed");
}
delete tick[""];
table.update([tick]);
response.end("Processed");
});

server.listen(3000, "0.0.0.0", (err) => {
if (err) {
console.error(err);
} else {
console.log(`Server is listening on 3000`);
}
})
server.listen(3000, "0.0.0.0", err => {
if (err) {
console.error(err);
} else {
console.log(`Server is listening on 3000`);
}
});
4 changes: 2 additions & 2 deletions packages/perspective-jupyterlab/src/js/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import worker from "worker-loader?inline=true&fallback=false!@jpmorganchase/perspective/src/js/perspective.wasm.js";
import buffer from "arraybuffer-loader!@jpmorganchase/perspective/build/psp.async.wasm"
import buffer from "arraybuffer-loader!@jpmorganchase/perspective/build/psp.async.wasm";

window.__PSP_WORKER__ = worker;
window.__PSP_WASM__ = buffer;
window.__PSP_WASM__ = buffer;
86 changes: 42 additions & 44 deletions packages/perspective-viewer-highcharts/src/js/color_axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,53 @@
*
*/

import * as gparser from 'gradient-parser';
import * as gparser from "gradient-parser";

function _get_gradient(type) {
const thermometer = document.createElement('rect');
thermometer.style.display = 'none';
thermometer.className = `highcharts-heatmap-gradient-${type}`;
const chart = this.querySelector('#pivot_chart');
chart.appendChild(thermometer);
const gradient = window.getComputedStyle(thermometer).getPropertyValue('background-image');
chart.removeChild(thermometer);
return gparser.parse(gradient)[0].colorStops.map(x => [
Number.parseFloat(x.length.value) / 100,
`rgb(${x.value.join(',')})`
]);
const thermometer = document.createElement("rect");
thermometer.style.display = "none";
thermometer.className = `highcharts-heatmap-gradient-${type}`;
const chart = this.querySelector("#pivot_chart");
chart.appendChild(thermometer);
const gradient = window.getComputedStyle(thermometer).getPropertyValue("background-image");
chart.removeChild(thermometer);
return gparser.parse(gradient)[0].colorStops.map(x => [Number.parseFloat(x.length.value) / 100, `rgb(${x.value.join(",")})`]);
}

const _get_gradients = (() => {
let gradients;
return function () {
if (gradients === undefined) {
gradients = {};
for (let type of ['positive', 'negative', 'full']) {
gradients[type] = _get_gradient.bind(this)(type);
}
}
return gradients;
};
let gradients;
return function() {
if (gradients === undefined) {
gradients = {};
for (let type of ["positive", "negative", "full"]) {
gradients[type] = _get_gradient.bind(this)(type);
}
}
return gradients;
};
})();

export function color_axis(config, colorRange) {
let gradient, {positive, negative, full} = _get_gradients.bind(this)();
if (colorRange[0] >= 0) {
gradient = positive;
} else if (colorRange[1] <= 0) {
gradient = negative;
} else {
gradient = full;
};
Object.assign(config, {
colorAxis: {
min: colorRange[0],
max: colorRange[1],
stops: gradient,
reversed: false,
startOnTick: false,
endOnTick: false,
}
});
config.legend.reversed = true;
config.legend.floating = false;
config.legend.enabled = true;
}
let gradient,
{ positive, negative, full } = _get_gradients.bind(this)();
if (colorRange[0] >= 0) {
gradient = positive;
} else if (colorRange[1] <= 0) {
gradient = negative;
} else {
gradient = full;
}
Object.assign(config, {
colorAxis: {
min: colorRange[0],
max: colorRange[1],
stops: gradient,
reversed: false,
startOnTick: false,
endOnTick: false
}
});
config.legend.reversed = true;
config.legend.floating = false;
config.legend.enabled = true;
}
Loading