Fossil

Check-in [68635d60]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the timeline graph generator so that it works with two or more graphs on a single page.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:68635d60dff02af1ea9a9351121962cd17dd691ec7797cce180b49634eaa3e7d
User & Date: drh 2017-12-06 17:38:02
Context
2017-12-06
18:02
Fix over-length source code lines in timeline.c. check-in: d7435bc2 user: drh tags: trunk
17:38
Fix the timeline graph generator so that it works with two or more graphs on a single page. check-in: 68635d60 user: drh tags: trunk
17:14
Fix harmless typo in comment. check-in: bf82c41d user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/finfo.c.

310
311
312
313
314
315
316

317
318
319
320
321
322
323
...
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
...
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
  HQuery url;
  GraphContext *pGraph;
  int brBg = P("brbg")!=0;
  int uBg = P("ubg")!=0;
  int fDebug = atoi(PD("debug","0"));
  int fShowId = P("showid")!=0;
  Stmt qparent;

  int tmFlags = 0;            /* Viewing mode */
  const char *zStyle;         /* Viewing mode name */

  login_check_credentials();
  if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
  style_header("File History");
  login_anonymous_available();
................................................................................
    blob_appendf(&title, "History of ");
    hyperlinked_path(zFilename, &title, 0, "tree", "");
    if( fShowId ) blob_appendf(&title, " (%d)", fnid);
  }
  @ <h2>%b(&title)</h2>
  blob_reset(&title);
  pGraph = graph_init();
  @ <table id="timelineTable" class="timelineTable">
  if( baseCheckin ){
    db_prepare(&qparent,
      "SELECT DISTINCT pid FROM mlink"
      " WHERE fid=:fid AND mid=:mid AND pid>0 AND fnid=:fnid"
      "   AND pmid IN (SELECT rid FROM ancestor)"
      " ORDER BY isaux /*sort*/"
    );
................................................................................
      graph_free(pGraph);
      pGraph = 0;
    }else{
      @ <tr class="timelineBottom"><td></td><td></td><td></td></tr>
    }
  }
  @ </table>
  timeline_output_graph_javascript(pGraph, 0, 1);
  style_footer();
}

/*
** WEBPAGE: mlink
** URL: /mlink?name=FILENAME
** URL: /mlink?ci=NAME







>







 







|







 







|







310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
...
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
...
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
  HQuery url;
  GraphContext *pGraph;
  int brBg = P("brbg")!=0;
  int uBg = P("ubg")!=0;
  int fDebug = atoi(PD("debug","0"));
  int fShowId = P("showid")!=0;
  Stmt qparent;
  int iTableId = timeline_tableid();
  int tmFlags = 0;            /* Viewing mode */
  const char *zStyle;         /* Viewing mode name */

  login_check_credentials();
  if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
  style_header("File History");
  login_anonymous_available();
................................................................................
    blob_appendf(&title, "History of ");
    hyperlinked_path(zFilename, &title, 0, "tree", "");
    if( fShowId ) blob_appendf(&title, " (%d)", fnid);
  }
  @ <h2>%b(&title)</h2>
  blob_reset(&title);
  pGraph = graph_init();
  @ <table id="timelineTable%d(iTableId)" class="timelineTable">
  if( baseCheckin ){
    db_prepare(&qparent,
      "SELECT DISTINCT pid FROM mlink"
      " WHERE fid=:fid AND mid=:mid AND pid>0 AND fnid=:fnid"
      "   AND pmid IN (SELECT rid FROM ancestor)"
      " ORDER BY isaux /*sort*/"
    );
................................................................................
      graph_free(pGraph);
      pGraph = 0;
    }else{
      @ <tr class="timelineBottom"><td></td><td></td><td></td></tr>
    }
  }
  @ </table>
  timeline_output_graph_javascript(pGraph, 0, iTableId, 1);
  style_footer();
}

