未验证 提交 adbc27a4 编写于 作者: M Matthieu Totet 提交者: GitHub

Fixing Json export position normalization (#2742)

* Bugfix, normalized coordinate are now used

* Allow writing coordinate with component = 0 when asking normalization only + test
上级 725041c6
......@@ -324,14 +324,14 @@ public class ExporterJson implements GraphExporter, CharacterExporter, LongTask
float x = normalization.normalizeX(node.x());
float y = normalization.normalizeY(node.y());
float z = normalization.normalizeZ(node.z());
if (!(x == 0 && y == 0 && z == 0)) {
if (normalize || !(x == 0 && y == 0 && z == 0)) {
out.name("x");
out.value(node.x());
out.value(x);
out.name("y");
out.value(node.y());
out.value(y);
if (normalization.minZ != 0 || normalization.maxZ != 0) {
out.name("z");
out.value(node.z());
out.value(z);
}
}
}
......
......@@ -81,7 +81,44 @@ public class JsonTest {
exporterJson.setExportColors(true);
Utils.assertExporterMatch("json/colors.json", exporterJson);
}
@Test
public void testPosition() throws IOException {
GraphGenerator graphGenerator =
GraphGenerator.build().generateTinyGraphWithPosition();
Graph graph = graphGenerator.getGraph();
Node n1 = graph.getNode(GraphGenerator.FIRST_NODE);
Node n2 = graph.getNode(GraphGenerator.SECOND_NODE);
n1.setColor(Color.CYAN);
n2.setColor(new Color(255, 100, 120, 254));
ExporterJson exporterJson = createExporter(graphGenerator);
exporterJson.setExportPosition(true);
exporterJson.setNormalize(false);
exporterJson.execute();
Utils.assertExporterMatch("json/position.json", exporterJson);
}
@Test
public void testPositionNormalized() throws IOException {
GraphGenerator graphGenerator =
GraphGenerator.build().generateTinyGraphWithPosition();
Graph graph = graphGenerator.getGraph();
Node n1 = graph.getNode(GraphGenerator.FIRST_NODE);
Node n2 = graph.getNode(GraphGenerator.SECOND_NODE);
n1.setColor(Color.CYAN);
n2.setColor(new Color(255, 100, 120, 254));
ExporterJson exporterJson = createExporter(graphGenerator);
exporterJson.setExportPosition(true);
exporterJson.setNormalize(true);
exporterJson.execute();
Utils.assertExporterMatch("json/position_normalized.json", exporterJson);
}
private static ExporterJson createExporter(GraphGenerator graphGenerator) {
Workspace workspace = graphGenerator.getWorkspace();
ExporterJson exporterJson = new ExporterJson();
......@@ -92,4 +129,5 @@ public class JsonTest {
exporterJson.setExportSize(false);
return exporterJson;
}
}
{
"options": {
"multi": false,
"allowSelfLoops": true,
"type": "directed"
},
"nodes": [
{
"key": "1",
"attributes": {
"x": 2.5,
"y": 4.7
}
},
{
"key": "2",
"attributes": {
"x": -3.3,
"y": -5.4
}
}
],
"edges": [
{
"key": "1",
"source": "1",
"target": "2",
"attributes": {
"weight": 1.0
}
}
]
}
\ No newline at end of file
{
"options": {
"multi": false,
"allowSelfLoops": true,
"type": "directed"
},
"nodes": [
{
"key": "1",
"attributes": {
"x": 1.0,
"y": 1.0
}
},
{
"key": "2",
"attributes": {
"x": 0.0,
"y": 0.0
}
}
],
"edges": [
{
"key": "1",
"source": "1",
"target": "2",
"attributes": {
"weight": 1.0
}
}
]
}
\ No newline at end of file
......@@ -94,6 +94,20 @@ public class GraphGenerator {
graphModel.getDirectedGraph().addEdge(e);
return this;
}
public GraphGenerator generateTinyGraphWithPosition() {
Node n1 = graphModel.factory().newNode(FIRST_NODE);
n1.setX(2.5f);
n1.setY(4.7f);
Node n2 = graphModel.factory().newNode(SECOND_NODE);
n2.setX(-3.3f);
n2.setY(-5.4f);
Edge e = graphModel.factory().newEdge(FIRST_EDGE, n1, n2, 0, 1.0, true);
graphModel.getDirectedGraph().addNode(n1);
graphModel.getDirectedGraph().addNode(n2);
graphModel.getDirectedGraph().addEdge(e);
return this;
}
public GraphGenerator generateTinyUndirectedGraph() {
Node n1 = graphModel.factory().newNode(FIRST_NODE);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册