Skip to content

Commit

Permalink
Add support for colors in Chen EER diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Davies committed Sep 15, 2024
1 parent 887bbda commit b2ca2ca
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.decoration.LinkDecor;
import net.sourceforge.plantuml.decoration.LinkType;
import net.sourceforge.plantuml.klimt.color.ColorParser;
import net.sourceforge.plantuml.klimt.color.ColorType;
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
import net.sourceforge.plantuml.klimt.creole.Display;
import net.sourceforge.plantuml.plasma.Quark;
Expand All @@ -69,9 +71,15 @@ protected static IRegex getRegexConcat() {
new RegexLeaf("PARTICIPATION2", "([-=])"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("NAME2", "([\\w-]+)"), //
RegexLeaf.spaceZeroOrMore(), //
color().getRegex(), //
RegexLeaf.end());
}

private static ColorParser color() {
return ColorParser.simpleColor(ColorType.LINE);
}

@Override
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
throws NoSuchColorException {
Expand Down Expand Up @@ -99,6 +107,7 @@ protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation
final Link link = new Link(diagram, diagram.getCurrentStyleBuilder(), entity1, entity2, linkType,
LinkArg.build(Display.getWithNewlines(cardinality), 3));
link.setPortMembers(diagram.getPortId(entity1.getName()), diagram.getPortId(entity2.getName()));
link.setColors(color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet()));
diagram.addLink(link);

return CommandExecutionResult.ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.decoration.LinkDecor;
import net.sourceforge.plantuml.decoration.LinkType;
import net.sourceforge.plantuml.klimt.color.ColorParser;
import net.sourceforge.plantuml.klimt.color.ColorType;
import net.sourceforge.plantuml.klimt.color.Colors;
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
import net.sourceforge.plantuml.klimt.creole.Display;
import net.sourceforge.plantuml.plasma.Quark;
Expand Down Expand Up @@ -74,10 +77,16 @@ protected static IRegex getRegexConcat() {
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("STEREO", "(<<.*>>)?"), //
RegexLeaf.spaceZeroOrMore(), //
color().getRegex(), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("COMPOSITE", "(\\{)?"), //
RegexLeaf.end());
}

private static ColorParser color() {
return ColorParser.simpleColor(ColorType.LINE);
}

@Override
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
throws NoSuchColorException {
Expand All @@ -98,6 +107,8 @@ protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation
final String stereo = arg.get("STEREO", 0);
final boolean composite = arg.get("COMPOSITE", 0) != null;

final Colors colors = color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet());

Entity entity = quark.getData();
if (entity == null) {
final Display display = Display.getWithNewlines(displayText);
Expand All @@ -111,9 +122,12 @@ protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation
entity.setStereostyle(stereo);
}

entity.setColors(colors);

final LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE);
final Link link = new Link(diagram, diagram.getCurrentStyleBuilder(), entity, owner, linkType,
LinkArg.build(Display.NULL, 2));
link.setColors(colors);
diagram.addLink(link);

if (composite) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import net.sourceforge.plantuml.cheneer.ChenEerDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.klimt.color.ColorParser;
import net.sourceforge.plantuml.klimt.color.ColorType;
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
import net.sourceforge.plantuml.klimt.creole.Display;
import net.sourceforge.plantuml.plasma.Quark;
Expand Down Expand Up @@ -73,10 +75,16 @@ protected static IRegex getRegexConcat() {
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("STEREO", "(<<.+>>)?"), //
RegexLeaf.spaceZeroOrMore(), //
color().getRegex(), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("\\{"), //
RegexLeaf.end());
}

private static ColorParser color() {
return ColorParser.simpleColor(ColorType.BACK);
}

@Override
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
throws NoSuchColorException {
Expand Down Expand Up @@ -115,6 +123,8 @@ protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation
entity.setStereostyle(stereo);
}

entity.setColors(color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet()));

diagram.pushOwner(entity);

