Skip to main content

Advanced Usage

Widget Functions

Once initialised, the widget emits interactive events that can be called by your site using global functions

The following are the functions emitted by the widget.

FunctionDescription
functionMap_getGraphDataOn load, this function will be called supplied with the graph data in this listed structure
functionMap_getSelectedEntityIdOn click of any entity in the graph, this function will be called supplied with the id of the respective entity
functionMap_getSelectedRelationshipIdOn click of any relationship in the graph, this function will be called supplied with the id of the respective relationship

Add Global Function names to the Widget Props

widget-props.js
const widgetProps = {
key: CLIENT_KEY,
parentElementSelector: ELEMENT_SELECTOR,

// Add these to your Widget Props
functionMap_getGraphData: "hswidget_handleShowGraphData",
functionMap_getSelectedEntityId: "hswidget_handleShowEntityId",
functionMap_getSelectedRelationshipId: "hswidget_handleShowRelationshipId",
};

Replace hswidget_handleShowGraphData, hswidget_handleShowEntityId and hswidget_handleShowRelationshipId with the name of your global functions. Having a prefix of hswidget_ is recommended.

Create your Global Functions

index.html
<html>
<head></head>
<body>
<script type="module">
import { widgetProps } from "./src/data/widget-props.js";

const graphData = document.getElementById("graphData");
const entity = document.getElementById("entity");
const relationship = document.getElementById("relationship");

window.hswidget_handleShowGraphData = function (data) {
graphData.innerText = data.graphType;
};

window.hswidget_handleShowGraphData = function (id) {
entity.innerText = id;
};

window.hswidget_handleShowGraphData = function (id) {
relationship.innerText = id;
};

/* ... widget initialisation script */
</script>

<div>
<div id="hsWidget"></div>
<ul>
<li id="graphData"></li>
<li id="entity"></li>
<li id="relationship"></li>
</ul>
</div>
</body>
</html>

Updating the Graph Visualisation using Widget Methods

widget-update-demo.js
import {
GraphData,
WidgetProps,
WidgetParametersEndpointData,
HSWidget,
} from "./types";

const widgetProps: WidgetProps = {
key: "client-key-001",
parentElementSelector: "#hs-graphs",
};

const widgetParametersRadial: WidgetParametersEndpointData = {
graphType: "radial",
datasets: ["CM"],
entities: [{ dataset: "CM", entityId: "xyz-001" }],
degree: 1,
};

const widgetParametersInterconnect: WidgetParametersEndpointData = {
graphType: "interconnect",
datasets: ["CM"],
entities: [
{ dataset: "CM", entityId: "xyz-001" },
{ dataset: "CM", entityId: "aaa-999" },
],
degree: 2,
};

// ... Widget Initialisation script

const widget = new hs_widget(widgetProps);

// use the drawGraphWithEndpointData method to generate a radial graph using API data
widget.drawGraphWithEndpointData(widgetParametersRadial);

// ... some logic before calling an update to the graph visualisation

// update the graph to an interconnect graph
widget.updateGraphWithEndpointData(widgetParametersInterconnect);