Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Commit

Permalink
Added te ability to set element border and opacity.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Nov 21, 2016
1 parent e6df978 commit fdfba96
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 19 deletions.
1 change: 1 addition & 0 deletions Structurizr.Core/Structurizr.Core.csproj
Expand Up @@ -76,6 +76,7 @@
<Compile Include="View\Routing.cs" />
<Compile Include="View\SequenceCounter.cs" />
<Compile Include="View\SequenceNumber.cs" />
<Compile Include="View\Border.cs" />
<Compile Include="View\Shape.cs" />
<Compile Include="View\Styles.cs" />
<Compile Include="Model\Container.cs" />
Expand Down
10 changes: 10 additions & 0 deletions Structurizr.Core/View/Border.cs
@@ -0,0 +1,10 @@
namespace Structurizr
{
public enum Border
{

Solid,
Dashed

}
}
44 changes: 36 additions & 8 deletions Structurizr.Core/View/ElementStyle.cs
Expand Up @@ -15,50 +15,78 @@ public class ElementStyle
/// </summary>
[DataMember(Name="tag", EmitDefaultValue=false)]
public string Tag { get; set; }


/// <summary>
/// The width of the element, in pixels.
/// </summary>
[DataMember(Name="width", EmitDefaultValue=false)]
public int? Width { get; set; }


/// <summary>
/// The height of the element, in pixels.
/// </summary>
[DataMember(Name="height", EmitDefaultValue=false)]
public int? Height { get; set; }


/// <summary>
/// The background colour of the element, as a HTML RGB hex string (e.g.
/// </summary>
[DataMember(Name="background", EmitDefaultValue=false)]
public string Background { get; set; }


/// <summary>
/// The foreground (text) colour of the element, as a HTML RGB hex string (e.g.
/// </summary>
[DataMember(Name="color", EmitDefaultValue=false)]
public string Color { get; set; }


/// <summary>
/// The standard font size used to render text, in pixels.
/// </summary>
/// <value>The standard font size used to render text, in pixels.</value>
[DataMember(Name="fontSize", EmitDefaultValue=false)]
public int? FontSize { get; set; }



/// <summary>
/// The shape used to render the element.
/// </summary>
[DataMember(Name="shape", EmitDefaultValue=false)]
public Shape Shape { get; set; }


/// <summary>
/// The border to use when rendering the element.
/// </summary>
[DataMember(Name="border", EmitDefaultValue=false)]
public Border Border { get; set; }

private int? _opacity;

/// <summary>
/// The opacity of the line/text; 0 to 100.
/// </summary>
[DataMember(Name = "opacity", EmitDefaultValue = false)]
public int? Opacity
{
get { return _opacity; }
set
{
if (value != null)
{
if (value < 0)
{
_opacity = 0;
}
else if (value > 100)
{
_opacity = 100;
}
else {
_opacity = value;
}
}
}
}

internal ElementStyle()
{
}
Expand Down
65 changes: 54 additions & 11 deletions Structurizr.Core/View/RelationshipStyle.cs
Expand Up @@ -16,55 +16,98 @@ public class RelationshipStyle
[DataMember(Name="tag", EmitDefaultValue=false)]
public string Tag { get; set; }


/// <summary>
/// The thickness of the line, in pixels.
/// </summary>
[DataMember(Name="thickness", EmitDefaultValue=false)]
public int? Thickness { get; set; }


/// <summary>
/// The colour of the line, as a HTML RGB hex string (e.g. #123456)
/// </summary>
[DataMember(Name="color", EmitDefaultValue=false)]
public string Color { get; set; }


/// <summary>
/// The standard font size used to render the relationship annotation, in pixels.
/// </summary>
[DataMember(Name="fontSize", EmitDefaultValue=false)]
public int? FontSize { get; set; }


/// <summary>
/// The width of the relationship annotation, in pixels.
/// </summary>
[DataMember(Name="width", EmitDefaultValue=false)]
public int? Width { get; set; }


/// <summary>
/// A flag to indicate whether the line is rendered as dashed or not.
/// </summary>
/// <value>A flag to indicate whether the line is rendered as dashed or not.</value>
[DataMember(Name="dashed", EmitDefaultValue=false)]
public bool? Dashed { get; set; }


