Fossil SCM

Experimental query parameters brbg and ubg for the timeline.

drh 2011-07-22 23:15 trunk
Commit b6b419c32db4ca48b040562454f328568404e49f
1 file changed +44
--- src/timeline.c
+++ src/timeline.c
@@ -107,11 +107,43 @@
107107
#define TIMELINE_LEAFONLY 0x0002 /* Show "Leaf", but not "Merge", "Fork" etc */
108108
#define TIMELINE_BRIEF 0x0004 /* Combine adjacent elements of same object */
109109
#define TIMELINE_GRAPH 0x0008 /* Compute a graph */
110110
#define TIMELINE_DISJOINT 0x0010 /* Elements are not contiguous */
111111
#define TIMELINE_FCHANGES 0x0020 /* Detail file changes */
112
+#define TIMELINE_BRCOLOR 0x0040 /* Background color by branch name */
113
+#define TIMELINE_UCOLOR 0x0080 /* Background color by user */
112114
#endif
115
+
116
+/*
117
+** Hash a string and use the hash to determine a background color.
118
+*/
119
+const char *hashColor(const char *z){
120
+ int i; /* Loop counter */
121
+ unsigned int h = 0; /* Hash on the branch name */
122
+ int r, g, b; /* Values for red, green, and blue */
123
+ int mx, mn, h1, h2; /* Components of HSV */
124
+ static char zColor[10]; /* The resulting color */
125
+
126
+ for(i=0; z[i]; i++ ){
127
+ h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[0];
128
+ z++;
129
+ }
130
+ mx = 0xd1;
131
+ mn = 0xa8;
132
+ h1 = h%6;
133
+ h2 = ((h/6)%(mx - mn)) + mn;
134
+ switch( h1 ){
135
+ case 0: r = mx; g = h2, b = mn; break;
136
+ case 1: r = h2; g = mx, b = mn; break;
137
+ case 2: r = mn; g = mx, b = h2; break;
138
+ case 3: r = mn; g = h2, b = mx; break;
139
+ case 4: r = h2; g = mn, b = mx; break;
140
+ default: r = mx; g = mn, b = h2; break;
141
+ }
142
+ sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
143
+ return zColor;
144
+}
113145
114146
/*
115147
** Output a timeline in the web format given a query. The query
116148
** should return these columns:
117149
**
@@ -208,10 +240,11 @@
208240
memcpy(zTime, &zDate[11], 5);
209241
zTime[5] = 0;
210242
@ <tr>
211243
@ <td class="timelineTime">%s(zTime)</td>
212244
@ <td class="timelineGraph">
245
+ if( tmFlags & TIMELINE_UCOLOR ) zBgClr = zUser ? hashColor(zUser) : 0;
213246
if( pGraph && zType[0]=='c' ){
214247
int nParent = 0;
215248
int aParent[32];
216249
const char *zBr;
217250
int gidx;
@@ -234,10 +267,17 @@
234267
db_bind_int(&qbranch, ":rid", rid);
235268
if( db_step(&qbranch)==SQLITE_ROW ){
236269
zBr = db_column_text(&qbranch, 0);
237270
}else{
238271
zBr = "trunk";
272
+ }
273
+ if( tmFlags & TIMELINE_BRCOLOR ){
274
+ if( zBr==0 || strcmp(zBr,"trunk")==0 ){
275
+ zBgClr = 0;
276
+ }else{
277
+ zBgClr = hashColor(zBr);
278
+ }
239279
}
240280
gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr, zBgClr, isLeaf);
241281
db_reset(&qbranch);
242282
@ <div id="m%d(gidx)"></div>
243283
}
@@ -768,10 +808,12 @@
768808
** fc Show details of files changed
769809
** f=RID Show family (immediate parents and children) of RID
770810
** from=RID Path from...
771811
** to=RID ... to this
772812
** nomerge ... avoid merge links on the path
813
+** brbg Background color from branch name
814
+** ubg Background color from user
773815
**
774816
** p= and d= can appear individually or together. If either p= or d=
775817
** appear, then u=, y=, a=, and b= are ignored.
776818
**
777819
** If a= and b= appear, only a= is used. If neither appear, the most
@@ -826,10 +868,12 @@
826868
tmFlags = TIMELINE_GRAPH;
827869
}
828870
if( P("ng")!=0 || zSearch!=0 ){
829871
tmFlags &= ~TIMELINE_GRAPH;
830872
}
873
+ if( P("brbg")!=0 ) tmFlags |= TIMELINE_BRCOLOR;
874
+ if( P("ubg")!=0 ) tmFlags |= TIMELINE_UCOLOR;
831875
832876
style_header("Timeline");
833877
login_anonymous_available();
834878
timeline_temp_table();
835879
blob_zero(&sql);
836880
--- src/timeline.c
+++ src/timeline.c
@@ -107,11 +107,43 @@
107 #define TIMELINE_LEAFONLY 0x0002 /* Show "Leaf", but not "Merge", "Fork" etc */
108 #define TIMELINE_BRIEF 0x0004 /* Combine adjacent elements of same object */
109 #define TIMELINE_GRAPH 0x0008 /* Compute a graph */
110 #define TIMELINE_DISJOINT 0x0010 /* Elements are not contiguous */
111 #define TIMELINE_FCHANGES 0x0020 /* Detail file changes */
 
 
112 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
114 /*
115 ** Output a timeline in the web format given a query. The query
116 ** should return these columns:
117 **
@@ -208,10 +240,11 @@
208 memcpy(zTime, &zDate[11], 5);
209 zTime[5] = 0;
210 @ <tr>
211 @ <td class="timelineTime">%s(zTime)</td>
212 @ <td class="timelineGraph">
 
213 if( pGraph && zType[0]=='c' ){
214 int nParent = 0;
215 int aParent[32];
216 const char *zBr;
217 int gidx;
@@ -234,10 +267,17 @@
234 db_bind_int(&qbranch, ":rid", rid);
235 if( db_step(&qbranch)==SQLITE_ROW ){
236 zBr = db_column_text(&qbranch, 0);
237 }else{
238 zBr = "trunk";
 
 
 
 
 
 
 
239 }
240 gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr, zBgClr, isLeaf);
241 db_reset(&qbranch);
242 @ <div id="m%d(gidx)"></div>
243 }
@@ -768,10 +808,12 @@
768 ** fc Show details of files changed
769 ** f=RID Show family (immediate parents and children) of RID
770 ** from=RID Path from...
771 ** to=RID ... to this
772 ** nomerge ... avoid merge links on the path
 
 
773 **
774 ** p= and d= can appear individually or together. If either p= or d=
775 ** appear, then u=, y=, a=, and b= are ignored.
776 **
777 ** If a= and b= appear, only a= is used. If neither appear, the most
@@ -826,10 +868,12 @@
826 tmFlags = TIMELINE_GRAPH;
827 }
828 if( P("ng")!=0 || zSearch!=0 ){
829 tmFlags &= ~TIMELINE_GRAPH;
830 }
 
 
831
832 style_header("Timeline");
833 login_anonymous_available();
834 timeline_temp_table();
835 blob_zero(&sql);
836
--- src/timeline.c
+++ src/timeline.c
@@ -107,11 +107,43 @@
107 #define TIMELINE_LEAFONLY 0x0002 /* Show "Leaf", but not "Merge", "Fork" etc */
108 #define TIMELINE_BRIEF 0x0004 /* Combine adjacent elements of same object */
109 #define TIMELINE_GRAPH 0x0008 /* Compute a graph */
110 #define TIMELINE_DISJOINT 0x0010 /* Elements are not contiguous */
111 #define TIMELINE_FCHANGES 0x0020 /* Detail file changes */
112 #define TIMELINE_BRCOLOR 0x0040 /* Background color by branch name */
113 #define TIMELINE_UCOLOR 0x0080 /* Background color by user */
114 #endif
115
116 /*
117 ** Hash a string and use the hash to determine a background color.
118 */
119 const char *hashColor(const char *z){
120 int i; /* Loop counter */
121 unsigned int h = 0; /* Hash on the branch name */
122 int r, g, b; /* Values for red, green, and blue */
123 int mx, mn, h1, h2; /* Components of HSV */
124 static char zColor[10]; /* The resulting color */
125
126 for(i=0; z[i]; i++ ){
127 h = (h<<11) ^ (h<<1) ^ (h>>3) ^ z[0];
128 z++;
129 }
130 mx = 0xd1;
131 mn = 0xa8;
132 h1 = h%6;
133 h2 = ((h/6)%(mx - mn)) + mn;
134 switch( h1 ){
135 case 0: r = mx; g = h2, b = mn; break;
136 case 1: r = h2; g = mx, b = mn; break;
137 case 2: r = mn; g = mx, b = h2; break;
138 case 3: r = mn; g = h2, b = mx; break;
139 case 4: r = h2; g = mn, b = mx; break;
140 default: r = mx; g = mn, b = h2; break;
141 }
142 sqlite3_snprintf(8, zColor, "#%02x%02x%02x", r,g,b);
143 return zColor;
144 }
145
146 /*
147 ** Output a timeline in the web format given a query. The query
148 ** should return these columns:
149 **
@@ -208,10 +240,11 @@
240 memcpy(zTime, &zDate[11], 5);
241 zTime[5] = 0;
242 @ <tr>
243 @ <td class="timelineTime">%s(zTime)</td>
244 @ <td class="timelineGraph">
245 if( tmFlags & TIMELINE_UCOLOR ) zBgClr = zUser ? hashColor(zUser) : 0;
246 if( pGraph && zType[0]=='c' ){
247 int nParent = 0;
248 int aParent[32];
249 const char *zBr;
250 int gidx;
@@ -234,10 +267,17 @@
267 db_bind_int(&qbranch, ":rid", rid);
268 if( db_step(&qbranch)==SQLITE_ROW ){
269 zBr = db_column_text(&qbranch, 0);
270 }else{
271 zBr = "trunk";
272 }
273 if( tmFlags & TIMELINE_BRCOLOR ){
274 if( zBr==0 || strcmp(zBr,"trunk")==0 ){
275 zBgClr = 0;
276 }else{
277 zBgClr = hashColor(zBr);
278 }
279 }
280 gidx = graph_add_row(pGraph, rid, nParent, aParent, zBr, zBgClr, isLeaf);
281 db_reset(&qbranch);
282 @ <div id="m%d(gidx)"></div>
283 }
@@ -768,10 +808,12 @@
808 ** fc Show details of files changed
809 ** f=RID Show family (immediate parents and children) of RID
810 ** from=RID Path from...
811 ** to=RID ... to this
812 ** nomerge ... avoid merge links on the path
813 ** brbg Background color from branch name
814 ** ubg Background color from user
815 **
816 ** p= and d= can appear individually or together. If either p= or d=
817 ** appear, then u=, y=, a=, and b= are ignored.
818 **
819 ** If a= and b= appear, only a= is used. If neither appear, the most
@@ -826,10 +868,12 @@
868 tmFlags = TIMELINE_GRAPH;
869 }
870 if( P("ng")!=0 || zSearch!=0 ){
871 tmFlags &= ~TIMELINE_GRAPH;
872 }
873 if( P("brbg")!=0 ) tmFlags |= TIMELINE_BRCOLOR;
874 if( P("ubg")!=0 ) tmFlags |= TIMELINE_UCOLOR;
875
876 style_header("Timeline");
877 login_anonymous_available();
878 timeline_temp_table();
879 blob_zero(&sql);
880

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button