packages feed

chart-unit-0.4.0: index.html

<meta charset="utf-8"> <link rel="stylesheet" href="https://tonyday567.github.io/other/lhs.css">
<script type="text/javascript" async
  src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<h1 id="chart-unit-build-status"><a href="https://tonyday567.github.io/chart-unit">chart-unit</a> <a href="https://travis-ci.org/tonyday567/chart-unit"><img src="https://travis-ci.org/tonyday567/chart-unit.png" alt="Build Status" /></a></h1>
<p><a href="https://tonyday567.github.com/chart-unit">repo</a></p>
<p><code>chart-unit</code> is an experimental haskell chart library.</p>
<p>scratchpad</p>
<p><img style="border:5px solid grey" src="other/scratchpad.svg"></p>
<h2 id="unital-charting">unital charting</h2>
<p>This slowly growing collection of charts:</p>
<ul class="incremental">
<li>renders nicely in svg over a wide chart size.</li>
<li>retain a similar look-n-feel across different scales</li>
<li>are highly customizable</li>
<li>have a unit scale in the spirit of the <a href="http://projects.haskell.org/diagrams/doc/quickstart.html">diagrams</a> design space, making combining a snap.</li>
<li>can be quickly integrated into ad-hoc haskell data analytics, providing a visual feedback loop.</li>
</ul>
<h1 id="charts">charts</h1>
<p>A chart can be anything that is represented on an XY plane, and usually comes with visual clues about what is being represented, such as axes, titles and legends. Here's the default blank chart:</p>
<div class="figure">
<img src="other/exampleAxes.svg" />

</div>
<pre><code>axes (chartAspect .~ sixbyfour $ chartRange .~ Just one $ def)</code></pre>
<p><code>sixbyfour</code> is a value of type XY, and represents the rectangle that the chart will be rendered with. As with any SVG element, the ultimate product is still subject to sizing on use, so think of <code>sixbyfour</code> as a relative aspect ratio rather than a concrete size.</p>
<h2 id="xy">XY</h2>
<p>chartRange is the range which we would like to plot. chartRange .~ Nothing represents that the range should be whatever the data range is.</p>
<h2 id="customization">customization</h2>
<p>Axes and most other things are highly customizable. Here's another style of chart:</p>
<div class="figure">
<img src="other/exampleGgplot.svg" />

</div>
<h2 id="line-chart">line chart</h2>
<p>Some actual, real-life lines to be plotted:</p>
<div class="figure">
<img src="other/exampleLine.svg" />

</div>
<pre><code>lines lineDefs sixbyfour lineData</code></pre>
<p>Breaking the code down:</p>
<ul class="incremental">
<li><code>lines</code> is a typical chart renderer, taking a</li>
<li><code>[LineConfig]</code>, which is a list of configurations for each line, an</li>
<li><code>Aspect</code>, the aspect ratio to render the chart, and, finally</li>
<li>the data, a <code>(Traversable g, Traversable f, R2~r) =&gt; g (f (r a))</code>, or in this case, a <code>[[V2 Double]]</code>, which is a double container of the values to chart</li>
</ul>
<h2 id="withchart">withChart</h2>
<p>You don't have to do anything special to combine these lines with axes.</p>
<div class="figure">
<img src="other/exampleLineAxes.svg" />

</div>
<pre><code>lines lineDefs sixbyfour lineData &lt;&gt; 
axes (chartRange .~ Just (rangeR2s lineData) $ def)</code></pre>
<p><code>withChart</code> is a convenience function for this common operation, and the code below is equivalent to the above code:</p>
<pre><code>withChart def (lines lineDefs) lineData</code></pre>
<h2 id="scatter">scatter</h2>
<p>Other default chart types follow this same pattern:</p>
<div class="figure">
<img src="other/exampleScatter.svg" />

</div>
<pre><code>xys &lt;- mkScatterData
withChart (chartAspect .~ asquare $ def) (scatters scatterDefs) xys</code></pre>
<p>As with <code>line</code>, <code>scatter</code> zips together multiple configurations and multiple containers of data. It's often much easier to construct charts assuming multiple data sets.</p>
<p>A major point of the chart-unit library is that the look-n-feel of a chart is invariant to the data scale.</p>
<div class="figure">
<img src="other/exampleScatter2.svg" />

