npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hopara/iframe

v2.2.20-b

Published

This package provides an iframe to add [Hopara](https://hopara.io) visualizations to your project.

Downloads

765

Readme

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

  // Short-lived token provided by Auth API used for authentication in API calls
  accessToken: string

  // Long-lived token used to obtain a new accessToken when the current one expires.
  refreshToken: string | undefined

  // 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

  // The filters to be added on data fetches
  filters: Filter[] | 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)

Filter

When adding a filter, the field name is handled as a dimension in Hopara.

Hopara.init({
  visualizationId: 'my-hopara-viz',
  accessToken: 'my-hopara-token',
  targetElementId: 'my-target-element',
  filters: [
    {
      field: 'type',
      values: ['REFRIGERATOR', 'FREEZER'],
    }
  ],
})

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)
      }
    }
  ],
})