forked from analogdevicesinc/iio-osc-mingw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtkdatabox-0.9.2.0.patch
138 lines (134 loc) · 2.9 KB
/
gtkdatabox-0.9.2.0.patch
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
diff --git a/gtk/gtkdatabox_lines.c b/gtk/gtkdatabox_lines.c
index 80e19cd..4fe05d9 100644
--- a/gtk/gtkdatabox_lines.c
+++ b/gtk/gtkdatabox_lines.c
@@ -132,6 +132,102 @@ gtk_databox_lines_new (guint len, gfloat * X, gfloat * Y,
return GTK_DATABOX_GRAPH (lines);
}
+static guint
+gtk_databox_lines_drop_points(GdkPoint * out, const GdkPoint * in,
+ guint len, guint *consumed)
+{
+ guint i;
+ gint min, max, x = in[0].x;
+
+ min = max = in[0].y;
+
+ for (i = 1; i < len && in[i].x == x; i++) {
+ min = MIN(min, in[i].y);
+ max = MAX(max, in[i].y);
+ }
+
+ *consumed = i;
+ out[0] = in[0];
+
+ if (min == max)
+ return 1;
+
+ /* More than two points -> some can be removed */
+ if (i > 2) {
+ out[1].x = x;
+
+ if (in[0].y == min) {
+ out[1].y = max;
+
+ if (in[i - 1].y == max) {
+ return 2;
+ } else {
+ out[2] = in[i - 1];
+ return 3;
+ }
+
+ } else if (in[0].y == max) {
+ out[1].y = min;
+
+ if (in[i - 1].y == min) {
+ return 2;
+ } else {
+ out[2] = in[i - 1];
+ return 3;
+ }
+
+ } else {
+ out[2].x = x;
+
+ if (in[i - 1].y == min) {
+ out[1].y = max;
+ out[2].y = min;
+ return 3;
+ } else if (in[i - 1].y == max) {
+ out[1].y = min;
+ out[2].y = max;
+ return 3;
+ } else if (in[0].y < in[i - 1].y) {
+ out[1].y = min;
+ out[2].y = max;
+ out[3] = in[i - 1];
+ return 4;
+ } else {
+ out[1].y = max;
+ out[2].y = min;
+ out[3] = in[i - 1];
+ return 4;
+ }
+ }
+
+ } else {
+ out[1] = in[1];
+ return 2;
+ }
+}
+
+static guint
+gtk_databox_reduce_number_of_points (GdkPoint *data, guint len)
+{
+ GdkPoint *in = data, *out = data;
+ guint new_len = 0;
+
+ do {
+ guint consumed;
+ guint ret = gtk_databox_lines_drop_points(
+ out, in, len, &consumed);
+ in += consumed;
+ if (len > consumed)
+ len -= consumed;
+ else
+ len = 0;
+ out += ret;
+ new_len += ret;
+ } while (len);
+
+ return new_len;
+}
+
static void
gtk_databox_lines_real_draw (GtkDataboxGraph * graph,
GtkDatabox * box)
@@ -147,6 +243,7 @@ gtk_databox_lines_real_draw (GtkDataboxGraph * graph,
gfloat *Y;
guint len;
gint size = 0;
+ gint width;
g_return_if_fail (GTK_DATABOX_IS_LINES (lines));
g_return_if_fail (GTK_IS_DATABOX (box));
@@ -166,6 +263,22 @@ gtk_databox_lines_real_draw (GtkDataboxGraph * graph,
gtk_databox_values_to_pixels (box, len, X, Y, data);
+ /* Clip the points at the left of the drawing area */
+ for (i = 0; i < len && data[i].x < 0; i++);
+ if (i == len)
+ return;
+
+ data += i;
+ len -= i;
+
+ /* Clip the points at the right of the drawing area */
+ gdk_pixmap_get_size (pixmap, &width, NULL);
+ for (i = 0; i < len && data[i].x < width; i++);
+
+ len = gtk_databox_reduce_number_of_points (data, i);
+ if (len <= 1)
+ return;
+
/* More than 2^16 lines will cause X IO error on most XServers
(Hint from Paul Barton-Davis) */
for (i = 0; i < len; i += 65536)