ButtonService
ButtonService is an Angular Factory in the Widget module with the name button.js
. It provides an API to create buttons, toggles, and radio button sets. To use these functions, see the documentation on injecting Angular services.
Function Descriptions
button
Creates a button – an element that executes a function when clicked.
Example Usage | Arguments | Return Value |
---|---|---|
var button = bns.button(div , id , gid , cb , tooltip ); |
| creates a button with the given information returns an object with an API (see below) |
Returned API Example Usage | Arguments | Return Value |
button.id; * | none | string that is the ID of the button |
button.width(); | none | number that is the width of the button plus padding (in pixels) |
* This API property is not a function.
An example of a button is the Reset pan / zoom button on the Topology View.
When clicked, the pan and zoom of the Topology View is reset to the default. This is an example of an "execute once" type of function, which is what buttons are for. Also shown is the tooltip.
toggle
Creates a toggle – an element that has state (selected or unselected) that executes a function on click.
Example Usage | Arguments | Return Value |
---|---|---|
var toggle = bns.toggle(div , id , gid , initState , cb , tooltip ); |
| creates a toggle with the given information |
Returned API Example Usage | Arguments | Return Value |
toggle.id * | none | string that is the ID of the toggle |
toggle.width(); | none | number that is the width of the toggle plus padding (in pixels) |
toggle.selected(); | none | boolean of the state of the toggle true - toggle is selected false - toggle is unselected |
toggle.toggle(); | none | this toggles the state of the button and executes cb with the selected state |
toggle.toggleNoCb(); | none | toggles the state of the button but does not execute cb |
* This API property is not a function.
An example of a toggle is the ONOS summary panel toggle on the Topology View:
When the state of the toggle is "selected", the summary panel will be shown on the Topology View. When the state is "unselected", the summary panel will not be shown on the view. The callback function for this toggle takes into account the state of the toggle and will either show or hide the panel based on the state. Also shown is the tooltip.
radioSet
Creates a radio button set – set of one or more elements that have state (one is selected at a time) that executes assigned functions when each are clicked.
Example Usage | Arguments | Return Value |
---|---|---|
var radioSet = radioSet(div , id , rset ); |
| creates a radio button set returns an object with an API (see below) |
Returned API Example Usage | Arguments | Return Value |
radioSet.width(); | none | returns the width of the entire radio button set plus padding |
radioSet.selected(x ); | getter / setter function
| selected radio button's |
radioSet.selectedIndex(x); | getter / setter function
| selected radio button's index if called with no arguments |
* Note: the first object (button) in the rset array will be initially selected.
Example of creating a radio button set:
var radioSet = radioSet(d3.select('div.foo'), 'foo-radio-set', [ { gid: 'bird', cb: function (index, key) { /* do something */ }, tooltip: 'Cool radio button 0', key: 'radioButton0' }, { gid: 'checkMark', cb: function (index, key) { /* do something else */ }, tooltip: 'Cool radio button 1', key: 'radioButton1' }, { gid: 'xMark', cb: function (index, key) { /* do something different than the other two */ }, tooltip: 'Cool radio button 2', key: 'radioButton2' } ]);
An example of a radio button set is below.
Each of the above buttons has a different callback and only one is active at a time.