All Products
Search
Document Center

DataV:Switch

Last Updated:Jan 15, 2025

This topic provides a guide on using the switch widget.

Component overview

The switch is a control widget that simulates a physical switch, allowing users to toggle between on and off states. Configurable interactions enable it to work in tandem with other widgets to manage content visibility, render different states, and more.

Scenarios

Switches are typically used in visualization applications to toggle the display or concealment of specific content based on the switch's state. For instance, a switch can be used to enable or disable sound or to show or hide sidebar configurations.

Effect display

  • Static Switch

    image.png

  • Interactive Scenarios

    screenshot_2025-01-09_17-20-00

Prerequisites

  • A data dashboard is available that supports creation using a template, a blank canvas.

  • Business data is ready for use. For more information, see Data Source.

Add a switch

  1. Access the DataV console.

  2. Navigate to Workbench > > All Applications > > Data Dashboard and select the desired dashboard to access the canvas editing page.

  3. In the Widget Library > Controls > Button Category list in the left-side navigation pane, click the Switch widget to add it to the canvas.

You can also use global search to add related widgets.

Connect to business data

After adding the widget, connect it to prepared business data for display. Click the switch, and in the Data Source tab on the right, select the data for the widget to render. image

  • The data fields received by the switch are as follows.

    Field

    Description

    onValue

    The value emitted when the switch is turned on. The default is 1.

    offValue

    The value emitted when the switch is turned off. The default is 0.

    state

    The on or off state of the switch. This parameter value can only be configured as the value of onValue or offValue. The default is 0 or 1, where 0 indicates the switch is off, and 1 indicates the switch is on.

    Below is the data structure and effect display of a sample switch.

    // Turn on the switch
    [
      {
        "onValue": 1,
        "offValue": 0,
        "state": 1
      }
    ]
    
    // Turn off the switch
    [
      {
        "onValue": 1,
        "offValue": 0,
        "state": 0
      }
    ]

    image

  • The key configuration items for the data source are as follows.

    Configuration Item

    Description

    Select Data Source

    Supports integrating various types of data such as CSV files, APIs, and various databases. For more information, see Data Source. You can edit data fields using a visual table or code.

    Configure Filter (Optional)

    Used to customize filter code to achieve data structure transformation, filtering, display, and simple calculations. For more information, see Manage Data Filters.

    Configure Data Mapping

    Used to map fields from the selected data source to the corresponding fields of the widget to achieve real-time data matching. Click the image icon to configure field styles.

    View Response Results

    Used to display the data integrated into the widget in real-time. When the widget data source changes, the latest data will be displayed here.

    • Click the data response result to view the code of the data fields written.

    • Click to view the example to see the array type and code example received by the data source. You can refer to the example to write related fields.

    Other data request configurations:

    • Disable Loading State: When selected, the loading content during widget initialization will not be displayed when updating or previewing the data dashboard.

    • Controlled Mode: When selected, the widget will not request data in the initialization state. At this time, data requests can only be initiated through the blueprint editor or global variable events.

    • Automatic Update Request: When selected, the platform will dynamically poll and update data according to the polling time you set. If not selected, you need to manually refresh the page or trigger a request to update data through the blueprint editor and global variable events.

Configure the switch

Click the switch widget to access its configuration options for basic styles, global variables, interaction occurrences, and other advanced settings, along with blueprint interaction configurations, in the right-side panel.

Style configuration

In the Style panel, configure the default state, background color, and border style of the switch. The configuration items are detailed below.

Note

Quickly find configuration items by clicking the image icon and using keywords to search, which supports fuzzy matches. For more information, see Search for Configuration Items.

The configuration items are described below.

Configuration item

Description

Illustration

Global configuration

Defines the position distribution, transparency, and interaction penetration of the widget in the data dashboard.

  • Opacity: The smaller the value, the more transparent the widget. The value range is within 0~1.

  • Interaction Penetration: When enabled, the mouse can penetrate this widget to avoid the widget blocking the interaction between the mouse and the underlying widget when there are many widgets on the dashboard.

image

Basic style configuration

