Lava Shortcode - Word Cloud

Description

Generate a visual word cloud highlighting the most frequent terms from a text block.

Documentation

This shortcut takes a large amount of text and converts it to a word cloud of the most popular terms. It's smart enough to take out common words like 'the', 'and', etc. Below are the various options for this shortcode. If you would like to play with the settings in real-time head over the Javascript's homepage.

{[ wordcloud ]}
... out a lot of text here ...
{[ endwordcloud ]}
  • width (960) – The width in pixels of the word cloud control.
  • height (420) - The height in pixels of the control.
  • fontname (Impact) – The font to use for the rendering.
  • maxwords (255) – The maximum number of words to use in the word cloud.
  • scalename (log) – The type of scaling algorithm to use. Options are 'log', ' sqrt' or 'linear'.
  • spiralname (archimedean) – The type of spiral used for positioning words. Options are 'archimedean' or 'rectangular'.
  • colors (#0193B9,#F2C852,#1DB82B,#2B515D,#ED3223) – A comma delimited list of colors to use for the words.
  • anglecount (6) – The maximum number of angles to place words on in the cloud.
  • anglemin (-90) – The minimum angle to use when drawing the cloud.
  • anglemax (90) – The maximum angle to use when drawing the cloud.

Markup

{% javascript id:'d3-layout-cloud' url:'/Scripts/d3-cloud/d3.layout.cloud.js' %}{% endjavascript %}
{% javascript id:'d3-min' url:'/Scripts/d3-cloud/d3.min.js' %}{% endjavascript %}

<div id="{{ uniqueid }}" style="width: {{ width }}; height: {{ height }};"></div>

{%- assign anglecount = anglecount | Trim -%}
{%- assign anglemin = anglemin | Trim -%}
{%- assign anglemax = anglemax | Trim -%}

{% javascript disableanonymousfunction:'true' %}
    $( document ).ready(function() {
        Rock.controls.wordcloud.initialize({
            inputTextId: 'hf-{{ uniqueid }}',
            visId: '{{ uniqueid }}',
            width: '{{ width }}',
            height: '{{ height }}',
            fontName: '{{ fontname }}',
            maxWords: {{ maxwords }},
            scaleName: '{{ scalename }}',
            spiralName: '{{ spiralname}}',
            colors: [ '{{ colors | Replace:',',"','" }}'],
            {%- if anglecount != '' %}
            anglecount: {{ anglecount }}{%- if anglemin != '' or anglemax != '' -%},{%- endif -%}
            {%- endif -%}
            {%- if anglemin != '' %}
            anglemin: {{ anglemin }}{%- if anglemax != '' -%},{%- endif -%}
            {%- endif -%}
            {%- if anglemax != '' %}
            anglemax: {{ anglemax }}
            {%- endif -%}
        });
    });
{% endjavascript %}

<input type="hidden" id="hf-{{ uniqueid }}" value="{{ blockContent }}" />