How to add a tooltip to a d3.js path? - vue.js

I am building a floormap from geojson data using d3.js topo and d3.js path. For clarification, I am also using vue.js. I want to add a tooltip when the user hovers over a room (aka the d3.js path). First I added just a console log to when the user hovers over a path but that did not work. I noticed that every time I load the app it does a console log but not when a user clicks / hovers over the d3.js path. I heard someone say that I would have to create an invisible circle or rectangle which would have the tooltip property bind to it but I don't think that route would work once the floor maps get complex. I dont care about adding any actual data to the tooltip right now but later I would want to. Can someone point me in the right direction, please? Thank you.
const data = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
0, 0
],
[
0, 11.4
],
[
7, 11.4
],
[
7, 0
],
[
0, 0
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
7, 0
],
[
7, 11.4
],
[
12, 11.4
],
[
12, 0
],
[
7, 0
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
12, 0
],
[
12, 11.4
],
[
19, 11.4
],
[
19, 0
],
[
12, 0
]
]
]
}
}
]
};
var svg = d3.select("svg")
var width = +svg.attr("width")
var height = +svg.attr("height")
svg.attr("transform", "translate(" + width / 2 + ",0)")
var projection = d3.geoIdentity().fitSize([width, height], data)
var path = d3.geoPath(projection)
svg.selectAll("path")
.data(data.features)
.enter()
.append("path")
.attr("d", path)
.attr("fill", "grey")
.attr("fill-opacity", .2)
.attr("stroke", "black")
.attr("stroke-width", 1.5)
.on("mouseover", console.log("hello"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<svg width="400" height="200"></svg>

There are several ways to do this. The simplest - but most limited - one is to create a <title> element in each path. It will show on hover, as it's browser native.
const data = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": { "name": "Kitchen" },
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
0, 0
],
[
0, 11.4
],
[
7, 11.4
],
[
7, 0
],
[
0, 0
]
]
]
}
},
{
"type": "Feature",
"properties": { "name": "Living room" },
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
7, 0
],
[
7, 11.4
],
[
12, 11.4
],
[
12, 0
],
[
7, 0
]
]
]
}
},
{
"type": "Feature",
"properties": { "name": "Toilet" },
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
12, 0
],
[
12, 11.4
],
[
19, 11.4
],
[
19, 0
],
[
12, 0
]
]
]
}
}
]
};
var svg = d3.select("svg")
var width = +svg.attr("width")
var height = +svg.attr("height")
svg.attr("transform", "translate(" + width / 2 + ",0)")
var projection = d3.geoIdentity().fitSize([width, height], data)
var path = d3.geoPath(projection)
svg.selectAll("path")
.data(data.features)
.enter()
.append("path")
.attr("d", path)
.attr("fill", "grey")
.attr("fill-opacity", .2)
.attr("stroke", "black")
.attr("stroke-width", 1.5)
.append("title")
// Do this to maintain access to the features you drew
.datum(function(d) { return d; })
.text(function(d) {
return d.properties.name;
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<svg width="400" height="200"></svg>
More complicated ones can use an absolutely positioned div, for example:
const data = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"name": "Kitchen"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
0, 0
],
[
0, 11.4
],
[
7, 11.4
],
[
7, 0
],
[
0, 0
]
]
]
}
},
{
"type": "Feature",
"properties": {
"name": "Living room"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
7, 0
],
[
7, 11.4
],
[
12, 11.4
],
[
12, 0
],
[
7, 0
]
]
]
}
},
{
"type": "Feature",
"properties": {
"name": "Toilet"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
12, 0
],
[
12, 11.4
],
[
19, 11.4
],
[
19, 0
],
[
12, 0
]
]
]
}
}
]
};
var svg = d3.select("svg")
var width = +svg.attr("width")
var height = +svg.attr("height")
var tooltip = d3.select("#tooltip")
svg.attr("transform", "translate(" + width / 2 + ",0)")
var projection = d3.geoIdentity().fitSize([width, height], data)
var path = d3.geoPath(projection)
svg.selectAll("path")
.data(data.features)
.enter()
.append("path")
.attr("d", path)
.attr("fill", "grey")
.attr("fill-opacity", .2)
.attr("stroke", "black")
.attr("stroke-width", 1.5)
.on("mousemove", function(d) {
// +3 as some offset to make sure spawning the tooltip doesn't
// accidentally also cause unhover and thus removing itself
tooltip
.html(d.properties.name)
.style("display", "block")
.style("left", d3.event.x + 3 + 'px')
.style("top", d3.event.y + 3 + 'px');
})
.on("mouseleave", function() {
tooltip
.style("display", null)
.style("left", null)
.style("top", null);
});
#tooltip {
position: absolute;
top: 0;
left: 0;
display: none;
border: solid 1px red;
padding: 5px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<svg width="400" height="200"></svg>
<div id="tooltip"></div>

