Custom widgets¶
ChartFactor Studio allows users to easily use custom javascript code to extend the functionality of the platform. This code can be used to create custom widgets with custom visualizations, custom interactions, custom data sources, and more.
In order to create a custom widget in ChartFactor Studio, you need to implement the following functions:
Setup(widgetId, utils)¶
The setup(widgetId, utils)
function is invoked by ChartFactor Studio to set up your widget. It should return an Aktive object that will be used by ChartFactor Studio to interact with the widget. This function can be asynchronous so that it returns a promise or it can be a normal function that returns an object.
Parameters:¶
widgetId
: The id of this widgetutils
: An object with Studio utility functions that are made available to the custom code. Theutils
object includes the following functions:getSourceFilters(provider, source)
: This function is used to get the filters for a specific source. Theprovider
parameter is the name of the provider and thesource
parameter is the name of the source. This function returns a promise that resolves to an array of filters.saveVar(name, value)
: This function is used to save a variable in the widget context. Thename
parameter is the name of the variable and thevalue
parameter is the value of the variable. This function returns a promise that resolves when the variable is saved.getVar(name)
: This function is used to get a variable from the widget context. Thename
parameter is the name of the variable. This function returns a promise that resolves to the value of the variable.removeVar(name)
: This function is used to remove a variable from the widget context. Thename
parameter is the name of the variable. This function returns a promise that resolves when the variable is removed.mergeData(...data)
: This function is used to merge data from multiple queries using the group in each data object. Therefore, it requires that each data object has only one group. Thedata
parameter allows you to pass multiple data objects, eg.mergeData(data1, data2, data3, data4)
. This function returns a promise that resolves to a single data object. The Custom Widget Example section shows how this function can be used.
loadProviders()¶
The loadProviders()
function is used to load the providers that will be used in the custom code. This function should return an array with the names of the providers that will be used in the custom code.
onDestroy()¶
The onDestroy()
function should perform any clean up needed when users delete the widget from the dashboard.
Custom Widget Example¶
The example below shows how to implement a custom widget that renders trends for ETF (Exchange Traded Funds) volume and consumer confidence. The data resides in two separate sources and this widget queries those data sources separately and then merges the trend results.
The code of this custom widget is below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
In the example above, we are using the loadProviders()
function to load the providers that will be used in the custom code. The getMultipleQueryData()
function is an asynchronous function that returns a promise and is used to get data from multiple queries. The setup()
function is an asynchronous function that returns a promise and is used to setup the custom code.
Note
You need to provide your own logic to persist filters and field metadata updates (e.g. field labels) manually. The utils parameter passed to the setup()
function includes helper functions that you can use to implement this functionality if needed.