a58b289e859dd3782b935b8d885e9253c12389e9
[framework/uifw/xorg/lib/libxaw.git] / packaging / 01_Xaw_StripChart_fix.diff
1 From: "Nikita V. Youshchenko" <yoush@cs.msu.su>
2 Date: Sat, 02 Nov 2002 17:57:13 +0300
3 Subject: A bug in Xaw/StripChart.c causes incorrect scale lines in xload window
4
5 Recently I tried to run xload on a high loaded server (load was more
6 than 10), and discovered that if window size is rather small, scale
7 lines are drawn incorrectly (upper than needed).
8
9 This is caused by a bug in Xaw/StripChart.c.
10 It draws lines with fixed integer steps. Than means that if window
11 height is 39 pixels, and 10 lines should be drawn to split view into 11
12 equal parts, lines will be drawn at 3, 6, 9, ,.., 30. So the bottom part
13 height will be 9 pixels while other parts height will be 2 pixels.
14
15 This patch makes part heights differ no more than by 1 pixel.
16
17 Debian bug#167448 <http://bugs.debian.org/167448>
18
19 Index: libXaw-X11R7.0-1.0.1/src/StripChart.c
20 ===================================================================
21 --- libXaw-X11R7.0-1.0.1.orig/src/StripChart.c  2005-12-30 14:50:24.000000000 -0500
22 +++ libXaw-X11R7.0-1.0.1/src/StripChart.c       2006-02-26 19:09:07.000000000 -0500
23 @@ -373,12 +373,12 @@
24   * the returned value is identical to the initial value of next and data is
25   * unchanged.  Otherwise keeps half a window's worth of data.  If data is
26   * changed, then w->strip_chart.max_value is updated to reflect the
27 - * largest data point
28 + * largest data point.
29   */
30 -static int 
31 +static int
32  repaint_window(StripChartWidget w, int left, int width)
33  {
34 -    int i, j;
35 +    int i, j, k;
36      int next = w->strip_chart.interval;
37      int scale = w->strip_chart.scale;
38      int scalewidth = 0;
39 @@ -423,8 +423,10 @@
40         }
41  
42         /* Draw graph reference lines */
43 +       k = XtHeight(w) % w->strip_chart.scale;
44         for (i = 1; i < w->strip_chart.scale; i++) {
45 -           j = i * ((int)XtHeight(w) / w->strip_chart.scale);
46 +           j = i * (XtHeight(w) / w->strip_chart.scale) +
47 +               ((i * k + w->strip_chart.scale/2) / w->strip_chart.scale);
48             XDrawLine(dpy, win, w->strip_chart.hiGC, left, j, scalewidth, j);
49         }
50      }
51 @@ -446,7 +448,7 @@
52  MoveChart(StripChartWidget w, Bool blit)
53  {
54      double old_max;
55 -    int left, i, j;
56 +    int left, i, j, k;
57      int next = w->strip_chart.interval;
58  
59      if (!XtIsRealized((Widget)w))
60 @@ -495,8 +497,10 @@
61  
62      /* Draw graph reference lines */
63      left = j;
64 +    k = XtHeight(w) % w->strip_chart.scale;
65      for (i = 1; i < w->strip_chart.scale; i++) {
66 -       j = i * (XtHeight(w) / w->strip_chart.scale);
67 +       j = i * (XtHeight(w) / w->strip_chart.scale) +
68 +           ((i * k + w->strip_chart.scale/2) / w->strip_chart.scale);
69         XDrawLine(XtDisplay((Widget)w), XtWindow((Widget)w),
70                   w->strip_chart.hiGC, left, j, XtWidth(w), j);
71      }
72 @@ -557,23 +561,26 @@
73      StripChartWidget w = (StripChartWidget)widget;
74      XPoint *points;
75      Cardinal size;
76 -    int i;
77 +    int i, k;
78  
79      if (w->strip_chart.scale <= 1) {
80         XtFree((char *)w->strip_chart.points);
81         w->strip_chart.points = NULL;
82         return;
83      }
84 -    
85 +
86      size = sizeof(XPoint) * (w->strip_chart.scale - 1);
87  
88      points = (XPoint *)XtRealloc((XtPointer)w->strip_chart.points, size);
89      w->strip_chart.points = points;
90  
91      /* Draw graph reference lines into clip mask */
92 -
93 +    k = XtHeight(w) % w->strip_chart.scale;
94      for (i = 1; i < w->strip_chart.scale; i++) {
95         points[i - 1].x = 0;
96 -       points[i - 1].y = XtHeight(w) / w->strip_chart.scale;
97 +       points[i - 1].y = i * (XtHeight(w) / w->strip_chart.scale) +
98 +           ((i * k + w->strip_chart.scale/2) / w->strip_chart.scale);
99      }
100 +    for (i = w->strip_chart.scale - 1; i > 1; i--)
101 +       points[i - 1].y -= points[i - 2].y;
102  }