Related

Rendering mpld3 JSON chart in React

Good day.
I just recently came across mpld3 and I am trying to see if it will be the solution to my issue.
I want to create Matplotlib charts in Python, save them as JSON objects to a database, and then render them in my React webpage.
So far I have created a plot in Python, using Matplotlib and converted it to a JSON object in a dictionary:
fig = plt.gcf()
mpld3.display(fig)
fig_to_dict = mpld3.fig_to_dict(fig)
Now I can save the dictionary to a file.
My question is: Can I then render this JSON chart in my React project? And if so, how do I do that?
Another thing is - I cannot use D3 in the front-end, I need to do all my "chart making" in the back-end.
Thank you for any and all assistance!
This is not a perfect answer, but I seemed to be solving a similar problem and I appear to have got it working so am sharing my code as is. Hopefully it will prove useful to someone.
This is my react component ('matPlotLibFig.js') that renders a simple figure
import React from 'react'
import mpld3_load_lib from "./mpld3_load_lib";
import mpld3 from 'mpld3'
import _json from "./plot_b.json"
const MatPlotLibFig = () => {
const fig_name = "fig_el427345810798888193429725"
return <div>
<script>
mpld3_load_lib("https://d3js.org/d3.v5.js", function () {
mpld3_load_lib("https://mpld3.github.io/js/mpld3.v0.5.8.js", function () {
mpld3.remove_figure(fig_name)
mpld3.draw_figure(fig_name, _json);
})
});
</script>
<div id={fig_name}></div>
</div>
}
export default MatPlotLibFig
plot_b.json:
{
"width": 640.0,
"height": 480.0,
"axes": [
{
"bbox": [0.125, 0.11, 0.775, 0.77],
"xlim": [-0.5, 10],
"ylim": [0, 10],
"xdomain": [-0.2, 10],
"ydomain": [0.0, 10],
"xscale": "linear",
"yscale": "linear",
"axes": [
{
"position": "bottom",
"nticks": 11,
"tickvalues": null,
"tickformat_formatter": "",
"tickformat": null,
"scale": "linear",
"fontsize": 10.0,
"grid": {
"gridOn": false
},
"visible": true
},
{
"position": "left",
"nticks": 11,
"tickvalues": null,
"tickformat_formatter": "",
"tickformat": null,
"scale": "linear",
"fontsize": 10.0,
"grid": {
"gridOn": false
},
"visible": true
}
],
"axesbg": "#FFFFFF",
"axesbgalpha": null,
"zoomable": true,
"id": "el91906139874005984112",
"lines": [
{
"data": "data01",
"xindex": 0,
"yindex": 1,
"coordinates": "data",
"id": "el91906139873968544448",
"color": "#000000",
"linewidth": 1.5,
"dasharray": "none",
"alpha": 1,
"zorder": 2,
"drawstyle": "default"
}
],
"paths": [],
"markers": [
{
"data": "data01",
"xindex": 0,
"yindex": 1,
"coordinates": "data",
"id": "el91906139873968544448pts",
"facecolor": "#000000",
"edgecolor": "#FFFFFF",
"edgewidth": 5,
"alpha": 1,
"zorder": 2,
"markerpath": [
[
[
-10.0,
10.0
],
[
10.0,
10.0
],
[
10.0,
-10.0
],
[
-10.0,
-10.0
]
],
[
"M",
"L",
"L",
"L",
"Z"
]
]
}
],
"texts": [],
"collections": [],
"images": [],
"sharex": [],
"sharey": []
}
],
"data": {
"data01": [
[
0.0,
6.0
],
[
1.0,
2.0
],
[
2.0,
8.0
],
[
3.0,
3.0
],
[
4.0,
0.0
],
[
5.0,
7.0
]
]
},
"id": "el91906139874196422128",
"plugins": [
{
"type": "reset"
},
{
"type": "zoom",
"button": true,
"enabled": false
},
{
"type": "boxzoom",
"button": true,
"enabled": false
}
]
}
mpld3_load_lib.js:
const mpld3_load_lib = (url, callback) => {
var s = document.createElement('script');
s.src = url;
s.async = true;
s.onreadystatechange = s.onload = callback;
s.onerror = function () { console.warn("failed to load library " + url); };
document.getElementsByTagName("head")[0].appendChild(s);
}
export default mpld3_load_lib
Which renders a dynamic plot that looks like

Ramda - How to filter array with other array and multiple properties

