Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions Source/OxyPlot.Avalonia/Themes/Default.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
xmlns:local="http://oxyplot.org/avalonia"
xmlns:oxy="clr-namespace:OxyPlot;assembly=OxyPlot">

<Style Selector="local|TrackerControl">
<!-- :is() selectors so that subclasses of the controls get the template too: a type selector
matches only the exact type. -->
<Style Selector=":is(local|TrackerControl)">
<Setter Property="Background" Value="#E0FFFFA0" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="1" />
Expand Down Expand Up @@ -53,14 +55,15 @@
</Setter>
</Style>

<Style Selector="local|PlotView">
<Style Selector=":is(local|PlotView)">
<Setter Property="Background" Value="White" />
<Setter Property="DefaultTrackerTemplate">
<Setter.Value>
<ControlTemplate x:DataType="oxy:TrackerHitResult">
<local:TrackerControl LineExtents="{Binding PlotModel.PlotArea}" Position="{Binding Position}">
<local:TrackerControl.Content>
<TextBlock Margin="7" Text="{Binding Text}" />
<!-- The tracker background is always light, so the text color is set explicitly, otherwise it is white in a dark theme -->
<TextBlock Margin="7" Foreground="Black" Text="{Binding Text}" />
</local:TrackerControl.Content>
</local:TrackerControl>
</ControlTemplate>
Expand All @@ -69,10 +72,12 @@
<Setter Property="ZoomRectangleTemplate">
<Setter.Value>
<ControlTemplate>
<!-- The stroke thickness of a Rectangle in Avalonia is 0 by default, without it the border is not visible -->
<Rectangle
Fill="#40FFFF00"
Stroke="Black"
StrokeDashArray="3,1" />
StrokeDashArray="3,1"
StrokeThickness="1" />
</ControlTemplate>
</Setter.Value>
</Setter>
Expand All @@ -90,14 +95,15 @@
</Setter>
</Style>

<Style Selector="local|Plot">
<Style Selector=":is(local|Plot)">
<Setter Property="Background" Value="White" />
<Setter Property="DefaultTrackerTemplate">
<Setter.Value>
<ControlTemplate x:DataType="oxy:TrackerHitResult">
<local:TrackerControl LineExtents="{Binding PlotModel.PlotArea}" Position="{Binding Position}">
<local:TrackerControl.Content>
<TextBlock Margin="7" Text="{Binding Text}" />
<!-- The tracker background is always light, so the text color is set explicitly, otherwise it is white in a dark theme -->
<TextBlock Margin="7" Foreground="Black" Text="{Binding Text}" />
</local:TrackerControl.Content>
</local:TrackerControl>
</ControlTemplate>
Expand All @@ -106,10 +112,12 @@
<Setter Property="ZoomRectangleTemplate">
<Setter.Value>
<ControlTemplate>
<!-- The stroke thickness of a Rectangle in Avalonia is 0 by default, without it the border is not visible -->
<Rectangle
Fill="#40FFFF00"
Stroke="Black"
StrokeDashArray="3,1" />
StrokeDashArray="3,1"
StrokeThickness="1" />
</ControlTemplate>
</Setter.Value>
</Setter>
Expand Down
14 changes: 11 additions & 3 deletions Source/OxyPlot.Avalonia/Tracker/TrackerControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace OxyPlot.Avalonia
using global::Avalonia.Layout;
using global::Avalonia.Media;
using global::Avalonia.VisualTree;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -60,7 +61,7 @@ public class TrackerControl : ContentControl
/// <summary>
/// Identifies the <see cref="CornerRadius"/> dependency property.
/// </summary>
public static readonly StyledProperty<double> CornerRadiusProperty = AvaloniaProperty.Register<TrackerControl, double>(nameof(CornerRadius), 0.0);
public static new readonly StyledProperty<double> CornerRadiusProperty = AvaloniaProperty.Register<TrackerControl, double>(nameof(CornerRadius), 0.0);

/// <summary>
/// Identifies the <see cref="Distance"/> dependency property.
Expand Down Expand Up @@ -139,6 +140,11 @@ static TrackerControl()
{
ClipToBoundsProperty.OverrideDefaultValue<TrackerControl>(false);
PositionProperty.Changed.AddClassHandler<TrackerControl>(PositionChanged);

// The border is built by UpdatePositionAndBorder, so it must be rebuilt when the shape changes too
CornerRadiusProperty.Changed.AddClassHandler<TrackerControl>(PositionChanged);
ShowPointerProperty.Changed.AddClassHandler<TrackerControl>(PositionChanged);
DistanceProperty.Changed.AddClassHandler<TrackerControl>(PositionChanged);
}

/// <summary>
Expand Down Expand Up @@ -240,7 +246,7 @@ public bool ShowPointer
/// <summary>
/// Gets or sets the corner radius (only used when ShowPoint=<c>false</c>).
/// </summary>
public double CornerRadius
public new double CornerRadius
{
get
{
Expand Down Expand Up @@ -488,7 +494,9 @@ private Geometry CreateBorderGeometry(
va == VerticalAlignment.Top ? m : 0,
ha == HorizontalAlignment.Right ? m : 0,
va == VerticalAlignment.Bottom ? m : 0);
return new RectangleGeometry(rect)/* { RadiusX = this.CornerRadius, RadiusY = this.CornerRadius }*/;
// The radius is at most half of the smaller side, otherwise the rounded corners overlap
var radius = Math.Max(0, Math.Min(CornerRadius, Math.Min(width, height) / 2));
return new RectangleGeometry(rect, radius, radius);
}

/// <summary>
Expand Down