finos / perspective

A data visualization and analytics component, especially well-suited for large and/or streaming datasets.
https://perspective.finos.org/
Apache License 2.0
8.61k stars 1.19k forks source link

Queries on Custom perspective plugin #959

Closed Madasamy26 closed 4 years ago

Madasamy26 commented 4 years ago

Hi,

I am developing custom plugin for perspective,

In that, plugin configuration, like below

    name: "Grid",
    create: grid_create,
    selectMode: "toggle",
    update: grid_update,
    deselectMode: "pivots",
    styleElement: style_element,
    save: function() {
        const hypergrid = get_hypergrid.call(this);
        if (hypergrid && hypergrid.selectionModel.hasRowSelections()) {
            return {selected: hypergrid.behavior.dataModel.getSelectedRowID()};
        }
    },
    restore: function(config) {
        this._plugin_config = config;
    },
    resize: async function() {
        const hypergrid = get_hypergrid.call(this);
        if (hypergrid) {
            let nrows = await this._view.num_rows();
            hypergrid.behavior.dataModel.setDirty(nrows);
            await hypergrid.canvas.resize(true);
        }
    },
    delete: function() {
        const hypergrid = get_hypergrid.call(this);
        if (hypergrid) {
            hypergrid.terminate();
            hypergrid.div = undefined;
            hypergrid.canvas.div = undefined;
            hypergrid.canvas.canvas = undefined;
            hypergrid.sbVScroller = undefined;
            hypergrid.sbHScroller = undefined;
            delete this[HYPERGRID_INSTANCE];
        }
    }
};  

So If we are sorting on perspective ..perspective will call the create method of plugin, create will re-instantiate the perspective plugin

Is there any method for invoking while changing options like filtering,sorting from perspective instead of create ?

texodus commented 4 years ago

create() is called when any UI parameters are changed, as Perspective's View objects are immutable, and the existing plugins are lazily instantiated. There is no "plugin state" initialization method so far - but in the pasted example above, the if (hypergrid) { part is effectively that, as it is only invoked when the plugin is instantiated.

You may find these tutorials helpful:

https://blog.scottlogic.com/2019/04/23/perspective-plugin-api-how-to-build-a-new-plugin.html https://blog.scottlogic.com/2019/04/18/building-a-perspective-plugin-with-d3fc.html

Madasamy26 commented 4 years ago

thanks @timkpaine