I am trying to filter one array with another array using Ramda.
This is an array of edges for ELK algorithm. sources and targets are arrays but in this case, those arrays have always single value.
const edges = [
{
"id": "47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada#2789a940-15d1-4ff0-b2ef-9f6cde676c18",
"sources": [
"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada"
],
"targets": [
"2789a940-15d1-4ff0-b2ef-9f6cde676c18"
]
},
{
"id": "47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada#7cf88eab-5da4-492b-839c-30916fa98fb9",
"sources": [
"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada"
],
"targets": [
"7cf88eab-5da4-492b-839c-30916fa98fb9"
]
},
{
"id": "fefd95e0-11d0-44f6-9b48-ec2a0ea1b328#53a6d558-c97b-42df-af69-cf27912dd158",
"sources": [
"fefd95e0-11d0-44f6-9b48-ec2a0ea1b328"
],
"targets": [
"53a6d558-c97b-42df-af69-cf27912dd158"
]
}
]
This is an example of a second array that I would like to use to filter values from the first one - id corresponds to the value in sources and outgoingNodeId corresponds to the value in targets from the first array.
const selectedNodes = [
{
"id": "47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada",
"outgoingNodeId": "2789a940-15d1-4ff0-b2ef-9f6cde676c18",
"groupId": "27",
"sectionId": "0e09e7dd-0f71-48a1-a843-36d8e85574b3"
},
{
"id": "fefd95e0-11d0-44f6-9b48-ec2a0ea1b328",
"outgoingNodeId": "53a6d558-c97b-42df-af69-cf27912dd158",
"groupId": "27",
"sectionId": "0e09e7dd-0f71-48a1-a843-36d8e85574b3"
}
]
In this case, result should look like this:
const result = [
{
"id": "47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada#2789a940-15d1-4ff0-b2ef-9f6cde676c18",
"sources": [
"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada"
],
"targets": [
"2789a940-15d1-4ff0-b2ef-9f6cde676c18"
]
},
{
"id": "fefd95e0-11d0-44f6-9b48-ec2a0ea1b328#53a6d558-c97b-42df-af69-cf27912dd158",
"sources": [
"fefd95e0-11d0-44f6-9b48-ec2a0ea1b328"
],
"targets": [
"53a6d558-c97b-42df-af69-cf27912dd158"
]
}
]
I tried few things but to be honest I don't have anything worth showing here.
My last try was around:
R.pipe(
R.groupBy(R.prop('sources'))
)(edges)
And then filtering using R.filter(R.compose(R.flip(R.contains)(selectedNodesIds), R.prop('id')))
But I need to filter not only sources but also targets
Any help would be appreciated. Thank you
EDIT:
Another example for a different approach:
const edges = [
{
"id": "47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada#2789a940-15d1-4ff0-b2ef-9f6cde676c18",
"sources": [
"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada"
],
"targets": [
"2789a940-15d1-4ff0-b2ef-9f6cde676c18"
]
},
{
"id": "47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada#7cf88eab-5da4-492b-839c-30916fa98fb9",
"sources": [
"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada"
],
"targets": [
"7cf88eab-5da4-492b-839c-30916fa98fb9"
]
},
{
"id": "fefd95e0-11d0-44f6-9b48-ec2a0ea1b328#53a6d558-c97b-42df-af69-cf27912dd158",
"sources": [
"fefd95e0-11d0-44f6-9b48-ec2a0ea1b328"
],
"targets": [
"53a6d558-c97b-42df-af69-cf27912dd158"
]
},
...multipleObjectsHere
]
selectedNodes contains only one object:
const selectedNodes = [
{
"id": "47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada",
"outgoingNodeId": "2789a940-15d1-4ff0-b2ef-9f6cde676c18",
"groupId": "27",
"sectionId": "0e09e7dd-0f71-48a1-a843-36d8e85574b3"
}
]
As a result, we get:
const result = [
{
"id": "47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada#2789a940-15d1-4ff0-b2ef-9f6cde676c18",
"sources": [
"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada"
],
"targets": [
"2789a940-15d1-4ff0-b2ef-9f6cde676c18"
]
},
{
"id": "fefd95e0-11d0-44f6-9b48-ec2a0ea1b328#53a6d558-c97b-42df-af69-cf27912dd158",
"sources": [
"fefd95e0-11d0-44f6-9b48-ec2a0ea1b328"
],
"targets": [
"53a6d558-c97b-42df-af69-cf27912dd158"
]
},
...multipleObjectsHere
]
To sum up, if something is not in selectedNodes we don't filter it out and leave it as a result
Use R.innerJoin to create an intersection between 2 arrays using a comparison function:
const { innerJoin, includes } = R
const fn = innerJoin(({ sources, targets }, { id, outgoingNodeId }) =>
includes(id, sources) && includes(outgoingNodeId, targets)
)
const edges = [{"id":"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada#2789a940-15d1-4ff0-b2ef-9f6cde676c18","sources":["47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada"],"targets":["2789a940-15d1-4ff0-b2ef-9f6cde676c18"]},{"id":"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada#7cf88eab-5da4-492b-839c-30916fa98fb9","sources":["47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada"],"targets":["7cf88eab-5da4-492b-839c-30916fa98fb9"]},{"id":"fefd95e0-11d0-44f6-9b48-ec2a0ea1b328#53a6d558-c97b-42df-af69-cf27912dd158","sources":["fefd95e0-11d0-44f6-9b48-ec2a0ea1b328"],"targets":["53a6d558-c97b-42df-af69-cf27912dd158"]}]
const selectedNodes = [{"id":"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada","outgoingNodeId":"2789a940-15d1-4ff0-b2ef-9f6cde676c18","groupId":"27","sectionId":"0e09e7dd-0f71-48a1-a843-36d8e85574b3"},{"id":"fefd95e0-11d0-44f6-9b48-ec2a0ea1b328","outgoingNodeId":"53a6d558-c97b-42df-af69-cf27912dd158","groupId":"27","sectionId":"0e09e7dd-0f71-48a1-a843-36d8e85574b3"}]
const result = fn(edges, selectedNodes)
console.log(result)
.as-console-wrapper { max-height: 100% !important; top: 0; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.28.0/ramda.min.js" integrity="sha512-t0vPcE8ynwIFovsylwUuLPIbdhDj6fav2prN9fEu/VYBupsmrmk9x43Hvnt+Mgn2h5YPSJOk7PMo9zIeGedD1A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
The other logic should be see if the id is included in sources. If it is also check the outgoingNodeId. If not, return true.
const { innerJoin, includes } = R
const fn = innerJoin(({ sources, targets }, { id, outgoingNodeId }) =>
!includes(id, sources) || includes(outgoingNodeId, targets)
)
const edges = [{"id":"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada#2789a940-15d1-4ff0-b2ef-9f6cde676c18","sources":["47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada"],"targets":["2789a940-15d1-4ff0-b2ef-9f6cde676c18"]},{"id":"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada#7cf88eab-5da4-492b-839c-30916fa98fb9","sources":["47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada"],"targets":["7cf88eab-5da4-492b-839c-30916fa98fb9"]},{"id":"fefd95e0-11d0-44f6-9b48-ec2a0ea1b328#53a6d558-c97b-42df-af69-cf27912dd158","sources":["fefd95e0-11d0-44f6-9b48-ec2a0ea1b328"],"targets":["53a6d558-c97b-42df-af69-cf27912dd158"]}]
const selectedNodes = [{"id":"47c0ffd2-6a2c-4e7f-9fd9-0e1207225ada","outgoingNodeId":"2789a940-15d1-4ff0-b2ef-9f6cde676c18","groupId":"27","sectionId":"0e09e7dd-0f71-48a1-a843-36d8e85574b3"}]
const result = fn(edges, selectedNodes)
console.log(result)
.as-console-wrapper { max-height: 100% !important; top: 0; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.28.0/ramda.min.js" integrity="sha512-t0vPcE8ynwIFovsylwUuLPIbdhDj6fav2prN9fEu/VYBupsmrmk9x43Hvnt+Mgn2h5YPSJOk7PMo9zIeGedD1A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

Amazon Athena returning `HIVE_CURSOR_ERROR: HIVE_CURSOR_ERROR` on geo json

I'm trying to read a geojson file using Amazon Athena.
The head of my input data looks like this:
{
"type": "FeatureCollection",
"name": "sql_statement",
"features": [
{ "type": "Feature", "properties": { "gridsize": 500.0, "big_gid": 353, "little_gid": 22482 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -981739.267883020918816, 30855.609566356935829 ], [ -981739.267883020918816, 31355.354737498135364 ], [ -981241.022986860014498, 31355.354737498135364 ], [ -981241.022986860014498, 30855.609566356935829 ], [ -981739.267883020918816, 30855.609566356935829 ] ] ] } },
{ "type": "Feature", "properties": { "gridsize": 500.0, "big_gid": 353, "little_gid": 22483 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -981241.022986860014498, 30855.609566356935829 ], [ -981241.022986860014498, 31355.354737498135364 ], [ -980742.778090699226595, 31355.354737498135364 ], [ -980742.778090699226595, 30855.609566356935829 ], [ -981241.022986860014498, 30855.609566356935829 ] ] ] } },
{ "type": "Feature", "properties": { "gridsize": 500.0, "big_gid": 353, "little_gid": 22484 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -980742.778090699226595, 30855.609566356935829 ], [ -980742.778090699226595, 31355.354737498135364 ], [ -980244.533194538322277, 31355.354737498135364 ], [ -980244.533194538322277, 30855.609566356935829 ], [ -980742.778090699226595, 30855.609566356935829 ] ] ] } },
{ "type": "Feature", "properties": { "gridsize": 500.0, "big_gid": 353, "little_gid": 22485 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -980244.533194538322277, 30855.609566356935829 ], [ -980244.533194538322277, 31355.354737498135364 ], [ -979746.288298377417959, 31355.354737498135364 ], [ -979746.288298377417959, 30855.609566356935829 ], [ -980244.533194538322277, 30855.609566356935829 ] ] ] } },
{ "type": "Feature", "properties": { "gridsize": 500.0, "big_gid": 353, "little_gid": 22486 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -979746.288298377417959, 30855.609566356935829 ], [ -979746.288298377417959, 31355.354737498135364 ], [ -979248.043402216513641, 31355.354737498135364 ], [ -979248.043402216513641, 30855.609566356935829 ], [ -979746.288298377417959, 30855.609566356935829 ] ] ] } },
{ "type": "Feature", "properties": { "gridsize": 500.0, "big_gid": 353, "little_gid": 22487 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -979248.043402216513641, 30855.609566356935829 ], [ -979248.043402216513641, 31355.354737498135364 ], [ -978749.798506055609323, 31355.354737498135364 ], [ -978749.798506055609323, 30855.609566356935829 ], [ -979248.043402216513641, 30855.609566356935829 ] ] ] } },
and I defined the table using the geospatial documentation as a template:
CREATE external TABLE IF NOT EXISTS testdb.grid_500
(
gridsize double,
big_gid int,
little_gid int,
geometry binary
)
ROW FORMAT SERDE 'com.esri.hadoop.hive.serde.JsonSerde'
STORED AS INPUTFORMAT 'com.esri.json.hadoop.EnclosedJsonInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION 's3://jdl-athena/grid/'
;
Any query I run against the table, however, returns the same, rather unhelpful, error:
Your query has the following error(s):
HIVE_CURSOR_ERROR: HIVE_CURSOR_ERROR
This query ran against the "testdb" database, unless qualified by the query.
Please post the error message on our forum or contact customer support with
Query Id: 25d3da93-5cfd-46bb-9f77-4eb014679ba6.
Any ideas why I might be receiving this error or how I might go about debugging it? I can't even figure out how to get enough info to diagnose what might be happening.
So after much Google Fu, I have discovered that (of course) ESRI has created their own JSON format for geographic data. I am using the open standard GeoJson and the ESRI format is called ESRI Enclosed JSON. For geometric JSON, Athena supports only the ESRI format, not GEOJSON.
I discovered this distinction here:
https://github.com/Esri/gis-tools-for-hadoop/issues/29
So it looks like I need my input data in a different format.

