Custom plug-ins

With the plug-in widget, you can customize how your data is processed and displayed.

The plug-in widget needs the next files to run:

backend.js

The backend.js return an object that contains three functions:

init(params):

This function is run when you initialize your widget on the server

params: key and value map of plug-in parameters

update(trace):

This function is called every time that your widget is reloaded

trace: object that contains the next methods:

TraceEvent: event object that contains the next methods

finalize(output):

This function is run when your data is processed and used to send the data you want to display to the browser, for example,

...
update: function(trace) {
    this.myVariable = "plugin test";
},
finalize: function(output) {
    output['myIntVariable'] = 8;
    output['myVariable'] = this.myVariable
}
...

Helpers

console: helper object with the purpose of printing messages on console

API: helper object that contains the next methods:

SummaryStatisticsLite: object to compute and store statistics

frontend.js

The frontend.js return an object that contains three functions:

init(context):

This function is run when you initialize the widget.

The context parameter is an object that contains two properties:

  1. element (jQuery object that contains DOM node of your widget)
  2. scope (angular context of your widget)

You can alter the DOM element of your widget with jQuery or alter the scope with AngularJS

update(data, context):

This function is run every time that the dashboard is reloaded.

data: object that contains your data that can be bound to the scope to be displayed

context: see the previous section

For example,

update: function(data, context) {
// set your data in scope so you can use it where you need
    context.scope.data = data;
}

Eventually you can manipulate your data by using jQuery or Underscore.js, for example,

update: function(data, context) {
// set your data in scope after transforming it so you can use it where you need
    context.scope.data = _.map(data, function(element) {
      return {
          name: element.id,
          text: element.value
      };
    });
}

resize(size, context):

This function is run every time that the widget is resized.

size: object that contains width and height of your widget

context: see the previous section

External Libraries Available

view.html

The view.html file contains the content of your widget.

To display your data and change HTML elements based on the content without the need to modify the DOM with JavaScript, you can use the next angular helpers:

For example,

frontend.js

init: function(context) {
    context.scope.myVariable = 'Plugin widget test';
    context.scope.myIntVariable = 8;
}

view.html

<!-- the next syntax will print the content of myVariable inside the paragraph -->
<p>{{myVariable}}</p>

<!-- the next paragraph will be displayed only if myIntVariable is greater than 5 and the content will be formatted as a number -->
<p ng-if="myIntVariable > 5">{{myIntVariable | number}}</p>

For more information, see the angular documentation

Advanced Filters

In addition to angular filters, you can use custom filters that are designed specifically to reach every need

formatMeasure: param

Filter to format any kind of value.

params can be one of the next values.

For example,

<!-- will print the date with the format based on your location i.e. 01/01/2018 -->
<p>{{myDateVariable | formatMeasure:'datetime'}}</p>

style.css

The style.cssfile contains the stylesheet for your widget, for example,

p {
    font-size: 14px;
    color: red;
}

Note: The style that is written in this file is only applied to your widget

schema

The schema table contains optional parameters that can be set in the widget options.

The parameter can be either of the next two types: