% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = ConTeXt (LuaTeX)
\setuppagenumber[state=stop]
\setupcaptions[number=no]
\usemodule[graph] 
%input graph

\startuseMPgraphic{graph::MEP}
boolean graph_close_file;
graph_close_file := false;
numeric u, y, x;
numeric a[];
u:= 1;
y:= u*1cm;
x:=u*1cm;
path q[];
path p[];

%%%%%Definition Marqueurs
picture rondpetit ; rondpetit := image(fill fullcircle scaled 3mm withcolor white;draw fullcircle scaled 3mm;);

picture rondpleinpetit ; rondpleinpetit := image(draw fullcircle scaled 3mm ;fill fullcircle scaled 3mm;);

picture barre; barre := image(draw (-1mm,0)--(1mm,0););

def MEPpre(expr xa, xb, sda, sdb) =
draw (xa-0mm, xb+sda)--(xa-0mm, xb-sdb);
draw barre shifted (xa-0mm, xb+sda);
draw barre shifted (xa-0mm, xb-sdb);
draw rondpetit shifted (xa-0mm, xb);
enddef;

def MEPpost(expr xa, xb, sda, sdb) =
draw (xa-0mm, xb+sda)--(xa-0mm, xb-sdb);
draw barre shifted (xa-0mm, xb+sda);
draw barre shifted (xa-0mm, xb-sdb);
draw rondpleinpetit shifted (xa-0mm, xb);
enddef;

def LegendePre(expr xa, xb) =
draw rondpetit shifted (xa-0mm, xb);
enddef;

def LegendePost(expr xa, xb) =
draw rondpleinpetit shifted (xa-0mm, xb);
enddef;

%%%%%%Axes
a1:=6;
a2:=5;
hauteury:=a1*y;
echelleMEP:=1/10*hauteury/a2;%echelle pour le plot des MEPs
draw (0,0)--(0,hauteury);

for i=0 step 1 until a2 :
draw(0,hauteury/a2*i)--(-0.1*x,hauteury/a2*i);
j:=i*10;
label.lft(textext(decimal j),(-0.1*x,hauteury/a2*i));
endfor;

%%%%%%Data plot
%Error Bar = SEM
%SUSgroup, sustained
gdata("sussus.d",s,
y1:= scantokens(s1);
y2:= scantokens(s2);
draw (1*x, y1*echelleMEP)--(2*x, y2*echelleMEP) withcolor 0.6 white;
);
MEPpre(1*x,9.78*echelleMEP,7.42*echelleMEP,0);
MEPpost(2*x,6.11*echelleMEP,3.55*echelleMEP,0);

%SUSgroup, explosive
gdata("susexpl.d",s,
y1:= scantokens(s1);
y2:= scantokens(s2);
draw (3*x, y1*echelleMEP)--(4*x, y2*echelleMEP) withcolor 0.6 white;
);
MEPpre(3*x,25.76*echelleMEP,17.09*echelleMEP,0);
MEPpost(4*x,25.38*echelleMEP,13.25*echelleMEP,0);

%EXplgroup, sustained
gdata("explsus.d",s,
y1:= scantokens(s1);
y2:= scantokens(s2);
draw (5.5*x, y1*echelleMEP)--(6.5*x, y2*echelleMEP) withcolor 0.6 white;
);
MEPpre(5.5*x,5.99*echelleMEP,3.93*echelleMEP,0);
MEPpost(6.5*x,3.49*echelleMEP,2.97*echelleMEP,0);

%EXplgroup, explosive
gdata("explexpl.d",s,
y1:= scantokens(s1);
y2:= scantokens(s2);
draw (7.5*x, y1*echelleMEP)--(8.5*x, y2*echelleMEP) withcolor 0.6 white;
);
MEPpre(7.5*x,26.14*echelleMEP,12.07*echelleMEP,0);
MEPpost(8.5*x,16.83*echelleMEP,8.46*echelleMEP,0);

%%%%%%%Legendes
LegendePre(0.3*x,50*echelleMEP); label.rt(btex Pre etex,(0.4*x,50*echelleMEP));
LegendePost(0.3*x,45*echelleMEP);label.rt(btex Post etex,(0.4*x,45*echelleMEP));

%%%%%%% Labels
label.lft(btex MEP area in \% Mmax area etex rotated 90, (-0.7*x,hauteury/2));
label(btex \star etex,(1.5*x,25*echelleMEP));
label(btex \star etex,(8*x,42*echelleMEP));
label.lft(btex Task etex,(0,-5*echelleMEP));
label.lft(btex Group etex,(0,-10*echelleMEP));
label(btex Sus etex,(1.5*x, -5*echelleMEP)); label(btex Expl etex,(3.5*x, -5*echelleMEP));
label(btex Sus etex,(6*x, -5*echelleMEP)); label(btex Expl etex,(8*x, -5*echelleMEP));
 label(btex SUSgroup etex,(2.5*x, -10*echelleMEP));  label(btex EXPLgroup etex,(7*x, -10*echelleMEP));
\stopuseMPgraphic

\starttext




\placefigure{}{\useMPgraphic{graph::MEP}}


\stoptext