/*
** WEBPAGE: mlink
** URL: /mlink?name=FILENAME
** URL: /mlink?ci=NAME

Changes to src/graph.js.

1
2
3
4
5
6

7
8
9
10
11
12
13
14
..
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359




















/* This module contains javascript needed to render timeline graphs in Fossil.
**
** Prior to sourcing this script, there should be a separate
** <script type='application/json' id='timeline-data'> containing JSON
** like this:
**

**   { "circleNodes": BOOLEAN,      // True for circle nodes. False for squares
**     "showArrowheads": BOOLEAN,   // True for arrowheads. False to omit
**     "iRailPitch": INTEGER,       // Spacing between vertical lines (px)
**     "colorGraph": BOOLEAN,       // True to put color on graph lines
**     "nomo": BOOLEAN,             // True to join merge lines with rails
**     "iTopRow": INTEGER,          // Index of top-most row in the graph
**     "omitDescenders": BOOLEAN,   // Omit ancestor lines off bottom of screen
**     "fileDiff": BOOLEAN,         // True for file diff. False for check-in
................................................................................
**   mi:  "merge-in".  An array of integer rail positions from which
**        merge arrows should be drawn into this node.  If the value is
**        negative, then the rail position is the absolute value of mi[]
**        and a thin merge-arrow descender is drawn to the bottom of
**        the screen.
**    h:  The artifact hash of the object being graphed
*/
var timelineObj = document.getElementById("timeline-data");
var timelineJson = timelineObj.textContent || timelineObj.innerText;
var tx = JSON.parse(timelineJson);
var css = "";
if( tx.circleNodes ){
  css += ".tl-node, .tl-node:after { border-radius: 50%; }";
}
if( tx.showArrowheads ){
  css += ".tl-arrow.u { display: none; }";
}
if( css!=="" ){
  var style = document.createElement("style");
  style.textContent = css;
  document.querySelector("head").appendChild(style);
}
var canvasDiv;
var railPitch;
var mergeOffset;
var node, arrow, arrowSmall, line, mArrow, mLine, wArrow, wLine;
function initGraph(){
  var parent = document.getElementById("timelineTable").rows[0].cells[1];
  parent.style.verticalAlign = "top";
  canvasDiv = document.createElement("div");
  canvasDiv.className = "tl-canvas";
  canvasDiv.style.position = "absolute";
  parent.appendChild(canvasDiv);

  var elems = {};
  var elemClasses = [
    "rail", "mergeoffset", "node", "arrow u", "arrow u sm", "line",
    "arrow merge r", "line merge", "arrow warp", "line warp"
  ];
  for( var i=0; i<elemClasses.length; i++ ){
    var cls = elemClasses[i];
    var elem = document.createElement("div");
    elem.className = "tl-" + cls;
    if( cls.indexOf("line")==0 ) elem.className += " v";
    canvasDiv.appendChild(elem);
    var k = cls.replace(/\s/g, "_");
    var r = elem.getBoundingClientRect();
    var w = Math.round(r.right - r.left);
    var h = Math.round(r.bottom - r.top);
    elems[k] = {w: w, h: h, cls: cls};
  }
  node = elems.node;
  arrow = elems.arrow_u;
  arrowSmall = elems.arrow_u_sm;
  line = elems.line;
  mArrow = elems.arrow_merge_r;
  mLine = elems.line_merge;
  wArrow = elems.arrow_warp;
  wLine = elems.line_warp;

  var minRailPitch = Math.ceil((node.w+line.w)/2 + mArrow.w + 1);
  if( tx.iRailPitch>0 ){
    railPitch = tx.iRailPitch;
  }else{
    railPitch = elems.rail.w;
    railPitch -= Math.floor((tx.nrail-1)*(railPitch-minRailPitch)/21);
  }
  railPitch = Math.max(railPitch, minRailPitch);

  if( tx.nomo ){
    mergeOffset = 0;
  }else{
    mergeOffset = railPitch-minRailPitch-mLine.w;
    mergeOffset = Math.min(mergeOffset, elems.mergeoffset.w);
    mergeOffset = mergeOffset>0 ? mergeOffset + line.w/2 : 0;
  }

  var canvasWidth = (tx.nrail-1)*railPitch + node.w;
  canvasDiv.style.width = canvasWidth + "px";
  canvasDiv.style.position = "relative";
}
function drawBox(cls,color,x0,y0,x1,y1){
  var n = document.createElement("div");
  x0 = Math.floor(x0);
  y0 = Math.floor(y0);
  x1 = x1 || x1===0 ? Math.floor(x1) : x0;
  y1 = y1 || y1===0 ? Math.floor(y1) : y0;
  if( x0>x1 ){ var t=x0; x0=x1; x1=t; }
  if( y0>y1 ){ var t=y0; y0=y1; y1=t; }
  var w = x1-x0;
  var h = y1-y0;
  n.style.position = "absolute";
  n.style.left = x0+"px";
  n.style.top = y0+"px";
  if( w ) n.style.width = w+"px";
  if( h ) n.style.height = h+"px";
  if( color ) n.style.backgroundColor = color;
  n.className = "tl-"+cls;
  canvasDiv.appendChild(n);
  return n;
}
function absoluteY(obj){
  var top = 0;
  if( obj.offsetParent ){
    do{
      top += obj.offsetTop;
    }while( obj = obj.offsetParent );
  }
  return top;
}
function miLineY(p){
  return p.y + node.h - mLine.w - 1;
}
function drawLine(elem,color,x0,y0,x1,y1){
  var cls = elem.cls + " ";
  if( x1===null ){
    x1 = x0+elem.w;
    cls += "v";
  }else{
    y1 = y0+elem.w;
    cls += "h";
  }
  drawBox(cls,color,x0,y0,x1,y1);
}
function drawUpArrow(from,to,color){
  var y = to.y + node.h;
  var arrowSpace = from.y - y + (!from.id || from.r!=to.r ? node.h/2 : 0);
  var arw = arrowSpace < arrow.h*1.5 ? arrowSmall : arrow;
  var x = to.x + (node.w-line.w)/2;
  var y0 = from.y + node.h/2;
  var y1 = Math.ceil(to.y + node.h + arw.h/2);
  drawLine(line,color,x,y0,null,y1);
  x = to.x + (node.w-arw.w)/2;
  var n = drawBox(arw.cls,null,x,y);
  n.style.borderBottomColor = color;
}
function drawMergeLine(x0,y0,x1,y1){
  drawLine(mLine,null,x0,y0,x1,y1);
}
function drawMergeArrow(p,rail){
  var x0 = rail*railPitch + node.w/2;
  if( rail in mergeLines ){
    x0 += mergeLines[rail];
    if( p.r<rail ) x0 += mLine.w;
  }else{
    x0 += (p.r<rail ? -1 : 1)*line.w/2;
  }
  var x1 = mArrow.w ? mArrow.w/2 : -node.w/2;
  x1 = p.x + (p.r<rail ? node.w + Math.ceil(x1) : -x1);
  var y = miLineY(p);
  drawMergeLine(x0,y,x1,null);
  var x = p.x + (p.r<rail ? node.w : -mArrow.w);
  var cls = "arrow merge " + (p.r<rail ? "l" : "r");
  drawBox(cls,null,x,y+(mLine.w-mArrow.h)/2);
}
function drawNode(p, btm){
  if( p.u>0 ) drawUpArrow(p,tx.rowinfo[p.u-tx.iTopRow],p.fg);
  var cls = node.cls;
  if( p.mi.length ) cls += " merge";
  if( p.f&1 ) cls += " leaf";
  var n = drawBox(cls,p.bg,p.x,p.y);
  n.id = "tln"+p.id;
  n.onclick = clickOnNode;
  n.style.zIndex = 10;
  if( !tx.omitDescenders ){
    if( p.u==0 ) drawUpArrow(p,{x: p.x, y: -node.h},p.fg);
    if( p.d ) drawUpArrow({x: p.x, y: btm-node.h/2},p,p.fg);
  }
  if( p.mo>=0 ){
    var x0 = p.x + node.w/2;
    var x1 = p.mo*railPitch + node.w/2;
    var u = tx.rowinfo[p.mu-tx.iTopRow];
    var y1 = miLineY(u);
    if( p.u<0 || p.mo!=p.r ){
      x1 += mergeLines[p.mo] = -mLine.w/2;
      var y0 = p.y+2;
      if( p.r!=p.mo ) drawMergeLine(x0,y0,x1+(x0<x1 ? mLine.w : 0),null);
      drawMergeLine(x1,y0+mLine.w,null,y1);
    }else if( mergeOffset ){
      mergeLines[p.mo] = u.r<p.r ? -mergeOffset-mLine.w : mergeOffset;
      x1 += mergeLines[p.mo];
      drawMergeLine(x1,p.y+node.h/2,null,y1);
    }else{
      delete mergeLines[p.mo];
    }
  }
  for( var i=0; i<p.au.length; i+=2 ){
    var rail = p.au[i];
    var x0 = p.x + node.w/2;
    var x1 = rail*railPitch + (node.w-line.w)/2;
    if( x0<x1 ){
      x0 = Math.ceil(x0);
      x1 += line.w;
    }
    var y0 = p.y + (node.h-line.w)/2;
    var u = tx.rowinfo[p.au[i+1]-tx.iTopRow];
    if( u.id<p.id ){
      drawLine(line,u.fg,x0,y0,x1,null);
      drawUpArrow(p,u,u.fg);
    }else{
      var y1 = u.y + (node.h-line.w)/2;
      drawLine(wLine,u.fg,x0,y0,x1,null);
      drawLine(wLine,u.fg,x1-line.w,y0,null,y1+line.w);
      drawLine(wLine,u.fg,x1,y1,u.x-wArrow.w/2,null);
      var x = u.x-wArrow.w;
      var y = u.y+(node.h-wArrow.h)/2;
      var n = drawBox(wArrow.cls,null,x,y);
      if( u.fg ) n.style.borderLeftColor = u.fg;
    }
  }
  for( var i=0; i<p.mi.length; i++ ){
    var rail = p.mi[i];
    if( rail<0 ){
      rail = -rail;
      mergeLines[rail] = -mLine.w/2;
      var x = rail*railPitch + (node.w-mLine.w)/2;
      drawMergeLine(x,miLineY(p),null,btm);
    }
    drawMergeArrow(p,rail);
  }
}
var mergeLines;
function renderGraph(){
  mergeLines = {};
  canvasDiv.innerHTML = "";
  var canvasY = absoluteY(canvasDiv);
  for(var i=0; i<tx.rowinfo.length; i++ ){
    var e = document.getElementById("m"+tx.rowinfo[i].id);
    tx.rowinfo[i].y = absoluteY(e) - canvasY;
    tx.rowinfo[i].x = tx.rowinfo[i].r*railPitch;
  }
  var tlBtm = document.querySelector(".timelineBottom");
  if( tlBtm.offsetHeight<node.h ){
    tlBtm.style.height = node.h + "px";
  }
  var btm = absoluteY(tlBtm) - canvasY + tlBtm.offsetHeight;
  for( var i=tx.rowinfo.length-1; i>=0; i-- ){
    drawNode(tx.rowinfo[i], btm);
  }
}
var selRow;
function clickOnNode(){
  var p = tx.rowinfo[parseInt(this.id.match(/\d+$/)[0], 10)-tx.iTopRow];
  if( !selRow ){
    selRow = p;
    this.className += " sel";
    canvasDiv.className += " sel";
  }else if( selRow==p ){
    selRow = null;
    this.className = this.className.replace(" sel", "");
    canvasDiv.className = canvasDiv.className.replace(" sel", "");
  }else{
    if( tx.fileDiff ){
      location.href=tx.baseUrl + "/fdiff?v1="+selRow.h+"&v2="+p.h
    }else{
      location.href=tx.baseUrl + "/vdiff?from="+selRow.h+"&to="+p.h
    }
  }
}
function changeDisplay(selector,value){
  var x = document.getElementsByClassName(selector);
  var n = x.length;
  for(var i=0; i<n; i++) {x[i].style.display = value;}
}
function changeDisplayById(id,value){
  var x = document.getElementById(id);
  if(x) x.style.display=value;
}
function toggleDetail(){
  var id = parseInt(this.getAttribute('data-id'))
  var x = gebi("detail-"+id);
  if( x.style.display=="inline" ){
    x.style.display="none";
    changeDisplayById("ellipsis-"+id,"inline");
    changeDisplayById("links-"+id,"none");
  }else{
    x.style.display="inline";
    changeDisplayById("ellipsis-"+id,"none");
    changeDisplayById("links-"+id,"inline");
  }
  checkHeight();
}
function scrollToSelected(){
  var x = document.getElementsByClassName('timelineSelected');
  if(x[0]){
    var h = window.innerHeight;
    var y = absoluteY(x[0]) - h/2;
    if( y>0 ) window.scrollTo(0, y);
  }
}
var lastRow = gebi("m"+tx.rowinfo[tx.rowinfo.length-1].id);
var lastY = 0;
function checkHeight(){
  var h = absoluteY(lastRow);
  if( h!=lastY ){
    renderGraph();
    lastY = h;
  }
  setTimeout(checkHeight, 1000);
}
initGraph();
checkHeight();
scrollToSelected();

