ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* bar graphs, m-graph, sarith
@ 2013-07-07  2:01 John Kitzmiller
  2013-07-07 13:24 ` Alan BRASLAU
  0 siblings, 1 reply; 3+ messages in thread
From: John Kitzmiller @ 2013-07-07  2:01 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: kitz

When trying to make a bar graph with m-graph.mkiv and sarith, the command Ssub (string subtract) seems to Sadd instead. An mwe of a bar graph:

 (data1 is a separate file containing
  01 02
  02 03)

\usemodule[m-graph]
\startMPpage[instance=graph]
input sarith;
draw begingraph(5cm,5cm);
 gdata("data1", v,
          path p;
          augment.p(v1,0);
          augment.p(v1,v2)
          augment.p(v1 Sadd "0.4",v2);
          augment.p(v1 Sadd "0.4",0);
          gfill p--cycle withcolor .8white;
          gdraw p--cycle;
          );
endgraph;
\stopMPpage

...which gives bars of width 0.4 starting at abscissa 1 and 2 as expected. To increase the width of the bars to 0.8 and have them centered over 1 and 2, I expect to Ssub from the first two augments:

\usemodule[m-graph]
\startMPpage[instance=graph]
input sarith;
draw begingraph(5cm,5cm);
 gdata("data1", v,
          path p;
          augment.p(v1 Ssub "0.4",0);
          augment.p(v1 Ssub "0.4",v2);
          augment.p(v1 Sadd "0.4",v2);
          augment.p(v1 Sadd "0.4",0);
          gfill p--cycle withcolor .8white;
          gdraw p--cycle;
          );
endgraph;
\stopMPpage

However, the Ssub adds instead and gives a line at 1.4 and 2.4.

Compiling the above with mpost or mptopdf gives the desired result(s), but I am curious if this can be resolved so such bar graphs could be made within ConTeXT/METAFUN.

Thanks! John



___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bar graphs, m-graph, sarith
  2013-07-07  2:01 bar graphs, m-graph, sarith John Kitzmiller
@ 2013-07-07 13:24 ` Alan BRASLAU
  2013-07-08 21:28   ` John Kitzmiller
  0 siblings, 1 reply; 3+ messages in thread
From: Alan BRASLAU @ 2013-07-07 13:24 UTC (permalink / raw)
  To: kitz; +Cc: mailing list for ConTeXt users

Metapost now has double precision arithmetic, so one no longer needs to
use the string arithmetic macros. However, it may be necessary to use
scantokens as in

clearxy;
z = (scantokens v1, scantokens v2);
augment.p(x,0);
augment.p(x,y);
x := x + 0.4 ;
augment.p(x,y);
augment.p(x,0);


Alan


On Sat, 6 Jul 2013 22:01:06 -0400
John Kitzmiller <kitz@inradius.net> wrote:

> When trying to make a bar graph with m-graph.mkiv and sarith, the
> command Ssub (string subtract) seems to augment.p(v1 Sadd
> "0.4",v2);Sadd instead. An mwe of a bar graph:
> 
>  (data1 is a separate file containing
>   01 02
>   02 03)
> 
> \usemodule[m-graph]
> \startMPpage[instance=graph]
> input sarith;
> draw begingraph(5cm,5cm);
>  gdata("data1", v,
>           path p;
>           augment.p(v1,0);
>           augment.p(v1,v2)
>           augment.p(v1 Sadd "0.4",v2);
>           augment.p(v1 Sadd "0.4",0);
>           gfill p--cycle withcolor .8white;
>           gdraw p--cycle;
>           );
> endgraph;
> \stopMPpage
> 
> ...which gives bars of width 0.4 starting at abscissa 1 and 2 as
> expected. To increase the width of the bars to 0.8 and have them
> centered over 1 and 2, I expect to Ssub from the first two augments:
> 
> \usemodule[m-graph]
> \startMPpage[instance=graph]
> input sarith;
> draw begingraph(5cm,5cm);
>  gdata("data1", v,
>           path p;
>           augment.p(v1 Ssub "0.4",0);
>           augment.p(v1 Ssub "0.4",v2);
>           augment.p(v1 Sadd "0.4",v2);
>           augment.p(v1 Sadd "0.4",0);
>           gfill p--cycle withcolor .8white;
>           gdraw p--cycle;
>           );
> endgraph;
> \stopMPpage
> 
> However, the Ssub adds instead and gives a line at 1.4 and 2.4.
> 
> Compiling the above with mpost or mptopdf gives the desired
> result(s), but I am curious if this can be resolved so such bar
> graphs could be made within ConTeXT/METAFUN.
> 
> Thanks! John
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: bar graphs, m-graph, sarith
  2013-07-07 13:24 ` Alan BRASLAU
