summaryrefslogtreecommitdiff
path: root/grapher/Models/Options/ActiveValueLabelXY.cs
blob: 12506e937e38f9cc2a25537914a6dd97f3549ccf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace grapher.Models.Options
{
    public class ActiveValueLabelXY
    {
        public const int ActiveLabelXYSeparation = 2;
        public const string ShortenedFormatString = "0.###";

        public ActiveValueLabelXY(
            ActiveValueLabel x,
            ActiveValueLabel y)
        {
            X = x;
            Y = y;

            FullWidth = x.Width;
            ShortenedWidth = (FullWidth - ActiveLabelXYSeparation) / 2;

            Y.Left = X.Left + ShortenedWidth + ActiveLabelXYSeparation;
            Y.Width = ShortenedWidth;
            Y.FormatString = ShortenedFormatString;

            Combined = false;
            SetCombined();
        }

        public ActiveValueLabel X { get; }

        public ActiveValueLabel Y { get; }

        public bool Combined { get; private set; }

        private int FullWidth { get; }

        private int ShortenedWidth { get; }

        public void SetValues(double x, double y)
        {
            X.SetValue(x);
            Y.SetValue(y);

            if (x == y)
            {
                SetCombined();
            }
            else
            {
                SetSeparate();
            }
        }

        public void SetCombined()
        {
            if (!Combined)
            {
                X.FormatString = ActiveValueLabel.DefaultFormatString;
                X.Width = FullWidth;
                X.Prefix = string.Empty;
                Y.Hide();
            }

            Combined = true;
        }

        public void SetSeparate()
        {
            if (Combined)
            {
                X.FormatString = ShortenedFormatString;
                X.Width = ShortenedWidth;
                X.Prefix = "X";
                Y.Prefix = "Y";
                Y.Show();
            }

            Combined = false;
        }
    }
}