0.4.5 • Published 4 days ago

@hopara/iframe v0.4.5

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
4 days ago

Hopara Iframe Client

This package provides an iframe to add Hopara visualizations to your project.

Installing

You can install the iframe as a NPM module or using the Hopara CDN directly:

As a module:

$ npm install @hopara/iframe

Using Hopara CDN:

<script src="https://statics.hopara.app/embedded/latest/client.js"></script>

Authentication

The iframe requires a valid accessToken. Use the Auth API to fetch it, as explained in our integration guide

Example

Node.JS

import React from 'react'
import Hopara from 'hopara'

class MyComponent extends React.Component {
  componentDidMount(): void {
    const hopara = Hopara.init({
      visualizationId: 'my-hopara-viz',
      accessToken: 'my-hopara-token',
      targetElementId: 'my-target-element',
    })
  }

  render() {
    <div id="my-target-element" />
  }
}

HTML

<html>
  <head>
    ...
    <script src="https://statics.hopara.app/embedded/latest/client.js"></script>
    <script>
      document.addEventListener("DOMContentLoaded", function(){
        const hopara = Hopara.init({
          visualizationId: 'my-hopara-viz',
          accessToken: 'my-hopara-token',
          targetElementId: 'my-target-element',
        })
      });
    </script>
  </head>
  <body>
    <div id="my-target-element"></div>
  </body>
</html>

API

Init

The init command starts the Hopara Visualization and returns a hopara instance that can be used to further interactions

const hopara = Hopara.init(config)

Update

Use the update command to update any config passed previously in the init command.

...
const hopara = Hopara.init(config)
hopara.update({accessToken: 'newAccessToken'})
...

Hopara Instance

{
  // When triggered Hopara Visualization will reload every data source on the view
  reload: () => void
}

Hopara Config