Defines the default selected state, background color, and border styles such as color, thickness, and border radius of the switch. The related descriptions are as follows:

  • Default selected state: When enabled, the added switch widget is in the on state by default.

    Note

    This configuration has a lower priority than the value of the state field in the data source. The configuration state of state takes precedence.

  • Background color: You need to configure the background colors for the on and off states of the switch separately.

image

Switch handle configuration

Defines the color, border style, width, height, and vertical position offset of the switch handle. The switch handle is typically used to control the on and off states of the switch. image

image

Advanced configuration

Define the interactions between the switch and other widgets. The configuration items are detailed below.

Configuration item

Description

Illustration

Interaction occurrences

Defines the interaction behavior with other widgets to achieve widget linkage. Click the image icon to define related interaction occurrences and actions.

image

Associate global variables

You can associate global parameters in the widget to enable parameter passing between widgets and achieve widget interactions. Click the image icon to enable the corresponding instruction and associate the required global variables.

When the state of the switch changes (that is, when the switch is turned on or off), it triggers a data request and emits the configured value in the data source panel. Turning on the switch emits the onValue value. Turning off the switch emits the offValue value. For more information, see Widget interaction configuration.

Blueprint interaction

Visually define the interaction relationships and behavior logic between widgets using the Blueprint Editor.

Procedure

  1. On the canvas editing page, click the image icon at the top left of the menu bar to enter the blueprint editor.

  2. Hover over the switch widget in the layer node list and click the image icon to add it to the main canvas.

  3. Configure the blueprint interaction effects for related widgets using connections as required.

    Below is an example. image

Configuration item description

The interaction occurrences and actions are detailed below.

Note

Click the image icon next to an occurrence or action in the blueprint configuration interface for detailed parameter descriptions.

Category

Subcategory

Description

Event

When Data Is Updated

This event is emitted when the widget data is updated.

When The Request Status Changes

This event is emitted when the data request status changes. The status values include Void, Loading, Success, and Error.

When The State Changes

This event is emitted when the state of the switch changes, along with the corresponding data item for that state. An example is shown below.

{
  "value": 1  // Current state value
}

Action

Import Data

Processes data according to the widget rendering format and imports it into the widget for re-rendering without re-requesting server-side data. An example is shown below.

[
  {
    "onValue": "1",
    "offValue": "0",
    "state": 1
  }
]

Request Data

Re-requests server-side data. The data emitted by upstream data processing nodes or layer nodes will be used as parameters. For example, if the API data source configured for the switch is https://api.test, and the data passed to the Request Data action is { id: '1'}, the final request will be https://api.test?id=1.

Obtain The Current Switch State

Obtains the current state of the switch.

Set The Current Switch State

Sets the current state of the switch. An example is shown below.

{
  "value": 1  // Current state value. 1 indicates the switch is on, and 0 indicates the switch is off.
}

Reset The Widget To Default Values

Reverts the widget to its default values.

Move

Move the widget to a specified position. The data example is as follows.

    {
      // Movement method. Absolute positioning: to, relative positioning: by. Default value: to.
        "positionType": "to",
      // Specified position. x-coordinate, y-coordinate.
      "attr": {
        "x": 0,
        "y": 0
      },
      // Animation method.
      "animation": {
        "enable": false,
        // Animation delay.
        "animationDuration": 1000,
        // Animation curve. Optional values are: linear|easeInOutQuad|easeInOutExpo.
        "animationEasing": "linear"
      }
    }

Toggle Visibility

Switch the widget to show or hide. The data example is as follows.

{
  "animationType": "fade",
  "animationDuration": 1000,
  "animationEasing": "linear"
}
  • animationType: Animation method. It can be configured as appear (appear/disappear), fade (fade in/fade out), slideToUp (fly in/fly out). If not configured, it means no animation.

  • animationDuration: Animation delay, default is 1000ms.

  • animationEasing: Animation curve. It can be configured as linear (uniform speed), easeInOutQuad (smooth), easeInOutExpo (slow-fast-slow).

Show

Hide

Update Widget Configuration

Dynamically update the style configuration of the widget.

  1. First, in the Style panel of the widget, click Copy Configuration To Clipboard to obtain the configuration data of the widget.

  2. As needed, change the field values of the corresponding style in the data processing node on the blueprint editor configuration page.