1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-21 20:45:10 +00:00

Improve style support for nwdiag

This commit is contained in:
Arnaud Roques 2021-09-15 23:03:09 +02:00
parent e1fe53457a
commit b3bf75e0b7
17 changed files with 141 additions and 57 deletions

View File

@ -357,3 +357,16 @@ timingDiagram {
}
}
nwdiagDiagram {
network {
FontSize 12
Shadowing 1.0
}
server {
FontSize 12
}
group {
FontSize 12
BackGroundColor #ddd
}
}

View File

@ -122,6 +122,9 @@ public class SkinParam implements ISkinParam {
if (type == UmlDiagramType.YAML) {
UseStyle.setBetaStyle(true);
}
if (type == UmlDiagramType.NWDIAG) {
UseStyle.setBetaStyle(true);
}
if (type == UmlDiagramType.SEQUENCE) {
// skin = "debug.skin";
// USE_STYLE2.set(true);

View File

@ -71,8 +71,13 @@ import net.sourceforge.plantuml.nwdiag.next.LinkedElement;
import net.sourceforge.plantuml.nwdiag.next.NBar;
import net.sourceforge.plantuml.nwdiag.next.NPlayField;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.style.StyleSignature;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.MinMax;
import net.sourceforge.plantuml.ugraphic.UBackground;
import net.sourceforge.plantuml.ugraphic.UEmpty;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.UGraphic;
@ -260,19 +265,22 @@ public class NwDiagram extends UmlDiagram {
};
}
private StyleSignature getStyleDefinitionNetwork() {
return StyleSignature.of(SName.root, SName.element, SName.nwdiagDiagram, SName.network);
}
private TextBlock toTextBlock(String name, String s) {
if (s != null) {
name += "\\n" + s;
}
return Display.getWithNewlines(name).create(getFontConfiguration(), HorizontalAlignment.RIGHT,
final StyleBuilder styleBuilder = getSkinParam().getCurrentStyleBuilder();
final Style style = getStyleDefinitionNetwork().getMergedStyle(styleBuilder);
final FontConfiguration fontConfiguration = style.getFontConfiguration(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet());
return Display.getWithNewlines(name).create(fontConfiguration, HorizontalAlignment.RIGHT,
new SpriteContainerEmpty());
}
private FontConfiguration getFontConfiguration() {
final UFont font = UFont.serif(11);
return new FontConfiguration(font, HColorUtils.BLACK, HColorUtils.BLACK, false);
}
private Dimension2D getTotalDimension(StringBounder stringBounder) {
return TextBlockUtils.getMinMax(new UDrawable() {
public void drawU(UGraphic ug) {
@ -315,8 +323,7 @@ public class NwDiagram extends UmlDiagram {
}
deltaX += 5;
grid.drawU(ug.apply(ColorParam.activityBorder.getDefaultValue())
.apply(ColorParam.activityBackground.getDefaultValue().bg()).apply(new UTranslate(deltaX, deltaY)));
grid.drawU(ug.apply(new UTranslate(deltaX, deltaY)));
final Dimension2D dimGrid = grid.calculateDimension(stringBounder);
ug.apply(new UTranslate(dimGrid.getWidth() + deltaX + margin, dimGrid.getHeight() + deltaY + margin))
@ -383,7 +390,7 @@ public class NwDiagram extends UmlDiagram {
}
if ("color".equalsIgnoreCase(property)) {
final HColor color = value == null ? null
: NwGroup.colors.getColorOrWhite(getSkinParam().getThemeStyle(), value);
: getSkinParam().getIHtmlColorSet().getColorOrWhite(getSkinParam().getThemeStyle(), value);
if (currentGroup != null) {
currentGroup.setColor(color);
} else if (currentNetwork() != null) {

View File

@ -42,7 +42,6 @@ import java.util.Map.Entry;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.ComponentStyle;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
@ -50,7 +49,6 @@ import net.sourceforge.plantuml.graphic.SymbolContext;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.graphic.USymbol;
import net.sourceforge.plantuml.mindmap.IdeaShape;
import net.sourceforge.plantuml.nwdiag.next.LinkedElement;
import net.sourceforge.plantuml.nwdiag.next.NBar;
import net.sourceforge.plantuml.skin.ActorStyle;
@ -90,7 +88,7 @@ public class NServer {
return connections.get(network);
}
protected final TextBlock toTextBlock(String s, ISkinSimple spriteContainer) {
private TextBlock toTextBlock(String s, ISkinParam skinParam) {
if (s == null) {
return null;
}
@ -98,29 +96,31 @@ public class NServer {
return TextBlockUtils.empty(0, 0);
}
s = s.replace(", ", "\\n");
return Display.getWithNewlines(s).create(getFontConfiguration(), HorizontalAlignment.LEFT, spriteContainer);
return Display.getWithNewlines(s).create(getFontConfiguration(skinParam), HorizontalAlignment.LEFT, skinParam);
}
private StyleSignature getStyleDefinition() {
return StyleSignature.of(SName.root, SName.element, SName.nwdiagDiagram, SName.node);
return StyleSignature.of(SName.root, SName.element, SName.nwdiagDiagram, SName.server);
}
private FontConfiguration getFontConfiguration(ISkinParam skinParam) {
final StyleBuilder styleBuilder = skinParam.getCurrentStyleBuilder();
final Style style = getStyleDefinition().getMergedStyle(styleBuilder);
return style.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet());
}
public LinkedElement asTextBlock(double topMargin, Map<Network, String> conns, List<Network> networks,
ISkinParam skinParam) {
double deltaShadow = 3;
final StyleBuilder styleBuilder = skinParam.getCurrentStyleBuilder();
if (styleBuilder != null) {
final Style style = getStyleDefinition().getMergedStyle(styleBuilder);
deltaShadow = style.value(PName.Shadowing).asDouble();
}
final Style style = getStyleDefinition().getMergedStyle(styleBuilder);
final SymbolContext symbolContext = style.getSymbolContext(skinParam.getThemeStyle(),
skinParam.getIHtmlColorSet());
final Map<Network, TextBlock> conns2 = new LinkedHashMap<Network, TextBlock>();
for (Entry<Network, String> ent : conns.entrySet()) {
conns2.put(ent.getKey(), toTextBlock(ent.getValue(), skinParam));
}
final SymbolContext symbolContext = new SymbolContext(ColorParam.activityBackground.getDefaultValue(),
ColorParam.activityBorder.getDefaultValue()).withShadow(deltaShadow);
final TextBlock desc = toTextBlock(getDescription(), skinParam);
final TextBlock box = getShape().asSmall(TextBlockUtils.empty(0, 0), desc, TextBlockUtils.empty(0, 0),
symbolContext, HorizontalAlignment.CENTER);
@ -156,11 +156,6 @@ public class NServer {
this.name = name;
}
protected final FontConfiguration getFontConfiguration() {
final UFont font = UFont.serif(11);
return new FontConfiguration(font, HColorUtils.BLACK, HColorUtils.BLACK, false);
}
public final String getDescription() {
return description;
}

View File

@ -48,18 +48,20 @@ import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.nwdiag.next.NBox;
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.style.StyleSignature;
import net.sourceforge.plantuml.ugraphic.MinMax;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class NwGroup {
public static final HColorSet colors = HColorSet.instance();
private final Set<String> names = new HashSet<>();
private final String name;
@ -115,11 +117,6 @@ public class NwGroup {
this.description = value;
}
public final FontConfiguration getGroupDescriptionFontConfiguration() {
final UFont font = UFont.serif(11);
return new FontConfiguration(font, HColorUtils.BLACK, HColorUtils.BLACK, false);
}
protected final String getDescription() {
return description;
}
@ -141,7 +138,13 @@ public class NwGroup {
return blockDim.getHeight();
}
private StyleSignature getStyleDefinition() {
return StyleSignature.of(SName.root, SName.element, SName.nwdiagDiagram, SName.group);
}
public void drawGroup(UGraphic ug, MinMax size, ISkinParam skinParam) {
final StyleBuilder styleBuilder = skinParam.getCurrentStyleBuilder();
final Style style = getStyleDefinition().getMergedStyle(styleBuilder);
final TextBlock block = buildHeaderName(skinParam);
if (block != null) {
final Dimension2D blockDim = block.calculateDimension(ug.getStringBounder());
@ -150,7 +153,8 @@ public class NwGroup {
}
HColor color = getColor();
if (color == null) {
color = colors.getColorOrWhite(skinParam.getThemeStyle(), "#AAA");
color = style.value(PName.BackGroundColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet());
}
size.draw(ug, color);
@ -163,7 +167,10 @@ public class NwGroup {
if (getDescription() == null) {
return null;
}
return Display.getWithNewlines(getDescription()).create(getGroupDescriptionFontConfiguration(),
final StyleBuilder styleBuilder = skinParam.getCurrentStyleBuilder();
final Style style = getStyleDefinition().getMergedStyle(styleBuilder);
return Display.getWithNewlines(getDescription()).create(
style.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()),
HorizontalAlignment.LEFT, skinParam);
}

View File

@ -125,11 +125,11 @@ public class GridTextBlockDecorated extends GridTextBlockSimple {
return false;
}
private StyleSignature getStyleDefinition() {
return StyleSignature.of(SName.root, SName.element, SName.nwdiagDiagram, SName.node);
private StyleSignature getStyleDefinitionNetwork() {
return StyleSignature.of(SName.root, SName.element, SName.nwdiagDiagram, SName.network);
}
private void drawNetworkTube(final UGraphic ug) {
private void drawNetworkTube(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
double y = 0;
@ -138,15 +138,17 @@ public class GridTextBlockDecorated extends GridTextBlockSimple {
computeMixMax(data.getLine(i), stringBounder, network);
final URectangle rect = new URectangle(network.getXmax() - network.getXmin(), NETWORK_THIN);
double deltaShadow = 1.0;
UGraphic ug2 = ug.apply(new UTranslate(network.getXmin(), y));
final StyleBuilder styleBuilder = getSkinParam().getCurrentStyleBuilder();
if (styleBuilder != null) {
final Style style = getStyleDefinition().getMergedStyle(styleBuilder);
deltaShadow = style.value(PName.Shadowing).asDouble();
}
final Style style = getStyleDefinitionNetwork().getMergedStyle(styleBuilder);
final double deltaShadow = style.value(PName.Shadowing).asDouble();
ug2 = ug2.apply(style.value(PName.LineColor).asColor(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet()));
ug2 = ug2.apply(style.value(PName.BackGroundColor)
.asColor(getSkinParam().getThemeStyle(), getSkinParam().getIHtmlColorSet()).bg());
rect.setDeltaShadow(deltaShadow);
UGraphic ug2 = ug.apply(new UTranslate(network.getXmin(), y));
if (network != null && network.getColor() != null) {
ug2 = ug2.apply(network.getColor().bg());
}

View File

@ -316,7 +316,7 @@ public class GanttDiagram extends TitledDiagram implements ToTaskDraw, WithSprit
private TimeHeader getTimeHeader() {
if (openClose.getCalendar() == null) {
return new TimeHeaderSimple(getTimelineStyle(), getClosedStyle(), getFactorScale(), min, max,
getIHtmlColorSet(), getSkinParam().getThemeStyle());
getIHtmlColorSet(), getSkinParam().getThemeStyle(), colorDays());
} else if (printScale == PrintScale.DAILY) {
return new TimeHeaderDaily(locale, getTimelineStyle(), getClosedStyle(), getFactorScale(),
openClose.getCalendar(), min, max, openClose, colorDays(), colorDaysOfWeek, nameDays, printStart,

View File

@ -41,11 +41,8 @@ import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.command.regex.IRegex;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.command.regex.RegexOptional;
import net.sourceforge.plantuml.command.regex.RegexOr;
import net.sourceforge.plantuml.command.regex.RegexResult;
import net.sourceforge.plantuml.project.GanttDiagram;
import net.sourceforge.plantuml.project.core.PrintScale;
public class CommandLanguage extends SingleLineCommand2<GanttDiagram> {

View File

@ -55,7 +55,6 @@ import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorNone;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public abstract class TimeHeader {

View File

@ -65,6 +65,7 @@ public abstract class TimeHeaderCalendar extends TimeHeader {
this.colorDaysOfWeek = colorDaysOfWeek;
}
// Duplicate in TimeHeaderSimple
class Pending {
final double x1;
double x2;

View File

@ -50,7 +50,6 @@ import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class TimeHeaderDaily extends TimeHeaderCalendar {

View File

@ -50,7 +50,6 @@ import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class TimeHeaderQuarterly extends TimeHeaderCalendar {

View File

@ -35,6 +35,8 @@
*/
package net.sourceforge.plantuml.project.draw;
import java.util.Map;
import net.sourceforge.plantuml.SpriteContainerEmpty;
import net.sourceforge.plantuml.ThemeStyle;
import net.sourceforge.plantuml.cucadiagram.Display;
@ -47,11 +49,13 @@ import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class TimeHeaderSimple extends TimeHeader {
private final Map<Day, HColor> colorDays;
@Override
public double getFullHeaderHeight() {
return getTimeHeaderHeight() + getHeaderNameDayHeight();
@ -70,8 +74,9 @@ public class TimeHeaderSimple extends TimeHeader {
}
public TimeHeaderSimple(Style timelineStyle, Style closedStyle, double scale, Day min, Day max, HColorSet colorSet,
ThemeStyle themeStyle) {
ThemeStyle themeStyle, Map<Day, HColor> colorDays) {
super(timelineStyle, closedStyle, min, max, new TimeScaleWink(scale), colorSet, themeStyle);
this.colorDays = colorDays;
}
private void drawSmallVlinesDay(UGraphic ug, TimeScale timeScale, double totalHeightWithoutFooter) {
@ -100,6 +105,7 @@ public class TimeHeaderSimple extends TimeHeader {
@Override
public void drawTimeHeader(final UGraphic ug, double totalHeightWithoutFooter) {
drawTextsBackground(ug.apply(UTranslate.dy(-3)), totalHeightWithoutFooter + 6);
final double xmin = getTimeScale().getStartingPosition(min);
final double xmax = getTimeScale().getEndingPosition(max);
drawSmallVlinesDay(ug, getTimeScale(), totalHeightWithoutFooter);
@ -119,4 +125,56 @@ public class TimeHeaderSimple extends TimeHeader {
ug.apply(getBarColor()).draw(ULine.hline(xmax - xmin));
}
// Duplicate in TimeHeaderDaily
class Pending {
final double x1;
double x2;
final HColor color;
Pending(HColor color, double x1, double x2) {
this.x1 = x1;
this.x2 = x2;
this.color = color;
}
public void draw(UGraphic ug, double height) {
drawRectangle(ug.apply(color.bg()), height, x1, x2);
}
}
protected final void drawTextsBackground(UGraphic ug, double totalHeightWithoutFooter) {
final double height = totalHeightWithoutFooter - getFullHeaderHeight();
Pending pending = null;
for (Day wink = min; wink.compareTo(max) <= 0; wink = wink.increment()) {
final double x1 = getTimeScale().getStartingPosition(wink);
final double x2 = getTimeScale().getEndingPosition(wink);
HColor back = colorDays.get(wink);
// // Day of week should be stronger than period of time (back color).
// final HColor backDoW = colorDaysOfWeek.get(wink.getDayOfWeek());
// if (backDoW != null) {
// back = backDoW;
// }
// if (back == null && defaultPlan.getLoadAt(wink) == 0) {
// back = closedBackgroundColor();
// }
if (back == null) {
if (pending != null)
pending.draw(ug, height);
pending = null;
} else {
if (pending != null && pending.color.equals(back) == false) {
pending.draw(ug, height);
pending = null;
}
if (pending == null) {
pending = new Pending(back, x1, x2);
} else {
pending.x2 = x2;
}
}
}
}
}

View File

@ -50,7 +50,6 @@ import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class TimeHeaderYearly extends TimeHeaderCalendar {

View File

@ -87,6 +87,7 @@ public enum SName {
lifeLine, //
milestone, //
mindmapDiagram, //
network, //
node, //
note, //
nwdiagDiagram, //
@ -104,6 +105,7 @@ public enum SName {
saltDiagram, //
separator, //
sequenceDiagram, //
server, //
stack, //
stateDiagram, //
stereotype, //

View File

@ -149,6 +149,9 @@ public class HColorSimple extends HColorAbstract implements HColor {
final float[] hsl1 = col1.getHSL();
final float[] hsl2 = col2.getHSL();
if (completionInt > 100)
completionInt = 100;
float completion = (float) (completionInt / 100.0);
completion = completion * completion * completion;
final float[] hsl = linear(completion, hsl1, hsl2);

View File

@ -80,7 +80,7 @@ public class Version {
}
public static int beta() {
final int beta = 2;
final int beta = 3;
return beta;
}