Files
aistudio-wpf-diagram/Live-Charts-master/WpfView/DefaultGeoMapTooltip.xaml.cs
2021-07-23 09:42:22 +08:00

162 lines
6.9 KiB
C#

//The MIT License(MIT)
//Copyright(c) 2016 Alberto Rodriguez & LiveCharts Contributors
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace LiveCharts.Wpf
{
public partial class DefaultGeoMapTooltip : UserControl
{
/// <summary>
/// Initializes a new instance of the <see cref="DefaultGeoMapTooltip"/> class.
/// </summary>
public DefaultGeoMapTooltip()
{
InitializeComponent();
SetCurrentValue(CornerRadiusProperty, 4d);
DataContext = this;
}
/// <summary>
/// The corner radius property
/// </summary>
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register(
"CornerRadius", typeof (double), typeof (DefaultGeoMapTooltip), new PropertyMetadata(default(double)));
/// <summary>
/// Gets or sets the corner radius.
/// </summary>
/// <value>
/// The corner radius.
/// </value>
public double CornerRadius
{
get { return (double) GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
}
/// <summary>
/// The label formatter property
/// </summary>
public static readonly DependencyProperty LabelFormatterProperty = DependencyProperty.Register(
"LabelFormatter", typeof (Func<double, string>), typeof (DefaultGeoMapTooltip), new PropertyMetadata(default(Func<double, string>)));
/// <summary>
/// Gets or sets the label formatter.
/// </summary>
/// <value>
/// The label formatter.
/// </value>
public Func<double, string> LabelFormatter
{
get { return (Func<double, string>) GetValue(LabelFormatterProperty); }
set { SetValue(LabelFormatterProperty, value); }
}
/// <summary>
/// The geo data property
/// </summary>
public static readonly DependencyProperty GeoDataProperty = DependencyProperty.Register(
"GeoData", typeof (GeoData), typeof (DefaultGeoMapTooltip), new PropertyMetadata(default(GeoData)));
/// <summary>
/// Gets or sets the geo data.
/// </summary>
/// <value>
/// The geo data.
/// </value>
public GeoData GeoData
{
get { return (GeoData) GetValue(GeoDataProperty); }
set { SetValue(GeoDataProperty, value); }
}
}
/// <summary>
///
/// </summary>
public class GeoData
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>
/// The name.
/// </value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the value.
/// </summary>
/// <value>
/// The value.
/// </value>
public double Value { get; set; }
}
/// <summary>
///
/// </summary>
/// <seealso cref="System.Windows.Data.IMultiValueConverter" />
public class GeoDataLabelConverter : IMultiValueConverter
{
/// <summary>
/// Converts source values to a value for the binding target. The data binding engine calls this method when it propagates the values from source bindings to the binding target.
/// </summary>
/// <param name="values">The array of values that the source bindings in the <see cref="T:System.Windows.Data.MultiBinding" /> produces. The value <see cref="F:System.Windows.DependencyProperty.UnsetValue" /> indicates that the source binding has no value to provide for conversion.</param>
/// <param name="targetType">The type of the binding target property.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>
/// A converted value.If the method returns null, the valid null value is used.A return value of <see cref="T:System.Windows.DependencyProperty" />.<see cref="F:System.Windows.DependencyProperty.UnsetValue" /> indicates that the converter did not produce a value, and that the binding will use the <see cref="P:System.Windows.Data.BindingBase.FallbackValue" /> if it is available, or else will use the default value.A return value of <see cref="T:System.Windows.Data.Binding" />.<see cref="F:System.Windows.Data.Binding.DoNothing" /> indicates that the binding does not transfer the value or use the <see cref="P:System.Windows.Data.BindingBase.FallbackValue" /> or the default value.
/// </returns>
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
Func<double, string> defF = x => x.ToString(CultureInfo.InvariantCulture);
var f = values[1] as Func<double, string> ?? defF;
return f(values[0] as double? ?? 0);
}
/// <summary>
/// Converts a binding target value to the source binding values.
/// </summary>
/// <param name="value">The value that the binding target produces.</param>
/// <param name="targetTypes">The array of types to convert to. The array length indicates the number and types of values that are suggested for the method to return.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>
/// An array of values that have been converted from the target value back to the source values.
/// </returns>
/// <exception cref="System.NotImplementedException"></exception>
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}