Skip to content

Commit

Permalink
custom label discretising
Browse files Browse the repository at this point in the history
  • Loading branch information
Chengxuan-Li committed Feb 6, 2024
1 parent 62a11c5 commit 8aea404
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Legend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public void SetDimStyle()
public double Scale = 1.0;
public double Height = 1.0;
public int DisiredCount = 20;
public List<double> Labels => PrettyBreaks(MinValue, MaxValue, DisiredCount);
public bool AutomaticLabelling = true;
public List<double> AlternativeLabels;
public List<double> Labels => AutomaticLabelling? PrettyBreaks(MinValue, MaxValue, DisiredCount) : AlternativeLabels;
public bool OnLeft = true;
public List<double> Positions
{
Expand Down
8 changes: 8 additions & 0 deletions ProfileVisualiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class ProfileVisualiser

public Legend Legend;

public bool OverrideLegendMinMax = false;
public double OverrideLegendMin;
public double OverrideLegendMax;

public double ActualMinValue => Math.Min(YValues.Min(), SuggestedMinValue);
public double ActualMaxValue => Math.Max(YValues.Max(), SuggestedMaxValue);

Expand Down Expand Up @@ -73,6 +77,8 @@ public void LegendLeft()
Height = this.Height,
Plane = plane,
OnLeft = true,
AutomaticLabelling = !OverrideLegendMinMax,
AlternativeLabels = Legend.PrettyBreaks(OverrideLegendMin, OverrideLegendMax, 7),
};
return;
}
Expand All @@ -93,6 +99,8 @@ public void LegendRight()
Height = this.Height,
Plane = plane,
OnLeft = false,
AutomaticLabelling = !OverrideLegendMinMax,
AlternativeLabels = Legend.PrettyBreaks(OverrideLegendMin, OverrideLegendMax, 7),
};
return;
}
Expand Down
31 changes: 23 additions & 8 deletions ProfileDisplay.cs → TemperatureProfileDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

namespace WallSectionWidget
{
public class ProfileDisplay : GH_Component
public class TemperatureProfileDisplay : GH_Component
{

public List<TextEntity> PreviewTexts = new List<TextEntity>();

/// <summary>
/// Initializes a new instance of the ProfileDisplay class.
/// </summary>
public ProfileDisplay()
: base("ProfileDisplay", "PFDis",
"Display for a wall section numeric profile",
public TemperatureProfileDisplay()
: base("TemperatureProfileDisplay", "TPFDis",
"Display for a wall section temperature profile",
"WallSectionWidget", "Display")
{
}
Expand All @@ -32,11 +32,14 @@ protected override void RegisterInputParams(GH_Component.GH_InputParamManager pM
pManager.AddPlaneParameter("Plane", "Pl", "Plane", GH_ParamAccess.item);
pManager.AddNumberParameter("Height", "H", "Height", GH_ParamAccess.item);
pManager.AddNumberParameter("Scale", "S", "Custom scale factor", GH_ParamAccess.item);
pManager.AddNumberParameter("OverrideLegendMin", "OLMin", "Value used to override the legend minimum", GH_ParamAccess.item);
pManager.AddNumberParameter("OverrideLegendMax", "OLMax", "Value used to override the legend maximum", GH_ParamAccess.item);
pManager[1].Optional = true;
pManager[2].Optional = true;
pManager[3].Optional = true;
pManager[4].Optional = true;
//pManager[5].Optional = true;
pManager[5].Optional = true;
pManager[6].Optional = true;
}

/// <summary>
Expand Down Expand Up @@ -86,8 +89,20 @@ protected override void SolveInstance(IGH_DataAccess DA)
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input error: scale should be bigger than zero");
return;
}

ProfileVisualiser vis = new ProfileVisualiser(model.Depths, model.DewPoints);
double overrideLegendMin = 0.0;
double overrideLegendMax = 30.0;
bool overrideLegendMinMax = false;
if (DA.GetData(5, ref overrideLegendMin) && DA.GetData(6, ref overrideLegendMax))
{
overrideLegendMinMax = true;
}
ProfileVisualiser vis = new ProfileVisualiser(model.Depths, model.Temperatures);
vis.OverrideLegendMinMax = overrideLegendMinMax;
if (overrideLegendMinMax)
{
vis.OverrideLegendMax = overrideLegendMax;
vis.OverrideLegendMin = overrideLegendMin;
}
vis.Plane = plane;
vis.Height = height;
vis.Scale = scale;
Expand Down Expand Up @@ -117,7 +132,7 @@ protected override System.Drawing.Bitmap Icon
{
get
{
//You can add image files to your project resources and access them like this:
// You can add image files to your project resources and access them like this:
// return Resources.IconForThisComponent;
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion WallSectionWidget.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<Compile Include="GHIOParam.cs" />
<Compile Include="ModelParameters.cs" />
<Compile Include="Parameters.cs" />
<Compile Include="ProfileDisplay.cs" />
<Compile Include="TemperatureProfileDisplay.cs" />
<Compile Include="ProfileVisualiser.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down
Binary file modified tests/sample.gh
Binary file not shown.

0 comments on commit 8aea404

Please sign in to comment.