Using Sample Widgets to Create Custom Widgets
WSO2 provides sample widgets for your reference so that you can create custom widgets with similar configurations. These widgets are hosted as projects in Stackblitz. To create your own custom widgets based on these samples, you can fork them and edit them as required. Once you have created your own widgets, you can download them as Zip files and deploy them in the WSO2 SP Dashboard Portal.
Before you begin:
- Install Node.js and npm by clicking one of the following links:
- On Windows
On Linux and other OS: Download for Linux and others
Understand how to work with Stackblitz.
The following sections cover the available sample widgets and how you can use them as templates to create your own custom widgets.
Accessing, downloading, and installing sample widgets
The directory structure of a widget is as follows:
â–¼mocking
â–¼components
â–ºassets
â–ºdataSet
â–ºpublic
â–ºresources
â–¼src
â–ºtheme
The following table describes the contents of the directories in the above structure:
Directory | Contents |
---|---|
<root> | Contains global configuration and Javascript files, the index, and the package.json file. |
mocking | Contains the publisher and subscriber simulation parts and React components that give the Dashboard Frame experience with external customizations(Theme/EventStack). It includes:
|
resources | Contains the
|
public | Contains the Index.html file that is used in the Stackblitz editor to render the live preview. |
src | Contains all the source code files required to preview the widget in the Dashboard. |
src/theme | Contains the material UI Theme customizations that are required for the user to interact with components and to change their view (e.g., dark and light). |
src/widget | Contains the React code used to implement the widget. |
All the code in files below the src/widget
directory is included in the production build.
To use the samples, follow the steps below:
- Open the required sample in the WSO2 account in Stackblitz and click Fork to make a copy in your fork. Observe how the widget operates and its functionality.
Make the required changes in the
MyWidget.jsx
file. For details on each individual widget, see Available sample widgets.It is recommended for you to edit only the
MyWidget.jsx
file because it is the only file required by the WSO2 SP Dashboard portal. The other files are available for the purpose of simulating the WSO2 SP Dashboard Portal functionality in Stackblitz so that you can understand how the widget is expected to function in the Dashboard Portal. However, you can edit thetheme.js
file in<root>/src/theme
directory if you want to change the theme (i.e., the light background or the dark background) and other properties related to the look and feel such as the colors, height, width, etc.- Optionally, add configurations to the
<WIDGET_HOME>/resources/widgetConf.json
file and make modifications to the other configuration files as described in the above table. - Once you finish editing the widget in the Stackblitz editor, download the file as a zip file by clicking on the icon marked in the image below. Then extract the content.
- To install, build, and deploy the widget, open your terminal and navigate to the root directory of the widget. Then issue the following commands.
- To install all the dependencies for the widget, issue
npm i
. - To build the widget, issue
npm run build
. - To deploy the widget, issue
npm run deploy
.
- To install all the dependencies for the widget, issue
Available sample widgets
The following is a list of sample widgets hosted in Stackblitz undee the wso2stackblitz account. You can observe the way in which they function via the mocking tools in Stackblitz. If you need to create similar widgets, you can fork the project for the required widget and edit the <WIDGET_HOME>/resources/widgetConf.json
file to customize it based on your requirement.
WSO2-LinChart-SiddhiDataProvider
Purpose | To preview a sample line chart and observe its functionality via a data set. |
---|---|
Information source | If you include this sample in WSO2 Stream Processor without making any changes, it uses the Siddhi Data Provider to load the data by executing a Siddhi application and the relevant Siddhi query. For more information about writing Siddhi applications and Siddhi queries, see the following sections: |
Customizing the widget | To learn about different chart types and how to do the configurations for customizations, see the React-VizGrammar documentation. The
|
Preview link | wso2-linechart-siddhiprovider |
WSO2-MultiBarChart
Purpose | To view a multiple bar chart that enables you to change the dimensions in real-time, and view multiple Y axis dimensions against a single X axis dynamically. |
---|---|
Information source | Create the Siddhi application and the query that forms the required columns. These columns are used to populate the chart. For more information about writing Siddhi applications and Siddhi queries, see the following sections: |
Customizing the widget | Check boxes are automatically loaded based on the data set provided. To change the chart type and the color configurations, see the React-VizGrammar documentation. The
|
Preview link | wso2-multibarchart |
WSO2-worldmap
Purpose | To view how your data can be distributed in a world map. |
---|---|
Information source | Create the Siddhi application and the query that builds the required data set. For more information about writing Siddhi applications and Siddhi queries, see the following sections: |
Customizing the widget | The To change the map type and the color variations, see the React-VizGrammar documentation. |
Preview link | wso2-worldmap |
WSO2-subscriber-piechart
Purpose | Shows how to manipulate a chart or table according to a particular value. You can use the publisher simulation to publish a date event or a JSON object, and you can view a pie chart sorted by the date events. You can check out the published events using the event stack. This widget is implemented to filter the data according to the published date events as well as the raw JSON object. To view this information in the Dashboard Portal, use the Date Range Picker that is already implemented for the widget ( in the DATE RANGE PICKER tab), or enter the region as a key value pair in the RAW VALUE PUBLISHER tab. For example, if you enter |
---|---|
Information source | Create the Siddhi application and the query that builds the required data set. For more information about writing Siddhi applications and Siddhi queries, see the following sections: |
Customizing the widget | To learn about different chart types and how to do the configurations for customizations, see the React-VizGrammar documentation. The
|
Preview link | wso2-subscriber-piechart |
WSO2-subscriber/publisher-barchart
Purpose | To observe a scenario where subscribing for data and publishing data takes place at the same time. This bar chart is implemented to select a date object on the publisher widget so that the data can also be filtered by that date object. If you click on a bar, data specific to the country represented by the bar is displayed. |
---|---|
Information source | Create the Siddhi application and the query that builds the required data set. For more information about writing Siddhi applications and Siddhi queries, see the following sections: |
Customizing the widget | To learn about different chart types and how to do the configurations for customizations, see the React-VizGrammar documentation. The
|
Preview link | wso2-subscriber-publisher-barchart |
WSO2-ValuePublisher
Purpose | The WSO2 dashboard supports inter-widget communication via a pub-sub model. If you need to publish a name-value pair to manipulate another widget, you can use this sample. The published value can be seen in the stack bar (as shown below) as well as in the mocking subscriber tool. |
---|---|
Information source | Create the Siddhi application and the query that builds the required data set. For more information about writing Siddhi applications and Siddhi queries, see the following sections: |
Customizing the widget | The
|
Preview link | wso2-valuepublisher |
WSO2-Aggregated chart
Purpose | To preview a chart where the data is in the form of an aggregation, and where data can be filtered based on a selected time range. Charts based on the aggregation concept typically use the date range picker to view data for different date ranges and time granularities. For more information about the aggregation concept, see Incremental Analysis. |
---|---|
Information source | This widget includes sample data sets to allow you to observe how an aggregation chart functions. The following is a guide to prepare a dataset from your aggregation source.
|
Customizing the widget | To change the chart type and the color configurations, see data setGrammar documentation. The
|
Preview link | wso2-aggregated-chart |
Testing sample widgets via mocking tools
When the functionality of a widget involves interacting with another widget, you also need the other widget to observe the functionality. This requirement exists mainly when the pubsub model is used when a user input made via one widget triggers a response in another widget. The sample widgets of this type are provided with a mocking tool. The mocking tool simulates the behaviour of the other widget with which the widget being tested is expected to interact.
- Subscriber mocking tool
This tool is implemented to demonstrate the functionality of sample publisher widgets.
When the widget is a publisher, it needs a subscriber widget to subscribe to the information it publishes. For sample publisher widgets in Stackblitz, WSO2 provides this subscriber mocking tool to mock the expected action of the connected subscriber widget.To activate this tool for a sample publisher widget, enter
publisher
as a key in the<WIDGET_HOME>/resources/widgetConf.json
file as shown in the following extract:"configs": {
"pubsub": {
"types": ["publisher"]
},
For example, the following bar chart is a publisher widget where if you click on a bar, the subscriber mocking tool displays information related to that bar in the same manner that a subscriber widget connected to this chart is expected to display that information.
- Publisher mocking tool
This tool is implemented to demonstrate the functionality of sample subscriber widgets.
When the widget is a subscriber, it needs a publisher widget to publish the information it subscribes for. For sample subscriber widgets in Stackblitz, WSO2 provides this publisher mocking tool to mock the expected action of the connected publisher widget.To activate this tool for a publisher widget, enter
subscriber
as a key in the<WIDGET_HOME>/resources/widgetConf.json
file as shown in the following extract:"configs": {
"pubsub": {
"types": ["subscriber"]
},
This tool publishes information in two methods:
- Date picker
In this method, you can publish date range events with granularity. If you need to view the actual publishing object you can switch to the JSON view. In the JSON view, you can manipulate your changes, but only date events are backward compatible. - Raw JSON
In this tab, you can validate your own JSON object. You can manipulate various factors relating to the widget behaviour such as date filtering and changes in color via these JSON objects.
- Date picker