Skip to content

Commit 61ffa99

Browse files
authored
Fix incorrect label placement on BarSeries with non-zero BaseValue (#1726) (#1727)
1 parent 40d32ae commit 61ffa99

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ All notable changes to this project will be documented in this file.
55

66
### Added
77
- Example for Issue #1716 showing poor tick spacing on DateTimeAxis with interval types of Weeks or Years
8+
- Example for label placement on BarSeries with non-zero BaseValue (#1726)
89

910
### Changed
1011

1112
### Removed
1213

1314
### Fixed
1415
- Zero-crossing axis bounds (#1708)
16+
- Incorrect label placement on BarSeries with non-zero BaseValue (#1726)
1517

1618
## [2.1.0-Preview1] - 2020-10-18
1719

‎Source/Examples/ExampleLibrary/Series/BarSeriesExamples.cs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,37 @@ public static PlotModel BaseValueOverlaping()
932932
return model;
933933
}
934934

935+
[Example("BaseValue (labels)")]
936+
public static PlotModel BaseValueLabels()
937+
{
938+
var model = new PlotModel { Title = "BaseValue with Labels" };
939+
940+
foreach (var placement in new[] { LabelPlacement.Base, LabelPlacement.Inside, LabelPlacement.Middle, LabelPlacement.Outside })
941+
{
942+
var bs = new BarSeries { Title = placement.ToString(), BaseValue = -25, LabelPlacement = placement, LabelFormatString = "{0:0}" };
943+
bs.Items.Add(new BarItem { Value = -40 });
944+
bs.Items.Add(new BarItem { Value = -25 });
945+
bs.Items.Add(new BarItem { Value = -10 });
946+
bs.Items.Add(new BarItem { Value = 0 });
947+
bs.Items.Add(new BarItem { Value = 10 });
948+
model.Series.Add(bs);
949+
}
950+
951+
var categoryAxis = new CategoryAxis
952+
{
953+
Title = "Category",
954+
Position = AxisPosition.Left,
955+
StartPosition = 1,
956+
EndPosition = 0,
957+
};
958+
categoryAxis.Labels.AddRange(new[] { "A", "B", "C", "D", "E" });
959+
model.Axes.Add(categoryAxis);
960+
961+
model.Legends.Add(new Legend());
962+
963+
return model;
964+
}
965+
935966
[Example("GapWidth 0%")]
936967
public static PlotModel GapWidth0()
937968
{

‎Source/OxyPlot/Series/BarSeries/BarSeries.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ protected void RenderLabel(
310310
HorizontalAlignment ha;
311311
ScreenPoint pt;
312312
var y = (categoryEndValue + categoryValue) / 2;
313-
var sign = Math.Sign(item.Value);
313+
var sign = Math.Sign(item.Value - baseValue);
314314
var marginVector = new ScreenVector(this.LabelMargin, 0) * sign;
315315

316316
switch (this.LabelPlacement)

0 commit comments

Comments
 (0)