From: jpbruyere Date: Tue, 9 Feb 2016 11:30:58 +0000 (+0100) Subject: simple trending widget X-Git-Tag: 0.3~24 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=ba7ccac1887de53e1bc3cc4660470029cab2a014;p=jp%2Fcrow.git simple trending widget --- diff --git a/Crow.csproj b/Crow.csproj index fbb6ca24..5d2ad868 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -133,6 +133,7 @@ + diff --git a/src/GraphicObjects/Trend.cs b/src/GraphicObjects/Trend.cs index ffc25c39..7f12b675 100644 --- a/src/GraphicObjects/Trend.cs +++ b/src/GraphicObjects/Trend.cs @@ -19,13 +19,163 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System; +using System.Collections.Generic; +using System.Xml.Serialization; +using System.ComponentModel; namespace Crow { - public class Trend + public class Trend : GraphicObject { + #region private fields + double minValue, maxValue, lowThreshold, highThreshold; + Fill lowThresholdFill, highThresholdFill; + int nbValues; + List values = new List(); + #endregion + + + + public virtual void AddValue(double _value) + { + values.Add (_value); + while (values.Count > nbValues) + values.RemoveAt (0); + registerForGraphicUpdate (); + } + public Trend () { } + [XmlIgnore]public virtual int NewValue { + set { + AddValue (value); + } + } + [XmlAttributeAttribute()][DefaultValue(100)] + public virtual int NbValue { + get { return nbValues; } + set { + if (nbValues == value) + return; + + nbValues = value; + NotifyValueChanged ("NbValues", minValue); + registerForGraphicUpdate (); + } + } + [XmlAttributeAttribute()][DefaultValue(0.0)] + public virtual double Minimum { + get { return minValue; } + set { + if (minValue == value) + return; + + minValue = value; + NotifyValueChanged ("Minimum", minValue); + registerForGraphicUpdate (); + } + } + [XmlAttributeAttribute()][DefaultValue(100.0)] + public virtual double Maximum + { + get { return maxValue; } + set { + if (maxValue == value) + return; + + maxValue = value; + NotifyValueChanged ("Maximum", maxValue); + registerForGraphicUpdate (); + } + } + [XmlAttributeAttribute()][DefaultValue(20.0)] + public virtual double LowThreshold { + get { return lowThreshold; } + set { + if (lowThreshold == value) + return; + lowThreshold = value; + NotifyValueChanged ("LowThreshold", lowThreshold); + registerForGraphicUpdate (); + } + } + [XmlAttributeAttribute()][DefaultValue(80.0)] + public virtual double HighThreshold { + get { return highThreshold; } + set { + if (highThreshold == value) + return; + highThreshold = value; + NotifyValueChanged ("HighThreshold", highThreshold); + registerForGraphicUpdate (); + } + } + [XmlAttributeAttribute()][DefaultValue("DarkRed")] + public virtual Fill LowThresholdFill { + get { return lowThresholdFill; } + set { + if (lowThresholdFill == value) + return; + lowThresholdFill = value; + NotifyValueChanged ("LowThresholdFill", lowThresholdFill); + registerForGraphicUpdate (); + } + } + [XmlAttributeAttribute()][DefaultValue("DarkGreen")] + public virtual Fill HighThresholdFill { + get { return highThresholdFill; } + set { + if (highThresholdFill == value) + return; + highThresholdFill = value; + NotifyValueChanged ("HighThresholdFill", highThresholdFill); + registerForGraphicUpdate (); + } + } + protected override void onDraw (Cairo.Context gr) + { + base.onDraw (gr); + + if (values.Count == 0) + return; + Rectangle r = ClientRectangle; + + int i = values.Count -1; + + double ptrX = (double)r.Right; + double scaleY = (double)r.Height / (Maximum - Minimum); + double stepX = (double)r.Width / (double)nbValues; + + gr.LineWidth = 1.0; + gr.SetDash (new double[]{ 1.0 },0.0); + + + + LowThresholdFill.SetAsSource (gr); + gr.MoveTo (r.Left, r.Bottom - LowThreshold * scaleY); + gr.LineTo (r.Right, r.Bottom - LowThreshold * scaleY); +// gr.Rectangle (r.Left, r.Bottom - LowThreshold * scaleY, r.Width, LowThreshold * scaleY); + gr.Stroke(); + + HighThresholdFill.SetAsSource (gr); + gr.MoveTo (r.Left, (Maximum - HighThreshold) * scaleY); + gr.LineTo (r.Right, (Maximum - HighThreshold) * scaleY); +// gr.Rectangle (r.Left, r.Top, r.Width, (Maximum - HighThreshold) * scaleY); + gr.Stroke(); + + gr.MoveTo (ptrX, values [i] * scaleY); + + Foreground.SetAsSource (gr); + gr.SetDash (new double[]{ }, 0.0); + + while (i >= 0) { + gr.LineTo (ptrX, r.Bottom - values [i] * scaleY); + ptrX -= stepX; + i--; + } + gr.Stroke (); + } } } +