I am starting with D3 and having the following problem:
I've created a directional force layout binding JSON data for links and nodes where data links are:
{
{ "source":"s1" , "target":"t1", "type_link"= "type1"},
{ "source":"s2" , "target":"t2", "type_link"= "type2"}
...
}
...where "source" and "target" identify nodes on both sides of each link.
I need to bind and visualize additional data to each node of previous force layout (no need to add or remove nodes to the layout). New data would be loaded for each existent node from another JSON file:
{
{ "node_id": "s1", value: {JSON object} //with additional data for node "s1"},
{ "node_id": "t1", value: {JSON object} //with additional data for node "t1"}
...
}
So, I would like to append 'value' field data (so, JSON object) to each 'node_id' node.
I thought that I could do it by binding to each node a dataset ( the JSON object), and then appending to each node (not circle) many SVG text as data in JSON object (maybe using .
But I've read in https://github.com/mbostock/d3/wiki/Force-Layout that "a given force layout instance can only be used with a single dataset", so I'm confused.
Please, could you hep me with this issue?
The single dataset means that you can't use a given instance of the force layout with different pairs of nodes and links, because the force layout will store additional properties in the nodes and links. For instance, if you have nodes1, links1 and nodes2, links2, you must create also a force layout for each (nodes, links) pair force1 and force2.
An example of force layout can be found here: http://bl.ocks.org/mbostock/4062045
Related
I would like to perform a depth first search on my graph and so, get all the paths existing from a given node ('N1456' in my example), and all the nodes of theses path must have the same property "PROPERTY_TO_FILTER".
Typically, my graph is composed of two types of node, and two types of relations.
For now, I tested the following request :
WITH "
MATCH (my_node{name : 'N1456'})
CALL apoc.path.expandConfig(protein, {uniqueness:'NODE_GLOBAL', bfs : FALSE}) YIELD path
WITH path, my_node, last(nodes(path)) as subgraph
WHERE my_node<> subgraph and my_node.my_property CONTAINS 'PROPERTY_TO_FILTER'
RETURN nodes(path), length(path) AS len
ORDER BY len DESC" AS query
CALL apoc.export.json.query(query, "my_results.json", {})
YIELD properties, data
RETURN properties, data;
However, the results are not the ones attended. I get a list of paths but only the first node has the property "PROPERTY_TO_FILTER" ; this filter is not taken into account for the other nodes...
I guess I should put a filter at apoc.path.expandConfig level, but I see in the documentation that this is only possible to filter the node label, not the node properties.
Could someone help please ?
Maybe this can help:
MATCH(fromNode:LABEL{name : 'N1456'})-[r:REL_TO_TRAVERSE*1..2]->(toNode:LABEL)
WHERE toNode.my_property CONTAINS 'PROPERTY_TO_FILTER'
RETURN fromNode,r,toNode
It's called variable length pattern matching:
https://neo4j.com/docs/cypher-manual/current/syntax/patterns/#cypher-pattern-varlength
I have been searching for ar.js multimarkers tutorial or anything that explains about it. But all I can find is 2 examples, but no tutorials or explanations.
So far, I understand that it requires to learn the pattern or order of the markers, then it stores it in localStorage. This data is used later to display the image.
What I don't understand, is how this "learner" is implemented. Also, the learning process is only used once by the "creator", right? The output file should be stored and then served later when needed, not created from scratch at each person's phone or computer.
Any help is appreciated.
Since the question is mostly about the learner page, I'll try to break it down as much as i can:
1) You need to have an array of {type, URL} objects.
A sample of creating the default array is shown below (source code):
var markersControlsParameters = [
{
type : 'pattern',
patternUrl : 'examples/marker-training/examples/pattern-files/pattern-hiro.patt',
},
{
type : 'pattern',
patternUrl : 'examples/marker-training/examples/pattern-files/pattern-kanji.patt',
}]
2) You need to feed this to the 'learner' object.
By default the above object is being encoded into the url (source) and then decoded by the learner site. What is important, happens on the site:
for each object in the array, an ArMarkerControls object is created and stored:
// array.forEach(function(markerParams){
var markerRoot = new THREE.Group()
scene.add(markerRoot)
// create markerControls for our markerRoot
var markerControls = new THREEx.ArMarkerControls(arToolkitContext, markerRoot, markerParams)
subMarkersControls.push(markerControls)
The subMarkersControls is used to create the object used to do the learning. At long last:
var multiMarkerLearning = new THREEx.ArMultiMakersLearning(arToolkitContext, subMarkersControls)
The example learner site has multiple utility functions, but as far as i know, the most important here are the ArMultiMakersLearning members which can be used in the following order (or any other):
// this method resets previously collected statistics
multiMarkerLearning.resetStats()
// this member flag enables data collection
multiMarkerLearning.enabled = true
// this member flag stops data collection
multiMarkerLearning.enabled = false
// To obtain the 'learned' data, simply call .toJSON()
var jsonString = multiMarkerLearning.toJSON()
Thats all. If you store the jsonString as
localStorage.setItem('ARjsMultiMarkerFile', jsonString);
then it will be used as the default multimarker file later on. If you want a custom name or more areas - then you'll have to modify the name in the source code.
3) 2.1.4 debugUI
It seems that the debug UI is broken - the UI buttons do exist but are nowhere to be seen. A hot fix would be using the 'markersAreaEnabled' span style for the div
containing the buttons (see this source bit).
It's all in this glitch, you can find it under the phrase 'CHANGES HERE' in the arjs code.
I'm trying to parse an HTML document into nested set of tags and content. It needs to support arbitrary nesting depth. The object (created in
Python code) looks like:
{
"content": [
"some text about a thing, ",
{"content": "More text with additional set of tags ",
"tags": ["strong"]
}
],
"tags": ["p"]
}
ES seems to dislike this structure, because the content field is of both a text and object type, producing this error; "reason": "mapper [content] of different type, current_type [text], merged_type [ObjectMapper]"
Does anyone have any ideas on how to index this type of object, and also allow for searches on both tags and content? Ideally I'd like to search by tags associated with the ancestors of a given object too. I can reformat it to
{
"content": [
{"content": "some text about a thing, "},
{"content": "More text with a different set of tags ",
"tags": ["strong"]
}
],
"tags": ["p"]
}
But then searching isn't very effective as I need to write content.content:"search string" to get results, which will become hard with multiple levels of nesting.
Why not store the ancestor tags in a separate field? Implementing a nested set will should solve your problem too.
Edit: As requested here comes a example of a nested set
Imagine a tree structure. Every node in this tree has a set of properties like description, or other attributes. Each node holds also a reference to it's parent node. Beside this there are two numbers: left and right position in the tree when traversing with in-depth search:
A(parent:null, left:1, right:12, desc:“root node“)
B(parent:A, left:2, right:3, desc:“left child“)
C(parent:A, left:4, right:11, desc:“right child“)
D(parent:C, left:5, right:6, desc:“foo“)
E(parent:C, left:7, right:10, desc:“bar“)
F(parent:E, left:8, right:9, desc:“baz“)
Calculating all ancenstors of a node is now easy:
ancestors(F for X) = search nodes as N WHERE N.left < X.left AND N.right > X.right
For the node F you'll get [E,C,A]. Ordering them by the left value you'll get the proper order for the ancestors of F.
So now you can use this criteria for the filter query in ES and use a second query for the search in the attributes of filtered nodes.
This structure is very efficient when looking for subtrees, but has downsides when you change the node order/position.
If you need further explanation, please add a comment.
Pretty straight forward question, as soon as i use setseries data the visibility my pie chart is no longer visible. I have checked the plot object and the series were updated correctly, however since I do not find a visibility attribute anywhere in the plot object, i am at a loss.
The lack of zingcharts documentation and proper examples does not aid either. Im fairly certain this is a simple scenario to solve, but I've been unable to do so.
zingchart.exec('organismplot', 'setseriesdata', {
"data": [
{
"values":data_update.organisms,
"text":"active",
"background-color":"#2d4962",
"border-width":"1px",
"shadow":0,
"visible":1
},
{
"values":(data_update.totalorganism-data_update.organisms),
"text":"passive",
"background-color":"#2d4962",
"border-width":"1px",
"shadow":0,
"visible":0
}]
I'm a member of the ZingChart team, and I'm happy to help you out!
What is the type of data_update.organisms and data_update.totalorganism-data_update.organisms? Make sure that you are passing a single element array, or if those are simply single values, wrap the variables in brackets to create a single value array for the "values" attribute. E.G.:
"data": [
{
"values":[data_update.organisms], // If data_update.organisms is a single value.
"text":"active",
"background-color":"#2d4962",
"border-width":"1px",
"shadow":0,
"visible":1
},
{
"values":[data_update.totalorganism-data_update.organisms], // Again, single value array.
"text":"passive",
"background-color":"#2d4962",
"border-width":"1px",
"shadow":0,
"visible":0
}
]
I've created a demo using your exact method call, except I've changed the "values" attributes to use a single value array, which are needed for pie charts. Check out the demo here.
I hope that helps. Let me know if you need some more help!
Given an HTML document, I want to identify all the numbers in the document and add custom tags around the numbers.
Right now, i use the following:
HtmlNodeCollection bodyNode = htmlDoc.DocumentNode.SelectNodes("//body");
MatchCollection numbersColl = Regex.Matches(htmlNode.InnerText, <some regex>);
Once I get the numbersColl, I can traverse through each Match and get the index.
However, I can't change the InnerText since it is read-only.
What I need is that if match.Value = 100 and match.Index=25, I want to replace that 25 with
<span isIdentified='true'> 25 </span>
Any help on this will be greatly appreciated. Currently, since I am not able to modify the inner text, I have to modify the InnerHtml but some element might have 25 in it's innerHtml. That should not be touched. But how do I identify whether the number is within
an html tag i.e. < table border='1' > has 1 in the tag.
Here's what I did to work around the read-only property limitation of the InnerText property of a Text node, just select the Parent node of the Text node and note the index of the Text node in the child node collections of the Parent node. Then just do a ReplaceChild(...).
private void WriteText(HtmlNode node, string text)
{
if (node.ChildNodes.Count > 0)
{
node.ReplaceChild(htmlDocument.CreateTextNode(text), node.ChildNodes.First());
}
else
{
node.AppendChild(htmlDocument.CreateTextNode(text));
}
}
In your case I believe you need to create a new Element node that wraps the text into an HtmlElement and then just use it as a replacement of the Text node.
Or even better, see if you can do something like the answer posted here:
Replacing a HTML div InnerText tag using HTML Agility Pack
creating a textnode does not what it should do in this case:
myParentNode.AppendChild(D.CreateTextNode("<script>alert('a');</script>"));
Console.Write(myParentNode.InnerHtml);
The result should be something like
<script....
but it is a working script task even if i add it as "TEXT" not as html. This causes kind of a security issue for me because the text would be a input from a anonymous user.