/* Set the onclick= attributes for elements of the "Compact" display
** mode so that clicking turns the details on and off. */
(function(){
  var lx = document.getElementsByClassName('timelineEllipsis');
  var i;
  for(i=0; i<lx.length; i++){
    if( lx[i].hasAttribute('data-id') ) lx[i].onclick = toggleDetail;
  }
  var lx = document.getElementsByClassName('timelineCompactComment');
  for(i=0; i<lx.length; i++){
    if( lx[i].hasAttribute('data-id') ) lx[i].onclick = toggleDetail;
  }
}())























|
|

>
|







 







|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
/* This module contains javascript needed to render timeline graphs in Fossil.
**
** Prior to sourcing this script, there should be a separate
** <script type='application/json' id='timeline-data-NN'> for each graph,
** each containing JSON like this:
**
**   { "iTableId": INTEGER,         // Table sequence number (NN)
**     "circleNodes": BOOLEAN,      // True for circle nodes. False for squares
**     "showArrowheads": BOOLEAN,   // True for arrowheads. False to omit
**     "iRailPitch": INTEGER,       // Spacing between vertical lines (px)
**     "colorGraph": BOOLEAN,       // True to put color on graph lines
**     "nomo": BOOLEAN,             // True to join merge lines with rails
**     "iTopRow": INTEGER,          // Index of top-most row in the graph
**     "omitDescenders": BOOLEAN,   // Omit ancestor lines off bottom of screen
**     "fileDiff": BOOLEAN,         // True for file diff. False for check-in
................................................................................
**   mi:  "merge-in".  An array of integer rail positions from which
**        merge arrows should be drawn into this node.  If the value is
**        negative, then the rail position is the absolute value of mi[]
**        and a thin merge-arrow descender is drawn to the bottom of
**        the screen.
**    h:  The artifact hash of the object being graphed
*/
var amendCssOnce = 1; // Only change the CSS one time
function amendCss(circleNodes,showArrowheads){
  if( !amendCssOnce ) return;
  var css = "";
  if( circleNodes ){
    css += ".tl-node, .tl-node:after { border-radius: 50%; }";
  }
  if( showArrowheads ){
    css += ".tl-arrow.u { display: none; }";
  }
  if( css!=="" ){
    var style = document.createElement("style");
    style.textContent = css;
    document.querySelector("head").appendChild(style);
  }
  amendCssOnce = 0;
}

