UNPKG

scrawl-canvas

Version:
348 lines (241 loc) 17.2 kB
<!DOCTYPE html> <html> <head> <title>Demo Modules 003</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <ul id="jump_to"> <li> <a class="large" href="javascript:void(0);">Jump To &hellip;</a> <a class="small" href="javascript:void(0);">+</a> <div id="jump_wrapper"> <div id="jump_page_wrapper"> <div id="jump_page"> <a class="source" href="canvas-minimap.html"> ./demo/modules/canvas-minimap.js </a> <a class="source" href="canvas-scene-editor.html"> ./demo/modules/canvas-scene-editor.js </a> <a class="source" href="dom-entity-editor.html"> ./demo/modules/dom-entity-editor.js </a> <a class="source" href="entity-copy-paste.html"> ./demo/modules/entity-copy-paste.js </a> <a class="source" href="entity-manipulation-gui.html"> ./demo/modules/entity-manipulation-gui.js </a> <a class="source" href="entity-navigation.html"> ./demo/modules/entity-navigation.js </a> <a class="source" href="entity-ring-builder.html"> ./demo/modules/entity-ring-builder.js </a> <a class="source" href="london-crime-graphic.html"> ./demo/modules/london-crime-graphic.js </a> <a class="source" href="london-crime-lines.html"> ./demo/modules/london-crime-lines.js </a> <a class="source" href="london-crime-stacked-bars.html"> ./demo/modules/london-crime-stacked-bars.js </a> <a class="source" href="lottie-loader.html"> ./demo/modules/lottie-loader.js </a> <a class="source" href="simple-chart-frame-tests.html"> ./demo/modules/simple-chart-frame-tests.js </a> <a class="source" href="simple-chart-frame.html"> ./demo/modules/simple-chart-frame.js </a> <a class="source" href="simple-graph-lines.html"> ./demo/modules/simple-graph-lines.js </a> <a class="source" href="simple-graph-stacked-bars.html"> ./demo/modules/simple-graph-stacked-bars.js </a> <a class="source" href="wikipedia-views-spiral-chart.html"> ./demo/modules/wikipedia-views-spiral-chart.js </a> <a class="source" href="../snippets/animated-highlight-gradient-text-snippet.html"> ./demo/snippets/animated-highlight-gradient-text-snippet.js </a> <a class="source" href="../snippets/animated-hover-gradient-snippet.html"> ./demo/snippets/animated-hover-gradient-snippet.js </a> <a class="source" href="../snippets/animated-word-gradient-snippet.html"> ./demo/snippets/animated-word-gradient-snippet.js </a> <a class="source" href="../snippets/before-after-slider-infographic.html"> ./demo/snippets/before-after-slider-infographic.js </a> <a class="source" href="../snippets/bubbles-text-snippet.html"> ./demo/snippets/bubbles-text-snippet.js </a> <a class="source" href="../snippets/green-box-snippet.html"> ./demo/snippets/green-box-snippet.js </a> <a class="source" href="../snippets/jazzy-button-snippet.html"> ./demo/snippets/jazzy-button-snippet.js </a> <a class="source" href="../snippets/page-performance-snippet-test.html"> ./demo/snippets/page-performance-snippet-test.js </a> <a class="source" href="../snippets/page-performance-snippet.html"> ./demo/snippets/page-performance-snippet.js </a> <a class="source" href="../snippets/pan-image-snippet.html"> ./demo/snippets/pan-image-snippet.js </a> <a class="source" href="../snippets/placeholder-effect-snippet.html"> ./demo/snippets/placeholder-effect-snippet.js </a> <a class="source" href="../snippets/ripple-effect-snippet.html"> ./demo/snippets/ripple-effect-snippet.js </a> <a class="source" href="../snippets/risograph-text-gradient-snippet.html"> ./demo/snippets/risograph-text-gradient-snippet.js </a> <a class="source" href="../snippets/spotlight-text-snippet-test.html"> ./demo/snippets/spotlight-text-snippet-test.js </a> <a class="source" href="../snippets/spotlight-text-snippet.html"> ./demo/snippets/spotlight-text-snippet.js </a> <a class="source" href="../snippets/swirling-stripes-text-snippet.html"> ./demo/snippets/swirling-stripes-text-snippet.js </a> <a class="source" href="../snippets/text-snippet-helper.html"> ./demo/snippets/text-snippet-helper.js </a> <a class="source" href="../snippets/word-highlighter-snippet.html"> ./demo/snippets/word-highlighter-snippet.js </a> <a class="source" href="../snippets/worley-text-gradient-snippet.html"> ./demo/snippets/worley-text-gradient-snippet.js </a> </div> </div> </li> </ul> <ul class="sections"> <li id="section-1"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-1">&#x00a7;</a> </div> <h1 id="demo-modules-003">Demo Modules 003</h1> <p>Factory functions to create more complex, compound entitys</p> <p>Related files:</p> <ul> <li><a href="../modules-003.html">Compound entitys - main module</a></li> </ul> <p>Import the Scrawl-canvas object </p> <ul> <li>There’s various ways to do this. See <a href="../dom-001.html">Demo DOM-001</a> for more details</li> </ul> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> scrawl <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../../source/scrawl.js&#x27;</span>;</pre></div></div> </li> <li id="section-2"> <div class="annotation"> <div class="sswrap "> <a class="ss" href="#section-2">&#x00a7;</a> </div> <h4 id="the-entity-ring-factory">The entity ring factory</h4> <p>This factory takes a single <strong>items</strong> Javascript Object argument (to match the functionality of built-in Scrawl-canvas factories). Three of the attributes of this argument object are required, the others will fall back on default values. These attrributes are:</p> <ul> <li><strong>canvas</strong> (required) - Scrawl-canvas Canvas wrapper object - the canvas which will be hosting the compound entity we are about to create</li> <li><strong>name</strong> (required) - String - unique name value</li> <li><strong>entity</strong> (required) - Scrawl-canvas entity object - any valid entity that has already been created</li> <li><strong>dimensions</strong> - Number - the square dimensions of the compound entity; default: 400</li> <li><strong>buildStartAngle</strong> - Number - the angle of the first entity we lay down; default: -45</li> <li><strong>buildEndAngle</strong> - Number - the angle of the last entity we lay down - note that this needs to be sufficient to cover at least half of the ring, which we can then copy and stamp to create the final output; default: 225</li> <li><strong>buildStepAngle</strong> - Number - the repeat value - higher values lead to fewer entitys making up the final ring; default: 15</li> <li><strong>buildOffset</strong> - Number - the entity’s offset from the center of the ring (as measured in px); default: 0</li> <li><strong>reflectOnly</strong> - Boolean - when the ring half is copied and pasted back into the final output, it can be set to reflect only, which will give us a bilateral rather than a radial symmetry; default: false</li> </ul> </div> <div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">function</span> (<span class="hljs-params">items = {}</span>) { <span class="hljs-keyword">if</span> (!items.<span class="hljs-property">canvas</span> || !items.<span class="hljs-property">entity</span> || !items.<span class="hljs-property">name</span>) <span class="hljs-keyword">return</span> {}; <span class="hljs-keyword">let</span> canvas = items.<span class="hljs-property">canvas</span>, name = items.<span class="hljs-property">name</span>, entity = items.<span class="hljs-property">entity</span>, dimensions = items.<span class="hljs-property">dimensions</span> || <span class="hljs-number">400</span>, buildStartAngle = items.<span class="hljs-property">buildStartAngle</span> || -<span class="hljs-number">45</span>, buildEndAngle = items.<span class="hljs-property">buildEndAngle</span> || <span class="hljs-number">225</span>, buildStepAngle = items.<span class="hljs-property">buildStepAngle</span> || <span class="hljs-number">15</span>, buildOffset = items.<span class="hljs-property">buildOffset</span> || <span class="hljs-number">0</span>, reflectOnly = items.<span class="hljs-property">reflectOnly</span> || <span class="hljs-literal">false</span>; <span class="hljs-keyword">const</span> cell = canvas.<span class="hljs-title function_">buildCell</span>({ <span class="hljs-attr">name</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-cell`</span>, <span class="hljs-attr">dimensions</span>: [dimensions, dimensions], <span class="hljs-attr">shown</span>: <span class="hljs-literal">false</span>, <span class="hljs-attr">compileOrder</span>: <span class="hljs-number">0</span>, }); <span class="hljs-keyword">const</span> clip = scrawl.<span class="hljs-title function_">makeGroup</span>({ <span class="hljs-attr">name</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-clip-group`</span>, <span class="hljs-attr">host</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-cell`</span>, <span class="hljs-attr">order</span>: <span class="hljs-number">0</span>, }); <span class="hljs-keyword">const</span> reflect = scrawl.<span class="hljs-title function_">makeGroup</span>({ <span class="hljs-attr">name</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-reflect-group`</span>, <span class="hljs-attr">host</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-cell`</span>, <span class="hljs-attr">order</span>: <span class="hljs-number">1</span>, }); scrawl.<span class="hljs-title function_">makeBlock</span>({ <span class="hljs-attr">name</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-clipper`</span>, <span class="hljs-attr">group</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-clip-group`</span>, <span class="hljs-attr">start</span>: [<span class="hljs-string">&#x27;left&#x27;</span>, <span class="hljs-string">&#x27;center&#x27;</span>], <span class="hljs-attr">dimensions</span>: [<span class="hljs-string">&#x27;100%&#x27;</span>, <span class="hljs-string">&#x27;50%&#x27;</span>], <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;clip&#x27;</span> }); <span class="hljs-keyword">let</span> v = scrawl.<span class="hljs-title function_">requestVector</span>(<span class="hljs-number">0</span>, buildOffset); v.<span class="hljs-title function_">rotate</span>(buildStartAngle); <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = buildStartAngle; i &lt;= buildEndAngle; i += buildStepAngle) { entity.<span class="hljs-title function_">clone</span>({ <span class="hljs-attr">name</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-ringitem-<span class="hljs-subst">${i}</span>`</span>, <span class="hljs-attr">group</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-clip-group`</span>, <span class="hljs-attr">roll</span>: i, <span class="hljs-attr">offset</span>: [v.<span class="hljs-property">x</span>, v.<span class="hljs-property">y</span>], }); v.<span class="hljs-title function_">rotate</span>(buildStepAngle); } scrawl.<span class="hljs-title function_">releaseVector</span>(v); scrawl.<span class="hljs-title function_">makePicture</span>({ <span class="hljs-attr">name</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-reflection`</span>, <span class="hljs-attr">group</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-reflect-group`</span>, <span class="hljs-attr">asset</span>: <span class="hljs-string">`<span class="hljs-subst">${name}</span>-cell`</span>, <span class="hljs-attr">start</span>: [<span class="hljs-string">&#x27;center&#x27;</span>, <span class="hljs-string">&#x27;25%&#x27;</span>], <span class="hljs-attr">handle</span>: [<span class="hljs-string">&#x27;center&#x27;</span>, <span class="hljs-string">&#x27;center&#x27;</span>], <span class="hljs-attr">flipUpend</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">flipReverse</span>: !reflectOnly, <span class="hljs-attr">dimensions</span>: [<span class="hljs-string">&#x27;100%&#x27;</span>, <span class="hljs-string">&#x27;50%&#x27;</span>], <span class="hljs-attr">copyDimensions</span>: [<span class="hljs-string">&#x27;100%&#x27;</span>, <span class="hljs-string">&#x27;50%&#x27;</span>], <span class="hljs-attr">copyStartY</span>: <span class="hljs-string">&#x27;50%&#x27;</span>, <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;fill&#x27;</span>, }); entity.<span class="hljs-title function_">set</span>({ <span class="hljs-attr">visibility</span>: <span class="hljs-literal">false</span>, }); <span class="hljs-keyword">return</span> { cell, <span class="hljs-attr">kill</span>: <span class="hljs-function">() =&gt;</span> { clip.<span class="hljs-title function_">kill</span>(<span class="hljs-literal">true</span>); reflect.<span class="hljs-title function_">kill</span>(<span class="hljs-literal">true</span>); cell.<span class="hljs-title function_">kill</span>(); }, } };</pre></div></div> </li> </ul> </div> </body> </html>