@ 2013-07-08 21:28   ` John Kitzmiller
  0 siblings, 0 replies; 3+ messages in thread
From: John Kitzmiller @ 2013-07-08 21:28 UTC (permalink / raw)
  To: Alan BRASLAU; +Cc: mailing list for ConTeXt users

Thank you Alan. That was exactly the redirection needed.

John

On Jul 7, 2013, at 9:24 AM, Alan BRASLAU wrote:

> Metapost now has double precision arithmetic, so one no longer needs to
> use the string arithmetic macros. However, it may be necessary to use
> scantokens as in
> 
> clearxy;
> z = (scantokens v1, scantokens v2);
> augment.p(x,0);
> augment.p(x,y);
> x := x + 0.4 ;
> augment.p(x,y);
> augment.p(x,0);
> 
> 
> Alan
> 
> 
> On Sat, 6 Jul 2013 22:01:06 -0400
> John Kitzmiller <kitz@inradius.net> wrote:
> 
>> When trying to make a bar graph with m-graph.mkiv and sarith, the
>> command Ssub (string subtract) seems to augment.p(v1 Sadd
>> "0.4",v2);Sadd instead. An mwe of a bar graph:
>> 
>> (data1 is a separate file containing
>>  01 02
>>  02 03)
>> 
>> \usemodule[m-graph]
>> \startMPpage[instance=graph]
>> input sarith;
>> draw begingraph(5cm,5cm);
>> gdata("data1", v,
>>          path p;
>>          augment.p(v1,0);
>>          augment.p(v1,v2)
>>          augment.p(v1 Sadd "0.4",v2);
>>          augment.p(v1 Sadd "0.4",0);
>>          gfill p--cycle withcolor .8white;
>>          gdraw p--cycle;
>>          );
>> endgraph;
>> \stopMPpage
>> 
>> ...which gives bars of width 0.4 starting at abscissa 1 and 2 as
>> expected. To increase the width of the bars to 0.8 and have them
>> centered over 1 and 2, I expect to Ssub from the first two augments:
>> 
>> \usemodule[m-graph]
>> \startMPpage[instance=graph]
>> input sarith;
>> draw begingraph(5cm,5cm);
>> gdata("data1", v,
>>          path p;
>>          augment.p(v1 Ssub "0.4",0);
>>          augment.p(v1 Ssub "0.4",v2);
>>          augment.p(v1 Sadd "0.4",v2);
>>          augment.p(v1 Sadd "0.4",0);
>>          gfill p--cycle withcolor .8white;
>>          gdraw p--cycle;
>>          );
>> endgraph;
>> \stopMPpage
>> 
>> However, the Ssub adds instead and gives a line at 1.4 and 2.4.
>> 
>> Compiling the above with mpost or mptopdf gives the desired
>> result(s), but I am curious if this can be resolved so such bar
>> graphs could be made within ConTeXT/METAFUN.
>> 
>> Thanks! John

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-07-08 21:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-07  2:01 bar graphs, m-graph, sarith John Kitzmiller
2013-07-07 13:24 ` Alan BRASLAU
2013-07-08 21:28   ` John Kitzmiller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).