function TimelineGraph(tx){
  var topObj = document.getElementById("timelineTable"+tx.iTableId);
  amendCss(tx.circleNodes, tx.showArrowheads);
  var canvasDiv;
  var railPitch;
  var mergeOffset;
  var node, arrow, arrowSmall, line, mArrow, mLine, wArrow, wLine;
  function initGraph(){
    var parent = topObj.rows[0].cells[1];
    parent.style.verticalAlign = "top";
    canvasDiv = document.createElement("div");
    canvasDiv.className = "tl-canvas";
    canvasDiv.style.position = "absolute";
    parent.appendChild(canvasDiv);
  
    var elems = {};
    var elemClasses = [
      "rail", "mergeoffset", "node", "arrow u", "arrow u sm", "line",
      "arrow merge r", "line merge", "arrow warp", "line warp"
    ];
    for( var i=0; i<elemClasses.length; i++ ){
      var cls = elemClasses[i];
      var elem = document.createElement("div");
      elem.className = "tl-" + cls;
      if( cls.indexOf("line")==0 ) elem.className += " v";
      canvasDiv.appendChild(elem);
      var k = cls.replace(/\s/g, "_");
      var r = elem.getBoundingClientRect();
      var w = Math.round(r.right - r.left);
      var h = Math.round(r.bottom - r.top);
      elems[k] = {w: w, h: h, cls: cls};
    }
    node = elems.node;
    arrow = elems.arrow_u;
    arrowSmall = elems.arrow_u_sm;
    line = elems.line;
    mArrow = elems.arrow_merge_r;
    mLine = elems.line_merge;
    wArrow = elems.arrow_warp;
    wLine = elems.line_warp;
  
    var minRailPitch = Math.ceil((node.w+line.w)/2 + mArrow.w + 1);
    if( tx.iRailPitch>0 ){
      railPitch = tx.iRailPitch;
    }else{
      railPitch = elems.rail.w;
      railPitch -= Math.floor((tx.nrail-1)*(railPitch-minRailPitch)/21);
    }
    railPitch = Math.max(railPitch, minRailPitch);
  
    if( tx.nomo ){
      mergeOffset = 0;
    }else{
      mergeOffset = railPitch-minRailPitch-mLine.w;
      mergeOffset = Math.min(mergeOffset, elems.mergeoffset.w);
      mergeOffset = mergeOffset>0 ? mergeOffset + line.w/2 : 0;
    }
  
    var canvasWidth = (tx.nrail-1)*railPitch + node.w;
    canvasDiv.style.width = canvasWidth + "px";
    canvasDiv.style.position = "relative";
  }
  function drawBox(cls,color,x0,y0,x1,y1){
    var n = document.createElement("div");
    x0 = Math.floor(x0);
    y0 = Math.floor(y0);
    x1 = x1 || x1===0 ? Math.floor(x1) : x0;
    y1 = y1 || y1===0 ? Math.floor(y1) : y0;
    if( x0>x1 ){ var t=x0; x0=x1; x1=t; }
    if( y0>y1 ){ var t=y0; y0=y1; y1=t; }
    var w = x1-x0;
    var h = y1-y0;
    n.style.position = "absolute";
    n.style.left = x0+"px";
    n.style.top = y0+"px";
    if( w ) n.style.width = w+"px";
    if( h ) n.style.height = h+"px";
    if( color ) n.style.backgroundColor = color;
    n.className = "tl-"+cls;
    canvasDiv.appendChild(n);
    return n;
  }
  function absoluteY(obj){
    var top = 0;
    if( obj.offsetParent ){
      do{
        top += obj.offsetTop;
      }while( obj = obj.offsetParent );
    }
    return top;
  }
  function miLineY(p){
    return p.y + node.h - mLine.w - 1;
  }
  function drawLine(elem,color,x0,y0,x1,y1){
    var cls = elem.cls + " ";
    if( x1===null ){
      x1 = x0+elem.w;
      cls += "v";
    }else{
      y1 = y0+elem.w;
      cls += "h";
    }
    drawBox(cls,color,x0,y0,x1,y1);
  }
  function drawUpArrow(from,to,color){
    var y = to.y + node.h;
    var arrowSpace = from.y - y + (!from.id || from.r!=to.r ? node.h/2 : 0);
    var arw = arrowSpace < arrow.h*1.5 ? arrowSmall : arrow;
    var x = to.x + (node.w-line.w)/2;
    var y0 = from.y + node.h/2;
    var y1 = Math.ceil(to.y + node.h + arw.h/2);
    drawLine(line,color,x,y0,null,y1);
    x = to.x + (node.w-arw.w)/2;
    var n = drawBox(arw.cls,null,x,y);
    n.style.borderBottomColor = color;
  }
  function drawMergeLine(x0,y0,x1,y1){
    drawLine(mLine,null,x0,y0,x1,y1);
  }
  function drawMergeArrow(p,rail){
    var x0 = rail*railPitch + node.w/2;
    if( rail in mergeLines ){
      x0 += mergeLines[rail];
      if( p.r<rail ) x0 += mLine.w;
    }else{
      x0 += (p.r<rail ? -1 : 1)*line.w/2;
    }
    var x1 = mArrow.w ? mArrow.w/2 : -node.w/2;
    x1 = p.x + (p.r<rail ? node.w + Math.ceil(x1) : -x1);
    var y = miLineY(p);
    drawMergeLine(x0,y,x1,null);
    var x = p.x + (p.r<rail ? node.w : -mArrow.w);
    var cls = "arrow merge " + (p.r<rail ? "l" : "r");
    drawBox(cls,null,x,y+(mLine.w-mArrow.h)/2);
  }
  function drawNode(p, btm){
    if( p.u>0 ) drawUpArrow(p,tx.rowinfo[p.u-tx.iTopRow],p.fg);
    var cls = node.cls;
    if( p.mi.length ) cls += " merge";
    if( p.f&1 ) cls += " leaf";
    var n = drawBox(cls,p.bg,p.x,p.y);
    n.id = "tln"+p.id;
    n.onclick = clickOnNode;
    n.style.zIndex = 10;
    if( !tx.omitDescenders ){
      if( p.u==0 ) drawUpArrow(p,{x: p.x, y: -node.h},p.fg);
      if( p.d ) drawUpArrow({x: p.x, y: btm-node.h/2},p,p.fg);
    }
    if( p.mo>=0 ){
      var x0 = p.x + node.w/2;
      var x1 = p.mo*railPitch + node.w/2;
      var u = tx.rowinfo[p.mu-tx.iTopRow];
      var y1 = miLineY(u);
      if( p.u<0 || p.mo!=p.r ){
        x1 += mergeLines[p.mo] = -mLine.w/2;
        var y0 = p.y+2;
        if( p.r!=p.mo ) drawMergeLine(x0,y0,x1+(x0<x1 ? mLine.w : 0),null);
        drawMergeLine(x1,y0+mLine.w,null,y1);
      }else if( mergeOffset ){
        mergeLines[p.mo] = u.r<p.r ? -mergeOffset-mLine.w : mergeOffset;
        x1 += mergeLines[p.mo];
        drawMergeLine(x1,p.y+node.h/2,null,y1);
      }else{
        delete mergeLines[p.mo];
      }
    }
    for( var i=0; i<p.au.length; i+=2 ){
      var rail = p.au[i];
      var x0 = p.x + node.w/2;
      var x1 = rail*railPitch + (node.w-line.w)/2;
      if( x0<x1 ){
        x0 = Math.ceil(x0);
        x1 += line.w;
      }
      var y0 = p.y + (node.h-line.w)/2;
      var u = tx.rowinfo[p.au[i+1]-tx.iTopRow];
      if( u.id<p.id ){
        drawLine(line,u.fg,x0,y0,x1,null);
        drawUpArrow(p,u,u.fg);
      }else{
        var y1 = u.y + (node.h-line.w)/2;
        drawLine(wLine,u.fg,x0,y0,x1,null);
        drawLine(wLine,u.fg,x1-line.w,y0,null,y1+line.w);
        drawLine(wLine,u.fg,x1,y1,u.x-wArrow.w/2,null);
        var x = u.x-wArrow.w;
        var y = u.y+(node.h-wArrow.h)/2;
        var n = drawBox(wArrow.cls,null,x,y);
        if( u.fg ) n.style.borderLeftColor = u.fg;
      }
    }
    for( var i=0; i<p.mi.length; i++ ){
      var rail = p.mi[i];
      if( rail<0 ){
        rail = -rail;
        mergeLines[rail] = -mLine.w/2;
        var x = rail*railPitch + (node.w-mLine.w)/2;
        drawMergeLine(x,miLineY(p),null,btm);
      }
      drawMergeArrow(p,rail);
    }
  }
  var mergeLines;
  function renderGraph(){
    mergeLines = {};
    canvasDiv.innerHTML = "";
    var canvasY = absoluteY(canvasDiv);
    for(var i=0; i<tx.rowinfo.length; i++ ){
      var e = document.getElementById("m"+tx.rowinfo[i].id);
      tx.rowinfo[i].y = absoluteY(e) - canvasY;
      tx.rowinfo[i].x = tx.rowinfo[i].r*railPitch;
    }
    var tlBtm = document.querySelector(".timelineBottom");
    if( tlBtm.offsetHeight<node.h ){
      tlBtm.style.height = node.h + "px";
    }
    var btm = absoluteY(tlBtm) - canvasY + tlBtm.offsetHeight;
    for( var i=tx.rowinfo.length-1; i>=0; i-- ){
      drawNode(tx.rowinfo[i], btm);
    }
  }
  var selRow;
  function clickOnNode(){
    var p = tx.rowinfo[parseInt(this.id.match(/\d+$/)[0], 10)-tx.iTopRow];
    if( !selRow ){
      selRow = p;
      this.className += " sel";
      canvasDiv.className += " sel";
    }else if( selRow==p ){
      selRow = null;
      this.className = this.className.replace(" sel", "");
      canvasDiv.className = canvasDiv.className.replace(" sel", "");
    }else{
      if( tx.fileDiff ){
        location.href=tx.baseUrl + "/fdiff?v1="+selRow.h+"&v2="+p.h
      }else{
        location.href=tx.baseUrl + "/vdiff?from="+selRow.h+"&to="+p.h
      }
    }
  }
  function changeDisplay(selector,value){
    var x = document.getElementsByClassName(selector);
    var n = x.length;
    for(var i=0; i<n; i++) {x[i].style.display = value;}
  }
  function changeDisplayById(id,value){
    var x = document.getElementById(id);
    if(x) x.style.display=value;
  }
  function toggleDetail(){
    var id = parseInt(this.getAttribute('data-id'))
    var x = gebi("detail-"+id);
    if( x.style.display=="inline" ){
      x.style.display="none";
      changeDisplayById("ellipsis-"+id,"inline");
      changeDisplayById("links-"+id,"none");
    }else{
      x.style.display="inline";
      changeDisplayById("ellipsis-"+id,"none");
      changeDisplayById("links-"+id,"inline");
    }
    checkHeight();
  }
  function scrollToSelected(){
    var x = document.getElementsByClassName('timelineSelected');
    if(x[0]){
      var h = window.innerHeight;
      var y = absoluteY(x[0]) - h/2;
      if( y>0 ) window.scrollTo(0, y);
    }
  }
  var lastRow = gebi("m"+tx.rowinfo[tx.rowinfo.length-1].id);
  var lastY = 0;
  function checkHeight(){
    var h = absoluteY(lastRow);
    if( h!=lastY ){
      renderGraph();
      lastY = h;
    }
    setTimeout(checkHeight, 1000);
  }
  initGraph();
  checkHeight();
  scrollToSelected();

  /* Set the onclick= attributes for elements of the "Compact" display
  ** mode so that clicking turns the details on and off.
  */
  var lx = topObj.getElementsByClassName('timelineEllipsis');
  var i;
  for(i=0; i<lx.length; i++){
    if( lx[i].hasAttribute('data-id') ) lx[i].onclick = toggleDetail;
  }
  lx = topObj.getElementsByClassName('timelineCompactComment');
  for(i=0; i<lx.length; i++){
    if( lx[i].hasAttribute('data-id') ) lx[i].onclick = toggleDetail;
  }
}
  
