[metapost] Re: [mp-implementors] Re: [fwd] A bug in mpgraph

Hans Hagen pragma at wxs.nl
Wed Mar 16 22:11:37 CET 2005


Yin Wang wrote:

> The files are here.
> In the plot the arrow is almost vertical.
> 
> And note that in gdrawarrow, no vertex coordinate can be larger than 4096, 
> while gdraw can.

here is what i can figure out after some tests (beware, i may be wrong)

- your plot itself is almost vertical

1 44
2 47
3 77
4 259
5 259
6 266
7 266
8 280
9 280
10 454
11 493
12 653
13 653
14 693
15 693
16 740
17 740
18 1160
19 1160
20 1188
21 1188
22 2882
24 3276
25 4096

- the arrowhead is calculated using the unscaled path
- this means that the arrowhead needs to be rotated according to the final scaling
- unfortunately we don't know the final dimensions (scale) then

so, a fix should come down to:

- calculate the xy-scale ratio earlier
- rotate the arrowhead accordingly

however, this is kind of impossible because content can be added after the
arrowhead is drawn

now, i'm no mathematician, but my impression is that an arrow in such a case is
kind of tricky anyway; an option is to use log axis (didn't test that)

Here is a workaround:

gdrawarrow_rotation := 0 ;

vardef Garwhd_(expr p)(text w) =
    addto Gcur_ also image (
        save _p_ ; picture _p_ ; _p_ := image (
            filldraw arrowhead(Garhwext_(precontrol infinity of p, point
infinity of p)) w;
        ) ;
        draw _p_ rotatedaround(point infinity of p,gdrawarrow_rotation) ;
        Gsetb_ point infinity of p..cycle ;
        gdrawarrow_rotation := 0 ;
    ) ;
enddef;

draw begingraph(12cm,8cm);

  setrange(origin,25.5,whatever);

  gdrawarrow_rotation := -15 ;

  gdrawarrow "chap6_opencircuit.d";

endgraph;



Hans






-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------



More information about the metapost mailing list