Last change
on this file since 1479 was
1194,
checked in by mstoeger, 16 years ago
|
Implemented a continuous-, discrete- and string- label provider for the X/Y axis labels. (#433)
|
File size:
758 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using HeuristicLab.Visualization.LabelProvider;
|
---|
4 |
|
---|
5 | namespace HeuristicLab.Visualization.LabelProvider {
|
---|
6 | public class StringLabelProvider : ILabelProvider {
|
---|
7 | private readonly Dictionary<int, string> labels = new Dictionary<int, string>();
|
---|
8 |
|
---|
9 | public void ClearLabels() {
|
---|
10 | labels.Clear();
|
---|
11 | }
|
---|
12 |
|
---|
13 | public void SetLabel(int index, string label) {
|
---|
14 | labels[index] = label;
|
---|
15 | }
|
---|
16 |
|
---|
17 | public string GetLabel(double value) {
|
---|
18 | int index = (int)Math.Round(value);
|
---|
19 | double delta = Math.Abs(index - value);
|
---|
20 |
|
---|
21 | string label;
|
---|
22 |
|
---|
23 | if (delta < 1e-10 && labels.TryGetValue(index, out label))
|
---|
24 | return label;
|
---|
25 | else
|
---|
26 | return string.Empty;
|
---|
27 | }
|
---|
28 | }
|
---|
29 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.