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

zoomdata-client

v23.4.12

Published

Zoomdata Standalone Web Client (SDK)

Downloads

426

Readme

Zoomdata Javascript SDK

[DEPRECATED]

This package is deprecated since Composer 7.10 release and will not be maintained starting 8.0. It is recommended to use Embed Manager as a replacement.


Trusted Access Tokens

The Zoomdata Javascript SDK requires a user's trusted access token to connect to a Zoomdata Server. For information on Trusted Access, its prerequisites, and generating user based tokens, please visit the Trusted Access Documentation

Install the library

npm install zoomdata-client

zoomdata-client comes built as an UMD. You are able to use it both in a browser from node_modules:

<script src="node_modules/zoomdata-client/sdk/zoomdata-client.js" type="text/javascript"></script>

or in a browser served from your Zoomdata server (update the URL accordingly):

<script src="https://localhost:8443/composer/sdk/zoomdata-client.js" type="text/javascript"></script>

or as a commonJS module:

var ZoomdataSDK = require('zoomdata-client');

Create a Client

When instantiating a Zoomdata JS client, you need to supply connection properties as well as an authentication trusted access token. The .createClient function returns a Javascript Promise that resolves to the client.

var credentials = {
    access_token: TRUSTED_ACCESS_TOKEN,
};

var application = {
    secure: false,
    host: 'localhost',
    port: 8080,
    path: '/composer',
};

ZoomdataSDK.createClient({
    credentials: credentials,
    application: application,
}).then(function (client) {
    console.log('Validated:', client);
});

Create a Query

When creating a Query, you need to supply a Data Source name as well as a query configuration.

The .createQuery function returns a Javascript Promise that resolves to the validated Query.

client.createQuery(
    { id: 'source_id' },
    {
        filters: [],
        groups: [
            {
                name: 'userincome',
                limit: 10,
                sort: {
                    dir: 'asc',
                    name: 'userincome',
                },
            },
        ],
        metrics: [],
    },
);

Query Configuration Details

A Query can be Grouped or Ungrouped.

An Ungrouped Query only requires an array of fields. This configuration will return all records with just the userincome and usergender fields.

{
    fields: ['userincome, usergender'];
}

A Grouped Query requires an array of Groupings. Optionally, you can include an array of Metrics. This configuration will group by the userincome field and calculate the average of the usersentiment field.

{
    groups: [{
        name: 'userincome',
        limit: 10,
        sort: {
            dir: 'asc',
            name: 'usergender'
        }
    }],
    metrics: [{
        name: 'usersentiment',
        func: 'avg'
    }]
}

All Queries can include an optional array of filters. This configuration will filter only results with a usersentiment between -0.5 and 0.5.

{
    filters: [
        {
            path: 'usersentiment',
            operation: 'BETWEEN',
            value: [-0.5, 0.5],
        },
    ];
}

Run a Query

When running a Query, you must provide a callback that receives new data as it arrives from the Zoomdata Server.

client.runQuery(query, function (data) {
    console.log(data);
});

Embed a Chart

When embedding a Chart, you must provide an HTML element to embed the chart into, a query to run for the chart, the name of the visualization, and an object for overriding Chart Variables.

Note: You can find variable names and values in your Zoomdata Server's Source Configuration Page.

var variables = {
    Size: 'count',
};

client.visualize({
    element: document.body,
    query: query,
    visualization: 'Donut',
    variables: variables,
});

Example

var credentials = {
    access_token: TRUSTED_ACCESS_TOKEN,
};

var application = {
    secure: false,
    host: 'localhost',
    port: 8080,
    path: '/zoomdata',
};

var variables = {
    Size: [{ name: 'count' }],
};

ZoomdataSDK.createClient({
    credentials: credentials,
    application: application,
})
    .then(function (client) {
        client
            .createQuery(
                { name: 'Real Time Sales' },
                {
                    filters: [],
                    groupBy: [
                        {
                            name: 'userincome',
                            limit: 10,
                        },
                    ],
                    metrics: [],
                },
            )
            .then(function (query) {
                client.runQuery(query, function (data) {
                    console.log(data);
                });

                client
                    .visualize({
                        element: document.body,
                        query: query,
                        visualization: 'Donut',
                        variables: variables,
                    })
                    .catch(onError);
            })
            .catch(onError);
    })
    .catch(onError);

function onError(reason) {
    console.error(reason.stack || reason.statusText || reason);
}

Licensing

Zoomdata Javascript SDK is licensed under the terms of the Zoomdata EULA.

See the LICENSE file for further information.