Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d3-sparql

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-sparql

Queries a SPARQL endpoint with a SELECT query

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

d3-sparql

This module lets you request data from SPARQL endpoints in the vein of d3-csv and friends. The access through a SPARQL endpoint allows a faster and more efficient data preparation (once you got the hang of SPARQL and the RDF data model). Ultimately it keeps visualizations up to date. Think of SPARQL endpoints as the most flexible API imaginable.

Define the SPARQL query and endpoint:

// Author of Q3011087 (D3.js)
var mikeQuery = `SELECT ?developerName WHERE {
  wd:Q3011087 wdt:P178 ?developer.
  ?developer rdfs:label ?developerName.
  FILTER(LANG(?developerName) = 'en')
}`

wikidataUrl = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql'

To query the endpoint and get the result:

d3.sparql(wikidataUrl, mikeQuery).then((data) => {
  console.log(data); // [{'developerName': 'Mike Bostock'}]
})

More examples are provided in the repository.

Features

  • Transformation of XSD Datatypes (e.g. xsd:dateTime, xsd:boolean, ...) to native JavaScript types.
  • Reformatting of the JSON Structure to a d3 style layout while using the provided variables names of the SPARQL Query.

Limitations

  • Only SELECT queries are supported. (This provides a projection of the graph data onto a table structure used by d3.)
  • Currently only supports endpoints which are able to respond with application/sparql-results+json.

Installing

Using NPM: npm install d3-sparql. Otherwise, download the latest release or use a CDN, for instance https://www.jsdelivr.com.

API Reference

This package add a sparql function to the global d3 object: d3.sparql(endpoint, query, options = {}).

# d3. sparql (endpoint, query[, options = {}]) <>

options is an optional object that will get merged with the second argument of fetch().

d3.sparql(endpoint, query)
  .then((data) => …);

Acknowledgement

The initial development of this library by Zazuko was supported by the City of Zürich.

Keywords

FAQs

Package last updated on 03 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc