operations.html 16.2 KB
Newer Older
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
<!--

/* This js doc browser is part of GEGL
 *
 * GEGL is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * GEGL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
 *
 * 2014 Øyvind Kolås.
 */

-->

<html>
  <head><title>GEGL Operation Reference</title></head>

  <style>
    body { font-size: 1.0em; font-family: Sans; margin:0; }
28
    #query { border:0;padding:0;margin:0; background: rgba(250,250,250,0.8); width: 100%;
29 30 31 32 33 34 35
      position: fixed; top:0;left:0; z-index: 1;
      font-size: 1.5em;
      padding-left: 0.75em;
    }
    #view { padding-top: 4em; margin-left: 1em; margin-right: 1em; }
    .categories {
      font-size: 0.8em;
36 37 38 39 40 41
      position: fixed;
      width: auto;
      top: 0; right: 0;
      padding-top: 0.25em;
      padding-right: 0.25em;
      z-index: 2;
42 43
     }
     .category { 
44
       display: inline-block;
45 46 47 48 49
       padding-left: 0.25em;
       padding-right: 0.25em;
       color: blue;
       cursor: hand;
     }
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

     .view-source { 
       display: inline-block;
       padding-left: 0.25em;
       padding-right: 0.25em;
       color: blue;
       cursor: hand;
     }
     .category:hover { background: black; color: white; }

     .res_category { 
       display: inline-block;
       padding-left: 0.25em;
       padding-right: 0.25em;
       color: blue;
       cursor: hand;
     }
     .res_category:hover { background: black; color: white; }

69 70
    .op-image { margin: 1em; margin-top: 0em; margin-left: 0em; float: left }
    .properties {margin-top: 1em; clear: left; }
71
    .property { margin-top: 1em; margin-right: 2em; clear: both;
72 73
       padding-top: 1em;
    }
74 75 76 77 78 79 80
    .property>div { }

    .property>.property-label {
        display: block;
        float: none;
        font-size: 1.4em;
        min-width: 10em;
81 82 83 84 85 86 87 88 89 90 91 92
      }

    .pad-c {
    }
    .pad-label {
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
      display: inline-block;
    }
    .pad-val {
      display: inline-block;
      font-family: monospace;
      padding-right: 0.6em;
93 94
    }