Yosys interpret and and not gate as nand for visualization

I was trying to use yosys purely for visualization in combination with https://github.com/nturley/netlistsvg. A tool which takes a yosys generated json file and creates an SVG out of it. If I have the verilog code:
module test(a,b,c);
input wire a,b;
output wire c;
assign c = ~(a & b);
endmodule
I want to generate an SVG file that has a NAND gate. I use the following Yosys commands:
read_verilog test.v
write_json output.json
Yosys interprests the assign statement as an AND gate and a NOT gate and outputs the following json:
{
"creator": "Yosys 0.7 (git sha1 61f6811, gcc 6.2.0-11ubuntu1 -O2 -fdebug-prefix-map=/build/yosys-OIL3SR/yosys-0.7=. -fstack-protector-strong -fPIC -Os)",
"modules": {
"test": {
"attributes": {
"src": "test.v:1"
},
"ports": {
"a": {
"direction": "input",
"bits": [ 2 ]
},
"b": {
"direction": "input",
"bits": [ 3 ]
},
"c": {
"direction": "output",
"bits": [ 4 ]
}
},
"cells": {
"$not$test.v:4$2": {
"hide_name": 1,
"type": "$not",
"parameters": {
"Y_WIDTH": 1,
"A_WIDTH": 1,
"A_SIGNED": 0
},
"attributes": {
"src": "test.v:4"
},
"port_directions": {
"Y": "output",
"A": "input"
},
"connections": {
"Y": [ 4 ],
"A": [ 5 ]
}
},
"$and$test.v:4$1": {
"hide_name": 1,
"type": "$and",
"parameters": {
"Y_WIDTH": 1,
"B_WIDTH": 1,
"A_WIDTH": 1,
"B_SIGNED": 0,
"A_SIGNED": 0
},
"attributes": {
"src": "test.v:4"
},
"port_directions": {
"Y": "output",
"B": "input",
"A": "input"
},
"connections": {
"Y": [ 5 ],
"B": [ 3 ],
"A": [ 2 ]
}
}
},
"netnames": {
"$not$test.v:4$2_Y": {
"hide_name": 1,
"bits": [ 4 ],
"attributes": {
"src": "test.v:4"
}
},
"$and$test.v:4$1_Y": {
"hide_name": 1,
"bits": [ 5 ],
"attributes": {
"src": "test.v:4"
}
},
"c": {
"hide_name": 0,
"bits": [ 4 ],
"attributes": {
"src": "test.v:3"
}
},
"b": {
"hide_name": 0,
"bits": [ 3 ],
"attributes": {
"src": "test.v:2"
}
},
"a": {
"hide_name": 0,
"bits": [ 2 ],
"attributes": {
"src": "test.v:2"
}
}
}
}
}
}
Is there anyway to force yosys to interpret the line as a nand gate and output json more like this:
{
"creator": "Yosys 0.7 (git sha1 61f6811, gcc 6.2.0-11ubuntu1 -O2 -fdebug-prefix-map=/build/yosys-OIL3SR/yosys-0.7=. -fstack-protector-strong -fPIC -Os)",
"modules": {
"test": {
"attributes": {
"src": "test.v:1"
},
"ports": {
"a": {
"direction": "input",
"bits": [ 2 ]
},
"b": {
"direction": "input",
"bits": [ 3 ]
},
"c": {
"direction": "output",
"bits": [ 4 ]
}
},
"cells": {
"$nand$test.v:4$1": {
"hide_name": 1,
"type": "$nand",
"parameters": {
"Y_WIDTH": 1,
"B_WIDTH": 1,
"A_WIDTH": 1,
"B_SIGNED": 0,
"A_SIGNED": 0
},
"attributes": {
"src": "test.v:4"
},
"port_directions": {
"Y": "output",
"B": "input",
"A": "input"
},
"connections": {
"Y": [ 4 ],
"B": [ 3 ],
"A": [ 2 ]
}
}
},
"netnames": {
"$nand$test.v:4$1_Y": {
"hide_name": 1,
"bits": [ 5 ],
"attributes": {
"src": "test.v:4"
}
},
"c": {
"hide_name": 0,
"bits": [ 4 ],
"attributes": {
"src": "test.v:3"
}
},
"b": {
"hide_name": 0,
"bits": [ 3 ],
"attributes": {
"src": "test.v:2"
}
},
"a": {
"hide_name": 0,
"bits": [ 2 ],
"attributes": {
"src": "test.v:2"
}
}
}
}
}
}
Or is this not something that can be done.
As you have not run any kind of synthesis, the design is still in the form of a word-wide RTL netlist. In this context "$and", "$not" and similar lowercase cells are multibit cells designed to match the Verilog operators.
Running the "synth" command will synthesise your design to a standard set of single-bit gate level cells. This includes a NAND cell. Note that these cells will have uppercase names such as "$_NAND_" and are equivalent to basic logic gates.