/* Look for all timeline-data-NN objects.  Load each one and draw
** a graph for each one.
*/
(function(){
  var i;
  for(i=0; 1; i++){
    var dataObj = document.getElementById("timeline-data-"+i);
    if(!dataObj) break;
    var txJson = dataObj.textContent || dataObj.innerText;
    var tx = JSON.parse(txJson);
    TimelineGraph(tx);
  }
}())

Changes to src/style.c.

83
84
85
86
87
88
89

90
91
92
93
94
95
96
...
502
503
504
505
506
507
508







509
510
511
512
513
514
515
...
527
528
529
530
531
532
533



534
535
536
537
538
539
540
static unsigned adUnitFlags = 0;

/*
** Flags for various javascript files needed prior to </body>
*/
static int needHrefJs = 0;   /* href.js */
static int needSortJs = 0;   /* sorttable.js */


/*
** Generate and return a anchor tag like this:
**
**        <a href="URL">
**  or    <a id="ID">
**
................................................................................

/*
** Indicate that the table-sorting javascript is needed.
*/
void style_table_sorter(void){
  needSortJs = 1;
}








/*
** Generate code to load a single javascript file
*/
void style_load_one_js_file(const char *zFile){
  @ <script src='%R/builtin/%s(zFile)?id=%S(MANIFEST_UUID)'></script>
}
................................................................................
    @ <script id='href-data' type='application/json'>\
    @ {"delay":%d(nDelay),"mouseover":%d(bMouseover)}</script>
    style_load_one_js_file("href.js");
  }
  if( needSortJs ){
    style_load_one_js_file("sorttable.js");
  }



}

