[12503] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Windows.Media;
|
---|
| 6 | using System.Windows;
|
---|
| 7 | using System.Diagnostics;
|
---|
| 8 | using Microsoft.Research.DynamicDataDisplay.Common.Auxiliary;
|
---|
| 9 | using Microsoft.Research.DynamicDataDisplay.Charts.Shapes;
|
---|
| 10 | using System.Windows.Threading;
|
---|
| 11 | using System.Globalization;
|
---|
| 12 | using Microsoft.Research.DynamicDataDisplay.Charts.NewLine;
|
---|
| 13 |
|
---|
| 14 | namespace Microsoft.Research.DynamicDataDisplay.Charts.Isolines
|
---|
| 15 | {
|
---|
| 16 | public abstract class IsolineRenderer : IsolineGraphBase
|
---|
| 17 | {
|
---|
| 18 | protected override void UpdateDataSource()
|
---|
| 19 | {
|
---|
| 20 | if (DataSource != null)
|
---|
| 21 | {
|
---|
| 22 | IsolineBuilder.DataSource = DataSource;
|
---|
| 23 | IsolineBuilder.MissingValue = MissingValue;
|
---|
| 24 | Collection = IsolineBuilder.BuildIsoline();
|
---|
| 25 | }
|
---|
| 26 | else
|
---|
| 27 | {
|
---|
| 28 | Collection = null;
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | protected IEnumerable<double> GetAdditionalLevels(IsolineCollection collection)
|
---|
| 33 | {
|
---|
| 34 | var dataSource = DataSource;
|
---|
| 35 | var visibleMinMax = dataSource.GetMinMax(Plotter2D.Visible);
|
---|
| 36 | double totalDelta = collection.Max - collection.Min;
|
---|
| 37 | double visibleMinMaxRatio = totalDelta / visibleMinMax.GetLength();
|
---|
| 38 | double defaultDelta = totalDelta / 12;
|
---|
| 39 |
|
---|
| 40 | if (true || 2 * defaultDelta < visibleMinMaxRatio)
|
---|
| 41 | {
|
---|
| 42 | double number = Math.Ceiling(visibleMinMaxRatio * 4);
|
---|
| 43 | number = Math.Pow(2, Math.Ceiling(Math.Log(number) / Math.Log(2)));
|
---|
| 44 | double delta = totalDelta / number;
|
---|
| 45 | double x = collection.Min + Math.Ceiling((visibleMinMax.Min - collection.Min) / delta) * delta;
|
---|
| 46 |
|
---|
| 47 | List<double> result = new List<double>();
|
---|
| 48 | while (x < visibleMinMax.Max)
|
---|
| 49 | {
|
---|
| 50 | result.Add(x);
|
---|
| 51 | x += delta;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | return result;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | return Enumerable.Empty<double>();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected void RenderIsolineCollection(DrawingContext dc, double strokeThickness, IsolineCollection collection, CoordinateTransform transform)
|
---|
| 61 | {
|
---|
| 62 | foreach (LevelLine line in collection)
|
---|
| 63 | {
|
---|
| 64 | StreamGeometry lineGeometry = new StreamGeometry();
|
---|
| 65 | using (var context = lineGeometry.Open())
|
---|
| 66 | {
|
---|
| 67 | context.BeginFigure(line.StartPoint.ViewportToScreen(transform), false, false);
|
---|
| 68 | if (!UseBezierCurves)
|
---|
| 69 | {
|
---|
| 70 | context.PolyLineTo(line.OtherPoints.ViewportToScreen(transform).ToArray(), true, true);
|
---|
| 71 | }
|
---|
| 72 | else
|
---|
| 73 | {
|
---|
| 74 | context.PolyBezierTo(BezierBuilder.GetBezierPoints(line.AllPoints.ViewportToScreen(transform).ToArray()).Skip(1).ToArray(), true, true);
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | lineGeometry.Freeze();
|
---|
| 78 |
|
---|
| 79 | Pen pen = new Pen(new SolidColorBrush(Palette.GetColor(line.Value01)), strokeThickness);
|
---|
| 80 |
|
---|
| 81 | dc.DrawGeometry(null, pen, lineGeometry);
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | }
|
---|
| 86 | }
|
---|