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

Commit c998895

Browse files
Merge pull request #458 from beto-rodriguez/develop
0.9.3 release
2 parents 34622a2 + c9fcc8d commit c998895

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+734
-138
lines changed

Core/AxisCore.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ internal virtual CoreMargin PrepareChart(AxisOrientation source, ChartCore chart
266266
InitializeGarbageCollector();
267267

268268
var bl = Math.Ceiling(BotLimit/Magnitude)*Magnitude;
269+
var u = View.BarUnit != 1d
270+
? View.BarUnit
271+
: View.Unit;
272+
if (u != 1d)
273+
{
274+
bl = Math.Ceiling(BotLimit / u) * u;
275+
}
276+
bl = Math.Round(bl/u)*u;
269277
FirstSeparator = bl;
270278

271279
for (var i = bl; i <= TopLimit - (EvaluatesUnitWidth ? 1 : 0); i += S)

Core/ChartFunctions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,17 @@ public static double GetUnitWidth(AxisOrientation source, ChartCore chart, AxisC
219219
if (source == AxisOrientation.Y)
220220
{
221221
min = axis.BotLimit;
222-
u = axis.View.BarUnit;
222+
u = axis.View.BarUnit != 1d
223+
? axis.View.BarUnit
224+
: axis.View.Unit;
223225
return ToDrawMargin(min, AxisOrientation.Y, chart, axis) -
224226
ToDrawMargin(min + u, AxisOrientation.Y, chart, axis);
225227
}
226228

227229
min = axis.BotLimit;
228-
u = axis.View.BarUnit;
230+
u = axis.View.BarUnit != 1d
231+
? axis.View.BarUnit
232+
: axis.View.Unit;
229233
return ToDrawMargin(min + u, AxisOrientation.X, chart, axis) -
230234
ToDrawMargin(min, AxisOrientation.X, chart, axis);
231235
}

Core/ChartUpdater.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ protected void Update(bool restartsAnimations = false)
108108

109109
foreach (var series in Chart.View.ActualSeries)
110110
{
111-
if (Chart.View.ContainsElement(series)) continue;
112-
113111
InitializeSeriesView(series);
114112
series.ActualValues.Initialize(series);
115113
series.InitializeColors();

Core/ChartValues.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ public void Initialize(ISeriesView seriesView)
8787

8888
var cp = new ChartPoint();
8989

90-
var source = this.ToArray();
91-
9290
var ax = seriesView.Model.Chart.AxisX[seriesView.ScalesXAt];
9391
var ay = seriesView.Model.Chart.AxisY[seriesView.ScalesYAt];
9492
double fx = double.IsNaN(ax.MinValue) ? double.NegativeInfinity : ax.MinValue,
@@ -98,10 +96,11 @@ public void Initialize(ISeriesView seriesView)
9896

9997
var isHorizontal = seriesView.Model.SeriesOrientation == SeriesOrientation.Horizontal;
10098

101-
for (var index = 0; index < source.Length; index++)
99+
var index = 0;
100+
foreach(var item in this)
102101
{
103-
var item = source[index];
104102
config.Evaluate(index, item, cp);
103+
index++;
105104

106105
if (isHorizontal)
107106
{
@@ -154,6 +153,7 @@ public void Initialize(ISeriesView seriesView)
154153
tracker.WLimit = new CoreLimit(double.IsInfinity(wMin)
155154
? 0
156155
: wMin, double.IsInfinity(wMax) ? 1 : wMax);
156+
157157
}
158158

159159
/// <summary>
@@ -180,11 +180,9 @@ public IEnumerable<ChartPoint> GetPoints(ISeriesView seriesView)
180180
var tracker = GetTracker(seriesView);
181181
var gci = tracker.Gci;
182182

183-
var source = this.ToList(); //copy it, to prevent async issues
184-
185-
for (var index = 0; index < source.Count; index++)
183+
var index = 0;
184+
foreach (var value in this)
186185
{
187-
var value = source[index];
188186
if (isObservable)
189187
{
190188
var observable = (IObservableChartPoint)value;
@@ -203,6 +201,7 @@ public IEnumerable<ChartPoint> GetPoints(ISeriesView seriesView)
203201
cp.SeriesView = seriesView;
204202

205203
config.Evaluate(index, value, cp);
204+
index++;
206205

207206
yield return cp;
208207
}

Core/Definitions/Charts/IAxisView.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
//SOFTWARE.
2222

23+
using System;
2324
using LiveCharts.Charts;
2425
using LiveCharts.Dtos;
2526

@@ -99,6 +100,14 @@ public interface IAxisView
99100
/// <value>
100101
/// The bar unit.
101102
/// </value>
103+
double Unit { get; set; }
104+
/// <summary>
105+
/// Gets or sets the bar unit.
106+
/// </summary>
107+
/// <value>
108+
/// The bar unit.
109+
/// </value>
110+
[Obsolete]
102111
double BarUnit { get; set; }
103112
/// <summary>
104113
/// Gets the previous maximum value.

Core/Definitions/Charts/IChartView.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,7 @@ public interface IChartView
224224
/// </summary>
225225
/// <param name="element">The element.</param>
226226
void EnsureElementBelongsToCurrentDrawMargin(object element);
227-
/// <summary>
228-
/// Determines whether the specified element contains element.
229-
/// </summary>
230-
/// <param name="element">The element.</param>
231-
bool ContainsElement(object element);
232-
227+
233228
/// <summary>
234229
/// Hides the tooltip.
235230
/// </summary>

Core/Definitions/Series/ISeriesView.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ public interface ISeriesView
100100
/// The title.
101101
/// </value>
102102
string Title { get; }
103+
/// <summary>
104+
/// Gets a value indicating whether this instance is first draw.
105+
/// </summary>
106+
/// <value>
107+
/// <c>true</c> if this instance is first draw; otherwise, <c>false</c>.
108+
/// </value>
109+
bool IsFirstDraw { get; }
103110

104111
/// <summary>
105112
/// Gets the point view.

Core/Helpers/NoisyCollection.cs

Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public interface INoisyCollection : IList, INotifyPropertyChanged, INotifyCollec
6868
public class NoisyCollection<T> : INoisyCollection, IList<T>
6969
{
7070
#region Private Fields
71+
private readonly object _sync = new object();
7172
private readonly List<T> _source;
7273
private const string CountString = "Count";
7374
private const string IndexerString = "Item[]";
@@ -153,11 +154,20 @@ event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
153154
/// <returns></returns>
154155
public T this[int index]
155156
{
156-
get { return _source[index]; }
157+
get
158+
{
159+
lock (_sync)
160+
{
161+
return _source[index];
162+
}
163+
}
157164
set
158165
{
159166
var original = this[index];
160-
_source[index] = value;
167+
lock (_sync)
168+
{
169+
_source[index] = value;
170+
}
161171
ReplaceItem(original, value, index);
162172
}
163173
}
@@ -169,11 +179,20 @@ public T this[int index]
169179
/// <returns></returns>
170180
object IList.this[int index]
171181
{
172-
get { return _source[index]; }
182+
get
183+
{
184+
lock (_sync)
185+
{
186+
return _source[index];
187+
}
188+
}
173189
set
174190
{
175191
var original = this[index];
176-
_source[index] = (T)value;
192+
lock (_sync)
193+
{
194+
_source[index] = (T)value;
195+
}
177196
ReplaceItem(original, value, index);
178197
}
179198
}
@@ -184,7 +203,10 @@ object IList.this[int index]
184203
/// <returns>collection enumeration</returns>
185204
public IEnumerator<T> GetEnumerator()
186205
{
187-
return _source.GetEnumerator();
206+
lock (_sync)
207+
{
208+
return new List<T>(_source).GetEnumerator();
209+
}
188210
}
189211

190212
/// <summary>
@@ -257,7 +279,10 @@ int IList.Add(object value)
257279
{
258280
var v = (T)value;
259281
Add(v);
260-
return _source.IndexOf(v);
282+
lock (_sync)
283+
{
284+
return _source.IndexOf(v);
285+
}
261286
}
262287

263288
/// <summary>
@@ -266,7 +291,10 @@ int IList.Add(object value)
266291
/// <returns>number of items in the collection</returns>
267292
public void Add(T item)
268293
{
269-
_source.Add(item);
294+
lock (_sync)
295+
{
296+
_source.Add(item);
297+
}
270298
OnNoisyCollectionChanged(null, new[] { item });
271299
OnPropertyChanged(CountString);
272300
OnPropertyChanged(IndexerString);
@@ -290,7 +318,10 @@ public void AddRange(IEnumerable<object> items)
290318
public void AddRange(IEnumerable<T> items)
291319
{
292320
var newItems = items as T[] ?? items.ToArray();
293-
_source.AddRange(newItems);
321+
lock (_sync)
322+
{
323+
_source.AddRange(newItems);
324+
}
294325
OnNoisyCollectionChanged(null, newItems);
295326
OnPropertyChanged(CountString);
296327
OnPropertyChanged(IndexerString);
@@ -307,7 +338,10 @@ public void AddRange(IEnumerable<T> items)
307338
/// <param name="item">item to insert</param>
308339
public void Insert(int index, T item)
309340
{
310-
_source.Insert(index, item);
341+
lock (_sync)
342+
{
343+
_source.Insert(index, item);
344+
}
311345
OnNoisyCollectionChanged(null, new[] { item });
312346
OnPropertyChanged(CountString);
313347
OnPropertyChanged(IndexerString);
@@ -343,7 +377,10 @@ public void InsertRange(int index, IEnumerable<object> collection)
343377
public void InsertRange(int index, IEnumerable<T> collection)
344378
{
345379
var newItems = collection as T[] ?? collection.ToArray();
346-
_source.InsertRange(index, newItems);
380+
lock (_sync)
381+
{
382+
_source.InsertRange(index, newItems);
383+
}
347384
OnNoisyCollectionChanged(null, newItems);
348385
OnPropertyChanged(CountString);
349386
OnPropertyChanged(IndexerString);
@@ -369,7 +406,11 @@ public void Remove(object value)
369406
/// <returns>number of items in the collection</returns>
370407
public bool Remove(T item)
371408
{
372-
var index = _source.IndexOf(item);
409+
int index;
410+
lock (_sync)
411+
{
412+
index = _source.IndexOf(item);
413+
}
373414
if (index < 0) return false;
374415
RemoveAt(index);
375416
return true;
@@ -399,8 +440,12 @@ void IList<T>.RemoveAt(int index)
399440
/// <param name="index">index to remove at</param>
400441
public void RemoveAt(int index)
401442
{
402-
var item = _source[index];
403-
_source.RemoveAt(index);
443+
T item;
444+
lock (_sync)
445+
{
446+
item = _source[index];
447+
_source.RemoveAt(index);
448+
}
404449
OnNoisyCollectionChanged(new[] { item }, null);
405450
OnPropertyChanged(CountString);
406451
OnPropertyChanged(IndexerString);
@@ -429,8 +474,12 @@ void ICollection<T>.Clear()
429474
/// </summary>
430475
public void Clear()
431476
{
432-
var backup = _source.ToArray();
433-
_source.Clear();
477+
T[] backup;
478+
lock (_sync)
479+
{
480+
backup = _source.ToArray();
481+
_source.Clear();
482+
}
434483
OnNoisyCollectionChanged(backup, null);
435484
OnNoisyCollectionReset();
436485
OnPropertyChanged(CountString);
@@ -455,7 +504,10 @@ public bool Contains(object value)
455504
/// <returns>evaluation</returns>
456505
public bool Contains(T item)
457506
{
458-
return _source.Contains(item);
507+
lock (_sync)
508+
{
509+
return _source.Contains(item);
510+
}
459511
}
460512

461513
/// <summary>
@@ -475,7 +527,10 @@ public void CopyTo(Array array, int index)
475527
/// <param name="index">array index</param>
476528
public void CopyTo(T[] array, int index)
477529
{
478-
_source.CopyTo(array, index);
530+
lock (_sync)
531+
{
532+
_source.CopyTo(array, index);
533+
}
479534
}
480535

481536
/// <summary>
@@ -495,7 +550,10 @@ public int IndexOf(object value)
495550
/// <returns></returns>
496551
public int IndexOf(T item)
497552
{
498-
return _source.IndexOf(item);
553+
lock (_sync)
554+
{
555+
return _source.IndexOf(item);
556+
}
499557
}
500558

501559
#endregion

Core/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
// You can specify all the values or you can default the Build and Revision Numbers
2626
// by using the '*' as shown below:
2727
// [assembly: AssemblyVersion("1.0.*")]
28-
[assembly: AssemblyVersion("0.9.2")]
29-
[assembly: AssemblyFileVersion("0.9.2")]
28+
[assembly: AssemblyVersion("0.9.3")]
29+
[assembly: AssemblyFileVersion("0.9.3")]
3030

3131
[assembly: InternalsVisibleTo("LiveCharts.Wpf")]
3232
[assembly: InternalsVisibleTo("LiveCharts.Uwp")]

Core40/AxisCore.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ internal virtual CoreMargin PrepareChart(AxisOrientation source, ChartCore chart
266266
InitializeGarbageCollector();
267267

268268
var bl = Math.Ceiling(BotLimit/Magnitude)*Magnitude;
269+
var u = View.BarUnit != 1d
270+
? View.BarUnit
271+
: View.Unit;
272+
if (u != 1d)
273+
{
274+
bl = Math.Ceiling(BotLimit / u) * u;
275+
}
276+
bl = Math.Round(bl/u)*u;
269277
FirstSeparator = bl;
270278

271279
for (var i = bl; i <= TopLimit - (EvaluatesUnitWidth ? 1 : 0); i += S)

0 commit comments

Comments
 (0)