/*
** Draw the footer at the bottom of the page.
*/
void style_footer(void){
  const char *zFooter;







>







 







>
>
>
>
>
>
>







 







>
>
>







83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
static unsigned adUnitFlags = 0;

/*
** Flags for various javascript files needed prior to </body>
*/
static int needHrefJs = 0;   /* href.js */
static int needSortJs = 0;   /* sorttable.js */
static int needGraphJs = 0;  /* graph.js */

/*
** Generate and return a anchor tag like this:
**
**        <a href="URL">
**  or    <a id="ID">
**
................................................................................

/*
** Indicate that the table-sorting javascript is needed.
*/
void style_table_sorter(void){
  needSortJs = 1;
}

/*
** Indicate that the table-sorting javascript is needed.
*/
void style_graph_generator(void){
  needGraphJs = 1;
}

/*
** Generate code to load a single javascript file
*/
void style_load_one_js_file(const char *zFile){
  @ <script src='%R/builtin/%s(zFile)?id=%S(MANIFEST_UUID)'></script>
}
................................................................................
    @ <script id='href-data' type='application/json'>\
    @ {"delay":%d(nDelay),"mouseover":%d(bMouseover)}</script>
    style_load_one_js_file("href.js");
  }
  if( needSortJs ){
    style_load_one_js_file("sorttable.js");
  }
  if( needGraphJs ){
    style_load_one_js_file("graph.js");
  }
}

