PageRenderTime 26ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/dist/components/isotope/_posts/custom-layout-modes/2011-12-05-big-graph.html

https://bitbucket.org/angelcabo/dfilm_ui
HTML | 196 lines | 160 code | 36 blank | 0 comment | 0 complexity | 167b57ac1831a981d43d23ffb104b5a0 MD5 | raw file
  1. ---
  2. title: BIG Graph
  3. layout: default
  4. category: custom-layout-modes
  5. ---
  6. <section id="copy">
  7. <p><a href="../docs/extending-isotope.html">Custom layout mode</a> to replicate the Flash interface of <a href="http://big.dk">big.dk</a>. Similiar to <a href="category-rows.html">Category rows</a>, item elements are grouped by their sorting data into columns.</p>
  8. {% highlight javascript %}
  9. $container.isotope({
  10. layoutMode: 'bigGraph',
  11. bigGraph: {
  12. columnWidth: 45, // size of item
  13. rowHeight: 45, // size of item
  14. maxRows: 11, // max number of items vertically
  15. gutterWidth: { // width of gutter, needs to match getSortData names
  16. year: 0,
  17. scale: 60,
  18. program: 40,
  19. status: 60,
  20. title: 0
  21. }
  22. },
  23. // options...
  24. });
  25. {% endhighlight %}
  26. <p>To use this layout mode, grab the <code>$.Isotope.prototype</code> methods from the script at the bottom of this page's source.</p>
  27. </section>
  28. <section id="options" class="clearfix">
  29. <h3>Sort</h3>
  30. <ul id="sort-by" class="option-set clearfix" data-option-key="sortBy">
  31. <li><a href="#sortBy=year" data-option-value="year" class="selected" data>Chronological</a></li>
  32. <li><a href="#sortBy=title" data-option-value="title">Alphabetical</a></li>
  33. <li><a href="#sortBy=program" data-option-value="program">Programmatic</a></li>
  34. <li><a href="#sortBy=scale" data-option-value="scale">Scale</a></li>
  35. <li><a href="#sortBy=status" data-option-value="status">Status</a></li>
  36. </ul>
  37. </section> <!-- #options -->
  38. <div id="container" class="big-graph clearfix">
  39. </div> <!-- #container -->
  40. <script src="../{{ site.jquery_js }}"></script>
  41. <script src="../{{ site.isotope_js }}"></script>
  42. <script src="../js/make-big-graph-projects.js"></script>
  43. <script>
  44. // categoryRows custom layout mode
  45. $.extend( $.Isotope.prototype, {
  46. _bigGraphReset : function() {
  47. this.bigGraph = {
  48. x : 0,
  49. y : 0,
  50. height : 0,
  51. column: 0,
  52. row: 0,
  53. gutter: 0,
  54. currentCategory : null
  55. };
  56. },
  57. _bigGraphLayout : function( $elems ) {
  58. var instance = this,
  59. containerWidth = this.element.width(),
  60. bigGraphOpts = this.options.bigGraph,
  61. sortBy = this.options.sortBy,
  62. elemsGroup = {},
  63. props = this.bigGraph;
  64. // group item elements into categories based on their sorting data
  65. $elems.each( function() {
  66. var category = $.data( this, 'isotope-sort-data' )[ sortBy ];
  67. elemsGroup[ category ] = elemsGroup[ category ] || [];
  68. elemsGroup[ category ].push( this );
  69. });
  70. var group, groupName, groupMaxRows, groupLen,
  71. gutterWidth = bigGraphOpts.gutterWidth[ sortBy ],
  72. x, y;
  73. // for each group...
  74. for ( groupName in elemsGroup ) {
  75. group = elemsGroup[ groupName ];
  76. groupLen = group.length;
  77. // make groups look nice, by limiting rows, makes for blockier blocks
  78. groupMaxRows = groupLen / Math.ceil( groupLen / bigGraphOpts.maxRows );
  79. $.each( group, function( i, elem ) {
  80. x = props.column * bigGraphOpts.columnWidth + props.gutter * gutterWidth;
  81. y = (bigGraphOpts.maxRows - props.row - 1) * bigGraphOpts.rowHeight;
  82. instance._pushPosition( $(elem), x, y );
  83. if ( props.row >= groupMaxRows - 1 ) {
  84. // start a new column
  85. props.row = 0;
  86. props.column++;
  87. } else {
  88. props.row++;
  89. }
  90. });
  91. // start a new group
  92. if ( props.row > 0 ) {
  93. props.row = 0;
  94. props.column++;
  95. }
  96. props.gutter++;
  97. }
  98. props.gutter--;
  99. props.width = props.column * bigGraphOpts.columnWidth + props.gutter * gutterWidth;
  100. },
  101. _bigGraphGetContainerSize : function () {
  102. bigGraphOpts = this.options.bigGraph;
  103. this.bigGraph.column++;
  104. return {
  105. width: this.bigGraph.width,
  106. height: bigGraphOpts.maxRows * bigGraphOpts.rowHeight
  107. };
  108. },
  109. _bigGraphResizeChanged : function() {
  110. return false;
  111. }
  112. });
  113. $(function(){
  114. // -------- dynamically create items ---------------- //
  115. var i = 120,
  116. projects = [];
  117. while (i--) {
  118. projects.push( makeBigGraphProject() );
  119. }
  120. var $container = $('#container');
  121. $container.append( $( projects.join('') ) );
  122. // -------- isotope ---------------- //
  123. $container.isotope({
  124. itemSelector: '.project',
  125. layoutMode: 'bigGraph',
  126. bigGraph: {
  127. columnWidth: 45, // size of item
  128. rowHeight: 45, // size of item
  129. maxRows: 11, // max number of items vertically
  130. gutterWidth: { // width of gutter, needs to match getSortData names
  131. year: 0,
  132. scale: 0,
  133. program: 35,
  134. status: 80,
  135. title: 0
  136. }
  137. },
  138. sortBy: 'year',
  139. getSortData: {
  140. year: function( $elem ) {
  141. return $elem.attr('data-year');
  142. },
  143. scale: function( $elem ) {
  144. return $elem.attr('data-scale');
  145. },
  146. program: function( $elem ) {
  147. return $elem.attr('data-program');
  148. },
  149. status: function( $elem ) {
  150. return $elem.attr('data-status');
  151. },
  152. title: function( $elem ) {
  153. var chara = $elem.find('p').text()[0];
  154. return isNaN( parseInt( chara ) ) ? chara : '0';
  155. }
  156. }
  157. });
  158. {% include option-set-buttons.js %}
  159. });
  160. </script>