Skip to main content
Public

Share visualization

Loading preview…

ICE 8 Araib

vizhub.com

Shared links may look like this on X, LinkedIn, Slack, and Discord.

Before sharing, review the publishing checklist.

Choose how to deliver this visualization

LinkedIn caption

LinkedIn may not keep text supplied by the share sheet. Copy the caption and paste it into the post if needed. You can tag the VizHub company page when posting.

More options

Embed on a websiteCopy iframe embed code
Download & exportPNG, HTML, source ZIP

ICE 8 Araib

0
SSyed Araib Karim
Last edited Apr 4, 2022
Created on Apr 3, 2022
Forked from Hello Package.json

This example displays a world map using the Natural Earth projection, coloring each country with a purple fill on a blue background. It loads geographic data from the `world-atlas` TopoJSON file, converts it to GeoJSON using `topojson.feature`, and renders the paths with `d3.geoPath` projected through `d3.geoNaturalEarth1`. The SVG also includes a sphere outline, and countries change color on hover via CSS. D3 v5 and v7 code coexist, with React dependencies declared but unused.

AI-generated description

An first example of VizHub's new package.json features.

Wait, what!?

That's right! You can now use package.json in VizHub. It's a way to declare your dependencies. If you use this, there's no longer any need to add any <script> tags yourself to index.html. VizHub will automatically append these when the page runs, based on the dependencies defined in package.json. To be clear, the dependencies are not included in the bundle. They are still pulled in from a CDN.

Because dependencies are pulled in from a CDN via <script> tags, and those tags introduce browser globals that define the packages, VizHub somehow needs to know how to resolve package names (like the 'react' part of import React from 'react') to browser globals (such as window.React). To date, this mapping has been defined in vizhub-libraries, which is a big list of mappings. This approach is not ideal, because if a library is not on that list, you can't use it with ES6 import syntax. But all that is about to change.

To support usage of any package with ES6 import syntax, we've added a special vizhub.libraries field in package.json. This field lets you define the mappings from package names to browser globals yourself. Also, since the CDN path to the browser build is sometimes not at the package root, and can be different for each package (and there's no way of knowing programmatically what it is), you can also specify what path to use.

You can also specify a custom license in the license field of package.json. This field is expected to be a valid SPDX license identifier, as described in the NPM Package.json documentation. If a license field is not present, the default MIT License is used.

Here's an example:

<iframe height="450" width="100%" src="https://vizhub.com/curran/161a5fcfe2e148f583cc75efb8ab3255?mode=snippet&file=package.json#" title="Hello Package.json" frameborder="0" ></iframe>

In the above example, the vizhub.libraries field specifies the global and path for react and react-dom. For React, the global tells VizHub to resolve the 'react' package to window.React, and the path field tells VizHub to append /umd/react-dom.production.min.js to the CDN path used in the <script> tag that pulls in the library. The CDN paths used are of the form https://unpkg.com/${name}@${version}${path}.

By the way, the above snippet is embedded using VizHub's snippet embed feature.

Comments

Sign in to join the discussion.

ISC Licensed