/*
** Draw the footer at the bottom of the page.
*/
void style_footer(void){
  const char *zFooter;

Changes to src/timeline.c.

253
254
255
256
257
258
259

260
261
262
263
264
265
266
...
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
...
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
...
760
761
762
763
764
765
766

767
768
769
770
771
772
773
...
778
779
780
781
782
783
784
785

786
787
788
789
790
791
792
...
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
  static Stmt qbranch;
  int pendingEndTr = 0;       /* True if a </td></tr> is needed */
  int vid = 0;                /* Current checkout version */
  int dateFormat = 0;         /* 0: HH:MM (default) */
  int bCommentGitStyle = 0;   /* Only show comments through first blank line */
  const char *zStyle;         /* Sub-name for classes for the style */
  const char *zDateFmt;


  if( fossil_strcmp(g.zIpAddr, "127.0.0.1")==0 && db_open_local(0) ){
    vid = db_lget_int("checkout", 0);
  }
  zPrevDate[0] = 0;
  mxWikiLen = db_get_int("timeline-max-comment", 0);
  dateFormat = db_get_int("timeline-date-format", 0);
................................................................................
    pGraph = graph_init();
  }
  db_static_prepare(&qbranch,
    "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=:rid",
    TAG_BRANCH
  );

  @ <table id="timelineTable" class="timelineTable">
  blob_zero(&comment);
  while( db_step(pQuery)==SQLITE_ROW ){
    int rid = db_column_int(pQuery, 0);
    const char *zUuid = db_column_text(pQuery, 1);
    int isLeaf = db_column_int(pQuery, 5);
    const char *zBgClr = db_column_text(pQuery, 6);
    const char *zDate = db_column_text(pQuery, 2);
................................................................................
      pGraph = 0;
    }else{
      @ <tr class="timelineBottom"><td></td><td></td><td></td></tr>
    }
  }
  @ </table>
  if( fchngQueryInit ) db_finalize(&fchngQuery);
  timeline_output_graph_javascript(pGraph, (tmFlags & TIMELINE_DISJOINT)!=0, 0);
}

