protected override object GetRawValue(TankViewModelBase tank, bool updateRelatedFields = false) { if (tank == null) { return(null); } TDataSource dataSource; if (tank != _dataSourceOwner) { dataSource = _dataItemDescriptor.DefaultDataSourceRetriever(tank); } else { dataSource = _dataSource; } var value = _valueRetriever(dataSource); if (updateRelatedFields && value is IUnitProvider) { _unit = ((IUnitProvider)value).Unit; this.RaisePropertyChanged(() => this.Unit); } return(value); }
public override int GetPriority(TankViewModelBase tank) { if (this.PrioritySelector != null) { return(this.PrioritySelector(tank)); } return(_priority); }
public FixedSourceDataItemDescriptor(DataItemDescriptor <TDataSource> dataItemDescriptor, TankViewModelBase dataSourceOwner, TDataSource dataSource, Func <TDataSource, object> valueRetriever) { _dataItemDescriptor = dataItemDescriptor; _dataSourceOwner = dataSourceOwner; _unit = _dataItemDescriptor.Unit; _dataSource = dataSource; _valueRetriever = valueRetriever; _dataItemDescriptor.PropertyChanged += _dataItemDescriptor_PropertyChanged; }
protected override object GetRawValue(TankViewModelBase tank, bool updateRelatedFields = false) { if (tank == null) { return(null); } var value = this.ValueRetriever(this.GetDataSource(tank)); if (updateRelatedFields && value is IUnitProvider) { _unit = ((IUnitProvider)value).Unit; this.RaisePropertyChanged(() => this.Unit); } return(value); }
public abstract int GetPriority(TankViewModelBase tank);
protected virtual TDataSource GetDataSource(TankViewModelBase tank) { return(this.DefaultDataSourceRetriever(tank)); }
public FixedSourceDataItemDescriptor <TDataSource> SpecifySource(TankViewModelBase dataSourceOwner, TDataSource dataSource) { return(new FixedSourceDataItemDescriptor <TDataSource>(this, dataSourceOwner, dataSource, this.ValueRetriever)); }
public bool ShouldShowFor(TankViewModelBase tank) { return(this.ShowCondition(tank)); }
public override int GetPriority(TankViewModelBase tank) { return(int.MaxValue); }
public override int GetPriority(TankViewModelBase tank) { return(this.Items.Select(i => i.GetPriority(tank)).Max()); }
public string GetValue(TankViewModelBase tank, bool updateRelatedFields = false) { var value = this.GetRawValue(tank, updateRelatedFields); var result = this.FormatValue(value, false); if (updateRelatedFields) { if (value is IValueTipContentElementProvider) { this.ValueTipContentElement = ((IValueTipContentElementProvider)value).ValueTipContentElement; } else { IEnumerable <Inline> valueTipContent; double maxHeight; if (value is IValueTipContentProvider) { var provider = (IValueTipContentProvider)value; valueTipContent = provider.ValueTipContent; maxHeight = provider.MaxHeight; } else { var inlines = new List <Inline>(); if (string.IsNullOrEmpty(this.Unit)) { inlines.Add(new Run(result) { FontSize = StandardTipContentFontSize }); } else { inlines.Add(new Run(string.Format(this.Unit, result)) { FontSize = StandardTipContentFontSize }); } valueTipContent = inlines; maxHeight = 100; } var viewbox = new Viewbox(); viewbox.VerticalAlignment = VerticalAlignment.Top; viewbox.MaxHeight = maxHeight; viewbox.Stretch = Stretch.Uniform; var textblock = new TextBlock(); textblock.HorizontalAlignment = HorizontalAlignment.Center; textblock.VerticalAlignment = VerticalAlignment.Center; textblock.TextAlignment = TextAlignment.Center; textblock.Inlines.AddRange(valueTipContent); viewbox.Child = textblock; this.ValueTipContentElement = viewbox; } this.RaisePropertyChanged(() => this.ValueTipContentElement); } return(result); }
protected abstract object GetRawValue(TankViewModelBase tank, bool updateRelatedFields = false);
public string GetDeltaValue(TankViewModelBase tank, TankViewModelBase comparedTo, out double deltaRatio) { if (this.ComparationMode == ComparisonMode.NotComparable) { deltaRatio = 0; return(null); } var myValue = this.GetRawValue(tank, false); var otherValue = this.GetRawValue(comparedTo, false); object delta; var myValueComparable = myValue as ICustomData; if (myValueComparable != null) { if (!myValueComparable.CanCompare) { deltaRatio = 0; return(null); } var otherComparable = (ICustomData)otherValue; delta = myValueComparable.Subtract(otherComparable); deltaRatio = myValueComparable.GetDeltaRatio(delta); } else { var myDoubleValue = Convert.ToDouble(myValue); var otherDoubleValue = Convert.ToDouble(otherValue); var doubleDelta = myDoubleValue - otherDoubleValue; delta = doubleDelta; if (myDoubleValue == 0) { deltaRatio = Math.Sign(doubleDelta); } else { deltaRatio = doubleDelta / myDoubleValue * Math.Sign(myDoubleValue); } } if (this.ComparationMode == ComparisonMode.LowerBetter) { deltaRatio = -deltaRatio; } var benchmarkRatio = Math.Abs(this.BenchmarkRatio); if (benchmarkRatio > double.Epsilon) { deltaRatio = (deltaRatio / benchmarkRatio).Clamp(-1.0, 1.0); } if (Math.Abs(deltaRatio) < 0.01) { deltaRatio = 0; return(null); } return(this.FormatValue(delta, true)); }