Neo4j 2.0.1 graphstyle.grass for multiple labels

耗尽温柔 提交于 2019-12-22 08:40:42

问题


I'm having a hard time setting properties for nodes with multiple labels.

My graphstyle.grass file looks like this:

node {
  diameter: 40px;
  color: #aaaaaa;
  border-color: #888888;
  border-width: 1.5px;
  text-color-internal: #000000;
  caption: '{name}';
  font-size: 12px;
}

node.foo {
  color: #aaaaff;
}

node.bar {
  color: #aaffaa;
}

node.bar.a {
  border-color: #ff0000;
}

node.bar.b {
  border-color: #0000ff;
}

So the intention here is that if you have a label of 'bar' the node is colored a certain way, if you also have an additional label of 'a' or 'b' your border is colored appropriately. My CSS knowledge is weak but I think this is traditionally how multiple class selectors are done.

The behavior I'm seeing in the Neo 2.0.1 browser graph display is that if a node has multiple labels, it picks the first label, tries to find a node.first_label selector in the grass file, if it doesn't find it it just adds a new selector for it. So two concrete examples:

  1. If there's a node with labels ['bar','a'] (in that order) then Neo4j will find the node.bar selector above and use it, not doing anything with the second class.. i.e. the 'node.bar.a' attributes won't be applied.
  2. If the node has the labels ['a','bar'] (in that order) then Neo4j will look for a selector of the form 'node.a' and not invoke any of the selectors above but instead create a new selector with a set of default parameters.

Any guidance or suggestions are greatly appreciated.


回答1:


That's a perfectly sensible approach, which would be correct. As of Neo4j 2.0.1, the graph stylesheets aren't yet clever enough to handle chained class selectors. The order of selection is (as you've observed) also broken.

update: As of 2.2, multiple class selectors are supported, as long as you edit the grass definition by hand.




回答2:


Maybe use Alchemy's SVG+CSS support for dataviz instead? (sending data to it via GraphJSON) - http://neo4j.com/developer/guide-data-visualization/#_library_alchemy_js_open_source_graph_visualization

At http://graphalchemist.github.io/Alchemy/#/docs is says: "Styling through CSS tends to be inflexible, as it's not related to the data in any way. However, some people may want to use an obscure feature offered by SVG/CSS, and we've made sure that that is easy to do. The svg elements of the nodes and edges receive classes that correspond to the types defined in the configuration options edgeTypes and nodeTypes. To create the same graph with css you can assign css styles based on those classes. Based on our data and this example we can use this css to generate the graph that follows"

Although it calls CSS inflexible, if SVG does support such CSS concepts like the ones you seek, I feel it's more flexible than the default way alchemy proposes you do the styling

I wonder if Alchemy supports images (bitmap and SVG ones) btw for nodes. I would also like to see multiple images (each for a label of the node) overlaid somehow (ordered based on label order if there's a label order concept indeed in Neo4j). Probably if one uses code similar to Popoto.js (http://www.popotojs.com/) which also uses D3



来源:https://stackoverflow.com/questions/22054684/neo4j-2-0-1-graphstyle-grass-for-multiple-labels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!