|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
|
|
|
|
|
<html>
|
|
|
|
|
|
|
|
|
|
<head>
|
|
|
|
|
|
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
|
<meta name="generator" content="pandoc" />
|
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<title>Build a regression model: prepare and visualize data</title>
|
|
|
|
|
|
|
|
|
|
<script>// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
|
|
|
|
|
// be compatible with the behavior of Pandoc < 2.8).
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function(e) {
|
|
|
|
|
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
|
|
|
|
|
var i, h, a;
|
|
|
|
|
for (i = 0; i < hs.length; i++) {
|
|
|
|
|
h = hs[i];
|
|
|
|
|
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
|
|
|
|
|
a = h.attributes;
|
|
|
|
|
while (a.length > 0) h.removeAttribute(a[0].name);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<script>/*! jQuery v3.6.0 | (c) OpenJS Foundation and other contributors | jquery.org/license */
|
|
|
|
|
!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(C,e){"use strict";var t=[],r=Object.getPrototypeOf,s=t.slice,g=t.flat?function(e){return t.flat.call(e)}:function(e){return t.concat.apply([],e)},u=t.push,i=t.indexOf,n={},o=n.toString,v=n.hasOwnProperty,a=v.toString,l=a.call(Object),y={},m=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType&&"function"!=typeof e.item},x=function(e){return null!=e&&e===e.window},E=C.document,c={type:!0,src:!0,nonce:!0,noModule:!0};function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e,t)for(r in c)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[o.call(e)]||"object":typeof e}var f="3.6.0",S=function(e,t){return new S.fn.init(e,t)};function p(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e)&&("array"===n||0===t||"number"==typeof t&&0<t&&t-1 in e)}S.fn=S.prototype={jquery:f,constructor:S,length:0,toArray:function(){return s.call(this)},get:function(e){return null==e?s.call(this):e<0?this[e+this.length]:this[e]},pushStack:function(e){var t=S.merge(this.constructor(),e);return t.prevObject=this,t},each:function(e){return S.each(this,e)},map:function(n){return this.pushStack(S.map(this,function(e,t){return n.call(e,t,e)}))},slice:function(){return this.pushStack(s.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},even:function(){return this.pushStack(S.grep(this,function(e,t){return(t+1)%2}))},odd:function(){return this.pushStack(S.grep(this,function(e,t){return t%2}))},eq:function(e){var t=this.length,n=+e+(e<0?t:0);return this.pushStack(0<=n&&n<t?[this[n]]:[])},end:function(){return this.prevObject||this.constructor()},push:u,sort:t.sort,splice:t.splice},S.extend=S.fn.extend=function(){var e,t,n,r,i,o,a=arguments[0]||{},s=1,u=arguments.length,l=!1;for("boolean"==typeof a&&(l=a,a=arguments[s]||{},s++),"object"==typeof a||m(a)||(a={}),s===u&&(a=this,s--);s<u;s++)if(null!=(e=arguments[s]))for(t in e)r=e[t],"__proto__"!==t&&a!==r&&(l&&r&&(S.isPlainObject(r)||(i=Array.isArray(r)))?(n=a[t],o=i&&!Array.isArray(n)?[]:i||S.isPlainObject(n)?n:{},i=!1,a[t]=S.extend(l,o,r)):void 0!==r&&(a[t]=r));return a},S.extend({expando:"jQuery"+(f+Math.random()).replace(/\D/g,""),isReady:!0,error:function(e){throw new Error(e)},noop:function(){},isPlainObject:function(e){var t,n;return!(!e||"[object Object]"!==o.call(e))&&(!(t=r(e))||"function"==typeof(n=v.call(t,"constructor")&&t.constructor)&&a.call(n)===l)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},globalEval:function(e,t,n){b(e,{nonce:t&&t.nonce},n)},each:function(e,t){var n,r=0;if(p(e)){for(n=e.length;r<n;r++)if(!1===t.call(e[r],r,e[r]))break}else for(r in e)if(!1===t.call(e[r],r,e[r]))break;return e},makeArray:function(e,t){var n=t||[];return null!=e&&(p(Object(e))?S.merge(n,"string"==typeof e?[e]:e):u.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:i.call(t,e,n)},merge:function(e,t){for(var n=+t.length,r=0,i=e.length;r<n;r++)e[i++]=t[r];return e.length=i,e},grep:function(e,t,n){for(var r=[],i=0,o=e.length,a=!n;i<o;i++)!t(e[i],i)!==a&&r.push(e[i]);return r},map:function(e,t,n){var r,i,o=0,a=[];if(p(e))for(r=e.length;o<r;o++)null!=(i=t(e[o],o,n))&&a.push(i);else for(o in e)null!=(i=t(e[o],o,n))&&a.push(i);return g(a)},guid:1,support:y}),"function"==typeof Symbol&&(S.fn[Symbol.iterator]=t[Symbol.iterator]),S.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "),function(e,t){n["[object "+t+"]"]=t.toLowerCase()});var d=function(n){var e,d,b,o,i,h,f,g,w,u,l,T,C,a,E,v,s,c,y,S="sizzle"+1*new Date,p=n.document,k=0,r=0,m=ue(),x=ue(),A=ue(),N=ue(),j=function(e,t){return e===t&&(l=!0),0},D={}.hasOwnProperty,t=[],q=t.pop,L=t.push,H=t.push,O=t.slice,P=function(e
|
|
|
|
|
</script>
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
|
<style type="text/css">@font-face {
|
|
|
|
|
font-family: 'Lato';
|
|
|
|
|
font-style: normal;
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
src: url(data:font/ttf;base64,AAEAAAARAQAABAAQR1BPU792x2wAAS2AAAASSkdT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ZekhIe1oyvhcnNR4eNCUWFiU0Hh41JxcESFKEXTIyXYRSVIheMzNeiFQ6TjAVFTBOOjhLLhQULksBbw8Y+n8QFQFUUoRdMzNdhFJUiF4zM16IVDpOMBUVME46OEwuFBQuTAACAED/8AWYBbYAQgBOATxAFAEASUcyMCknIyESEAoHAEIBQggHK0uwHlBYQEI7AQMBTEsmHAQGAy4BBAYDHgABAgMCAQMyAAICAAEAJAcBAAARHwADAwQBACQFAQQEDB8ABgYEAQAkBQEEBAwEIAgbS7BfUFhAQDsBAwFMSyYcBAYDLgEEBgMeAAECAwIBAzIAAgIAAQAkBwEAABEfAAMDBAEAJAAEBAwfAAYGBQEAJAAFBRIFIAgbS7BlUFhAPjsBAwFMSyYcBAYDLgEEBgMeAAECAwIBAzIHAQAAAgEAAgEAJgADAwQBACQABAQPHwAGBgUBACQABQUVBSAHG0BFOwEDAUxLJhwEBgMuAQQGAx4AAQIDAgEDMgcBAAACAQACAQAmAAYEBQYBACMAAwAEBQMEAQAmAAYGBQEAJAAFBgUBACEHWVlZsDgrATIeAhcHBiIjIiYnLgMjIg4CFRQeAhcBPgE3PgE7AQ4BBwEjI
|
|
|
|
|
}
|
|
|
|
|
@font-face {
|
|
|
|
|
font-family: 'Lato';
|
|
|
|
|
font-style: italic;
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
src: url(data:font/ttf;base64,AAEAAAARAQAABAAQR1BPU/k9olMAASo4AAATDEdTVUKOOI56AAE9RAAAAHBPUy8y2a6p5gAAyxQAAABgY21hcIwYkAAAAMt0AAAAtGN2dCAG8BiZAADTXAAAAC5mcGdtclpyQAAAzCgAAAblZ2FzcAARABgAASosAAAADGdseWZusxknAAABHAAAxExoZWFk+6rxnQAAx0gAAAA2aGhlYQ/IDiQAAMrwAAAAJGhtdHg+wkYhAADHgAAAA25rZXJuOjJCAwAA04wAAFLsbG9jYaRbddQAAMWIAAABvm1heHAB3gf5AADFaAAAACBuYW1lG+M2zAABJngAAAFwcG9zdFbbDTIAAS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MyHgIHNC4CIyIOAhUUHgIzMj4CAT4BOwEBDgErAQEUDgIjIi4CNTQ+AjMyHgIHNC4CIyIOAhUUHgIzMj4CAtw7YHtBOF5DJTZdfUY4XkMmhxUkMRwoRzQfFCQxHSdHNR8CdwsdF3z7jAodFH4FAjpgfEE4XUMlNl19RjhdRCWGFSQxHChHNR8UJDEdJ0c2HwR4Y5pqNylNb0Zjm2s4KU5wSDJILhYiSnNRMUUtFSFHcQFVCxH6hQ0PAY1jm2k3KU1uRmObbDgpTnBIMkcuFSJKclExRi0VIUhyAAIAOf/wBNEFpwBCAE4BMEAUAQBJRzIwKScjIRQSDQsAQgFCCAcrS7AeUFhAPzsBAwFMSy4mHAUGAwIeAAECAwIBAzIAAgIAAQAkBwEAABEfAAMDBAEAJAUBBAQMHwAGBgQBACQFAQQEDAQgCBtLsF9QWEA9OwEDAUxLLiYcBQYDAh4AA
|
|
|
|
|
}
|
|
|
|
|
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:0.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace, monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}@media print{*,*:before,*:after{background:transparent !important;color:#000 !important;-webkit-box-shadow:none !important;box-shadow:none !important;text-shadow:none !important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href) ")"}abbr[title]:after{content:" (" attr(title) ")"}a[href^="#"]:after,a[href^="javascript:"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}p,h2,h3{orphans:3;widows:3}h2,h3{page-break-after:avoid}.navbar{display:none}.btn>.caret,.dropup>.btn>.caret{border-top-color:#000 !important}.label{border:1px solid #000}.table{border-collapse:collapse !important}.table td,.table th{background-color:#fff !important}.table-bordered th,.table-bordered td{border:1px solid #ddd !important}}@font-face{font-family:'Glyphicons Halflings';src:url(data:application/vnd.ms-fontobject;base64,n04AAEFNAAACAAIABAAAAAAABQAAAAAAAAABAJABAAAEAExQAAAAAAAAAAIAAAAAAAAAAAEAAAAAAAAAJxJ/LAAAAAAAAAAAAAAAAAAAAAAAACgARwBMAFkAUABIAEkAQwBPAE4AUwAgAEgAYQBsAGYAbABpAG4AZwBzAAAADgBSAGUAZwB1AGwAYQByAAAAeABWAGUAcgBzAGkAbwBuACAAMQAuADAAMAA5ADsAUABTACAAMAAwADEALgAwADAAOQA7AGgAbwB0AGMAbwBuAHYAIAAxAC4AMAAuADcAMAA7AG0AYQBrAGUAbwB0AGYALgBsAGkAYgAyAC4ANQAuADUAOAAzADIAOQAAADgARwBMAFkAUABIAEkAQwBPAE4AUwAgAEgAYQBsAGYAbABpAG4AZwBzACAAUgBlAGcAdQBsAGEAcgAAAAAAQlNHUAAAAAAAAAAAAAAAAAAAAAADAKncAE0TAE0ZAEbuFM3pjM/SEdmjKHUbyow8ATBE40IvWA3vTu8LiABDQ+pexwUMcm1SMnNryctQSiI1K5ZnbOlXKmnVV5YvRe6RnNMFNCOs1KNVpn6yZhCJkRtVRNzEufeIq7HgSrcx4S8h/v4vnrrKc6oCNxmSk2uKlZQHBii6iKFoH0746ThvkO1kJHlxjrkxs+LWORaDQBEtiYJIR5IB9Bi1UyL4Rmr0BNigNkMzlKQmnofBHviqVzUxwdMb3NdCn69hy+pRYVKGVS/1tnsqv4LL7wCCPZZAZPT4aCShHjHJVNuXbmMrY5LeQaGnvAkXlVrJgKRAUdFjrWEah9XebPeQMj7KS7DIBAFt8ycgC5PLGUOHSE3ErGZCiViNLL5ZARfywnCoZaKQCu6NuFX42AEeKtKUGnr/Cm2Cy8tpFhBPMW5Fxi4Qm4TkDWh4IWFDClhU2hRWosUWqcKLlgyXB+lSHaWaHiWlBAR8SeSgSPCQxdVQgzUixWKSTrIQEbU94viDctkvX+VSjJuUmV8L4CXShI11esnp0pjWNZIyxKHS4wVQ2ime1P4RnhvGw0aDN1OLAXGERsB7buFpFGGBAre4QEQR0HOIO5oYH305G+KspT/FupEGGa
|
|
|
|
|
</style>
|
|
|
|
|
<script>/*!
|
|
|
|
|
* Bootstrap v3.3.5 (http://getbootstrap.com)
|
|
|
|
|
* Copyright 2011-2015 Twitter, Inc.
|
|
|
|
|
* Licensed under the MIT license
|
|
|
|
|
*/
|
|
|
|
|
if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";var b=a.fn.jquery.split(" ")[0].split(".");if(b[0]<2&&b[1]<9||1==b[0]&&9==b[1]&&b[2]<1)throw new Error("Bootstrap's JavaScript requires jQuery version 1.9.1 or higher")}(jQuery),+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one("bsTransitionEnd",function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b(),a.support.transition&&(a.event.special.bsTransitionEnd={bindType:a.support.transition.end,delegateType:a.support.transition.end,handle:function(b){return a(b.target).is(this)?b.handleObj.handler.apply(this,arguments):void 0}})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var c=a(this),e=c.data("bs.alert");e||c.data("bs.alert",e=new d(this)),"string"==typeof b&&e[b].call(c)})}var c='[data-dismiss="alert"]',d=function(b){a(b).on("click",c,this.close)};d.VERSION="3.3.5",d.TRANSITION_DURATION=150,d.prototype.close=function(b){function c(){g.detach().trigger("closed.bs.alert").remove()}var e=a(this),f=e.attr("data-target");f||(f=e.attr("href"),f=f&&f.replace(/.*(?=#[^\s]*$)/,""));var g=a(f);b&&b.preventDefault(),g.length||(g=e.closest(".alert")),g.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(g.removeClass("in"),a.support.transition&&g.hasClass("fade")?g.one("bsTransitionEnd",c).emulateTransitionEnd(d.TRANSITION_DURATION):c())};var e=a.fn.alert;a.fn.alert=b,a.fn.alert.Constructor=d,a.fn.alert.noConflict=function(){return a.fn.alert=e,this},a(document).on("click.bs.alert.data-api",c,d.prototype.close)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof b&&b;e||d.data("bs.button",e=new c(this,f)),"toggle"==b?e.toggle():b&&e.setState(b)})}var c=function(b,d){this.$element=a(b),this.options=a.extend({},c.DEFAULTS,d),this.isLoading=!1};c.VERSION="3.3.5",c.DEFAULTS={loadingText:"loading..."},c.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",null==f.resetText&&d.data("resetText",d[e]()),setTimeout(a.proxy(function(){d[e](null==f[b]?this.options[b]:f[b]),"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c))},this),0)},c.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")?(c.prop("checked")&&(a=!1),b.find(".active").removeClass("active"),this.$element.addClass("active")):"checkbox"==c.prop("type")&&(c.prop("checked")!==this.$element.hasClass("active")&&(a=!1),this.$element.toggleClass("active")),c.prop("checked",this.$element.hasClass("active")),a&&c.trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active")),this.$element.toggleClass("active")};var d=a.fn.button;a.fn.button=b,a.fn.button.Constructor=c,a.fn.button.noConflict=function(){return a.fn.button=d,this},a(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(c){var d=a(c.target);d.hasClass("btn")||(d=d.closest(".btn")),b.call(d,"toggle"),a(c.target).is('input[type="radio"]')||a(c.target).is('input[type="checkbox"]')||c.preventDefault()}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(b){a(b.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(b.type))})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},c.DEFAULTS,d.data(),"object"==typeof b&&b),g="string"==typeof b?b:f.slide;e||d.data("bs.carousel",e=new c(this,f)),"number"==type
|
|
|
|
|
d.trigger("activate.bs.scrollspy")},b.prototype.clear=function(){a(this.selector).parentsUntil(this.options.target,".active").removeClass("active")};var d=a.fn.scrollspy;a.fn.scrollspy=c,a.fn.scrollspy.Constructor=b,a.fn.scrollspy.noConflict=function(){return a.fn.scrollspy=d,this},a(window).on("load.bs.scrollspy.data-api",function(){a('[data-spy="scroll"]').each(function(){var b=a(this);c.call(b,b.data())})})}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.tab");e||d.data("bs.tab",e=new c(this)),"string"==typeof b&&e[b]()})}var c=function(b){this.element=a(b)};c.VERSION="3.3.5",c.TRANSITION_DURATION=150,c.prototype.show=function(){var b=this.element,c=b.closest("ul:not(.dropdown-menu)"),d=b.data("target");if(d||(d=b.attr("href"),d=d&&d.replace(/.*(?=#[^\s]*$)/,"")),!b.parent("li").hasClass("active")){var e=c.find(".active:last a"),f=a.Event("hide.bs.tab",{relatedTarget:b[0]}),g=a.Event("show.bs.tab",{relatedTarget:e[0]});if(e.trigger(f),b.trigger(g),!g.isDefaultPrevented()&&!f.isDefaultPrevented()){var h=a(d);this.activate(b.closest("li"),c),this.activate(h,h.parent(),function(){e.trigger({type:"hidden.bs.tab",relatedTarget:b[0]}),b.trigger({type:"shown.bs.tab",relatedTarget:e[0]})})}}},c.prototype.activate=function(b,d,e){function f(){g.removeClass("active").find("> .dropdown-menu > .active").removeClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!1),b.addClass("active").find('[data-toggle="tab"]').attr("aria-expanded",!0),h?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu").length&&b.closest("li.dropdown").addClass("active").end().find('[data-toggle="tab"]').attr("aria-expanded",!0),e&&e()}var g=d.find("> .active"),h=e&&a.support.transition&&(g.length&&g.hasClass("fade")||!!d.find("> .fade").length);g.length&&h?g.one("bsTransitionEnd",f).emulateTransitionEnd(c.TRANSITION_DURATION):f(),g.removeClass("in")};var d=a.fn.tab;a.fn.tab=b,a.fn.tab.Constructor=c,a.fn.tab.noConflict=function(){return a.fn.tab=d,this};var e=function(c){c.preventDefault(),b.call(a(this),"show")};a(document).on("click.bs.tab.data-api",'[data-toggle="tab"]',e).on("click.bs.tab.data-api",'[data-toggle="pill"]',e)}(jQuery),+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof b&&b;e||d.data("bs.affix",e=new c(this,f)),"string"==typeof b&&e[b]()})}var c=function(b,d){this.options=a.extend({},c.DEFAULTS,d),this.$target=a(this.options.target).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(b),this.affixed=null,this.unpin=null,this.pinnedOffset=null,this.checkPosition()};c.VERSION="3.3.5",c.RESET="affix affix-top affix-bottom",c.DEFAULTS={offset:0,target:window},c.prototype.getState=function(a,b,c,d){var e=this.$target.scrollTop(),f=this.$element.offset(),g=this.$target.height();if(null!=c&&"top"==this.affixed)return c>e?"top":!1;if("bottom"==this.affixed)return null!=c?e+this.unpin<=f.top?!1:"bottom":a-d>=e+g?!1:"bottom";var h=null==this.affixed,i=h?e:f.top,j=h?g:b;return null!=c&&c>=e?"top":null!=d&&i+j>=a-d?"bottom":!1},c.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(c.RESET).addClass("affix");var a=this.$target.scrollTop(),b=this.$element.offset();return this.pinnedOffset=b.top-a},c.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},c.prototype.checkPosition=function(){if(this.$element.is(":visible")){var b=this.$element.height(),d=this.options.offset,e=d.top,f=d.bottom,g=Math.max(a(document).height(),a(document.body).height());"object"!=typeof d&&(f=e=d),"function"==typeof e&&(e=d.top(this.$element)),"function"==typeof f&&(f=d.bottom(this.$element));var h=this.getState(g,b,e,f);if(this.affixed!=h){null!=this.unpin&&this.$element.css("top","");var i="affix"+(h?"-"+h:""),j=a.Event(i+".bs.affix");if(this.$element.trigger(j),j.isDefaultPrevented())return;this.affi
|
|
|
|
|
<script>/**
|
|
|
|
|
* @preserve HTML5 Shiv 3.7.2 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
|
|
|
|
|
*/
|
|
|
|
|
// Only run this code in IE 8
|
|
|
|
|
if (!!window.navigator.userAgent.match("MSIE 8")) {
|
|
|
|
|
!function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x<style>"+b+"</style>",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.2",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="<xyz></xyz>",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b)}(this,document);
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<script>/*! Respond.js v1.4.2: min/max-width media query polyfill * Copyright 2013 Scott Jehl
|
|
|
|
|
* Licensed under https://github.com/scottjehl/Respond/blob/master/LICENSE-MIT
|
|
|
|
|
* */
|
|
|
|
|
|
|
|
|
|
// Only run this code in IE 8
|
|
|
|
|
if (!!window.navigator.userAgent.match("MSIE 8")) {
|
|
|
|
|
!function(a){"use strict";a.matchMedia=a.matchMedia||function(a){var b,c=a.documentElement,d=c.firstElementChild||c.firstChild,e=a.createElement("body"),f=a.createElement("div");return f.id="mq-test-1",f.style.cssText="position:absolute;top:-100em",e.style.background="none",e.appendChild(f),function(a){return f.innerHTML='­<style media="'+a+'"> #mq-test-1 { width: 42px; }</style>',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){u(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))};if(c.ajax=f,c.queue=d,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/,maxw:/\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var g,h,i,j=a.document,k=j.documentElement,l=[],m=[],n=[],o={},p=30,q=j.getElementsByTagName("head")[0]||k,r=j.getElementsByTagName("base")[0],s=q.getElementsByTagName("link"),t=function(){var a,b=j.createElement("div"),c=j.body,d=k.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=j.createElement("body"),c.style.background="none"),k.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&k.insertBefore(c,k.firstChild),a=b.offsetWidth,f?k.removeChild(c):c.removeChild(b),k.style.fontSize=d,e&&(c.style.fontSize=e),a=i=parseFloat(a)},u=function(b){var c="clientWidth",d=k[c],e="CSS1Compat"===j.compatMode&&d||j.body[c]||d,f={},o=s[s.length-1],r=(new Date).getTime();if(b&&g&&p>r-g)return a.clearTimeout(h),h=a.setTimeout(u,p),void 0;g=r;for(var v in l)if(l.hasOwnProperty(v)){var w=l[v],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?i||t():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?i||t():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(m[w.rules]))}for(var C in n)n.hasOwnProperty(C)&&n[C]&&n[C].parentNode===q&&q.removeChild(n[C]);n.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=j.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,q.insertBefore(E,o.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(j.createTextNode(F)),n.push(E)}},v=function(a,b,d){var e=a.replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var g=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},h=!f&&d;b.length&&(b+="/"),h&&(f=1);for(var i=0;f>i;i++){var j,k,n,o;h?(j=d,m.push(g(a))):(j=e[i].match(c.regex.findStyles)&&RegExp.$1,m.push(RegExp.$2&&g(RegExp.$2))),n=j.split(","),o=n.length;for(var p=0;o>p;p++)k=n[p],l.push({media:k.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:m.length-1,hasquery:k.indexOf("(")>-1,minw:k.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:k.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},w=function(){if(d.length){var b=d.shift();f(b.href,function(c){v(c,b.href,b.media),o[b.href]=!0,a.setTimeout(function(){w()},0)})}},x=function(){for(var b=0;b<s.length;b++){var c=s[b],e=c.href,f=c.media,g=c.rel&&"stylesheet"===c.rel.toLowerCase();e&&g&&!o[e]&&(c.styleSheet&&c.styleSheet.rawCssText?(v(c.styleSheet.rawCssText,e,f),o[e]=!0):(!/^([a-zA-Z:]*\/\/)/.test(e)&&!r||e.replace(RegExp.$1,"").split("/")[0]===a.location.host)&&("//"===e.substring(0,2)&&(e=a.location.protocol+e),d.push({href:e,media:f})))}w()};x(),c.update=x,c.getEmVal
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<style>h1 {font-size: 34px;}
|
|
|
|
|
h1.title {font-size: 38px;}
|
|
|
|
|
h2 {font-size: 30px;}
|
|
|
|
|
h3 {font-size: 24px;}
|
|
|
|
|
h4 {font-size: 18px;}
|
|
|
|
|
h5 {font-size: 16px;}
|
|
|
|
|
h6 {font-size: 12px;}
|
|
|
|
|
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
|
|
|
|
|
pre:not([class]) { background-color: white }</style>
|
|
|
|
|
<script>/*! jQuery UI - v1.11.4 - 2016-01-05
|
|
|
|
|
* http://jqueryui.com
|
|
|
|
|
* Includes: core.js, widget.js, mouse.js, position.js, draggable.js, droppable.js, resizable.js, selectable.js, sortable.js, accordion.js, autocomplete.js, button.js, dialog.js, menu.js, progressbar.js, selectmenu.js, slider.js, spinner.js, tabs.js, tooltip.js, effect.js, effect-blind.js, effect-bounce.js, effect-clip.js, effect-drop.js, effect-explode.js, effect-fade.js, effect-fold.js, effect-highlight.js, effect-puff.js, effect-pulsate.js, effect-scale.js, effect-shake.js, effect-size.js, effect-slide.js, effect-transfer.js
|
|
|
|
|
* Copyright jQuery Foundation and other contributors; Licensed MIT */
|
|
|
|
|
|
|
|
|
|
(function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)})(function(e){function t(t,s){var n,a,o,r=t.nodeName.toLowerCase();return"area"===r?(n=t.parentNode,a=n.name,t.href&&a&&"map"===n.nodeName.toLowerCase()?(o=e("img[usemap='#"+a+"']")[0],!!o&&i(o)):!1):(/^(input|select|textarea|button|object)$/.test(r)?!t.disabled:"a"===r?t.href||s:s)&&i(t)}function i(t){return e.expr.filters.visible(t)&&!e(t).parents().addBack().filter(function(){return"hidden"===e.css(this,"visibility")}).length}function s(e){return function(){var t=this.element.val();e.apply(this,arguments),this._refresh(),t!==this.element.val()&&this._trigger("change")}}e.ui=e.ui||{},e.extend(e.ui,{version:"1.11.4",keyCode:{BACKSPACE:8,COMMA:188,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,LEFT:37,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SPACE:32,TAB:9,UP:38}}),e.fn.extend({scrollParent:function(t){var i=this.css("position"),s="absolute"===i,n=t?/(auto|scroll|hidden)/:/(auto|scroll)/,a=this.parents().filter(function(){var t=e(this);return s&&"static"===t.css("position")?!1:n.test(t.css("overflow")+t.css("overflow-y")+t.css("overflow-x"))}).eq(0);return"fixed"!==i&&a.length?a:e(this[0].ownerDocument||document)},uniqueId:function(){var e=0;return function(){return this.each(function(){this.id||(this.id="ui-id-"+ ++e)})}}(),removeUniqueId:function(){return this.each(function(){/^ui-id-\d+$/.test(this.id)&&e(this).removeAttr("id")})}}),e.extend(e.expr[":"],{data:e.expr.createPseudo?e.expr.createPseudo(function(t){return function(i){return!!e.data(i,t)}}):function(t,i,s){return!!e.data(t,s[3])},focusable:function(i){return t(i,!isNaN(e.attr(i,"tabindex")))},tabbable:function(i){var s=e.attr(i,"tabindex"),n=isNaN(s);return(n||s>=0)&&t(i,!n)}}),e("<a>").outerWidth(1).jquery||e.each(["Width","Height"],function(t,i){function s(t,i,s,a){return e.each(n,function(){i-=parseFloat(e.css(t,"padding"+this))||0,s&&(i-=parseFloat(e.css(t,"border"+this+"Width"))||0),a&&(i-=parseFloat(e.css(t,"margin"+this))||0)}),i}var n="Width"===i?["Left","Right"]:["Top","Bottom"],a=i.toLowerCase(),o={innerWidth:e.fn.innerWidth,innerHeight:e.fn.innerHeight,outerWidth:e.fn.outerWidth,outerHeight:e.fn.outerHeight};e.fn["inner"+i]=function(t){return void 0===t?o["inner"+i].call(this):this.each(function(){e(this).css(a,s(this,t)+"px")})},e.fn["outer"+i]=function(t,n){return"number"!=typeof t?o["outer"+i].call(this,t):this.each(function(){e(this).css(a,s(this,t,!0,n)+"px")})}}),e.fn.addBack||(e.fn.addBack=function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}),e("<a>").data("a-b","a").removeData("a-b").data("a-b")&&(e.fn.removeData=function(t){return function(i){return arguments.length?t.call(this,e.camelCase(i)):t.call(this)}}(e.fn.removeData)),e.ui.ie=!!/msie [\w.]+/.exec(navigator.userAgent.toLowerCase()),e.fn.extend({focus:function(t){return function(i,s){return"number"==typeof i?this.each(function(){var t=this;setTimeout(function(){e(t).focus(),s&&s.call(t)},i)}):t.apply(this,arguments)}}(e.fn.focus),disableSelection:function(){var e="onselectstart"in document.createElement("div")?"selectstart":"mousedown";return function(){return this.bind(e+".ui-disableSelection",function(e){e.preventDefault()})}}(),enableSelection:function(){return this.unbind(".ui-disableSelection")},zIndex:function(t){if(void 0!==t)return this.css("zIndex",t);if(this.length)for(var i,s,n=e(this[0]);n.length&&n[0]!==document;){if(i=n.css("position"),("absolute"===i||"relative"===i||"fixed"===i)&&(s=parseInt(n.css("zIndex"),10),!isNaN(s)&&0!==s))return s;n=n.parent()}return 0}}),e.ui.plugin={add:function(t,i,s){var n,a=e.ui[t].prototype;for(n in s)a.plugins[n]=a.plugins[n]||[],a.plugins[n].push([i,s[n]])},call:function(e,t,i,s){var n,a=e.plugins[t];if(a&&(s||e.element[0].parentNode&&11!==e.element[0].parentNode.nodeType))for(n=0;a.length>n;n++)e.options[a[n][0]]&&a[n][1].apply(e.element,i)}};var n=0,a=Array.prototype.slice;e.cleanData=function(t){return function(i){var s,n,a;for(a=0;null!=(n=i[a]);a++)try{s=e._data(n,"events"),s&&s.remove&&e(n).triggerHandler("remove
|
|
|
|
|
})),n?(a.isOver||(a.isOver=1,s._parent=i.helper.parent(),a.currentItem=i.helper.appendTo(a.element).data("ui-sortable-item",!0),a.options._helper=a.options.helper,a.options.helper=function(){return i.helper[0]},t.target=a.currentItem[0],a._mouseCapture(t,!0),a._mouseStart(t,!0,!0),a.offset.click.top=s.offset.click.top,a.offset.click.left=s.offset.click.left,a.offset.parent.left-=s.offset.parent.left-a.offset.parent.left,a.offset.parent.top-=s.offset.parent.top-a.offset.parent.top,s._trigger("toSortable",t),s.dropped=a.element,e.each(s.sortables,function(){this.refreshPositions()}),s.currentItem=s.element,a.fromOutside=s),a.currentItem&&(a._mouseDrag(t),i.position=a.position)):a.isOver&&(a.isOver=0,a.cancelHelperRemoval=!0,a.options._revert=a.options.revert,a.options.revert=!1,a._trigger("out",t,a._uiHash(a)),a._mouseStop(t,!0),a.options.revert=a.options._revert,a.options.helper=a.options._helper,a.placeholder&&a.placeholder.remove(),i.helper.appendTo(s._parent),s._refreshOffsets(t),i.position=s._generatePosition(t,!0),s._trigger("fromSortable",t),s.dropped=!1,e.each(s.sortables,function(){this.refreshPositions()}))})}}),e.ui.plugin.add("draggable","cursor",{start:function(t,i,s){var n=e("body"),a=s.options;n.css("cursor")&&(a._cursor=n.css("cursor")),n.css("cursor",a.cursor)},stop:function(t,i,s){var n=s.options;n._cursor&&e("body").css("cursor",n._cursor)}}),e.ui.plugin.add("draggable","opacity",{start:function(t,i,s){var n=e(i.helper),a=s.options;n.css("opacity")&&(a._opacity=n.css("opacity")),n.css("opacity",a.opacity)},stop:function(t,i,s){var n=s.options;n._opacity&&e(i.helper).css("opacity",n._opacity)}}),e.ui.plugin.add("draggable","scroll",{start:function(e,t,i){i.scrollParentNotHidden||(i.scrollParentNotHidden=i.helper.scrollParent(!1)),i.scrollParentNotHidden[0]!==i.document[0]&&"HTML"!==i.scrollParentNotHidden[0].tagName&&(i.overflowOffset=i.scrollParentNotHidden.offset())},drag:function(t,i,s){var n=s.options,a=!1,o=s.scrollParentNotHidden[0],r=s.document[0];o!==r&&"HTML"!==o.tagName?(n.axis&&"x"===n.axis||(s.overflowOffset.top+o.offsetHeight-t.pageY<n.scrollSensitivity?o.scrollTop=a=o.scrollTop+n.scrollSpeed:t.pageY-s.overflowOffset.top<n.scrollSensitivity&&(o.scrollTop=a=o.scrollTop-n.scrollSpeed)),n.axis&&"y"===n.axis||(s.overflowOffset.left+o.offsetWidth-t.pageX<n.scrollSensitivity?o.scrollLeft=a=o.scrollLeft+n.scrollSpeed:t.pageX-s.overflowOffset.left<n.scrollSensitivity&&(o.scrollLeft=a=o.scrollLeft-n.scrollSpeed))):(n.axis&&"x"===n.axis||(t.pageY-e(r).scrollTop()<n.scrollSensitivity?a=e(r).scrollTop(e(r).scrollTop()-n.scrollSpeed):e(window).height()-(t.pageY-e(r).scrollTop())<n.scrollSensitivity&&(a=e(r).scrollTop(e(r).scrollTop()+n.scrollSpeed))),n.axis&&"y"===n.axis||(t.pageX-e(r).scrollLeft()<n.scrollSensitivity?a=e(r).scrollLeft(e(r).scrollLeft()-n.scrollSpeed):e(window).width()-(t.pageX-e(r).scrollLeft())<n.scrollSensitivity&&(a=e(r).scrollLeft(e(r).scrollLeft()+n.scrollSpeed)))),a!==!1&&e.ui.ddmanager&&!n.dropBehaviour&&e.ui.ddmanager.prepareOffsets(s,t)}}),e.ui.plugin.add("draggable","snap",{start:function(t,i,s){var n=s.options;s.snapElements=[],e(n.snap.constructor!==String?n.snap.items||":data(ui-draggable)":n.snap).each(function(){var t=e(this),i=t.offset();this!==s.element[0]&&s.snapElements.push({item:this,width:t.outerWidth(),height:t.outerHeight(),top:i.top,left:i.left})})},drag:function(t,i,s){var n,a,o,r,h,l,u,d,c,p,f=s.options,m=f.snapTolerance,g=i.offset.left,v=g+s.helperProportions.width,y=i.offset.top,b=y+s.helperProportions.height;for(c=s.snapElements.length-1;c>=0;c--)h=s.snapElements[c].left-s.margins.left,l=h+s.snapElements[c].width,u=s.snapElements[c].top-s.margins.top,d=u+s.snapElements[c].height,h-m>v||g>l+m||u-m>b||y>d+m||!e.contains(s.snapElements[c].item.ownerDocument,s.snapElements[c].item)?(s.snapElements[c].snapping&&s.options.snap.release&&s.options.snap.release.call(s.element,t,e.extend(s._uiHash(),{snapItem:s.snapElements[c].item})),s.snapElements[c].snapping=!1):("inner"!==f.snapMode&&(n=m>=Math.abs(u-b),a=m>=Math.abs(d-y),o=m>=Math.abs(h-v),r=m>=Math.abs(l-g),n&&
|
|
|
|
|
i&&i.element!==s.element[0]&&("touch"===n.tolerance?l=!(i.left>r||a>i.right||i.top>h||o>i.bottom):"fit"===n.tolerance&&(l=i.left>a&&r>i.right&&i.top>o&&h>i.bottom),l?(i.selected&&(i.$element.removeClass("ui-selected"),i.selected=!1),i.unselecting&&(i.$element.removeClass("ui-unselecting"),i.unselecting=!1),i.selecting||(i.$element.addClass("ui-selecting"),i.selecting=!0,s._trigger("selecting",t,{selecting:i.element}))):(i.selecting&&((t.metaKey||t.ctrlKey)&&i.startselected?(i.$element.removeClass("ui-selecting"),i.selecting=!1,i.$element.addClass("ui-selected"),i.selected=!0):(i.$element.removeClass("ui-selecting"),i.selecting=!1,i.startselected&&(i.$element.addClass("ui-unselecting"),i.unselecting=!0),s._trigger("unselecting",t,{unselecting:i.element}))),i.selected&&(t.metaKey||t.ctrlKey||i.startselected||(i.$element.removeClass("ui-selected"),i.selected=!1,i.$element.addClass("ui-unselecting"),i.unselecting=!0,s._trigger("unselecting",t,{unselecting:i.element})))))}),!1}},_mouseStop:function(t){var i=this;return this.dragged=!1,e(".ui-unselecting",this.element[0]).each(function(){var s=e.data(this,"selectable-item");s.$element.removeClass("ui-unselecting"),s.unselecting=!1,s.startselected=!1,i._trigger("unselected",t,{unselected:s.element})}),e(".ui-selecting",this.element[0]).each(function(){var s=e.data(this,"selectable-item");s.$element.removeClass("ui-selecting").addClass("ui-selected"),s.selecting=!1,s.selected=!0,s.startselected=!0,i._trigger("selected",t,{selected:s.element})}),this._trigger("stop",t),this.helper.remove(),!1}}),e.widget("ui.sortable",e.ui.mouse,{version:"1.11.4",widgetEventPrefix:"sort",ready:!1,options:{appendTo:"parent",axis:!1,connectWith:!1,containment:!1,cursor:"auto",cursorAt:!1,dropOnEmpty:!0,forcePlaceholderSize:!1,forceHelperSize:!1,grid:!1,handle:!1,helper:"original",items:"> *",opacity:!1,placeholder:!1,revert:!1,scroll:!0,scrollSensitivity:20,scrollSpeed:20,scope:"default",tolerance:"intersect",zIndex:1e3,activate:null,beforeStop:null,change:null,deactivate:null,out:null,over:null,receive:null,remove:null,sort:null,start:null,stop:null,update:null},_isOverAxis:function(e,t,i){return e>=t&&t+i>e},_isFloating:function(e){return/left|right/.test(e.css("float"))||/inline|table-cell/.test(e.css("display"))},_create:function(){this.containerCache={},this.element.addClass("ui-sortable"),this.refresh(),this.offset=this.element.offset(),this._mouseInit(),this._setHandleClassName(),this.ready=!0},_setOption:function(e,t){this._super(e,t),"handle"===e&&this._setHandleClassName()},_setHandleClassName:function(){this.element.find(".ui-sortable-handle").removeClass("ui-sortable-handle"),e.each(this.items,function(){(this.instance.options.handle?this.item.find(this.instance.options.handle):this.item).addClass("ui-sortable-handle")})},_destroy:function(){this.element.removeClass("ui-sortable ui-sortable-disabled").find(".ui-sortable-handle").removeClass("ui-sortable-handle"),this._mouseDestroy();for(var e=this.items.length-1;e>=0;e--)this.items[e].item.removeData(this.widgetName+"-item");return this},_mouseCapture:function(t,i){var s=null,n=!1,a=this;return this.reverting?!1:this.options.disabled||"static"===this.options.type?!1:(this._refreshItems(t),e(t.target).parents().each(function(){return e.data(this,a.widgetName+"-item")===a?(s=e(this),!1):void 0}),e.data(t.target,a.widgetName+"-item")===a&&(s=e(t.target)),s?!this.options.handle||i||(e(this.options.handle,s).find("*").addBack().each(function(){this===t.target&&(n=!0)}),n)?(this.currentItem=s,this._removeCurrentsFromItems(),!0):!1:!1)},_mouseStart:function(t,i,s){var n,a,o=this.options;if(this.currentContainer=this,this.refreshPositions(),this.helper=this._createHelper(t),this._cacheHelperProportions(),this._cacheMargins(),this.scrollParent=this.helper.scrollParent(),this.offset=this.currentItem.offset(),this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left},e.extend(this.offset,{click:{left:t.pageX-this.offset.left,top:t.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffse
|
|
|
|
|
t.preventDefault(),a&&!i.collapsible||this._trigger("beforeActivate",t,l)===!1||(i.active=o?!1:this.headers.index(n),this.active=a?e():n,this._toggle(l),s.removeClass("ui-accordion-header-active ui-state-active"),i.icons&&s.children(".ui-accordion-header-icon").removeClass(i.icons.activeHeader).addClass(i.icons.header),a||(n.removeClass("ui-corner-all").addClass("ui-accordion-header-active ui-state-active ui-corner-top"),i.icons&&n.children(".ui-accordion-header-icon").removeClass(i.icons.header).addClass(i.icons.activeHeader),n.next().addClass("ui-accordion-content-active")))},_toggle:function(t){var i=t.newPanel,s=this.prevShow.length?this.prevShow:t.oldPanel;this.prevShow.add(this.prevHide).stop(!0,!0),this.prevShow=i,this.prevHide=s,this.options.animate?this._animate(i,s,t):(s.hide(),i.show(),this._toggleComplete(t)),s.attr({"aria-hidden":"true"}),s.prev().attr({"aria-selected":"false","aria-expanded":"false"}),i.length&&s.length?s.prev().attr({tabIndex:-1,"aria-expanded":"false"}):i.length&&this.headers.filter(function(){return 0===parseInt(e(this).attr("tabIndex"),10)}).attr("tabIndex",-1),i.attr("aria-hidden","false").prev().attr({"aria-selected":"true","aria-expanded":"true",tabIndex:0})},_animate:function(e,t,i){var s,n,a,o=this,r=0,h=e.css("box-sizing"),l=e.length&&(!t.length||e.index()<t.index()),u=this.options.animate||{},d=l&&u.down||u,c=function(){o._toggleComplete(i)};return"number"==typeof d&&(a=d),"string"==typeof d&&(n=d),n=n||d.easing||u.easing,a=a||d.duration||u.duration,t.length?e.length?(s=e.show().outerHeight(),t.animate(this.hideProps,{duration:a,easing:n,step:function(e,t){t.now=Math.round(e)}}),e.hide().animate(this.showProps,{duration:a,easing:n,complete:c,step:function(e,i){i.now=Math.round(e),"height"!==i.prop?"content-box"===h&&(r+=i.now):"content"!==o.options.heightStyle&&(i.now=Math.round(s-t.outerHeight()-r),r=0)}}),void 0):t.animate(this.hideProps,a,n,c):e.animate(this.showProps,a,n,c)},_toggleComplete:function(e){var t=e.oldPanel;t.removeClass("ui-accordion-content-active").prev().removeClass("ui-corner-top").addClass("ui-corner-all"),t.length&&(t.parent()[0].className=t.parent()[0].className),this._trigger("activate",null,e)}}),e.widget("ui.menu",{version:"1.11.4",defaultElement:"<ul>",delay:300,options:{icons:{submenu:"ui-icon-carat-1-e"},items:"> *",menus:"ul",position:{my:"left-1 top",at:"right top"},role:"menu",blur:null,focus:null,select:null},_create:function(){this.activeMenu=this.element,this.mouseHandled=!1,this.element.uniqueId().addClass("ui-menu ui-widget ui-widget-content").toggleClass("ui-menu-icons",!!this.element.find(".ui-icon").length).attr({role:this.options.role,tabIndex:0}),this.options.disabled&&this.element.addClass("ui-state-disabled").attr("aria-disabled","true"),this._on({"mousedown .ui-menu-item":function(e){e.preventDefault()},"click .ui-menu-item":function(t){var i=e(t.target);!this.mouseHandled&&i.not(".ui-state-disabled").length&&(this.select(t),t.isPropagationStopped()||(this.mouseHandled=!0),i.has(".ui-menu").length?this.expand(t):!this.element.is(":focus")&&e(this.document[0].activeElement).closest(".ui-menu").length&&(this.element.trigger("focus",[!0]),this.active&&1===this.active.parents(".ui-menu").length&&clearTimeout(this.timer)))},"mouseenter .ui-menu-item":function(t){if(!this.previousFilter){var i=e(t.currentTarget);i.siblings(".ui-state-active").removeClass("ui-state-active"),this.focus(t,i)}},mouseleave:"collapseAll","mouseleave .ui-menu":"collapseAll",focus:function(e,t){var i=this.active||this.element.find(this.options.items).eq(0);t||this.focus(e,i)},blur:function(t){this._delay(function(){e.contains(this.element[0],this.document[0].activeElement)||this.collapseAll(t)})},keydown:"_keydown"}),this.refresh(),this._on(this.document,{click:function(e){this._closeOnDocumentClick(e)&&this.collapseAll(e),this.mouseHandled=!1}})},_destroy:function(){this.element.removeAttr("aria-activedescendant").find(".ui-menu").addBack().removeClass("ui-menu ui-widget ui-widget-content ui-menu-icons ui-front").removeAttr("role").removeAttr("tabIndex").removeAt
|
|
|
|
|
},_createButtonPane:function(){this.uiDialogButtonPane=e("<div>").addClass("ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"),this.uiButtonSet=e("<div>").addClass("ui-dialog-buttonset").appendTo(this.uiDialogButtonPane),this._createButtons()},_createButtons:function(){var t=this,i=this.options.buttons;return this.uiDialogButtonPane.remove(),this.uiButtonSet.empty(),e.isEmptyObject(i)||e.isArray(i)&&!i.length?(this.uiDialog.removeClass("ui-dialog-buttons"),void 0):(e.each(i,function(i,s){var n,a;s=e.isFunction(s)?{click:s,text:i}:s,s=e.extend({type:"button"},s),n=s.click,s.click=function(){n.apply(t.element[0],arguments)},a={icons:s.icons,text:s.showText},delete s.icons,delete s.showText,e("<button></button>",s).button(a).appendTo(t.uiButtonSet)}),this.uiDialog.addClass("ui-dialog-buttons"),this.uiDialogButtonPane.appendTo(this.uiDialog),void 0)},_makeDraggable:function(){function t(e){return{position:e.position,offset:e.offset}}var i=this,s=this.options;this.uiDialog.draggable({cancel:".ui-dialog-content, .ui-dialog-titlebar-close",handle:".ui-dialog-titlebar",containment:"document",start:function(s,n){e(this).addClass("ui-dialog-dragging"),i._blockFrames(),i._trigger("dragStart",s,t(n))},drag:function(e,s){i._trigger("drag",e,t(s))},stop:function(n,a){var o=a.offset.left-i.document.scrollLeft(),r=a.offset.top-i.document.scrollTop();s.position={my:"left top",at:"left"+(o>=0?"+":"")+o+" "+"top"+(r>=0?"+":"")+r,of:i.window},e(this).removeClass("ui-dialog-dragging"),i._unblockFrames(),i._trigger("dragStop",n,t(a))}})},_makeResizable:function(){function t(e){return{originalPosition:e.originalPosition,originalSize:e.originalSize,position:e.position,size:e.size}}var i=this,s=this.options,n=s.resizable,a=this.uiDialog.css("position"),o="string"==typeof n?n:"n,e,s,w,se,sw,ne,nw";this.uiDialog.resizable({cancel:".ui-dialog-content",containment:"document",alsoResize:this.element,maxWidth:s.maxWidth,maxHeight:s.maxHeight,minWidth:s.minWidth,minHeight:this._minHeight(),handles:o,start:function(s,n){e(this).addClass("ui-dialog-resizing"),i._blockFrames(),i._trigger("resizeStart",s,t(n))},resize:function(e,s){i._trigger("resize",e,t(s))},stop:function(n,a){var o=i.uiDialog.offset(),r=o.left-i.document.scrollLeft(),h=o.top-i.document.scrollTop();s.height=i.uiDialog.height(),s.width=i.uiDialog.width(),s.position={my:"left top",at:"left"+(r>=0?"+":"")+r+" "+"top"+(h>=0?"+":"")+h,of:i.window},e(this).removeClass("ui-dialog-resizing"),i._unblockFrames(),i._trigger("resizeStop",n,t(a))}}).css("position",a)},_trackFocus:function(){this._on(this.widget(),{focusin:function(t){this._makeFocusTarget(),this._focusedElement=e(t.target)}})},_makeFocusTarget:function(){this._untrackInstance(),this._trackingInstances().unshift(this)},_untrackInstance:function(){var t=this._trackingInstances(),i=e.inArray(this,t);-1!==i&&t.splice(i,1)},_trackingInstances:function(){var e=this.document.data("ui-dialog-instances");return e||(e=[],this.document.data("ui-dialog-instances",e)),e},_minHeight:function(){var e=this.options;return"auto"===e.height?e.minHeight:Math.min(e.minHeight,e.height)},_position:function(){var e=this.uiDialog.is(":visible");e||this.uiDialog.show(),this.uiDialog.position(this.options.position),e||this.uiDialog.hide()},_setOptions:function(t){var i=this,s=!1,n={};e.each(t,function(e,t){i._setOption(e,t),e in i.sizeRelatedOptions&&(s=!0),e in i.resizableRelatedOptions&&(n[e]=t)}),s&&(this._size(),this._position()),this.uiDialog.is(":data(ui-resizable)")&&this.uiDialog.resizable("option",n)},_setOption:function(e,t){var i,s,n=this.uiDialog;"dialogClass"===e&&n.removeClass(this.options.dialogClass).addClass(t),"disabled"!==e&&(this._super(e,t),"appendTo"===e&&this.uiDialog.appendTo(this._appendTo()),"buttons"===e&&this._createButtons(),"closeText"===e&&this.uiDialogTitlebarClose.button({label:""+t}),"draggable"===e&&(i=n.is(":data(ui-draggable)"),i&&!t&&n.draggable("destroy"),!i&&t&&this._makeDraggable()),"position"===e&&this._position(),"resizable"===e&&(s=n.is(":data(ui-resizable)"),s&&!t&&n.resizable("destroy"),s&&"string"==typeo
|
|
|
|
|
},_format:function(e){return""===e?"":window.Globalize&&this.options.numberFormat?Globalize.format(e,this.options.numberFormat,this.options.culture):e},_refresh:function(){this.element.attr({"aria-valuemin":this.options.min,"aria-valuemax":this.options.max,"aria-valuenow":this._parse(this.element.val())})},isValid:function(){var e=this.value();return null===e?!1:e===this._adjustValue(e)},_value:function(e,t){var i;""!==e&&(i=this._parse(e),null!==i&&(t||(i=this._adjustValue(i)),e=this._format(i))),this.element.val(e),this._refresh()},_destroy:function(){this.element.removeClass("ui-spinner-input").prop("disabled",!1).removeAttr("autocomplete").removeAttr("role").removeAttr("aria-valuemin").removeAttr("aria-valuemax").removeAttr("aria-valuenow"),this.uiSpinner.replaceWith(this.element)},stepUp:s(function(e){this._stepUp(e)}),_stepUp:function(e){this._start()&&(this._spin((e||1)*this.options.step),this._stop())},stepDown:s(function(e){this._stepDown(e)}),_stepDown:function(e){this._start()&&(this._spin((e||1)*-this.options.step),this._stop())},pageUp:s(function(e){this._stepUp((e||1)*this.options.page)}),pageDown:s(function(e){this._stepDown((e||1)*this.options.page)}),value:function(e){return arguments.length?(s(this._value).call(this,e),void 0):this._parse(this.element.val())},widget:function(){return this.uiSpinner}}),e.widget("ui.tabs",{version:"1.11.4",delay:300,options:{active:null,collapsible:!1,event:"click",heightStyle:"content",hide:null,show:null,activate:null,beforeActivate:null,beforeLoad:null,load:null},_isLocal:function(){var e=/#.*$/;return function(t){var i,s;t=t.cloneNode(!1),i=t.href.replace(e,""),s=location.href.replace(e,"");try{i=decodeURIComponent(i)}catch(n){}try{s=decodeURIComponent(s)}catch(n){}return t.hash.length>1&&i===s}}(),_create:function(){var t=this,i=this.options;this.running=!1,this.element.addClass("ui-tabs ui-widget ui-widget-content ui-corner-all").toggleClass("ui-tabs-collapsible",i.collapsible),this._processTabs(),i.active=this._initialActive(),e.isArray(i.disabled)&&(i.disabled=e.unique(i.disabled.concat(e.map(this.tabs.filter(".ui-state-disabled"),function(e){return t.tabs.index(e)}))).sort()),this.active=this.options.active!==!1&&this.anchors.length?this._findActive(i.active):e(),this._refresh(),this.active.length&&this.load(i.active)},_initialActive:function(){var t=this.options.active,i=this.options.collapsible,s=location.hash.substring(1);return null===t&&(s&&this.tabs.each(function(i,n){return e(n).attr("aria-controls")===s?(t=i,!1):void 0}),null===t&&(t=this.tabs.index(this.tabs.filter(".ui-tabs-active"))),(null===t||-1===t)&&(t=this.tabs.length?0:!1)),t!==!1&&(t=this.tabs.index(this.tabs.eq(t)),-1===t&&(t=i?!1:0)),!i&&t===!1&&this.anchors.length&&(t=0),t},_getCreateEventData:function(){return{tab:this.active,panel:this.active.length?this._getPanelForTab(this.active):e()}},_tabKeydown:function(t){var i=e(this.document[0].activeElement).closest("li"),s=this.tabs.index(i),n=!0;if(!this._handlePageNav(t)){switch(t.keyCode){case e.ui.keyCode.RIGHT:case e.ui.keyCode.DOWN:s++;break;case e.ui.keyCode.UP:case e.ui.keyCode.LEFT:n=!1,s--;break;case e.ui.keyCode.END:s=this.anchors.length-1;break;case e.ui.keyCode.HOME:s=0;break;case e.ui.keyCode.SPACE:return t.preventDefault(),clearTimeout(this.activating),this._activate(s),void 0;case e.ui.keyCode.ENTER:return t.preventDefault(),clearTimeout(this.activating),this._activate(s===this.options.active?!1:s),void 0;default:return}t.preventDefault(),clearTimeout(this.activating),s=this._focusNextTab(s,n),t.ctrlKey||t.metaKey||(i.attr("aria-selected","false"),this.tabs.eq(s).attr("aria-selected","true"),this.activating=this._delay(function(){this.option("active",s)},this.delay))}},_panelKeydown:function(t){this._handlePageNav(t)||t.ctrlKey&&t.keyCode===e.ui.keyCode.UP&&(t.preventDefault(),this.active.focus())},_handlePageNav:function(t){return t.altKey&&t.keyCode===e.ui.keyCode.PAGE_UP?(this._activate(this._focusNextTab(this.options.active-1,!1)),!0):t.altKey&&t.keyCode===e.ui.keyCode.PAGE_DOWN?(this._activate(this._focusNextTab(this.options
|
|
|
|
|
}})},e.effects.effect.bounce=function(t,i){var s,n,a,o=e(this),r=["position","top","bottom","left","right","height","width"],h=e.effects.setMode(o,t.mode||"effect"),l="hide"===h,u="show"===h,d=t.direction||"up",c=t.distance,p=t.times||5,f=2*p+(u||l?1:0),m=t.duration/f,g=t.easing,v="up"===d||"down"===d?"top":"left",y="up"===d||"left"===d,b=o.queue(),_=b.length;for((u||l)&&r.push("opacity"),e.effects.save(o,r),o.show(),e.effects.createWrapper(o),c||(c=o["top"===v?"outerHeight":"outerWidth"]()/3),u&&(a={opacity:1},a[v]=0,o.css("opacity",0).css(v,y?2*-c:2*c).animate(a,m,g)),l&&(c/=Math.pow(2,p-1)),a={},a[v]=0,s=0;p>s;s++)n={},n[v]=(y?"-=":"+=")+c,o.animate(n,m,g).animate(a,m,g),c=l?2*c:c/2;l&&(n={opacity:0},n[v]=(y?"-=":"+=")+c,o.animate(n,m,g)),o.queue(function(){l&&o.hide(),e.effects.restore(o,r),e.effects.removeWrapper(o),i()}),_>1&&b.splice.apply(b,[1,0].concat(b.splice(_,f+1))),o.dequeue()},e.effects.effect.clip=function(t,i){var s,n,a,o=e(this),r=["position","top","bottom","left","right","height","width"],h=e.effects.setMode(o,t.mode||"hide"),l="show"===h,u=t.direction||"vertical",d="vertical"===u,c=d?"height":"width",p=d?"top":"left",f={};e.effects.save(o,r),o.show(),s=e.effects.createWrapper(o).css({overflow:"hidden"}),n="IMG"===o[0].tagName?s:o,a=n[c](),l&&(n.css(c,0),n.css(p,a/2)),f[c]=l?a:0,f[p]=l?0:a/2,n.animate(f,{queue:!1,duration:t.duration,easing:t.easing,complete:function(){l||o.hide(),e.effects.restore(o,r),e.effects.removeWrapper(o),i()}})},e.effects.effect.drop=function(t,i){var s,n=e(this),a=["position","top","bottom","left","right","opacity","height","width"],o=e.effects.setMode(n,t.mode||"hide"),r="show"===o,h=t.direction||"left",l="up"===h||"down"===h?"top":"left",u="up"===h||"left"===h?"pos":"neg",d={opacity:r?1:0};e.effects.save(n,a),n.show(),e.effects.createWrapper(n),s=t.distance||n["top"===l?"outerHeight":"outerWidth"](!0)/2,r&&n.css("opacity",0).css(l,"pos"===u?-s:s),d[l]=(r?"pos"===u?"+=":"-=":"pos"===u?"-=":"+=")+s,n.animate(d,{queue:!1,duration:t.duration,easing:t.easing,complete:function(){"hide"===o&&n.hide(),e.effects.restore(n,a),e.effects.removeWrapper(n),i()}})},e.effects.effect.explode=function(t,i){function s(){b.push(this),b.length===d*c&&n()}function n(){p.css({visibility:"visible"}),e(b).remove(),m||p.hide(),i()}var a,o,r,h,l,u,d=t.pieces?Math.round(Math.sqrt(t.pieces)):3,c=d,p=e(this),f=e.effects.setMode(p,t.mode||"hide"),m="show"===f,g=p.show().css("visibility","hidden").offset(),v=Math.ceil(p.outerWidth()/c),y=Math.ceil(p.outerHeight()/d),b=[];for(a=0;d>a;a++)for(h=g.top+a*y,u=a-(d-1)/2,o=0;c>o;o++)r=g.left+o*v,l=o-(c-1)/2,p.clone().appendTo("body").wrap("<div></div>").css({position:"absolute",visibility:"visible",left:-o*v,top:-a*y}).parent().addClass("ui-effects-explode").css({position:"absolute",overflow:"hidden",width:v,height:y,left:r+(m?l*v:0),top:h+(m?u*y:0),opacity:m?0:1}).animate({left:r+(m?0:l*v),top:h+(m?0:u*y),opacity:m?1:0},t.duration||500,t.easing,s)},e.effects.effect.fade=function(t,i){var s=e(this),n=e.effects.setMode(s,t.mode||"toggle");s.animate({opacity:n},{queue:!1,duration:t.duration,easing:t.easing,complete:i})},e.effects.effect.fold=function(t,i){var s,n,a=e(this),o=["position","top","bottom","left","right","height","width"],r=e.effects.setMode(a,t.mode||"hide"),h="show"===r,l="hide"===r,u=t.size||15,d=/([0-9]+)%/.exec(u),c=!!t.horizFirst,p=h!==c,f=p?["width","height"]:["height","width"],m=t.duration/2,g={},v={};e.effects.save(a,o),a.show(),s=e.effects.createWrapper(a).css({overflow:"hidden"}),n=p?[s.width(),s.height()]:[s.height(),s.width()],d&&(u=parseInt(d[1],10)/100*n[l?0:1]),h&&s.css(c?{height:0,width:u}:{height:u,width:0}),g[f[0]]=h?n[0]:u,v[f[1]]=h?n[1]:0,s.animate(g,m,t.easing).animate(v,m,t.easing,function(){l&&a.hide(),e.effects.restore(a,o),e.effects.removeWrapper(a),i()})},e.effects.effect.highlight=function(t,i){var s=e(this),n=["backgroundImage","backgroundColor","opacity"],a=e.effects.setMode(s,t.mode||"show"),o={backgroundColor:s.css("backgroundColor")};"hide"===a&&(o.opacity=0),e.effects.save(s,n),s.show().css({backgroundImage:"none",back
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
|
|
|
|
|
.tocify {
|
|
|
|
|
width: 20%;
|
|
|
|
|
max-height: 90%;
|
|
|
|
|
overflow: auto;
|
|
|
|
|
margin-left: 2%;
|
|
|
|
|
position: fixed;
|
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tocify ul, .tocify li {
|
|
|
|
|
list-style: none;
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
border: none;
|
|
|
|
|
line-height: 30px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tocify-header {
|
|
|
|
|
text-indent: 10px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tocify-subheader {
|
|
|
|
|
text-indent: 20px;
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tocify-subheader li {
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tocify-subheader .tocify-subheader {
|
|
|
|
|
text-indent: 30px;
|
|
|
|
|
}
|
|
|
|
|
.tocify-subheader .tocify-subheader .tocify-subheader {
|
|
|
|
|
text-indent: 40px;
|
|
|
|
|
}
|
|
|
|
|
.tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader {
|
|
|
|
|
text-indent: 50px;
|
|
|
|
|
}
|
|
|
|
|
.tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader {
|
|
|
|
|
text-indent: 60px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tocify .tocify-item > a, .tocify .nav-list .nav-header {
|
|
|
|
|
margin: 0px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.tocify .tocify-item a, .tocify .list-group-item {
|
|
|
|
|
padding: 5px;
|
|
|
|
|
}
|
|
|
|
|
.tocify .nav-pills > li {
|
|
|
|
|
float: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
<script>/* jquery Tocify - v1.9.1 - 2013-10-22
|
|
|
|
|
* http://www.gregfranko.com/jquery.tocify.js/
|
|
|
|
|
* Copyright (c) 2013 Greg Franko; Licensed MIT */
|
|
|
|
|
|
|
|
|
|
// Immediately-Invoked Function Expression (IIFE) [Ben Alman Blog Post](http://benalman.com/news/2010/11/immediately-invoked-function-expression/) that calls another IIFE that contains all of the plugin logic. I used this pattern so that anyone viewing this code would not have to scroll to the bottom of the page to view the local parameters that were passed to the main IIFE.
|
|
|
|
|
(function(tocify) {
|
|
|
|
|
|
|
|
|
|
// ECMAScript 5 Strict Mode: [John Resig Blog Post](http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/)
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
// Calls the second IIFE and locally passes in the global jQuery, window, and document objects
|
|
|
|
|
tocify(window.jQuery, window, document);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Locally passes in `jQuery`, the `window` object, the `document` object, and an `undefined` variable. The `jQuery`, `window` and `document` objects are passed in locally, to improve performance, since javascript first searches for a variable match within the local variables set before searching the global variables set. All of the global variables are also passed in locally to be minifier friendly. `undefined` can be passed in locally, because it is not a reserved word in JavaScript.
|
|
|
|
|
(function($, window, document, undefined) {
|
|
|
|
|
|
|
|
|
|
// ECMAScript 5 Strict Mode: [John Resig Blog Post](http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/)
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var tocClassName = "tocify",
|
|
|
|
|
tocClass = "." + tocClassName,
|
|
|
|
|
tocFocusClassName = "tocify-focus",
|
|
|
|
|
tocHoverClassName = "tocify-hover",
|
|
|
|
|
hideTocClassName = "tocify-hide",
|
|
|
|
|
hideTocClass = "." + hideTocClassName,
|
|
|
|
|
headerClassName = "tocify-header",
|
|
|
|
|
headerClass = "." + headerClassName,
|
|
|
|
|
subheaderClassName = "tocify-subheader",
|
|
|
|
|
subheaderClass = "." + subheaderClassName,
|
|
|
|
|
itemClassName = "tocify-item",
|
|
|
|
|
itemClass = "." + itemClassName,
|
|
|
|
|
extendPageClassName = "tocify-extend-page",
|
|
|
|
|
extendPageClass = "." + extendPageClassName;
|
|
|
|
|
|
|
|
|
|
// Calling the jQueryUI Widget Factory Method
|
|
|
|
|
$.widget("toc.tocify", {
|
|
|
|
|
|
|
|
|
|
//Plugin version
|
|
|
|
|
version: "1.9.1",
|
|
|
|
|
|
|
|
|
|
// These options will be used as defaults
|
|
|
|
|
options: {
|
|
|
|
|
|
|
|
|
|
// **context**: Accepts String: Any jQuery selector
|
|
|
|
|
// The container element that holds all of the elements used to generate the table of contents
|
|
|
|
|
context: "body",
|
|
|
|
|
|
|
|
|
|
// **ignoreSelector**: Accepts String: Any jQuery selector
|
|
|
|
|
// A selector to any element that would be matched by selectors that you wish to be ignored
|
|
|
|
|
ignoreSelector: null,
|
|
|
|
|
|
|
|
|
|
// **selectors**: Accepts an Array of Strings: Any jQuery selectors
|
|
|
|
|
// The element's used to generate the table of contents. The order is very important since it will determine the table of content's nesting structure
|
|
|
|
|
selectors: "h1, h2, h3",
|
|
|
|
|
|
|
|
|
|
// **showAndHide**: Accepts a boolean: true or false
|
|
|
|
|
// Used to determine if elements should be shown and hidden
|
|
|
|
|
showAndHide: true,
|
|
|
|
|
|
|
|
|
|
// **showEffect**: Accepts String: "none", "fadeIn", "show", or "slideDown"
|
|
|
|
|
// Used to display any of the table of contents nested items
|
|
|
|
|
showEffect: "slideDown",
|
|
|
|
|
|
|
|
|
|
// **showEffectSpeed**: Accepts Number (milliseconds) or String: "slow", "medium", or "fast"
|
|
|
|
|
// The time duration of the show animation
|
|
|
|
|
showEffectSpeed: "medium",
|
|
|
|
|
|
|
|
|
|
// **hideEffect**: Accepts String: "none", "fadeOut", "hide", or "slideUp"
|
|
|
|
|
// Used to hide any of the table of contents nested items
|
|
|
|
|
hideEffect: "slideUp",
|
|
|
|
|
|
|
|
|
|
// **hideEffectSpeed**: Accepts Number (milliseconds) or String: "slow", "medium", or "fast"
|
|
|
|
|
// The time duration of the hide animation
|
|
|
|
|
hideEffectSpeed: "medium",
|
|
|
|
|
|
|
|
|
|
// **smoothScroll**: Accepts a boolean: true or false
|
|
|
|
|
// Determines if a jQuery animation should be used to scroll to specific table of contents items on the page
|
|
|
|
|
smoothScroll: true,
|
|
|
|
|
|
|
|
|
|
// **smoothScrollSpeed**: Accepts Number (milliseconds) or String: "slow", "medium", or "fast"
|
|
|
|
|
// The time duration of the smoothScroll animation
|
|
|
|
|
smoothScrollSpeed: "medium",
|
|
|
|
|
|
|
|
|
|
// **scrollTo**: Accepts Number (pixels)
|
|
|
|
|
// The amount of space between the top of page and the selected table of contents item after the page has been scrolled
|
|
|
|
|
scrollTo: 0,
|
|
|
|
|
|
|
|
|
|
// **showAndHideOnScroll**: Accepts a boolean: true or false
|
|
|
|
|
// Determines if table of contents nested items should be shown and hidden while scrolling
|
|
|
|
|
showAndHideOnScroll: true,
|
|
|
|
|
|
|
|
|
|
// **highlightOnScroll**: Accepts a boolean: true or false
|
|
|
|
|
// Determines if table of contents nested items should be highlighted (set to a different color) while scrolling
|
|
|
|
|
highlightOnScroll: true,
|
|
|
|
|
|
|
|
|
|
// **highlightOffset**: Accepts a number
|
|
|
|
|
// The offset distance in pixels to trigger the next active table of contents item
|
|
|
|
|
highlightOffset: 40,
|
|
|
|
|
|
|
|
|
|
// **theme**: Accepts a string: "bootstrap", "jqueryui", or "none"
|
|
|
|
|
// Determines if Twitter Bootstrap, jQueryUI, or Tocify classes should be added to the table of contents
|
|
|
|
|
theme: "bootstrap",
|
|
|
|
|
|
|
|
|
|
// **extendPage**: Accepts a boolean: true or false
|
|
|
|
|
// If a user scrolls to the bottom of the page and the page is not tall enough to scroll to the last table of contents item, then the page height is increased
|
|
|
|
|
extendPage: true,
|
|
|
|
|
|
|
|
|
|
// **extendPageOffset**: Accepts a number: pixels
|
|
|
|
|
// How close to the bottom of the page a user must scroll before the page is extended
|
|
|
|
|
extendPageOffset: 100,
|
|
|
|
|
|
|
|
|
|
// **history**: Accepts a boolean: true or false
|
|
|
|
|
// Adds a hash to the page url to maintain history
|
|
|
|
|
history: true,
|
|
|
|
|
|
|
|
|
|
// **scrollHistory**: Accepts a boolean: true or false
|
|
|
|
|
// Adds a hash to the page url, to maintain history, when scrolling to a TOC item
|
|
|
|
|
scrollHistory: false,
|
|
|
|
|
|
|
|
|
|
// **hashGenerator**: How the hash value (the anchor segment of the URL, following the
|
|
|
|
|
// # character) will be generated.
|
|
|
|
|
//
|
|
|
|
|
// "compact" (default) - #CompressesEverythingTogether
|
|
|
|
|
// "pretty" - #looks-like-a-nice-url-and-is-easily-readable
|
|
|
|
|
// function(text, element){} - Your own hash generation function that accepts the text as an
|
|
|
|
|
// argument, and returns the hash value.
|
|
|
|
|
hashGenerator: "compact",
|
|
|
|
|
|
|
|
|
|
// **highlightDefault**: Accepts a boolean: true or false
|
|
|
|
|
// Set's the first TOC item as active if no other TOC item is active.
|
|
|
|
|
highlightDefault: true
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// _Create
|
|
|
|
|
// -------
|
|
|
|
|
// Constructs the plugin. Only called once.
|
|
|
|
|
_create: function() {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
self.extendPageScroll = true;
|
|
|
|
|
|
|
|
|
|
// Internal array that keeps track of all TOC items (Helps to recognize if there are duplicate TOC item strings)
|
|
|
|
|
self.items = [];
|
|
|
|
|
|
|
|
|
|
// Generates the HTML for the dynamic table of contents
|
|
|
|
|
self._generateToc();
|
|
|
|
|
|
|
|
|
|
// Adds CSS classes to the newly generated table of contents HTML
|
|
|
|
|
self._addCSSClasses();
|
|
|
|
|
|
|
|
|
|
self.webkit = (function() {
|
|
|
|
|
|
|
|
|
|
for (var prop in window) {
|
|
|
|
|
|
|
|
|
|
if (prop) {
|
|
|
|
|
|
|
|
|
|
if (prop.toLowerCase().indexOf("webkit") !== -1) {
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
|
// Adds jQuery event handlers to the newly generated table of contents
|
|
|
|
|
self._setEventHandlers();
|
|
|
|
|
|
|
|
|
|
// Binding to the Window load event to make sure the correct scrollTop is calculated
|
|
|
|
|
$(window).on("load", function() {
|
|
|
|
|
|
|
|
|
|
// Sets the active TOC item
|
|
|
|
|
self._setActiveElement(true);
|
|
|
|
|
|
|
|
|
|
// Once all animations on the page are complete, this callback function will be called
|
|
|
|
|
$("html, body").promise().done(function() {
|
|
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
|
|
|
|
self.extendPageScroll = false;
|
|
|
|
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// _generateToc
|
|
|
|
|
// ------------
|
|
|
|
|
// Generates the HTML for the dynamic table of contents
|
|
|
|
|
_generateToc: function() {
|
|
|
|
|
|
|
|
|
|
// _Local variables_
|
|
|
|
|
|
|
|
|
|
// Stores the plugin context in the self variable
|
|
|
|
|
var self = this,
|
|
|
|
|
|
|
|
|
|
// All of the HTML tags found within the context provided (i.e. body) that match the top level jQuery selector above
|
|
|
|
|
firstElem,
|
|
|
|
|
|
|
|
|
|
// Instantiated variable that will store the top level newly created unordered list DOM element
|
|
|
|
|
ul,
|
|
|
|
|
ignoreSelector = self.options.ignoreSelector;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Determine the element to start the toc with
|
|
|
|
|
// get all the top level selectors
|
|
|
|
|
firstElem = [];
|
|
|
|
|
var selectors = this.options.selectors.replace(/ /g, "").split(",");
|
|
|
|
|
// find the first set that have at least one non-ignored element
|
|
|
|
|
for(var i = 0; i < selectors.length; i++) {
|
|
|
|
|
var foundSelectors = $(this.options.context).find(selectors[i]);
|
|
|
|
|
for (var s = 0; s < foundSelectors.length; s++) {
|
|
|
|
|
if (!$(foundSelectors[s]).is(ignoreSelector)) {
|
|
|
|
|
firstElem = foundSelectors;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (firstElem.length> 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!firstElem.length) {
|
|
|
|
|
|
|
|
|
|
self.element.addClass(hideTocClassName);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.element.addClass(tocClassName);
|
|
|
|
|
|
|
|
|
|
// Loops through each top level selector
|
|
|
|
|
firstElem.each(function(index) {
|
|
|
|
|
|
|
|
|
|
//If the element matches the ignoreSelector then we skip it
|
|
|
|
|
if ($(this).is(ignoreSelector)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Creates an unordered list HTML element and adds a dynamic ID and standard class name
|
|
|
|
|
ul = $("<ul/>", {
|
|
|
|
|
"id": headerClassName + index,
|
|
|
|
|
"class": headerClassName
|
|
|
|
|
}).
|
|
|
|
|
|
|
|
|
|
// Appends a top level list item HTML element to the previously created HTML header
|
|
|
|
|
append(self._nestElements($(this), index));
|
|
|
|
|
|
|
|
|
|
// Add the created unordered list element to the HTML element calling the plugin
|
|
|
|
|
self.element.append(ul);
|
|
|
|
|
|
|
|
|
|
// Finds all of the HTML tags between the header and subheader elements
|
|
|
|
|
$(this).nextUntil(this.nodeName.toLowerCase()).each(function() {
|
|
|
|
|
|
|
|
|
|
// If there are no nested subheader elemements
|
|
|
|
|
if ($(this).find(self.options.selectors).length === 0) {
|
|
|
|
|
|
|
|
|
|
// Loops through all of the subheader elements
|
|
|
|
|
$(this).filter(self.options.selectors).each(function() {
|
|
|
|
|
|
|
|
|
|
//If the element matches the ignoreSelector then we skip it
|
|
|
|
|
if ($(this).is(ignoreSelector)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self._appendSubheaders.call(this, self, ul);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If there are nested subheader elements
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
// Loops through all of the subheader elements
|
|
|
|
|
$(this).find(self.options.selectors).each(function() {
|
|
|
|
|
|
|
|
|
|
//If the element matches the ignoreSelector then we skip it
|
|
|
|
|
if ($(this).is(ignoreSelector)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self._appendSubheaders.call(this, self, ul);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_setActiveElement: function(pageload) {
|
|
|
|
|
|
|
|
|
|
var self = this,
|
|
|
|
|
|
|
|
|
|
hash = window.location.hash.substring(1),
|
|
|
|
|
|
|
|
|
|
elem = self.element.find('li[data-unique="' + hash + '"]');
|
|
|
|
|
|
|
|
|
|
if (hash.length) {
|
|
|
|
|
|
|
|
|
|
// Removes highlighting from all of the list item's
|
|
|
|
|
self.element.find("." + self.focusClass).removeClass(self.focusClass);
|
|
|
|
|
|
|
|
|
|
// Highlights the current list item that was clicked
|
|
|
|
|
elem.addClass(self.focusClass);
|
|
|
|
|
|
|
|
|
|
// Triggers the click event on the currently focused TOC item
|
|
|
|
|
elem.click();
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// Removes highlighting from all of the list item's
|
|
|
|
|
self.element.find("." + self.focusClass).removeClass(self.focusClass);
|
|
|
|
|
|
|
|
|
|
if (!hash.length && pageload && self.options.highlightDefault) {
|
|
|
|
|
|
|
|
|
|
// Highlights the first TOC item if no other items are highlighted
|
|
|
|
|
self.element.find(itemClass).first().addClass(self.focusClass);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// _nestElements
|
|
|
|
|
// -------------
|
|
|
|
|
// Helps create the table of contents list by appending nested list items
|
|
|
|
|
_nestElements: function(self, index) {
|
|
|
|
|
|
|
|
|
|
var arr, item, hashValue;
|
|
|
|
|
|
|
|
|
|
arr = $.grep(this.items, function(item) {
|
|
|
|
|
|
|
|
|
|
return item === self.text();
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// If there is already a duplicate TOC item
|
|
|
|
|
if (arr.length) {
|
|
|
|
|
|
|
|
|
|
// Adds the current TOC item text and index (for slight randomization) to the internal array
|
|
|
|
|
this.items.push(self.text() + index);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If there not a duplicate TOC item
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
// Adds the current TOC item text to the internal array
|
|
|
|
|
this.items.push(self.text());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hashValue = this._generateHashValue(arr, self, index);
|
|
|
|
|
|
|
|
|
|
// Appends a list item HTML element to the last unordered list HTML element found within the HTML element calling the plugin
|
|
|
|
|
item = $("<li/>", {
|
|
|
|
|
|
|
|
|
|
// Sets a common class name to the list item
|
|
|
|
|
"class": itemClassName,
|
|
|
|
|
|
|
|
|
|
"data-unique": hashValue
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (this.options.theme !== "bootstrap3") {
|
|
|
|
|
|
|
|
|
|
item.append($("<a/>", {
|
|
|
|
|
|
|
|
|
|
"html": self.html()
|
|
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
item.html(self.html());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adds an HTML anchor tag before the currently traversed HTML element
|
|
|
|
|
self.before($("<div/>", {
|
|
|
|
|
|
|
|
|
|
// Sets a name attribute on the anchor tag to the text of the currently traversed HTML element (also making sure that all whitespace is replaced with an underscore)
|
|
|
|
|
"name": hashValue,
|
|
|
|
|
|
|
|
|
|
"data-unique": hashValue
|
|
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// _generateHashValue
|
|
|
|
|
// ------------------
|
|
|
|
|
// Generates the hash value that will be used to refer to each item.
|
|
|
|
|
_generateHashValue: function(arr, self, index) {
|
|
|
|
|
|
|
|
|
|
var hashValue = "",
|
|
|
|
|
hashGeneratorOption = this.options.hashGenerator;
|
|
|
|
|
|
|
|
|
|
if (hashGeneratorOption === "pretty") {
|
|
|
|
|
|
|
|
|
|
// prettify the text
|
|
|
|
|
hashValue = self.text().toLowerCase().replace(/\s/g, "-");
|
|
|
|
|
|
|
|
|
|
// fix double hyphens
|
|
|
|
|
while (hashValue.indexOf("--") > -1) {
|
|
|
|
|
hashValue = hashValue.replace(/--/g, "-");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fix colon-space instances
|
|
|
|
|
while (hashValue.indexOf(":-") > -1) {
|
|
|
|
|
hashValue = hashValue.replace(/:-/g, "-");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (typeof hashGeneratorOption === "function") {
|
|
|
|
|
|
|
|
|
|
// call the function
|
|
|
|
|
hashValue = hashGeneratorOption(self.text(), self);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// compact - the default
|
|
|
|
|
hashValue = self.text().replace(/\s/g, "");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add the index if we need to
|
|
|
|
|
if (arr.length) {
|
|
|
|
|
hashValue += "" + index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// return the value
|
|
|
|
|
return hashValue;
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// _appendElements
|
|
|
|
|
// ---------------
|
|
|
|
|
// Helps create the table of contents list by appending subheader elements
|
|
|
|
|
|
|
|
|
|
_appendSubheaders: function(self, ul) {
|
|
|
|
|
|
|
|
|
|
// The current element index
|
|
|
|
|
var index = $(this).index(self.options.selectors),
|
|
|
|
|
|
|
|
|
|
// Finds the previous header DOM element
|
|
|
|
|
previousHeader = $(self.options.selectors).eq(index - 1),
|
|
|
|
|
|
|
|
|
|
currentTagName = +$(this).prop("tagName").charAt(1),
|
|
|
|
|
|
|
|
|
|
previousTagName = +previousHeader.prop("tagName").charAt(1),
|
|
|
|
|
|
|
|
|
|
lastSubheader;
|
|
|
|
|
|
|
|
|
|
// If the current header DOM element is smaller than the previous header DOM element or the first subheader
|
|
|
|
|
if (currentTagName < previousTagName) {
|
|
|
|
|
|
|
|
|
|
// Selects the last unordered list HTML found within the HTML element calling the plugin
|
|
|
|
|
self.element.find(subheaderClass + "[data-tag=" + currentTagName + "]").last().append(self._nestElements($(this), index));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the current header DOM element is the same type of header(eg. h4) as the previous header DOM element
|
|
|
|
|
else if (currentTagName === previousTagName) {
|
|
|
|
|
|
|
|
|
|
ul.find(itemClass).last().after(self._nestElements($(this), index));
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// Selects the last unordered list HTML found within the HTML element calling the plugin
|
|
|
|
|
ul.find(itemClass).last().
|
|
|
|
|
|
|
|
|
|
// Appends an unorderedList HTML element to the dynamic `unorderedList` variable and sets a common class name
|
|
|
|
|
after($("<ul/>", {
|
|
|
|
|
|
|
|
|
|
"class": subheaderClassName,
|
|
|
|
|
|
|
|
|
|
"data-tag": currentTagName
|
|
|
|
|
|
|
|
|
|
})).next(subheaderClass).
|
|
|
|
|
|
|
|
|
|
// Appends a list item HTML element to the last unordered list HTML element found within the HTML element calling the plugin
|
|
|
|
|
append(self._nestElements($(this), index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// _setEventHandlers
|
|
|
|
|
// ----------------
|
|
|
|
|
// Adds jQuery event handlers to the newly generated table of contents
|
|
|
|
|
_setEventHandlers: function() {
|
|
|
|
|
|
|
|
|
|
// _Local variables_
|
|
|
|
|
|
|
|
|
|
// Stores the plugin context in the self variable
|
|
|
|
|
var self = this,
|
|
|
|
|
|
|
|
|
|
// Instantiates a new variable that will be used to hold a specific element's context
|
|
|
|
|
$self,
|
|
|
|
|
|
|
|
|
|
// Instantiates a new variable that will be used to determine the smoothScroll animation time duration
|
|
|
|
|
duration;
|
|
|
|
|
|
|
|
|
|
// Event delegation that looks for any clicks on list item elements inside of the HTML element calling the plugin
|
|
|
|
|
this.element.on("click.tocify", "li", function(event) {
|
|
|
|
|
|
|
|
|
|
if (self.options.history) {
|
|
|
|
|
|
|
|
|
|
window.location.hash = $(this).attr("data-unique");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Removes highlighting from all of the list item's
|
|
|
|
|
self.element.find("." + self.focusClass).removeClass(self.focusClass);
|
|
|
|
|
|
|
|
|
|
// Highlights the current list item that was clicked
|
|
|
|
|
$(this).addClass(self.focusClass);
|
|
|
|
|
|
|
|
|
|
// If the showAndHide option is true
|
|
|
|
|
if (self.options.showAndHide) {
|
|
|
|
|
|
|
|
|
|
var elem = $('li[data-unique="' + $(this).attr("data-unique") + '"]');
|
|
|
|
|
|
|
|
|
|
self._triggerShow(elem);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self._scrollTo($(this));
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Mouseenter and Mouseleave event handlers for the list item's within the HTML element calling the plugin
|
|
|
|
|
this.element.find("li").on({
|
|
|
|
|
|
|
|
|
|
// Mouseenter event handler
|
|
|
|
|
"mouseenter.tocify": function() {
|
|
|
|
|
|
|
|
|
|
// Adds a hover CSS class to the current list item
|
|
|
|
|
$(this).addClass(self.hoverClass);
|
|
|
|
|
|
|
|
|
|
// Makes sure the cursor is set to the pointer icon
|
|
|
|
|
$(this).css("cursor", "pointer");
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Mouseleave event handler
|
|
|
|
|
"mouseleave.tocify": function() {
|
|
|
|
|
|
|
|
|
|
if (self.options.theme !== "bootstrap") {
|
|
|
|
|
|
|
|
|
|
// Removes the hover CSS class from the current list item
|
|
|
|
|
$(this).removeClass(self.hoverClass);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// only attach handler if needed (expensive in IE)
|
|
|
|
|
if (self.options.extendPage || self.options.highlightOnScroll || self.options.scrollHistory || self.options.showAndHideOnScroll) {
|
|
|
|
|
// Window scroll event handler
|
|
|
|
|
$(window).on("scroll.tocify", function() {
|
|
|
|
|
|
|
|
|
|
// Once all animations on the page are complete, this callback function will be called
|
|
|
|
|
$("html, body").promise().done(function() {
|
|
|
|
|
|
|
|
|
|
// Local variables
|
|
|
|
|
|
|
|
|
|
// Stores how far the user has scrolled
|
|
|
|
|
var winScrollTop = $(window).scrollTop(),
|
|
|
|
|
|
|
|
|
|
// Stores the height of the window
|
|
|
|
|
winHeight = $(window).height(),
|
|
|
|
|
|
|
|
|
|
// Stores the height of the document
|
|
|
|
|
docHeight = $(document).height(),
|
|
|
|
|
|
|
|
|
|
scrollHeight = $("body")[0].scrollHeight,
|
|
|
|
|
|
|
|
|
|
// Instantiates a variable that will be used to hold a selected HTML element
|
|
|
|
|
elem,
|
|
|
|
|
|
|
|
|
|
lastElem,
|
|
|
|
|
|
|
|
|
|
lastElemOffset,
|
|
|
|
|
|
|
|
|
|
currentElem;
|
|
|
|
|
|
|
|
|
|
if (self.options.extendPage) {
|
|
|
|
|
|
|
|
|
|
// If the user has scrolled to the bottom of the page and the last toc item is not focused
|
|
|
|
|
if ((self.webkit && winScrollTop >= scrollHeight - winHeight - self.options.extendPageOffset) || (!self.webkit && winHeight + winScrollTop > docHeight - self.options.extendPageOffset)) {
|
|
|
|
|
|
|
|
|
|
if (!$(extendPageClass).length) {
|
|
|
|
|
|
|
|
|
|
lastElem = $('div[data-unique="' + $(itemClass).last().attr("data-unique") + '"]');
|
|
|
|
|
|
|
|
|
|
if (!lastElem.length) return;
|
|
|
|
|
|
|
|
|
|
// Gets the top offset of the page header that is linked to the last toc item
|
|
|
|
|
lastElemOffset = lastElem.offset().top;
|
|
|
|
|
|
|
|
|
|
// Appends a div to the bottom of the page and sets the height to the difference of the window scrollTop and the last element's position top offset
|
|
|
|
|
$(self.options.context).append($("<div/>", {
|
|
|
|
|
|
|
|
|
|
"class": extendPageClassName,
|
|
|
|
|
|
|
|
|
|
"height": Math.abs(lastElemOffset - winScrollTop) + "px",
|
|
|
|
|
|
|
|
|
|
"data-unique": extendPageClassName
|
|
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
if (self.extendPageScroll) {
|
|
|
|
|
|
|
|
|
|
currentElem = self.element.find('li.' + self.focusClass);
|
|
|
|
|
|
|
|
|
|
self._scrollTo($('div[data-unique="' + currentElem.attr("data-unique") + '"]'));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The zero timeout ensures the following code is run after the scroll events
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
|
|
|
|
// _Local variables_
|
|
|
|
|
|
|
|
|
|
// Stores the distance to the closest anchor
|
|
|
|
|
var closestAnchorDistance = null,
|
|
|
|
|
|
|
|
|
|
// Stores the index of the closest anchor
|
|
|
|
|
closestAnchorIdx = null,
|
|
|
|
|
|
|
|
|
|
// Keeps a reference to all anchors
|
|
|
|
|
anchors = $(self.options.context).find("div[data-unique]"),
|
|
|
|
|
|
|
|
|
|
anchorText;
|
|
|
|
|
|
|
|
|
|
// Determines the index of the closest anchor
|
|
|
|
|
anchors.each(function(idx) {
|
|
|
|
|
var distance = Math.abs(($(this).next().length ? $(this).next() : $(this)).offset().top - winScrollTop - self.options.highlightOffset);
|
|
|
|
|
if (closestAnchorDistance == null || distance < closestAnchorDistance) {
|
|
|
|
|
closestAnchorDistance = distance;
|
|
|
|
|
closestAnchorIdx = idx;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
anchorText = $(anchors[closestAnchorIdx]).attr("data-unique");
|
|
|
|
|
|
|
|
|
|
// Stores the list item HTML element that corresponds to the currently traversed anchor tag
|
|
|
|
|
elem = $('li[data-unique="' + anchorText + '"]');
|
|
|
|
|
|
|
|
|
|
// If the `highlightOnScroll` option is true and a next element is found
|
|
|
|
|
if (self.options.highlightOnScroll && elem.length) {
|
|
|
|
|
|
|
|
|
|
// Removes highlighting from all of the list item's
|
|
|
|
|
self.element.find("." + self.focusClass).removeClass(self.focusClass);
|
|
|
|
|
|
|
|
|
|
// Highlights the corresponding list item
|
|
|
|
|
elem.addClass(self.focusClass);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (self.options.scrollHistory) {
|
|
|
|
|
|
|
|
|
|
if (window.location.hash !== "#" + anchorText) {
|
|
|
|
|
|
|
|
|
|
window.location.replace("#" + anchorText);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the `showAndHideOnScroll` option is true
|
|
|
|
|
if (self.options.showAndHideOnScroll && self.options.showAndHide) {
|
|
|
|
|
|
|
|
|
|
self._triggerShow(elem, true);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Show
|
|
|
|
|
// ----
|
|
|
|
|
// Opens the current sub-header
|
|
|
|
|
show: function(elem, scroll) {
|
|
|
|
|
|
|
|
|
|
// Stores the plugin context in the `self` variable
|
|
|
|
|
var self = this,
|
|
|
|
|
element = elem;
|
|
|
|
|
|
|
|
|
|
// If the sub-header is not already visible
|
|
|
|
|
if (!elem.is(":visible")) {
|
|
|
|
|
|
|
|
|
|
// If the current element does not have any nested subheaders, is not a header, and its parent is not visible
|
|
|
|
|
if (!elem.find(subheaderClass).length && !elem.parent().is(headerClass) && !elem.parent().is(":visible")) {
|
|
|
|
|
|
|
|
|
|
// Sets the current element to all of the subheaders within the current header
|
|
|
|
|
elem = elem.parents(subheaderClass).add(elem);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the current element does not have any nested subheaders and is not a header
|
|
|
|
|
else if (!elem.children(subheaderClass).length && !elem.parent().is(headerClass)) {
|
|
|
|
|
|
|
|
|
|
// Sets the current element to the closest subheader
|
|
|
|
|
elem = elem.closest(subheaderClass);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Determines what jQuery effect to use
|
|
|
|
|
switch (self.options.showEffect) {
|
|
|
|
|
|
|
|
|
|
//Uses `no effect`
|
|
|
|
|
case "none":
|
|
|
|
|
|
|
|
|
|
elem.show();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
//Uses the jQuery `show` special effect
|
|
|
|
|
case "show":
|
|
|
|
|
|
|
|
|
|
elem.show(self.options.showEffectSpeed);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
//Uses the jQuery `slideDown` special effect
|
|
|
|
|
case "slideDown":
|
|
|
|
|
|
|
|
|
|
elem.slideDown(self.options.showEffectSpeed);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
//Uses the jQuery `fadeIn` special effect
|
|
|
|
|
case "fadeIn":
|
|
|
|
|
|
|
|
|
|
elem.fadeIn(self.options.showEffectSpeed);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
//If none of the above options were passed, then a `jQueryUI show effect` is expected
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
elem.show();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the current subheader parent element is a header
|
|
|
|
|
if (elem.parent().is(headerClass)) {
|
|
|
|
|
|
|
|
|
|
// Hides all non-active sub-headers
|
|
|
|
|
self.hide($(subheaderClass).not(elem));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the current subheader parent element is not a header
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
// Hides all non-active sub-headers
|
|
|
|
|
self.hide($(subheaderClass).not(elem.closest(headerClass).find(subheaderClass).not(elem.siblings())));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Maintains chainablity
|
|
|
|
|
return self;
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Hide
|
|
|
|
|
// ----
|
|
|
|
|
// Closes the current sub-header
|
|
|
|
|
hide: function(elem) {
|
|
|
|
|
|
|
|
|
|
// Stores the plugin context in the `self` variable
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
//Determines what jQuery effect to use
|
|
|
|
|
switch (self.options.hideEffect) {
|
|
|
|
|
|
|
|
|
|
// Uses `no effect`
|
|
|
|
|
case "none":
|
|
|
|
|
|
|
|
|
|
elem.hide();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// Uses the jQuery `hide` special effect
|
|
|
|
|
case "hide":
|
|
|
|
|
|
|
|
|
|
elem.hide(self.options.hideEffectSpeed);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// Uses the jQuery `slideUp` special effect
|
|
|
|
|
case "slideUp":
|
|
|
|
|
|
|
|
|
|
elem.slideUp(self.options.hideEffectSpeed);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// Uses the jQuery `fadeOut` special effect
|
|
|
|
|
case "fadeOut":
|
|
|
|
|
|
|
|
|
|
elem.fadeOut(self.options.hideEffectSpeed);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// If none of the above options were passed, then a `jqueryUI hide effect` is expected
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
elem.hide();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Maintains chainablity
|
|
|
|
|
return self;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// _triggerShow
|
|
|
|
|
// ------------
|
|
|
|
|
// Determines what elements get shown on scroll and click
|
|
|
|
|
_triggerShow: function(elem, scroll) {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
// If the current element's parent is a header element or the next element is a nested subheader element
|
|
|
|
|
if (elem.parent().is(headerClass) || elem.next().is(subheaderClass)) {
|
|
|
|
|
|
|
|
|
|
// Shows the next sub-header element
|
|
|
|
|
self.show(elem.next(subheaderClass), scroll);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the current element's parent is a subheader element
|
|
|
|
|
else if (elem.parent().is(subheaderClass)) {
|
|
|
|
|
|
|
|
|
|
// Shows the parent sub-header element
|
|
|
|
|
self.show(elem.parent(), scroll);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Maintains chainability
|
|
|
|
|
return self;
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// _addCSSClasses
|
|
|
|
|
// --------------
|
|
|
|
|
// Adds CSS classes to the newly generated table of contents HTML
|
|
|
|
|
_addCSSClasses: function() {
|
|
|
|
|
|
|
|
|
|
// If the user wants a jqueryUI theme
|
|
|
|
|
if (this.options.theme === "jqueryui") {
|
|
|
|
|
|
|
|
|
|
this.focusClass = "ui-state-default";
|
|
|
|
|
|
|
|
|
|
this.hoverClass = "ui-state-hover";
|
|
|
|
|
|
|
|
|
|
//Adds the default styling to the dropdown list
|
|
|
|
|
this.element.addClass("ui-widget").find(".toc-title").addClass("ui-widget-header").end().find("li").addClass("ui-widget-content");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the user wants a twitterBootstrap theme
|
|
|
|
|
else if (this.options.theme === "bootstrap") {
|
|
|
|
|
|
|
|
|
|
this.element.find(headerClass + "," + subheaderClass).addClass("nav nav-list");
|
|
|
|
|
|
|
|
|
|
this.focusClass = "active";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the user wants a twitterBootstrap theme
|
|
|
|
|
else if (this.options.theme === "bootstrap3") {
|
|
|
|
|
|
|
|
|
|
this.element.find(headerClass + "," + subheaderClass).addClass("list-group");
|
|
|
|
|
|
|
|
|
|
this.element.find(itemClass).addClass("list-group-item");
|
|
|
|
|
|
|
|
|
|
this.focusClass = "active";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If a user does not want a prebuilt theme
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
// Adds more neutral classes (instead of jqueryui)
|
|
|
|
|
|
|
|
|
|
this.focusClass = tocFocusClassName;
|
|
|
|
|
|
|
|
|
|
this.hoverClass = tocHoverClassName;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Maintains chainability
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// setOption
|
|
|
|
|
// ---------
|
|
|
|
|
// Sets a single Tocify option after the plugin is invoked
|
|
|
|
|
setOption: function() {
|
|
|
|
|
|
|
|
|
|
// Calls the jQueryUI Widget Factory setOption method
|
|
|
|
|
$.Widget.prototype._setOption.apply(this, arguments);
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// setOptions
|
|
|
|
|
// ----------
|
|
|
|
|
// Sets a single or multiple Tocify options after the plugin is invoked
|
|
|
|
|
setOptions: function() {
|
|
|
|
|
|
|
|
|
|
// Calls the jQueryUI Widget Factory setOptions method
|
|
|
|
|
$.Widget.prototype._setOptions.apply(this, arguments);
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// _scrollTo
|
|
|
|
|
// ---------
|
|
|
|
|
// Scrolls to a specific element
|
|
|
|
|
_scrollTo: function(elem) {
|
|
|
|
|
|
|
|
|
|
var self = this,
|
|
|
|
|
duration = self.options.smoothScroll || 0,
|
|
|
|
|
scrollTo = self.options.scrollTo,
|
|
|
|
|
currentDiv = $('div[data-unique="' + elem.attr("data-unique") + '"]');
|
|
|
|
|
|
|
|
|
|
if (!currentDiv.length) {
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Once all animations on the page are complete, this callback function will be called
|
|
|
|
|
$("html, body").promise().done(function() {
|
|
|
|
|
|
|
|
|
|
// Animates the html and body element scrolltops
|
|
|
|
|
$("html, body").animate({
|
|
|
|
|
|
|
|
|
|
// Sets the jQuery `scrollTop` to the top offset of the HTML div tag that matches the current list item's `data-unique` tag
|
|
|
|
|
"scrollTop": currentDiv.offset().top - ($.isFunction(scrollTo) ? scrollTo.call() : scrollTo) + "px"
|
|
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
|
|
|
|
|
// Sets the smoothScroll animation time duration to the smoothScrollSpeed option
|
|
|
|
|
"duration": duration
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Maintains chainability
|
|
|
|
|
return self;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})); //end of plugin
|
|
|
|
|
</script>
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* jQuery Plugin: Sticky Tabs
|
|
|
|
|
*
|
|
|
|
|
* @author Aidan Lister <aidan@php.net>
|
|
|
|
|
* adapted by Ruben Arslan to activate parent tabs too
|
|
|
|
|
* http://www.aidanlister.com/2014/03/persisting-the-tab-state-in-bootstrap/
|
|
|
|
|
*/
|
|
|
|
|
(function($) {
|
|
|
|
|
"use strict";
|
|
|
|
|
$.fn.rmarkdownStickyTabs = function() {
|
|
|
|
|
var context = this;
|
|
|
|
|
// Show the tab corresponding with the hash in the URL, or the first tab
|
|
|
|
|
var showStuffFromHash = function() {
|
|
|
|
|
var hash = window.location.hash;
|
|
|
|
|
var selector = hash ? 'a[href="' + hash + '"]' : 'li.active > a';
|
|
|
|
|
var $selector = $(selector, context);
|
|
|
|
|
if($selector.data('toggle') === "tab") {
|
|
|
|
|
$selector.tab('show');
|
|
|
|
|
// walk up the ancestors of this element, show any hidden tabs
|
|
|
|
|
$selector.parents('.section.tabset').each(function(i, elm) {
|
|
|
|
|
var link = $('a[href="#' + $(elm).attr('id') + '"]');
|
|
|
|
|
if(link.data('toggle') === "tab") {
|
|
|
|
|
link.tab("show");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set the correct tab when the page loads
|
|
|
|
|
showStuffFromHash(context);
|
|
|
|
|
|
|
|
|
|
// Set the correct tab when a user uses their back/forward button
|
|
|
|
|
$(window).on('hashchange', function() {
|
|
|
|
|
showStuffFromHash(context);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Change the URL when tabs are clicked
|
|
|
|
|
$('a', context).on('click', function(e) {
|
|
|
|
|
history.pushState(null, null, this.href);
|
|
|
|
|
showStuffFromHash(context);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
}(jQuery));
|
|
|
|
|
|
|
|
|
|
window.buildTabsets = function(tocID) {
|
|
|
|
|
|
|
|
|
|
// build a tabset from a section div with the .tabset class
|
|
|
|
|
function buildTabset(tabset) {
|
|
|
|
|
|
|
|
|
|
// check for fade and pills options
|
|
|
|
|
var fade = tabset.hasClass("tabset-fade");
|
|
|
|
|
var pills = tabset.hasClass("tabset-pills");
|
|
|
|
|
var navClass = pills ? "nav-pills" : "nav-tabs";
|
|
|
|
|
|
|
|
|
|
// determine the heading level of the tabset and tabs
|
|
|
|
|
var match = tabset.attr('class').match(/level(\d) /);
|
|
|
|
|
if (match === null)
|
|
|
|
|
return;
|
|
|
|
|
var tabsetLevel = Number(match[1]);
|
|
|
|
|
var tabLevel = tabsetLevel + 1;
|
|
|
|
|
|
|
|
|
|
// find all subheadings immediately below
|
|
|
|
|
var tabs = tabset.find("div.section.level" + tabLevel);
|
|
|
|
|
if (!tabs.length)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// create tablist and tab-content elements
|
|
|
|
|
var tabList = $('<ul class="nav ' + navClass + '" role="tablist"></ul>');
|
|
|
|
|
$(tabs[0]).before(tabList);
|
|
|
|
|
var tabContent = $('<div class="tab-content"></div>');
|
|
|
|
|
$(tabs[0]).before(tabContent);
|
|
|
|
|
|
|
|
|
|
// build the tabset
|
|
|
|
|
var activeTab = 0;
|
|
|
|
|
tabs.each(function(i) {
|
|
|
|
|
|
|
|
|
|
// get the tab div
|
|
|
|
|
var tab = $(tabs[i]);
|
|
|
|
|
|
|
|
|
|
// get the id then sanitize it for use with bootstrap tabs
|
|
|
|
|
var id = tab.attr('id');
|
|
|
|
|
|
|
|
|
|
// see if this is marked as the active tab
|
|
|
|
|
if (tab.hasClass('active'))
|
|
|
|
|
activeTab = i;
|
|
|
|
|
|
|
|
|
|
// remove any table of contents entries associated with
|
|
|
|
|
// this ID (since we'll be removing the heading element)
|
|
|
|
|
$("div#" + tocID + " li a[href='#" + id + "']").parent().remove();
|
|
|
|
|
|
|
|
|
|
// sanitize the id for use with bootstrap tabs
|
|
|
|
|
id = id.replace(/[.\/?&!#<>]/g, '').replace(/\s/g, '_');
|
|
|
|
|
tab.attr('id', id);
|
|
|
|
|
|
|
|
|
|
// get the heading element within it, grab it's text, then remove it
|
|
|
|
|
var heading = tab.find('h' + tabLevel + ':first');
|
|
|
|
|
var headingText = heading.html();
|
|
|
|
|
heading.remove();
|
|
|
|
|
|
|
|
|
|
// build and append the tab list item
|
|
|
|
|
var a = $('<a role="tab" data-toggle="tab">' + headingText + '</a>');
|
|
|
|
|
a.attr('href', '#' + id);
|
|
|
|
|
a.attr('aria-controls', id);
|
|
|
|
|
var li = $('<li role="presentation"></li>');
|
|
|
|
|
li.append(a);
|
|
|
|
|
tabList.append(li);
|
|
|
|
|
|
|
|
|
|
// set it's attributes
|
|
|
|
|
tab.attr('role', 'tabpanel');
|
|
|
|
|
tab.addClass('tab-pane');
|
|
|
|
|
tab.addClass('tabbed-pane');
|
|
|
|
|
if (fade)
|
|
|
|
|
tab.addClass('fade');
|
|
|
|
|
|
|
|
|
|
// move it into the tab content div
|
|
|
|
|
tab.detach().appendTo(tabContent);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// set active tab
|
|
|
|
|
$(tabList.children('li')[activeTab]).addClass('active');
|
|
|
|
|
var active = $(tabContent.children('div.section')[activeTab]);
|
|
|
|
|
active.addClass('active');
|
|
|
|
|
if (fade)
|
|
|
|
|
active.addClass('in');
|
|
|
|
|
|
|
|
|
|
if (tabset.hasClass("tabset-sticky"))
|
|
|
|
|
tabset.rmarkdownStickyTabs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// convert section divs with the .tabset class to tabsets
|
|
|
|
|
var tabsets = $("div.section.tabset");
|
|
|
|
|
tabsets.each(function(i) {
|
|
|
|
|
buildTabset($(tabsets[i]));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
<script>
|
|
|
|
|
window.initializeCodeFolding = function(show) {
|
|
|
|
|
|
|
|
|
|
// handlers for show-all and hide all
|
|
|
|
|
$("#rmd-show-all-code").click(function() {
|
|
|
|
|
$('div.r-code-collapse').each(function() {
|
|
|
|
|
$(this).collapse('show');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
$("#rmd-hide-all-code").click(function() {
|
|
|
|
|
$('div.r-code-collapse').each(function() {
|
|
|
|
|
$(this).collapse('hide');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// index for unique code element ids
|
|
|
|
|
var currentIndex = 1;
|
|
|
|
|
|
|
|
|
|
// select all R code blocks
|
|
|
|
|
var rCodeBlocks = $('pre.r, pre.python, pre.bash, pre.sql, pre.cpp, pre.stan, pre.julia, pre.foldable');
|
|
|
|
|
rCodeBlocks.each(function() {
|
|
|
|
|
// skip if the block has fold-none class
|
|
|
|
|
if ($(this).hasClass('fold-none')) return;
|
|
|
|
|
|
|
|
|
|
// create a collapsable div to wrap the code in
|
|
|
|
|
var div = $('<div class="collapse r-code-collapse"></div>');
|
|
|
|
|
var showThis = (show || $(this).hasClass('fold-show')) && !$(this).hasClass('fold-hide');
|
|
|
|
|
var id = 'rcode-643E0F36' + currentIndex++;
|
|
|
|
|
div.attr('id', id);
|
|
|
|
|
$(this).before(div);
|
|
|
|
|
$(this).detach().appendTo(div);
|
|
|
|
|
|
|
|
|
|
// add a show code button right above
|
|
|
|
|
var showCodeText = $('<span>' + (showThis ? 'Hide' : 'Code') + '</span>');
|
|
|
|
|
var showCodeButton = $('<button type="button" class="btn btn-default btn-xs btn-secondary btn-sm code-folding-btn pull-right float-right"></button>');
|
|
|
|
|
showCodeButton.append(showCodeText);
|
|
|
|
|
showCodeButton
|
|
|
|
|
.attr('data-toggle', 'collapse')
|
|
|
|
|
.attr('data-bs-toggle', 'collapse') // BS5
|
|
|
|
|
.attr('data-target', '#' + id)
|
|
|
|
|
.attr('data-bs-target', '#' + id) // BS5
|
|
|
|
|
.attr('aria-expanded', showThis)
|
|
|
|
|
.attr('aria-controls', id);
|
|
|
|
|
|
|
|
|
|
var buttonRow = $('<div class="row"></div>');
|
|
|
|
|
var buttonCol = $('<div class="col-md-12"></div>');
|
|
|
|
|
|
|
|
|
|
buttonCol.append(showCodeButton);
|
|
|
|
|
buttonRow.append(buttonCol);
|
|
|
|
|
|
|
|
|
|
div.before(buttonRow);
|
|
|
|
|
|
|
|
|
|
// show the div if necessary
|
|
|
|
|
if (showThis) div.collapse('show');
|
|
|
|
|
|
|
|
|
|
// update state of button on show/hide
|
|
|
|
|
// * Change text
|
|
|
|
|
// * add a class for intermediate states styling
|
|
|
|
|
div.on('hide.bs.collapse', function () {
|
|
|
|
|
showCodeText.text('Code');
|
|
|
|
|
showCodeButton.addClass('btn-collapsing');
|
|
|
|
|
});
|
|
|
|
|
div.on('hidden.bs.collapse', function () {
|
|
|
|
|
showCodeButton.removeClass('btn-collapsing');
|
|
|
|
|
});
|
|
|
|
|
div.on('show.bs.collapse', function () {
|
|
|
|
|
showCodeText.text('Hide');
|
|
|
|
|
showCodeButton.addClass('btn-expanding');
|
|
|
|
|
});
|
|
|
|
|
div.on('shown.bs.collapse', function () {
|
|
|
|
|
showCodeButton.removeClass('btn-expanding');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<script>
|
|
|
|
|
window.initializeSourceEmbed = function(filename) {
|
|
|
|
|
$("#rmd-download-source").click(function() {
|
|
|
|
|
var src = $("#rmd-source-code").html();
|
|
|
|
|
var a = document.createElement('a');
|
|
|
|
|
a.href = "data:text/x-r-markdown;base64," + src;
|
|
|
|
|
a.download = filename;
|
|
|
|
|
document.body.appendChild(a);
|
|
|
|
|
a.click();
|
|
|
|
|
document.body.removeChild(a);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<style type="text/css">.pagedtable {
|
|
|
|
|
overflow: auto;
|
|
|
|
|
padding-left: 8px;
|
|
|
|
|
padding-right: 8px;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-wrapper {
|
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable table {
|
|
|
|
|
width: 100%;
|
|
|
|
|
max-width: 100%;
|
|
|
|
|
margin: 0;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable th {
|
|
|
|
|
padding: 0 5px 0 5px;
|
|
|
|
|
border: none;
|
|
|
|
|
border-bottom: 2px solid #dddddd;
|
|
|
|
|
min-width: 45px;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-empty th {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable td {
|
|
|
|
|
padding: 0 4px 0 4px;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable .even {
|
|
|
|
|
background-color: rgba(140, 140, 140, 0.1);
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-padding-col {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable a {
|
|
|
|
|
-webkit-touch-callout: none;
|
|
|
|
|
-webkit-user-select: none;
|
|
|
|
|
-khtml-user-select: none;
|
|
|
|
|
-moz-user-select: none;
|
|
|
|
|
-ms-user-select: none;
|
|
|
|
|
user-select: none;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-index-nav {
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
padding: 0 5px 0 5px;
|
|
|
|
|
float: right;
|
|
|
|
|
border: 0;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-index-nav-disabled {
|
|
|
|
|
cursor: default;
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
color: #999;
|
|
|
|
|
}
|
|
|
|
|
a.pagedtable-index-nav-disabled:hover {
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
color: #999;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-indexes {
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
float: right;
|
|
|
|
|
border: 0;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-index-current {
|
|
|
|
|
cursor: default;
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
color: #333;
|
|
|
|
|
border: 0;
|
|
|
|
|
}
|
|
|
|
|
a.pagedtable-index-current:hover {
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
color: #333;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-index {
|
|
|
|
|
width: 30px;
|
|
|
|
|
display: inline-block;
|
|
|
|
|
text-align: center;
|
|
|
|
|
border: 0;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-index-separator-left {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
color: #333;
|
|
|
|
|
font-size: 9px;
|
|
|
|
|
padding: 0 0 0 0;
|
|
|
|
|
cursor: default;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-index-separator-right {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
color: #333;
|
|
|
|
|
font-size: 9px;
|
|
|
|
|
padding: 0 4px 0 0;
|
|
|
|
|
cursor: default;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-footer {
|
|
|
|
|
padding-top: 4px;
|
|
|
|
|
padding-bottom: 5px;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-not-empty .pagedtable-footer {
|
|
|
|
|
border-top: 2px solid #dddddd;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-info {
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
color: #999;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-header-name {
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-header-type {
|
|
|
|
|
color: #999;
|
|
|
|
|
font-weight: 400;
|
|
|
|
|
}
|
|
|
|
|
.pagedtable-na-cell {
|
|
|
|
|
font-style: italic;
|
|
|
|
|
opacity: 0.3;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
<script>// Production steps of ECMA-262, Edition 5, 15.4.4.18
|
|
|
|
|
// Reference: http://es5.github.io/#x15.4.4.18
|
|
|
|
|
if (!Array.prototype.forEach) {
|
|
|
|
|
|
|
|
|
|
Array.prototype.forEach = function(callback, thisArg) {
|
|
|
|
|
|
|
|
|
|
var T, k;
|
|
|
|
|
|
|
|
|
|
if (this === null) {
|
|
|
|
|
throw new TypeError(' this is null or not defined');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 1. Let O be the result of calling toObject() passing the
|
|
|
|
|
// |this| value as the argument.
|
|
|
|
|
var O = Object(this);
|
|
|
|
|
|
|
|
|
|
// 2. Let lenValue be the result of calling the Get() internal
|
|
|
|
|
// method of O with the argument "length".
|
|
|
|
|
// 3. Let len be toUint32(lenValue).
|
|
|
|
|
var len = O.length >>> 0;
|
|
|
|
|
|
|
|
|
|
// 4. If isCallable(callback) is false, throw a TypeError exception.
|
|
|
|
|
// See: http://es5.github.com/#x9.11
|
|
|
|
|
if (typeof callback !== "function") {
|
|
|
|
|
throw new TypeError(callback + ' is not a function');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 5. If thisArg was supplied, let T be thisArg; else let
|
|
|
|
|
// T be undefined.
|
|
|
|
|
if (arguments.length > 1) {
|
|
|
|
|
T = thisArg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 6. Let k be 0
|
|
|
|
|
k = 0;
|
|
|
|
|
|
|
|
|
|
// 7. Repeat, while k < len
|
|
|
|
|
while (k < len) {
|
|
|
|
|
|
|
|
|
|
var kValue;
|
|
|
|
|
|
|
|
|
|
// a. Let Pk be ToString(k).
|
|
|
|
|
// This is implicit for LHS operands of the in operator
|
|
|
|
|
// b. Let kPresent be the result of calling the HasProperty
|
|
|
|
|
// internal method of O with argument Pk.
|
|
|
|
|
// This step can be combined with c
|
|
|
|
|
// c. If kPresent is true, then
|
|
|
|
|
if (k in O) {
|
|
|
|
|
|
|
|
|
|
// i. Let kValue be the result of calling the Get internal
|
|
|
|
|
// method of O with argument Pk.
|
|
|
|
|
kValue = O[k];
|
|
|
|
|
|
|
|
|
|
// ii. Call the Call internal method of callback with T as
|
|
|
|
|
// the this value and argument list containing kValue, k, and O.
|
|
|
|
|
callback.call(T, kValue, k, O);
|
|
|
|
|
}
|
|
|
|
|
// d. Increase k by 1.
|
|
|
|
|
k++;
|
|
|
|
|
}
|
|
|
|
|
// 8. return undefined
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Production steps of ECMA-262, Edition 5, 15.4.4.19
|
|
|
|
|
// Reference: http://es5.github.io/#x15.4.4.19
|
|
|
|
|
if (!Array.prototype.map) {
|
|
|
|
|
|
|
|
|
|
Array.prototype.map = function(callback, thisArg) {
|
|
|
|
|
|
|
|
|
|
var T, A, k;
|
|
|
|
|
|
|
|
|
|
if (this == null) {
|
|
|
|
|
throw new TypeError(' this is null or not defined');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 1. Let O be the result of calling ToObject passing the |this|
|
|
|
|
|
// value as the argument.
|
|
|
|
|
var O = Object(this);
|
|
|
|
|
|
|
|
|
|
// 2. Let lenValue be the result of calling the Get internal
|
|
|
|
|
// method of O with the argument "length".
|
|
|
|
|
// 3. Let len be ToUint32(lenValue).
|
|
|
|
|
var len = O.length >>> 0;
|
|
|
|
|
|
|
|
|
|
// 4. If IsCallable(callback) is false, throw a TypeError exception.
|
|
|
|
|
// See: http://es5.github.com/#x9.11
|
|
|
|
|
if (typeof callback !== 'function') {
|
|
|
|
|
throw new TypeError(callback + ' is not a function');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
|
|
|
|
if (arguments.length > 1) {
|
|
|
|
|
T = thisArg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 6. Let A be a new array created as if by the expression new Array(len)
|
|
|
|
|
// where Array is the standard built-in constructor with that name and
|
|
|
|
|
// len is the value of len.
|
|
|
|
|
A = new Array(len);
|
|
|
|
|
|
|
|
|
|
// 7. Let k be 0
|
|
|
|
|
k = 0;
|
|
|
|
|
|
|
|
|
|
// 8. Repeat, while k < len
|
|
|
|
|
while (k < len) {
|
|
|
|
|
|
|
|
|
|
var kValue, mappedValue;
|
|
|
|
|
|
|
|
|
|
// a. Let Pk be ToString(k).
|
|
|
|
|
// This is implicit for LHS operands of the in operator
|
|
|
|
|
// b. Let kPresent be the result of calling the HasProperty internal
|
|
|
|
|
// method of O with argument Pk.
|
|
|
|
|
// This step can be combined with c
|
|
|
|
|
// c. If kPresent is true, then
|
|
|
|
|
if (k in O) {
|
|
|
|
|
|
|
|
|
|
// i. Let kValue be the result of calling the Get internal
|
|
|
|
|
// method of O with argument Pk.
|
|
|
|
|
kValue = O[k];
|
|
|
|
|
|
|
|
|
|
// ii. Let mappedValue be the result of calling the Call internal
|
|
|
|
|
// method of callback with T as the this value and argument
|
|
|
|
|
// list containing kValue, k, and O.
|
|
|
|
|
mappedValue = callback.call(T, kValue, k, O);
|
|
|
|
|
|
|
|
|
|
// iii. Call the DefineOwnProperty internal method of A with arguments
|
|
|
|
|
// Pk, Property Descriptor
|
|
|
|
|
// { Value: mappedValue,
|
|
|
|
|
// Writable: true,
|
|
|
|
|
// Enumerable: true,
|
|
|
|
|
// Configurable: true },
|
|
|
|
|
// and false.
|
|
|
|
|
|
|
|
|
|
// In browsers that support Object.defineProperty, use the following:
|
|
|
|
|
// Object.defineProperty(A, k, {
|
|
|
|
|
// value: mappedValue,
|
|
|
|
|
// writable: true,
|
|
|
|
|
// enumerable: true,
|
|
|
|
|
// configurable: true
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// For best browser support, use the following:
|
|
|
|
|
A[k] = mappedValue;
|
|
|
|
|
}
|
|
|
|
|
// d. Increase k by 1.
|
|
|
|
|
k++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 9. return A
|
|
|
|
|
return A;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var PagedTable = function (pagedTable) {
|
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
|
|
var source = function(pagedTable) {
|
|
|
|
|
var sourceElems = [].slice.call(pagedTable.children).filter(function(e) {
|
|
|
|
|
return e.hasAttribute("data-pagedtable-source");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (sourceElems === null || sourceElems.length !== 1) {
|
|
|
|
|
throw("A single data-pagedtable-source was not found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JSON.parse(sourceElems[0].innerHTML);
|
|
|
|
|
}(pagedTable);
|
|
|
|
|
|
|
|
|
|
var options = function(source) {
|
|
|
|
|
var options = typeof(source.options) !== "undefined" &&
|
|
|
|
|
source.options !== null ? source.options : {};
|
|
|
|
|
|
|
|
|
|
var columns = typeof(options.columns) !== "undefined" ? options.columns : {};
|
|
|
|
|
var rows = typeof(options.rows) !== "undefined" ? options.rows : {};
|
|
|
|
|
|
|
|
|
|
var positiveIntOrNull = function(value) {
|
|
|
|
|
return parseInt(value) >= 0 ? parseInt(value) : null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
pages: positiveIntOrNull(options.pages),
|
|
|
|
|
rows: {
|
|
|
|
|
min: positiveIntOrNull(rows.min),
|
|
|
|
|
max: positiveIntOrNull(rows.max),
|
|
|
|
|
total: positiveIntOrNull(rows.total)
|
|
|
|
|
},
|
|
|
|
|
columns: {
|
|
|
|
|
min: positiveIntOrNull(columns.min),
|
|
|
|
|
max: positiveIntOrNull(columns.max),
|
|
|
|
|
total: positiveIntOrNull(columns.total)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}(source);
|
|
|
|
|
|
|
|
|
|
var Measurer = function() {
|
|
|
|
|
|
|
|
|
|
// set some default initial values that will get adjusted in runtime
|
|
|
|
|
me.measures = {
|
|
|
|
|
padding: 12,
|
|
|
|
|
character: 8,
|
|
|
|
|
height: 15,
|
|
|
|
|
defaults: true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.calculate = function(measuresCell) {
|
|
|
|
|
if (!me.measures.defaults)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var measuresCellStyle = window.getComputedStyle(measuresCell, null);
|
|
|
|
|
|
|
|
|
|
var newPadding = parsePadding(measuresCellStyle.paddingLeft) +
|
|
|
|
|
parsePadding(measuresCellStyle.paddingRight);
|
|
|
|
|
|
|
|
|
|
var sampleString = "ABCDEFGHIJ0123456789";
|
|
|
|
|
var newCharacter = Math.ceil(measuresCell.clientWidth / sampleString.length);
|
|
|
|
|
|
|
|
|
|
if (newPadding <= 0 || newCharacter <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
me.measures.padding = newPadding;
|
|
|
|
|
me.measures.character = newCharacter;
|
|
|
|
|
me.measures.height = measuresCell.clientHeight;
|
|
|
|
|
me.measures.defaults = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return me;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var Page = function(data, options) {
|
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
|
|
var defaults = {
|
|
|
|
|
max: 7,
|
|
|
|
|
rows: 10
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var totalPages = function() {
|
|
|
|
|
return Math.ceil(data.length / me.rows);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.number = 0;
|
|
|
|
|
me.max = options.pages !== null ? options.pages : defaults.max;
|
|
|
|
|
me.visible = me.max;
|
|
|
|
|
me.rows = options.rows.min !== null ? options.rows.min : defaults.rows;
|
|
|
|
|
me.total = totalPages();
|
|
|
|
|
|
|
|
|
|
me.setRows = function(newRows) {
|
|
|
|
|
me.rows = newRows;
|
|
|
|
|
me.total = totalPages();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.setPageNumber = function(newPageNumber) {
|
|
|
|
|
if (newPageNumber < 0) newPageNumber = 0;
|
|
|
|
|
if (newPageNumber >= me.total) newPageNumber = me.total - 1;
|
|
|
|
|
|
|
|
|
|
me.number = newPageNumber;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.setVisiblePages = function(visiblePages) {
|
|
|
|
|
me.visible = Math.min(me.max, visiblePages);
|
|
|
|
|
me.setPageNumber(me.number);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.getVisiblePageRange = function() {
|
|
|
|
|
var start = me.number - Math.max(Math.floor((me.visible - 1) / 2), 0);
|
|
|
|
|
var end = me.number + Math.floor(me.visible / 2) + 1;
|
|
|
|
|
var pageCount = me.total;
|
|
|
|
|
|
|
|
|
|
if (start < 0) {
|
|
|
|
|
var diffToStart = 0 - start;
|
|
|
|
|
start += diffToStart;
|
|
|
|
|
end += diffToStart;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (end > pageCount) {
|
|
|
|
|
var diffToEnd = end - pageCount;
|
|
|
|
|
start -= diffToEnd;
|
|
|
|
|
end -= diffToEnd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start = start < 0 ? 0 : start;
|
|
|
|
|
end = end >= pageCount ? pageCount : end;
|
|
|
|
|
|
|
|
|
|
var first = false;
|
|
|
|
|
var last = false;
|
|
|
|
|
|
|
|
|
|
if (start > 0 && me.visible > 1) {
|
|
|
|
|
start = start + 1;
|
|
|
|
|
first = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (end < pageCount && me.visible > 2) {
|
|
|
|
|
end = end - 1;
|
|
|
|
|
last = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
first: first,
|
|
|
|
|
start: start,
|
|
|
|
|
end: end,
|
|
|
|
|
last: last
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.getRowStart = function() {
|
|
|
|
|
var rowStart = page.number * page.rows;
|
|
|
|
|
if (rowStart < 0)
|
|
|
|
|
rowStart = 0;
|
|
|
|
|
|
|
|
|
|
return rowStart;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.getRowEnd = function() {
|
|
|
|
|
var rowStart = me.getRowStart();
|
|
|
|
|
return Math.min(rowStart + me.rows, data.length);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.getPaddingRows = function() {
|
|
|
|
|
var rowStart = me.getRowStart();
|
|
|
|
|
var rowEnd = me.getRowEnd();
|
|
|
|
|
return data.length > me.rows ? me.rows - (rowEnd - rowStart) : 0;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var Columns = function(data, columns, options) {
|
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
|
|
me.defaults = {
|
|
|
|
|
min: 5
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.number = 0;
|
|
|
|
|
me.visible = 0;
|
|
|
|
|
me.total = columns.length;
|
|
|
|
|
me.subset = [];
|
|
|
|
|
me.padding = 0;
|
|
|
|
|
me.min = options.columns.min !== null ? options.columns.min : me.defaults.min;
|
|
|
|
|
me.max = options.columns.max !== null ? options.columns.max : null;
|
|
|
|
|
me.widths = {};
|
|
|
|
|
|
|
|
|
|
var widthsLookAhead = Math.max(100, options.rows.min);
|
|
|
|
|
var paddingColChars = 10;
|
|
|
|
|
|
|
|
|
|
me.emptyNames = function() {
|
|
|
|
|
columns.forEach(function(column) {
|
|
|
|
|
if (columns.label !== null && columns.label !== "")
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var parsePadding = function(value) {
|
|
|
|
|
return parseInt(value) >= 0 ? parseInt(value) : 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.calculateWidths = function(measures) {
|
|
|
|
|
columns.forEach(function(column) {
|
|
|
|
|
var maxChars = Math.max(
|
|
|
|
|
column.label.toString().length,
|
|
|
|
|
column.type.toString().length
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
for (var idxRow = 0; idxRow < Math.min(widthsLookAhead, data.length); idxRow++) {
|
|
|
|
|
maxChars = Math.max(maxChars, data[idxRow][column.name.toString()].length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
me.widths[column.name] = {
|
|
|
|
|
// width in characters
|
|
|
|
|
chars: maxChars,
|
|
|
|
|
// width for the inner html columns
|
|
|
|
|
inner: maxChars * measures.character,
|
|
|
|
|
// width adding outer styles like padding
|
|
|
|
|
outer: maxChars * measures.character + measures.padding
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.getWidth = function() {
|
|
|
|
|
var widthOuter = 0;
|
|
|
|
|
for (var idxCol = 0; idxCol < me.subset.length; idxCol++) {
|
|
|
|
|
var columnName = me.subset[idxCol].name;
|
|
|
|
|
widthOuter = widthOuter + me.widths[columnName].outer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widthOuter = widthOuter + me.padding * paddingColChars * measurer.measures.character;
|
|
|
|
|
|
|
|
|
|
if (me.hasMoreLeftColumns()) {
|
|
|
|
|
widthOuter = widthOuter + columnNavigationWidthPX + measurer.measures.padding;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (me.hasMoreRightColumns()) {
|
|
|
|
|
widthOuter = widthOuter + columnNavigationWidthPX + measurer.measures.padding;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return widthOuter;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.updateSlice = function() {
|
|
|
|
|
if (me.number + me.visible >= me.total)
|
|
|
|
|
me.number = me.total - me.visible;
|
|
|
|
|
|
|
|
|
|
if (me.number < 0) me.number = 0;
|
|
|
|
|
|
|
|
|
|
me.subset = columns.slice(me.number, Math.min(me.number + me.visible, me.total));
|
|
|
|
|
|
|
|
|
|
me.subset = me.subset.map(function(column) {
|
|
|
|
|
Object.keys(column).forEach(function(colKey) {
|
|
|
|
|
column[colKey] = column[colKey] === null ? "" : column[colKey].toString();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
column.width = null;
|
|
|
|
|
return column;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.setVisibleColumns = function(columnNumber, newVisibleColumns, paddingCount) {
|
|
|
|
|
me.number = columnNumber;
|
|
|
|
|
me.visible = newVisibleColumns;
|
|
|
|
|
me.padding = paddingCount;
|
|
|
|
|
|
|
|
|
|
me.updateSlice();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.incColumnNumber = function(increment) {
|
|
|
|
|
me.number = me.number + increment;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.setColumnNumber = function(newNumber) {
|
|
|
|
|
me.number = newNumber;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.setPaddingCount = function(newPadding) {
|
|
|
|
|
me.padding = newPadding;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.getPaddingCount = function() {
|
|
|
|
|
return me.padding;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.hasMoreLeftColumns = function() {
|
|
|
|
|
return me.number > 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.hasMoreRightColumns = function() {
|
|
|
|
|
return me.number + me.visible < me.total;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.updateSlice(0);
|
|
|
|
|
return me;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var data = source.data;
|
|
|
|
|
var page = new Page(data, options);
|
|
|
|
|
var measurer = new Measurer(data, options);
|
|
|
|
|
var columns = new Columns(data, source.columns, options);
|
|
|
|
|
|
|
|
|
|
var table = null;
|
|
|
|
|
var tableDiv = null;
|
|
|
|
|
var header = null;
|
|
|
|
|
var footer = null;
|
|
|
|
|
var tbody = null;
|
|
|
|
|
|
|
|
|
|
// Caches pagedTable.clientWidth, specially for webkit
|
|
|
|
|
var cachedPagedTableClientWidth = null;
|
|
|
|
|
|
|
|
|
|
var onChangeCallbacks = [];
|
|
|
|
|
|
|
|
|
|
var clearSelection = function() {
|
|
|
|
|
if(document.selection && document.selection.empty) {
|
|
|
|
|
document.selection.empty();
|
|
|
|
|
} else if(window.getSelection) {
|
|
|
|
|
var sel = window.getSelection();
|
|
|
|
|
sel.removeAllRanges();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var columnNavigationWidthPX = 5;
|
|
|
|
|
|
|
|
|
|
var renderColumnNavigation = function(increment, backwards) {
|
|
|
|
|
var arrow = document.createElement("div");
|
|
|
|
|
arrow.setAttribute("style",
|
|
|
|
|
"border-top: " + columnNavigationWidthPX + "px solid transparent;" +
|
|
|
|
|
"border-bottom: " + columnNavigationWidthPX + "px solid transparent;" +
|
|
|
|
|
"border-" + (backwards ? "right" : "left") + ": " + columnNavigationWidthPX + "px solid;");
|
|
|
|
|
|
|
|
|
|
var header = document.createElement("th");
|
|
|
|
|
header.appendChild(arrow);
|
|
|
|
|
header.setAttribute("style",
|
|
|
|
|
"cursor: pointer;" +
|
|
|
|
|
"vertical-align: middle;" +
|
|
|
|
|
"min-width: " + columnNavigationWidthPX + "px;" +
|
|
|
|
|
"width: " + columnNavigationWidthPX + "px;");
|
|
|
|
|
|
|
|
|
|
header.onclick = function() {
|
|
|
|
|
columns.incColumnNumber(backwards ? -1 : increment);
|
|
|
|
|
|
|
|
|
|
me.animateColumns(backwards);
|
|
|
|
|
renderFooter();
|
|
|
|
|
|
|
|
|
|
clearSelection();
|
|
|
|
|
triggerOnChange();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return header;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var maxColumnWidth = function(width) {
|
|
|
|
|
var padding = 80;
|
|
|
|
|
var columnMax = Math.max(cachedPagedTableClientWidth - padding, 0);
|
|
|
|
|
|
|
|
|
|
return parseInt(width) > 0 ?
|
|
|
|
|
Math.min(columnMax, parseInt(width)) + "px" :
|
|
|
|
|
columnMax + "px";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var clearHeader = function() {
|
|
|
|
|
var thead = pagedTable.querySelectorAll("thead")[0];
|
|
|
|
|
thead.innerHTML = "";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var renderHeader = function(clear) {
|
|
|
|
|
cachedPagedTableClientWidth = pagedTable.clientWidth;
|
|
|
|
|
|
|
|
|
|
var fragment = document.createDocumentFragment();
|
|
|
|
|
|
|
|
|
|
header = document.createElement("tr");
|
|
|
|
|
fragment.appendChild(header);
|
|
|
|
|
|
|
|
|
|
if (columns.number > 0)
|
|
|
|
|
header.appendChild(renderColumnNavigation(-columns.visible, true));
|
|
|
|
|
|
|
|
|
|
columns.subset = columns.subset.map(function(columnData) {
|
|
|
|
|
var column = document.createElement("th");
|
|
|
|
|
column.setAttribute("align", columnData.align);
|
|
|
|
|
column.style.textAlign = columnData.align;
|
|
|
|
|
|
|
|
|
|
column.style.maxWidth = maxColumnWidth(null);
|
|
|
|
|
if (columnData.width) {
|
|
|
|
|
column.style.minWidth =
|
|
|
|
|
column.style.maxWidth = maxColumnWidth(columnData.width);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var columnName = document.createElement("div");
|
|
|
|
|
columnName.setAttribute("class", "pagedtable-header-name");
|
|
|
|
|
if (columnData.label === "") {
|
|
|
|
|
columnName.innerHTML = " ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
columnName.appendChild(document.createTextNode(columnData.label));
|
|
|
|
|
}
|
|
|
|
|
column.appendChild(columnName);
|
|
|
|
|
|
|
|
|
|
var columnType = document.createElement("div");
|
|
|
|
|
columnType.setAttribute("class", "pagedtable-header-type");
|
|
|
|
|
if (columnData.type === "") {
|
|
|
|
|
columnType.innerHTML = " ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
columnType.appendChild(document.createTextNode("<" + columnData.type + ">"));
|
|
|
|
|
}
|
|
|
|
|
column.appendChild(columnType);
|
|
|
|
|
|
|
|
|
|
header.appendChild(column);
|
|
|
|
|
|
|
|
|
|
columnData.element = column;
|
|
|
|
|
|
|
|
|
|
return columnData;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (var idx = 0; idx < columns.getPaddingCount(); idx++) {
|
|
|
|
|
var paddingCol = document.createElement("th");
|
|
|
|
|
paddingCol.setAttribute("class", "pagedtable-padding-col");
|
|
|
|
|
header.appendChild(paddingCol);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (columns.number + columns.visible < columns.total)
|
|
|
|
|
header.appendChild(renderColumnNavigation(columns.visible, false));
|
|
|
|
|
|
|
|
|
|
if (typeof(clear) == "undefined" || clear) clearHeader();
|
|
|
|
|
var thead = pagedTable.querySelectorAll("thead")[0];
|
|
|
|
|
thead.appendChild(fragment);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.animateColumns = function(backwards) {
|
|
|
|
|
var thead = pagedTable.querySelectorAll("thead")[0];
|
|
|
|
|
|
|
|
|
|
var headerOld = thead.querySelectorAll("tr")[0];
|
|
|
|
|
var tbodyOld = table.querySelectorAll("tbody")[0];
|
|
|
|
|
|
|
|
|
|
me.fitColumns(backwards);
|
|
|
|
|
|
|
|
|
|
renderHeader(false);
|
|
|
|
|
|
|
|
|
|
header.style.opacity = "0";
|
|
|
|
|
header.style.transform = backwards ? "translateX(-30px)" : "translateX(30px)";
|
|
|
|
|
header.style.transition = "transform 200ms linear, opacity 200ms";
|
|
|
|
|
header.style.transitionDelay = "0";
|
|
|
|
|
|
|
|
|
|
renderBody(false);
|
|
|
|
|
|
|
|
|
|
if (headerOld) {
|
|
|
|
|
headerOld.style.position = "absolute";
|
|
|
|
|
headerOld.style.transform = "translateX(0px)";
|
|
|
|
|
headerOld.style.opacity = "1";
|
|
|
|
|
headerOld.style.transition = "transform 100ms linear, opacity 100ms";
|
|
|
|
|
headerOld.setAttribute("class", "pagedtable-remove-head");
|
|
|
|
|
if (headerOld.style.transitionEnd) {
|
|
|
|
|
headerOld.addEventListener("transitionend", function() {
|
|
|
|
|
var headerOldByClass = thead.querySelector(".pagedtable-remove-head");
|
|
|
|
|
if (headerOldByClass) thead.removeChild(headerOldByClass);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
thead.removeChild(headerOld);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tbodyOld) table.removeChild(tbodyOld);
|
|
|
|
|
|
|
|
|
|
tbody.style.opacity = "0";
|
|
|
|
|
tbody.style.transition = "transform 200ms linear, opacity 200ms";
|
|
|
|
|
tbody.style.transitionDelay = "0ms";
|
|
|
|
|
|
|
|
|
|
// force relayout
|
|
|
|
|
window.getComputedStyle(header).opacity;
|
|
|
|
|
window.getComputedStyle(tbody).opacity;
|
|
|
|
|
|
|
|
|
|
if (headerOld) {
|
|
|
|
|
headerOld.style.transform = backwards ? "translateX(20px)" : "translateX(-30px)";
|
|
|
|
|
headerOld.style.opacity = "0";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
header.style.transform = "translateX(0px)";
|
|
|
|
|
header.style.opacity = "1";
|
|
|
|
|
|
|
|
|
|
tbody.style.opacity = "1";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
me.onChange = function(callback) {
|
|
|
|
|
onChangeCallbacks.push(callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var triggerOnChange = function() {
|
|
|
|
|
onChangeCallbacks.forEach(function(onChange) {
|
|
|
|
|
onChange();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var clearBody = function() {
|
|
|
|
|
if (tbody) {
|
|
|
|
|
table.removeChild(tbody);
|
|
|
|
|
tbody = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var renderBody = function(clear) {
|
|
|
|
|
cachedPagedTableClientWidth = pagedTable.clientWidth
|
|
|
|
|
|
|
|
|
|
var fragment = document.createDocumentFragment();
|
|
|
|
|
|
|
|
|
|
var pageData = data.slice(page.getRowStart(), page.getRowEnd());
|
|
|
|
|
|
|
|
|
|
pageData.forEach(function(dataRow, idxRow) {
|
|
|
|
|
var htmlRow = document.createElement("tr");
|
|
|
|
|
htmlRow.setAttribute("class", (idxRow % 2 !==0) ? "even" : "odd");
|
|
|
|
|
|
|
|
|
|
if (columns.hasMoreLeftColumns())
|
|
|
|
|
htmlRow.appendChild(document.createElement("td"));
|
|
|
|
|
|
|
|
|
|
columns.subset.forEach(function(columnData) {
|
|
|
|
|
var cellName = columnData.name;
|
|
|
|
|
var dataCell = dataRow[cellName];
|
|
|
|
|
var htmlCell = document.createElement("td");
|
|
|
|
|
|
|
|
|
|
if (dataCell === "NA") htmlCell.setAttribute("class", "pagedtable-na-cell");
|
|
|
|
|
if (dataCell === "__NA__") dataCell = "NA";
|
|
|
|
|
|
|
|
|
|
var cellText = document.createTextNode(dataCell);
|
|
|
|
|
htmlCell.appendChild(cellText);
|
|
|
|
|
if (dataCell.length > 50) {
|
|
|
|
|
htmlCell.setAttribute("title", dataCell);
|
|
|
|
|
}
|
|
|
|
|
htmlCell.setAttribute("align", columnData.align);
|
|
|
|
|
htmlCell.style.textAlign = columnData.align;
|
|
|
|
|
htmlCell.style.maxWidth = maxColumnWidth(null);
|
|
|
|
|
if (columnData.width) {
|
|
|
|
|
htmlCell.style.minWidth = htmlCell.style.maxWidth = maxColumnWidth(columnData.width);
|
|
|
|
|
}
|
|
|
|
|
htmlRow.appendChild(htmlCell);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (var idx = 0; idx < columns.getPaddingCount(); idx++) {
|
|
|
|
|
var paddingCol = document.createElement("td");
|
|
|
|
|
paddingCol.setAttribute("class", "pagedtable-padding-col");
|
|
|
|
|
htmlRow.appendChild(paddingCol);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (columns.hasMoreRightColumns())
|
|
|
|
|
htmlRow.appendChild(document.createElement("td"));
|
|
|
|
|
|
|
|
|
|
fragment.appendChild(htmlRow);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (var idxPadding = 0; idxPadding < page.getPaddingRows(); idxPadding++) {
|
|
|
|
|
var paddingRow = document.createElement("tr");
|
|
|
|
|
|
|
|
|
|
var paddingCellRow = document.createElement("td");
|
|
|
|
|
paddingCellRow.innerHTML = " ";
|
|
|
|
|
paddingCellRow.setAttribute("colspan", "100%");
|
|
|
|
|
paddingRow.appendChild(paddingCellRow);
|
|
|
|
|
|
|
|
|
|
fragment.appendChild(paddingRow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof(clear) == "undefined" || clear) clearBody();
|
|
|
|
|
tbody = document.createElement("tbody");
|
|
|
|
|
tbody.appendChild(fragment);
|
|
|
|
|
|
|
|
|
|
table.appendChild(tbody);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var getLabelInfo = function() {
|
|
|
|
|
var pageStart = page.getRowStart();
|
|
|
|
|
var pageEnd = page.getRowEnd();
|
|
|
|
|
var totalRows = data.length;
|
|
|
|
|
|
|
|
|
|
var totalRowsLabel = options.rows.total ? options.rows.total : totalRows;
|
|
|
|
|
var totalRowsLabelFormat = totalRowsLabel.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,');
|
|
|
|
|
|
|
|
|
|
var infoText = (pageStart + 1) + "-" + pageEnd + " of " + totalRowsLabelFormat + " rows";
|
|
|
|
|
if (totalRows < page.rows) {
|
|
|
|
|
infoText = totalRowsLabel + " row" + (totalRows != 1 ? "s" : "");
|
|
|
|
|
}
|
|
|
|
|
if (columns.total > columns.visible) {
|
|
|
|
|
var totalColumnsLabel = options.columns.total ? options.columns.total : columns.total;
|
|
|
|
|
|
|
|
|
|
infoText = infoText + " | " + (columns.number + 1) + "-" +
|
|
|
|
|
(Math.min(columns.number + columns.visible, columns.total)) +
|
|
|
|
|
" of " + totalColumnsLabel + " columns";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return infoText;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var clearFooter = function() {
|
|
|
|
|
footer = pagedTable.querySelectorAll("div.pagedtable-footer")[0];
|
|
|
|
|
footer.innerHTML = "";
|
|
|
|
|
|
|
|
|
|
return footer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var createPageLink = function(idxPage) {
|
|
|
|
|
var pageLink = document.createElement("a");
|
|
|
|
|
pageLinkClass = idxPage === page.number ? "pagedtable-index pagedtable-index-current" : "pagedtable-index";
|
|
|
|
|
pageLink.setAttribute("class", pageLinkClass);
|
|
|
|
|
pageLink.setAttribute("data-page-index", idxPage);
|
|
|
|
|
pageLink.onclick = function() {
|
|
|
|
|
page.setPageNumber(parseInt(this.getAttribute("data-page-index")));
|
|
|
|
|
renderBody();
|
|
|
|
|
renderFooter();
|
|
|
|
|
|
|
|
|
|
triggerOnChange();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pageLink.appendChild(document.createTextNode(idxPage + 1));
|
|
|
|
|
|
|
|
|
|
return pageLink;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var renderFooter = function() {
|
|
|
|
|
footer = clearFooter();
|
|
|
|
|
|
|
|
|
|
var next = document.createElement("a");
|
|
|
|
|
next.appendChild(document.createTextNode("Next"));
|
|
|
|
|
next.onclick = function() {
|
|
|
|
|
page.setPageNumber(page.number + 1);
|
|
|
|
|
renderBody();
|
|
|
|
|
renderFooter();
|
|
|
|
|
|
|
|
|
|
triggerOnChange();
|
|
|
|
|
};
|
|
|
|
|
if (data.length > page.rows) footer.appendChild(next);
|
|
|
|
|
|
|
|
|
|
var pageNumbers = document.createElement("div");
|
|
|
|
|
pageNumbers.setAttribute("class", "pagedtable-indexes");
|
|
|
|
|
|
|
|
|
|
var pageRange = page.getVisiblePageRange();
|
|
|
|
|
|
|
|
|
|
if (pageRange.first) {
|
|
|
|
|
var pageLink = createPageLink(0);
|
|
|
|
|
pageNumbers.appendChild(pageLink);
|
|
|
|
|
|
|
|
|
|
var pageSeparator = document.createElement("div");
|
|
|
|
|
pageSeparator.setAttribute("class", "pagedtable-index-separator-left");
|
|
|
|
|
pageSeparator.appendChild(document.createTextNode("..."))
|
|
|
|
|
pageNumbers.appendChild(pageSeparator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var idxPage = pageRange.start; idxPage < pageRange.end; idxPage++) {
|
|
|
|
|
var pageLink = createPageLink(idxPage);
|
|
|
|
|
|
|
|
|
|
pageNumbers.appendChild(pageLink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pageRange.last) {
|
|
|
|
|
var pageSeparator = document.createElement("div");
|
|
|
|
|
pageSeparator.setAttribute("class", "pagedtable-index-separator-right");
|
|
|
|
|
pageSeparator.appendChild(document.createTextNode("..."))
|
|
|
|
|
pageNumbers.appendChild(pageSeparator);
|
|
|
|
|
|
|
|
|
|
var pageLink = createPageLink(page.total - 1);
|
|
|
|
|
pageNumbers.appendChild(pageLink);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.length > page.rows) footer.appendChild(pageNumbers);
|
|
|
|
|
|
|
|
|
|
var previous = document.createElement("a");
|
|
|
|
|
previous.appendChild(document.createTextNode("Previous"));
|
|
|
|
|
previous.onclick = function() {
|
|
|
|
|
page.setPageNumber(page.number - 1);
|
|
|
|
|
renderBody();
|
|
|
|
|
renderFooter();
|
|
|
|
|
|
|
|
|
|
triggerOnChange();
|
|
|
|
|
};
|
|
|
|
|
if (data.length > page.rows) footer.appendChild(previous);
|
|
|
|
|
|
|
|
|
|
var infoLabel = document.createElement("div");
|
|
|
|
|
infoLabel.setAttribute("class", "pagedtable-info");
|
|
|
|
|
infoLabel.setAttribute("title", getLabelInfo());
|
|
|
|
|
infoLabel.appendChild(document.createTextNode(getLabelInfo()));
|
|
|
|
|
footer.appendChild(infoLabel);
|
|
|
|
|
|
|
|
|
|
var enabledClass = "pagedtable-index-nav";
|
|
|
|
|
var disabledClass = "pagedtable-index-nav pagedtable-index-nav-disabled";
|
|
|
|
|
previous.setAttribute("class", page.number <= 0 ? disabledClass : enabledClass);
|
|
|
|
|
next.setAttribute("class", (page.number + 1) * page.rows >= data.length ? disabledClass : enabledClass);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var measuresCell = null;
|
|
|
|
|
|
|
|
|
|
var renderMeasures = function() {
|
|
|
|
|
var measuresTable = document.createElement("table");
|
|
|
|
|
measuresTable.style.visibility = "hidden";
|
|
|
|
|
measuresTable.style.position = "absolute";
|
|
|
|
|
measuresTable.style.whiteSpace = "nowrap";
|
|
|
|
|
measuresTable.style.height = "auto";
|
|
|
|
|
measuresTable.style.width = "auto";
|
|
|
|
|
|
|
|
|
|
var measuresRow = document.createElement("tr");
|
|
|
|
|
measuresTable.appendChild(measuresRow);
|
|
|
|
|
|
|
|
|
|
measuresCell = document.createElement("td");
|
|
|
|
|
var sampleString = "ABCDEFGHIJ0123456789";
|
|
|
|
|
measuresCell.appendChild(document.createTextNode(sampleString));
|
|
|
|
|
|
|
|
|
|
measuresRow.appendChild(measuresCell);
|
|
|
|
|
|
|
|
|
|
tableDiv.appendChild(measuresTable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
me.init = function() {
|
|
|
|
|
tableDiv = document.createElement("div");
|
|
|
|
|
pagedTable.appendChild(tableDiv);
|
|
|
|
|
var pagedTableClass = data.length > 0 ?
|
|
|
|
|
"pagedtable pagedtable-not-empty" :
|
|
|
|
|
"pagedtable pagedtable-empty";
|
|
|
|
|
|
|
|
|
|
if (columns.total == 0 || (columns.emptyNames() && data.length == 0)) {
|
|
|
|
|
pagedTableClass = pagedTableClass + " pagedtable-empty-columns";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tableDiv.setAttribute("class", pagedTableClass);
|
|
|
|
|
|
|
|
|
|
renderMeasures();
|
|
|
|
|
measurer.calculate(measuresCell);
|
|
|
|
|
columns.calculateWidths(measurer.measures);
|
|
|
|
|
|
|
|
|
|
table = document.createElement("table");
|
|
|
|
|
table.setAttribute("cellspacing", "0");
|
|
|
|
|
table.setAttribute("class", "table table-condensed");
|
|
|
|
|
tableDiv.appendChild(table);
|
|
|
|
|
|
|
|
|
|
table.appendChild(document.createElement("thead"));
|
|
|
|
|
|
|
|
|
|
var footerDiv = document.createElement("div");
|
|
|
|
|
footerDiv.setAttribute("class", "pagedtable-footer");
|
|
|
|
|
tableDiv.appendChild(footerDiv);
|
|
|
|
|
|
|
|
|
|
// if the host has not yet provided horizontal space, render hidden
|
|
|
|
|
if (tableDiv.clientWidth <= 0) {
|
|
|
|
|
tableDiv.style.opacity = "0";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
me.render();
|
|
|
|
|
|
|
|
|
|
// retry seizing columns later if the host has not provided space
|
|
|
|
|
function retryFit() {
|
|
|
|
|
if (tableDiv.clientWidth <= 0) {
|
|
|
|
|
setTimeout(retryFit, 100);
|
|
|
|
|
} else {
|
|
|
|
|
me.render();
|
|
|
|
|
triggerOnChange();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (tableDiv.clientWidth <= 0) {
|
|
|
|
|
retryFit();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var registerWidths = function() {
|
|
|
|
|
columns.subset = columns.subset.map(function(column) {
|
|
|
|
|
column.width = columns.widths[column.name].inner;
|
|
|
|
|
return column;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var parsePadding = function(value) {
|
|
|
|
|
return parseInt(value) >= 0 ? parseInt(value) : 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.fixedHeight = function() {
|
|
|
|
|
return options.rows.max != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
me.fitRows = function() {
|
|
|
|
|
if (me.fixedHeight())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
measurer.calculate(measuresCell);
|
|
|
|
|
|
|
|
|
|
var rows = options.rows.min !== null ? options.rows.min : 0;
|
|
|
|
|
var headerHeight = header !== null && header.offsetHeight > 0 ? header.offsetHeight : 0;
|
|
|
|
|
var footerHeight = footer !== null && footer.offsetHeight > 0 ? footer.offsetHeight : 0;
|
|
|
|
|
|
|
|
|
|
if (pagedTable.offsetHeight > 0) {
|
|
|
|
|
var availableHeight = pagedTable.offsetHeight - headerHeight - footerHeight;
|
|
|
|
|
rows = Math.floor((availableHeight) / measurer.measures.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rows = options.rows.min !== null ? Math.max(options.rows.min, rows) : rows;
|
|
|
|
|
|
|
|
|
|
page.setRows(rows);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The goal of this function is to add as many columns as possible
|
|
|
|
|
// starting from left-to-right, when the right most limit is reached
|
|
|
|
|
// it tries to add columns from the left as well.
|
|
|
|
|
//
|
|
|
|
|
// When startBackwards is true columns are added from right-to-left
|
|
|
|
|
me.fitColumns = function(startBackwards) {
|
|
|
|
|
measurer.calculate(measuresCell);
|
|
|
|
|
columns.calculateWidths(measurer.measures);
|
|
|
|
|
|
|
|
|
|
if (tableDiv.clientWidth > 0) {
|
|
|
|
|
tableDiv.style.opacity = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var visibleColumns = tableDiv.clientWidth <= 0 ? Math.max(columns.min, 1) : 1;
|
|
|
|
|
var columnNumber = columns.number;
|
|
|
|
|
var paddingCount = 0;
|
|
|
|
|
|
|
|
|
|
// track a list of added columns as we build the visible ones to allow us
|
|
|
|
|
// to remove columns when they don't fit anymore.
|
|
|
|
|
var columnHistory = [];
|
|
|
|
|
|
|
|
|
|
var lastTableHeight = 0;
|
|
|
|
|
var backwards = startBackwards;
|
|
|
|
|
|
|
|
|
|
var tableDivStyle = window.getComputedStyle(tableDiv, null);
|
|
|
|
|
var tableDivPadding = parsePadding(tableDivStyle.paddingLeft) +
|
|
|
|
|
parsePadding(tableDivStyle.paddingRight);
|
|
|
|
|
|
|
|
|
|
var addPaddingCol = false;
|
|
|
|
|
var currentWidth = 0;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
columns.setVisibleColumns(columnNumber, visibleColumns, paddingCount);
|
|
|
|
|
currentWidth = columns.getWidth();
|
|
|
|
|
|
|
|
|
|
if (tableDiv.clientWidth - tableDivPadding < currentWidth) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
columnHistory.push({
|
|
|
|
|
columnNumber: columnNumber,
|
|
|
|
|
visibleColumns: visibleColumns,
|
|
|
|
|
paddingCount: paddingCount
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (columnHistory.length > 100) {
|
|
|
|
|
console.error("More than 100 tries to fit columns, aborting");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (columns.max !== null &&
|
|
|
|
|
columns.visible + columns.getPaddingCount() >= columns.max) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we run out of right-columns
|
|
|
|
|
if (!backwards && columnNumber + columns.visible >= columns.total) {
|
|
|
|
|
// if we started adding right-columns, try adding left-columns
|
|
|
|
|
if (!startBackwards && columnNumber > 0) {
|
|
|
|
|
backwards = true;
|
|
|
|
|
}
|
|
|
|
|
else if (columns.min === null || visibleColumns + columns.getPaddingCount() >= columns.min) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
paddingCount = paddingCount + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we run out of left-columns
|
|
|
|
|
if (backwards && columnNumber == 0) {
|
|
|
|
|
// if we started adding left-columns, try adding right-columns
|
|
|
|
|
if (startBackwards && columnNumber + columns.visible < columns.total) {
|
|
|
|
|
backwards = false;
|
|
|
|
|
}
|
|
|
|
|
else if (columns.min === null || visibleColumns + columns.getPaddingCount() >= columns.min) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
paddingCount = paddingCount + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// when moving backwards try fitting left columns first
|
|
|
|
|
if (backwards && columnNumber > 0) {
|
|
|
|
|
columnNumber = columnNumber - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (columnNumber + visibleColumns < columns.total) {
|
|
|
|
|
visibleColumns = visibleColumns + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var lastRenderableColumn = {
|
|
|
|
|
columnNumber: columnNumber,
|
|
|
|
|
visibleColumns: visibleColumns,
|
|
|
|
|
paddingCount: paddingCount
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (columnHistory.length > 0) {
|
|
|
|
|
lastRenderableColumn = columnHistory[columnHistory.length - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
columns.setVisibleColumns(
|
|
|
|
|
lastRenderableColumn.columnNumber,
|
|
|
|
|
lastRenderableColumn.visibleColumns,
|
|
|
|
|
lastRenderableColumn.paddingCount);
|
|
|
|
|
|
|
|
|
|
if (pagedTable.offsetWidth > 0) {
|
|
|
|
|
page.setVisiblePages(Math.max(Math.ceil(1.0 * (pagedTable.offsetWidth - 250) / 40), 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
registerWidths();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
me.fit = function(startBackwards) {
|
|
|
|
|
me.fitRows();
|
|
|
|
|
me.fitColumns(startBackwards);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
me.render = function() {
|
|
|
|
|
me.fitColumns(false);
|
|
|
|
|
|
|
|
|
|
// render header/footer to measure height accurately
|
|
|
|
|
renderHeader();
|
|
|
|
|
renderFooter();
|
|
|
|
|
|
|
|
|
|
me.fitRows();
|
|
|
|
|
renderBody();
|
|
|
|
|
|
|
|
|
|
// re-render footer to match new rows
|
|
|
|
|
renderFooter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resizeLastWidth = -1;
|
|
|
|
|
var resizeLastHeight = -1;
|
|
|
|
|
var resizeNewWidth = -1;
|
|
|
|
|
var resizeNewHeight = -1;
|
|
|
|
|
var resizePending = false;
|
|
|
|
|
|
|
|
|
|
me.resize = function(newWidth, newHeight) {
|
|
|
|
|
|
|
|
|
|
function resizeDelayed() {
|
|
|
|
|
resizePending = false;
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
(resizeNewWidth !== resizeLastWidth) ||
|
|
|
|
|
(!me.fixedHeight() && resizeNewHeight !== resizeLastHeight)
|
|
|
|
|
) {
|
|
|
|
|
resizeLastWidth = resizeNewWidth;
|
|
|
|
|
resizeLastHeight = resizeNewHeight;
|
|
|
|
|
|
|
|
|
|
setTimeout(resizeDelayed, 200);
|
|
|
|
|
resizePending = true;
|
|
|
|
|
} else {
|
|
|
|
|
me.render();
|
|
|
|
|
triggerOnChange();
|
|
|
|
|
|
|
|
|
|
resizeLastWidth = -1;
|
|
|
|
|
resizeLastHeight = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resizeNewWidth = newWidth;
|
|
|
|
|
resizeNewHeight = newHeight;
|
|
|
|
|
|
|
|
|
|
if (!resizePending) resizeDelayed();
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var PagedTableDoc;
|
|
|
|
|
(function (PagedTableDoc) {
|
|
|
|
|
var allPagedTables = [];
|
|
|
|
|
|
|
|
|
|
PagedTableDoc.initAll = function() {
|
|
|
|
|
allPagedTables = [];
|
|
|
|
|
|
|
|
|
|
var pagedTables = [].slice.call(document.querySelectorAll('[data-pagedtable="false"],[data-pagedtable=""]'));
|
|
|
|
|
pagedTables.forEach(function(pagedTable, idx) {
|
|
|
|
|
pagedTable.setAttribute("data-pagedtable", "true");
|
|
|
|
|
pagedTable.setAttribute("pagedtable-page", 0);
|
|
|
|
|
pagedTable.setAttribute("class", "pagedtable-wrapper");
|
|
|
|
|
|
|
|
|
|
var pagedTableInstance = new PagedTable(pagedTable);
|
|
|
|
|
pagedTableInstance.init();
|
|
|
|
|
|
|
|
|
|
allPagedTables.push(pagedTableInstance);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PagedTableDoc.resizeAll = function() {
|
|
|
|
|
allPagedTables.forEach(function(pagedTable) {
|
|
|
|
|
pagedTable.render();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.addEventListener("resize", PagedTableDoc.resizeAll);
|
|
|
|
|
|
|
|
|
|
return PagedTableDoc;
|
|
|
|
|
})(PagedTableDoc || (PagedTableDoc = {}));
|
|
|
|
|
|
|
|
|
|
window.onload = function() {
|
|
|
|
|
PagedTableDoc.initAll();
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
code{white-space: pre-wrap;}
|
|
|
|
|
span.smallcaps{font-variant: small-caps;}
|
|
|
|
|
span.underline{text-decoration: underline;}
|
|
|
|
|
div.column{display: inline-block; vertical-align: top; width: 50%;}
|
|
|
|
|
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
|
|
|
|
|
ul.task-list{list-style: none;}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
code {
|
|
|
|
|
white-space: pre;
|
|
|
|
|
}
|
|
|
|
|
.sourceCode {
|
|
|
|
|
overflow: visible;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
<style type="text/css" data-origin="pandoc">
|
|
|
|
|
pre > code.sourceCode { white-space: pre; position: relative; }
|
|
|
|
|
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
|
|
|
|
|
pre > code.sourceCode > span:empty { height: 1.2em; }
|
|
|
|
|
.sourceCode { overflow: visible; }
|
|
|
|
|
code.sourceCode > span { color: inherit; text-decoration: inherit; }
|
|
|
|
|
div.sourceCode { margin: 1em 0; }
|
|
|
|
|
pre.sourceCode { margin: 0; }
|
|
|
|
|
@media screen {
|
|
|
|
|
div.sourceCode { overflow: auto; }
|
|
|
|
|
}
|
|
|
|
|
@media print {
|
|
|
|
|
pre > code.sourceCode { white-space: pre-wrap; }
|
|
|
|
|
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
|
|
|
|
|
}
|
|
|
|
|
pre.numberSource code
|
|
|
|
|
{ counter-reset: source-line 0; }
|
|
|
|
|
pre.numberSource code > span
|
|
|
|
|
{ position: relative; left: -4em; counter-increment: source-line; }
|
|
|
|
|
pre.numberSource code > span > a:first-child::before
|
|
|
|
|
{ content: counter(source-line);
|
|
|
|
|
position: relative; left: -1em; text-align: right; vertical-align: baseline;
|
|
|
|
|
border: none; display: inline-block;
|
|
|
|
|
-webkit-touch-callout: none; -webkit-user-select: none;
|
|
|
|
|
-khtml-user-select: none; -moz-user-select: none;
|
|
|
|
|
-ms-user-select: none; user-select: none;
|
|
|
|
|
padding: 0 4px; width: 4em;
|
|
|
|
|
background-color: #232629;
|
|
|
|
|
color: #7a7c7d;
|
|
|
|
|
}
|
|
|
|
|
pre.numberSource { margin-left: 3em; border-left: 1px solid #7a7c7d; padding-left: 4px; }
|
|
|
|
|
div.sourceCode
|
|
|
|
|
{ color: #cfcfc2; background-color: #232629; }
|
|
|
|
|
@media screen {
|
|
|
|
|
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
|
|
|
|
|
}
|
|
|
|
|
code span { color: #cfcfc2; }
|
|
|
|
|
code span.al { color: #95da4c; background-color: #4d1f24; font-weight: bold; }
|
|
|
|
|
code span.an { color: #3f8058; }
|
|
|
|
|
code span.at { color: #2980b9; }
|
|
|
|
|
code span.bn { color: #f67400; }
|
|
|
|
|
code span.bu { color: #7f8c8d; }
|
|
|
|
|
code span.cf { color: #fdbc4b; font-weight: bold; }
|
|
|
|
|
code span.ch { color: #3daee9; }
|
|
|
|
|
code span.cn { color: #27aeae; font-weight: bold; }
|
|
|
|
|
code span.co { color: #7a7c7d; }
|
|
|
|
|
code span.cv { color: #7f8c8d; }
|
|
|
|
|
code span.do { color: #a43340; }
|
|
|
|
|
code span.dt { color: #2980b9; }
|
|
|
|
|
code span.dv { color: #f67400; }
|
|
|
|
|
code span.er { color: #da4453; text-decoration: underline; }
|
|
|
|
|
code span.ex { color: #0099ff; font-weight: bold; }
|
|
|
|
|
code span.fl { color: #f67400; }
|
|
|
|
|
code span.fu { color: #8e44ad; }
|
|
|
|
|
code span.im { color: #27ae60; }
|
|
|
|
|
code span.in { color: #c45b00; }
|
|
|
|
|
code span.kw { color: #cfcfc2; font-weight: bold; }
|
|
|
|
|
code span.op { color: #cfcfc2; }
|
|
|
|
|
code span.ot { color: #27ae60; }
|
|
|
|
|
code span.pp { color: #27ae60; }
|
|
|
|
|
code span.re { color: #2980b9; background-color: #153042; }
|
|
|
|
|
code span.sc { color: #3daee9; }
|
|
|
|
|
code span.ss { color: #da4453; }
|
|
|
|
|
code span.st { color: #f44f4f; }
|
|
|
|
|
code span.va { color: #27aeae; }
|
|
|
|
|
code span.vs { color: #da4453; }
|
|
|
|
|
code span.wa { color: #da4453; }
|
|
|
|
|
</style>
|
|
|
|
|
<script>
|
|
|
|
|
// apply pandoc div.sourceCode style to pre.sourceCode instead
|
|
|
|
|
(function() {
|
|
|
|
|
var sheets = document.styleSheets;
|
|
|
|
|
for (var i = 0; i < sheets.length; i++) {
|
|
|
|
|
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
|
|
|
|
|
try { var rules = sheets[i].cssRules; } catch (e) { continue; }
|
|
|
|
|
var j = 0;
|
|
|
|
|
while (j < rules.length) {
|
|
|
|
|
var rule = rules[j];
|
|
|
|
|
// check if there is a div.sourceCode rule
|
|
|
|
|
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") {
|
|
|
|
|
j++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
var style = rule.style.cssText;
|
|
|
|
|
// check if color or background-color is set
|
|
|
|
|
if (rule.style.color === '' && rule.style.backgroundColor === '') {
|
|
|
|
|
j++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// replace div.sourceCode by a pre.sourceCode rule
|
|
|
|
|
sheets[i].deleteRule(j);
|
|
|
|
|
sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
#rmd-source-code {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
.main-container {
|
|
|
|
|
max-width: 940px;
|
|
|
|
|
margin-left: auto;
|
|
|
|
|
margin-right: auto;
|
|
|
|
|
}
|
|
|
|
|
img {
|
|
|
|
|
max-width:100%;
|
|
|
|
|
}
|
|
|
|
|
.tabbed-pane {
|
|
|
|
|
padding-top: 12px;
|
|
|
|
|
}
|
|
|
|
|
.html-widget {
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
}
|
|
|
|
|
button.code-folding-btn:focus {
|
|
|
|
|
outline: none;
|
|
|
|
|
}
|
|
|
|
|
summary {
|
|
|
|
|
display: list-item;
|
|
|
|
|
}
|
|
|
|
|
details > summary > p:only-child {
|
|
|
|
|
display: inline;
|
|
|
|
|
}
|
|
|
|
|
pre code {
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- tabsets -->
|
|
|
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
.tabset-dropdown > .nav-tabs {
|
|
|
|
|
display: inline-table;
|
|
|
|
|
max-height: 500px;
|
|
|
|
|
min-height: 44px;
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
}
|
|
|
|
|
.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before {
|
|
|
|
|
content: "\e259";
|
|
|
|
|
font-family: 'Glyphicons Halflings';
|
|
|
|
|
display: inline-block;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
border-right: 1px solid #ddd;
|
|
|
|
|
}
|
|
|
|
|
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
|
|
|
|
|
content: "\e258";
|
|
|
|
|
font-family: 'Glyphicons Halflings';
|
|
|
|
|
border: none;
|
|
|
|
|
}
|
|
|
|
|
.tabset-dropdown > .nav-tabs > li.active {
|
|
|
|
|
display: block;
|
|
|
|
|
}
|
|
|
|
|
.tabset-dropdown > .nav-tabs > li > a,
|
|
|
|
|
.tabset-dropdown > .nav-tabs > li > a:focus,
|
|
|
|
|
.tabset-dropdown > .nav-tabs > li > a:hover {
|
|
|
|
|
border: none;
|
|
|
|
|
display: inline-block;
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
background-color: transparent;
|
|
|
|
|
}
|
|
|
|
|
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
|
|
|
|
|
display: block;
|
|
|
|
|
float: none;
|
|
|
|
|
}
|
|
|
|
|
.tabset-dropdown > .nav-tabs > li {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<!-- code folding -->
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
.code-folding-btn { margin-bottom: 4px; }
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
|
#TOC {
|
|
|
|
|
margin: 25px 0px 20px 0px;
|
|
|
|
|
}
|
|
|
|
|
@media (max-width: 768px) {
|
|
|
|
|
#TOC {
|
|
|
|
|
position: relative;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@media print {
|
|
|
|
|
.toc-content {
|
|
|
|
|
|
|
|
|
|
float: right;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.toc-content {
|
|
|
|
|
padding-left: 30px;
|
|
|
|
|
padding-right: 40px;
|
|
|
|
|
}
|
|
|
|
|
div.main-container {
|
|
|
|
|
max-width: 1200px;
|
|
|
|
|
}
|
|
|
|
|
div.tocify {
|
|
|
|
|
width: 20%;
|
|
|
|
|
max-width: 260px;
|
|
|
|
|
max-height: 85%;
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 768px) and (max-width: 991px) {
|
|
|
|
|
div.tocify {
|
|
|
|
|
width: 25%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@media (max-width: 767px) {
|
|
|
|
|
div.tocify {
|
|
|
|
|
width: 100%;
|
|
|
|
|
max-width: none;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.tocify ul, .tocify li {
|
|
|
|
|
line-height: 20px;
|
|
|
|
|
}
|
|
|
|
|
.tocify-subheader .tocify-item {
|
|
|
|
|
font-size: 0.90em;
|
|
|
|
|
}
|
|
|
|
|
.tocify .list-group-item {
|
|
|
|
|
border-radius: 0px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="container-fluid main-container">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- setup 3col/9col grid for toc_float and main content -->
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col-xs-12 col-sm-4 col-md-3">
|
|
|
|
|
<div id="TOC" class="tocify">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div id="header">
|
|
|
|
|
|
|
|
|
|
<div class="btn-group pull-right float-right">
|
|
|
|
|
<button type="button" class="btn btn-default btn-xs btn-secondary btn-sm dropdown-toggle" data-toggle="dropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span>Code</span> <span class="caret"></span></button>
|
|
|
|
|
<ul class="dropdown-menu dropdown-menu-right" style="min-width: 50px;">
|
|
|
|
|
<li><a id="rmd-download-source" href="#">Download Rmd</a></li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h1 class="title toc-ignore">Build a regression model: prepare and
|
|
|
|
|
visualize data</h1>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div id="linear-regression-for-pumpkins---lesson-2" class="section level2">
|
|
|
|
|
<h2><strong>Linear Regression for Pumpkins - Lesson 2</strong></h2>
|
|
|
|
|
<div id="introduction" class="section level4">
|
|
|
|
|
<h4>Introduction</h4>
|
|
|
|
|
<p>Now that you are set up with the tools you need to start tackling
|
|
|
|
|
machine learning model building with Tidymodels and the Tidyverse, you
|
|
|
|
|
are ready to start asking questions of your data. As you work with data
|
|
|
|
|
and apply ML solutions, it’s very important to understand how to ask the
|
|
|
|
|
right question to properly unlock the potentials of your dataset.</p>
|
|
|
|
|
<p>In this lesson, you will learn:</p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li><p>How to prepare your data for model-building.</p></li>
|
|
|
|
|
<li><p>How to use <code>ggplot2</code> for data visualization.</p></li>
|
|
|
|
|
</ul>
|
|
|
|
|
<p>The question you need answered will determine what type of ML
|
|
|
|
|
algorithms you will leverage. And the quality of the answer you get back
|
|
|
|
|
will be heavily dependent on the nature of your data.</p>
|
|
|
|
|
<p>Let’s see this by working through a practical exercise.</p>
|
|
|
|
|
<div class="figure">
|
|
|
|
|
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wgARCAOgCAADASIAAhEBAxEB/8QAHAABAAIDAQEBAAAAAAAAAAAAAAECAwQFBgcI/8QAGwEBAAMBAQEBAAAAAAAAAAAAAAECAwQFBgf/2gAMAwEAAhADEAAAAfsoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAByqTqeU13zPVszjvy3shCUIShKVRKtZXikSvGOJjLGMZGMZWIZYxjJFIleKRLIxjJOKTLbFarKpMTZUMc4rxa2vF438+jvYWyWi2MiYmJCEiImJAASTASImTFewCCJiWMTC1chIrIAACCRQXqkgiUzWQiEWmsnvR9zwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAA53RQ+KfZPnXqfO19H4b3Ot25/DNrLqeNvnFJ0fvHwX7Z6mPV0t12U+KW7Po/H3+eTjyYzo93lYtI+8W1Nv2sHmfTKz8Y5f3n4/wCfp9T3/nv0LtzDaAAHJ6yj5Xfqcr5bsy5MOTC2SqYeX72jzu3PvYd7m4
|
|
|
|
|
<p class="caption">Artwork by @allison_horst</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="importing-pumpkins-data-and-summoning-the-tidyverse" class="section level2">
|
|
|
|
|
<h2>1. Importing pumpkins data and summoning the Tidyverse</h2>
|
|
|
|
|
<p>We’ll require the following packages to slice and dice this
|
|
|
|
|
lesson:</p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li><code>tidyverse</code>: The <a href="https://www.tidyverse.org/">tidyverse</a> is a <a href="https://www.tidyverse.org/packages">collection of R packages</a>
|
|
|
|
|
designed to makes data science faster, easier and more fun!</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<p>You can have them installed as:</p>
|
|
|
|
|
<p><code>install.packages(c("tidyverse"))</code></p>
|
|
|
|
|
<p>The script below checks whether you have the packages required to
|
|
|
|
|
complete this module and installs them for you in case they are
|
|
|
|
|
missing.</p>
|
|
|
|
|
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> (<span class="sc">!</span><span class="fu">require</span>(<span class="st">"pacman"</span>)) <span class="fu">install.packages</span>(<span class="st">"pacman"</span>)</span>
|
|
|
|
|
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>pacman<span class="sc">::</span><span class="fu">p_load</span>(tidyverse)</span></code></pre></div>
|
|
|
|
|
<p>Now, let’s fire up some packages and load the <a href="https://github.com/microsoft/ML-For-Beginners/blob/main/2-Regression/data/US-pumpkins.csv">data</a>
|
|
|
|
|
provided for this lesson!</p>
|
|
|
|
|
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Load the core Tidyverse packages</span></span>
|
|
|
|
|
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidyverse)</span>
|
|
|
|
|
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Import the pumpkins data</span></span>
|
|
|
|
|
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="ot"><-</span> <span class="fu">read_csv</span>(<span class="at">file =</span> <span class="st">"https://raw.githubusercontent.com/microsoft/ML-For-Beginners/main/2-Regression/data/US-pumpkins.csv"</span>)</span>
|
|
|
|
|
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="co"># Get a glimpse and dimensions of the data</span></span>
|
|
|
|
|
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a><span class="fu">glimpse</span>(pumpkins)</span></code></pre></div>
|
|
|
|
|
<pre><code>## Rows: 1,757
|
|
|
|
|
## Columns: 26
|
|
|
|
|
## $ `City Name` <chr> "BALTIMORE", "BALTIMORE", "BALTIMORE", "BALTIMORE", ~
|
|
|
|
|
## $ Type <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ Package <chr> "24 inch bins", "24 inch bins", "24 inch bins", "24 ~
|
|
|
|
|
## $ Variety <chr> NA, NA, "HOWDEN TYPE", "HOWDEN TYPE", "HOWDEN TYPE",~
|
|
|
|
|
## $ `Sub Variety` <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ Grade <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ Date <chr> "4/29/17", "5/6/17", "9/24/16", "9/24/16", "11/5/16"~
|
|
|
|
|
## $ `Low Price` <dbl> 270, 270, 160, 160, 90, 90, 160, 160, 160, 160, 160,~
|
|
|
|
|
## $ `High Price` <dbl> 280, 280, 160, 160, 100, 100, 170, 160, 170, 160, 17~
|
|
|
|
|
## $ `Mostly Low` <dbl> 270, 270, 160, 160, 90, 90, 160, 160, 160, 160, 160,~
|
|
|
|
|
## $ `Mostly High` <dbl> 280, 280, 160, 160, 100, 100, 170, 160, 170, 160, 17~
|
|
|
|
|
## $ Origin <chr> "MARYLAND", "MARYLAND", "DELAWARE", "VIRGINIA", "MAR~
|
|
|
|
|
## $ `Origin District` <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ `Item Size` <chr> "lge", "lge", "med", "med", "lge", "lge", "med", "lg~
|
|
|
|
|
## $ Color <chr> NA, NA, "ORANGE", "ORANGE", "ORANGE", "ORANGE", "ORA~
|
|
|
|
|
## $ Environment <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ `Unit of Sale` <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ Quality <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ Condition <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ Appearance <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ Storage <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ Crop <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ Repack <chr> "E", "E", "N", "N", "N", "N", "N", "N", "N", "N", "N~
|
|
|
|
|
## $ `Trans Mode` <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ ...25 <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~
|
|
|
|
|
## $ ...26 <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ~</code></pre>
|
|
|
|
|
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Print the first 50 rows of the data set</span></span>
|
|
|
|
|
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">slice_head</span>(<span class="at">n =</span><span class="dv">50</span>)</span></code></pre></div>
|
|
|
|
|
<div data-pagedtable="false">
|
|
|
|
|
<script data-pagedtable-source type="application/json">
|
|
|
|
|
{"columns":[{"label":["City Name"],"name":[1],"type":["chr"],"align":["left"]},{"label":["Type"],"name":[2],"type":["chr"],"align":["left"]},{"label":["Package"],"name":[3],"type":["chr"],"align":["left"]},{"label":["Variety"],"name":[4],"type":["chr"],"align":["left"]},{"label":["Sub Variety"],"name":[5],"type":["chr"],"align":["left"]},{"label":["Grade"],"name":[6],"type":["lgl"],"align":["right"]},{"label":["Date"],"name":[7],"type":["chr"],"align":["left"]},{"label":["Low Price"],"name":[8],"type":["dbl"],"align":["right"]},{"label":["High Price"],"name":[9],"type":["dbl"],"align":["right"]},{"label":["Mostly Low"],"name":[10],"type":["dbl"],"align":["right"]},{"label":["Mostly High"],"name":[11],"type":["dbl"],"align":["right"]},{"label":["Origin"],"name":[12],"type":["chr"],"align":["left"]},{"label":["Origin District"],"name":[13],"type":["chr"],"align":["left"]},{"label":["Item Size"],"name":[14],"type":["chr"],"align":["left"]},{"label":["Color"],"name":[15],"type":["chr"],"align":["left"]},{"label":["Environment"],"name":[16],"type":["lgl"],"align":["right"]},{"label":["Unit of Sale"],"name":[17],"type":["chr"],"align":["left"]},{"label":["Quality"],"name":[18],"type":["lgl"],"align":["right"]},{"label":["Condition"],"name":[19],"type":["lgl"],"align":["right"]},{"label":["Appearance"],"name":[20],"type":["lgl"],"align":["right"]},{"label":["Storage"],"name":[21],"type":["lgl"],"align":["right"]},{"label":["Crop"],"name":[22],"type":["lgl"],"align":["right"]},{"label":["Repack"],"name":[23],"type":["chr"],"align":["left"]},{"label":["Trans Mode"],"name":[24],"type":["lgl"],"align":["right"]},{"label":["...25"],"name":[25],"type":["lgl"],"align":["right"]},{"label":["...26"],"name":[26],"type":["chr"],"align":["left"]}],"data":[{"1":"BALTIMORE","2":"NA","3":"24 inch bins","4":"NA","5":"NA","6":"NA","7":"4/29/17","8":"270","9":"280","10":"270","11":"280","12":"MARYLAND","13":"NA","14":"lge","15":"NA","16":"NA","17":"NA","18":"NA","19":"NA","20":"NA","21":"NA","22":"NA","23":"E","24":"NA","25":"NA","26":"NA"},{"1":"BALTIMORE","2":"NA","3":"24 inch bins","4":"NA","5":"NA","6":"NA","7":"5/6/17","8":"270","9":"280","10":"270","11":"280","12":"MARYLAND","13":"NA","14":"lge","15":"NA","16":"NA","17":"NA","18":"NA","19":"NA","20":"NA","21":"NA","22":"NA","23":"E","24":"NA","25":"NA","26":"NA"},{"1":"BALTIMORE","2":"NA","3":"24 inch bins","4":"HOWDEN TYPE","5":"NA","6":"NA","7":"9/24/16","8":"160","9":"160","10":"160","11":"160","12":"DELAWARE","13":"NA","14":"med","15":"ORANGE","16":"NA","17":"NA","18":"NA","19":"NA","20":"NA","21":"NA","22":"NA","23":"N","24":"NA","25":"NA","26":"NA"},{"1":"BALTIMORE","2":"NA","3":"24 inch bins","4":"HOWDEN TYPE","5":"NA","6":"NA","7":"9/24/16","8":"160","9":"160","10":"160","11":"160","12":"VIRGINIA","13":"NA","14":"med","15":"ORANGE","16":"NA","17":"NA","18":"NA","19":"NA","20":"NA","21":"NA","22":"NA","23":"N","24":"NA","25":"NA","26":"NA"},{"1":"BALTIMORE","2":"NA","3":"24 inch bins","4":"HOWDEN TYPE","5":"NA","6":"NA","7":"11/5/16","8":"90","9":"100","10":"90","11":"100","12":"MARYLAND","13":"NA","14":"lge","15":"ORANGE","16":"NA","17":"NA","18":"NA","19":"NA","20":"NA","21":"NA","22":"NA","23":"N","24":"NA","25":"NA","26":"NA"},{"1":"BALTIMORE","2":"NA","3":"24 inch bins","4":"HOWDEN TYPE","5":"NA","6":"NA","7":"11/12/16","8":"90","9":"100","10":"90","11":"100","12":"MARYLAND","13":"NA","14":"lge","15":"ORANGE","16":"NA","17":"NA","18":"NA","19":"NA","20":"NA","21":"NA","22":"NA","23":"N","24":"NA","25":"NA","26":"NA"},{"1":"BALTIMORE","2":"NA","3":"36 inch bins","4":"HOWDEN TYPE","5":"NA","6":"NA","7":"9/24/16","8":"160","9":"170","10":"160","11":"170","12":"MARYLAND","13":"NA","14":"med","15":"ORANGE","16":"NA","17":"NA","18":"NA","19":"NA","20":"NA","21":"NA","22":"NA","23":"N","24":"NA","25":"NA","26":"NA"},{"1":"BALTIMORE","2":"NA","3":"36 inch bins","4":"HOWDEN TYPE","5":"NA","6":"NA","7":"9/24/16","8":"160","9":"160","10":"160","11":"160","12":"PENNSYLVANIA","13":"NA","14":"lge","15":"ORANGE","16":"NA","17":"NA","18":"NA","19":"NA","20":"NA","21":"NA","22":"NA","23":"N","
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
<p>A quick <code>glimpse()</code> immediately shows that there are
|
|
|
|
|
blanks and a mix of strings (<code>chr</code>) and numeric data
|
|
|
|
|
(<code>dbl</code>). The <code>Date</code> is of type character and
|
|
|
|
|
there’s also a strange column called <code>Package</code> where the data
|
|
|
|
|
is a mix between <code>sacks</code>, <code>bins</code> and other values.
|
|
|
|
|
The data, in fact, is a bit of a mess 😤.</p>
|
|
|
|
|
<p>In fact, it is not very common to be gifted a dataset that is
|
|
|
|
|
completely ready to use to create a ML model out of the box. But worry
|
|
|
|
|
not, in this lesson, you will learn how to prepare a raw dataset using
|
|
|
|
|
standard R libraries 🧑🔧. You will also learn various techniques to
|
|
|
|
|
visualize the data.📈📊</p>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>A refresher: The pipe operator (<code>%>%</code>) performs
|
|
|
|
|
operations in logical sequence by passing an object forward into a
|
|
|
|
|
function or call expression. You can think of the pipe operator as
|
|
|
|
|
saying “and then” in your code.</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="check-for-missing-data" class="section level2">
|
|
|
|
|
<h2>2. Check for missing data</h2>
|
|
|
|
|
<p>One of the most common issues data scientists need to deal with is
|
|
|
|
|
incomplete or missing data. R represents missing, or unknown values,
|
|
|
|
|
with special sentinel value: <code>NA</code> (Not Available).</p>
|
|
|
|
|
<p>So how would we know that the data frame contains missing values?</p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>One straight forward way would be to use the base R function
|
|
|
|
|
<code>anyNA</code> which returns the logical objects <code>TRUE</code>
|
|
|
|
|
or <code>FALSE</code></li>
|
|
|
|
|
</ul>
|
|
|
|
|
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">anyNA</span>()</span></code></pre></div>
|
|
|
|
|
<pre><code>## [1] TRUE</code></pre>
|
|
|
|
|
<p>Great, there seems to be some missing data! That’s a good place to
|
|
|
|
|
start.</p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>Another way would be to use the function <code>is.na()</code> that
|
|
|
|
|
indicates which individual column elements are missing with a logical
|
|
|
|
|
<code>TRUE</code>.</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">is.na</span>() <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">head</span>(<span class="at">n =</span> <span class="dv">7</span>)</span></code></pre></div>
|
|
|
|
|
<pre><code>## City Name Type Package Variety Sub Variety Grade Date Low Price
|
|
|
|
|
## [1,] FALSE TRUE FALSE TRUE TRUE TRUE FALSE FALSE
|
|
|
|
|
## [2,] FALSE TRUE FALSE TRUE TRUE TRUE FALSE FALSE
|
|
|
|
|
## [3,] FALSE TRUE FALSE FALSE TRUE TRUE FALSE FALSE
|
|
|
|
|
## [4,] FALSE TRUE FALSE FALSE TRUE TRUE FALSE FALSE
|
|
|
|
|
## [5,] FALSE TRUE FALSE FALSE TRUE TRUE FALSE FALSE
|
|
|
|
|
## [6,] FALSE TRUE FALSE FALSE TRUE TRUE FALSE FALSE
|
|
|
|
|
## [7,] FALSE TRUE FALSE FALSE TRUE TRUE FALSE FALSE
|
|
|
|
|
## High Price Mostly Low Mostly High Origin Origin District Item Size Color
|
|
|
|
|
## [1,] FALSE FALSE FALSE FALSE TRUE FALSE TRUE
|
|
|
|
|
## [2,] FALSE FALSE FALSE FALSE TRUE FALSE TRUE
|
|
|
|
|
## [3,] FALSE FALSE FALSE FALSE TRUE FALSE FALSE
|
|
|
|
|
## [4,] FALSE FALSE FALSE FALSE TRUE FALSE FALSE
|
|
|
|
|
## [5,] FALSE FALSE FALSE FALSE TRUE FALSE FALSE
|
|
|
|
|
## [6,] FALSE FALSE FALSE FALSE TRUE FALSE FALSE
|
|
|
|
|
## [7,] FALSE FALSE FALSE FALSE TRUE FALSE FALSE
|
|
|
|
|
## Environment Unit of Sale Quality Condition Appearance Storage Crop Repack
|
|
|
|
|
## [1,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE
|
|
|
|
|
## [2,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE
|
|
|
|
|
## [3,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE
|
|
|
|
|
## [4,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE
|
|
|
|
|
## [5,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE
|
|
|
|
|
## [6,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE
|
|
|
|
|
## [7,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE
|
|
|
|
|
## Trans Mode ...25 ...26
|
|
|
|
|
## [1,] TRUE TRUE TRUE
|
|
|
|
|
## [2,] TRUE TRUE TRUE
|
|
|
|
|
## [3,] TRUE TRUE TRUE
|
|
|
|
|
## [4,] TRUE TRUE TRUE
|
|
|
|
|
## [5,] TRUE TRUE TRUE
|
|
|
|
|
## [6,] TRUE TRUE TRUE
|
|
|
|
|
## [7,] TRUE TRUE TRUE</code></pre>
|
|
|
|
|
<p>Okay, got the job done but with a large data frame such as this, it
|
|
|
|
|
would be inefficient and practically impossible to review all of the
|
|
|
|
|
rows and columns individually😴.</p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>A more intuitive way would be to calculate the sum of the missing
|
|
|
|
|
values for each column:</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">is.na</span>() <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">colSums</span>()</span></code></pre></div>
|
|
|
|
|
<pre><code>## City Name Type Package Variety Sub Variety
|
|
|
|
|
## 0 1712 0 5 1461
|
|
|
|
|
## Grade Date Low Price High Price Mostly Low
|
|
|
|
|
## 1757 0 0 0 103
|
|
|
|
|
## Mostly High Origin Origin District Item Size Color
|
|
|
|
|
## 103 3 1626 279 616
|
|
|
|
|
## Environment Unit of Sale Quality Condition Appearance
|
|
|
|
|
## 1757 1595 1757 1757 1757
|
|
|
|
|
## Storage Crop Repack Trans Mode ...25
|
|
|
|
|
## 1757 1757 0 1757 1757
|
|
|
|
|
## ...26
|
|
|
|
|
## 1654</code></pre>
|
|
|
|
|
<p>Much better! There is missing data, but maybe it won’t matter for the
|
|
|
|
|
task at hand. Let’s see what further analysis brings forth.</p>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>Along with the awesome sets of packages and functions, R has a very
|
|
|
|
|
good documentation. For instance, use <code>help(colSums)</code> or
|
|
|
|
|
<code>?colSums</code> to find out more about the function.</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="dplyr-a-grammar-of-data-manipulation" class="section level2">
|
|
|
|
|
<h2>3. Dplyr: A Grammar of Data Manipulation</h2>
|
|
|
|
|
<div class="figure">
|
|
|
|
|
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB3kAAAX6CAYAAAD+3dIbAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAAsTAAALEwEAmpwYAAABj2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyI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RxmJREUAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAYK87AMIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIBAHQkQ5K2jjcWiIoAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAgR52QcQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQACBOhIgyFtHG4tFRQABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBAjysg8ggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACdSRAkLeONhaLigACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCBDkZR9AAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEE6kiAIG8dbSwWFQEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEECDIyz6AAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAII1JEAQd462lgsKgIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIECQl30AAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQqCMBgrx1tLFYVAQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQIAgL/sAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAgggUEcCBHnraGOxqAgggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggABBXvYBBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAoI4ECPLW0cZiURFAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAGCvOwDCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAQB0JEOSto43FoiKAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIEedkHEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAgToSIMhbRxuLRUUAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQI8rIPIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAnUkQJC3jjYWi4oAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggQ5GUfQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBOpIgCBvHW0sFhUBBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBAgyMs+gAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCNSRAEHeOtpYLCoCCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCBAkJd9AAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEKgjAYK8dbSxWFQEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEECAIC/7AAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIFBHAgR562hjsagIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAQV72AQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQKCOBAjy1tHGYlERQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABgrzsAwgggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggEAdCRDkraONxaIigAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACBHnZBxBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAIE6EiDIW0cbi0VFAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEECPKyDyCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAJ1JECQt442FouKAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIEORlH0AAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQTqSIAgbx1tLBYVAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQIMjLPoAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAgjUkQBB3jraWCwqAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAgggQJCXfQABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBCoIwGCvHW0sVhUBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAgCAv+wACCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCBQRwIEeetoY7GoCCCAAAIIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAEFe9gEEEEAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEECgjgQI8tbRxmJREUAAAQQQQAABBBBAAAEEEEAAAQQQQAABBBBAAAEEEEAAAYK87AMIIIAAAggggAACCCCAAAIIIIAAAggggAACCCCAAAIIIIBAHQkQ5K2
|
|
|
|
|
<p class="caption">Artwork by @allison_horst</p>
|
|
|
|
|
</div>
|
|
|
|
|
<p><a href="https://dplyr.tidyverse.org/"><code>dplyr</code></a>, a
|
|
|
|
|
package in the Tidyverse, is a grammar of data manipulation that
|
|
|
|
|
provides a consistent set of verbs that help you solve the most common
|
|
|
|
|
data manipulation challenges. In this section, we’ll explore some of
|
|
|
|
|
dplyr’s verbs!</p>
|
|
|
|
|
<div id="dplyrselect" class="section level4">
|
|
|
|
|
<h4>dplyr::select()</h4>
|
|
|
|
|
<p><code>select()</code> is a function in the package <code>dplyr</code>
|
|
|
|
|
which helps you pick columns to keep or exclude.</p>
|
|
|
|
|
<p>To make your data frame easier to work with, drop several of its
|
|
|
|
|
columns, using <code>select()</code>, keeping only the columns you
|
|
|
|
|
need.</p>
|
|
|
|
|
<p>For instance, in this exercise, our analysis will involve the columns
|
|
|
|
|
<code>Package</code>, <code>Low Price</code>, <code>High Price</code>
|
|
|
|
|
and <code>Date</code>. Let’s select these columns.</p>
|
|
|
|
|
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Select desired columns</span></span>
|
|
|
|
|
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="ot"><-</span> pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(Package, <span class="st">`</span><span class="at">Low Price</span><span class="st">`</span>, <span class="st">`</span><span class="at">High Price</span><span class="st">`</span>, Date)</span>
|
|
|
|
|
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a><span class="co"># Print data set</span></span>
|
|
|
|
|
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">slice_head</span>(<span class="at">n =</span> <span class="dv">5</span>)</span></code></pre></div>
|
|
|
|
|
<div data-pagedtable="false">
|
|
|
|
|
<script data-pagedtable-source type="application/json">
|
|
|
|
|
{"columns":[{"label":["Package"],"name":[1],"type":["chr"],"align":["left"]},{"label":["Low Price"],"name":[2],"type":["dbl"],"align":["right"]},{"label":["High Price"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["Date"],"name":[4],"type":["chr"],"align":["left"]}],"data":[{"1":"24 inch bins","2":"270","3":"280","4":"4/29/17"},{"1":"24 inch bins","2":"270","3":"280","4":"5/6/17"},{"1":"24 inch bins","2":"160","3":"160","4":"9/24/16"},{"1":"24 inch bins","2":"160","3":"160","4":"9/24/16"},{"1":"24 inch bins","2":"90","3":"100","4":"11/5/16"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="dplyrmutate" class="section level4">
|
|
|
|
|
<h4>dplyr::mutate()</h4>
|
|
|
|
|
<p><code>mutate()</code> is a function in the package <code>dplyr</code>
|
|
|
|
|
which helps you create or modify columns, while keeping the existing
|
|
|
|
|
columns.</p>
|
|
|
|
|
<p>The general structure of mutate is:</p>
|
|
|
|
|
<p><code>data %>% mutate(new_column_name = what_it_contains)</code></p>
|
|
|
|
|
<p>Let’s take <code>mutate</code> out for a spin using the
|
|
|
|
|
<code>Date</code> column by doing the following operations:</p>
|
|
|
|
|
<ol style="list-style-type: decimal">
|
|
|
|
|
<li><p>Convert the dates (currently of type character) to a month format
|
|
|
|
|
(these are US dates, so the format is <code>MM/DD/YYYY</code>).</p></li>
|
|
|
|
|
<li><p>Extract the month from the dates to a new column.</p></li>
|
|
|
|
|
</ol>
|
|
|
|
|
<p>In R, the package <a href="https://lubridate.tidyverse.org/">lubridate</a> makes it easier to
|
|
|
|
|
work with Date-time data. So, let’s use <code>dplyr::mutate()</code>,
|
|
|
|
|
<code>lubridate::mdy()</code>, <code>lubridate::month()</code> and see
|
|
|
|
|
how to achieve the above objectives. We can drop the Date column since
|
|
|
|
|
we won’t be needing it again in subsequent operations.</p>
|
|
|
|
|
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Load lubridate</span></span>
|
|
|
|
|
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(lubridate)</span>
|
|
|
|
|
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="ot"><-</span> pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a> <span class="co"># Convert the Date column to a date object</span></span>
|
|
|
|
|
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Date =</span> <span class="fu">mdy</span>(Date)) <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a> <span class="co"># Extract month from Date</span></span>
|
|
|
|
|
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Month =</span> <span class="fu">month</span>(Date)) <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a> <span class="co"># Drop Date column</span></span>
|
|
|
|
|
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(<span class="sc">-</span>Date)</span>
|
|
|
|
|
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true" tabindex="-1"></a><span class="co"># View the first few rows</span></span>
|
|
|
|
|
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true" tabindex="-1"></a> <span class="fu">slice_head</span>(<span class="at">n =</span> <span class="dv">7</span>)</span></code></pre></div>
|
|
|
|
|
<div data-pagedtable="false">
|
|
|
|
|
<script data-pagedtable-source type="application/json">
|
|
|
|
|
{"columns":[{"label":["Package"],"name":[1],"type":["chr"],"align":["left"]},{"label":["Low Price"],"name":[2],"type":["dbl"],"align":["right"]},{"label":["High Price"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["Month"],"name":[4],"type":["dbl"],"align":["right"]}],"data":[{"1":"24 inch bins","2":"270","3":"280","4":"4"},{"1":"24 inch bins","2":"270","3":"280","4":"5"},{"1":"24 inch bins","2":"160","3":"160","4":"9"},{"1":"24 inch bins","2":"160","3":"160","4":"9"},{"1":"24 inch bins","2":"90","3":"100","4":"11"},{"1":"24 inch bins","2":"90","3":"100","4":"11"},{"1":"36 inch bins","2":"160","3":"170","4":"9"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
<p>Woohoo! 🤩</p>
|
|
|
|
|
<p>Next, let’s create a new column <code>Price</code>, which represents
|
|
|
|
|
the average price of a pumpkin. Now, let’s take the average of the
|
|
|
|
|
<code>Low Price</code> and <code>High Price</code> columns to populate
|
|
|
|
|
the new Price column.</p>
|
|
|
|
|
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a new column Price</span></span>
|
|
|
|
|
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="ot"><-</span> pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Price =</span> (<span class="st">`</span><span class="at">Low Price</span><span class="st">`</span> <span class="sc">+</span> <span class="st">`</span><span class="at">High Price</span><span class="st">`</span>)<span class="sc">/</span><span class="dv">2</span>)</span>
|
|
|
|
|
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a><span class="co"># View the first few rows of the data</span></span>
|
|
|
|
|
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">slice_head</span>(<span class="at">n =</span> <span class="dv">5</span>)</span></code></pre></div>
|
|
|
|
|
<div data-pagedtable="false">
|
|
|
|
|
<script data-pagedtable-source type="application/json">
|
|
|
|
|
{"columns":[{"label":["Package"],"name":[1],"type":["chr"],"align":["left"]},{"label":["Low Price"],"name":[2],"type":["dbl"],"align":["right"]},{"label":["High Price"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["Month"],"name":[4],"type":["dbl"],"align":["right"]},{"label":["Price"],"name":[5],"type":["dbl"],"align":["right"]}],"data":[{"1":"24 inch bins","2":"270","3":"280","4":"4","5":"275"},{"1":"24 inch bins","2":"270","3":"280","4":"5","5":"275"},{"1":"24 inch bins","2":"160","3":"160","4":"9","5":"160"},{"1":"24 inch bins","2":"160","3":"160","4":"9","5":"160"},{"1":"24 inch bins","2":"90","3":"100","4":"11","5":"95"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
<p>Yeees!💪</p>
|
|
|
|
|
<p>“But wait!”, you’ll say after skimming through the whole data set
|
|
|
|
|
with <code>View(pumpkins)</code>, “There’s something odd here!”🤔</p>
|
|
|
|
|
<p>If you look at the <code>Package</code> column, pumpkins are sold in
|
|
|
|
|
many different configurations. Some are sold in
|
|
|
|
|
<code>1 1/9 bushel</code> measures, and some in <code>1/2 bushel</code>
|
|
|
|
|
measures, some per pumpkin, some per pound, and some in big boxes with
|
|
|
|
|
varying widths.</p>
|
|
|
|
|
<p>Let’s verify this:</p>
|
|
|
|
|
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Verify the distinct observations in Package column</span></span>
|
|
|
|
|
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a>pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">distinct</span>(Package)</span></code></pre></div>
|
|
|
|
|
<div data-pagedtable="false">
|
|
|
|
|
<script data-pagedtable-source type="application/json">
|
|
|
|
|
{"columns":[{"label":["Package"],"name":[1],"type":["chr"],"align":["left"]}],"data":[{"1":"24 inch bins"},{"1":"36 inch bins"},{"1":"50 lb sacks"},{"1":"1 1/9 bushel cartons"},{"1":"1/2 bushel cartons"},{"1":"1 1/9 bushel crates"},{"1":"bushel cartons"},{"1":"bins"},{"1":"35 lb cartons"},{"1":"each"},{"1":"20 lb cartons"},{"1":"50 lb cartons"},{"1":"40 lb cartons"},{"1":"bushel baskets"},{"1":"22 lb cartons"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
<p>Amazing!👏</p>
|
|
|
|
|
<p>Pumpkins seem to be very hard to weigh consistently, so let’s filter
|
|
|
|
|
them by selecting only pumpkins with the string <em>bushel</em> in the
|
|
|
|
|
<code>Package</code> column and put this in a new data frame
|
|
|
|
|
<code>new_pumpkins</code>.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="dplyrfilter-and-stringrstr_detect" class="section level4">
|
|
|
|
|
<h4>dplyr::filter() and stringr::str_detect()</h4>
|
|
|
|
|
<p><a href="https://dplyr.tidyverse.org/reference/filter.html"><code>dplyr::filter()</code></a>:
|
|
|
|
|
creates a subset of the data only containing <strong>rows</strong> that
|
|
|
|
|
satisfy your conditions, in this case, pumpkins with the string
|
|
|
|
|
<em>bushel</em> in the <code>Package</code> column.</p>
|
|
|
|
|
<p><a href="https://stringr.tidyverse.org/reference/str_detect.html">stringr::str_detect()</a>:
|
|
|
|
|
detects the presence or absence of a pattern in a string.</p>
|
|
|
|
|
<p>The <a href="https://github.com/tidyverse/stringr"><code>stringr</code></a>
|
|
|
|
|
package provides simple functions for common string operations.</p>
|
|
|
|
|
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Retain only pumpkins with "bushel"</span></span>
|
|
|
|
|
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>new_pumpkins <span class="ot"><-</span> pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(<span class="fu">str_detect</span>(Package, <span class="st">"bushel"</span>))</span>
|
|
|
|
|
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Get the dimensions of the new data</span></span>
|
|
|
|
|
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a><span class="fu">dim</span>(new_pumpkins)</span></code></pre></div>
|
|
|
|
|
<pre><code>## [1] 415 5</code></pre>
|
|
|
|
|
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="co"># View a few rows of the new data</span></span>
|
|
|
|
|
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>new_pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">slice_head</span>(<span class="at">n =</span> <span class="dv">5</span>)</span></code></pre></div>
|
|
|
|
|
<div data-pagedtable="false">
|
|
|
|
|
<script data-pagedtable-source type="application/json">
|
|
|
|
|
{"columns":[{"label":["Package"],"name":[1],"type":["chr"],"align":["left"]},{"label":["Low Price"],"name":[2],"type":["dbl"],"align":["right"]},{"label":["High Price"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["Month"],"name":[4],"type":["dbl"],"align":["right"]},{"label":["Price"],"name":[5],"type":["dbl"],"align":["right"]}],"data":[{"1":"1 1/9 bushel cartons","2":"15","3":"15","4":"9","5":"15"},{"1":"1 1/9 bushel cartons","2":"18","3":"18","4":"9","5":"18"},{"1":"1 1/9 bushel cartons","2":"18","3":"18","4":"10","5":"18"},{"1":"1 1/9 bushel cartons","2":"17","3":"17","4":"10","5":"17"},{"1":"1 1/9 bushel cartons","2":"15","3":"15","4":"10","5":"15"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
<p>You can see that we have narrowed down to 415 or so rows of data
|
|
|
|
|
containing pumpkins by the bushel.🤩</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="dplyrcase_when" class="section level4">
|
|
|
|
|
<h4>dplyr::case_when()</h4>
|
|
|
|
|
<p><strong>But wait! There’s one more thing to do</strong></p>
|
|
|
|
|
<p>Did you notice that the bushel amount varies per row? You need to
|
|
|
|
|
normalize the pricing so that you show the pricing per bushel, not per 1
|
|
|
|
|
1/9 or 1/2 bushel. Time to do some math to standardize it.</p>
|
|
|
|
|
<p>We’ll use the function <a href="https://dplyr.tidyverse.org/reference/case_when.html"><code>case_when()</code></a>
|
|
|
|
|
to <em>mutate</em> the Price column depending on some conditions.
|
|
|
|
|
<code>case_when</code> allows you to vectorise multiple
|
|
|
|
|
<code>if_else()</code>statements.</p>
|
|
|
|
|
<div class="sourceCode" id="cb18"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Convert the price if the Package contains fractional bushel values</span></span>
|
|
|
|
|
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>new_pumpkins <span class="ot"><-</span> new_pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">Price =</span> <span class="fu">case_when</span>(</span>
|
|
|
|
|
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">str_detect</span>(Package, <span class="st">"1 1/9"</span>) <span class="sc">~</span> Price<span class="sc">/</span>(<span class="dv">1</span> <span class="sc">+</span> <span class="dv">1</span><span class="sc">/</span><span class="dv">9</span>),</span>
|
|
|
|
|
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">str_detect</span>(Package, <span class="st">"1/2"</span>) <span class="sc">~</span> Price<span class="sc">/</span>(<span class="dv">1</span><span class="sc">/</span><span class="dv">2</span>),</span>
|
|
|
|
|
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a> <span class="cn">TRUE</span> <span class="sc">~</span> Price))</span>
|
|
|
|
|
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true" tabindex="-1"></a><span class="co"># View the first few rows of the data</span></span>
|
|
|
|
|
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true" tabindex="-1"></a>new_pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb18-10"><a href="#cb18-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">slice_head</span>(<span class="at">n =</span> <span class="dv">30</span>)</span></code></pre></div>
|
|
|
|
|
<div data-pagedtable="false">
|
|
|
|
|
<script data-pagedtable-source type="application/json">
|
|
|
|
|
{"columns":[{"label":["Package"],"name":[1],"type":["chr"],"align":["left"]},{"label":["Low Price"],"name":[2],"type":["dbl"],"align":["right"]},{"label":["High Price"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["Month"],"name":[4],"type":["dbl"],"align":["right"]},{"label":["Price"],"name":[5],"type":["dbl"],"align":["right"]}],"data":[{"1":"1 1/9 bushel cartons","2":"15","3":"15.0","4":"9","5":"13.500"},{"1":"1 1/9 bushel cartons","2":"18","3":"18.0","4":"9","5":"16.200"},{"1":"1 1/9 bushel cartons","2":"18","3":"18.0","4":"10","5":"16.200"},{"1":"1 1/9 bushel cartons","2":"17","3":"17.0","4":"10","5":"15.300"},{"1":"1 1/9 bushel cartons","2":"15","3":"15.0","4":"10","5":"13.500"},{"1":"1 1/9 bushel cartons","2":"18","3":"18.0","4":"10","5":"16.200"},{"1":"1 1/9 bushel cartons","2":"17","3":"17.0","4":"10","5":"15.300"},{"1":"1 1/9 bushel cartons","2":"17","3":"18.5","4":"10","5":"15.975"},{"1":"1 1/9 bushel cartons","2":"15","3":"15.0","4":"10","5":"13.500"},{"1":"1 1/9 bushel cartons","2":"17","3":"17.0","4":"10","5":"15.300"},{"1":"1 1/9 bushel cartons","2":"17","3":"18.5","4":"10","5":"15.975"},{"1":"1 1/9 bushel cartons","2":"15","3":"15.0","4":"10","5":"13.500"},{"1":"1 1/9 bushel cartons","2":"17","3":"17.0","4":"10","5":"15.300"},{"1":"1 1/9 bushel cartons","2":"17","3":"18.5","4":"10","5":"15.975"},{"1":"1 1/9 bushel cartons","2":"15","3":"15.0","4":"10","5":"13.500"},{"1":"1 1/9 bushel cartons","2":"16","3":"17.0","4":"10","5":"14.850"},{"1":"1 1/9 bushel cartons","2":"16","3":"18.0","4":"10","5":"15.300"},{"1":"1 1/9 bushel cartons","2":"18","3":"18.0","4":"9","5":"16.200"},{"1":"1 1/9 bushel cartons","2":"16","3":"16.0","4":"9","5":"14.400"},{"1":"1 1/9 bushel cartons","2":"18","3":"18.0","4":"9","5":"16.200"},{"1":"1 1/9 bushel cartons","2":"16","3":"16.0","4":"9","5":"14.400"},{"1":"1 1/9 bushel cartons","2":"16","3":"16.0","4":"9","5":"14.400"},{"1":"1 1/9 bushel cartons","2":"16","3":"16.0","4":"9","5":"14.400"},{"1":"1/2 bushel cartons","2":"18","3":"18.0","4":"9","5":"36.000"},{"1":"1/2 bushel cartons","2":"15","3":"15.0","4":"9","5":"30.000"},{"1":"1/2 bushel cartons","2":"18","3":"18.0","4":"10","5":"36.000"},{"1":"1/2 bushel cartons","2":"15","3":"15.0","4":"10","5":"30.000"},{"1":"1/2 bushel cartons","2":"17","3":"17.0","4":"10","5":"34.000"},{"1":"1/2 bushel cartons","2":"15","3":"15.0","4":"10","5":"30.000"},{"1":"1/2 bushel cartons","2":"15","3":"18.0","4":"10","5":"33.000"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
<p>Now, we can analyze the pricing per unit based on their bushel
|
|
|
|
|
measurement. All this study of bushels of pumpkins, however, goes to
|
|
|
|
|
show how very <code>important</code> it is to
|
|
|
|
|
<code>understand the nature of your data</code>!</p>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>✅ According to <a href="https://www.thespruceeats.com/how-much-is-a-bushel-1389308">The
|
|
|
|
|
Spruce Eats</a>, a bushel’s weight depends on the type of produce, as
|
|
|
|
|
it’s a volume measurement. “A bushel of tomatoes, for example, is
|
|
|
|
|
supposed to weigh 56 pounds… Leaves and greens take up more space with
|
|
|
|
|
less weight, so a bushel of spinach is only 20 pounds.” It’s all pretty
|
|
|
|
|
complicated! Let’s not bother with making a bushel-to-pound conversion,
|
|
|
|
|
and instead price by the bushel. All this study of bushels of pumpkins,
|
|
|
|
|
however, goes to show how very important it is to understand the nature
|
|
|
|
|
of your data!</p>
|
|
|
|
|
<p>✅ Did you notice that pumpkins sold by the half-bushel are very
|
|
|
|
|
expensive? Can you figure out why? Hint: little pumpkins are way pricier
|
|
|
|
|
than big ones, probably because there are so many more of them per
|
|
|
|
|
bushel, given the unused space taken by one big hollow pie pumpkin.</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
<p>Now lastly, for the sheer sake of adventure 💁♀️, let’s also move the
|
|
|
|
|
Month column to the first position i.e <code>before</code> column
|
|
|
|
|
<code>Package</code>.</p>
|
|
|
|
|
<p><code>dplyr::relocate()</code> is used to change column
|
|
|
|
|
positions.</p>
|
|
|
|
|
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a new data frame new_pumpkins</span></span>
|
|
|
|
|
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>new_pumpkins <span class="ot"><-</span> new_pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">relocate</span>(Month, <span class="at">.before =</span> Package)</span>
|
|
|
|
|
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a>new_pumpkins <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">slice_head</span>(<span class="at">n =</span> <span class="dv">7</span>)</span></code></pre></div>
|
|
|
|
|
<div data-pagedtable="false">
|
|
|
|
|
<script data-pagedtable-source type="application/json">
|
|
|
|
|
{"columns":[{"label":["Month"],"name":[1],"type":["dbl"],"align":["right"]},{"label":["Package"],"name":[2],"type":["chr"],"align":["left"]},{"label":["Low Price"],"name":[3],"type":["dbl"],"align":["right"]},{"label":["High Price"],"name":[4],"type":["dbl"],"align":["right"]},{"label":["Price"],"name":[5],"type":["dbl"],"align":["right"]}],"data":[{"1":"9","2":"1 1/9 bushel cartons","3":"15","4":"15","5":"13.5"},{"1":"9","2":"1 1/9 bushel cartons","3":"18","4":"18","5":"16.2"},{"1":"10","2":"1 1/9 bushel cartons","3":"18","4":"18","5":"16.2"},{"1":"10","2":"1 1/9 bushel cartons","3":"17","4":"17","5":"15.3"},{"1":"10","2":"1 1/9 bushel cartons","3":"15","4":"15","5":"13.5"},{"1":"10","2":"1 1/9 bushel cartons","3":"18","4":"18","5":"16.2"},{"1":"10","2":"1 1/9 bushel cartons","3":"17","4":"17","5":"15.3"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
<p>Good job!👌 You now have a clean, tidy dataset on which you can build
|
|
|
|
|
your new regression model!</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="data-visualization-with-ggplot2" class="section level2">
|
|
|
|
|
<h2>4. Data visualization with ggplot2</h2>
|
|
|
|
|
<div class="figure">
|
|
|
|
|
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA1EAAAJYCAYAAACD/WzWAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAkGVYSWZNTQAqAAAACAAGAQYAAwAAAAEAAgAAARIAAwAAAAEAAQAAARoABQAAAAEAAABWARsABQAAAAEAAABeASgAAwAAAAEAAgAAh2kABAAAAAEAAABmAAAAAAAAASwAAAABAAABLAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAADUaADAAQAAAABAAACWAAAAAD8wRCoAAAACXBIWXMAAC4jAAAuIwF4pT92AAACtmlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8ZXhpZjpQaXhlbFhEaW1lbnNpb24+MzUwODwvZXhpZjpQaXhlbFhEaW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p>
|
|
|
|
|
</div>
|
|
|
|
|
<p>There is a <em>wise</em> saying that goes like this:</p>
|
|
|
|
|
<blockquote>
|
|
|
|
|
<p>“The simple graph has brought more information to the data analyst’s
|
|
|
|
|
mind than any other device.” — John Tukey</p>
|
|
|
|
|
</blockquote>
|
|
|
|
|
<p>Part of the data scientist’s role is to demonstrate the quality and
|
|
|
|
|
nature of the data they are working with. To do this, they often create
|
|
|
|
|
interesting visualizations, or plots, graphs, and charts, showing
|
|
|
|
|
different aspects of data. In this way, they are able to visually show
|
|
|
|
|
relationships and gaps that are otherwise hard to uncover.</p>
|
|
|
|
|
<p>Visualizations can also help determine the machine learning technique
|
|
|
|
|
most appropriate for the data. A scatterplot that seems to follow a
|
|
|
|
|
line, for example, indicates that the data is a good candidate for a
|
|
|
|
|
linear regression exercise.</p>
|
|
|
|
|
<p>R offers a number of several systems for making graphs, but <a href="https://ggplot2.tidyverse.org/index.html"><code>ggplot2</code></a>
|
|
|
|
|
is one of the most elegant and most versatile. <code>ggplot2</code>
|
|
|
|
|
allows you to compose graphs by <strong>combining independent
|
|
|
|
|
components</strong>.</p>
|
|
|
|
|
<p>Let’s start with a simple scatter plot for the Price and Month
|
|
|
|
|
columns.</p>
|
|
|
|
|
<p>So in this case, we’ll start with <a href="https://ggplot2.tidyverse.org/reference/ggplot.html"><code>ggplot()</code></a>,
|
|
|
|
|
supply a dataset and aesthetic mapping (with <a href="https://ggplot2.tidyverse.org/reference/aes.html"><code>aes()</code></a>)
|
|
|
|
|
then add a layers (like <a href="https://ggplot2.tidyverse.org/reference/geom_point.html"><code>geom_point()</code></a>)
|
|
|
|
|
for scatter plots.</p>
|
|
|
|
|
<div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Set a theme for the plots</span></span>
|
|
|
|
|
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a><span class="fu">theme_set</span>(<span class="fu">theme_light</span>())</span>
|
|
|
|
|
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a></span>
|
|
|
|
|
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a scatter plot</span></span>
|
|
|
|
|
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a>p <span class="ot"><-</span> <span class="fu">ggplot</span>(<span class="at">data =</span> new_pumpkins, <span class="fu">aes</span>(<span class="at">x =</span> Price, <span class="at">y =</span> Month))</span>
|
|
|
|
|
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a>p <span class="sc">+</span> <span class="fu">geom_point</span>()</span></code></pre></div>
|
|
|
|
|
<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABUAAAAPACAMAAADDuCPrAAABL1BMVEUAAAAAADoAAGYAOjoAOmYAOpAAZrY6AAA6OgA6Ojo6OmY6OpA6ZmY6ZpA6ZrY6kNtNTU1NTW5NTY5Nbm5Nbo5NbqtNjshmAABmOgBmOjpmZjpmZmZmZpBmkJBmkLZmtttmtv9uTU1ubk1ubm5ubo5ujqtujshuq+SOTU2Obk2Obm6Oq6uOq8iOq+SOyOSOyP+QOgCQZjqQZmaQkGaQttuQ2/+rbk2rbm6rjm6ryOSr5P+zs7O2ZgC2Zjq2Zma2kDq2kGa2tra2ttu229u22/+2///Ijk3Ijm7IyKvI5P/I///bkDrbtmbbtpDb27bb29vb2//b///e3t7kq27kyI7kyKvk5Mjk////tmb/yI7/25D/27b/29v/5Kv/5Mj/5OT//7b//8j//9v//+T///8IBG3qAAAACXBIWXMAAB2HAAAdhwGP5fFlAAAgAElEQVR4nO3de2Nbh2HeYbhJ6qbrBcpsp43XLdoaW067XLrUy61dt6T0HC/ZStlz5FReJPH7f4aRAHgHcMBDAO8D8f39EVsBDs7DQ+g1JILS5KS11tqoJmlAa60dah3Q1lobWQe0tdZG1gFtrbWRdUBba21kHdDWWht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dBMjgSiOBKI4kggiiPpgGZyJBDFkUAURwJRHEkHNJMjgSiOBKI4EojiSDqgmRwJRHEkEMWRQBRH0gHN5EggiiOBKI4EojiSDmgmRwJRHAlEcSQQxZF0QDM5EojiSCCKI4EojqQD
|
|
|
|
|
<p>Is this a useful plot 🤷? Does anything about it surprise you?</p>
|
|
|
|
|
<p>It’s not particularly useful as all it does is display in your data
|
|
|
|
|
as a spread of points in a given month.</p>
|
|
|
|
|
<div id="how-do-we-make-it-useful" class="section level3">
|
|
|
|
|
<h3><strong>How do we make it useful?</strong></h3>
|
|
|
|
|
<p>To get charts to display useful data, you usually need to group the
|
|
|
|
|
data somehow. For instance in our case, finding the average price of
|
|
|
|
|
pumpkins for each month would provide more insights to the underlying
|
|
|
|
|
patterns in our data. This leads us to one more <strong>dplyr</strong>
|
|
|
|
|
flyby:</p>
|
|
|
|
|
<div id="dplyrgroup_by-summarize" class="section level4">
|
|
|
|
|
<h4><code>dplyr::group_by() %>% summarize()</code></h4>
|
|
|
|
|
<p>Grouped aggregation in R can be easily computed using</p>
|
|
|
|
|
<p><code>dplyr::group_by() %>% summarize()</code></p>
|
|
|
|
|
<ul>
|
|
|
|
|
<li><p><code>dplyr::group_by()</code> changes the unit of analysis from
|
|
|
|
|
the complete dataset to individual groups such as per month.</p></li>
|
|
|
|
|
<li><p><code>dplyr::summarize()</code> creates a new data frame with one
|
|
|
|
|
column for each grouping variable and one column for each of the summary
|
|
|
|
|
statistics that you have specified.</p></li>
|
|
|
|
|
</ul>
|
|
|
|
|
<p>For example, we can use the
|
|
|
|
|
<code>dplyr::group_by() %>% summarize()</code> to group the pumpkins
|
|
|
|
|
into groups based on the <strong>Month</strong> columns and then find
|
|
|
|
|
the <strong>mean price</strong> for each month.</p>
|
|
|
|
|
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Find the average price of pumpkins per month</span></span>
|
|
|
|
|
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>new_pumpkins <span class="sc">%>%</span></span>
|
|
|
|
|
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Month) <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarise</span>(<span class="at">mean_price =</span> <span class="fu">mean</span>(Price))</span></code></pre></div>
|
|
|
|
|
<div data-pagedtable="false">
|
|
|
|
|
<script data-pagedtable-source type="application/json">
|
|
|
|
|
{"columns":[{"label":["Month"],"name":[1],"type":["dbl"],"align":["right"]},{"label":["mean_price"],"name":[2],"type":["dbl"],"align":["right"]}],"data":[{"1":"8","2":"24.36667"},{"1":"9","2":"28.54438"},{"1":"10","2":"28.35524"},{"1":"11","2":"25.06721"},{"1":"12","2":"15.41250"}],"options":{"columns":{"min":{},"max":[10]},"rows":{"min":[10],"max":[10]},"pages":{}}}
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
<p>Succinct!✨</p>
|
|
|
|
|
<p>Categorical features such as months are better represented using a
|
|
|
|
|
bar plot 📊. The layers responsible for bar charts are
|
|
|
|
|
<code>geom_bar()</code> and <code>geom_col()</code>. Consult</p>
|
|
|
|
|
<p><code>?geom_bar</code> to find out more.</p>
|
|
|
|
|
<p>Let’s whip up one!</p>
|
|
|
|
|
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Find the average price of pumpkins per month then plot a bar chart</span></span>
|
|
|
|
|
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>new_pumpkins <span class="sc">%>%</span></span>
|
|
|
|
|
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(Month) <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarise</span>(<span class="at">mean_price =</span> <span class="fu">mean</span>(Price)) <span class="sc">%>%</span> </span>
|
|
|
|
|
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> Month, <span class="at">y =</span> mean_price)) <span class="sc">+</span></span>
|
|
|
|
|
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_col</span>(<span class="at">fill =</span> <span class="st">"midnightblue"</span>, <span class="at">alpha =</span> <span class="fl">0.7</span>) <span class="sc">+</span></span>
|
|
|
|
|
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">ylab</span>(<span class="st">"Pumpkin Price"</span>)</span></code></pre></div>
|
|
|
|
|
<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABUAAAAPACAMAAADDuCPrAAABXFBMVEUAAAAAADoAAGYAOjoAOmYAOpAAZpAAZrY6AAA6ADo6OgA6Ojo6OmY6OpA6Zjo6ZmY6ZpA6ZrY6kJA6kLY6kNtNTU1NTW5NTY5Nbm5Nbo5NbqtNjshUVJFeXptmAABmADpmOgBmOjpmOmZmZjpmZmZmZpBmkGZmkJBmkLZmkNtmtttmtv9uTU1ubk1ubo5ujqtujshuq+SOTU2Obk2Obm6Oq6uOq8iOyOSOyP+QOgCQOjqQZjqQZmaQkGaQkLaQtraQttuQ29uQ2/+rbk2rjm6ryOSr5P+zs7O2ZgC2Zjq2kDq2kGa2kJC2tpC2tra2ttu2tv+229u22/+2/9u2///Ijk3Ijm7I5P/I///bkDrbkGbbtmbbtpDbtrbb27bb29vb2//b///e3t7kq27kyI7kyKvk5Mjk////tmb/yI7/25D/27b/29v/5Kv/5Mj//7b//8j//9v//+T///8hyK0AAAAACXBIWXMAAB2HAAAdhwGP5fFlAAAgAElEQVR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aIKAKmGlAQIaQElAEwRUCSsNENAASgKaIKBKWGmAgAZQEtAEAVXCSgMENICSgCYIqBJWGiCgAZQENEFAlbDSAAENoCSgCQKqhJUGCGgAJQFNEFAlrDRAQAMoCWiCgCphpQECGkBJQBMEVAkrDRDQAEoCmiCgSlhpgIAGUBLQBAFVwkoDBDSA
|
|
|
|
|
<p>🤩🤩This is a more useful data visualization! It seems to indicate
|
|
|
|
|
that the highest price for pumpkins occurs in September and October.
|
|
|
|
|
Does that meet your expectation? Why or why not?</p>
|
|
|
|
|
<p>Congratulations on finishing the second lesson 👏! You prepared your
|
|
|
|
|
data for model building, then uncovered more insights using
|
|
|
|
|
visualizations!</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div id="rmd-source-code">LS0tDQp0aXRsZTogJ0J1aWxkIGEgcmVncmVzc2lvbiBtb2RlbDogcHJlcGFyZSBhbmQgdmlzdWFsaXplIGRhdGEnDQpvdXRwdXQ6DQogIGh0bWxfZG9jdW1lbnQ6DQogICAgZGZfcHJpbnQ6IHBhZ2VkDQogICAgdGhlbWU6IGZsYXRseQ0KICAgIGhpZ2hsaWdodDogYnJlZXplZGFyaw0KICAgIHRvYzogeWVzDQogICAgdG9jX2Zsb2F0OiB5ZXMNCiAgICBjb2RlX2Rvd25sb2FkOiB5ZXMNCi0tLQ0KDQojIyAqKkxpbmVhciBSZWdyZXNzaW9uIGZvciBQdW1wa2lucyAtIExlc3NvbiAyKioNCg0KIyMjIyBJbnRyb2R1Y3Rpb24NCg0KTm93IHRoYXQgeW91IGFyZSBzZXQgdXAgd2l0aCB0aGUgdG9vbHMgeW91IG5lZWQgdG8gc3RhcnQgdGFja2xpbmcgbWFjaGluZSBsZWFybmluZyBtb2RlbCBidWlsZGluZyB3aXRoIFRpZHltb2RlbHMgYW5kIHRoZSBUaWR5dmVyc2UsIHlvdSBhcmUgcmVhZHkgdG8gc3RhcnQgYXNraW5nIHF1ZX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2lsbCBsZWFybiBob3cgdG8gcHJlcGFyZSBhIHJhdyBkYXRhc2V0IHVzaW5nIHN0YW5kYXJkIFIgbGlicmFyaWVzIPCfp5HigI3wn5SnLiBZb3Ugd2lsbCBhbHNvIGxlYXJuIHZhcmlvdXMgdGVjaG5pcXVlcyB0byB2aXN1YWxpemUgdGhlIGRhdGEu8J+TiPCfk4oNCg0KDQoNCj4gQSByZWZyZXNoZXI6IFRoZSBwaXBlIG9wZXJhdG9yIChgJT4lYCkgcGVyZm9ybXMgb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
|
|
// add bootstrap table styles to pandoc tables
|
|
|
|
|
function bootstrapStylePandocTables() {
|
|
|
|
|
$('tr.odd').parent('tbody').parent('table').addClass('table table-condensed');
|
|
|
|
|
}
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
bootstrapStylePandocTables();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<!-- tabsets -->
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
window.buildTabsets("TOC");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
$('.tabset-dropdown > .nav-tabs > li').click(function () {
|
|
|
|
|
$(this).parent().toggleClass('nav-tabs-open');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<!-- code folding -->
|
|
|
|
|
<script>
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
window.initializeSourceEmbed("lesson_2.Rmd");
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
|
|
|
|
|
// temporarily add toc-ignore selector to headers for the consistency with Pandoc
|
|
|
|
|
$('.unlisted.unnumbered').addClass('toc-ignore')
|
|
|
|
|
|
|
|
|
|
// move toc-ignore selectors from section div to header
|
|
|
|
|
$('div.section.toc-ignore')
|
|
|
|
|
.removeClass('toc-ignore')
|
|
|
|
|
.children('h1,h2,h3,h4,h5').addClass('toc-ignore');
|
|
|
|
|
|
|
|
|
|
// establish options
|
|
|
|
|
var options = {
|
|
|
|
|
selectors: "h1,h2,h3",
|
|
|
|
|
theme: "bootstrap3",
|
|
|
|
|
context: '.toc-content',
|
|
|
|
|
hashGenerator: function (text) {
|
|
|
|
|
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
|
|
|
|
|
},
|
|
|
|
|
ignoreSelector: ".toc-ignore",
|
|
|
|
|
scrollTo: 0
|
|
|
|
|
};
|
|
|
|
|
options.showAndHide = true;
|
|
|
|
|
options.smoothScroll = true;
|
|
|
|
|
|
|
|
|
|
// tocify
|
|
|
|
|
var toc = $("#TOC").tocify(options).data("toc-tocify");
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<!-- dynamically load mathjax for compatibility with self-contained -->
|
|
|
|
|
<script>
|
|
|
|
|
(function () {
|
|
|
|
|
var script = document.createElement("script");
|
|
|
|
|
script.type = "text/javascript";
|
|
|
|
|
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
|
|
|
|
|
document.getElementsByTagName("head")[0].appendChild(script);
|
|
|
|
|
})();
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|