(* ternarni diagram 3.3.2012 Pavel Pokorny *)
(* nastavime si adresar, odkud budeme cist soubory *)
SetDirectory["/home/pokornp/kr3"];
(* precteme si excellovsky soubor *)
v=Import["TERNAR.XLS"];
(* bude mas zajimat prvni list *)
v1=v[[1]];
(* najdeme tri dulezite radky a oznacime je n1,n2,n3 *)
Table[
(* pripravime si i-tou radku *)
r=v1[[i]];
(* zajima nas prvni slovo *)
w1 = r[[1]];
(* zajima nas prvni znak, zatim inicializujeme napr. mezerou *)
z1=" ";
(* je-li w1 string nenulove delky, zjistime prvni znak *)
If[StringQ[w1],If[StringLength[w1]>0,z1=Characters[w1][[1]]]];
(* je-li to e, uloz cislo radky do n1, zde zacinaji exp. data *)
If[z1=="e",n1=i];
(* je-li to V, uloz cislo radky do n2, zde zacinaji vyp. data *)
If[z1=="V",n2=i];
(* cislo posledniho radku s daty uloz do n3 *)
If[Length[r]==8, If[NumberQ[r[[2]]],n3=i]]
,{i,Length[v1]}]; 
(*prevod koncentraci na kartezske souradnice v rovine*)c2c[{ca_,cb_}]:={(1-ca+cb)/2,(1-ca-cb) Sqrt[3]/2};
(*aby nepsal tecku za nulou a jednickou*)
nf[x_]:=If[x==0,0,If[x==1,1,x]];
(* pripravime si znacky *)
trojuhelnicek[{x_,y_}]:=With[{rr=0.011},Polygon[Table[{x+rr*Cos[fi],y+rr*Sin[fi]},{fi,-Pi/2,3 Pi/2,2 Pi/3}]]];
ctverecek[{x_,y_}]:=With[{rr=0.011},Polygon[Table[{x+rr*Cos[fi],y+rr*Sin[fi]},{fi,Pi/4,9 Pi/4,Pi/2}]]];
(* a jdeme malovat *)
Graphics[{
(* obvod *)
Line[{c2c[{1,0}],c2c[{0,1}],c2c[{0,0}],c2c[{1,0}]}],
(* tenka mrizka *)
{Dashed,Thickness[0.001],
Table[{
Line[{c2c[{1-i,i}],c2c[{0,i}]}],
Line[{c2c[{1-i,i}],c2c[{1-i,0}]}],
Line[{c2c[{0,i}],c2c[{i,0}]}]},
{i,1/10,9/10,1/10}]},
(* dilky na osach *)
With[{rr=0.01},
Table[{
o=c2c[{1-i,i}];Line[{o,o-rr{0,1}}],
o=c2c[{0,i}];Line[{o,o+rr{Sqrt[3],1}/2}],
o=c2c[{i,0}];Line[{o,o+rr{-Sqrt[3],1}/2}]
},
{i,1/10,9/10,1/10}]],
(* popis vrcholu *)
Text[Style["A",Blue,Italic,FontSize->Scaled[0.06]],{-0.05,0.1}],
Text[Style["B",Blue,Italic,FontSize->Scaled[0.06]],{1.05,0.1}],
Text[Style["C",Blue,Italic,FontSize->Scaled[0.06]],{0.6,0.85}],
(* data *)
{Red,Table[ctverecek[c2c[{v1[[i,4]],v1[[i,2]]}]],{i,n1+1,n2-1}]},
{Blue,Table[ctverecek[c2c[{v1[[i,8]],v1[[i,6]]}]],{i,n1+1,n2-1}]},
{Brown,Line[Table[c2c[{v1[[i,4]],v1[[i,2]]}],{i,n2+1,n3}]]},
{Magenta,Line[Table[c2c[{v1[[i,8]],v1[[i,6]]}],{i,n2+1,n3}]]},
(* umiseni legendy *)
ul={0.9,0.6};
(* legenda *)
{Red,ctverecek[ul+{0,0.2}]},Text["Experiment",ul+{0.25,0.2}],
{Blue,ctverecek[ul+{0,0.15}]},Text["Experiment",ul+{0.25,0.15}],
{Brown,Line[{ul+{-0.05,0.1},ul+{0.05,0.1}}]},Text["Vypocet",ul+{0.25,0.1}],
{Magenta,Line[{ul+{-0.05,0.05},ul+{0.05,0.05}}]},Text["Vypocet",ul+{0.25,0.05}],
(* sirka ramecku legendy *)
srl=0.4;
(* vyska ramecku legendy *)
vrl=0.25;
(* ramecek legendy *)
Line[{ul-{0.1,0},ul+{srl,0},ul+{srl,vrl},ul+{-0.1,vrl},ul-{0.1,0}}]
}]