publish and subscribe. After embed.js is run (see Embed Components Using JavaScript and Trusted Access), these methods become available for use with the global Zoomdata object on window.
Cross-visual links (channels) are used primarily for cross-visual filtering. Visuals can publish cross-visual filters for cross-visual links. Other visuals can listen (subscribe) to the links and apply them when a cross-visual filter is specified.
Prerequisites
Embedding applications should listen for thecomposer-dashboard-loaded event on the first embedded dashboard before calling these methods. See Embedded Events.
See the following topics:
- Supported Zoomdata Methods
- Supported Cross-Visual Publish JavaScript Properties
- Published Cross-Visual JavaScript Message Structure
- Supported Cross-Visual Subscribe JavaScript Properties
- Embedded Dashboard Cross-Visual Publish and Subscribe Example
Embedded Dashboard Cross-Visual Publish and Subscribe Example
The following JavaScript example uses methods, properties, and embedded events of theZoomdata and EmbedManager classes to publish and subscribe cross-visual links and filters in an embedded dashboard.
Supported Zoomdata Methods
The following methods for the Zoomdata class can be used to manage embedded settings for published and subscribed cross-visual links in a dashboard. Sample code showing the use of these methods in an application are provided. See Embedded Dashboard Cross-Visual Publish and Subscribe Example.
| Method | Description |
|---|---|
publish() | The publish method publishes a message (filter) for a specific cross-source or same-source link (channel). Publishing a link filter causes any subscribing handlers for the link to be called and passed the filter message. There is no registration process for a link, simply call the publish method with a link name and it will be created. No value is returned.The filter message structure is described in Published Cross-Visual JavaScript Message Structure. The properties for the publish method are described in Supported Cross-Visual Publish JavaScript Properties. |
subscribe() | The subscribe method attaches a subscription handler to a cross-source or same-source link (filter). Each time a new cross-visual filter is published to the link, the subscription handler is called and passed the newly published filter.When you call the subscribe method, the unsubscribe function is returned. Run the unsubscribe function to remove the handler for the link. This guarantees that the handler will no longer be notified when new messages are published for the link.Messages passed on the channel can be an arbitrary message object or null. Because the message objects are not restricted, the subscription handler should never assume its structure and always check that the message is in the structure the handler is expecting.Messages that are null are interpreted as a clearing of the channel and should be handled by undoing any actions taken based on the last messages received by the handler. For example, when a visual receives a null message in its filtering logic, it removes any filters created by previous messages on the given channel (link).If a message is published to the channel before the subscribe method is called, the subscription handler is executed immediately with the latest message that was published on the channel.The properties for the subscribe method are described in Supported Cross-Visual Subscribe JavaScript Properties. |
Supported Cross-Visual Publish JavaScript Properties
The properties for thepublish method of the Zoomdata class are described in the following table.
| Property/Object | Description |
|---|---|
<linkName> | The link (channel) name. Link names can be custom names, specified when a cross-source link is created, or names in the format <source-name>.<field-name>, automatically generated for every field in a data source for same-source links.The link name is defined when you define a cross-source link. See Define Cross-Source Links. It is published for use by a dashboard as a cross-visual filter. See Publish a Link. The link name represents the channel into which the message should be published. It is typically called a topic in standard publish/subscribe systems. Type: string |
<message> | The message sent with the link. The message published can either be an arbitrary object or null. An object published to a link channel is not restricted to any particular structure but a Self-Service Analytics dashboard only recognizes messages in the structure described in Published Cross-Visual JavaScript Message Structure. Publishing a null message can clear the last published message from the channel. If the last published message’s publisherId matches the null message’s publisherId, the last message is removed from the channel and subscribers receive a null message. If the publisherId of the last published message on the channel does not match the null message’s publisherId, nothing happens.The most recently published message on each channel is stored and sent to new subscribers at the time of subscription. Type: object or null |
<options> | Options for how the link should be applied. All values are optional. Options include:
Type: object |
Published Cross-Visual JavaScript Message Structure
All messages (cross-visual filters) that can be consumed by Self-Service Analytics or that will be published by Self-Service Analytics must conform to the following structure. The value of thetype property defines the structure of the rest of the message.
The properties for the message (filter) structure are described in the following table:
| Property | Description |
|---|---|
type: 'selection' | Only a value of selection is supported at this time, identifying a selection of values on a visual or widget. This signifies that the message is a SelectionMessage.Type: string |
valueType: 'NUMBER' | Identifies the type of value being selected. The following value types are supported:
Type: string |
ranges | An array of selected ranges. The set of allowed operations depends on the specified valueType. Currently only a single range is supported per message (filter). Ranges after the first range will be ignored. Ranges should be structured as follows:The operation and value properties are described next.Type: array |
operation: 'EQUALS' | The filter operation. Supported operations include:
Type: string |
value: '6' | Provide a value as described for each filter operation.Type: string, number, array<string | number | null> |
Supported Cross-Visual Subscribe JavaScript Properties
The properties for thesubscribe method of the Zoomdata class are described in the following table.
| Property/Object | Description |
|---|---|
<linkName> | The link (channel) name to which the subscription handler should subscribe. The link name is defined when you define a cross-source link. See Define Cross-Source Links. It is published for use by a dashboard as a cross-visual filter. See Publish a Link. The link name represents the channel from which the message should be subscribed. It is typically called a topic in standard publish/subscribe systems. Type: string |
subscriptionHandler | The handler that will be called upon new messages. This handler will be provided with the published message as the first argument and the ID of the publisher as the second argument. Type: function |