Skip to content

Commit 004d75b

Browse files
committed
add attribute validator to serializer
Signed-off-by: Stefan Niederhauser <[email protected]>
1 parent b85d0e3 commit 004d75b

24 files changed

+909
-570
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,12 @@ final Graph g = graph("ex1").directed().with(
427427
.nodeAttr().with(Style.FILLED)
428428
.graphAttr().with(Color.BLUE, Label.of("process #2"))
429429
.with(node("b0").link(node("b1").link(node("b2")))),
430-
node("start").with(Shape.mDiamond("", "")).link("a0", "b0"),
430+
node("start").with(Shape.M_DIAMOND).link("a0", "b0"),
431431
node("a0").with(Style.FILLED, Color.RED.gradient(Color.BLUE)).link("b1"),
432432
node("b1").link("a2"),
433433
node("a2").link("end"),
434434
node("b2").link("end"),
435-
node("end").with(Shape.mSquare("", ""))
435+
node("end").with(Shape.M_SQUARE)
436436
);
437437

438438
Graphviz.fromGraph(g)

graphviz-java/src/main/java/guru/nidi/graphviz/attribute/Shape.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
import javax.annotation.Nullable;
1919

20-
import static guru.nidi.graphviz.attribute.Attributes.attr;
21-
import static guru.nidi.graphviz.attribute.Attributes.attrs;
2220
import static guru.nidi.graphviz.attribute.NodeAttr.nodeAttr;
2321