public bool? Dashed { get; set; }

/// <summary>
/// The routing of the line.
/// </summary>
[DataMember(Name="routing", EmitDefaultValue=false)]
public Routing? Routing { get; set; }



private int? _position;

/// <summary>
/// The position of the annotation along the line; 0 (start) to 100 (end).
/// </summary>
[DataMember(Name="position", EmitDefaultValue=false)]
public int? Position { get; set; }
public int? Position
{
get { return _position; }
set
{
if (value != null)
{
if (value < 0)
{
_position = 0;
}
else if (value > 100)
{
_position = 100;
}
else {
_position = value;
}
}
}
}

private int? _opacity;

/// <summary>
/// The opacity of the line/text; 0 to 100.
/// </summary>
[DataMember(Name = "opacity", EmitDefaultValue = false)]
public int? Opacity
{
get { return _opacity; }
set
{
if (value != null)
{
if (value < 0)
{
_opacity = 0;
}
else if (value > 100)
{
_opacity = 100;
}
else {
_opacity = value;
}
}
}
}

internal RelationshipStyle()
{
Expand Down
2 changes: 2 additions & 0 deletions Structurizr.CoreTests/Structurizr.CoreTests.csproj
Expand Up @@ -73,11 +73,13 @@
<Compile Include="View\ComponentViewTests.cs" />
<Compile Include="View\ContainerViewTests.cs" />
<Compile Include="View\EnterpriseContextViewTests.cs" />
<Compile Include="View\ElementStyleTests.cs" />
<Compile Include="View\SystemContextViewTests.cs" />
<Compile Include="View\ConfigurationTests.cs" />
<Compile Include="View\SequenceCounterTests.cs" />
<Compile Include="View\SequenceNumberTests.cs" />
<Compile Include="View\DynamicViewTests.cs" />
<Compile Include="View\RelationshipStyleTests.cs" />
<Compile Include="WorkspaceTests.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
32 changes: 32 additions & 0 deletions Structurizr.CoreTests/View/ElementStyleTests.cs
@@ -0,0 +1,32 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Structurizr.CoreTests
{
[TestClass]
public class ElementStyleTests
{

[TestMethod]
public void Test_Opacity()
{
ElementStyle style = new ElementStyle();
Assert.IsNull(style.Opacity);

style.Opacity = -1;
Assert.AreEqual(0, style.Opacity);

style.Opacity = 0;
Assert.AreEqual(0, style.Opacity);

style.Opacity = 50;
Assert.AreEqual(50, style.Opacity);

style.Opacity = 100;
Assert.AreEqual(100, style.Opacity);

style.Opacity = 101;
Assert.AreEqual(100, style.Opacity);
}

}
}
53 changes: 53 additions & 0 deletions Structurizr.CoreTests/View/RelationshipStyleTests.cs
@@ -0,0 +1,53 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Structurizr.CoreTests.View
{
[TestClass]
public class RelationshipStyleTests
{

[TestMethod]
public void Test_Position()
{
RelationshipStyle style = new RelationshipStyle();
Assert.IsNull(style.Position);

style.Position = -1;
Assert.AreEqual(0, style.Position);

style.Position = 0;
Assert.AreEqual(0, style.Position);

style.Position = 50;
Assert.AreEqual(50, style.Position);

style.Position = 100;
Assert.AreEqual(100, style.Position);

style.Position = 101;
Assert.AreEqual(100, style.Position);
}

[TestMethod]
public void Test_Opacity()
{
RelationshipStyle style = new RelationshipStyle();
Assert.IsNull(style.Opacity);

style.Opacity = -1;
Assert.AreEqual(0, style.Opacity);

style.Opacity = 0;
Assert.AreEqual(0, style.Opacity);

style.Opacity = 50;
Assert.AreEqual(50, style.Opacity);

style.Opacity = 100;
Assert.AreEqual(100, style.Opacity);

style.Opacity = 101;
Assert.AreEqual(100, style.Opacity);
}
}
}

0 comments on commit fdfba96

Please sign in to comment.