Store and query extremely large amount of JSON data

Context:
300000 lines of JSON data are generated approximately every five seconds by a game's remote public API. This data disappears immediately after the next update and is never accessible again. I want to be able to save compressed historical records of this data, which can be reliably and efficiently indexed and searched.
Question:
What is the best database system to store JSON data on this scale, considering possible compression methods and most importantly query efficiency?
EDIT Adding example unpacked JSON (one object out of around 30000):
{
"accountName": "Kabancheg11",
"lastCharacterName": "KabanNeedBuff",
"id": "427d66d977b5a63af08b3c39173a1a567eb783fde6d6f97df505dbe6c1fa5988",
"stash": "~b/o 30 chaos",
"stashType": "PremiumStash",
"items": [
{
"verified": false,
"w": 1,
"h": 1,
"ilvl": 71,
"icon": "http://web.poecdn.com/image/Art/2DItems/Amulets/Amulet37.png?scale=1&w=1&h=1&v=25bebeac11abfd9f7931d574765521093",
"league": "Hardcore",
"id": "a7bb36a28e55865b9d766dcebd5bc0c6893d5ecb6cd9870dc0bcd3c9f1164f29",
"sockets": [],
"name": "",
"typeLine": "Onyx Amulet",
"identified": false,
"corrupted": false,
"lockedToCharacter": false,
"implicitMods": [
"+15 to all Attributes"
],
"frameType": 3,
"x": 11,
"y": 0,
"inventoryId": "Stash1",
"socketedItems": []
},
{
"verified": false,
"w": 1,
"h": 3,
"ilvl": 75,
"icon": "http://web.poecdn.com/image/Art/2DItems/Weapons/OneHandWeapons/Daggers/Heartbreaker.png?scale=1&w=1&h=3&v=b4f18d5c0602a17381df6a45b4c57be33",
"league": "Hardcore",
"id": "c955f054ffae9439e5d257c4a444b02423b2dbe304d1fa581227d21a0f203aa9",
"sockets": [
{
"group": 0,
"attr": "D"
},
{
"group": 0,
"attr": "D"
}
],
"name": "<<set:MS>><<set:M>><<set:S>>Heartbreaker",
"typeLine": "Royal Skean",
"identified": true,
"corrupted": false,
"lockedToCharacter": false,
"properties": [
{
"name": "Dagger",
"values": [],
"displayMode": 0
},
{
"name": "Physical Damage",
"values": [
[
"15-59",
0
]
],
"displayMode": 0
},
{
"name": "Critical Strike Chance",
"values": [
[
"6.60%",
0
]
],
"displayMode": 0
},
{
"name": "Attacks per Second",
"values": [
[
"1.45",
0
]
],
"displayMode": 0
}
],
"requirements": [
{
"name": "Level",
"values": [
[
"50",
0
]
],
"displayMode": 0
},
{
"name": "Dex",
"values": [
[
"71",
0
]
],
"displayMode": 1
},
{
"name": "Int",
"values": [
[
"102",
0
]
],
"displayMode": 1
}
],
"implicitMods": [
"40% increased Global Critical Strike Chance"
],
"explicitMods": [
"45% increased Spell Damage",
"+50 to maximum Mana",
"+50 to maximum Energy Shield",
"10% faster start of Energy Shield Recharge",
"Your Spells have Culling Strike"
],
"flavourText": [
"A heart can be stabbed by thoughts, \r",
"If your mind is sharp enough."
],
"frameType": 3,
"x": 0,
"y": 9,
"inventoryId": "Stash2",
"socketedItems": []
},
{
"verified": false,
"w": 2,
"h": 3,
"ilvl": 75,
"icon": "http://web.poecdn.com/image/Art/2DItems/Weapons/OneHandWeapons/Scepters/MontregulsGrasp.png?scale=1&w=2&h=3&v=fed985831c32e8e25b7663608a2b7a5c3",
"league": "Hardcore",
"id": "a78e6bfff62145c78b92714cc7de10e4484c42745d48b585ef905b3972c2a319",
"sockets": [
{
"group": 0,
"attr": "S"
},
{
"group": 0,
"attr": "S"
}
],
"name": "",
"typeLine": "Void Sceptre",
"identified": false,
"corrupted": false,
"lockedToCharacter": false,
"properties": [
{
"name": "One Handed Mace",
"values": [],
"displayMode": 0
},
{
"name": "Physical Damage",
"values": [
[
"42-63",
0
]
],
"displayMode": 0
},
{
"name": "Critical Strike Chance",
"values": [
[
"6.50%",
0
]
],
"displayMode": 0
},
{
"name": "Attacks per Second",
"values": [
[
"1.25",
0
]
],
"displayMode": 0
}
],
"requirements": [
{
"name": "Str",
"values": [
[
"104",
0
]
],
"displayMode": 1
},
{
"name": "Int",
"values": [
[
"122",
0
]
],
"displayMode": 1
}
],
"implicitMods": [
"15% increased Elemental Damage"
],
"frameType": 3,
"x": 0,
"y": 6,
"inventoryId": "Stash3",
"socketedItems": []
},
{
"verified": false,
"w": 2,
"h": 4,
"ilvl": 74,
"icon": "http://web.poecdn.com/image/Art/2DItems/Weapons/TwoHandWeapons/TwoHandAxes/TwoHandAxe11Unique.png?scale=1&w=2&h=4&v=49f4f7aff220d356fc6300d7454df63a3",
"league": "Hardcore",
"id": "c8d722c909939d1fda4431722c732e7af4c17781d9d9c58da613bf776ea1e993",
"sockets": [
{
"group": 0,
"attr": "D"
}
],
"name": "",
"typeLine": "Superior Karui Chopper",
"identified": false,
"corrupted": false,
"lockedToCharacter": false,
"properties": [
{
"name": "Two Handed Axe",
"values": [],
"displayMode": 0
},
{
"name": "Quality",
"values": [
[
"+10%",
1
]
],
"displayMode": 0
},
{
"name": "Physical Damage",
"values": [
[
"88-138",
1
]
],
"displayMode": 0
},
{
"name": "Critical Strike Chance",
"values": [
[
"5.00%",
0
]
],
"displayMode": 0
},
{
"name": "Attacks per Second",
"values": [
[
"1.15",
0
]
],
"displayMode": 0
}
],
"requirements": [
{
"name": "Str",
"values": [
[
"151",
0
]
],
"displayMode": 1
},
{
"name": "Dex",
"values": [
[
"43",
0
]
],
"displayMode": 1
}
],
"frameType": 3,
"x": 2,
"y": 0,
"inventoryId": "Stash4",
"socketedItems": []
},
{
"verified": false,
"w": 2,
"h": 3,
"ilvl": 51,
"icon": "http://web.poecdn.com/image/Art/2DItems/Armours/BodyArmours/StrInt3AUnique2.png?scale=1&w=2&h=3&v=3ef1aa6bc50b635ca334653ca95485a63",
"league": "Hardcore",
"id": "26c55af00fb31f63bec7229b622c3c79fb6efcfa03d3d2595672a92778d04d99",
"sockets": [
{
"group": 0,
"attr": "I"
},
{
"group": 1,
"attr": "I"
}
],
"name": "<<set:MS>><<set:M>><<set:S>>Ambu's Charge",
"typeLine": "Crusader Chainmail",
"identified": true,
"corrupted": false,
"lockedToCharacter": false,
"properties": [
{
"name": "Armour",
"values": [
[
"477",
1
]
],
"displayMode": 0
},
{
"name": "Energy Shield",
"values": [
[
"141",
1
]
],
"displayMode": 0
}
],
"requirements": [
{
"name": "Level",
"values": [
[
"43",
0
]
],
"displayMode": 0
},
{
"name": "Str",
"values": [
[
"64",
0
]
],
"displayMode": 1
},
{
"name": "Int",
"values": [
[
"64",
0
]
],
"displayMode": 1
}
],
"explicitMods": [
"182% increased Armour and Energy Shield",
"+15% to all Elemental Resistances",
"Gain an Endurance Charge when you take a Critical Strike",
"2% of Life Regenerated per second while on Low Life",
"Share Endurance Charges with nearby party members"
],
"flavourText": [
"Nothing stops the pain like a courageous rush into battle."
],
"frameType": 3,
"x": 0,
"y": 0,
"inventoryId": "Stash5",
"socketedItems": []
},
{
"verified": false,
"w": 1,
"h": 1,
"ilvl": 64,
"icon": "http://web.poecdn.com/image/Art/2DItems/Jewels/basicint.png?scale=1&w=1&h=1&v=cd579ea22c05f1c6ad2fd015d7a710bd3",
"league": "Hardcore",
"id": "34103c553f0ae3e36c695664a7540dd6e547338596c33554ca3a8443dd5349c1",
"sockets": [],
"name": "<<set:MS>><<set:M>><<set:S>>Cataclysm Heart",
"typeLine": "Cobalt Jewel",
"identified": true,
"corrupted": false,
"lockedToCharacter": false,
"explicitMods": [
"2% increased Cast Speed",
"7% increased maximum Energy Shield",
"+13% to Lightning Resistance"
],
"descrText": "Place into an allocated Jewel Socket on the Passive Skill Tree. Right click to remove from the Socket.",
"frameType": 2,
"x": 0,
"y": 3,
"inventoryId": "Stash6",
"socketedItems": []
},
{
"verified": false,
"w": 1,
"h": 1,
"ilvl": 0,
"icon": "http://web.poecdn.com/image/Art/2DItems/Gems/VaalGems/VaalArc.png?scale=1&w=1&h=1&v=b4f32328e279496ebb227521e8dce6793",
"support": false,
"league": "Hardcore",
"id": "be9a23cfe0a53942b19c22da32b7d461b464838749110d04689e15498dcad86b",
"sockets": [],
"name": "",
"typeLine": "Vaal Arc",
"identified": true,
"corrupted": true,
"lockedToCharacter": false,
"properties": [
{
"name": "Vaal, Spell, Chaining, Lightning",
"values": [],
"displayMode": 0
},
{
"name": "Level",
"values": [
[
"20 (Max)",
0
]
],
"displayMode": 0
},
{
"name": "Mana Cost",
"values": [
[
"0",
0
]
],
"displayMode": 0
},
{
"name": "Souls Per Use",
"values": [
[
"32",
0
]
],
"displayMode": 0
},
{
"name": "Can Store %0 Use",
"values": [
[
"1",
0
]
],
"displayMode": 3
},
{
"name": "Cast Time",
"values": [
[
"0.80 sec",
0
]
],
"displayMode": 0
},
{
"name": "Critical Strike Chance",
"values": [
[
"5.00%",
0
]
],
"displayMode": 0
},
{
"name": "Damage Effectiveness",
"values": [
[
"80%",
0
]
],
"displayMode": 0
}
],
"requirements": [
{
"name": "Level",
"values": [
[
"70",
0
]
],
"displayMode": 0
},
{
"name": "Int",
"values": [
[
"155",
0
]
],
"displayMode": 1
}
],
"secDescrText": "An arc of lightning stretches from the caster to a targeted nearby enemy and chains on to many additional targets.",
"explicitMods": [
"Deals 49 to 938 Lightning Damage",
"Chain +40 Times",
"100% chance to Shock enemies"
],
"descrText": "Place into an item socket of the right colour to gain this skill. Right click to remove from a socket.",
"frameType": 4,
"x": 0,
"y": 4,
"inventoryId": "Stash7",
"socketedItems": []
}
],
"public": true
}
An example query could be asking how many of the items nested inside every object like the one shown above have an ilvl field greater than or equal to an integer.