return CommandExecutionResult.ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.decoration.LinkDecor;
import net.sourceforge.plantuml.decoration.LinkType;
import net.sourceforge.plantuml.klimt.color.ColorParser;
import net.sourceforge.plantuml.klimt.color.ColorType;
import net.sourceforge.plantuml.klimt.color.Colors;
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
import net.sourceforge.plantuml.klimt.creole.Display;
import net.sourceforge.plantuml.plasma.Quark;
Expand Down Expand Up @@ -75,9 +78,15 @@ protected static IRegex getRegexConcat() {
new RegexLeaf("\\{"), //
new RegexLeaf("SUBCLASSES", "(.+)"), //
new RegexLeaf("\\}"), //
RegexLeaf.spaceZeroOrMore(), //
color().getRegex(), //
RegexLeaf.end());
}

private static ColorParser color() {
return ColorParser.simpleColor(ColorType.BACK);
}

@Override
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
throws NoSuchColorException {
Expand All @@ -92,11 +101,15 @@ protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation
final boolean isDouble = arg.get("PARTICIPATION", 0).equals("=");
final String symbol = arg.get("SYMBOL", 0);

final Colors colors = color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet());

final Quark<Entity> centerQuark = diagram.quarkInContext(false,
superclass + "/" + symbol + subclasses + "/center");
final Entity centerEntity = diagram.reallyCreateLeaf(centerQuark, Display.create(symbol), LeafType.CHEN_CIRCLE,
null);

centerEntity.setColors(colors);

