Hello,
hope all is well.
I am trying to embed the widget code in react. Some help and examples would help.
I keep getting prompted with:
Line 2:16: 'dataSourceWidget' is not defined no-undef
This is the full code that I am embedding into on of my react components:
<script src="https://cdn.jsdelivr.net/npm/vega@5.19.1"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@5.0.0"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6.15.1"></script>
<script src="https://cdn.jsdelivr.net/gh/bitquery/widgets-runtime@v1.0/dataSource.js"></script>
<div style="width: 500px; height: 500px; overflow-y: hidden; " id="s6vT76tTyzL"></div>
<script>
let ds = new dataSourceWidget(`
query ($network: BitcoinNetwork!,
$dateFormat: String!,
$from: ISO8601DateTime,
$till: ISO8601DateTime){
bitcoin(network: $network ){
transactions(options:{asc: "date.date"}, date: {
since: $from
till: $till}
) {
date: date{
date(format: $dateFormat)
}
count: countBigInt
feeValue
avgFee: feeValue(calculate: average)
}
}
}`, {"limit":10,"offset":0,"network":"bitcoin","from":"2022-07-18","till":"2022-07-25T23:59:59","dateFormat":"%Y-%m-%d"}, `bitcoin.transactions`, 'BQY3gTGqa8DtHsDVO4nF3JYmcfvGtSKQ')
async function barWidgetRenderer(ds, config, el) {
let values = undefined
if (!ds.values) {
const data = await ds.fetcher()
const json = await data.json()
values = ds.setupData(json)
} else {
values = ds.values
}
let cfg = {
$schema: 'https://vega.github.io/schema/vega-lite/v4.json',
description: 'A simple bar chart with embedded data.',
width: "container",
height: "container",
mark: {"type": "bar", "tooltip": true},
selection: {
highlight: {
type: "single",
empty: "none",
on: "mouseover"
}
},
...config,
data: {
values
}
}
try {
vegaEmbed(`#${el}`, cfg, {actions: false})
} catch (error) {
console.log(error)
}
}
const config = {"transform":[{"sample":1000}],"encoding":{"x":{"field":"date.date","type":"ordinal","sort":null},"y":{"field":"count","type":"quantitative"},"stroke":{"condition":{"selection":"highlight","value":"#000"}}}}
barWidgetRenderer(ds, config, 's6vT76tTyzL')
</script>
Thanks