Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
randomize starting color
Browse files Browse the repository at this point in the history
  • Loading branch information
beto-rodriguez committed Sep 20, 2015
1 parent 574bcaf commit 6566496
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Charts/Charts/Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public abstract class Chart : UserControl
public List<HoverableShape> HoverableShapes = new List<HoverableShape>();
private Point _panOrigin;
private bool _isDragging;
public int ColorStartIndex = 0;
private static Random _randomizer;

//these timers are to avoid multiple graph ploting, graph will only plot when timer ticks.
private readonly DispatcherTimer _resizeTimer;
Expand All @@ -77,6 +79,7 @@ static Chart()
Color.FromRgb(210,84,0),
Color.FromRgb(191,57,43)
};
_randomizer = new Random();
}

protected Chart()
Expand Down Expand Up @@ -111,12 +114,23 @@ protected Chart()
_seriesCangedTimer.Tick += UpdateModifiedDataSeries;

CurrentScale = 1;
if (RandomizeStartingColor)
{
ColorStartIndex = _randomizer.Next(0, Colors.Count - 1);
}
}

abstract protected void Scale();
abstract protected bool ScaleChanged { get; }

/// <summary>
/// List of Colors series will use, yu can change this list to your own colors.
/// </summary>
public static List<Color> Colors { get; set; }
/// <summary>
/// indicates wether each instance of chart you create needs to randomize starting color
/// </summary>
public static bool RandomizeStartingColor { get; set; }

public static readonly DependencyProperty ZoomingProperty = DependencyProperty.Register(
"Zooming", typeof(bool), typeof(Chart));
Expand Down
7 changes: 6 additions & 1 deletion Charts/Series/Serie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class Serie
private Color? _color;
protected List<Shape> Shapes = new List<Shape>();
private Chart _chart;
private int _colorId;

protected Serie()
{
Expand Down Expand Up @@ -70,9 +71,13 @@ public Chart Chart
}
}

public int ColorId { get; set; }
public double StrokeThickness { get; set; }
public double PointRadius { get; set; }
public int ColorId
{
get { return _colorId + Chart.ColorStartIndex; }
set { _colorId = value; }
}
public Color Color
{
get
Expand Down
29 changes: 29 additions & 0 deletions Charts/ShapeHoverBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//The MIT License(MIT)

//Copyright(c) 2015 Alberto Rodriguez

//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.

namespace Charts
{
public enum ShapeHoverBehavior
{
Dot, Shape
}
}

0 comments on commit 6566496

Please sign in to comment.