Class: Button

Button

A UI Button instance. The button, when pressed, will perform a certain action on the chart. Buttons are configured by the CompactChart configuration Config. Buttons is a plugin. To use it, you must add "buttons" to the InteractionConfig plugins array.

Since:
  • 9.4.0 Introduced
  • 10.1.0 Added rangeValue property to button, sourced from value button parameter. Added built-in action for pressing a range button.

Members


<readonly> name :string

Button name.

Type:
  • string
Since:
  • 9.4.0


<readonly> qc :CompactChart

CompactChart instance to which this button belongs.

Type:
Since:
  • 10.1.0

Methods


press()

Forcibly "presses" a button even if it is not currently visible. This is useful when external UI is created to replicate the internal button functionality. The button must exist for this function to work.

Since:
  • 10.1.0

Example

Switch to a bar chart:

cc.buttons.bar.press();

setActive()

For a group of buttons that act as radios (only one button in the group can be active at one time), this function will show the instance's button as active while deactivating the rest of the buttons in the group. Note this does not actually perform the button's action.

Since:
  • 9.4.0 Introduced
  • 10.1.0 removed qc parameter
Example

Toggle a custom theme:

cc.setTheme("myTheme");
myButton.setActive(); // in the process deactivate any other theme buttons.

toggleActive(value)

For a single button, will activate the button if deactivated, or will deactivate if activated, Note this does not actually perform the button's action.

Parameters:
Name Type Description
value boolean

New state of button.

Since:
  • 9.4.0

Example

Turn on custom functionality when a button is pressed:

doAction(...);
myButton.toggleActive(true);

Type Definitions


ButtonConfig

Configuration settings for a single button. Note that the Periodicity settings this type extends are optional.

Type:
Properties:
Name Type Argument Description
group string <optional>

For a menu button, set to "main" to indicate top level, otherwise set to the button name of parent menu.

useIcon boolean <optional>

true to place image defined in css for content of button.

label string <optional>

Text to place within a button. May contain html markup. This text will not appear if useIcon is set to true and an icon is found. If this is not set the text to use in the button will be the same as the button name.

reader string <optional>

Text to be read by a screen reader when button is in focus.

role string <optional>

Usually the button has a checkbox role, but the role can be changed to "radio" with this property.

toggles string <optional>

If the button toggles a layout setting, set this property to the layout property being set.

action ButtonConfigVoidFunction <optional>

For custom defined buttons, fired when button is pressed. Function has access to the compact chart object and to the button.

escape ButtonConfigVoidFunction <optional>

Used to custom-define an action to be performed when button has focus and the Escape key is pressed. Function has access to the compact chart object and to the button.

shouldShow ButtonConfigBooleanFunction <optional>

Used to custom-define whether a button is visible under certain conditions. Function has access to the compact chart object and to the button.

isActive ButtonConfigBooleanFunction <optional>

Used to custom-define whether the button should show an indication of being active (on) or not. Function returns a boolean. Function has access to the compact chart object and to the button.

topLevel boolean <optional>

Indicates a top level menu item. A button with group set to "main" is automatically a top level menu item. Buttons belonging to a group and not a top level item are considered sub-menu items and are accessible only from its group's button.

chartScale string <optional>

Used in a button that changes the y-axis scaling to indicate the scaling method.

value Array <optional>

Used in a span button to configure what range the button will set the chart to. For example, to set a value of a 5 day span using 1 hour bars, use value: [5, "day", 30, 2, "minute"]. For a three-month range with a daily periodicity, only two array elements are required: value: [3, "month"].

Elements
Index Type Argument Description
0 number

Period of range.

1 string

Units of range.

2 number <optional>

Interval of bars to fetch.

3 number <optional>

Period of bars to fetch.

4 TimeUnit <optional>

Timeunit of bars to fetch.

Since:
  • 9.4.0


ButtonConfigBooleanFunction(qc)

Function used for buttons (ButtonConfig) that returns a boolean. The this parameter can be used within the function to refer to the button calling the function.

Parameters:
Name Type Description
qc CompactChart

Compact chart instance.

Since:
  • 9.4.0

Returns:

Result of function.

Type
boolean

ButtonConfigVoidFunction(qc)

Function used for buttons (ButtonConfig) that returns a void. The this parameter can be used within the function to refer to the button calling the function.

Parameters:
Name Type Description
qc CompactChart

Compact chart instance.

Since:
  • 9.4.0


ButtonsConfig

UI menu buttons configuration. Configures the UI buttons that appear on the chart to control various features. The buttons can exist in a hierarchy resembling menus and submenus. Some buttons have their functionality defined within the application, while others can be customized by you. In order to use buttons, you must also include the interaction feature, as it is a "plugin" of interaction. Buttons emit custom events that you can listen to. They propagate up the DOM tree, so you can add an event listener to the chart container to catch them. The event type is "chartiq".

Type:
Properties:
Name Type Argument Description
export string <optional>

Name of the exported class, usually "Button".

backgroundColor string <optional>

Color for the background of the buttton

color string <optional>

Color for the text of the button

borderColor string <optional>

Color for the border of the button

types Record.<string, ButtonConfig> <optional>

Collection of buttons represented as objects, where the key is the button name and the value is the configuration object.

Since:
  • 9.4.0


Menu state.

Type:
  • object
Properties:
Name Type Argument Description
lastState string <optional>

Hash of menu layout.

main string <optional>

Name of parent menu item of item selected.

over boolean <optional>

Hover state of menu item.

showing string <optional>

Name of menu item currently selected.

Since:
  • 9.4.0