</div>
<pre><code>let xys1 = fmap (over _x (*1e8) . over _y (*1e-8)) &lt;$&gt; xys in
withChart (chartAspect .~ asquare $ def) (scatters scatterDefs) xys1</code></pre>
<h2 id="histogram">histogram</h2>
<p>A histogram, in widescreen</p>
<div class="figure">
<img src="other/exampleHist.svg" />

</div>
<p>A histogram, with unequal bin sizes (based on quantiles)</p>
<div class="figure">
<img src="other/exampleHistUnequal.svg" />

</div>
<p>... converted to a line chart</p>
<div class="figure">
<img src="other/exampleHistUnequal2.svg" />

</div>
<p>A labelled bar chart:</p>
<div class="figure">
<img src="other/exampleLabelledBar.svg" />

</div>
<h2 id="pixel-chart">pixel chart</h2>
<p>A chart with a color for each XY point in a plane. Close synonyms are probably an area chart, a surface chart. A contour chart must be close.</p>
<div class="figure">
<img src="other/examplePixels.svg" />

</div>
<h2 id="one-dim-chart">One-dim chart</h2>
<p>axes technology can be re-purposed to create skinny charts:</p>
<div class="figure">
<img src="other/exampleOneDim.svg" />

</div>
<h2 id="compound-charts">Compound charts</h2>
<p><code>chart-unit</code> is a fairly thin wrapper over diagrams that establishes the basics of what a chart is, and provides some sane defaults. From this starting point, production of high-quality charting is easy and pleasant. Some examples:</p>
<p>Comparing two histograms.</p>
<div class="figure">
<img src="other/exampleHistCompare.svg" />

</div>
<p>A scatter chart with histograms of the data along the x &amp; y dimensions.</p>
<div class="figure">
<img src="other/exampleScatterHist.svg" />

</div>
<p>A unital gradient chart, using diagrams arrows:</p>
<div class="figure">
<img src="other/exampleArrow.svg" />

</div>
<p>The <code>QChart</code> type exists to enable combining different types of charts using the same scale.</p>
<div class="figure">
<img src="other/exampleCompound.svg" />

</div>
<p>Clipping charts</p>
<div class="figure">
<img src="other/exampleClipping.svg" />

</div>
<h2 id="animation">animation</h2>
<p><img style="border:5px solid grey" src="other/anim.gif"></p>
<h2 id="data">data</h2>
<p>Double-containered dimensioned data covers what a chart charts - one or more data sets with at least an x and y dimension (called R2 in the linear library).</p>
<p>Most chart variations are about what to do with the extra dimensions in the data. A rectangle, for example, is built from 4 dimensions, an anchoring of position in XY space, with a width (W) and height (Z). A contour map is three dimensional data (V3 in linear), with placement as XY and color as Z.</p>
<h2 id="diagrams-development-recipe">diagrams development recipe</h2>
<p>In constructing new chart units:</p>
<ul class="incremental">
<li>diagrams go from polymorphic &amp; abstract to strongly-typed &amp; concrete</li>
<li>V2 (-0.5 ... 0.5) (-0.5 ... 0.5) forms a unitSquare: one unit by one unit, origin in the center</li>
<li>regularly check where the origin is, usually not where it needs to be.</li>
<li>turn pointful shapes into a Trail</li>
<li>close the Trail into a SVG-like loop</li>
<li>turn the closed Trail into a QDiagram</li>
</ul>
<p>You can slide up and down the various diagrams abstraction levels creating transformations at each level. For example, here's something I use to work at the point level:</p>
<pre><code>unitp f = unitSquare # f # fromVertices # closeTrail # strokeTrail</code></pre>
<h2 id="workflow">workflow</h2>
<p>recipe 1</p>
<div class="sourceCode"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">scratch ::</span> <span class="dt">Chart</span> <span class="dt">SVG</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()
scratch <span class="fu">=</span> fileSvg <span class="st">&quot;other/scratchpad.svg&quot;</span> (<span class="dv">600</span>,<span class="dv">400</span>)</code></pre></div>
<p>I tend to work in ghci a lot, using the above <code>scratch</code> to try code out, mashing the refresh button in the browser. Or I switch on stacks --file-watch ...</p>
<p>recipe 2</p>
<pre><code>stack build --test --exec &quot;$(stack path --local-install-root)/bin/chart-unit-examples&quot; --exec &quot;$(stack path --local-bin)/pandoc -f markdown+lhs -i app/examples.hs -t html -o index.html --filter pandoc-include --mathjax&quot; --file-watch</code></pre>