{
  // The vizualization
  visualizationId: string

  // The accessToken provided by auth API
  accessToken: string

  // Switch the theme mode to dark scheme (default: false)
  darkMode: boolean | undefined

  // Overwrites data at rendering time
  dataLoaders: DataLoader[] | undefined

  // The initial position to load the visualization
  initialPosition: InitialPosition | undefined

  // The initial row (e.g. asset) to load the visualization
  initialRow: InitialRow | undefined

  // Overrides the map style defined in the visualization studio. See the Map Style section for the available options
  mapStyle: string | undefined

  // Functions called when callback actions are triggered
  callbacks: CallbackFunction[]

Data Loader

By default Hopara will load the same visualization and data as seen as in hopara.app. You can use the data loader prop to provide a custom way to load the data.

type DataLoader = {
  // query name
  query: string

  // data source name
  source: string

  // callback to be used on data load
  loader: (filterSet: {limit: number, offset:number, filters: any[]}) => Promise<Record<string, any>[]>
}

Example

const customDataLoaders = [{
  query: 'queryName',
  source: 'dataSourceName',
  loader: async () => {
    return [
      {
        id: 1,
        name: 'Eiffel Tower',
        country: 'France',
        longitude: 48.85845461500544,
        latitude: 2.294467845588995
      },
      {
        id: 2,
        name: 'Liberty Statue',
        country: 'USA',
        longitude: 40.68815550804761,
        latitude: -74.02620077137483
      },
      {
        id: 3,
        name: 'Great Wall of China',
        country: 'China',
        longitude: 40.43211592595951,
        latitude: 116.57040708445938,
      }
    ]
  }
}]

Hopara.init({
  visualizationId: 'my-hopara-viz',
  accessToken: 'my-hopara-token',
  targetElementId: 'my-target-element',
  dataLoaders: customDataLoaders,
})

Initial Position

The initial position prop overrides the initial position of the visualization.

type InitialPosition = {
  latitude: number | undefined
  longitude: number | undefined
  x: number | undefined
  y: number | undefined
  z: number | undefined
  zoom: number | undefined
  bearing: number | undefined
}

Initial Row

The initial row prop centers the visualization around a specific row (e.g. asset, facility).

type InitialRow = {
  layerId: string
  rowId: string
}

Manual refresh

You can manually trigger a data refresh by calling the refresh method. This will result in all data loaders being called again.

const hopara = Hopara.init({
  visualizationId: 'my-hopara-viz',
  accessToken: 'my-hopara-token',
  targetElementId: 'my-target-element',
})

// force data refresh every 3 seconds
setInterval(() => {
  if (!hopara) return
  hopara.refresh()
}, 3000)

Map Style

In a geo visualization this config overrides the map style defined in the visualization studio.

The available options are 'none', 'building', 'dark', 'light', 'light-street', 'navigation', 'satellite'.

Hopara.init({
  visualizationId: 'my-hopara-viz',
  accessToken: 'my-hopara-token',
  targetElementId: 'my-target-element',
  mapStyle: 'building',
})

Callback Function

You can implement custom interactions by adding callback actions to a layer. When the user selects an object in the visualization and click on the action the registered javascript function will be called with the associated row data.

type CallbackFunction = {
  name: string
  callback: (row) => void
}
Hopara.init({
  visualizationId: 'my-hopara-viz',
  accessToken: 'my-hopara-token',
  targetElementId: 'my-target-element',
  callbacks: [
    {
      name: 'my-callback-action',
      callback: (row) => {
        console.log('Callback triggered', row)
      }
    }
  ],
})
0.4.5

4 days ago

0.4.4

5 days ago

0.4.2

6 days ago

0.4.1

8 days ago

0.3.107

11 days ago

0.3.106

12 days ago

0.3.109

11 days ago

0.3.108

11 days ago

0.3.105

12 days ago

0.3.104

12 days ago

0.3.102

13 days ago

0.3.101

15 days ago

0.3.100

17 days ago

0.3.99

17 days ago

0.3.97

18 days ago

0.3.98

18 days ago

0.3.96-a

23 days ago

0.3.96-b

22 days ago

0.3.96

25 days ago

0.3.95

26 days ago

0.3.94

29 days ago

0.3.93

29 days ago

0.3.92

29 days ago

0.3.91

29 days ago

0.3.90

30 days ago

0.3.89

30 days ago

0.3.88-c

1 month ago

0.3.88-b

1 month ago

0.3.86

1 month ago

0.3.85

1 month ago

0.3.88

1 month ago

0.3.87

1 month ago

0.3.84

1 month ago

0.3.83

1 month ago

0.3.82

1 month ago

0.3.81

2 months ago

0.3.80

2 months ago

0.3.79

2 months ago

0.3.75

2 months ago

0.3.73

2 months ago

0.3.72

2 months ago

0.3.78

2 months ago

0.3.76

2 months ago

0.3.71

2 months ago

0.3.70

2 months ago

0.3.69

2 months ago

0.3.68

2 months ago

0.3.67

2 months ago

0.3.65

2 months ago

0.3.64

2 months ago

0.3.63

2 months ago

0.3.62

2 months ago

0.3.61

2 months ago

0.3.60

2 months ago

0.3.59

2 months ago

0.3.58

2 months ago

0.3.56

2 months ago

0.3.55

2 months ago

0.3.53

2 months ago

0.3.52

2 months ago

0.3.50-1

2 months ago

0.3.51

2 months ago

0.3.49-d

2 months ago

0.3.49-e

2 months ago

0.3.49-b

2 months ago

0.3.49-a

2 months ago

0.3.49-c

2 months ago

0.3.50

3 months ago

0.3.49

3 months ago

0.3.48

3 months ago

0.3.47

4 months ago

0.3.46

4 months ago

0.3.45

5 months ago

0.3.44

5 months ago

0.3.31

8 months ago

0.3.30

8 months ago

0.3.39

6 months ago

0.3.38

6 months ago

0.3.37

6 months ago

0.3.36

6 months ago

0.3.35

6 months ago

0.3.34

7 months ago

0.3.34-a

7 months ago

0.3.32

7 months ago

0.3.34-f

7 months ago

0.3.34-g

7 months ago

0.3.29

8 months ago

0.3.34-k

7 months ago

0.3.20

9 months ago

0.3.27

8 months ago

0.3.41-b

6 months ago

0.3.26

8 months ago

0.3.25

9 months ago

0.3.24

9 months ago

0.3.43-d

5 months ago

0.3.22

9 months ago

0.3.43-c

5 months ago

0.3.21

9 months ago

0.3.19

9 months ago

0.3.18

10 months ago

0.3.9

11 months ago

0.3.16

10 months ago

0.3.31-a

8 months ago

0.3.15

10 months ago

0.3.14

10 months ago

0.3.31-c

8 months ago

0.3.13

10 months ago

0.3.31-b

8 months ago

0.3.10

10 months ago

0.3.42

6 months ago

0.3.41

6 months ago

0.3.40

6 months ago

0.3.42-a

6 months ago

0.3.42-b

6 months ago

0.3.43

6 months ago

0.1.119

1 year ago

0.1.114

1 year ago

0.1.116

1 year ago

0.3.0

12 months ago

0.2.1

12 months ago

0.2.0

1 year ago

0.3.6

11 months ago

0.3.5

11 months ago

0.1.120

1 year ago

0.3.8

11 months ago

0.3.7

11 months ago

0.3.2

11 months ago

0.2.3

12 months ago

0.3.1

12 months ago

0.2.2

12 months ago

0.3.4

11 months ago

0.2.5

12 months ago

0.3.3

11 months ago

0.2.4

12 months ago

0.1.109

1 year ago

0.1.108

1 year ago

0.1.113

1 year ago

0.1.105

1 year ago

0.1.104

1 year ago

0.1.112

1 year ago

0.1.103

2 years ago

0.1.102

2 years ago

0.1.101

2 years ago

0.1.100

2 years ago

0.1.99

2 years ago

0.1.98

2 years ago

0.1.96

2 years ago

0.1.93

2 years ago

0.1.92

2 years ago

0.1.91

2 years ago

0.1.90

2 years ago