MINERVA
Platform Documentation

Events#

Plugins can interact with Minerva by subscribing to events. These events allow plugins to respond to user actions, system events, or changes in the application state.

Add Event Listener#

To listen for specific events, plugins can use the addListener method in events object returned by window.minerva.plugins.registerPlugin. This method takes two arguments: the name of the event and a callback function to handle the event. Available Events:

{
  "name": "Example Overlay",
  "creatorId": 3,
  "creator": "3",
  "description": "Different",
  "genomeType": null,
  "genomeVersion": null,
  "id": 149,
  "publicOverlay": false,
  "type": "GENERIC",
  "order": 9
}
43
{
  "name": "Generic advanced format overlay",
  "creatorId": 3,
  "creator": "3",
  "description": "Data set provided by a user",
  "genomeType": null,
  "genomeVersion": null,
  "id": 20,
  "publicOverlay": true,
  "type": "GENERIC",
  "order": 9
}
{
  "name": "colored overlay",
  "creatorId": 3,
  "creator": "3",
  "description": "",
  "genomeType": null,
  "genomeVersion": null,
  "id": 24,
  "publicOverlay": true,
  "type": "GENERIC",
  "order": 10
}
15
{
  type: 'drugs',
  searchValues: ['PRKN'],
  results: [
    [{
      bioEntity: {
        id: 38253,
        map: 52,
        glyph: null,
        submap: null,
        compartment: 46644,
        elementId: 'path_0_sa11305',
        x: 18412,
        y: 3088.653195488725,
        z: 2298,
        width: 80,
        height: 40,
        fontSize: 12,
        fontColor: {
          alpha: 255,
          rgb: -16777216,
        },
        fontColorRgba: '#000000FF',
        fillColor: {
          alpha: 255,
          rgb: -3342388,
        },
        fillColorRgba: '#CCFFCCFF',
        borderColor: {
          alpha: 255,
          rgb: -16777216,
        },
        borderColorRgba: '#000000FF',
        visibilityLevel: '4',
        transparencyLevel: '0',
        notes: '',
        symbol: 'PRKN',
        fullName: 'parkin RBR E3 ubiquitin protein ligase',
        name: 'PRKN',
        nameX: 18412,
        nameY: 3088.653195488725,
        nameWidth: 80,
        nameHeight: 40,
        nameVerticalAlign: 'MIDDLE',
        nameHorizontalAlign: 'CENTER',
        synonyms: ['AR-JP', 'PDJ', 'parkin'],
        formerSymbols: ['PARK2'],
        activity: false,
        lineWidth: 1,
        complex: 38252,
        initialAmount: null,
        charge: null,
        initialConcentration: 0,
        onlySubstanceUnits: false,
        homodimer: 1,
        hypothetical: null,
        boundaryCondition: false,
        constant: false,
        modificationResidues: [{
          id: 58046,
          idModificationResidue: 'rs2',
          name: '',
          x: 18481.67916137211,
          y: 3118.9740341163433,
          z: 2299,
          width: 15,
          height: 15,
          borderColor: {
            alpha: 255,
            rgb: -16777216,
          },
          borderColorRgba: '#000000FF',
          fontSize: 10,
          state: null,
          size: 225,
          center: {
            x: 18489.17916137211,
            y: 3126.4740341163433,
          },
          elementId: 'rs2',
        }, ],
        stringType: 'Protein',
        substanceUnits: null,
        references: [{
          link: 'https://www.genenames.org/cgi-bin/gene_symbol_report?match=PRKN',
          type: 'HGNC_SYMBOL',
          resource: 'PRKN',
          id: 173229,
          annotator: 'HGNC',
        }, ],
        compartmentName: 'Dopamine metabolism',
        complexName: 'insoluble aggregates',
      },
      perfect: true,
    }, ],
  ],
};
{
  "modelId": 52,
  "zoom": 9.033753064925367
}
{
  "modelId": 52,
  "x": 8557,
  "y": 1675
}
{
  "id": 40072,
  "modelId": 52,
  "type": "ALIAS"
}
{
  "id": 40072
}

Marker pin:

{
  "id": "b0a478ad-7e7a-47f5-8130-e96cbeaa0cfe"
}
{
  "id": 18
}

Surface marker overlay:

{
  "id": "a3a5305f-acfa-47ff-bf77-a26d017c6eb3"
}
{
  "id": "b0a478ad-7e7a-47f5-8130-e96cbeaa0cfe"
}
{
  "mapId": 52,
  "x": 8557,
  "y": 1675,
  "target": {
    "type": "element",
    "id": 40072
  }
}
52
51
{
  "name": "search"
}
{
  "name": "overlays"
}

Panel names: search, project-info, export, submaps, overlays, overlay-group, available-plugins, layers, reaction, bio-entity, comment. Switching directly from one panel to another emits onPanelClose for the old panel, then onPanelOpen for the new one. Both events are triggered whether the change came from the user or from openPanel / hidePanel (see Interface). The legend is not a panel and triggers neither event.

{
  "hash": "b0a478ad-7e7a-47f5-8130-e96cbeaa0cfe"
}
Example of adding event listener:#
const {
  element,
  events: { addListener, removeListener, removeAllListeners },
} = minerva.plugins.registerPlugin({
  pluginName,
  pluginVersion,
  pluginUrl,
});

const callbackShowOverlay = data => {
  console.log('onShowOverlay', data);
};

addListener('onShowOverlay', callbackShowOverlay);

Remove Event Listener#

To remove event listener, plugins can use the removeListener method in events object returned by window.minerva.plugins.registerPlugin. This method takes two arguments: the name of the event and the reference to the callback function previously used to add the listener.

const {
  element,
  events: { addListener, removeListener, removeAllListeners },
} = minerva.plugins.registerPlugin({
  pluginName,
  pluginVersion,
  pluginUrl,
});

const callbackShowOverlay = data => {
  console.log('onShowOverlay', data);
};

addListener('onShowOverlay', callbackShowOverlay);

removeListener('onShowOverlay', callbackShowOverlay);

Remove All Event Listeners#

To remove all event listeners attached by a plugin, plugins can use the removeAllListeners method in events object returned by window.minerva.plugins.registerPlugin.

const {
  element,
  events: { addListener, removeListener, removeAllListeners },
} = minerva.plugins.registerPlugin({
  pluginName,
  pluginVersion,
  pluginUrl,
});

const callbackShowOverlay = data => {
  console.log('onShowOverlay', data);
};

const callbackHideOverlay = data => {
  console.log('onHideOverlay', data);
};

const callbackOpenSubamp = data => {
  console.log('onSubmapOpen', data);
};

addListener('onHideOverlay', callbackHideOverlay);

addListener('onSubmapOpen', callbackOpenSubamp);

addListener('onShowOverlay', callbackShowOverlay);

removeAllListeners();