UNPKG

@tidepool/viz

Version:

Tidepool data visualization for diabetes device data.

696 lines (292 loc) • 22.5 kB
<!DOCTYPE HTML> <html lang="" > <head> <meta charset="UTF-8"> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>React Motion · GitBook</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="description" content=""> <meta name="generator" content="GitBook 3.2.2"> <link rel="stylesheet" href="../../gitbook/style.css"> <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css"> <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css"> <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css"> <meta name="HandheldFriendly" content="true"/> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png"> <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon"> <link rel="next" href="Redux.html" /> <link rel="prev" href="React.html" /> </head> <body> <div class="book"> <div class="book-summary"> <div id="book-search-input" role="search"> <input type="text" placeholder="Type to search" /> </div> <nav role="navigation"> <ul class="summary"> <li class="chapter " data-level="1.1" data-path="../../"> <a href="../../"> Introduction </a> </li> <li class="chapter " data-level="1.2" data-path="../StartHere.html"> <a href="../StartHere.html"> @tidepool/viz developer guide </a> <ul class="articles"> <li class="chapter " data-level="1.2.1" data-path="../Background.html"> <a href="../Background.html"> background </a> </li> <li class="chapter " data-level="1.2.2" data-path="../FeatureOverview.html"> <a href="../FeatureOverview.html"> overview of features </a> </li> <li class="chapter " data-level="1.2.3" data-path="../Architecture.html"> <a href="../Architecture.html"> planned architecture </a> </li> <li class="chapter " data-level="1.2.4" data-path="../DirectoryStructure.html"> <a href="../DirectoryStructure.html"> app & directory structure </a> </li> <li class="chapter " data-level="1.2.5" data-path="../CodeStyle.html"> <a href="../CodeStyle.html"> code style </a> </li> </ul> </li> <li class="chapter " data-level="1.3" data-path="../views/"> <a href="../views/"> per-view documentation </a> <ul class="articles"> <li class="chapter " data-level="1.3.1" data-path="../../src/components/settings/"> <a href="../../src/components/settings/"> Device Settings view </a> </li> <li class="chapter " data-level="1.3.2" data-path="../views/Trends.html"> <a href="../views/Trends.html"> Trends view </a> </li> </ul> </li> <li class="chapter " data-level="1.4" data-path="../Storybook.html"> <a href="../Storybook.html"> use of React Storybook </a> </li> <li class="chapter " data-level="1.5" data-path="./"> <a href="./"> usage of dependencies </a> <ul class="articles"> <li class="chapter " data-level="1.5.1" data-path="D3.html"> <a href="D3.html"> D3 </a> </li> <li class="chapter " data-level="1.5.2" data-path="GSAP.html"> <a href="GSAP.html"> GSAP </a> </li> <li class="chapter " data-level="1.5.3" data-path="Moment.html"> <a href="Moment.html"> Moment </a> </li> <li class="chapter " data-level="1.5.4" data-path="React.html"> <a href="React.html"> React </a> </li> <li class="chapter active" data-level="1.5.5" data-path="ReactMotion.html"> <a href="ReactMotion.html"> React Motion </a> </li> <li class="chapter " data-level="1.5.6" data-path="Redux.html"> <a href="Redux.html"> Redux </a> </li> <li class="chapter " data-level="1.5.7" data-path="Webpack.html"> <a href="Webpack.html"> webpack </a> </li> </ul> </li> <li class="chapter " data-level="1.6" data-path="../../src/utils/"> <a href="../../src/utils/"> utilities </a> <ul class="articles"> <li class="chapter " data-level="1.6.1" data-path="../../src/utils/apidocs/"> <a href="../../src/utils/apidocs/"> API docs for utilities </a> <ul class="articles"> <li class="chapter " data-level="1.6.1.1" data-path="../../src/utils/apidocs/basal.html"> <a href="../../src/utils/apidocs/basal.html"> basal </a> </li> <li class="chapter " data-level="1.6.1.2" data-path="../../src/utils/apidocs/bloodglucose.html"> <a href="../../src/utils/apidocs/bloodglucose.html"> blood glucose </a> </li> <li class="chapter " data-level="1.6.1.3" data-path="../../src/utils/apidocs/bolus.html"> <a href="../../src/utils/apidocs/bolus.html"> bolus </a> </li> <li class="chapter " data-level="1.6.1.4" data-path="../../src/utils/apidocs/datetime.html"> <a href="../../src/utils/apidocs/datetime.html"> datetime </a> </li> <li class="chapter " data-level="1.6.1.5" data-path="../../src/utils/apidocs/format.html"> <a href="../../src/utils/apidocs/format.html"> format </a> </li> <li class="chapter " data-level="1.6.1.6" data-path="../../src/utils/apidocs/misc.html"> <a href="../../src/utils/apidocs/misc.html"> misc </a> </li> </ul> </li> </ul> </li> <li class="chapter " data-level="1.7" data-path="../misc/"> <a href="../misc/"> misc </a> <ul class="articles"> <li class="chapter " data-level="1.7.1" data-path="../misc/CommonProps.html"> <a href="../misc/CommonProps.html"> Common props </a> </li> <li class="chapter " data-level="1.7.2" data-path="../misc/Docs.html"> <a href="../misc/Docs.html"> Docs setup & publishing </a> </li> <li class="chapter " data-level="1.7.3" data-path="../misc/TimeRenderingModes.html"> <a href="../misc/TimeRenderingModes.html"> Time-rendering modes </a> </li> </ul> </li> <li class="divider"></li> <li> <a href="https://www.gitbook.com" target="blank" class="gitbook-link"> Published with GitBook </a> </li> </ul> </nav> </div> <div class="book-body"> <div class="body-inner"> <div class="book-header" role="navigation"> <!-- Title --> <h1> <i class="fa fa-circle-o-notch fa-spin"></i> <a href="../.." >React Motion</a> </h1> </div> <div class="page-wrapper" tabindex="-1" role="main"> <div class="page-inner"> <div id="book-search-results"> <div class="search-noresults"> <section class="normal markdown-section"> <h2 id="tidepoolvizs-usage-of-react-motion">@tidepool/viz&apos;s usage of React Motion</h2> <p>The history of React and animation is not an untroubled one. Tools for even simple CSS3-based animations on mounting and unmounting components&#x2014;a very common use case&#x2014;didn&apos;t even exist (in the form of the <code>React(CSS)TransitionGroup</code> addons) until version <a href="https://github.com/facebook/react/blob/master/CHANGELOG.md#react-with-addons-new" title="React CHANGELOG" target="_blank">0.5.0</a> (released in October of 2013). And even the <code>ReactCSSTransitionGroup</code> and <code>ReactTransitionGroup</code> solutions are not <em>great</em>, as their requirements for successful usage are rather unintuitive.</p> <p>A number of additional libraries have tried to solve various pieces of the React &amp; animation problem, and <a href="https://github.com/chenglou/react-motion" title="GitHub: react-motion" target="_blank">React motion</a> is perhaps the most popular. Because its <code>TransitionMotion</code> API suits <em>most</em> of our use cases and because it&apos;s a popular project with a reasonably large community behind it, we have chosen it as our default replacement for D3&apos;s <code>transition</code> API for animating transitions in our data visualizations.</p> <p>As a library, React motion exports four commonly-used things:</p> <ul> <li>the <code>spring</code> function, which can be customized with a set of parameters (namely: <code>stiffness</code>, <code>damping</code>, and <code>precision</code>); it provides the interpolation between the starting and ending states that you&apos;re animating</li> <li>the <code>Motion</code> component for animating on mount and/or between two states</li> <li>the <code>TransitionMotion</code> component for animating exiting and (re)entering components (as well as mounting and transitioning, just like <code>Motion</code>)</li> <li>the <code>StaggeredMotion</code> component for, you guessed it, staggered animations</li> </ul> <p>At Tidepool so far we are only using <code>spring</code> and <code>TransitionMotion</code>, and it isn&apos;t very likely that that will change. <code>Motion</code> is not useful to us since it doesn&apos;t allow for animation on component unmount<sup><a href="#fn_a" id="reffn_a">a</a></sup>, and we generally want animations at every possible (for the particular component) moment in the lifecycle: on initial mount, on transition, on exit/unmount, and on re-entry. And the use cases that <code>StaggeredMotion</code> works for are a fairly restricted subset of stagger animations<sup><a href="#fn_b" id="reffn_b">b</a></sup> that we don&apos;t have in our visualizations.</p> <p>For example code and a detailed tutorial on using <code>TransitionMotion</code> for transitions in a data visualization rendered in inline SVG via React, see the following:</p> <p>Simplest examples (1): &quot;<code>TransitionMotion</code> for grow-in, shrink-out single SVG <code>&lt;rect&gt;</code>&quot;</p> <p></p><p data-height="265" data-theme-id="0" data-slug-hash="xgxYbm" data-default-tab="js" data-user="jebeck" data-embed-version="2" data-pen-title="TransitionMotion for grow-in, shrink-out single SVG &lt;rect&gt;" class="codepen">See the Pen <a href="http://codepen.io/jebeck/pen/xgxYbm/" target="_blank">TransitionMotion for grow-in, shrink-out single SVG <rect></rect></a> by Jana Beck (<a href="http://codepen.io/jebeck" target="_blank">@jebeck</a>) on <a href="http://codepen.io" target="_blank">CodePen</a>.</p><p></p> <script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script> <p>Simplest examples (2): &quot;<code>TransitionMotion</code> for grow-in, shrink-out single SVG <code>&lt;circle&gt;</code>&quot;</p> <p></p><p data-height="265" data-theme-id="0" data-slug-hash="apdpxg" data-default-tab="js" data-user="jebeck" data-embed-version="2" data-pen-title="TransitionMotion for grow-in, shrink-out single SVG &lt;circle&gt;" class="codepen">See the Pen <a href="http://codepen.io/jebeck/pen/apdpxg/" target="_blank">TransitionMotion for grow-in, shrink-out single SVG <circle></circle></a> by Jana Beck (<a href="http://codepen.io/jebeck" target="_blank">@jebeck</a>) on <a href="http://codepen.io" target="_blank">CodePen</a>.</p><p></p> <script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script> <p>More complex example: &quot;<code>TransitionMotion</code> for grow-in, shrink-out of stacked <code>&lt;rect&gt;s</code>&quot;</p> <p></p><p data-height="265" data-theme-id="0" data-slug-hash="QdwBBz" data-default-tab="js" data-user="jebeck" data-embed-version="2" data-pen-title="TransitionMotion for grow-in, shrink-out of stacked &lt;rect&gt;s" class="codepen">See the Pen <a href="http://codepen.io/jebeck/pen/QdwBBz/" target="_blank">TransitionMotion for grow-in, shrink-out of stacked <rect></rect>s</a> by Jana Beck (<a href="http://codepen.io/jebeck" target="_blank">@jebeck</a>) on <a href="http://codepen.io" target="_blank">CodePen</a>.</p><p></p> <script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script> <!-- TODO: add links/embeds Most complex example TBA: "Dataviz in React with React Motion for transition animations" TODO: embed @jebeck's [detailed tutorial](http://todo.com 'TODO: link') walks through all these examples progressively. --> <hr> <blockquote id="fn_a"> <sup>a</sup>. At present, though in <a href="https://github.com/chenglou/react-motion/issues/311" title="GitHub: react-motion issue #311" target="_blank">this issue</a> the library&apos;s author Cheng Lou advocates for someone to extend the <code>Motion</code> component&apos;s functionality to include single element enter and leave animations.<a href="#reffn_a" title="Jump back to footnote [a] in the text."> &#x21A9;</a> </blockquote> <blockquote id="fn_b"> <sup>b</sup>. <code>StaggeredMotion</code> works only in cases where the staggered values depend on each other. It does not fit use cases such as staggering the mounting animation of a day&apos;s worth of CGM values, where each value (both x- and y- coordinates since there may be small (or large) time gaps in the data) is <em>not</em> strictly dependent on the previous (or next) value.<a href="#reffn_b" title="Jump back to footnote [b] in the text."> &#x21A9;</a> </blockquote> </section> </div> <div class="search-results"> <div class="has-results"> <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1> <ul class="search-results-list"></ul> </div> <div class="no-results"> <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1> </div> </div> </div> </div> </div> </div> <a href="React.html" class="navigation navigation-prev " aria-label="Previous page: React"> <i class="fa fa-angle-left"></i> </a> <a href="Redux.html" class="navigation navigation-next " aria-label="Next page: Redux"> <i class="fa fa-angle-right"></i> </a> </div> <script> var gitbook = gitbook || []; gitbook.push(function() { gitbook.page.hasChanged({"page":{"title":"React Motion","level":"1.5.5","depth":2,"next":{"title":"Redux","level":"1.5.6","depth":2,"path":"docs/deps/Redux.md","ref":"docs/deps/Redux.md","articles":[]},"previous":{"title":"React","level":"1.5.4","depth":2,"path":"docs/deps/React.md","ref":"docs/deps/React.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"docs/deps/ReactMotion.md","mtime":"2017-05-23T17:51:07.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-05-31T15:26:30.892Z"},"basePath":"../..","book":{"language":""}}); }); </script> </div> <script src="../../gitbook/gitbook.js"></script> <script src="../../gitbook/theme.js"></script> <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script> <script src="../../gitbook/gitbook-plugin-search/search.js"></script> <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script> <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script> <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script> <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script> </body> </html>