summaryrefslogtreecommitdiff
path: root/texmf-dist/tex/latex/bargraph-js/dynam-js.def
blob: 4749e1322ba749bd9e1103730b2cb5c9f50feea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
%%
%% This is file `dynam-js.def',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% bargraph-js.dtx  (with options: `copyright,dynam')
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% bargraph-js.sty package,                              %%
%% Copyright (C) 2019                                    %%
%%   dpstory@uakron.edu                                  %%
%%                                                       %%
%% This program can redistributed and/or modified under  %%
%% the terms of the LaTeX Project Public License         %%
%% Distributed from CTAN archives in directory           %%
%% macros/latex/base/lppl.txt; either version 1.2 of the %%
%% License, or (at your option) any later version.       %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{insDLJS}{dynam}{Display dynamic bar graphs}
function displayDyBargraph(env,aPr,bPmf,bOptimize) {
  if (typeof aPr[0]=="undefined") return;
  var aBars=dataForEnv[env].bgs;
  var bar=env+"@"+dataForEnv[env].bgs[0];
  var n=aPr.length;
  var index=(bPmf)?1:2;
  var bc=color.red;
  var fc=color.blue;
  var lbl=_labelDyBars;
  if (arguments.length>4) {
    var o=arguments[4];
    bc=(o.bc==undefined)?bc:o.bc;
    fc=(o.fc==undefined)?fc:o.fc;
    var lbl=(o.lbl==undefined)?_labelDyBars:o.lbl;
  } else {
    var f=this.getField(bar+".bar0");
    if ( f !=null ) {
      bc=f.strokeColor;
      fc=f.fillColor;
    }
  }
  var hbar=bar.replace(/@/,"@x"); // dps07
  this.removeField(bar);
  var pos=hbar.indexOf("@");
  var env=hbar.substring(0,pos);
// get aux info, begin with
  var hb=this.getField(hbar);
  var f=hb.getArray()[0];
  var pg=f.page;
  var wd=dataForEnv[env].width;
  var ht=dataForEnv[env].height;
  var isHoriz=dataForEnv[env].horiz;
  var frameH=ht; // frameH is one unit high
  if (bPmf&&bOptimize) {
    var maxValue=0;
    for (var i=0; i<n; i++)
      if (aPr[i][index]>maxValue) maxValue=aPr[i][index];
  }
  var w=wd/(n+1);
  var r=f.rect;
  var defwidth=r[2]-r[0];
  if (defwidth*(n+1)>=wd) r[2]=r[0]+w;
  else w=defwidth;
  var gap=-1; // contiguous boundaries overlap
  var sf=(bPmf&&bOptimize)?frameH/maxValue:frameH;
  for (var i=0; i<n; i++){
    var g=this.addField(bar+".bar"+i,"button",pg,r);
    // calculate height
    var Rect=g.rect;
    var v=aPr[i][index];
    this.delay=true;
    Rect[1]=Rect[3]+(v*sf);
    var pr=aPr[i][0];
    g.userName=lbl(pr,v,bPmf);
    g.display=display.visible;
    g.rect=Rect;
    r[0]+=(w+gap);
    r[2]+=(w+gap);
    this.delay=false;
  }
  if (!bPmf) { // cdf
    var totalW=(n+1)*(w+gap);
    var delta=wd-totalW;
    r[2]+=delta;
    g=this.addField(bar+".bar"+n,"button",pg,r);
    var Rect=g.rect;
    var v=1;
    this.delay=true;
    Rect[1]=Rect[3]+(v*sf);
    g.display=display.visible;
    g.rect=Rect;
  }
// Now set color properties
  g=this.getField(bar);
  g.fillColor=fc;
  g.strokeColor=bc;
  this.delay=false;
}
function _labelDyBars(pr,v,bPmf) {
  return bPmf?("Pr(X="+pr+")="+v):("Pr(X<="+pr+")="+v);
}
\end{insDLJS}
\endinput
%%
%% End of file `dynam-js.def'.