Creating a Custom Widget for Use in Stories

Objectives

After completing this lesson, you will be able to:

  • Create a Top Three custom widget with basic configuration options

Custom Widget Defined

Custom widgets are used when story creators need a specific user interface element, a particular visualization of data, or a certain functionality in your analytic application that is not provided by the predefined set of widgets.

Custom widgets seamlessly integrate into SAP Analytics Cloud. Like any other widget used for a story, a custom widget provides the following capabilities:

  • It is listed in the widget menu list from where you can add it to the canvas.
  • It can be moved and resized on the canvas.
  • It appears in the widget outline.
  • It can contribute script methods to the javascript language.
  • It can provide configuration options in the Styling Panel and Builder Panel.

Custom Widget Creation

Custom widgets are technically a simple set of files. The most basic custom widget consists of simply a JSON file and a JavaScript file.

The JSON file specifies the custom widget and contains specific properties of the custom widget, including references to the JavaScript file that defines it. You can also create a JavaScript file to customize the SAP Analytics Cloud Builder and Styling panes for the widget, but those are optional.

To create custom widgets, you do not need special software. At the beginning, a simple text editor will do. However, when your custom widgets get more complex, a good JavaScript text editor will make your development efforts easier.

An SAP Analytics Cloud custom widget is implemented as a Web Component in the HTML Document Object Model (or DOM) of a web page that will not interfere with the rest of the HTML DOM. We achieve this by separating a custom widget’s HTML DOM from the HTML DOM of the web page in a shadow DOM.

Let's check in with Julie to see how she is designing the custom widget for Dirk. She will refer to the SAP Analytics Cloud Custom Widget Developer Guide, so you may want to download a copy of it and keep it handy for your custom widget projects.

The JSON File Explained

The JSON file defines the custom widget. Juile explains the logic of her JSON file in this video.

The JavaScript Files Explained

The Javascript files Implement the custom elements of the custom widget. You can define up to three files:

  • Main file - defines the custom widget
  • Styling file - defines the styling pane options for the custom widget
  • Builder file - defines the builder pane options for the custom widget

The Main files is mandatory, but the other two are optional.

In this video, Julie explains the logic of her Main and Sytling JavaScript files.

Log in to track your progress & complete quizzes