95
    .property-name {
96 97 98
      font-family: Monospace;
      min-width: 6em;
      padding-right: 1em;
99 100 101 102
      float:left;
    }
    .property-name:before { content:"name: ";
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
103
      padding-right: 1em;
104 105 106
    }
    .property-type {
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
107
      padding-right: 1em;
108 109 110 111 112 113
      min-width: 4em;
      float:left;
    }
    .property-type:before { content:"type: ";
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
      font-size: 60%;
114 115
    }
    .property-default {
116
      padding-right: 1em;
117 118
      min-width: 4em;
      float:left;
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

    .property-default:before { content:"default: ";
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
      font-size: 60%;
    }

    .property-ui-gamma:before { content:"ui-gamma:";
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
      font-size: 60%;
    }

    .property-ui-digits:before { content:"ui-digits:";
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
      padding-right: 1.5em;
      font-size: 60%;
    }

    .property-value-range:before { content:"range:";
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
      padding-right: 2.2em;
      font-size: 60%;
    }

    .property-ui-range:before { content:"ui-range: ";
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
      padding-right: 0.8em;
      font-size: 60%;
    }
    .property-ui-steps:before { content:"ui-steps: ";
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
      padding-right: 1.0em;
      font-size: 60%;
    }
    .property-meta-key {
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
      font-size: 60%;
      min-width: 5.5em;
      display: inline-block;
      vertical-align: text-bottom;
      padding-top: 0.5em;
      float :left;
      clear: left;
    }
    .property-meta-value {
      display: inline-block;
      float :left;
    }

    .property-value-range,
    .property-ui-range,
    .property-ui-digits,
    .property-ui-gamma,
    .property-ui-steps,
    {
174 175 176 177 178 179
      -webkit-opacity: 0.5; -moz-opacity: 0.5; opacity: 0.5 ;
      padding-left: 1em;
        min-width: 6em;
    }
    .property-description {
      clear: left;
180 181 182 183 184 185 186 187
      padding-top: 0.5em;
    }

    .property>div.property-meta {
      float: right;
      min-width: 11em;
      padding-left: 1em;
      clear: right;
188
    }
189

190
    .opname  { font-weight: bold; margin-bottom: 0.2em; display: none; }
191 192 193 194
    .optitle { margin-bottom: 0.2em; 
    
               font-size: 1.4em;
    }
195

196
    .description { margin-bottom: 1em;}
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
    .result       { border: 2px solid transparent; }
    .result:hover { border: 2px solid black; background : #555; color :
      blue; cursor: hand; }
    .small .result     { display: inline-block; width: 150px; height: 150px;
      overflow: clip; }
    .small .result>img { margin-right:0.2em;min-width: 150px; height: 150px; }
    .small .result>div { display: inline-block;  position: relative; background:
      rgba(255,255,255, 0.8); padding-right: 0.4em; height: 1em;
      overflow:hidden;
      font-size: 0.75em;
      top: -1.0em; }
    .result { vertical-align: top; }
    .big .result     { display: inline-block; width: 200px; height: 200px;
      overflow: clip; }
    .big .result>img { margin-right:0.2em;min-width: 200px; height: 200px; }
    .big .result>div { display: inline-block;  position: relative; background:
      rgba(255,255,255, 0.8); padding-right: 0.4em; height: 1em;
      overflow:hidden;
      top: -1.0em; }
    .big>.result.text { height: 2em; }
    .small>.result.text { height: 2em; }
    .result.text>div { position:relative; top: 0.4em;}
  </style>

  <script src='operations.json'>
  </script>

  <script>

function id(idi) { return document.getElementById(idi) }
function show_op(op)
{
  id('view').innerHTML = window.opdb[0].op;
}

function filter_db(query)
{
  var opdb = window.opdb;
  var result = [];
  var uquery = query.toUpperCase ();

238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
  var command = query.split(' ');
  if (command.length > 1)
    {
      var arg;
      command = command[0];
      arg = query.slice(command.length + 1);

      if (command == 'op')
      {
        for (var i = 0; i < opdb.length; i++)
        {
          if (opdb[i].op == arg)
            return [opdb[i]];
        }
      }
    }

255 256
  for (var i = 0; i < opdb.length; i++)
  {
257
    var op = opdb[i];
258
    var score = 0;
259
    var uop_name = op.op.toUpperCase ();
260

261 262 263 264
    /* ad-hoc opencl query */
    if (query == 'opencl' && op['opencl-support'])
      score += 20;

265 266
    if (opdb[i].parent == query) score += 100;

267 268 269
    if (op.op.indexOf(query) == 0)           score += 1000;
    if (op.op.slice(5).indexOf(query) == 0)  score += 900;
    if (op.op.indexOf(query) > 0)            score += 500;
270

271
    if (op.meta) {
272
      var got_title = false;
273 274
      for (var j = 0; j < op.meta.length; j++)
      {
275 276
        if (op.meta[0] == 'title' )
          got_title = true;
277 278 279 280 281
        if (op.meta[j][1].indexOf(query) == 0) score += 100;
        if (op.meta[j][1].toUpperCase().indexOf(uquery) == 0) score += 100;
        if (op.meta[j][1].indexOf(query) >= 0) score += 10;
        if (op.meta[j][1].toUpperCase().indexOf(uquery) >= 0) score += 10;
      }
282 283
      if (query == 'notitle' && !got_title)
        score += 2;
284 285 286 287
    }

    if (op.description &&
        op.description.indexOf(query) >= 0)  score += 10;
288 289 290 291 292

    if (uop_name.indexOf(uquery) == 0)           score += 1000;
    if (uop_name.slice(5).indexOf(uquery) == 0)  score += 900;
    if (uop_name.indexOf(uquery) > 0)            score += 500;

293 294
    if (op.description &&
        op.description.toUpperCase().indexOf(uquery) >= 0)  score += 10;
295 296

      {
297 298
        if (op.categories)
        for (var j = 0; j < op.categories.length; j++)
299
        {
300
          if (op.categories[j].indexOf(query) >= 0)
301 302 303 304 305 306 307
          {
            score += 30;
            break;
          }
        }
      }

308 309 310 311 312 313
    if (op.image == undefined)
    {
      /* make image-less ones rise to(wards) top */
      score *= 2;
    }

314 315
    if (score > 0)
    {
316 317 318 319
      /* var o = JSON.parse(JSON.stringify(opdb[i])); */ /* we only have one
      set of results,. so updating score in-place */
        op.score = score;
        result.push (op);
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
      }
  }

  result = result.sort(function(a,b){
    if (a.score != b.score)
      return (b.score - a.score);
    return a.op > b.op;
  });
  return result;
}

var initialized = false;
var previous_content = "";

function render_properties(properties)
{
  var result = ''
  result += '<div class="properties">'
   for (var i = 0; i < properties.length ; i++)
     {
       var prop = properties[i];
       result += '<div class="property">';

343
       result += "<div class='property-meta'>";
344 345 346 347 348 349

       if (prop.minimum && prop.maximum)
         {
         result += '<div class="property-value-range" title="value range">' + prop.minimum + '&ndash;' + prop.maximum + ' </div>';
         }

350

351 352
       if (prop['ui-minimum'] && prop['ui-maximum'])
         {
353 354
         result += '<div class="property-ui-range">' + prop['ui-minimum'] +
           '&ndash;' + prop['ui-maximum'] + '</div>';
355
       }
356 357 358 359 360
       if (prop['ui-gamma'])
         {
         result += '<div class="property-ui-gamma">' + prop['ui-gamma'] + ' </div>';
         }

361 362
       if (prop['ui-step-small'] && prop['ui-step-big'])
         {
363 364 365 366 367 368
         result += '<div class="property-ui-steps">' + prop['ui-step-small'] +
           ',' + prop['ui-step-big'] + ' </div>';
         }
       if (prop['ui-digits'])
         {
         result += '<div class="property-ui-digits">' + prop['ui-digits'] + ' </div>';
369 370 371 372 373
         }
       if (prop.meta)
       {
         for (var j = 0; j < prop.meta.length; j++)
         {
374 375
           result += '<div class="property-meta-key">' + prop.meta[j][0] +
             ':</div><div class="property-meta-value">' + 
376 377 378
            prop.meta[j][1] + '</div>';
         }
       }
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394

       result += "</div>";


       result += '<div class="property-label">' + prop.label + ' </div>';
       result += '<div class="property-name">' + prop.name + ' </div>';
       result += '<div class="property-type" title="data type">' + prop.type + ' </div>';

       if (prop.default)
         result += '<div class="property-default" title="default value">' + prop.default+ ' </div>';



       if (prop.description)
         result += '<div class="property-description">' + prop.description + ' </div>';

395 396 397 398 399 400 401 402 403
     result += '</div>'
   }
   result += '</div>'
   return result;
}

function render_item (item)
{
  var result = '';
404 405 406
  result += '<div class="categories">';


407 408 409 410 411 412
  if (item.categories)
  {
    for (var i = 0; i < item.categories.length; i ++)
    {
      result += '<div class="category" ' + "onclick='go(\""+item.categories[i]+"\")'" + '>' + item.categories[i] + '</div>';
    }
413 414 415 416
    result += '<div class="category" '+"onclick='go(\""+item.parent+"\")'" + '>' + item.parent.slice(13) + '</div>';

  if (item['opencl-support'])
    result += '<div class="category" '+"onclick=\"go('opencl')\"" + '>CL</div>';
417 418

   if (item.source)
419
     result += '<div class="view-source"><a href="' + item.source+ '#n18">View source</a></div>';
420 421 422 423 424
   result += '</div>';

  if (item.image)
    result += ' <img class="op-image" src="' + item.image + '" / >';

425 426 427 428 429 430 431 432 433 434
    result += '<div class="opname">' + item.op + '</div>';

    if (item.meta) {
      for (var j = 0; j < item.meta.length; j++)
      {
        if (item.meta[j][0] == 'title')
          result += '<div class="optitle">' + item.meta[j][1] + '</div>';
      }
    }

435 436 437
  result += '<div class="description">' + item.description +
    '</div>';

438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
  if (item['input-pads'])
  {
  result += '<div><div class="pad-label">Inputs:&nbsp;</div>';
    for (var i = 0; i < item['input-pads'].length; i++)
    {
      result += '<div class="pad-val">' + item['input-pads'][i] + '</div>';
    }
  result += '</div>';
  }
  if (item['output-pads'])
  {
  result += '<div><div class="pad-label">Outputs:&nbsp;</div><div class="pad-val">';
    for (var i = 0; i < item['output-pads'].length; i++)
      result += item['output-pads'][i];
      result += '</div></div>';
  }

455 456 457
  if (item.properties.length)
    result += render_properties (item.properties);

458 459


460 461 462 463 464 465 466 467 468
    result += '<div style="clear:all">&nbsp;</div>';
    result += '<div style="margin-top:4em;"></div>';
  }


  if (item.meta)
  {
    for (var j = 0; j < item.meta.length; j++)
    {
469 470
      if (item.meta[j][0] == 'reference-composition' ||
          item.meta[j][0] == 'title')
471 472 473
        continue;
        result += '<div style="clear:both"><b>' + item.meta[j][0] +
            '</b>&nbsp;' + 
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
       item.meta[j][1] + '</div>';
    }
  }

  return result;
}

function go (query)
{
  window.location.hash=id('query').value;
  window.location.hash=query;
  id("query").value=query;
  show_matches();
}

function render_list2 (items, maxitems)
{
  var result = '';
  for (var i = 0; i < items.length && i < maxitems; i++)
  {
    var item = items[i];

    if (items[i].image)
    {
498
      result += "<div class='result' onclick='go(\"op "+item.op+"\")' >";
499 500 501 502 503 504
      result += ' <img src="' + items[i].image + '"/>';
      result += '<div class="title">' + item.op + '</div>';
      result += '</div>';
    }
    else
    {
505
      result += "<div class='result text' onclick='go(\"op "+item.op+"\")' >";
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
      result += '<div class="title">' + item.op + '</div>';
      result += '</div>';
    }

  }
  return result;
}

function render_all ()
{
  var result = '';
  var items = window.opdb;
  for (var i = 0; i < items.length; i++)
  {
    result += '<div style="font-weight:bold;font-size:1.5em;margin-top:1em;margin-bottom:1em;">' + items[i].op +'</div>';
    result += render_item (items[i]);
  }
  return result;
}

function render_list_big (items)
{
528
  return '<div class="big">' + render_list2 (items, 23) + '</div>';
529 530 531 532
}

function render_list_small (items)
{
533
  return '<div class="small">' + render_list2 (items, 42) + '</div>';
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
}

function render_categories ()
{
  var result = '';

  var cats = [];
  var opdb = window.opdb;

  for (var i = 0; i < opdb.length; i++)
  {
      if (opdb[i].categories)
      for (var j = 0; j < opdb[i].categories.length; j++)
      {
        var found = false;
        for (var k = 0; k < cats.length; k++)
        if (cats[k] == opdb[i].categories[j])
          found = true;
        if (!found)
          cats.push(opdb[i].categories[j]);
      }
  }

  cats = cats.sort();

  for (var i = 0; i < cats.length; i++)
  {
561
  result += '<div class="res_category" style="font-size: 150%;"'
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
    + "onclick='go(\""+cats[i]+"\")'>" 
    + cats[i] + '</div>';
  }


  return result;
}

window.onhashchange = function ()
{
  id('query').value = window.location.hash.slice(1);
  show_matches ();
}


function show_matches(e)
{
  var items;
  var result = '';

  if (e && e.keyCode == 13)
  {
    window.location.hash=id('query').value;
  }

  if (!initialized)
  {
    if (id('query').value == '')
    id('query').value = window.location.hash.slice(1);
    initialized = true;
  }

  items = filter_db(id('query').value);

  if (id('query').value == 'list of all ops')
  {
    result += render_all ();
  }
  else if (id('query').value == '')
  {
    result += render_categories ();
  }
  else if (items.length == 0)
  {
    result = 'eek';
  }
  else if (items.length == 1)
  {
610 611
    if (items[0].op == id('query').value ||
    id('query').value.indexOf('op')==0)
612 613 614 615
    result += render_item (items[0]);
    else
    result += render_list_big (items);
  }
616
  else if (items.length < 23)
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
  {
    result += render_list_big (items);
  }
  else
    result += render_list_small (items);


  if (result != previous_content)
  {
    id('view').innerHTML = result;
    previous_content = result;
  }
}

  </script>

  <body>
    <input id='query' value='' placeholder="type to search"
    onkeyup='show_matches(event);'
    onactivate='setloc()'
     autocomplete='off'></input>
     <div id='view'>foo</div>
  </body>

  <script>
    show_matches();
    id('query').focus();
  </script>
</html>