How to use @finos/perspective - 10 common examples

To help you get started, we’ve selected a few @finos/perspective examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github finos / perspective / packages / perspective-bench / src / js / bench.js View on Github external
exports.run = async function run(version, benchmark, ...cmdArgs) {
    const options = cmdArgs.splice(cmdArgs.length - 1, 1)[0];
    const host = await new_host();
    // const port = host._server.address().port;

    let benchmark_name = options.output || "benchmark";

    console.log(chalk`\n{whiteBright Running v.${version} (${cmdArgs.join(",")})}`);

    let version_index = 1;
    let table = undefined;
    if (options.read && fs.existsSync(`${benchmark_name}.arrow`)) {
        const buffer = fs.readFileSync(`${benchmark_name}.arrow`, null).buffer;
        table = perspective.table(buffer);
        const view = table.view({row_pivots: ["version"], columns: []});
        const json = await view.to_json();
        version_index = json.length;
    }

    const RUN_TEST = fs.readFileSync(path.resolve(benchmark)).toString();
    let bins;

    if (options.puppeteer) {
        const puppeteer = require("puppeteer");
        let browser = await puppeteer.launch({
            headless: true,
            args: ["--no-sandbox"]
        });

        bins = await run_version(browser, cmdArgs, RUN_TEST);
github finos / perspective / packages / perspective-viewer / src / js / viewer / perspective_element.js View on Github external
if (type_config.type || type) {
            if (col.op === "" || perspective.TYPE_AGGREGATES[type_config.type || type].indexOf(col.op) === -1) {
                col.op = type_config.aggregate;
            }
            aggregates.push(col);
        } else {
            console.warn(`No column "${col.column}" found (specified in aggregates attribute).`);
        }
    }

    // Add columns detected from dataset.
    for (const col of cols) {
        if (!found.has(col)) {
            aggregates.push({
                column: col,
                op: get_type_config(schema[col]).aggregate
            });
        }
    }

    return aggregates;
}
github finos / perspective / packages / perspective-viewer / src / js / viewer / perspective_element.js View on Github external
function get_aggregates_with_defaults(aggregate_attribute, schema, cols) {
    const found = new Set();
    const aggregates = [];
    for (const col of aggregate_attribute) {
        const type = schema[col.column];
        const type_config = get_type_config(type);
        found.add(col.column);
        if (type_config.type || type) {
            if (col.op === "" || perspective.TYPE_AGGREGATES[type_config.type || type].indexOf(col.op) === -1) {
                col.op = type_config.aggregate;
            }
            aggregates.push(col);
        } else {
            console.warn(`No column "${col.column}" found (specified in aggregates attribute).`);
        }
    }

    // Add columns detected from dataset.
    for (const col of cols) {
        if (!found.has(col)) {
            aggregates.push({
                column: col,
github finos / perspective / packages / perspective-viewer / src / js / viewer / perspective_element.js View on Github external
function get_aggregates_with_defaults(aggregate_attribute, schema, cols) {
    const found = new Set();
    const aggregates = [];
    for (const col of aggregate_attribute) {
        const type = schema[col.column];
        const type_config = get_type_config(type);
        found.add(col.column);
        if (type_config.type || type) {
            if (col.op === "" || perspective.TYPE_AGGREGATES[type_config.type || type].indexOf(col.op) === -1) {
                col.op = type_config.aggregate;
            }
            aggregates.push(col);
        } else {
            console.warn(`No column "${col.column}" found (specified in aggregates attribute).`);
        }
    }

    // Add columns detected from dataset.
    for (const col of cols) {
        if (!found.has(col)) {
            aggregates.push({
                column: col,
                op: get_type_config(schema[col]).aggregate
            });
        }
github finos / perspective / examples / remote / server.js View on Github external
async function init_dynamic() {
    // Create a `table`.
    const table = perspective.table(newRows(TABLE_SIZE), {limit: TABLE_SIZE});

    // The `table` needs to be registered to a name with the Perspective
    // `WebSocketServer` in order for the client to get a proxy handle to it.
    host.host_view("data_source_one", table.view());

    // Loop and update the `table` oocasionally.
    (function postRow() {
        table.update(newRows());
        setTimeout(postRow, TICK_RATE);
    })();
}
github timkpaine / aat / js / src / ts / index.ts View on Github external
const main = async () => {
  const tradesViewer = document.createElement("perspective-viewer");
  await tradesViewer.restore({
    plugin: "datagrid",
    sort: [["timestamp", "asc"]],
  });

  const ordersViewer = document.createElement("perspective-viewer");
  await ordersViewer.restore({
    "column-pivots": ["side"],
    "plugin": "datagrid",
    "sort": [["price", "desc"]],
  });

  // connect to perspective
  const websocket = perspective.websocket("ws://localhost:8080/api/v1/ws");

  const tradesTable = websocket.open_table("trades");
  const ordersTable = websocket.open_table("orders");

  // perspective workspace
  // const workspace = new PerspectiveWorkspace();
  // workspace.addClass("workspace");
  // workspace.title.label = "AAT";
  const workspace = new DockPanel();
  workspace.addClass("workspace");

  // const tradesWidget = new PerspectiveViewerWidget("Trades");
  // const ordersWidget = new PerspectiveViewerWidget("Orders");

  // Add tables to workspace
  const tradesWidget = new Widget({node: tradesViewer});
github finos / perspective / python / perspective / examples / python-phosphor / src / js / index.js View on Github external
window.addEventListener("load", async () => {
    // Create a client that expects a Perspective server to accept connections at the specified URL.
    const websocket = perspective.websocket("ws://localhost:3001/websocket");
    //const worker = perspective.worker();
    //worker.initialize_profile_thread();

    //const view = websocket.open_view("data_source_one");

    // Table created in JS from datafeed in python
    const table = websocket.open_table("data_source_one");
    const workspace = new PerspectiveWorkspace();

    const widget1 = new PerspectiveWidget("Spread", {
        editable: true,
        plugin: "d3_y_line",
        "row-pivots": ["client"],
        "column-pivots": ["name"],
        columns: ["spread"],
        aggregates: {
github finos / perspective / examples / remote / server.js View on Github external
// How many rows per update?
var UPDATE_SIZE = 50;

// Update every N milliseconds
var TICK_RATE = 20;

// Size limit of the server-side table
var TABLE_SIZE = 10000;

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 __CACHE__ = [];

perspective.initialize_profile_thread();

/*******************************************************************************
 *
 * Slow mode (new rows generated on the fly)
 */

function choose(choices) {
    return choices[Math.floor(Math.random() * choices.length)];
}

function newRows(total_rows = UPDATE_SIZE) {
    var rows = [];
    for (var x = 0; x < total_rows; x++) {
        rows.push({
            name: choose(SECURITIES),
            client: choose(CLIENTS),
github finos / perspective / packages / perspective-test / src / js / index.js View on Github external
beforeAll(() => {
        if (test_root === "") {
            throw "ERROR";
        }
        server = new WebSocketServer({
            assets: paths || [path.join(test_root, "dist", "umd")],
            port: 0,
            on_start: () => {
                __PORT__ = server._server.address().port;
            }
        });
    });
github finos / perspective / packages / perspective-cli / src / js / utils.js View on Github external
function infer_table(buffer) {
    if (buffer.slice(0, 6).toString() === "ARROW1") {
        console.log("Loaded Arrow");
        return table(buffer.buffer);
    } else {
        let text = buffer.toString();
        try {
            let json = JSON.parse(text);
            console.log("Loaded JSON");
            return table(json);
        } catch (e) {
            console.log("Loaded CSV");
            return table(text);
        }
    }
}