Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/Isolines/IsolineTextAnnotater.cs @ 12503

Last change on this file since 12503 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Collections.ObjectModel;
6using System.Windows;
7using Microsoft.Research.DynamicDataDisplay.Common;
8
9namespace Microsoft.Research.DynamicDataDisplay.Charts.Isolines
10{
11  /// <summary>
12  /// IsolineTextAnnotater defines methods to annotate isolines - create a list of labels with its position.
13  /// </summary>
14  public sealed class IsolineTextAnnotater
15  {
16    private double wayBeforeText = 10;
17    /// <summary>
18    /// Gets or sets the distance between text labels.
19    /// </summary>
20    public double WayBeforeText
21    {
22      get { return wayBeforeText; }
23      set { wayBeforeText = value; }
24    }
25
26    /// <summary>
27    /// Annotates the specified isoline collection.
28    /// </summary>
29    /// <param name="collection">The collection.</param>
30    /// <param name="visible">The visible rectangle.</param>
31    /// <returns></returns>
32    public Collection<IsolineTextLabel> Annotate(IsolineCollection collection, DataRect visible)
33    {
34      Collection<IsolineTextLabel> res = new Collection<IsolineTextLabel>();
35
36      foreach (var line in collection.Lines)
37      {
38        double way = 0;
39
40        var forwardSegments = line.GetSegments();
41        var forwardEnumerator = forwardSegments.GetEnumerator();
42        forwardEnumerator.MoveNext();
43
44        foreach (var segment in line.GetSegments())
45        {
46          bool hasForwardSegment = forwardEnumerator.MoveNext();
47
48          double length = segment.GetLength();
49          way += length;
50          if (way > wayBeforeText)
51          {
52            way = 0;
53
54            var rotation = (segment.Max - segment.Min).ToAngle();
55            if (hasForwardSegment)
56            {
57              var forwardSegment = forwardEnumerator.Current;
58              rotation = (rotation + (forwardSegment.Max - forwardSegment.Min).ToAngle()) / 2;
59            }
60
61            res.Add(new IsolineTextLabel
62            {
63              Value = line.RealValue,
64              Position = segment.Max,
65              Rotation = rotation
66            });
67          }
68        }
69      }
70
71      return res;
72    }
73  }
74}
Note: See TracBrowser for help on using the repository browser.