/*
** Change the RGB background color given in the argument in a foreground
** color with the same hue.
*/
static const char *bg_to_fg(const char *zIn){
................................................................................
/*
** Generate all of the necessary javascript to generate a timeline
** graph.
*/
void timeline_output_graph_javascript(
  GraphContext *pGraph,     /* The graph to be displayed */
  int omitDescenders,       /* True to omit descenders */

  int fileDiff              /* True for file diff.  False for check-in diff */
){
  if( pGraph && pGraph->nErr==0 && pGraph->nRow>0 ){
    GraphRow *pRow;
    int i;
    char cSep;
    int iRailPitch;      /* Pixels between consecutive rails */
................................................................................

    iRailPitch = atoi(PD("railpitch","0"));
    showArrowheads = skin_detail_boolean("timeline-arrowheads");
    circleNodes = skin_detail_boolean("timeline-circle-nodes");
    colorGraph = skin_detail_boolean("timeline-color-graph-lines");
    iTopRow = pGraph->pFirst ? pGraph->pFirst->idx : 0;

    @ <script id='timeline-data' type='application/json'>{

    @   "circleNodes": %d(circleNodes),
    @   "showArrowheads": %d(showArrowheads),
    @   "iRailPitch": %d(iRailPitch),
    @   "colorGraph": %d(colorGraph),
    @   "nomo": %d(PB("nomo")),
    @   "iTopRow": %d(iTopRow),
    @   "omitDescenders": %d(omitDescenders),
................................................................................
        }
      }
      if( cSep=='[' ) cgi_printf("[");
      cgi_printf("],\"h\":\"%!S\"}%s",
                 pRow->zUuid, pRow->pNext ? ",\n" : "]\n");
    }
    @ }</script>
    style_load_one_js_file("graph.js");
    graph_free(pGraph);
  }
}

/*
** Create a temporary table suitable for storing timeline data.
*/







>







 







|







 







|







 







>







 







|
>







 







|







253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
...
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
...
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
...
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
...
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
...
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
  static Stmt qbranch;
  int pendingEndTr = 0;       /* True if a </td></tr> is needed */
  int vid = 0;                /* Current checkout version */
  int dateFormat = 0;         /* 0: HH:MM (default) */
  int bCommentGitStyle = 0;   /* Only show comments through first blank line */
  const char *zStyle;         /* Sub-name for classes for the style */
  const char *zDateFmt;
  int iTableId = timeline_tableid();

  if( fossil_strcmp(g.zIpAddr, "127.0.0.1")==0 && db_open_local(0) ){
    vid = db_lget_int("checkout", 0);
  }
  zPrevDate[0] = 0;
  mxWikiLen = db_get_int("timeline-max-comment", 0);
  dateFormat = db_get_int("timeline-date-format", 0);
................................................................................
    pGraph = graph_init();
  }
  db_static_prepare(&qbranch,
    "SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=:rid",
    TAG_BRANCH
  );

  @ <table id="timelineTable%d(iTableId)" class="timelineTable">
  blob_zero(&comment);
  while( db_step(pQuery)==SQLITE_ROW ){
    int rid = db_column_int(pQuery, 0);
    const char *zUuid = db_column_text(pQuery, 1);
    int isLeaf = db_column_int(pQuery, 5);
    const char *zBgClr = db_column_text(pQuery, 6);
    const char *zDate = db_column_text(pQuery, 2);
................................................................................
      pGraph = 0;
    }else{
      @ <tr class="timelineBottom"><td></td><td></td><td></td></tr>
    }
  }
  @ </table>
  if( fchngQueryInit ) db_finalize(&fchngQuery);
  timeline_output_graph_javascript(pGraph, (tmFlags & TIMELINE_DISJOINT)!=0, iTableId, 0);
}

/*
** Change the RGB background color given in the argument in a foreground
** color with the same hue.
*/
static const char *bg_to_fg(const char *zIn){
................................................................................
/*
** Generate all of the necessary javascript to generate a timeline
** graph.
*/
void timeline_output_graph_javascript(
  GraphContext *pGraph,     /* The graph to be displayed */
  int omitDescenders,       /* True to omit descenders */
  int iTableId,             /* Which graph is this for */
  int fileDiff              /* True for file diff.  False for check-in diff */
){
  if( pGraph && pGraph->nErr==0 && pGraph->nRow>0 ){
    GraphRow *pRow;
    int i;
    char cSep;
    int iRailPitch;      /* Pixels between consecutive rails */
................................................................................

    iRailPitch = atoi(PD("railpitch","0"));
    showArrowheads = skin_detail_boolean("timeline-arrowheads");
    circleNodes = skin_detail_boolean("timeline-circle-nodes");
    colorGraph = skin_detail_boolean("timeline-color-graph-lines");
    iTopRow = pGraph->pFirst ? pGraph->pFirst->idx : 0;

    @ <script id='timeline-data-%d(iTableId)' type='application/json'>{
    @   "iTableId": %d(iTableId),
    @   "circleNodes": %d(circleNodes),
    @   "showArrowheads": %d(showArrowheads),
    @   "iRailPitch": %d(iRailPitch),
    @   "colorGraph": %d(colorGraph),
    @   "nomo": %d(PB("nomo")),
    @   "iTopRow": %d(iTopRow),
    @   "omitDescenders": %d(omitDescenders),
................................................................................
        }
      }
      if( cSep=='[' ) cgi_printf("[");
      cgi_printf("],\"h\":\"%!S\"}%s",
                 pRow->zUuid, pRow->pNext ? ",\n" : "]\n");
    }
    @ }</script>
    style_graph_generator();
    graph_free(pGraph);
  }
}

/*
** Create a temporary table suitable for storing timeline data.
*/