Switch widget

更新时间:
复制 MD 格式

The switch widget toggles between on and off states and can interact with other widgets to control content visibility.

Widget overview

The switch is a control widget that mimics a physical switch. Click it to toggle between on and off states. You can configure interactions with other widgets to control content visibility or present different states.

Scenarios

Use the switch in visualization applications to show or hide specific content by defining its on or off state. For example, use a switch to enable or disable sound, or to show or hide sidebar configurations.

Demonstration

  • Static switch

    image.png

  • Interaction scenario

    screenshot_2025-01-09_17-20-00

Prerequisites

Add a switch widget

  1. Access the DataV console.

  2. On the Workbench page, in the Data Dashboards area, hover over the target dashboard and click Edit. The canvas editor opens.

  3. In the navigation pane on the left, add the Switch widget to the canvas.image

You can also use the global search to add components.

Connect to business data

After you add the widget, connect it to your business data. Click the switch widget, and then on the Data Source tab in the right-side panel, configure the data.image

  • The following table describes the data fields accepted by the switch widget.

    Field

    Description

    onValue

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

    offValue

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

    state

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

    The following shows the data structure and effect of an example switch.

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

    image

  • This section describes the core configuration items for the data source.

    Configuration

    Description

    Select Data Source

    Supports various data types, such as CSV files, APIs, and different databases. For more information, see Supported data source types. Edit data fields in a visual table or in code.

    Configure Filter (Optional)

    Customize filter code to transform, filter, display, and perform simple calculations on data. For more information, see Manage data filters.

    Configure Data Mapping

    Map fields from the selected data source to the widget's fields. This enables real-time data matching. Click the image icon to configure field styles.

    View Response Result

    Displays the data connected to the widget in real time. When the widget's data source changes, this section shows the latest data.

    • Click the data response result to view the data field code.

    • Click View Example to see the array type and sample code that the data source accepts. You can write your fields based on the example.

    Other data request configurations:

    • Disable Loading State: If you check this box, the widget's initial loading content does not appear when the widget updates or when you preview the data dashboard.

    • Controlled Mode: If you check this box, the widget does not request data when it initializes. Data requests can only be started by the blueprint editor or by global variable events.

    • Auto Update Request: If you check this box, the platform polls for data updates at the interval you set. If you do not check this box, you must refresh the page manually or use the blueprint editor or global variable events to trigger data updates.

Configure the switch widget

Click the switch widget. In the right-side panel, configure its basic styles, advanced settings such as global variables and interaction events, and Blueprint interactions.

Style configuration

On the Style panel, configure the default state, background color, and border style of the switch.

Note

You can also click the image icon and search by keyword to quickly locate a specific configuration item. The search feature supports fuzzy matching. For more information, see Search for configuration items.

The following table describes the configuration items.

Configuration Item

Description

Example

Global Settings

Defines the widget's position, transparency, and interaction passthrough in the data dashboard.

  • Opacity: The smaller the value, the more transparent the widget. The value ranges from 0 to 1.

  • Interaction Passthrough: If you turn this on, mouse events pass through the widget. This is useful when many widgets are on the dashboard and you need to interact with widgets in lower layers.

image

Basic Styles

Configure styles for the switch, including its default selected state, background color, and border properties such as line style, color, thickness, and border radius. The following section provides more details:

  • Default Selected State: When enabled, the switch widget is on by default.

    Note

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

  • Background Color: Configure the background colors for the on and off states of the switch separately.

image

Switch Handle Configuration

Specifies the color, border style, width, height, and vertical offset of the switch handle.image

image

Advanced Configuration

Define interactions between the switch and other widgets. The following table describes the configuration items.

Configuration Item

Description

Illustration

Interaction Events

Define interaction behaviors with other widgets to enable filter interactions. Click the image icon to define interaction events and actions.

image

Associate Global Variables

Associate global parameters to pass values between widgets for interaction. Click the image icon to enable the instruction and associate the required global variable.

When the switch state changes, a data request is triggered and the configured value in the Data Source panel is returned. When the switch is on, the onValue is returned. When the switch is off, the offValue is returned. For more information, see Component Interaction Configuration.

Blueprint interaction

Use the Blueprint editor to define interaction relationships and behavior logic between widgets by connecting them visually.

Procedure

  1. On the canvas editor page, click the image icon on the left side of the top menu bar to open the Blueprint editor.

  2. In the layer node list, hover over the switch widget and click the image icon to add the widget to the main canvas.

  3. Connect the widgets to configure the Blueprint interaction effects as needed.

    The following figure shows an example.image

Configuration items

The following describes the interaction events and actions.

Note

On the right side of the Blueprint editor, you can also click the image icon next to an event or action to view detailed parameter descriptions.

Category

Subcategory

Description

Event

When data is updated

Triggered when the component data is updated.

When data request status changes

Triggered when the data request status changes. The status values include Void, Loading, Success, and Error.

When status changes

Triggered when the switch status changes. Returns the corresponding data item. The following is a data example.

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

Action

Import data

Processes data into the component's format and imports it to redraw the component without requesting server-side data again. The following is a data example.

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

Request data

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

Get current switch status

Retrieves the current status of the switch.

Set current switch status

Sets the current status of the switch. The following is a data example.

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

Clear component to default value

Resets the component to its default value.

Move

Moves the widget to a specified position. The following code shows a data example.

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

Toggle visibility

Toggles the widget's visibility between shown and hidden. The following code shows a data example.

{
  "animationType": "fade",
  "animationDuration": 1000,
  "animationEasing": "linear"
}
  • animationType: The animation method. You can set this to appear (appear/disappear), fade (fade in/fade out), or slideToUp (fly in/fly out). If not configured, there is no animation.

  • animationDuration: The animation duration. The default is 1000 ms.

  • animationEasing: The animation curve. You can set this to linear (constant speed), easeInOutQuad (smooth), or easeInOutExpo (slow-fast-slow).

Show

Hide

Update component configuration

Dynamically updates the widget's style configuration.

  1. On the widget's Style panel, click Copy Configuration to Clipboard to get the widget's configuration data.

  2. In the data processing node on the blueprint editor's configuration page, change the field values for the corresponding styles as needed.