Users can create iframe based widgets with LocalFocus. The Widget API is a small javascript function that helps developers to add simple functionalities, like a loading spinner. It uses postMessage.
This script, code examples and documentation are licenced under MIT Licence.
Getting started
Download the latest localfocusapi.js and copy the function or include the script in your webpage:
<script src="path-to-the-script/localfocusapi.js"></script>
Append ?api=1
to the widget's links to force widgets to listen to commands:
<iframe class="localfocusvisual" scrolling="no" frameborder="0" style="width:100%;height:550px;overflow:hidden" src="https://localfocus2.appspot.com/5846cde78fdeb?api=1"></iframe>
This example demonstrates a loading spinner. Widgets send signals to your webpage about their current state. This example listens to the "ready" signal with the widgetObject.on() function. It then hides the spinner and fades in the chart.
The code
LocalFocus visualisations can have interactive options. Use the widgetObject.activate() function to activate an item from the dropdown menu. Want to create your own interaction buttons? With the noui=1 parameter you can hide the chart's default dropdown menu.
The code
You can (and must) append parameters to the iframe links:
api=1 (required! This activates the Widget API) |
It forces the widget to listen to API commands. |
noui=1 |
Disable the widget's default interaction panel. Now you can create your custom control panel. Maps and tables are not supported. |
With the LocalFocusAPI
you can select iframes that contain LocalFocus widgets.
LocalFocusAPI.select(selector)Select one widget that you want to control. Arguments
Returns A new object |
|
Commands specific widgets using the widgetObject
object.
widgetObject.on(event, callback)Only the "ready" event is supported. This event will be broadcast when the widget finishes loading and rendering. Arguments
Returns Current |
|
widgetObject.activate(label)Visualisations can have interactive features. To activate one of the labels using the API, use this method. Maps and tables are not supported. Arguments
Returns Current |
|
widgetObject.element()Get the iframe element. Arguments None Returns iframe element |
|