Skip to content

Commit

Permalink
refactor: removed useless DrawLegendMethod, update tests and components
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikaLos committed Dec 13, 2024
1 parent ca85142 commit 0f78424
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion GsaGH/Components/6_Display/AssemblyResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public override void CreateAttributes() {

public override void DrawViewportWires(IGH_PreviewArgs args) {
base.DrawViewportWires(args);
_contourLegendMenager.DrawLegend(args, _resType, _case, _gradients);
_contourLegendMenager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients);
}

public override bool Read(GH_IReader reader) {
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/6_Display/Contour1dResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public override void CreateAttributes() {

public override void DrawViewportWires(IGH_PreviewArgs args) {
base.DrawViewportWires(args);
_contourLegendMenager.DrawLegend(args, _resType, _case, _gradients);
_contourLegendMenager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients);
}

public override bool Read(GH_IReader reader) {
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/6_Display/Contour2dResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public override void CreateAttributes() {
public override void DrawViewportWires(IGH_PreviewArgs args) {
base.DrawViewportWires(args);

_contourLegendMenager.DrawLegend(args, _resType, _case, _gradients);
_contourLegendMenager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients);
}

public override bool Read(GH_IReader reader) {
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/6_Display/Contour3dResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public override void CreateAttributes() {

public override void DrawViewportWires(IGH_PreviewArgs args) {
base.DrawViewportWires(args);
_contourLegendMenager.DrawLegend(args, _resType, _case, _gradients);
_contourLegendMenager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients);
}

public override bool Read(GH_IReader reader) {
Expand Down
2 changes: 1 addition & 1 deletion GsaGH/Components/6_Display/ContourNodeResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public override void CreateAttributes() {
public override void DrawViewportWires(IGH_PreviewArgs args) {
base.DrawViewportWires(args);

_contourLegendMenager.DrawLegend(args, _resType, _case, _gradients);
_contourLegendMenager.Legend.DrawLegendRectangle(args, _resType, _case, _gradients);
}

public override bool Read(GH_IReader reader) {
Expand Down
11 changes: 0 additions & 11 deletions GsaGH/Helpers/GH/Legend/ContourLegendManager.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

using GH_IO.Serialization;

using Grasshopper.Kernel;

using GsaGH.Helpers.GH;

using OasysGH.Components;
Expand All @@ -32,13 +28,6 @@ public ContourLegendManager(
MenuBuilder = menuBuilder;
}

//drawing
public void DrawLegend(
IGH_PreviewArgs args, string title, string bottomText,
List<(int startY, int endY, Color gradientColor)> gradients) {
Legend.DrawLegendRectangle(args, title, bottomText, gradients);
}

//menu
public ToolStripMenuItem CreateMenu(GH_OasysDropDownComponent component, Action updateUI) {
LegendMenuBuilder.SetLegendScaleDelegate setScaleDelegate = UpdateScale;
Expand Down
16 changes: 8 additions & 8 deletions GsaGHTests/Helpers/GH/Legend/ContourLegendMenagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
namespace GsaGHTests.Helpers {
[Collection("GrasshopperFixture collection")]
public class ContourLegendMenagerTests {
private static Mock<ContourLegend> _mockLegend;
private static Mock<ContourLegendConfiguration> _mockConfiguration;
private static ContourLegend _legend;
private static ContourLegendConfiguration _configuration;
private static ContourLegendManager _manager;
private static Mock<IGH_PreviewArgs> _mockArgs;

public ContourLegendMenagerTests() {
_mockLegend = new Mock<ContourLegend>();
_mockConfiguration = new Mock<ContourLegendConfiguration>();
_configuration = new ContourLegendConfiguration(1, 1, 1.0d);
_legend = new ContourLegend(_configuration);
var menuBuilder = new LegendMenuBuilder();
_manager = new ContourLegendManager(_mockConfiguration.Object, _mockLegend.Object, menuBuilder);
_manager = new ContourLegendManager(_configuration, _legend, menuBuilder);

_mockArgs = new Mock<IGH_PreviewArgs>();
}
Expand All @@ -39,9 +39,9 @@ public void DrawLegend_CallsDrawLegendRectangle() {
(10, 20, Color.Green),
};

_manager.DrawLegend(_mockArgs.Object, title, bottomText, gradients);
_manager.Legend.DrawLegendRectangle(_mockArgs.Object, title, bottomText, gradients);

_mockLegend.Verify(l => l.DrawLegendRectangle(_mockArgs.Object, title, bottomText, gradients), Times.Once);
Assert.True(_manager.Legend.IsInvalidConfiguration);
}

[Fact]
Expand All @@ -58,7 +58,7 @@ ToolStripMenuItem menuItem
public void UpdateScale_CallsSetLegendScale() {
double scale = 2.5;
_manager.UpdateScale(scale);
Assert.Equal(scale, _mockConfiguration.Object.Scale);
Assert.Equal(scale, _configuration.Scale);
}
}
}

0 comments on commit 0f78424

Please sign in to comment.