Skip to content

Commit

Permalink
D2 bumpup to version 0.6.0, add themes, add options (#1629)
Browse files Browse the repository at this point in the history
* d2 version bumpup
* add missing themes
* add missing options for d2
* added tests for d2
* fixed the tests
  • Loading branch information
vfosnar authored Aug 29, 2023
1 parent 4faa272 commit 2be17fb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions ci/tests/diagrams/connections.d2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dogs -> cats -> mice: chase
replica 1 <-> replica 2
a -> b: To err is human, to moo bovine {
style.animated: true
source-arrowhead: 1
target-arrowhead: * {
shape: diamond
Expand Down
4 changes: 4 additions & 0 deletions ci/tests/smoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ const tests = [
{ engine: 'diagramsnet', file: 'diagramsnet-infography.xml', options: { id: 'foo' }, outputFormat: ['svg', 'png'] },
{ engine: 'd2', file: 'connections.d2', options: {}, outputFormat: ['svg'] },
{ engine: 'd2', file: 'connections.d2', options: { layout: 'elk' }, outputFormat: ['svg'] },
{ engine: 'd2', file: 'connections.d2', options: { theme: '200' }, outputFormat: ['svg'] },
{ engine: 'd2', file: 'connections.d2', options: { pad: '50' }, outputFormat: ['svg'] },
{ engine: 'd2', file: 'connections.d2', options: { "animate-interval": '50' }, outputFormat: ['svg'] },
{ engine: 'd2', file: 'connections.d2', options: { sketch: 'true' }, outputFormat: ['svg'] },
{ engine: 'd2', file: 'connections.d2', options: { scale: '1' }, outputFormat: ['svg'] },
{ engine: 'wireviz', file: 'wireviz.yaml', options: {}, outputFormat: ['svg', 'png'] },
{ engine: 'tikz', file: 'periodic-table.tex', options: {}, outputFormat: ['jpeg', 'pdf', 'png', 'svg'] }
]
Expand Down
2 changes: 1 addition & 1 deletion server/ops/docker/jdk11-jammy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ RUN SVGBOB_VERSION=`cat Cargo.toml | grep "svgbob_cli =" | sed -r 's/.*"([^"]+)"
## yuzutech/kroki
FROM eclipse-temurin:11.0.19_7-jre-jammy

ARG D2_VERSION="0.5.1"
ARG D2_VERSION="0.6.0"
ARG PLANTUML_VERSION="1.2023.10"
ARG UMLET_VERSION="2023-03-20_UMLet_v15.1"
ARG GRAPHVIZ_VERSION="8.0.5"
Expand Down
41 changes: 35 additions & 6 deletions server/src/main/java/io/kroki/server/service/D2.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public class D2 implements DiagramService {
entry("everglade-green", 104),
entry("buttered-toast", 105),
entry("dark-mauve", 200),
entry("dark-flagship-terrastruct", 201),
entry("terminal", 300),
entry("terminal-grayscale", 301)
entry("terminal-grayscale", 301),
entry("origami", 302)
);

public D2(Vertx vertx, JsonObject config, Commander commander) {
Expand All @@ -71,7 +73,7 @@ public SourceDecoder getSourceDecoder() {

@Override
public String getVersion() {
return "0.5.1";
return "0.6.0";
}

@Override
Expand All @@ -89,6 +91,11 @@ public void convert(String sourceDecoded, String serviceName, FileFormat fileFor
private byte[] d2(byte[] source, JsonObject options) throws IOException, InterruptedException, IllegalStateException {
List<String> commands = new ArrayList<>();
commands.add(binPath);
String layout = options.getString("layout");
if (layout != null && layout.equals("elk")) {
// Only pass the layout argument if the ELK layout engine is requested (default is 'dagre')
commands.add("--layout=" + layout);
}
String theme = options.getString("theme");
if (theme != null) {
int themeId = 0;
Expand All @@ -104,15 +111,37 @@ private byte[] d2(byte[] source, JsonObject options) throws IOException, Interru
}
commands.add("--theme=" + themeId);
}
String layout = options.getString("layout");
if (layout != null && layout.equals("elk")) {
// Only pass the layout argument if the ELK layout engine is requested (default is 'dagre')
commands.add("--layout=" + layout);
String darkTheme = options.getString("dark-theme");
if (darkTheme != null) {
int themeId = 0;
Integer builtinThemeId = builtinThemes.get(darkTheme.toLowerCase().replaceAll("\\s", "-"));
if (builtinThemeId != null) {
themeId = builtinThemeId;
} else {
try {
themeId = Integer.parseInt(darkTheme, 10);
} catch (NumberFormatException e) {
// ignore, fallback to 0
}
}
commands.add("--dark-theme=" + themeId);
}
String pad = options.getString("pad");
if (pad != null) {
commands.add("--pad=" + pad);
}
String animateInterval = options.getString("animate-interval");
if (animateInterval != null) {
commands.add("--animate-interval=" + animateInterval);
}
String sketch = options.getString("sketch");
if (sketch != null) {
commands.add("--sketch");
}
String scale = options.getString("scale");
if (scale != null) {
commands.add("--scale=" + scale);
}
commands.add("-"); // read from stdin
return commander.execute(source, commands.toArray(new String[0]));
}
Expand Down

0 comments on commit 2be17fb

Please sign in to comment.