ScottPlot / ScottPlot/ScottPlot
Adding alignment options to the Bar is the best practice
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.8k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
Suggestion: Adding alignment options to the Bar is the best practice
Bar should not be centered on the X-axis by default
Let's take a look at the problem first. I hope the Bar has the correct time width for this room
public class BarPosition : RecipeBase
{
public override string Name => "Bar Positioning";
public override string Description => "The exact position and size of each bar may be customized.";
[Test]
public override void Execute()
{
DateTime d1 = DateTime.Parse("2025-1-1 12:00:00");
DateTime d2 = DateTime.Parse("2025-1-1 12:00:15");
DateTime d3 = DateTime.Parse("2025-1-1 12:00:20");
DateTime d4 = DateTime.Parse("2025-1-1 12:00:50");
double p1 = d1.ToOADate();
double p2 = d2.ToOADate();
double p3 = d3.ToOADate();
double p4 = d4.ToOADate();
double w1 = p2 - p1;
double w2 = p3 - p2;
double w3 = p4 - p3;
double xz = w1 / 2;
ScottPlot.Bar[] bars =
{
new() { Position = p1, Value = 10, ValueBase = 3,Size=w1, FillColor = Colors.Red },
new() { Position = p2, Value = 5, ValueBase = 0,Size=w2, FillColor = Colors.Blue },
new() { Position = p3, Value = 3, ValueBase = 2,Size=w3, FillColor = Colors.Green },
};
myPlot.Add.Bars(bars);
myPlot.Axes.DateTimeTicksBottom();
}
}
The result is as follows: This is confusing and confusing
I traced the calculation issue here
public class Bar : IHasFill, IHasLine
{
......
public CoordinateRect Rect
{
get
{
return Orientation == Orientation.Vertical
? new CoordinateRect(
left: Position - Size / 2,
right: Position + Size / 2,
bottom: ValueBase,
top: Value)
: new CoordinateRect(
left: ValueBase,
right: Value,
bottom: Position - Size / 2,
top: Position + Size / 2);
}
}
}
If I change it this way, I can got to what I expected
public CoordinateRect Rect
{
get
{
return Orientation == Orientation.Vertical
? new CoordinateRect(
left: Position ,
right: Position + Size ,
bottom: ValueBase,
top: Value)
: new CoordinateRect(
left: ValueBase,
right: Value,
bottom: Position,
top: Position);
}
}
That's already wonderful!
Of course, if a percentage value is specified for the fill color ,and Adaptive scaling label, that would be perfect. Thank you
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the BarPosition recipe and the Bar.Rect entry point shown in the issue, then trace Add.Bars and the bar rendering tests or examples around them. Compare the current centered placement with the requested alignment options and define completion by reproducing the expected DateTime bar layout. The percentage fill-color and adaptive-scaling requests are additional scope to clarify.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100