1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.IO;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using NUnit.Framework;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Visualization.Test {
|
---|
8 | [TestFixture]
|
---|
9 | public class LineChartPersistenceTests {
|
---|
10 | [Test]
|
---|
11 | public void TestPersistence() {
|
---|
12 | // setup
|
---|
13 | ChartDataRowsModel model = new ChartDataRowsModel();
|
---|
14 |
|
---|
15 | model.Title = "model";
|
---|
16 |
|
---|
17 | model.XAxis.Label = "xaxis";
|
---|
18 | model.XAxis.Color = Color.FromArgb(1, 2, 3, 4);
|
---|
19 | model.XAxis.GridColor = Color.FromArgb(1, 2, 3, 4);
|
---|
20 | model.XAxis.ShowGrid = true;
|
---|
21 | model.XAxis.ShowLabel = true;
|
---|
22 |
|
---|
23 | IDataRow row1 = new DataRow();
|
---|
24 |
|
---|
25 | row1.RowSettings.Label = "row1";
|
---|
26 | row1.RowSettings.Color = Color.FromArgb(1, 2, 3, 4);
|
---|
27 | row1.RowSettings.LineType = DataRowType.Normal;
|
---|
28 | row1.RowSettings.ShowMarkers = true;
|
---|
29 | row1.RowSettings.Style = DrawingStyle.Dashed;
|
---|
30 | row1.RowSettings.Thickness = 5;
|
---|
31 |
|
---|
32 | row1.AddValues(new double[] {0, 10.3, 5});
|
---|
33 |
|
---|
34 | row1.YAxis = model.DefaultYAxis;
|
---|
35 | row1.YAxis.ClipChangeable = true;
|
---|
36 | row1.YAxis.GridColor = Color.FromArgb(1, 2, 3, 4);
|
---|
37 | row1.YAxis.Label = "yaxis label";
|
---|
38 | row1.YAxis.Position = AxisPosition.Right;
|
---|
39 | row1.YAxis.ShowGrid = true;
|
---|
40 | row1.YAxis.ShowYAxis = true;
|
---|
41 | row1.YAxis.ShowYAxisLabel = true;
|
---|
42 |
|
---|
43 | model.AddDataRow(row1);
|
---|
44 |
|
---|
45 | IDataRow row2 = new DataRow();
|
---|
46 |
|
---|
47 | row2.RowSettings.Label = "row2";
|
---|
48 | row2.RowSettings.Color = Color.FromArgb(5, 6, 7, 8);
|
---|
49 | row2.RowSettings.LineType = DataRowType.Points;
|
---|
50 | row2.RowSettings.ShowMarkers = false;
|
---|
51 | row2.RowSettings.Style = DrawingStyle.Solid;
|
---|
52 | row2.RowSettings.Thickness = 6;
|
---|
53 |
|
---|
54 | row2.AddValues(new double[] { 1, 2, 3 });
|
---|
55 |
|
---|
56 | row2.YAxis = new YAxisDescriptor();
|
---|
57 | row2.YAxis.ClipChangeable = false;
|
---|
58 | row2.YAxis.GridColor = Color.FromArgb(4, 3, 2, 1);
|
---|
59 | row2.YAxis.Label = "yaxis2 label";
|
---|
60 | row2.YAxis.Position = AxisPosition.Left;
|
---|
61 | row2.YAxis.ShowGrid = false;
|
---|
62 | row2.YAxis.ShowYAxis = false;
|
---|
63 | row2.YAxis.ShowYAxisLabel = false;
|
---|
64 |
|
---|
65 | model.AddDataRow(row2);
|
---|
66 |
|
---|
67 | // execute
|
---|
68 | MemoryStream storage = new MemoryStream();
|
---|
69 | PersistenceManager.Save(model, storage);
|
---|
70 |
|
---|
71 | Console.Out.WriteLine(new StreamReader(new MemoryStream(storage.ToArray())).ReadToEnd());
|
---|
72 |
|
---|
73 | storage.Position = 0;
|
---|
74 | ChartDataRowsModel restoredModel = (ChartDataRowsModel)PersistenceManager.Load(new MemoryStream(storage.ToArray()));
|
---|
75 |
|
---|
76 | // verify
|
---|
77 | Assert.AreEqual("model", restoredModel.Title);
|
---|
78 |
|
---|
79 | Assert.AreEqual(Color.FromArgb(1, 2, 3, 4), restoredModel.XAxis.Color);
|
---|
80 | Assert.AreEqual(Color.FromArgb(1, 2, 3, 4), restoredModel.XAxis.GridColor);
|
---|
81 | Assert.AreEqual(Color.FromArgb(1, 2, 3, 4), restoredModel.XAxis.GridColor);
|
---|
82 | Assert.AreEqual("xaxis", restoredModel.XAxis.Label);
|
---|
83 | Assert.AreEqual(true, restoredModel.XAxis.ShowGrid);
|
---|
84 | Assert.AreEqual(true, restoredModel.XAxis.ShowLabel);
|
---|
85 |
|
---|
86 | Assert.AreEqual(2, restoredModel.Rows.Count);
|
---|
87 |
|
---|
88 | // row 1
|
---|
89 | Assert.AreEqual("row1", restoredModel.Rows[0].RowSettings.Label);
|
---|
90 | Assert.AreEqual(Color.FromArgb(1, 2, 3, 4), restoredModel.Rows[0].RowSettings.Color);
|
---|
91 | Assert.AreEqual(DataRowType.Normal, restoredModel.Rows[0].RowSettings.LineType);
|
---|
92 | Assert.AreEqual(true, restoredModel.Rows[0].RowSettings.ShowMarkers);
|
---|
93 | Assert.AreEqual(DrawingStyle.Dashed, restoredModel.Rows[0].RowSettings.Style);
|
---|
94 | Assert.AreEqual(5, restoredModel.Rows[0].RowSettings.Thickness);
|
---|
95 |
|
---|
96 | Assert.AreEqual(3, restoredModel.Rows[0].Count);
|
---|
97 | Assert.AreEqual(0, restoredModel.Rows[0][0]);
|
---|
98 | Assert.AreEqual(10.3, restoredModel.Rows[0][1]);
|
---|
99 | Assert.AreEqual(5, restoredModel.Rows[0][2]);
|
---|
100 | Assert.AreEqual(0, restoredModel.Rows[0].MinValue);
|
---|
101 | Assert.AreEqual(10.3, restoredModel.Rows[0].MaxValue);
|
---|
102 |
|
---|
103 | Assert.AreEqual(true, restoredModel.Rows[0].YAxis.ClipChangeable);
|
---|
104 | Assert.AreEqual(Color.FromArgb(1, 2, 3, 4), restoredModel.Rows[0].YAxis.GridColor);
|
---|
105 | Assert.AreEqual("yaxis label", restoredModel.Rows[0].YAxis.Label);
|
---|
106 | Assert.AreEqual(AxisPosition.Right, restoredModel.Rows[0].YAxis.Position);
|
---|
107 | Assert.AreEqual(true, restoredModel.Rows[0].YAxis.ShowGrid);
|
---|
108 | Assert.AreEqual(true, restoredModel.Rows[0].YAxis.ShowYAxis);
|
---|
109 | Assert.AreEqual(true, restoredModel.Rows[0].YAxis.ShowYAxisLabel);
|
---|
110 |
|
---|
111 | // row 2
|
---|
112 | Assert.AreEqual("row2", restoredModel.Rows[1].RowSettings.Label);
|
---|
113 | Assert.AreEqual(Color.FromArgb(5, 6, 7, 8), restoredModel.Rows[1].RowSettings.Color);
|
---|
114 | Assert.AreEqual(DataRowType.Points, restoredModel.Rows[1].RowSettings.LineType);
|
---|
115 | Assert.AreEqual(false, restoredModel.Rows[1].RowSettings.ShowMarkers);
|
---|
116 | Assert.AreEqual(DrawingStyle.Solid, restoredModel.Rows[1].RowSettings.Style);
|
---|
117 | Assert.AreEqual(6, restoredModel.Rows[1].RowSettings.Thickness);
|
---|
118 |
|
---|
119 | Assert.AreEqual(3, restoredModel.Rows[1].Count);
|
---|
120 | Assert.AreEqual(1, restoredModel.Rows[1][0]);
|
---|
121 | Assert.AreEqual(2, restoredModel.Rows[1][1]);
|
---|
122 | Assert.AreEqual(3, restoredModel.Rows[1][2]);
|
---|
123 | Assert.AreEqual(1, restoredModel.Rows[1].MinValue);
|
---|
124 | Assert.AreEqual(3, restoredModel.Rows[1].MaxValue);
|
---|
125 |
|
---|
126 | Assert.AreEqual(false, restoredModel.Rows[1].YAxis.ClipChangeable);
|
---|
127 | Assert.AreEqual(Color.FromArgb(4, 3, 2, 1), restoredModel.Rows[1].YAxis.GridColor);
|
---|
128 | Assert.AreEqual("yaxis2 label", restoredModel.Rows[1].YAxis.Label);
|
---|
129 | Assert.AreEqual(AxisPosition.Left, restoredModel.Rows[1].YAxis.Position);
|
---|
130 | Assert.AreEqual(false, restoredModel.Rows[1].YAxis.ShowGrid);
|
---|
131 | Assert.AreEqual(false, restoredModel.Rows[1].YAxis.ShowYAxis);
|
---|
132 | Assert.AreEqual(false, restoredModel.Rows[1].YAxis.ShowYAxisLabel);
|
---|
133 | }
|
---|
134 | }
|
---|
135 | } |
---|