2422
public final class Shape extends SingleAttributes<String, ForNode> {
@@ -76,7 +74,7 @@ public final class Shape extends SingleAttributes<String, ForNode> {
7674
SIGNATURE = new Shape("signature"),
7775
INSULATOR = new Shape("insulator"),
7876
RIBO_SITE = new Shape("ribosite"),
79-
RNA_STAB= new Shape("rnastab"),
77+
RNA_STAB = new Shape("rnastab"),
8078
PROTEASE_SITE = new Shape("proteasesite"),
8179
PROTEIN_STAB = new Shape("proteinstab"),
8280
R_PROMOTER = new Shape("rpromoter"),

graphviz-java/src/main/java/guru/nidi/graphviz/attribute/validate/AttributeConfig.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,26 @@
2525
import static java.util.Collections.singletonList;
2626

2727
final class AttributeConfig {
28-
enum Engine {
29-
//TODO make public or unify with oter engine enum
30-
CIRCO, NOT_DOT, DOT, NEATO, OSAGE, TWOPI, FDP, SFDP, PATCHWORK
31-
}
32-
33-
enum Format {
34-
//TODO make public or unify with oter format enum
35-
WRITE, SVG, BITMAP, MAP, CMAP, POSTSCRIPT, XDOT
36-
}
37-
28+
final EnumSet<Scope> scopes;
3829
final List<Datatype> types;
3930
@Nullable
4031
final Object defVal;
4132
@Nullable
4233
final Double min;
43-
final EnumSet<Engine> engines;
44-
final EnumSet<Format> formats;
45-
final EnumSet<Scope> scopes;
34+
@Nullable
35+
final Double max;
36+
final EnumSet<ValidatorEngine> engines;
37+
final EnumSet<ValidatorFormat> formats;
4638

47-
private AttributeConfig(@Nullable EnumSet<Scope> scopes, List<Datatype> types, @Nullable Object defVal,
48-
@Nullable Double min, @Nullable EnumSet<Engine> engines,
49-
@Nullable EnumSet<Format> formats) {
50-
this.scopes = scopes == null ? EnumSet.noneOf(Scope.class) : scopes;
39+
private AttributeConfig(EnumSet<Scope> scopes, List<Datatype> types, @Nullable Object defVal, @Nullable Double min,
40+
@Nullable Double max, EnumSet<ValidatorEngine> engines, EnumSet<ValidatorFormat> formats) {
41+
this.scopes = scopes;
5142
this.types = types;
5243
this.defVal = defVal;
5344
this.min = min;
54-
this.engines = engines == null ? EnumSet.noneOf(Engine.class) : engines;
55-
this.formats = formats == null ? EnumSet.noneOf(Format.class) : formats;
45+
this.max = max;
46+
this.engines = engines;
47+
this.formats = formats;
5648
}
5749

5850
static AttributeConfig entry(String scopes, Datatype type) {
@@ -75,16 +67,27 @@ static AttributeConfig entry(String scopes, Datatype type, @Nullable Object defV
7567
return entry(scopes, singletonList(type), defVal, min);
7668
}
7769

70+
static AttributeConfig entry(String scopes, Datatype type, @Nullable Object defVal,
71+
@Nullable Double min, @Nullable Double max) {
72+
return entry(scopes, singletonList(type), defVal, min, max);
73+
}
74+
7875
static AttributeConfig entry(String scopes, List<Datatype> types, @Nullable Object defVal, @Nullable Double min) {
79-
return new AttributeConfig(scopesOf(scopes), types, defVal, min, null, null);
76+
return entry(scopes, types, defVal, min, null);
77+
}
78+
79+
static AttributeConfig entry(String scopes, List<Datatype> types, @Nullable Object defVal,
80+
@Nullable Double min, @Nullable Double max) {
81+
return new AttributeConfig(scopesOf(scopes), types, defVal, min,
82+
max, EnumSet.noneOf(ValidatorEngine.class), EnumSet.noneOf(ValidatorFormat.class));
8083
}
8184

82-
AttributeConfig engines(Engine... engines) {
83-
return new AttributeConfig(scopes, types, defVal, min, EnumSet.of(engines[0], engines), formats);
85+
AttributeConfig engines(ValidatorEngine... engines) {
86+
return new AttributeConfig(scopes, types, defVal, min, max, EnumSet.of(engines[0], engines), formats);
8487
}
8588

86-
AttributeConfig formats(Format... formats) {
87-
return new AttributeConfig(scopes, types, defVal, min, engines, EnumSet.of(formats[0], formats));
89+
AttributeConfig formats(ValidatorFormat... formats) {
90+
return new AttributeConfig(scopes, types, defVal, min, max, engines, EnumSet.of(formats[0], formats));
8891
}
8992

9093
private static EnumSet<Scope> scopesOf(String scopes) {

graphviz-java/src/main/java/guru/nidi/graphviz/attribute/validate/AttributeConfigs.java

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@
1717

1818
import java.util.*;
1919

20-
import static guru.nidi.graphviz.attribute.validate.AttributeConfig.Engine.*;
21-
import static guru.nidi.graphviz.attribute.validate.AttributeConfig.Format.*;
2220
import static guru.nidi.graphviz.attribute.validate.AttributeConfig.entry;
2321
import static guru.nidi.graphviz.attribute.validate.Datatypes.*;
22+
import static guru.nidi.graphviz.attribute.validate.ValidatorEngine.*;
23+
import static guru.nidi.graphviz.attribute.validate.ValidatorFormat.*;
2424
import static java.util.Arrays.asList;
2525
import static java.util.Collections.singletonList;
2626

2727
final class AttributeConfigs {
2828
private static final double EPSILON = 1e-8;
29-
private static final Map<String, List<AttributeConfig>> MAP = new HashMap<>();
29+
private static final Map<String, List<AttributeConfig>> CONFIG = new HashMap<>();
3030

3131
private AttributeConfigs() {
3232
}
3333

3434
static List<AttributeConfig> get(String name) {
35-
return MAP.get(name);
35+
return CONFIG.get(name);
3636
}
3737

3838
static {
3939
add("Damping", entry("G", DOUBLE, 0.99, 0.0).engines(NEATO));
4040
add("K", entry("GC", DOUBLE, 0.3, 0.0).engines(SFDP, FDP));
41-
add("URL", entry("ENGC", ESC_STRING).formats(SVG, POSTSCRIPT, AttributeConfig.Format.MAP));
41+
add("URL", entry("ENGC", ESC_STRING).formats(SVG, POSTSCRIPT, MAP));
4242
add("_background", entry("G", STRING));
4343
add("area", entry("NC", DOUBLE, 1.0, EPSILON).engines(PATCHWORK));
4444
add("arrowhead", entry("E", ARROW_TYPE, "normal"));
@@ -63,9 +63,9 @@ static List<AttributeConfig> get(String name) {
6363
add("diredgeconstraints", entry("G", asList(STRING, BOOL), false).engines(NEATO));
6464
add("distortion", entry("N", DOUBLE, 0.0, -100.0));
6565
add("dpi", entry("G", DOUBLE, 72.0).formats(SVG, BITMAP));
66-
add("edgeURL", entry("E", ESC_STRING, "").formats(SVG, AttributeConfig.Format.MAP));
67-
add("edgehref", entry("E", ESC_STRING, "").formats(SVG, AttributeConfig.Format.MAP));
68-
add("edgetarget", entry("E", ESC_STRING).formats(SVG, AttributeConfig.Format.MAP));
66+
add("edgeURL", entry("E", ESC_STRING, "").formats(SVG, MAP));
67+
add("edgehref", entry("E", ESC_STRING, "").formats(SVG, MAP));
68+
add("edgetarget", entry("E", ESC_STRING).formats(SVG, MAP));
6969
add("edgetooltip", entry("E", ESC_STRING, "").formats(SVG, CMAP));
7070
add("epsilon", entry("G", DOUBLE, ".0001 * # nodes(mode == KK)<BR>.0001(mode == major)").engines(NEATO));
7171
add("esep", entry("G", asList(ADD_DOUBLE, ADD_POINT), "+3").engines(NOT_DOT));
@@ -79,35 +79,35 @@ static List<AttributeConfig> get(String name) {
7979
add("forcelabels", entry("G", BOOL, true));
8080
add("gradientangle", entry("NCG", INT, 0));
8181
add("group", entry("N", STRING, "").engines(DOT));
82-
add("headURL", entry("E", ESC_STRING, "").formats(SVG, AttributeConfig.Format.MAP));
82+
add("headURL", entry("E", ESC_STRING, "").formats(SVG, MAP));
8383
add("head_lp", entry("E", POINT).formats(WRITE));
8484
add("headclip", entry("E", BOOL, true));
85-
add("headhref", entry("E", ESC_STRING, "").formats(SVG, AttributeConfig.Format.MAP));
85+
add("headhref", entry("E", ESC_STRING, "").formats(SVG, MAP));
8686
add("headlabel", entry("E", LBL_STRING, ""));
8787
add("headport", entry("E", PORT_POS, "center"));
88-
add("headtarget", entry("E", ESC_STRING).formats(SVG, AttributeConfig.Format.MAP));
88+
add("headtarget", entry("E", ESC_STRING).formats(SVG, MAP));
8989
add("headtooltip", entry("E", ESC_STRING, "").formats(SVG, CMAP));
9090
add("height", entry("N", DOUBLE, 0.5, 0.02));
91-
add("href", entry("GCNE", ESC_STRING, "").formats(SVG, POSTSCRIPT, AttributeConfig.Format.MAP));
92-
add("id", entry("GCNE", ESC_STRING, "").formats(SVG, POSTSCRIPT, AttributeConfig.Format.MAP));
91+
add("href", entry("GCNE", ESC_STRING, "").formats(SVG, POSTSCRIPT, MAP));
92+
add("id", entry("GCNE", ESC_STRING, "").formats(SVG, POSTSCRIPT, MAP));
9393
add("image", entry("N", STRING, ""));
9494
add("imagepath", entry("G", STRING, ""));
9595
add("imagepos", entry("N", STRING, "mc"));
9696
add("imagescale", entry("N", BOOL, false));
9797
add("inputscale", entry("G", DOUBLE).engines(FDP, NEATO));
9898
add("label", entry("ENGC", LBL_STRING, "\\N(nodes)<BR>''(otherwise)"));
99-
add("labelURL", entry("E", ESC_STRING, "").formats(SVG, AttributeConfig.Format.MAP));
99+
add("labelURL", entry("E", ESC_STRING, "").formats(SVG, MAP));
100100
add("label_scheme", entry("G", INT, 0, 0.0).engines(SFDP));
101101
add("labelangle", entry("E", DOUBLE, -25.0, -180.0));
102102
add("labeldistance", entry("E", DOUBLE, 1.0, 0.0));
103103
add("labelfloat", entry("E", BOOL, false));
104104
add("labelfontcolor", entry("E", COLOR, "black"));
105105
add("labelfontname", entry("E", STRING, "Times-Roman"));
106106
add("labelfontsize", entry("E", DOUBLE, 14.0, 1.0));
107-
add("labelhref", entry("E", ESC_STRING, "").formats(SVG, AttributeConfig.Format.MAP));
107+
add("labelhref", entry("E", ESC_STRING, "").formats(SVG, MAP));
108108
add("labeljust", entry("GC", STRING, "c"));
109109
add("labelloc", entry("NGC", STRING, "'t'(clusters)<BR>'b'(root graphs)<BR>'c'(nodes)"));
110-
add("labeltarget", entry("E", ESC_STRING).formats(SVG, AttributeConfig.Format.MAP));
110+
add("labeltarget", entry("E", ESC_STRING).formats(SVG, MAP));
111111
add("labeltooltip", entry("E", ESC_STRING, "").formats(SVG, CMAP));
112112
add("landscape", entry("G", BOOL, false));
113113
add("layer", entry("ENC", LAYER_RANGE, ""));
@@ -140,7 +140,9 @@ static List<AttributeConfig> get(String name) {
140140
add("nslimit", entry("G", DOUBLE).engines(DOT));
141141
add("nslimit1", entry("G", DOUBLE).engines(DOT));
142142
add("ordering", entry("GN", STRING, "").engines(DOT));
143-
add("orientation", entry("N", DOUBLE, 0.0, 360.0), entry("G", STRING, ""));
143+
add("orientation",
144+
entry("N", DOUBLE, 0.0, 0.0, 360.0),
145+
entry("G", STRING, ""));
144146
add("outputorder", entry("G", OUTPUT_MODE, "breadthfirst"));
145147
add("overlap", entry("G", asList(STRING, BOOL), true).engines(NOT_DOT));
146148
add("overlap_scaling", entry("G", DOUBLE, -4.0, -1.0e10)); //TODO prism only
@@ -187,15 +189,15 @@ static List<AttributeConfig> get(String name) {
187189
add("start", entry("G", START_TYPE, "").engines(FDP, NEATO));
188190
add("style", entry("ENCG", STYLE, ""));
189191
add("stylesheet", entry("G", STRING, "").formats(SVG));
190-
add("tailURL", entry("E", ESC_STRING, "").formats(SVG, AttributeConfig.Format.MAP));
192+
add("tailURL", entry("E", ESC_STRING, "").formats(SVG, MAP));
191193
add("tail_lp", entry("E", POINT).formats(WRITE));
192194
add("tailclip", entry("E", BOOL, true));
193-
add("tailhref", entry("E", ESC_STRING, "").formats(SVG, AttributeConfig.Format.MAP));
195+
add("tailhref", entry("E", ESC_STRING, "").formats(SVG, MAP));
194196
add("taillabel", entry("E", LBL_STRING, ""));
195197
add("tailport", entry("E", PORT_POS, "center"));
196-
add("tailtarget", entry("E", ESC_STRING).formats(SVG, AttributeConfig.Format.MAP));
198+
add("tailtarget", entry("E", ESC_STRING).formats(SVG, MAP));
197199
add("tailtooltip", entry("E", ESC_STRING, "").formats(SVG, CMAP));
198-
add("target", entry("ENGC", asList(ESC_STRING, STRING)).formats(SVG, AttributeConfig.Format.MAP));
200+
add("target", entry("ENGC", asList(ESC_STRING, STRING)).formats(SVG, MAP));
199201
add("tooltip", entry("NEC", ESC_STRING, "").formats(SVG, CMAP));
200202
add("truecolor", entry("G", BOOL).formats(BITMAP));
201203
add("vertices", entry("N", POINT_LIST).formats(WRITE));
@@ -212,10 +214,10 @@ static List<AttributeConfig> get(String name) {
212214
}
213215

214216
private static void add(String name, AttributeConfig entry) {
215-
MAP.put(name, singletonList(entry));
217+
CONFIG.put(name, singletonList(entry));
216218
}
217219

218220
private static void add(String name, AttributeConfig... entries) {
219-
MAP.put(name, asList(entries));
221+
CONFIG.put(name, asList(entries));
220222
}
221223
}

0 commit comments

Comments
 (0)