final Quark<Entity> superclassQuark = diagram.quarkInContext(true, superclass);
final Entity superclassEntity = superclassQuark.getData();
if (superclassEntity == null) {
Expand All @@ -113,6 +126,7 @@ protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation
final Link link = new Link(diagram, diagram.getCurrentStyleBuilder(), superclassEntity,
centerEntity, linkType, LinkArg.build(Display.NULL, 2));
link.setPortMembers(diagram.getPortId(superclassEntity.getName()), diagram.getPortId(centerEntity.getName()));
link.setColors(colors);
diagram.addLink(link);

for (String subclass : subclassIds) {
Expand All @@ -128,6 +142,7 @@ protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation
}
final Link subclassLink = new Link(diagram, diagram.getCurrentStyleBuilder(), centerEntity,
subclassEntity, subclassLinkType, LinkArg.build(Display.NULL, 3));
subclassLink.setColors(colors);
diagram.addLink(subclassLink);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.decoration.LinkDecor;
import net.sourceforge.plantuml.decoration.LinkType;
import net.sourceforge.plantuml.klimt.color.ColorParser;
import net.sourceforge.plantuml.klimt.color.ColorType;
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
import net.sourceforge.plantuml.klimt.creole.Display;
import net.sourceforge.plantuml.plasma.Quark;
Expand All @@ -67,9 +69,15 @@ protected static IRegex getRegexConcat() {
new RegexLeaf("PARTICIPATION2", "([-=])"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("NAME2", "([\\w-]+)"), //
RegexLeaf.spaceZeroOrMore(), //
color().getRegex(), //
RegexLeaf.end());
}

private static ColorParser color() {
return ColorParser.simpleColor(ColorType.LINE);
}

@Override
protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation location, RegexResult arg)
throws NoSuchColorException {
Expand Down Expand Up @@ -102,6 +110,7 @@ protected CommandExecutionResult executeArg(ChenEerDiagram diagram, LineLocation
final Link link = new Link(diagram, diagram.getCurrentStyleBuilder(), entity1, entity2,
linkType, LinkArg.build(Display.NULL, 3));
link.setPortMembers(diagram.getPortId(entity1.getName()), diagram.getPortId(entity2.getName()));
link.setColors(color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet()));
diagram.addLink(link);

return CommandExecutionResult.ok();
Expand Down
14 changes: 7 additions & 7 deletions test/nonreg/simple/ChenMovieExtended_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
Age
}
entity CUSTOMER {
Number <<key>>
entity CUSTOMER #lightblue;line:blue {
Number <<key>> #lime;line:orange
Bonus <<derived>>
Name <<multi>>
}
Expand All @@ -34,11 +34,11 @@
Code
}
relationship RENTED_TO {
relationship RENTED_TO #pink;line:red {
Date
}
RENTED_TO -1- CUSTOMER
RENTED_TO -1- CUSTOMER #lime
RENTED_TO -N- MOVIE
RENTED_TO -(N,M)- DIRECTOR
Expand All @@ -48,8 +48,8 @@
entity MEMBER {
}
CUSTOMER ->- PARENT
MEMBER -<- CUSTOMER
CUSTOMER ->- PARENT #line:purple
MEMBER -<- CUSTOMER #line:purple
entity CHILD <<weak>> {
Name <<key>>
Expand Down Expand Up @@ -78,7 +78,7 @@
entity PERSON {
}
PERSON ->- U { CUSTOMER, DIRECTOR }
PERSON ->- U { CUSTOMER, DIRECTOR } #lime;line:green
@endchen
"""
Expand Down
30 changes: 15 additions & 15 deletions test/nonreg/simple/ChenMovieExtended_TestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class ChenMovieExtended_TestResult {
DPI: 96
dimension: [ 1617.3106 ; 720.0000 ]
scaleFactor: 1.0000
seed: -7760046765121812191
seed: -8173812650123393805
svgLinkTarget: _top
hoverPathColorRGB: null
preserveAspectRatio: none
Expand Down Expand Up @@ -163,8 +163,8 @@ public class ChenMovieExtended_TestResult {
yCorner: 0
stroke: 0.0-0.0-0.5
shadow: 0
color: ff181818
backcolor: fff1f1f1
color: ff0000ff
backcolor: ffadd8e6
TEXT:
text: CUSTOMER
Expand All @@ -181,7 +181,7 @@ public class ChenMovieExtended_TestResult {
extend: 0.0
stroke: 0.0-0.0-0.5
shadow: 0
color: ff181818
color: ffffa500
backcolor: fff1f1f1
TEXT:
Expand Down Expand Up @@ -282,8 +282,8 @@ public class ChenMovieExtended_TestResult {
- [ 744.2105 ; 173.7105 ]
stroke: 0.0-0.0-0.5
shadow: 0
color: ff181818
backcolor: fff1f1f1
color: ffff0000
backcolor: ffffc0cb
TEXT:
text: RENTED_TO
Expand Down Expand Up @@ -574,8 +574,8 @@ public class ChenMovieExtended_TestResult {
extend: 0.0
stroke: 0.0-0.0-0.5
shadow: 0
color: ff181818
backcolor: fff1f1f1
color: ff008000
backcolor: ff00ff00
TEXT:
text: U
Expand Down Expand Up @@ -686,7 +686,7 @@ public class ChenMovieExtended_TestResult {
pt3: [ 1189.8552 ; 303.8761 ]
stroke: 0.0-0.0-1.0
shadow: 0
color: ff181818
color: ffffa500
backcolor: NULL_COLOR
PATH:
Expand Down Expand Up @@ -754,7 +754,7 @@ public class ChenMovieExtended_TestResult {
pt3: [ 1157.8461 ; 313.3561 ]
stroke: 0.0-0.0-1.0
shadow: 0
color: ff181818
color: ff00ff00
backcolor: NULL_COLOR
EMPTY:
Expand Down Expand Up @@ -842,7 +842,7 @@ public class ChenMovieExtended_TestResult {
pt3: [ 1283.8492 ; 458.6705 ]
stroke: 0.0-0.0-1.0
shadow: 0
color: ff181818
color: ff800080
backcolor: NULL_COLOR
PATH:
Expand All @@ -862,7 +862,7 @@ public class ChenMovieExtended_TestResult {
pt3: [ 1252.5110 ; 303.9427 ]
stroke: 0.0-0.0-1.0
shadow: 0
color: ff181818
color: ff800080
backcolor: NULL_COLOR
PATH:
Expand Down Expand Up @@ -1046,7 +1046,7 @@ public class ChenMovieExtended_TestResult {
pt3: [ 909.0000 ; 109.9627 ]
stroke: 0.0-0.0-1.0
shadow: 0
color: ff181818
color: ff008000
backcolor: NULL_COLOR
PATH:
Expand All @@ -1066,7 +1066,7 @@ public class ChenMovieExtended_TestResult {
pt3: [ 1258.4998 ; 303.8713 ]
stroke: 0.0-0.0-1.0
shadow: 0
color: ff181818
color: ff008000
backcolor: NULL_COLOR
PATH:
Expand All @@ -1086,7 +1086,7 @@ public class ChenMovieExtended_TestResult {
pt3: [ 407.8635 ; 314.6541 ]
stroke: 0.0-0.0-1.0
shadow: 0
color: ff181818
color: ff008000
backcolor: NULL_COLOR
"""
Expand Down

0 comments on commit b2ca2ca

Please sign in to comment.