You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by ah...@apache.org on 2023/09/08 11:17:41 UTC
[causeway] branch master updated: CAUSEWAY-3565: adds obj graph renderer for D3js
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/master by this push:
new c04edcea86 CAUSEWAY-3565: adds obj graph renderer for D3js
c04edcea86 is described below
commit c04edcea869d85e065ad2b706a4f77c625dd33c5
Author: andi-huber <ah...@apache.org>
AuthorDate: Fri Sep 8 13:17:34 2023 +0200
CAUSEWAY-3565: adds obj graph renderer for D3js
---
.../domainobjects/EntityDiagramPageAbstract.java | 3 +-
.../asciidoc/builder/AsciiDocBuilder.java | 92 +++++
.../asciidoc/builder/AsciiDocFactory.java | 6 +
.../valuetypes/asciidoc/builder/NodeWriter.java | 10 +-
.../objgraph/d3js/ObjectGraphRendererD3js.java | 151 ++++++++
.../objgraph/d3js/force-directed-graph-1.0.js | 420 +++++++++++++++++++++
.../asciidoc/builder/objgraph/d3js/g-style.css | 86 +++++
.../asciidoc/builder/objgraph/d3js/svgCheckBox.js | 126 +++++++
.../plantuml}/ObjectGraphRendererPlantuml.java | 2 +-
.../test/ast/AbstractAsciiDocWriterTest.java | 4 +-
.../builder/test/ast/PassthroughBlockTest.java | 59 +++
.../src/test/resources/approved/passthrough.adoc | 5 +
12 files changed, 958 insertions(+), 6 deletions(-)
diff --git a/extensions/core/docgen/help/src/main/java/org/apache/causeway/extensions/docgen/help/topics/domainobjects/EntityDiagramPageAbstract.java b/extensions/core/docgen/help/src/main/java/org/apache/causeway/extensions/docgen/help/topics/domainobjects/EntityDiagramPageAbstract.java
index 174e85d917..eb4fb47203 100644
--- a/extensions/core/docgen/help/src/main/java/org/apache/causeway/extensions/docgen/help/topics/domainobjects/EntityDiagramPageAbstract.java
+++ b/extensions/core/docgen/help/src/main/java/org/apache/causeway/extensions/docgen/help/topics/domainobjects/EntityDiagramPageAbstract.java
@@ -29,7 +29,7 @@ import org.apache.causeway.applib.services.metamodel.ObjectGraph;
import org.apache.causeway.extensions.docgen.help.CausewayModuleExtDocgenHelp;
import org.apache.causeway.extensions.docgen.help.applib.HelpPage;
import org.apache.causeway.valuetypes.asciidoc.applib.value.AsciiDoc;
-import org.apache.causeway.valuetypes.asciidoc.builder.plantuml.obj.ObjectGraphRendererPlantuml;
+import org.apache.causeway.valuetypes.asciidoc.builder.objgraph.plantuml.ObjectGraphRendererPlantuml;
import lombok.RequiredArgsConstructor;
import lombok.val;
@@ -62,7 +62,6 @@ public abstract class EntityDiagramPageAbstract implements HelpPage {
*/
protected String renderObjectGraph(final ObjectGraph objectGraph) {
val plantumlSource = objectGraph.render(new ObjectGraphRendererPlantuml());
-
return "== " + getTitle() + "\n\n"
+ _DiagramUtils.plantumlBlock(plantumlSource)
+ "\n"
diff --git a/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/AsciiDocBuilder.java b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/AsciiDocBuilder.java
new file mode 100644
index 0000000000..a2d8e21ce1
--- /dev/null
+++ b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/AsciiDocBuilder.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.causeway.valuetypes.asciidoc.builder;
+
+import java.util.function.Consumer;
+
+import org.asciidoctor.ast.Document;
+
+import org.apache.causeway.valuetypes.asciidoc.applib.value.AsciiDoc;
+
+import static org.apache.causeway.valuetypes.asciidoc.builder.AsciiDocFactory.doc;
+
+/**
+ * Provides fluent factory methods to build a (AsciiDoc) Document Model.
+ * @since Sep 8, 2023
+ * @apiNote The <i>AsciiDoc<i> name is trademarked by the <i>Eclipse Foundation</i>.
+ * <p>
+ This project is <b>not</b> part of the specification effort for <i>AsciiDoc<i> under the
+ <i>AsciiDoc Working Group</i>. See https://projects.eclipse.org/proposals/asciidoc-language
+ and https://accounts.eclipse.org/mailing-list/asciidoc-wg. However, we are happy to
+ help with transfer of source code, if any project (under the umbrella of the
+ <i>AsciiDoc Working Group</i>) is willing to take over.
+ </p>
+ */
+public class AsciiDocBuilder {
+
+ private final Document doc = doc();
+
+ // -- APPEND
+
+ public AsciiDocBuilder append(final Consumer<Document> appender) {
+ appender.accept(doc);
+ return this;
+ }
+
+//XXX looks great, but would not support block nesting ...
+// // -- TITLE
+//
+// public AsciiDocBuilder title(final String title) {
+// doc.setTitle(title);
+// return this;
+// }
+//
+// // -- BLOCKS
+//
+// public AsciiDocBuilder javaBlockWithTitle(final String source, @Nullable final String title) {
+// AsciiDocFactory.SourceFactory.java(doc, source, title);
+// return this;
+// }
+//
+// public AsciiDocBuilder xmlBlockWithTitle(final String source, @Nullable final String title) {
+// AsciiDocFactory.SourceFactory.xml(doc, source, title);
+// return this;
+// }
+//
+// public AsciiDocBuilder yamlBlockWithTitle(final String source, @Nullable final String title) {
+// AsciiDocFactory.SourceFactory.yaml(doc, source, title);
+// return this;
+// }
+//
+// public AsciiDocBuilder htmlPassthrough(final String html) {
+// AsciiDocFactory.htmlPassthroughBlock(doc, html);
+// return this;
+// }
+
+ // -- BUILD
+
+ public String build() {
+ return AsciiDocWriter.toString(doc);
+ }
+
+ public AsciiDoc buildAsAsciiDoc() {
+ return AsciiDoc.valueOf(build());
+ }
+
+}
diff --git a/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/AsciiDocFactory.java b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/AsciiDocFactory.java
index 398c03a370..3d53b18708 100644
--- a/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/AsciiDocFactory.java
+++ b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/AsciiDocFactory.java
@@ -177,6 +177,12 @@ public class AsciiDocFactory {
return sourceBlock;
}
+ public static Block htmlPassthroughBlock(final StructuralNode parent, @NonNull final String html) {
+ val block = block(parent, html);
+ block.setStyle("passthrough");
+ return block;
+ }
+
public static Block diagramBlock(
final StructuralNode parent,
@NonNull final String diagramType,
diff --git a/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/NodeWriter.java b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/NodeWriter.java
index 1894c9d85b..95aafcef4f 100644
--- a/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/NodeWriter.java
+++ b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/NodeWriter.java
@@ -123,6 +123,7 @@ final class NodeWriter implements StructuralNodeVisitor {
CALLOUT_LIST("arabic"::equals),
COLLAPSIBLE_BLOCK("example"::equals),
SOURCE_BLOCK("source"::equals),
+ PASSTHROUG_BLOCK("passthrough"::equals),
DIAGRAM_BLOCK(KNOWN_DIAGRAM_TYPES::contains),
ADMONITION_NOTE("NOTE"::equals),
ADMONITION_TIP("TIP"::equals),
@@ -154,6 +155,9 @@ final class NodeWriter implements StructuralNodeVisitor {
public boolean isSourceBlock() {
return this==Style.SOURCE_BLOCK;
}
+ public boolean isPassthroughBlock() {
+ return this==Style.PASSTHROUG_BLOCK;
+ }
public boolean isDiagramBlock() {
return this==Style.DIAGRAM_BLOCK;
}
@@ -205,7 +209,9 @@ final class NodeWriter implements StructuralNodeVisitor {
_Strings.nonEmpty(block.getTitle())
.ifPresent(this::printBlockTitle);
println("----");
- } if(style.isDiagramBlock()) {
+ } else if(style.isPassthroughBlock()) {
+ println("++++");
+ } else if(style.isDiagramBlock()) {
val diagramTypeAndOptions = IntStream
.iterate(1, index->block.getAttribute(""+index)!=null, index->index+1)
@@ -243,6 +249,8 @@ final class NodeWriter implements StructuralNodeVisitor {
|| style.isSourceBlock()
|| style.isDiagramBlock()) {
println("----");
+ } else if(style.isPassthroughBlock()) {
+ println("++++");
} else if(style.isCollapsibleBlock()) {
println("====");
}
diff --git a/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/ObjectGraphRendererD3js.java b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/ObjectGraphRendererD3js.java
new file mode 100644
index 0000000000..7553430908
--- /dev/null
+++ b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/ObjectGraphRendererD3js.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.causeway.valuetypes.asciidoc.builder.objgraph.d3js;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.causeway.applib.services.metamodel.ObjectGraph;
+import org.apache.causeway.commons.io.DataSource;
+import org.apache.causeway.commons.io.JsonUtils;
+
+import lombok.Builder;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.val;
+
+@RequiredArgsConstructor
+public class ObjectGraphRendererD3js implements ObjectGraph.Renderer {
+
+ @Builder
+ public static class GraphRenderOptions {
+ @Builder.Default @Getter private final double scale = 1.0;
+ @Builder.Default @Getter private final int node_radius = 5;
+ @Builder.Default @Getter private final int arrow_length = 8;
+ @Builder.Default @Getter private final int arrow_breadth = 5;
+ @Builder.Default @Getter private final Boolean enable_nodelabels = true;
+ @Builder.Default @Getter private final Boolean enable_edgelabels = true;
+ @Builder.Default @Getter private final Boolean enable_edgearrows = true;
+ @Builder.Default @Getter private final Boolean enable_stickyNodeDrag = true;
+ String toJavaScript() {
+ return JsonUtils.toStringUtf8(this).replace('"', ' ');
+ }
+ }
+
+ /**
+ * Graph model used as input to accompanied force-directed-graph JavaScript.
+ */
+ @lombok.Value
+ private static class D3jsGraph {
+ @lombok.Value
+ public static class Node {
+ int id;
+ String label;
+ String group; // future use
+ String description;
+ }
+ @lombok.Value
+ public static class Link {
+ int source;
+ int target;
+ String label;
+ float weight = 1.f;
+ }
+ private final List<Node> nodes;
+ private final List<Link> links;
+ }
+
+ private final GraphRenderOptions graphRenderOptions;
+
+ @Override
+ public void render(final StringBuilder sb, final ObjectGraph objGraph) {
+
+ renderProlog(sb);
+
+ val d3jsGraph = new D3jsGraph(new ArrayList<>(), new ArrayList<>());
+
+//debug
+// d3jsGraph.nodes.add(new D3jsGraph.Node(1, "A", "an A"));
+// d3jsGraph.nodes.add(new D3jsGraph.Node(2, "B", "a B"));
+// d3jsGraph.nodes.add(new D3jsGraph.Node(3, "C", "a C"));
+//
+// d3jsGraph.links.add(new D3jsGraph.Link(1, 2, "E1"));
+// d3jsGraph.links.add(new D3jsGraph.Link(2, 3, "E2"));
+// d3jsGraph.links.add(new D3jsGraph.Link(3, 1, "E3"));
+
+
+ val objectLookup = new HashMap<ObjectGraph.Object, Integer>();
+
+ objGraph.objects().forEach(obj->{
+ val counter = objectLookup.size();
+ d3jsGraph.nodes.add(new D3jsGraph.Node(counter, obj.name(), obj.packageName(), obj.packageName()));
+ objectLookup.put(obj, counter);
+ });
+
+ objGraph.relations().forEach(rel->{
+ val source = objectLookup.get(rel.from());
+ val target = objectLookup.get(rel.to());
+ d3jsGraph.links.add(new D3jsGraph.Link(source, target, rel.labelFormatted()));
+ });
+
+ renderSvg(sb, d3jsGraph);
+ }
+
+ protected void renderSvg(final StringBuilder sb, final D3jsGraph d3jsGraph) {
+ sb.append("<div class=\"svg-container\">\n");
+ sb.append("<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"force-directed-graph\">\n");
+ sb.append("<script>\n");
+ sb.append("var d3jsGraph =\n");
+ sb.append(JsonUtils.toStringUtf8(d3jsGraph)).append("\n");
+ sb.append("renderForceDirectedGraph(d3jsGraph);\n");
+ sb.append("</script>\n");
+ sb.append("</svg>\n");
+ sb.append("</div>\n");
+ }
+
+ protected void renderProlog(final StringBuilder sb) {
+ sb.append("<script src=\"https://d3js.org/d3.v4.min.js\"></script>\n");
+
+ // -- CSS
+
+ sb.append("<style>\n");
+ sb.append(DataSource.ofResource(ObjectGraphRendererD3js.class, "g-style.css")
+ .tryReadAsStringUtf8()
+ .valueAsNonNullElseFail());
+ sb.append("\n</style>\n");
+
+ // -- JS
+
+ sb.append("<script>\n");
+ sb.append("var ropts = ")
+ .append(graphRenderOptions.toJavaScript())
+ .append(";\n");
+ sb.append(DataSource.ofResource(ObjectGraphRendererD3js.class, "svgCheckBox.js")
+ .tryReadAsStringUtf8()
+ .valueAsNonNullElseFail());
+ sb.append(DataSource.ofResource(ObjectGraphRendererD3js.class, "force-directed-graph-1.0.js")
+ .tryReadAsStringUtf8()
+ .valueAsNonNullElseFail());
+ sb.append("\n</script>\n");
+ }
+
+}
+
+
diff --git a/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/force-directed-graph-1.0.js b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/force-directed-graph-1.0.js
new file mode 100644
index 0000000000..c982656804
--- /dev/null
+++ b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/force-directed-graph-1.0.js
@@ -0,0 +1,420 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* -- DEFAULTS
+var ropts = {
+ scale : 1.0,
+ node_radius: 5,
+ arrow_length: 8,
+ arrow_breadth: 5,
+ enable_nodelabels: true,
+ enable_edgelabels: true,
+ enable_edgearrows: true,
+ enable_stickyNodeDrag: true
+};*/
+
+var frameBox = {
+ _width: Math.round(1800/ropts.scale),
+ _height: Math.round(1200/ropts.scale),
+ border_padding: 2,
+ node_radius: ropts.node_radius,
+ width: function () {
+ return this._width;
+ },
+ height: function () {
+ return this._height;
+ },
+ minX: function () {
+ return 0;
+ },
+ minY: function () {
+ return 0;
+ },
+ maxX: function () {
+ return this.width();
+ },
+ maxY: function () {
+ return this.height();
+ },
+ getViewBoxLiteral: function () {
+ return ' ' + (this.minX()-this.border_padding) + ' ' + (this.minY()-this.border_padding) + ' ' + (this.maxX()+this.border_padding) + ' ' + (this.maxY()+this.border_padding);
+ },
+ forceCenterBounded: function(x, y) {
+ var nodes;
+
+ if (x == null) x = this.width() / 2;
+ if (y == null) y = this.height() / 2;
+
+ var minX=this.minX()+this.node_radius,
+ minY=this.minY()+this.node_radius,
+ maxX=this.maxX()-this.node_radius,
+ maxY=this.maxY()-this.node_radius;
+
+ function force() {
+ var i,
+ n = nodes.length,
+ node,
+ sx = 0,
+ sy = 0;
+
+ for (i = 0; i < n; ++i) {
+ node = nodes[i], sx += node.x, sy += node.y;
+ }
+
+ for (sx = sx / n - x, sy = sy / n - y, i = 0; i < n; ++i) {
+ node = nodes[i], node.x -= sx, node.y -= sy;
+ // don't let nodes leave the bounding frame
+ if(node.x>maxX){ node.x=maxX; }
+ if(node.y>maxY){ node.y=maxY; }
+ if(node.x<minX){ node.x=minX; }
+ if(node.y<minY){ node.y=minY; }
+ }
+ }
+
+ force.initialize = function(_) {
+ nodes = _;
+ };
+
+ force.x = function(_) {
+ return arguments.length ? (x = +_, force) : x;
+ };
+
+ force.y = function(_) {
+ return arguments.length ? (y = +_, force) : y;
+ };
+
+ return force;
+ },
+ bind: function(target){
+ target.attr("preserveAspectRatio", "xMinYMin meet");
+ target.attr("viewBox", this.getViewBoxLiteral());
+
+ target.append("rect")
+ .attr("class", "frame-box")
+ .attr("x", this.minX())
+ .attr("y", this.minY())
+ .attr("width", this.width())
+ .attr("height", this.height());
+ }
+};
+
+// render-model
+var rmodel = {
+ nodes : null,
+ nodelabels : null,
+ edgelabels : null,
+ edgelines : null,
+ rerenderFunction : null
+ };
+
+function renderForceDirectedGraph(data) {
+
+ var svg = d3.select(".force-directed-graph");
+
+ frameBox.bind(svg);
+
+ var color = d3.scaleOrdinal(d3.schemeCategory20);
+
+ { // options
+
+ var checkBox1 = new svgCheckBox("Node Labels").x(5).y(5).rx(5).ry(5).checked(ropts.enable_nodelabels);
+ var checkBox2 = new svgCheckBox("Edge Labels").x(5).y(5+24).rx(5).ry(5).checked(ropts.enable_edgelabels);
+ var checkBox3 = new svgCheckBox("Edge Arrows").x(5).y(5+24*2).rx(5).ry(5).checked(ropts.enable_edgearrows);
+
+ svg.append("text")
+ .attr("x", 5)
+ .attr("y", 5+24*3.6)
+ .text("Note: Double-click on any node to release it from stickyness.");
+
+ var updateCB = function () {
+
+ var checkBox1changed = ropts.enable_nodelabels != checkBox1.checked();
+ var checkBox2changed = ropts.enable_edgelabels != checkBox2.checked();
+ var checkBox3changed = ropts.enable_edgearrows != checkBox3.checked();
+
+ ropts.enable_nodelabels = checkBox1.checked();
+ ropts.enable_edgelabels = checkBox2.checked();
+ ropts.enable_edgearrows = checkBox3.checked();
+
+ function invalidateAll(){
+ svg.selectAll(".nodes").remove();
+ rmodel.nodes = null;
+ svg.selectAll(".links").remove();
+ rmodel.edgelines = null;
+ svg.selectAll(".nodelabels").remove();
+ rmodel.nodelabels = null;
+ svg.selectAll(".edgelabel").remove();
+ rmodel.edgelabels = null;
+ }
+
+ if(!ropts.enable_nodelabels) {
+ svg.selectAll(".nodelabels").remove();
+ rmodel.nodelabels = null;
+ }
+
+ if(!ropts.enable_edgelabels) {
+ svg.selectAll(".edgelabel").remove();
+ rmodel.edgelabels = null;
+ }
+
+ if(!ropts.enable_edgearrows) {
+ invalidateAll();
+ } else {
+ // invalide on re-enable as well
+ if(checkBox3changed) {
+ invalidateAll();
+ }
+ }
+
+ if(rmodel.rerenderFunction!=null) {
+ rmodel.rerenderFunction(); // trigger re-render
+ }
+
+ };
+
+ //Setting up each check box
+ checkBox1.clickEvent(updateCB);
+ checkBox2.clickEvent(updateCB);
+ checkBox3.clickEvent(updateCB);
+
+ svg.call(checkBox1);
+ svg.call(checkBox2);
+ svg.call(checkBox3);
+
+ updateCB();
+
+ }
+
+ var simulation = d3.forceSimulation()
+ .force("link", d3.forceLink().id(function(d) { return d.id; }))
+ .force("charge", d3.forceManyBody())
+ .force("center", frameBox.forceCenterBounded());
+
+ function renderGraph(graph) {
+
+ // factories
+
+ function createEdges() {
+
+ var link = svg.append("g")
+ .attr("class", "links")
+ .selectAll("line")
+ .data(graph.links)
+ .enter().append("line")
+ .style("pointer-events", "none")
+ .attr("stroke-width", function(d) { return Math.sqrt(d.weight); })
+ ;
+
+ if(ropts.enable_edgearrows){
+
+ var a = ropts.arrow_length,
+ b = ropts.arrow_breadth,
+ r = ropts.node_radius,
+ b2 = b*0.5;
+
+ svg.append('defs').append('marker')
+ .attr('id','arrowhead')
+ .attr('viewBox','-0 -'+b2+' '+a+' '+b)
+ .attr('refX', a+r)
+ .attr('refY', 0)
+ .attr('orient', 'auto')
+ .attr('markerWidth', a)
+ .attr('markerHeight', b)
+ .attr('xoverflow', 'visible')
+
+ .append('svg:path')
+ .attr('d', 'M 0,-'+b2+' L '+a+',0 L 0,'+b2)
+ .attr('fill', '#ccc')
+ .attr('stroke','#ccc')
+
+ ;
+
+ link.attr('marker-end','url(#arrowhead)');
+ }
+
+ return link;
+ }
+
+ function createNodes() {
+
+ var node = svg.append("g")
+ .attr("class", "nodes")
+ .selectAll("circle")
+ .data(graph.nodes)
+ .enter().append("circle")
+ .attr("r", ropts.node_radius)
+ .attr("fill", function(d) { return color(d.group); })
+ .call(d3.drag()
+ .on("start", dragstarted)
+ .on("drag", dragged)
+ .on("end", dragended))
+ .on("dblclick", releaseNode)
+ ;
+
+ node.append("title")
+ .text(function(d) { return d.description; });
+
+ return node;
+ }
+
+ function createNodeLabels() {
+ return svg.append("g")
+ .attr("class", "nodelabels")
+ .selectAll(".nodelabel")
+ .data(graph.nodes)
+ .enter()
+ .append("text")
+ .style("pointer-events", "none")
+ .attr("class", "nodelabel")
+ .text(function(d){ return d.label; });
+ }
+
+ function createEdgeLabels() {
+ return svg.append("g")
+ .attr("class", "edgelabels")
+ .selectAll(".edgelabel")
+ .data(graph.links)
+ .enter()
+ .append('text')
+ .style("pointer-events", "none")
+ .style("text-anchor", "middle")
+ .attr("class", "edgelabel")
+ .text(function(d,i){return d.label;});
+ }
+
+ // getters
+
+ function getNodes() {
+ if(rmodel.nodes != null) {
+ return rmodel.nodes;
+ }
+ rmodel.nodes = createNodes();
+ return rmodel.nodes;
+ }
+
+ function getEdges() {
+ if(rmodel.edgelines != null) {
+ return rmodel.edgelines;
+ }
+ rmodel.edgelines = createEdges();
+ return rmodel.edgelines;
+ }
+
+ function getNodeLabels() {
+ if(!ropts.enable_nodelabels) {
+ return null;
+ }
+ if(rmodel.nodelabels != null) {
+ return rmodel.nodelabels;
+ }
+ rmodel.nodelabels = createNodeLabels();
+ return rmodel.nodelabels;
+ }
+
+ function getEdgeLabels() {
+ if(!ropts.enable_edgelabels) {
+ return null;
+ }
+ if(rmodel.edgelabels != null) {
+ return rmodel.edgelabels;
+ }
+ rmodel.edgelabels = createEdgeLabels();
+ return rmodel.edgelabels;
+ }
+
+
+ simulation
+ .nodes(graph.nodes)
+ .on("tick", ticked);
+
+ simulation.force("link")
+ .links(graph.links);
+
+ function ticked() {
+
+
+ getEdges()
+ .attr("x1", function(d) { return d.source.x; })
+ .attr("y1", function(d) { return d.source.y; })
+ .attr("x2", function(d) { return d.target.x; })
+ .attr("y2", function(d) { return d.target.y; })
+ ;
+
+ getNodes()
+ .attr("cx", function(d) { return d.x; })
+ .attr("cy", function(d) { return d.y; })
+ ;
+
+ if(ropts.enable_nodelabels) {
+ getNodeLabels()
+ .attr("x", function(d) { return d.x+ropts.node_radius; })
+ .attr("y", function(d) { return d.y; })
+ ;
+ }
+
+ if(ropts.enable_edgelabels)
+ getEdgeLabels()
+ .attr("x", function(d) { return (d.source.x + d.target.x)*0.5; })
+ .attr("y", function(d) { return (d.source.y + d.target.y)*0.5; })
+ .attr('transform', function(d,i){
+ var cx = (d.source.x + d.target.x)*0.5;
+ var cy = (d.source.y + d.target.y)*0.5;
+ var dx = d.target.x - d.source.x;
+ var dy = d.target.y - d.source.y;
+ var degree = Math.atan2(dy, dx)*57.2958; //180./3.141592654;
+ if (d.target.x<d.source.x)
+ degree+=180;
+ return 'rotate('+degree+' '+cx+' '+cy+')';
+ })
+ ;
+
+
+ }
+
+ rmodel.rerenderFunction = ticked;
+
+ }
+
+ renderGraph(data);
+
+ function dragstarted(d) {
+ if (!d3.event.active) simulation.alphaTarget(0.3).restart();
+ d.fx = d.x;
+ d.fy = d.y;
+ }
+
+ function dragged(d) {
+ d.fx = d3.event.x;
+ d.fy = d3.event.y;
+ }
+
+ function dragended(d) {
+ if (!d3.event.active) simulation.alphaTarget(0);
+ if(!ropts.enable_stickyNodeDrag){
+ releaseNode(d);
+ }
+ }
+
+ function releaseNode(d) {
+ d.fx = null;
+ d.fy = null;
+ }
+
+
+}
\ No newline at end of file
diff --git a/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/g-style.css b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/g-style.css
new file mode 100644
index 0000000000..372aed7d30
--- /dev/null
+++ b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/g-style.css
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+.links line {
+ stroke: #999;
+ stroke-opacity: 0.6;
+}
+
+.nodes circle {
+ stroke: #fff;
+ stroke-width: 1.5px;
+}
+
+.nodelabels .nodelabel {
+ stroke: none;
+ fill: black;
+ font-family: Verdana, Geneva, sans-serif;
+ font-size: 0.5em;
+}
+
+.edgelabel {
+ stroke: none;
+ fill: brown;
+ font-family: Verdana, Geneva, sans-serif;
+ font-size: 0.5em;
+}
+
+.svg-container {
+ display: inline-block;
+ position: relative;
+ width: 100%;
+ padding-bottom: 100%; /* aspect ratio */
+ vertical-align: top;
+ overflow: hidden;
+}
+
+.force-directed-graph {
+ display: inline-block;
+ position: absolute;
+ top: 10px;
+ left: 0;
+}
+
+.frame-box {
+ fill: none;
+ stroke: Silver;
+ stroke-width: 1px;
+}
+
+.checkBox {
+ fill: silver;
+ fill-opacity: 0.1;
+ stroke-width: 1;
+ stroke: black;
+}
+
+.checkMark-checked, .checkMark-unchecked {
+ stroke-width : 5;
+ fill : none;
+}
+
+.checkMark-checked {
+ stroke : green;
+ opacity: 1;
+}
+
+.checkMark-unchecked {
+ stroke : black;
+ opacity: 0.1;
+}
\ No newline at end of file
diff --git a/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/svgCheckBox.js b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/svgCheckBox.js
new file mode 100644
index 0000000000..0f179c9d5f
--- /dev/null
+++ b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/d3js/svgCheckBox.js
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+function svgCheckBox (label) {
+
+ var size = 20,
+ x = 0,
+ y = 0,
+ rx = 0,
+ ry = 0,
+ checked = false,
+ clickEvent,
+ calculatedTextHeight = 10,
+ labelMarginLeft = size/3;
+
+ function checkBox (selection) {
+
+ var g = selection.append("g");
+ var box = g.append("rect")
+ .attr("class", "checkBox")
+ .attr("width", size)
+ .attr("height", size)
+ .attr("x", x)
+ .attr("y", y)
+ .attr("rx", rx)
+ .attr("ry", ry)
+ ;
+
+ // coors to represent the check mark path
+ var coordinates = [
+ {x: x + (size / 8), y: y + (size / 3)},
+ {x: x + (size / 2.2), y: (y + size) - (size / 4)},
+ {x: (x + size) - (size / 8), y: (y + (size / 10))}
+ ];
+
+ // coors to place the label
+ var labelBottomLeft = {
+ x: (x + size) + labelMarginLeft,
+ y: (y + (size+calculatedTextHeight) / 2)
+ };
+
+ var line = d3.line()
+ .x(function(d){ return d.x; })
+ .y(function(d){ return d.y; })
+ .curve(d3.curveCardinal)
+ ;
+
+ var mark = g.append("path");
+
+ mark.attr("d", line(coordinates))
+ .attr("class", (checked)? "checkMark-checked" : "checkMark-unchecked");
+
+ var text = g.append("text");
+ text.attr("x", labelBottomLeft.x).attr("y", labelBottomLeft.y).text(label);
+
+ g.on("click", function () {
+ checked = !checked;
+ mark.attr("class", (checked)? "checkMark-checked" : "checkMark-unchecked");
+
+ if(clickEvent) {
+ clickEvent();
+ }
+
+ d3.event.stopPropagation();
+ });
+
+ }
+
+ checkBox.size = function (val) {
+ size = val;
+ return checkBox;
+ }
+
+ checkBox.x = function (val) {
+ x = val;
+ return checkBox;
+ }
+
+ checkBox.y = function (val) {
+ y = val;
+ return checkBox;
+ }
+
+ checkBox.rx = function (val) {
+ rx = val;
+ return checkBox;
+ }
+
+ checkBox.ry = function (val) {
+ ry = val;
+ return checkBox;
+ }
+
+ checkBox.checked = function (val) {
+
+ if(val === undefined) {
+ return checked;
+ } else {
+ checked = val;
+ return checkBox;
+ }
+ }
+
+ checkBox.clickEvent = function (val) {
+ clickEvent = val;
+ return checkBox;
+ }
+
+ return checkBox;
+}
\ No newline at end of file
diff --git a/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/plantuml/obj/ObjectGraphRendererPlantuml.java b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/plantuml/ObjectGraphRendererPlantuml.java
similarity index 97%
rename from valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/plantuml/obj/ObjectGraphRendererPlantuml.java
rename to valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/plantuml/ObjectGraphRendererPlantuml.java
index 7c82e582fd..a6c43e7be6 100644
--- a/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/plantuml/obj/ObjectGraphRendererPlantuml.java
+++ b/valuetypes/asciidoc/builder/src/main/java/org/apache/causeway/valuetypes/asciidoc/builder/objgraph/plantuml/ObjectGraphRendererPlantuml.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.causeway.valuetypes.asciidoc.builder.plantuml.obj;
+package org.apache.causeway.valuetypes.asciidoc.builder.objgraph.plantuml;
import org.apache.causeway.applib.services.metamodel.ObjectGraph;
import org.apache.causeway.commons.internal.exceptions._Exceptions;
diff --git a/valuetypes/asciidoc/builder/src/test/java/org/apache/causeway/valuetypes/asciidoc/builder/test/ast/AbstractAsciiDocWriterTest.java b/valuetypes/asciidoc/builder/src/test/java/org/apache/causeway/valuetypes/asciidoc/builder/test/ast/AbstractAsciiDocWriterTest.java
index 95ef23e009..6968e832c8 100644
--- a/valuetypes/asciidoc/builder/src/test/java/org/apache/causeway/valuetypes/asciidoc/builder/test/ast/AbstractAsciiDocWriterTest.java
+++ b/valuetypes/asciidoc/builder/src/test/java/org/apache/causeway/valuetypes/asciidoc/builder/test/ast/AbstractAsciiDocWriterTest.java
@@ -50,12 +50,12 @@ abstract class AbstractAsciiDocWriterTest {
}
_Text.assertTextEquals(
- TextUtils.readLinesFromResource(this.getClass(), adocSourceResourceLocation, StandardCharsets.UTF_8),
+ TextUtils.readLinesFromResource(this.getClass(), "/approved/" + adocSourceResourceLocation, StandardCharsets.UTF_8),
sourceUnderTest);
}
protected void assertReferenceDocumentIsCorrectlyWritten() {
- val adocRef = _Strings.readFromResource(this.getClass(), adocSourceResourceLocation, StandardCharsets.UTF_8);
+ val adocRef = _Strings.readFromResource(this.getClass(), "/approved/" + adocSourceResourceLocation, StandardCharsets.UTF_8);
val asciidoctor = Asciidoctor.Factory.create();
val refDoc = asciidoctor.load(adocRef, Options.builder().build());
diff --git a/valuetypes/asciidoc/builder/src/test/java/org/apache/causeway/valuetypes/asciidoc/builder/test/ast/PassthroughBlockTest.java b/valuetypes/asciidoc/builder/src/test/java/org/apache/causeway/valuetypes/asciidoc/builder/test/ast/PassthroughBlockTest.java
new file mode 100644
index 0000000000..50304304e8
--- /dev/null
+++ b/valuetypes/asciidoc/builder/src/test/java/org/apache/causeway/valuetypes/asciidoc/builder/test/ast/PassthroughBlockTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.causeway.valuetypes.asciidoc.builder.test.ast;
+
+import java.io.IOException;
+
+import org.asciidoctor.ast.Document;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import org.apache.causeway.valuetypes.asciidoc.builder.AsciiDocFactory;
+
+import static org.apache.causeway.valuetypes.asciidoc.builder.AsciiDocFactory.doc;
+
+class PassthroughBlockTest extends AbstractAsciiDocWriterTest {
+
+ private Document doc;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ doc = doc();
+ super.adocSourceResourceLocation = "passthrough.adoc";
+ //super.debugEnabled = true;
+ super.skipAsciidocjComplianceTest = true;
+ }
+
+ // = Passthrough
+ //
+ // ++++
+ // <a href="example.org">Hello</a>
+ // ++++
+ @Test
+ void testPassthroughBlock() throws IOException {
+
+ doc.setTitle("Passthrough");
+
+ AsciiDocFactory.htmlPassthroughBlock(doc, "<a href=\"example.org\">Hello</a>");
+
+ assertDocumentIsCorrectlyWritten(doc);
+ }
+
+
+}
diff --git a/valuetypes/asciidoc/builder/src/test/resources/approved/passthrough.adoc b/valuetypes/asciidoc/builder/src/test/resources/approved/passthrough.adoc
new file mode 100644
index 0000000000..cb63033a8e
--- /dev/null
+++ b/valuetypes/asciidoc/builder/src/test/resources/approved/passthrough.adoc
@@ -0,0 +1,5 @@
+= Passthrough
+
+++++
+<a href="example.org">Hello</a>
+++++