Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zazuko/d3-sparql
Query a SPARQL endpoint with a SELECT query and get the data ready to be used with d3js
https://github.com/zazuko/d3-sparql
d3js json rdf sparql triplestore
Last synced: 2 months ago
JSON representation
Query a SPARQL endpoint with a SELECT query and get the data ready to be used with d3js
- Host: GitHub
- URL: https://github.com/zazuko/d3-sparql
- Owner: zazuko
- License: bsd-3-clause
- Created: 2017-07-22T13:45:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-10T08:00:54.000Z (over 5 years ago)
- Last Synced: 2024-09-05T08:49:08.867Z (4 months ago)
- Topics: d3js, json, rdf, sparql, triplestore
- Language: JavaScript
- Homepage:
- Size: 102 KB
- Stars: 116
- Watchers: 9
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-d3 - d3-sparql - Utility for accessing data from SPARQL Endpoints (Utils)
- awesome-d3 - d3-sparql - Utility for accessing data from SPARQL Endpoints (Utils)
- awesome-d3 - d3-sparql - Utility for accessing data from SPARQL Endpoints (Utils)
README
# d3-sparql
This module lets you request data from [SPARQL](https://www.w3.org/TR/sparql11-query/) [endpoints](https://www.w3.org/wiki/SparqlEndpoints) in the vein of [d3-csv](https://github.com/d3/d3-dsv) and friends. It is generating a JSON structure from SPARQL query results, you can use that in any way you like in your code, with or without D3.
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](https://www.youtube.com/watch?v=FvGndkpa4K0)). Ultimately it keeps visualizations up to date. Think of SPARQL endpoints as the most flexible API imaginable.
Define the SPARQL query and endpoint:
```js
// 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:
```js
d3.sparql(wikidataUrl, mikeQuery).then((data) => {
console.log(data); // [{'developerName': 'Mike Bostock'}]
})
```More [examples](https://github.com/zazuko/d3-sparql/tree/master/examples) are provided in the [repository](https://github.com/zazuko/d3-sparql).
## Features
- Transformation of [XSD Datatypes](https://www.w3.org/2011/rdf-wg/wiki/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`. You can also use a CDN, for instance .
See [CHANGELOG](CHANGELOG.md) for details about available versions.
## API Reference
This package adds a `sparql` function to the global `d3` object: `d3.sparql(endpoint, query, options = {})`.
# d3. sparql (endpoint, query[, options = {}]) [<>](https://github.com/zazuko/d3-sparql/blob/master/src/sparql.js#L8 "Source")
`options` is an optional object that will get merged with the second argument of [`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch).
```js
d3.sparql(endpoint, query)
.then((data) => …);
```## Acknowledgement
The initial development of this library by [Zazuko](http://www.zazuko.com) was supported by the [City of Zürich](https://www.stadt-zuerich.ch/).