// ======= amplib js main ======= !function(n,l){"object"==typeof exports&&"undefined"!=typeof module?l(exports):"function"==typeof define&&define.amd?define(["exports"],l):l(n.preact={})}(this,function(n){var l,u,t,i,o,f,r,e={},c=[],s=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord/i;function a(n,l){for(var u in l)n[u]=l[u];return n}function h(n){var l=n.parentNode;l&&l.removeChild(n)}function p(n,l,u){var t,i=arguments,o={};for(t in l)"key"!==t&&"ref"!==t&&(o[t]=l[t]);if(arguments.length>3)for(u=[u],t=3;t2&&(l.children=c.slice.call(arguments,2)),v(n.type,l,l.key||n.key,l.ref||n.ref)},n.createContext=function(n){var l={},u={__c:"__cC"+r++,__:n,Consumer:function(n,l){return n.children(l)},Provider:function(n){var t,i=this;return this.getChildContext||(t=[],this.getChildContext=function(){return l[u.__c]=i,l},this.shouldComponentUpdate=function(l){n.value!==l.value&&t.some(function(n){n.context=l.value,g(n)})},this.sub=function(n){t.push(n);var l=n.componentWillUnmount;n.componentWillUnmount=function(){t.splice(t.indexOf(n),1),l&&l.call(n)}}),n.children}};return u.Consumer.contextType=u,u},n.toChildArray=b,n._e=A,n.options=l}); //# sourceMappingURL=preact.umd.js.map let e = preact.createElement; !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.moment=t()}(this,function(){"use strict";var e,i;function c(){return e.apply(null,arguments)}function o(e){return e instanceof Array||"[object Array]"===Object.prototype.toString.call(e)}function u(e){return null!=e&&"[object Object]"===Object.prototype.toString.call(e)}function l(e){return void 0===e}function h(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function d(e){return e instanceof Date||"[object Date]"===Object.prototype.toString.call(e)}function f(e,t){var n,s=[];for(n=0;n>>0,s=0;sSe(e)?(r=e+1,o-Se(e)):(r=e,o),{year:r,dayOfYear:a}}function Ie(e,t,n){var s,i,r=Ve(e.year(),t,n),a=Math.floor((e.dayOfYear()-r-1)/7)+1;return a<1?s=a+Ae(i=e.year()-1,t,n):a>Ae(e.year(),t,n)?(s=a-Ae(e.year(),t,n),i=e.year()+1):(i=e.year(),s=a),{week:s,year:i}}function Ae(e,t,n){var s=Ve(e,t,n),i=Ve(e+1,t,n);return(Se(e)-s+i)/7}I("w",["ww",2],"wo","week"),I("W",["WW",2],"Wo","isoWeek"),C("week","w"),C("isoWeek","W"),F("week",5),F("isoWeek",5),ue("w",B),ue("ww",B,z),ue("W",B),ue("WW",B,z),fe(["w","ww","W","WW"],function(e,t,n,s){t[s.substr(0,1)]=D(e)});function je(e,t){return e.slice(t,7).concat(e.slice(0,t))}I("d",0,"do","day"),I("dd",0,0,function(e){return this.localeData().weekdaysMin(this,e)}),I("ddd",0,0,function(e){return this.localeData().weekdaysShort(this,e)}),I("dddd",0,0,function(e){return this.localeData().weekdays(this,e)}),I("e",0,0,"weekday"),I("E",0,0,"isoWeekday"),C("day","d"),C("weekday","e"),C("isoWeekday","E"),F("day",11),F("weekday",11),F("isoWeekday",11),ue("d",B),ue("e",B),ue("E",B),ue("dd",function(e,t){return t.weekdaysMinRegex(e)}),ue("ddd",function(e,t){return t.weekdaysShortRegex(e)}),ue("dddd",function(e,t){return t.weekdaysRegex(e)}),fe(["dd","ddd","dddd"],function(e,t,n,s){var i=n._locale.weekdaysParse(e,s,n._strict);null!=i?t.d=i:g(n).invalidWeekday=e}),fe(["d","e","E"],function(e,t,n,s){t[s]=D(e)});var Ze="Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_");var ze="Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_");var $e="Su_Mo_Tu_We_Th_Fr_Sa".split("_");var qe=ae;var Je=ae;var Be=ae;function Qe(){function e(e,t){return t.length-e.length}var t,n,s,i,r,a=[],o=[],u=[],l=[];for(t=0;t<7;t++)n=y([2e3,1]).day(t),s=this.weekdaysMin(n,""),i=this.weekdaysShort(n,""),r=this.weekdays(n,""),a.push(s),o.push(i),u.push(r),l.push(s),l.push(i),l.push(r);for(a.sort(e),o.sort(e),u.sort(e),l.sort(e),t=0;t<7;t++)o[t]=he(o[t]),u[t]=he(u[t]),l[t]=he(l[t]);this._weekdaysRegex=new RegExp("^("+l.join("|")+")","i"),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp("^("+u.join("|")+")","i"),this._weekdaysShortStrictRegex=new RegExp("^("+o.join("|")+")","i"),this._weekdaysMinStrictRegex=new RegExp("^("+a.join("|")+")","i")}function Xe(){return this.hours()%12||12}function Ke(e,t){I(e,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)})}function et(e,t){return t._meridiemParse}I("H",["HH",2],0,"hour"),I("h",["hh",2],0,Xe),I("k",["kk",2],0,function(){return this.hours()||24}),I("hmm",0,0,function(){return""+Xe.apply(this)+L(this.minutes(),2)}),I("hmmss",0,0,function(){return""+Xe.apply(this)+L(this.minutes(),2)+L(this.seconds(),2)}),I("Hmm",0,0,function(){return""+this.hours()+L(this.minutes(),2)}),I("Hmmss",0,0,function(){return""+this.hours()+L(this.minutes(),2)+L(this.seconds(),2)}),Ke("a",!0),Ke("A",!1),C("hour","h"),F("hour",13),ue("a",et),ue("A",et),ue("H",B),ue("h",B),ue("k",B),ue("HH",B,z),ue("hh",B,z),ue("kk",B,z),ue("hmm",Q),ue("hmmss",X),ue("Hmm",Q),ue("Hmmss",X),ce(["H","HH"],ge),ce(["k","kk"],function(e,t,n){var s=D(e);t[ge]=24===s?0:s}),ce(["a","A"],function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e}),ce(["h","hh"],function(e,t,n){t[ge]=D(e),g(n).bigHour=!0}),ce("hmm",function(e,t,n){var s=e.length-2;t[ge]=D(e.substr(0,s)),t[ve]=D(e.substr(s)),g(n).bigHour=!0}),ce("hmmss",function(e,t,n){var s=e.length-4,i=e.length-2;t[ge]=D(e.substr(0,s)),t[ve]=D(e.substr(s,2)),t[pe]=D(e.substr(i)),g(n).bigHour=!0}),ce("Hmm",function(e,t,n){var s=e.length-2;t[ge]=D(e.substr(0,s)),t[ve]=D(e.substr(s))}),ce("Hmmss",function(e,t,n){var s=e.length-4,i=e.length-2;t[ge]=D(e.substr(0,s)),t[ve]=D(e.substr(s,2)),t[pe]=D(e.substr(i))});var tt,nt=Te("Hours",!0),st={calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},longDateFormat:{LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},invalidDate:"Invalid date",ordinal:"%d",dayOfMonthOrdinalParse:/\d{1,2}/,relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",ss:"%d seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},months:Ce,monthsShort:He,week:{dow:0,doy:6},weekdays:Ze,weekdaysMin:$e,weekdaysShort:ze,meridiemParse:/[ap]\.?m?\.?/i},it={},rt={};function at(e){return e?e.toLowerCase().replace("_","-"):e}function ot(e){var t=null;if(!it[e]&&"undefined"!=typeof module&&module&&module.exports)try{t=tt._abbr,require("./locale/"+e),ut(t)}catch(e){}return it[e]}function ut(e,t){var n;return e&&((n=l(t)?ht(e):lt(e,t))?tt=n:"undefined"!=typeof console&&console.warn&&console.warn("Locale "+e+" not found. Did you forget to load it?")),tt._abbr}function lt(e,t){if(null===t)return delete it[e],null;var n,s=st;if(t.abbr=e,null!=it[e])T("defineLocaleOverride","use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info."),s=it[e]._config;else if(null!=t.parentLocale)if(null!=it[t.parentLocale])s=it[t.parentLocale]._config;else{if(null==(n=ot(t.parentLocale)))return rt[t.parentLocale]||(rt[t.parentLocale]=[]),rt[t.parentLocale].push({name:e,config:t}),null;s=n._config}return it[e]=new P(x(s,t)),rt[e]&&rt[e].forEach(function(e){lt(e.name,e.config)}),ut(e),it[e]}function ht(e){var t;if(e&&e._locale&&e._locale._abbr&&(e=e._locale._abbr),!e)return tt;if(!o(e)){if(t=ot(e))return t;e=[e]}return function(e){for(var t,n,s,i,r=0;r=t&&a(i,n,!0)>=t-1)break;t--}r++}return tt}(e)}function dt(e){var t,n=e._a;return n&&-2===g(e).overflow&&(t=n[_e]<0||11Pe(n[me],n[_e])?ye:n[ge]<0||24Ae(n,r,a)?g(e)._overflowWeeks=!0:null!=u?g(e)._overflowWeekday=!0:(o=Ee(n,s,i,r,a),e._a[me]=o.year,e._dayOfYear=o.dayOfYear)}(e),null!=e._dayOfYear&&(r=ct(e._a[me],s[me]),(e._dayOfYear>Se(r)||0===e._dayOfYear)&&(g(e)._overflowDayOfYear=!0),n=Ge(r,0,e._dayOfYear),e._a[_e]=n.getUTCMonth(),e._a[ye]=n.getUTCDate()),t=0;t<3&&null==e._a[t];++t)e._a[t]=a[t]=s[t];for(;t<7;t++)e._a[t]=a[t]=null==e._a[t]?2===t?1:0:e._a[t];24===e._a[ge]&&0===e._a[ve]&&0===e._a[pe]&&0===e._a[we]&&(e._nextDay=!0,e._a[ge]=0),e._d=(e._useUTC?Ge:function(e,t,n,s,i,r,a){var o;return e<100&&0<=e?(o=new Date(e+400,t,n,s,i,r,a),isFinite(o.getFullYear())&&o.setFullYear(e)):o=new Date(e,t,n,s,i,r,a),o}).apply(null,a),i=e._useUTC?e._d.getUTCDay():e._d.getDay(),null!=e._tzm&&e._d.setUTCMinutes(e._d.getUTCMinutes()-e._tzm),e._nextDay&&(e._a[ge]=24),e._w&&void 0!==e._w.d&&e._w.d!==i&&(g(e).weekdayMismatch=!0)}}var mt=/^\s*((?:[+-]\d{6}|\d{4})-(?:\d\d-\d\d|W\d\d-\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?::\d\d(?::\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/,_t=/^\s*((?:[+-]\d{6}|\d{4})(?:\d\d\d\d|W\d\d\d|W\d\d|\d\d\d|\d\d))(?:(T| )(\d\d(?:\d\d(?:\d\d(?:[.,]\d+)?)?)?)([\+\-]\d\d(?::?\d\d)?|\s*Z)?)?$/,yt=/Z|[+-]\d\d(?::?\d\d)?/,gt=[["YYYYYY-MM-DD",/[+-]\d{6}-\d\d-\d\d/],["YYYY-MM-DD",/\d{4}-\d\d-\d\d/],["GGGG-[W]WW-E",/\d{4}-W\d\d-\d/],["GGGG-[W]WW",/\d{4}-W\d\d/,!1],["YYYY-DDD",/\d{4}-\d{3}/],["YYYY-MM",/\d{4}-\d\d/,!1],["YYYYYYMMDD",/[+-]\d{10}/],["YYYYMMDD",/\d{8}/],["GGGG[W]WWE",/\d{4}W\d{3}/],["GGGG[W]WW",/\d{4}W\d{2}/,!1],["YYYYDDD",/\d{7}/]],vt=[["HH:mm:ss.SSSS",/\d\d:\d\d:\d\d\.\d+/],["HH:mm:ss,SSSS",/\d\d:\d\d:\d\d,\d+/],["HH:mm:ss",/\d\d:\d\d:\d\d/],["HH:mm",/\d\d:\d\d/],["HHmmss.SSSS",/\d\d\d\d\d\d\.\d+/],["HHmmss,SSSS",/\d\d\d\d\d\d,\d+/],["HHmmss",/\d\d\d\d\d\d/],["HHmm",/\d\d\d\d/],["HH",/\d\d/]],pt=/^\/?Date\((\-?\d+)/i;function wt(e){var t,n,s,i,r,a,o=e._i,u=mt.exec(o)||_t.exec(o);if(u){for(g(e).iso=!0,t=0,n=gt.length;tn.valueOf():n.valueOf()this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()},mn.isLocal=function(){return!!this.isValid()&&!this._isUTC},mn.isUtcOffset=function(){return!!this.isValid()&&this._isUTC},mn.isUtc=Et,mn.isUTC=Et,mn.zoneAbbr=function(){return this._isUTC?"UTC":""},mn.zoneName=function(){return this._isUTC?"Coordinated Universal Time":""},mn.dates=n("dates accessor is deprecated. Use date instead.",un),mn.months=n("months accessor is deprecated. Use month instead",Ue),mn.years=n("years accessor is deprecated. Use year instead",Oe),mn.zone=n("moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/",function(e,t){return null!=e?("string"!=typeof e&&(e=-e),this.utcOffset(e,t),this):-this.utcOffset()}),mn.isDSTShifted=n("isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information",function(){if(!l(this._isDSTShifted))return this._isDSTShifted;var e={};if(w(e,this),(e=Ot(e))._a){var t=e._isUTC?y(e._a):bt(e._a);this._isDSTShifted=this.isValid()&&0>16,e>>8&255,255&e,1]}if(r.match(fr)){5!==r.length&&9!==r.length||(r=r.substr(1)),4===r.length&&(r=(r=r.split(""))[0]+r[0]+r[1]+r[1]+r[2]+r[2]+r[3]+r[3]);var n=parseInt(r,16);return[n>>24&255,n>>16&255,n>>8&255,Math.round((255&n)/255*100)/100]}throw new Error("unknown hex color: "+r)},ur=o.type;A.prototype.hex=function(r){return tr(this._rgb,r)},_.hex=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(A,[null].concat(r,["hex"])))},b.format.hex=or,b.autodetect.push({p:4,test:function(r){for(var e=[],n=arguments.length-1;0>16,r>>8&255,255&r,1];throw new Error("unknown num color: "+r)},xe=o.type;A.prototype.num=function(){return Me(this._rgb)},_.num=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(A,[null].concat(r,["num"])))},b.format.num=_e,b.autodetect.push({p:5,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if(1===r.length&&"number"===xe(r[0])&&0<=r[0]&&r[0]<=16777215)return"num"}});var Ae=o.unpack,Ee=o.type,Pe=Math.round;A.prototype.rgb=function(r){return void 0===r&&(r=!0),!1===r?this._rgb.slice(0,3):this._rgb.slice(0,3).map(Pe)},A.prototype.rgba=function(n){return void 0===n&&(n=!0),this._rgb.slice(0,4).map(function(r,e){return e<3?!1===n?r:Pe(r):r})},_.rgb=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(A,[null].concat(r,["rgb"])))},b.format.rgb=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=Ae(r,"rgba");return void 0===n[3]&&(n[3]=1),n},b.autodetect.push({p:3,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if(r=Ae(r,"rgba"),"array"===Ee(r)&&(3===r.length||4===r.length&&"number"==Ee(r[3])&&0<=r[3]&&r[3]<=1))return"rgb"}});var Fe=Math.log,Oe=function(r){var e,n,t,a=r/100;return t=a<66?(e=255,n=-155.25485562709179-.44596950469579133*(n=a-2)+104.49216199393888*Fe(n),a<20?0:.8274096064007395*(t=a-10)-254.76935184120902+115.67994401066147*Fe(t)):(e=351.97690566805693+.114206453784165*(e=a-55)-40.25366309332127*Fe(e),n=325.4494125711974+.07943456536662342*(n=a-50)-28.0852963507957*Fe(n),255),[e,n,t,1]},je=o.unpack,Ge=Math.round,qe=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];for(var n,t=je(r,"rgb"),a=t[0],f=t[2],o=1e3,u=4e4;.4=f/a?u=n:o=n}return Ge(n)};A.prototype.temp=A.prototype.kelvin=A.prototype.temperature=function(){return qe(this._rgb)},_.temp=_.kelvin=_.temperature=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(A,[null].concat(r,["temp"])))},b.format.temp=b.format.kelvin=b.format.temperature=Oe;var Le=o.type;A.prototype.alpha=function(r,e){return void 0===e&&(e=!1),void 0!==r&&"number"===Le(r)?e?(this._rgb[3]=r,this):new A([this._rgb[0],this._rgb[1],this._rgb[2],r],"rgb"):this._rgb[3]},A.prototype.clipped=function(){return this._rgb._clipped||!1},A.prototype.darken=function(r){void 0===r&&(r=1);var e=this.lab();return e[0]-=qr*r,new A(e,"lab").alpha(this.alpha(),!0)},A.prototype.brighten=function(r){return void 0===r&&(r=1),this.darken(-r)},A.prototype.darker=A.prototype.darken,A.prototype.brighter=A.prototype.brighten,A.prototype.get=function(r){var e=r.split("."),n=e[0],t=e[1],a=this[n]();if(t){var f=n.indexOf(t);if(-1=s[n];)n++;return n-1}(r)/(s.length-2):g!==p?(r-p)/(g-p):1;t=k(t),e||(t=w(t)),1!==y&&(t=nn(t,y)),t=d[0]+t*(1-d[0]-d[1]),t=Math.min(1,Math.max(0,t));var a=Math.floor(1e4*t);if(m&&v[a])n=v[a];else{if("array"===en(b))for(var f=0;f=u[e+1];)e++;var n=(r-u[e])/(u[e+1]-u[e]);return o[e]+n*(o[e+1]-o[e])})}}return l=[p,g],N},N.mode=function(r){return arguments.length?(u=r,f(),N):u},N.range=function(r,e){return a(r),N},N.out=function(r){return n=r,N},N.spread=function(r){return arguments.length?(e=r,N):e},N.correctLightness=function(r){return null==r&&(r=!0),t=r,f(),w=t?function(r){for(var e=M(0,!0).lab()[0],n=M(1,!0).lab()[0],t=nn.max&&(n.max=r),n.count+=1)}),n.domain=[n.min,n.max],n.limits=function(r,e){return Nn(n,r,e)},n},Nn=function(r,e,n){void 0===e&&(e="equal"),void 0===n&&(n=7),"array"==Y(r)&&(r=Mn(r));var t=r.min,a=r.max,f=r.values.sort(function(r,e){return r-e});if(1===n)return[t,a];var o=[];if("c"===e.substr(0,1)&&(o.push(t),o.push(a)),"e"===e.substr(0,1)){o.push(t);for(var u=1;u 0");var c=Math.LOG10E*mn(t),i=Math.LOG10E*mn(a);o.push(t);for(var l=1;la?c.indexOf("-"):-1,c=c.replace(/[\+|\-]/g,"")),b._.includes(c,"a")&&(e=c.match(/a(k|m|b|t)?/),e=e?e[1]:!1,b._.includes(c," a")&&(q=" "),c=c.replace(new RegExp(q+"a[kmbt]?"),""),g>=r&&!e||"t"===e?(q+=m.abbreviations.trillion,a/=r):r>g&&g>=s&&!e||"b"===e?(q+=m.abbreviations.billion,a/=s):s>g&&g>=t&&!e||"m"===e?(q+=m.abbreviations.million,a/=t):(t>g&&g>=u&&!e||"k"===e)&&(q+=m.abbreviations.thousand,a/=u)),b._.includes(c,"[.]")&&(o=!0,c=c.replace("[.]",".")),h=a.toString().split(".")[0],i=c.split(".")[1],k=c.indexOf(","),p=(c.split(".")[0].split(",")[0].match(/0/g)||[]).length,i?(b._.includes(i,"[")?(i=i.replace("]",""),i=i.split("["),v=b._.toFixed(a,i[0].length+i[1].length,d,i[1].length)):v=b._.toFixed(a,i.length,d),h=v.split(".")[0],v=b._.includes(v,".")?m.delimiters.decimal+v.split(".")[1]:"",o&&0===Number(v.slice(1))&&(v="")):h=b._.toFixed(a,0,d),q&&!e&&Number(h)>=1e3&&q!==m.abbreviations.trillion)switch(h=String(Number(h)/1e3),q){case m.abbreviations.thousand:q=m.abbreviations.million;break;case m.abbreviations.million:q=m.abbreviations.billion;break;case m.abbreviations.billion:q=m.abbreviations.trillion}if(b._.includes(h,"-")&&(h=h.slice(1),w=!0),h.length0;x--)h="0"+h;return k>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m.delimiters.thousands)),0===c.indexOf(".")&&(h=""),l=h+v+(q?q:""),n?l=(n&&w?"(":"")+l+(n&&w?")":""):j>=0?l=0===j?(w?"-":"+")+l:l+(w?"-":"+"):w&&(l="-"+l),l},stringToNumber:function(a){var b,c,d,e=f[h.currentLocale],g=a,i={thousand:3,million:6,billion:9,trillion:12};if(h.zeroFormat&&a===h.zeroFormat)c=0;else if(h.nullFormat&&a===h.nullFormat||!a.replace(/[^0-9]+/g,"").length)c=null;else{c=1,"."!==e.delimiters.decimal&&(a=a.replace(/\./g,"").replace(e.delimiters.decimal,"."));for(b in i)if(d=new RegExp("[^a-zA-Z]"+e.abbreviations[b]+"(?:\\)|(\\"+e.currency.symbol+")?(?:\\))?)?$"),g.match(d)){c*=Math.pow(10,i[b]);break}c*=(a.split("-").length+Math.min(a.split("(").length-1,a.split(")").length-1))%2?1:-1,a=a.replace(/[^0-9\.]+/g,""),c*=Number(a)}return c},isNaN:function(a){return"number"==typeof a&&isNaN(a)},includes:function(a,b){return-1!==a.indexOf(b)},insert:function(a,b,c){return a.slice(0,c)+b+a.slice(c)},reduce:function(a,b){if(null===this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof b)throw new TypeError(b+" is not a function");var c,d=Object(a),e=d.length>>>0,f=0;if(3===arguments.length)c=arguments[2];else{for(;e>f&&!(f in d);)f++;if(f>=e)throw new TypeError("Reduce of empty array with no initial value");c=d[f++]}for(;e>f;f++)f in d&&(c=b(c,d[f],f,d));return c},multiplier:function(a){var b=a.toString().split(".");return b.length<2?1:Math.pow(10,b[1].length)},correctionFactor:function(){var a=Array.prototype.slice.call(arguments);return a.reduce(function(a,b){var d=c.multiplier(b);return a>d?a:d},1)},toFixed:function(a,b,c,d){var e,f,g,h,i=a.toString().split("."),j=b-(d||0);return e=2===i.length?Math.min(Math.max(i[1].length,j),b):j,g=Math.pow(10,e),h=(c(a+"e+"+e)/g).toFixed(e),d>b-e&&(f=new RegExp("\\.?0{1,"+(d-(b-e))+"}$"),h=h.replace(f,"")),h}},b.options=h,b.formats=e,b.locales=f,b.locale=function(a){return a&&(h.currentLocale=a.toLowerCase()),h.currentLocale},b.localeData=function(a){if(!a)return f[h.currentLocale];if(a=a.toLowerCase(),!f[a])throw new Error("Unknown locale : "+a);return f[a]},b.reset=function(){for(var a in g)h[a]=g[a]},b.zeroFormat=function(a){h.zeroFormat="string"==typeof a?a:null},b.nullFormat=function(a){h.nullFormat="string"==typeof a?a:null},b.defaultFormat=function(a){h.defaultFormat="string"==typeof a?a:"0.0"},b.register=function(a,b,c){if(b=b.toLowerCase(),this[a+"s"][b])throw new TypeError(b+" "+a+" already registered.");return this[a+"s"][b]=c,c},b.validate=function(a,c){var d,e,f,g,h,i,j,k;if("string"!=typeof a&&(a+="",console.warn&&console.warn("Numeral.js: Value is not string. It has been co-erced to: ",a)),a=a.trim(),a.match(/^\d+$/))return!0;if(""===a)return!1;try{j=b.localeData(c)}catch(l){j=b.localeData(b.locale())}return f=j.currency.symbol,h=j.abbreviations,d=j.delimiters.decimal,e="."===j.delimiters.thousands?"\\.":j.delimiters.thousands,k=a.match(/^[^\d]+/),null!==k&&(a=a.substr(1),k[0]!==f)?!1:(k=a.match(/[^\d]+$/),null!==k&&(a=a.slice(0,-1),k[0]!==h.thousand&&k[0]!==h.million&&k[0]!==h.billion&&k[0]!==h.trillion)?!1:(i=new RegExp(e+"{2}"),a.match(/[^\d.,]/g)?!1:(g=a.split(d),g.length>2?!1:g.length<2?!!g[0].match(/^\d+.*\d$/)&&!g[0].match(i):1===g[0].length?!!g[0].match(/^\d+$/)&&!g[0].match(i)&&!!g[1].match(/^\d+$/):!!g[0].match(/^\d+.*\d$/)&&!g[0].match(i)&&!!g[1].match(/^\d+$/))))},b.fn=a.prototype={clone:function(){return b(this)},format:function(a,c){var d,f,g,i=this._value,j=a||h.defaultFormat;if(c=c||Math.round,0===i&&null!==h.zeroFormat)f=h.zeroFormat;else if(null===i&&null!==h.nullFormat)f=h.nullFormat;else{for(d in e)if(j.match(e[d].regexps.format)){g=e[d].format;break}g=g||b._.numberToFormat,f=g(i,j,c)}return f},value:function(){return this._value},input:function(){return this._input},set:function(a){return this._value=Number(a),this},add:function(a){function b(a,b,c,e){return a+Math.round(d*b)}var d=c.correctionFactor.call(null,this._value,a);return this._value=c.reduce([this._value,a],b,0)/d,this},subtract:function(a){function b(a,b,c,e){return a-Math.round(d*b)}var d=c.correctionFactor.call(null,this._value,a);return this._value=c.reduce([a],b,Math.round(this._value*d))/d,this},multiply:function(a){function b(a,b,d,e){var f=c.correctionFactor(a,b);return Math.round(a*f)*Math.round(b*f)/Math.round(f*f)}return this._value=c.reduce([this._value,a],b,1),this},divide:function(a){function b(a,b,d,e){var f=c.correctionFactor(a,b);return Math.round(a*f)/Math.round(b*f)}return this._value=c.reduce([this._value,a],b),this},difference:function(a){return Math.abs(b(this._value).subtract(a).value())}},b.register("locale","en",{delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"$"}}),function(){b.register("format","bps",{regexps:{format:/(BPS)/,unformat:/(BPS)/},format:function(a,c,d){var e,f=b._.includes(c," BPS")?" ":"";return a=1e4*a,c=c.replace(/\s?BPS/,""),e=b._.numberToFormat(a,c,d),b._.includes(e,")")?(e=e.split(""),e.splice(-1,0,f+"BPS"),e=e.join("")):e=e+f+"BPS",e},unformat:function(a){return+(1e-4*b._.stringToNumber(a)).toFixed(15)}})}(),function(){var a={base:1e3,suffixes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]},c={base:1024,suffixes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},d=a.suffixes.concat(c.suffixes.filter(function(b){return a.suffixes.indexOf(b)<0})),e=d.join("|");e="("+e.replace("B","B(?!PS)")+")",b.register("format","bytes",{regexps:{format:/([0\s]i?b)/,unformat:new RegExp(e)},format:function(d,e,f){var g,h,i,j,k=b._.includes(e,"ib")?c:a,l=b._.includes(e," b")||b._.includes(e," ib")?" ":"";for(e=e.replace(/\s?i?b/,""),h=0;h<=k.suffixes.length;h++)if(i=Math.pow(k.base,h),j=Math.pow(k.base,h+1),null===d||0===d||d>=i&&j>d){l+=k.suffixes[h],i>0&&(d/=i);break}return g=b._.numberToFormat(d,e,f),g+l},unformat:function(d){var e,f,g=b._.stringToNumber(d);if(g){for(e=a.suffixes.length-1;e>=0;e--){if(b._.includes(d,a.suffixes[e])){f=Math.pow(a.base,e);break}if(b._.includes(d,c.suffixes[e])){f=Math.pow(c.base,e);break}}g*=f||1}return g}})}(),function(){b.register("format","currency",{regexps:{format:/(\$)/},format:function(a,c,d){var e,f,g,h=b.locales[b.options.currentLocale],i={before:c.match(/^([\+|\-|\(|\s|\$]*)/)[0],after:c.match(/([\+|\-|\)|\s|\$]*)$/)[0]};for(c=c.replace(/\s?\$\s?/,""),e=b._.numberToFormat(a,c,d),a>=0?(i.before=i.before.replace(/[\-\(]/,""),i.after=i.after.replace(/[\-\)]/,"")):0>a&&!b._.includes(i.before,"-")&&!b._.includes(i.before,"(")&&(i.before="-"+i.before),g=0;g=0;g--)switch(f=i.after[g]){case"$":e=g===i.after.length-1?e+h.currency.symbol:b._.insert(e,h.currency.symbol,-(i.after.length-(1+g)));break;case" ":e=g===i.after.length-1?e+" ":b._.insert(e," ",-(i.after.length-(1+g)+h.currency.symbol.length-1))}return e}})}(),function(){b.register("format","exponential",{regexps:{format:/(e\+|e-)/,unformat:/(e\+|e-)/},format:function(a,c,d){var e,f="number"!=typeof a||b._.isNaN(a)?"0e+0":a.toExponential(),g=f.split("e");return c=c.replace(/e[\+|\-]{1}0/,""),e=b._.numberToFormat(Number(g[0]),c,d),e+"e"+g[1]},unformat:function(a){function c(a,c,d,e){var f=b._.correctionFactor(a,c),g=a*f*(c*f)/(f*f);return g}var d=b._.includes(a,"e+")?a.split("e+"):a.split("e-"),e=Number(d[0]),f=Number(d[1]);return f=b._.includes(a,"e-")?f*=-1:f,b._.reduce([e,Math.pow(10,f)],c,1)}})}(),function(){b.register("format","ordinal",{regexps:{format:/(o)/},format:function(a,c,d){var e,f=b.locales[b.options.currentLocale],g=b._.includes(c," o")?" ":"";return c=c.replace(/\s?o/,""),g+=f.ordinal(a),e=b._.numberToFormat(a,c,d),e+g}})}(),function(){b.register("format","percentage",{regexps:{format:/(%)/,unformat:/(%)/},format:function(a,c,d){var e,f=b._.includes(c," %")?" ":"";return b.options.scalePercentBy100&&(a=100*a),c=c.replace(/\s?\%/,""),e=b._.numberToFormat(a,c,d),b._.includes(e,")")?(e=e.split(""),e.splice(-1,0,f+"%"),e=e.join("")):e=e+f+"%",e},unformat:function(a){var c=b._.stringToNumber(a);return b.options.scalePercentBy100?.01*c:c}})}(),function(){b.register("format","time",{regexps:{format:/(:)/,unformat:/(:)/},format:function(a,b,c){var d=Math.floor(a/60/60),e=Math.floor((a-60*d*60)/60),f=Math.round(a-60*d*60-60*e);return d+":"+(10>e?"0"+e:e)+":"+(10>f?"0"+f:f)},unformat:function(a){var b=a.split(":"),c=0;return 3===b.length?(c+=60*Number(b[0])*60,c+=60*Number(b[1]),c+=Number(b[2])):2===b.length&&(c+=60*Number(b[0]),c+=Number(b[1])),Number(c)}})}(),b}); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var dataform = function () { function dataform(options) { var _this = this; _classCallCheck(this, dataform); this.submit = function (options) { if (_this.options.path) { _this.submit_state = 'submitting'; _this.render(); var postOptions = { on_success: function on_success(ob) { if (ob.response && ob.response.valid == true) { _this.probs = false; if (_this.options.on_submit_complete) { _this.options.on_submit_complete({ response: ob.response }); } _this.submit_state = false; _this.submitted_count++; _this.render(); } else { // console.log(ob); _this.submit_state = false; if (ob.response && ob.response.probs) { _this.probs = ob.response.probs; if (_this.options.on_submit_fail) { _this.options.on_submit_fail({ response: ob.response }); } } _this.render(); } } }; if (_this.options.path_format) { postOptions.path_format = _this.options.path_format; } ui.controller.formPost(_this.options.path, _this.data, postOptions); } else { console.error('No form path.'); } }; this.render = function () { if (_this.context) { _this.context.setState({ version: Date.now() }); } }; this.options = options; this.data = this.options.data || {}; this.context = this.options.context || false; this.probs = false; this.submitted_count = 0; this.submit_state = false; } _createClass(dataform, [{ key: 'update', value: function update(updates) { for (var dataKey in updates) { if (updates.hasOwnProperty(dataKey)) { if (this.data[dataKey] != updates[dataKey]) { this.data[dataKey] = updates[dataKey]; delete this.probs[dataKey]; } } } this.render(); } }]); return dataform; }(); var Controls = function (_preact$Component) { _inherits(Controls, _preact$Component); function Controls() { _classCallCheck(this, Controls); var _this2 = _possibleConstructorReturn(this, (Controls.__proto__ || Object.getPrototypeOf(Controls)).call(this)); _this2.state = {}; return _this2; } _createClass(Controls, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var controls = []; if (this.props.items) { for (var itemKey in this.props.items) { if (this.props.items.hasOwnProperty(itemKey)) { var item = this.props.items[itemKey]; controls.push(e('div', { id: itemKey, class: 'controls-item' }, e(Button, item))); } } } return e('div', { class: 'controls' }, controls); } }]); return Controls; }(preact.Component); var Probs = function (_preact$Component2) { _inherits(Probs, _preact$Component2); function Probs() { _classCallCheck(this, Probs); var _this3 = _possibleConstructorReturn(this, (Probs.__proto__ || Object.getPrototypeOf(Probs)).call(this)); _this3.state = {}; return _this3; } _createClass(Probs, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var probs = []; if (this.props.items) { for (var itemKey in this.props.items) { if (this.props.items.hasOwnProperty(itemKey)) { var item = this.props.items[itemKey]; probs.push(e('div', { id: itemKey, class: 'probs-item' }, this.props.items[itemKey])); } } } return e('div', { class: 'probs' }, probs); } }]); return Probs; }(preact.Component); var Button = function (_preact$Component3) { _inherits(Button, _preact$Component3); function Button() { _classCallCheck(this, Button); var _this4 = _possibleConstructorReturn(this, (Button.__proto__ || Object.getPrototypeOf(Button)).call(this)); _this4.click = function (event) { if (_this4.props.onClick) { event.preventDefault(); event.stopPropagation(); _this4.props.onClick({ event: event }); } }; _this4.state = {}; return _this4; } _createClass(Button, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var classes = ['button']; if (this.props.color) { classes.push('color-' + this.props.color); } return e('button', { onClick: this.click, class: classes.join(' ') }, this.props.title); } }]); return Button; }(preact.Component); var Timeslot = function (_preact$Component4) { _inherits(Timeslot, _preact$Component4); function Timeslot() { _classCallCheck(this, Timeslot); var _this5 = _possibleConstructorReturn(this, (Timeslot.__proto__ || Object.getPrototypeOf(Timeslot)).call(this)); _this5.click = function (event) {}; _this5.state = {}; return _this5; } _createClass(Timeslot, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var _this6 = this; var classes = ['timeslot']; var dayData = {}; var slots = this.props.field.slots().map(function (slot) { // console.log(slot); slot.local = moment.utc(slot.date).local().clone(); // console.log(slot.local.format('l h:mm A')); if (!dayData[slot.local.format('YYYY-MM-DD')]) { dayData[slot.local.format('YYYY-MM-DD')] = { available: [] }; } dayData[slot.local.format('YYYY-MM-DD')].available.push(slot); return slot; }); var days = []; var curDate = moment().startOf('week'); var weeksNumbers = [1, 2]; var weekItems = weeksNumbers.map(function (week) { var days = []; var available = []; for (var i = 1; i <= 7; i++) { available = []; if (dayData[curDate.format('YYYY-MM-DD')]) { available = dayData[curDate.format('YYYY-MM-DD')].available; } available = available.sort(function (a, b) { if (a.date > b.date) return 1; if (a.date < b.date) return -1; return 0; }); days.push({ date: curDate.format('YYYY-MM-DD'), moment: curDate.clone(), available: available }); curDate.add(1, 'day'); } return { week: week, days: days }; }); var dateToday = moment().format('YYYY-MM-DD'); var dateTomorrow = moment().add(1, 'day').format('YYYY-MM-DD'); var weeks = weekItems.map(function (week) { var days = week.days.map(function (day) { var useDay = true; if (day.moment.format('dddd') == 'Sunday') useDay = false; if (day.moment.format('dddd') == 'Saturday') useDay = false; if (useDay) { var _slots = day.available.map(function (slot) { var slotValue = slot.local.format('YYYY-MM-DD HH:mm:ss'); var classes = ['timeslot-week-day-slots-slot']; if (_this6.props.dataform.data[_this6.props.field_name] == slotValue) { classes.push('active'); } return e('div', { onClick: function onClick() { // console.log(slotValue); // console.log(this.props); _this6.props.dataform.update(_defineProperty({}, _this6.props.field_name, slotValue)); }, class: classes.join(' ') }, e('div', { class: 'timeslot-week-day-slots-slot-time' }, slot.local.format('h:mm A'))); }); var dayHead = []; if (dateToday == day.moment.format('YYYY-MM-DD')) { dayHead.push(e('div', { class: 'timeslot-week-day-head-label' }, 'Today')); } else if (dateTomorrow == day.moment.format('YYYY-MM-DD')) { dayHead.push(e('div', { class: 'timeslot-week-day-head-label' }, 'Tomorrow')); } else { dayHead.push(e('div', { class: 'timeslot-week-day-head-weekday' }, day.moment.format('ddd'))); dayHead.push(e('div', { class: 'timeslot-week-day-head-month' }, day.moment.format('MMM'))); dayHead.push(e('div', { class: 'timeslot-week-day-head-date' }, day.moment.format('D'))); } return e('div', { class: 'timeslot-week-day' }, e('div', { class: 'timeslot-week-day-head' }, dayHead), e('div', { class: 'timeslot-week-day-slots' }, _slots)); } }); return e('div', { class: 'timeslot-week' }, days); }); var tz = Intl.DateTimeFormat().resolvedOptions().timeZone; tz = tz.replace('/', ' / '); tz = tz.replace(/_/g, ' '); return [e('div', { onClick: this.click, class: classes.join(' ') }, weeks),, e('div', { class: 'timeslot-tz' }, 'Available times are ' + tz + ' timezone.')]; } }]); return Timeslot; }(preact.Component); var Form = function (_preact$Component5) { _inherits(Form, _preact$Component5); function Form() { _classCallCheck(this, Form); var _this7 = _possibleConstructorReturn(this, (Form.__proto__ || Object.getPrototypeOf(Form)).call(this)); _this7.inputKeyUp = function (ob) { if (ob.event.keyCode === 13) { if (_this7.props.dataform && _this7.props.dataform.options.form_enter) { _this7.props.dataform.options.form_enter(ob); } else if (_this7.props.dataform) { ob.event.target.blur(); _this7.props.dataform.submit(); setTimeout(function () { ob.event.target.focus(); }, 20); } } else { return _this7.inputChange(ob); } }; _this7.inputChange = function (ob) { if (_this7.props.dataform) { if (ob.value) { _this7.props.dataform.update(_defineProperty({}, ob.field, ob.value)); } else if (ob.event) { _this7.props.dataform.update(_defineProperty({}, ob.field, ob.event.target.value)); } } }; _this7.state = {}; return _this7; } _createClass(Form, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var _this8 = this; var fields = []; var formClasses = ['form']; if (this.props.dataform && this.props.dataform.submit_state == 'submitting') { formClasses.push('submitting'); } if (this.props.dataform && this.props.dataform.submitted_count > 0) { formClasses.push('submitted'); } if (this.props.fields) { for (var fieldKey in this.props.fields) { if (this.props.fields.hasOwnProperty(fieldKey)) { var placeholder; var prob; var optionKey; (function () { var fieldClasses = ['field']; var field = _this8.props.fields[fieldKey]; var inputType = field.input_type || 'text'; var input = null; var label = null; var value = ''; if (_this8.props.data && _this8.props.data[fieldKey]) { value = _this8.props.data[fieldKey]; } else if (_this8.props.dataform && _this8.props.dataform.data && _this8.props.dataform.data[fieldKey]) { value = _this8.props.dataform.data[fieldKey]; } if (field.input_type == 'togglebuttons') { if (!Array.isArray(value)) { value = []; } } placeholder = null; if (_this8.props.placeholder) { placeholder = field.title; } if (!placeholder) { label = e('div', { class: 'field-label' }, field.title); } prob = null; if (_this8.props.dataform && _this8.props.dataform.probs && _this8.props.dataform.probs[fieldKey]) { prob = e('div', { class: 'field-prob' }, _this8.props.dataform.probs[fieldKey]); } if (field.input_type == 'timeslot') { input = e(Timeslot, { field_name: fieldKey, field: field, dataform: _this8.props.dataform }); } else if (field.input_type == 'togglebuttons') { var buttons = []; for (optionKey in field.options) { if (field.options.hasOwnProperty(optionKey)) { (function () { var option = optionKey; var optionItem = field.options[optionKey]; var classes = ['field-togglebuttons-button']; if (value.indexOf(optionKey) !== -1) { classes.push('active'); } buttons.push(e('div', { onClick: function onClick(event) { // console.log(event); if (value.indexOf(option) === -1) { value.push(option); } else { value = value.filter(function (item) { if (item == option) return false; return true; }); } _this8.inputChange({ field: fieldKey, value: value }); }, class: classes.join(' ') }, e('div', { class: 'field-togglebuttons-button-title' }, optionItem.title))); })(); } } input = e('div', { class: 'field-togglebuttons' }, buttons); } else if (field.input_type === 'textarea') { input = e('textarea', { tabIndex: 1, placeholder: placeholder, onKeyUp: function (fieldKey, event) { this.inputKeyUp({ event: event, field: fieldKey }); }.bind(_this8, fieldKey), type: inputType, defaultValue: value }); } else { if (_this8.props.hasOwnProperty('is_current') && _this8.props.is_current == false) { input = e('div', { class: 'field-not-current' }, value); } else { input = e('input', { // onChange: event => { // this.inputChange({ // event, // field: fieldKey // }); // }, tabIndex: 1, placeholder: placeholder, onKeyUp: function (fieldKey, event) { this.inputKeyUp({ event: event, field: fieldKey }); }.bind(_this8, fieldKey), type: inputType, value: value }); } } fields.push(e('div', { class: fieldClasses.join(' ') }, label, e('div', { class: 'field-input text' }, input), prob)); })(); } } } return e('div', { class: formClasses.join(' ') }, fields); } }]); return Form; }(preact.Component); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Ui = function Ui(options) { _classCallCheck(this, Ui); // console.log(options); this.options = options; this.tab = Math.floor(Date.now() / 1000); this.controller = Ui_controller ? new Ui_controller(this) : false; this.dom = Ui_dom ? new Ui_dom(this) : false; this.layout = Ui_layout ? new Ui_layout(this) : false; this.color = Ui_color ? new Ui_color(this) : false; }; function Component(options) { var _this = this; this.options = options; this.id = options.id; this.data = options.data || {}; this.root = document.getElementById('component_' + this.id); this.state = options.state || {}; this.element = new window[options.component](this); this.setState = function (state, callback) { Object.assign(_this.state, state); _this.render(callback); }; this.before = function () { if (_this.element.before) { _this.element.before(); } }; this.render = function (callback) { if (_this.element.render) { _this.element.render(); } if (callback) { callback(); } }; this.before(); this.render(); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Ui_controller = function Ui_controller(ui) { var _this = this; _classCallCheck(this, Ui_controller); this.formPost = function (path, data, options) { options = options || {}; var pathFormat = options.path_format || 'form_view'; var url = void 0; if (pathFormat == 'direct') { url = _this.appUrl(path, false, { direct: true }); } else { url = _this.appUrl('controller/form_view/' + path + '.htp', { recupdate_action: 'update' }); } fetch(url, { method: 'POST', // or 'PUT' headers: { 'Content-Type': 'text/plain' }, body: JSON.stringify({ data: data }) }).then(function (response) { return response.json(); }).then(function (data) { if (options.on_success) { options.on_success({ response: data }); } }).catch(function (error) { if (options.on_error) { options.on_error({ response: data }); } }); }; this.appUrl = function (path, addParams, options) { var url = []; var qs = []; options = options || {}; if (!options.direct) { url.push(_this.ui.options.app_url_root); } url.push(path); var params = { s: _this.ui.options.site, p: _this.ui.options.page, ul_client_date: new Date().toISOString(), ul_client_key: _this.ui.options.ul_client_key, ul_app_id: _this.ui.options.app, uslapp_session: _this.ui.options.uslapp_session, ul_client_tab: _this.ui.tab }; if (addParams) { for (var paramKey in addParams) { if (addParams.hasOwnProperty(paramKey)) { params[paramKey] = addParams[paramKey]; } } } for (var paramKey in params) { if (params.hasOwnProperty(paramKey)) { qs.push(paramKey + '=' + encodeURIComponent(params[paramKey])); } } if (path.indexOf('?') !== -1) { url.push('&' + qs.join('&')); } else { url.push('?' + qs.join('&')); } return url.join(''); }; this.ui = ui; }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Ui_dom = function Ui_dom(ui) { var _this = this; _classCallCheck(this, Ui_dom); this.ini = function () { _this.iniResize(); _this.iniScroll(); _this.iniFeatures(); _this.iniIntersect(); }; this.sslCheck = function () { if (location.protocol != 'https:') { location.href = 'https:' + window.location.href.substring(window.location.protocol.length); } }; this.uid = function () { return _this.uidcur++; }; this.checkAll = function () { _this.checkScroll(); _this.checkMobile(); }; this.iniIntersect = function () { var options = { root: document.querySelector('#scrollArea'), rootMargin: '0px', threshold: .4 }; _this.observer = new IntersectionObserver(_this.intersectCallback, options); }; this.backgroundToImge = function (backgroundSelector, imageSelector) { var bg = document.querySelector(backgroundSelector); var img = document.querySelector(imageSelector); var style = bg.currentStyle || window.getComputedStyle(bg, false); var bi = style.backgroundImage.slice(4, -1).replace(/"/g, ""); img.src = bi; console.log(bi); }; this.intersectCallback = function (entries, observer) { // console.log(entries); entries.forEach(function (entry) { // console.log(entry); if (entry.isIntersecting) { entry.target.classList.remove('ui-dom-intersect-below'); entry.target.classList.remove('ui-dom-intersect-above'); entry.target.classList.add('ui-dom-intersect-in'); entry.target.classList.remove('ui-dom-intersect-out'); } else { var windowHeightHalf = window.outerHeight / 2; if (entry.boundingClientRect.bottom > windowHeightHalf) { entry.target.classList.add('ui-dom-intersect-below'); entry.target.classList.remove('ui-dom-intersect-above'); } else { entry.target.classList.remove('ui-dom-intersect-below'); entry.target.classList.add('ui-dom-intersect-above'); } entry.target.classList.remove('ui-dom-intersect-in'); entry.target.classList.add('ui-dom-intersect-out'); } // Each entry describes an intersection change for one observed // target element: // entry.boundingClientRect // entry.intersectionRatio // entry.intersectionRect // entry.isIntersecting // entry.rootBounds // entry.target // entry.time }); }; this.iniScroll = function () { _this.checkScrollLastTop = 0; window.addEventListener('scroll', _this.checkScroll); }; this.iniResize = function () { window.addEventListener('resize', _this.checkAll); }; this.iniFeatures = function () { _this.featureWebP(); }; this.featureWebP = function () { var webP = false; var elem = document.createElement('canvas'); if (!!(elem.getContext && elem.getContext('2d'))) { webP = elem.toDataURL('image/webp').indexOf('data:image/webp') == 0; } if (webP) { document.documentElement.classList.add('f-webp'); _this.sup.webp = true; } else { document.documentElement.classList.add('f-webp-0'); _this.sup.webp = false; } }; this.checkScroll = function () { var top = (window.pageYOffset || document.scrollTop) - (document.clientTop || 0); var scrollDiff = top - _this.checkScrollLastTop; // console.log(scrollDiff); if (top > _this.checkScrollLastTop) { document.body.classList.add('scrolling-last-down'); document.body.classList.remove('scrolling-last-up'); } else if (top < _this.checkScrollLastTop) { document.body.classList.remove('scrolling-last-down'); document.body.classList.add('scrolling-last-up'); } _this.checkScrollLastTop = top; if (top >= 10) { document.body.classList.add('scrolled-down'); document.body.classList.remove('scrolled-up'); } else { document.body.classList.remove('scrolled-down'); document.body.classList.add('scrolled-up'); } }; this.checkMobile = function () { console.log(document.body.clientWidth); if (document.body.clientWidth > 800) { _this.screen = 'desktop'; document.body.classList.add('desktop'); document.body.classList.remove('mobile'); } else { _this.screen = 'mobile'; document.body.classList.remove('desktop'); document.body.classList.add('mobile'); } }; this.ui = ui; this.screen = false; this.sup = { webp: false }; this.checkAll(); this.ini(); this.uidcur = 1; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Ui_layout = function () { function Ui_layout(ui) { _classCallCheck(this, Ui_layout); this.ui = ui; } _createClass(Ui_layout, [{ key: "autoMatrix", value: function autoMatrix(options) { var width = options.width, height = options.height, items = options.items, padding = options.padding; var itemsUse = items.slice(0); var count = itemsUse.length; var grid = { x: 0, y: 0 }; while (grid.x * grid.y < count) { if (width > height) { if (count == 3) { grid.x = 2; grid.y = 1; } grid.x++; if (grid.x * grid.y >= count) break; grid.y++; if (grid.x * grid.y >= count) break; } else { grid.y++; if (grid.x * grid.y >= count) break; grid.x++; if (grid.x * grid.y >= count) break; } } var remainder = grid.x * grid.y - count; var remainderWas = remainder; // console.log(grid); // console.log(remainder); var matrix = { rows: [] }; for (var y = 0; y < grid.y; y++) { var xUse = grid.x; if (remainderWas >= grid.y - y) { if (remainder > 0) { xUse--; remainder--; } } // console.log('xUse', xUse); var newRow = { items: [] }; for (var x = 0; x < xUse; x++) { newRow.items.push(itemsUse.shift()); } matrix.rows.push(newRow); } var itemHeight = (height - padding * (matrix.rows.length + 1)) / matrix.rows.length; var itemWidth = (width - padding * (grid.x + 1)) / grid.x; matrix.rows = matrix.rows.map(function (row, rowKey) { var rowItemSpace = { width: itemWidth, height: itemHeight }; var rowExtraSpace = 0; if (grid.x > row.items.length) { var rowXDiff = grid.x - row.items.length; rowExtraSpace = rowXDiff * (itemWidth + padding) * .5; } row.items = row.items.map(function (item, itemKey) { var itemBox = { width: rowItemSpace.width, height: rowItemSpace.height }; itemBox.left = rowExtraSpace + itemWidth * itemKey + padding * (itemKey + 1); itemBox.top = itemHeight * rowKey + padding * (rowKey + 1); item.box = itemBox; return item; }); return row; }); // console.log(matrix); return matrix; } }]); return Ui_layout; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Ui_color = function () { _createClass(Ui_color, [{ key: 'hexToComplimentary', value: function hexToComplimentary(hex) { // Convert hex to rgb // Credit to Denis http://stackoverflow.com/a/36253499/4939630 var rgb = 'rgb(' + (hex = hex.replace('#', '')).match(new RegExp('(.{' + hex.length / 3 + '})', 'g')).map(function (l) { return parseInt(hex.length % 2 ? l + l : l, 16); }).join(',') + ')'; // Get array of RGB values rgb = rgb.replace(/[^\d,]/g, '').split(','); var r = rgb[0], g = rgb[1], b = rgb[2]; // Convert RGB to HSL // Adapted from answer by 0x000f http://stackoverflow.com/a/34946092/4939630 r /= 255.0; g /= 255.0; b /= 255.0; var max = Math.max(r, g, b); var min = Math.min(r, g, b); var h, s, l = (max + min) / 2.0; if (max == min) { h = s = 0; //achromatic } else { var d = max - min; s = l > 0.5 ? d / (2.0 - max - min) : d / (max + min); if (max == r && g >= b) { h = 1.0472 * (g - b) / d; } else if (max == r && g < b) { h = 1.0472 * (g - b) / d + 6.2832; } else if (max == g) { h = 1.0472 * (b - r) / d + 2.0944; } else if (max == b) { h = 1.0472 * (r - g) / d + 4.1888; } } h = h / 6.2832 * 360.0 + 0; // Shift hue to opposite side of wheel and convert to [0-1] value h += 180; if (h > 360) { h -= 360; } h /= 360; // Convert h s and l values into r g and b values // Adapted from answer by Mohsen http://stackoverflow.com/a/9493060/4939630 if (s === 0) { r = g = b = l; // achromatic } else { var hue2rgb = function hue2rgb(p, q, t) { if (t < 0) t += 1; if (t > 1) t -= 1; if (t < 1 / 6) return p + (q - p) * 6 * t; if (t < 1 / 2) return q; if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; return p; }; var q = l < 0.5 ? l * (1 + s) : l + s - l * s; var p = 2 * l - q; r = hue2rgb(p, q, h + 1 / 3); g = hue2rgb(p, q, h); b = hue2rgb(p, q, h - 1 / 3); } r = Math.round(r * 255); g = Math.round(g * 255); b = Math.round(b * 255); // Convert r b and g values to hex rgb = b | g << 8 | r << 16; return "#" + (0x1000000 | rgb).toString(16).substring(1); } }]); function Ui_color(ui) { _classCallCheck(this, Ui_color); this.ui = ui; } return Ui_color; }(); var headMenusOpen = {}; function headMenu(component) { var _this = this; this.c = component; this.select = function (selected) { _this.c.setState({ selected: selected }); }; this.menuOpen = false; this.timers = {}; this.overNav = false; this.overDisplay = false; this.focused = false; this.timing = { enter: 200, leave: 200, duration: 200 }; this.showStarting = false; this.displayElmEnter = function () { _this.overDisplay = true; if (_this.timers.leaving) { clearTimeout(_this.timers.leaving); } }; this.displayElmLeave = function () { if (_this.focused) return false; _this.overDisplay = false; _this.timers.leaving = setTimeout(function () { _this.hideNow(); }, _this.timing.leave); }; this.menuElmEnter = function () { _this.overNav = true; if (_this.timers.leaving) { clearTimeout(_this.timers.leaving); } _this.timers.showing = setTimeout(function () { // console.log(this.overNav); // console.log(this.overDisplay); if (_this.overNav == true || _this.overDisplay == true) { // console.log('showing'); _this.showNow(); } }, _this.timing.enter); }; this.menuElmLeave = function () { _this.overNav = false; _this.timers.leaving = setTimeout(function () { _this.hideNow(); }, _this.timing.leave); }; this.menuElmClick = function (event) { event.target.blur(); event.preventDefault(); event.stopPropagation(); console.log(event); }; this.displayElmClick = function (event) { // console.log(event); event.preventDefault(); event.stopPropagation(); _this.focused = true; }; // this.leaveStart = () =>{ // if (this.leaveStarting) { // clearTimeout(this.leaveStarting) // } // this.leaveStarting = setTimeout(()=>{ // this.hideNow(); // }, this.timing.leave) // } // this.showStart = () =>{ // // headMenusOpen[this.c.state.id] = true; // if (this.showStarting) { // clearTimeout(this.showStarting) // } // this.showStarting = setTimeout(()=>{ // this.showNow(); // }, this.timing.enter) // } this.showNow = function () { // console.log(Object.keys(headMenusOpen).length); _this.displayElmPosition(); _this.displayElm.classList.add('active'); if (Object.keys(headMenusOpen).length < 2) { _this.displayElm.classList.add('entering'); setTimeout(function () { _this.displayElm.classList.remove('entering'); }, _this.timing.duration); } _this.displayElm.classList.remove('leaving'); }; this.displayElmPosition = function () { var menuBox = _this.menuElm.getBoundingClientRect(); _this.displayElm.style.display = 'block'; var displayBox = _this.displayElm.getBoundingClientRect(); _this.displayElm.style.display = null; var menuBoxCenter = (menuBox.left + menuBox.right) / 2; var newLeft = menuBoxCenter - displayBox.width / 2; if (newLeft < 100) newLeft = 100; _this.displayElm.style.left = newLeft + 'px'; var pointerLeft = menuBoxCenter - newLeft - 8; _this.displayPointerElm.style.marginLeft = pointerLeft + 'px'; }; this.hideNow = function () { delete headMenusOpen[_this.c.state.id]; _this.displayElm.classList.remove('active'); // if (Object.keys(headMenusOpen).length<1) { // this.displayElm.classList.add('leaving'); // setTimeout(()=>{ // this.displayElm.classList.remove('leaving'); // }, this.timing.duration) // } }; this.bodyClick = function (event) { if (_this.focused) { // event.preventDefault(); // event.stopPropagation(); _this.focused = false; _this.hideNow(); } }; this.before = function () { _this.menuElm = document.getElementById('head_menu_' + _this.c.state.id); _this.displayElm = document.getElementById('menu_' + _this.c.state.id); _this.displayPointerElm = document.getElementById('menu_pointer_' + _this.c.state.id); // window.addEventListener('scroll', this.scroll); if (_this.menuElm && _this.displayElm && _this.displayPointerElm) { document.body.addEventListener('click', _this.bodyClick); _this.menuElm.addEventListener('click', _this.menuElmClick); _this.menuElm.addEventListener('mouseenter', _this.menuElmEnter); _this.menuElm.addEventListener('mouseleave', _this.menuElmLeave); if (_this.displayElm.classList.contains('focusable')) { _this.displayElm.addEventListener('click', _this.displayElmClick); } _this.displayElm.addEventListener('mouseenter', _this.displayElmEnter); _this.displayElm.addEventListener('mouseleave', _this.displayElmLeave); } }; this.render = function () { // console.log('render ' + this.c.state.id); }; } function navBurgClick() { if (document.body.classList.contains('menu')) { document.body.classList.remove('menu'); } else { setTimeout(function () { document.body.classList.add('menu'); }, 20); } } function navBind() { document.body.addEventListener('click', navBodyClick); } var navBodyClick = function navBodyClick(event) { if (document.body.classList.contains('menu')) { // console.log('has menu'); var element = document.querySelector('.app-nav-mobile-nav'); if (element) { console.log('has elm'); if (!element.contains(event.target)) { // or use: event.target.closest(selector) === null // console.log('contains target'); document.body.classList.remove('menu'); } } } // console.log('allowing'); }; navBind(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Dashboard_mobile = function (_preact$Component) { _inherits(Dashboard_mobile, _preact$Component); function Dashboard_mobile() { _classCallCheck(this, Dashboard_mobile); var _this = _possibleConstructorReturn(this, (Dashboard_mobile.__proto__ || Object.getPrototypeOf(Dashboard_mobile)).call(this)); _this.ref = null; _this.setRef = function (dom) { return _this.ref = dom; }; _this.resize = function () { _this.setState({ loaded: Date.now() }); setTimeout(function () { _this.setState({ loaded: Date.now() }); }, 1000); setTimeout(function () { _this.setState({ loaded: Date.now() }); }, 2000); }; _this.configParse = function (config) { return config; }; _this.layout = function (options) { var layout = { charts: [] }; var config = options.config; var device = _this.props.device || 'desktop'; if (!_this.ref) return false; // console.log(this.ref); // let box = this.ref. / x /getBoundingClientRect(); var chartMargin = _this.ref.clientWidth * .02; // let orientation = box.width > box.height ? 'landscape' : 'portrait'; var chartWidth = _this.ref.clientWidth - chartMargin * 2; // console.log(chartWidth); var chartHeight = chartWidth / 16 * 9; if (chartWidth > chartHeight) { var chartSize = chartHeight * 0.12; } else { var chartSize = chartWidth * 0.12; } // console.log(box); // console.log(this.ref.clientHeight); // console.log(this.ref.clientWidth); var chartsList = Object.values(config.charts); chartsList = chartsList.sort(function (a, b) { if (a.sortorder < b.sortorder) return -1; if (a.sortorder > b.sortorder) return 1; return 0; }); var addCharts = chartsList.slice(0); chartsList.forEach(function (chart, chartIndex) { var chartBox = {}; chartBox.width = chartWidth; chartBox.margin = chartMargin; chartBox.height = chartHeight; chartBox.fontSize = chartSize * .6; var chartToAdd = addCharts.shift(); chartToAdd = chartToAdd.config; var chartType = 'Chart_placeholder'; chartToAdd.space = { size: chartSize, margin: chartSize * .2, width: chartWidth, height: chartHeight }; chartToAdd.chroma = chroma('#8596a6'); chartToAdd.chroma2 = chroma('#a6cccc'); chartToAdd.palette = ['#0081e5', '#de49a8', '#f68931']; if (window['Chart_' + chartToAdd.type]) { chartType = 'Chart_' + chartToAdd.type; } // console.log(chartToAdd); var component = e('div', { class: 'dashboard-mobile-charts-chart', style: chartBox }, e(window[chartType], chartToAdd)); layout.charts.push(component); }); return layout; }; _this.id = Date.now() + '_' + Math.random(); _this.state = {}; return _this; } _createClass(Dashboard_mobile, [{ key: 'componentDidMount', value: function componentDidMount() { var _this2 = this; this.setState({ loaded: Date.now() }); setTimeout(function () { _this2.setState({ loaded: Date.now() }); }, 1000); window.addEventListener('resize', this.resize); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { window.removeEventListener('resize', this.resize); } }, { key: 'render', value: function render() { var config = this.props.config; var layout = this.layout({ config: config }); return e('div', { ref: this.setRef, class: 'dashboard-mobile' }, e('div', { class: 'dashboard-mobile-charts' }, layout.charts)); } }]); return Dashboard_mobile; }(preact.Component); var Dashboard = function (_preact$Component2) { _inherits(Dashboard, _preact$Component2); function Dashboard() { _classCallCheck(this, Dashboard); var _this3 = _possibleConstructorReturn(this, (Dashboard.__proto__ || Object.getPrototypeOf(Dashboard)).call(this)); _this3.ref = null; _this3.setRef = function (dom) { return _this3.ref = dom; }; _this3.configParse = function (config) { return config; }; _this3.layout = function (options) { var layout = { charts: [] }; var config = options.config; var device = _this3.props.device || 'desktop'; if (!_this3.ref) return false; // console.log(this.ref.parentElement); var box = _this3.ref.getBoundingClientRect(); if (box.height == 0) { _this3.retry = _this3.retry * 1.1; setTimeout(function () { console.log('retry: ' + _this3.retry); _this3.setState({ version: Date.now() }); }, _this3.retry); return null; } var chartMargin = box.width * .01; var orientation = box.width > box.height ? 'landscape' : 'portrait'; // console.log(box); // console.log(this.ref.clientHeight); // console.log(this.ref.clientWidth); var chartsList = Object.values(config.charts); chartsList = chartsList.sort(function (a, b) { if (a.sortorder < b.sortorder) return -1; if (a.sortorder > b.sortorder) return 1; return 0; }); var dims = { x: 0, y: 0 }; var addCharts = chartsList.slice(0); // console.log(chartsList.length); // // console.log(orientation); while (dims.x * dims.y < chartsList.length) { if (orientation == 'landscape') { dims.x++; if (dims.x * dims.y >= chartsList.length) break; dims.y++; if (dims.x * dims.y >= chartsList.length) break; } else { dims.y++; if (dims.x * dims.y >= chartsList.length) break; dims.x++; if (dims.x * dims.y >= chartsList.length) break; } } // console.log(dims); var remainder = dims.x * dims.y % chartsList.length; var grid = { rows: {} }; // var chartSize = // var chartSize = 150 / chartsList.length; // // if (chartSize > 30 ) chartSize =30; // // if (ui.dom.screen=='mobile') { // chartSize = chartSize * .4; // } // console.log(chartsList.length); for (var y = 1; y <= dims.y; y++) { grid.rows[y] = { charts: {} }; var xOffset = 0; if (remainder) { xOffset--; remainder--; } var nonMarginWidth = box.width - (dims.x + xOffset + 1) * chartMargin; var nonMarginHeight = box.height - (dims.y + 1) * chartMargin; var chartWidth = nonMarginWidth / (dims.x + xOffset); var chartHeight = nonMarginHeight / dims.y; if (chartWidth > chartHeight) { var chartSize = chartHeight * 0.12; } else { var chartSize = chartWidth * 0.12; } // // console.log(chartSize); // // var chartSize = chartWidth * chartHeight * 0.0006; // // console.log(chartSize); // if (chartSize > 40) chartSize = 40; // if (ui.dom.screen == 'mobile') { // chartSize = chartSize * 2; // } // console.log('chartSize', chartSize); // console.log('chartSize', chartSize); for (var x = 1; x <= dims.x + xOffset; x++) { var chartBox = {}; chartBox.width = chartWidth; chartBox.height = chartHeight; chartBox.left = (x - 1) * chartWidth + chartMargin * x; chartBox.top = (y - 1) * chartHeight + chartMargin * y; chartBox.fontSize = chartSize * .6; var chartToAdd = addCharts.shift(); chartToAdd = chartToAdd.config; var chartType = 'Chart_placeholder'; chartToAdd.space = { size: chartSize, margin: chartSize * .2, width: chartWidth, height: chartHeight }; chartToAdd.chroma = chroma('#8596a6'); chartToAdd.chroma2 = chroma('#a6cccc'); chartToAdd.palette = [ // '#003f5c', '#8596a6', '#a6cccc', '#c1c3a3']; // chartToAdd.palette = [ // // '#003f5c', // '#df4319', // // '#a6cccc', // // '#c1c3a3', // ] if (chartToAdd.palette.length == 1) { chartToAdd.palette.push('#CCCCCC'); } if (window['Chart_' + chartToAdd.type]) { chartType = 'Chart_' + chartToAdd.type; } // console.log(chartToAdd); var component = e('div', { key: x + '_' + y, class: 'dashboard-charts-chart', style: chartBox }, e(window[chartType], chartToAdd)); grid.rows[y].charts[x] = { chartBox: chartBox }; layout.charts.push(component); } } return layout; }; _this3.id = Date.now() + '_' + Math.random(); _this3.state = {}; _this3.retry = 10; return _this3; } _createClass(Dashboard, [{ key: 'componentDidMount', value: function componentDidMount() { this.setState({ loaded: Date.now() }); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var config = this.props.config; var layout = this.layout({ config: config }); return e('div', { ref: this.setRef, class: 'dashboard' }, e('div', { class: 'dashboard-charts' }, layout.charts)); } }]); return Dashboard; }(preact.Component); var Chart_integration_logo = function (_preact$Component3) { _inherits(Chart_integration_logo, _preact$Component3); function Chart_integration_logo() { _classCallCheck(this, Chart_integration_logo); var _this4 = _possibleConstructorReturn(this, (Chart_integration_logo.__proto__ || Object.getPrototypeOf(Chart_integration_logo)).call(this)); _this4.state = {}; return _this4; } _createClass(Chart_integration_logo, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var integration = integrationsData.items[integrationsData.names[this.props.integration]]; if (!integration) return null; var height = this.props.size || 20; height = height * .5; var width = height * 2; var title = null; if (this.props.title) { title = e('div', { class: 'chart-integration-logo' }, this.props.title); } var spriteUrl = "url('https://vertex.dev.userlite.com/web/amplib/df/items/logotrain/sprite.jpg?items=integrations&format=webp')"; if (ui.dom.screen == 'mobile') { spriteUrl = "url('https://vertex.dev.userlite.com/web/amplib/df/items/logotrain/sprite.jpg?items=integrations')"; } return e('div', { style: { fontSize: height * .5 }, class: 'chart-integration-logo' }, e('div', { style: { width: width, height: height, backgroundImage: spriteUrl, backgroundSize: width * integrationsData.grid.x + 'px auto', backgroundPosition: width * integration.__grid.x * -1 + 'px ' + height * integration.__grid.y * -1 + 'px' }, class: 'chart-integration-logo-image' }, ''), title); } }]); return Chart_integration_logo; }(preact.Component); var Chart_social = function (_preact$Component4) { _inherits(Chart_social, _preact$Component4); function Chart_social() { _classCallCheck(this, Chart_social); var _this5 = _possibleConstructorReturn(this, (Chart_social.__proto__ || Object.getPrototypeOf(Chart_social)).call(this)); _this5.state = {}; return _this5; } _createClass(Chart_social, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { return e('div', { class: 'chart-social' }, 'Social'); } }]); return Chart_social; }(preact.Component); var Chart_layout_default = function (_preact$Component5) { _inherits(Chart_layout_default, _preact$Component5); function Chart_layout_default() { _classCallCheck(this, Chart_layout_default); var _this6 = _possibleConstructorReturn(this, (Chart_layout_default.__proto__ || Object.getPrototypeOf(Chart_layout_default)).call(this)); _this6.state = {}; return _this6; } _createClass(Chart_layout_default, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { var header = null; var content = null; if (this.props.title) { header = e('div', { class: 'chart-layout-default-header' }, this.props.title); } if (this.props.children) { content = e('div', { class: 'chart-layout-default-content' }, this.props.children); } return e('div', { class: 'chart-layout-default' }, header, content); } }]); return Chart_layout_default; }(preact.Component); var Chart_placeholder = function (_preact$Component6) { _inherits(Chart_placeholder, _preact$Component6); function Chart_placeholder() { _classCallCheck(this, Chart_placeholder); var _this7 = _possibleConstructorReturn(this, (Chart_placeholder.__proto__ || Object.getPrototypeOf(Chart_placeholder)).call(this)); _this7.state = {}; return _this7; } _createClass(Chart_placeholder, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { return e('div', { class: 'chart-placeholder' }, this.props.type); } }]); return Chart_placeholder; }(preact.Component); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Chart_bar = function () { var _class, _temp, _initialiseProps; return _temp = _class = function (_preact$Component) { _inherits(Chart_bar, _preact$Component); function Chart_bar(props) { _classCallCheck(this, Chart_bar); var _this = _possibleConstructorReturn(this, (Chart_bar.__proto__ || Object.getPrototypeOf(Chart_bar)).call(this, props)); _initialiseProps.call(_this); _this.state = {}; _this.chartData = _this.getChartData(_this.props); return _this; } _createClass(Chart_bar, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'componentWillUpdate', value: function componentWillUpdate(newProps) { this.chartData = this.getChartData(newProps); } }, { key: 'render', value: function render() { var _this2 = this; var parts = []; var size = this.props.space.size; var dims = {}; dims.padding = size * .5; dims.headerHeight = size + dims.padding * 3; dims.contentHeight = this.props.space.height - dims.headerHeight; dims.labelWidth = size * 1.2; dims.labelFontSize = size * .5; dims.labelHeight = dims.contentHeight / this.chartData.labels.length; dims.barsWidth = this.props.space.width - dims.labelWidth - dims.padding * 3; dims.barWidth = dims.barsWidth / this.chartData.periods.length; dims.barLabelFontsize = dims.barWidth * .2; if (dims.barLabelFontsize > size * .6) dims.barLabelFontsize = size * .6; dims.barLabelHeight = dims.barLabelFontsize * 2; dims.barsHeight = dims.contentHeight - dims.barLabelHeight; dims.barSegmentWidth = dims.barWidth * .6; if (dims.barSegmentWidth > 20) dims.barSegmentWidth = 20; parts.push(e('div', { style: { left: dims.padding * 2, right: dims.padding, top: dims.padding }, key: 'title', class: 'chart-bar-title' }, this.chartData.title)); // console.log('labels', this.chartData.labels); this.chartData.labels.map(function (label, labelKey) { parts.push(e('div', { style: { top: (_this2.chartData.labels.length - labelKey) * dims.labelHeight + dims.padding * 2, left: dims.padding, fontSize: dims.labelFontSize, width: dims.labelWidth }, key: 'title', class: 'chart-bar-label' }, label.title)); }); this.chartData.periods.map(function (period, periodKey) { parts.push(e('div', { style: { left: dims.padding * 2 + dims.labelWidth + periodKey * dims.barWidth, width: dims.barWidth, height: dims.barsHeight, bottom: dims.barLabelHeight + dims.padding }, key: 'segment_' + periodKey, class: 'chart-bar-bar' }, e('div', { style: { height: period.__perc * 100 + '%', width: dims.barSegmentWidth }, class: 'chart-bar-bar-segment' }, ''))); parts.push(e('div', { style: { left: dims.padding * 2 + dims.labelWidth + periodKey * dims.barWidth, width: dims.barWidth, height: dims.barLabelHeight, bottom: dims.padding, fontSize: dims.barLabelFontsize }, key: 'label_' + periodKey, class: 'chart-bar-bar-label' }, period.label)); }); return e('div', { class: 'chart-bar chart-box' }, parts); } }]); return Chart_bar; }(preact.Component), _initialiseProps = function _initialiseProps() { this.getChartData = function (props) { if (!Array.isArray(props.options)) { var chartData = props.options; chartData.__value_max = 0; } else { var chartData = { title: props.options[0], periods: [], lables: [], target_start: props.options[2], target_end: props.options[3], __value_max: 0 }; var increaseFactor = chartData.target_end * 1 - chartData.target_start * 1; var current = chartData.target_start * 1; for (var i = 1; i <= props.options[1]; i++) { var increase = (Math.random() - 0.25) * increaseFactor; current += increase; if (current > chartData.__value_max) chartData.__value_max = current; chartData.periods.push({ value: current }); } } if (chartData.__value_max == 0) chartData.__value_max = 1; var barMoment = moment(); barMoment.subtract(chartData.periods.length, 'weeks'); chartData.periods.forEach(function (item, key) { if (chartData.__value_max < item.value * 1) { chartData.__value_max = item.value * 1; } }); if (!chartData.hasOwnProperty('labels')) { chartData.labels = []; var labelCount = 5; var labelInc = chartData.__value_max / labelCount; for (var i = 0; i < labelCount; i++) { chartData.labels.push({ title: numeral(labelInc * i).format('0as') }); } } chartData.periods = chartData.periods.map(function (item, key) { if (!item.hasOwnProperty('label')) { item.label = barMoment.format('MMM-D'); } barMoment.add(1, 'week'); item.__perc = item.value / chartData.__value_max; return item; }); // console.log(chartData); return chartData; }; }, _temp; }(); var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Chart_pie = function () { var _class, _temp, _initialiseProps; return _temp = _class = function (_preact$Component) { _inherits(Chart_pie, _preact$Component); function Chart_pie(props) { _classCallCheck(this, Chart_pie); var _this = _possibleConstructorReturn(this, (Chart_pie.__proto__ || Object.getPrototypeOf(Chart_pie)).call(this, props)); _initialiseProps.call(_this); _this.state = {}; _this.chartData = _this.getChartData(_this.props); return _this; } _createClass(Chart_pie, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'componentWillUpdate', value: function componentWillUpdate(newProps) { this.chartData = this.getChartData(newProps); } }, { key: 'getCoordinatesForPercent', value: function getCoordinatesForPercent(percent) { var x = Math.cos(2 * Math.PI * percent); var y = Math.sin(2 * Math.PI * percent); return [x, y]; } }, { key: 'render', value: function render() { var _this2 = this; var parts = []; var cd = this.chartData; var size = this.props.space.size; var dims = {}; dims.padding = size * 0.5; dims.titleSize = size * 2.5; dims.headerHeight = dims.titleSize; dims.contentHeight = this.props.space.height - dims.headerHeight; dims.contentWidth = this.props.space.width - dims.padding * 2; dims.legendFontSize = size * .5; // dims.contentWidth = dims.contentWidth / 2; // dims.contentHeight = dims.contentHeight / 2; var aspectRatio = dims.contentWidth / dims.contentHeight; var legendClass = ''; if (aspectRatio >= 0.7 && aspectRatio <= 1.5) { // console.log(aspectRatio); dims.pieSize = dims.contentWidth * .7 - dims.padding * 2; if (dims.pieSize > dims.contentHeight - dims.padding * 1) dims.pieSize = dims.contentHeight - dims.padding * 1; dims.pieLeft = dims.padding; dims.pieTop = dims.headerHeight; dims.legendLeft = dims.pieSize + dims.padding * 2; dims.legendTop = dims.headerHeight + dims.pieSize / 2; dims.legendHeight = dims.contentHeight - dims.pieSize / 2 - dims.padding; dims.legendWidth = dims.contentWidth - dims.pieSize - dims.padding; } else if (aspectRatio < 0.7) { dims.pieSize = dims.contentHeight / 2 - dims.padding * 2; if (dims.pieSize > dims.contentWidth - dims.padding * 1) dims.pieSize = dims.contentWidth - dims.padding * 1; dims.pieTop = dims.headerHeight + dims.padding; dims.pieLeft = dims.padding + (dims.contentWidth - dims.pieSize) / 2; dims.legendLeft = dims.padding; dims.legendTop = dims.headerHeight + dims.pieSize + dims.padding * 2; dims.legendHeight = dims.contentHeight - (dims.pieSize + dims.padding * 3); dims.legendWidth = dims.contentWidth - dims.padding * 0; } else { legendClass = 'center-rows'; dims.pieSize = dims.contentWidth / 2 - dims.padding * 2; if (dims.pieSize > dims.contentHeight - dims.padding * 1) dims.pieSize = dims.contentHeight - dims.padding * 1; dims.pieLeft = dims.padding * 2; dims.pieTop = dims.headerHeight; dims.legendLeft = dims.pieSize + dims.padding * 3; dims.legendTop = dims.headerHeight; dims.legendHeight = dims.contentHeight - dims.padding; dims.legendWidth = dims.contentWidth - dims.pieSize - dims.padding * 2; } dims.pieStrokeWidth = dims.pieSize * 0.0005; var pieSlices = []; var slices = [{ percent: 0.15, color: 'Coral' }, { percent: 0.1, color: 'CornflowerBlue' }, { percent: 0.75, color: '#00ab6b' }]; var cumulativePercent = 0; sliceStroke = 0; var legendItems = []; this.chartData.segments.forEach(function (slice, sliceKey) { legendItems.push(e('div', { key: 'slice_' + sliceKey, class: 'chart-pie-legend-item' }, e('div', { style: { backgroundColor: slice.color, fontSize: dims.legendFontSize }, class: 'chart-pie-legend-item-swatch' }, ''), e('div', { style: { fontSize: dims.legendFontSize }, class: 'chart-pie-legend-item-title' }, slice.label))); // destructuring assignment sets the two variables at once var _getCoordinatesForPer = _this2.getCoordinatesForPercent(cumulativePercent), _getCoordinatesForPer2 = _slicedToArray(_getCoordinatesForPer, 2), startX = _getCoordinatesForPer2[0], startY = _getCoordinatesForPer2[1]; // each slice starts where the last slice ended, so keep a cumulative percent cumulativePercent += slice.percent; var _getCoordinatesForPer3 = _this2.getCoordinatesForPercent(cumulativePercent), _getCoordinatesForPer4 = _slicedToArray(_getCoordinatesForPer3, 2), endX = _getCoordinatesForPer4[0], endY = _getCoordinatesForPer4[1]; // if the slice is more than 50%, take the large arc (the long way around) var largeArcFlag = slice.percent > 0.5 ? 1 : 0; // create an array and join it just for code readability var pathData = ['M ' + startX + ' ' + startY, // Move 'A 1 1 0 ' + largeArcFlag + ' 1 ' + endX + ' ' + endY, // Arc 'L 0 0' // Line ].join(' '); // create a and append it to the element sliceStroke = dims.pieStrokeWidth; pieSlices.push(e('path', { d: pathData, style: { fill: slice.color // stroke: '#FFFFFF', // strokeWidth: sliceStroke } })); }); var titleLogo = null; var title = null; if (cd.integration) { titleLogo = e(Chart_integration_logo, { integration: cd.integration, title: this.chartData.title, size: dims.titleSize }); } else { title = e('div', { class: 'chart-pie-title-text' }, this.chartData.title); } parts.push(e('div', { style: { left: dims.padding * 2, right: dims.padding, top: dims.padding }, key: 'title', class: 'chart-pie-title' }, titleLogo, title)); parts.push(e('div', { style: { left: dims.legendLeft, width: dims.legendWidth, top: dims.legendTop, height: dims.legendHeight }, key: 'title', class: 'chart-pie-legend ' + legendClass }, legendItems)); var chart = e('div', { key: 'chart', class: 'chart-pie-chart', style: { top: dims.pieTop, left: dims.pieLeft } }, e('svg', { viewBox: '-1 -1 2 2', style: { width: dims.pieSize, transform: 'rotate(-0.25turn)' } }, pieSlices)); parts.push(chart); return e('div', { class: 'chart-pie chart-box' }, parts); } }]); return Chart_pie; }(preact.Component), _initialiseProps = function _initialiseProps() { this.getChartData = function (props) { if (!Array.isArray(props.options)) { var chartData = props.options; chartData.__value_max = 0; chartData.__value_total = 0; } else {} chartData.color = { a: props.chroma, b: props.chroma2 }; chartData.palette = props.palette; // console.log(chartData); var color = '74,78,83'; var colorOpc = 0.8; var colorOpcInc = 0.8 / chartData.segments.length; var colorScale = chroma.scale(chartData.palette).mode('lch').colors(Object.keys(chartData.segments).length); if (chartData.segments) { chartData.segments.forEach(function (item, key) { if (chartData.__value_max < item.value * 1) { chartData.__value_max = item.value * 1; } chartData.__value_total = chartData.__value_total + item.value * 1; }); if (chartData.__value_max == 0) chartData.__value_max = 1; chartData.segments = chartData.segments.map(function (item, key) { if (!item.hasOwnProperty('label')) { item.label = 'Something'; } item.percent = item.value / chartData.__value_total; item.color = colorScale[key]; colorOpc -= colorOpcInc; return item; }); } // console.log(chartData); return chartData; }; }, _temp; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Chart_usa = function () { var _class, _temp, _initialiseProps; return _temp = _class = function (_preact$Component) { _inherits(Chart_usa, _preact$Component); function Chart_usa(props) { _classCallCheck(this, Chart_usa); var _this = _possibleConstructorReturn(this, (Chart_usa.__proto__ || Object.getPrototypeOf(Chart_usa)).call(this, props)); _initialiseProps.call(_this); _this.state = { mapHtml: '' }; _this.chartData = _this.getChartData(_this.props); _this.id = 'chart_usa_' + ui.dom.uid(); return _this; } _createClass(Chart_usa, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillMount', value: function componentWillMount() { var _this2 = this; fetch('https://d2beia7gtp5yjy.cloudfront.net/cdn_image/df/397f7/33250515/25038/hds2c/usa.svg').then(function (r) { return r.text(); }).then(function (text) { _this2.setState({ mapHtml: text }); }).catch(console.error.bind(console)); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'componentWillUpdate', value: function componentWillUpdate(newProps) { this.chartData = this.getChartData(newProps); } }, { key: 'render', value: function render() { var _this3 = this; var parts = []; var cd = this.chartData; var color = '74,78,83'; var size = this.props.space.size; var dims = {}; dims.padding = size * 0.5; dims.titleSize = size * 2.5; dims.headerHeight = dims.titleSize; dims.contentHeight = this.props.space.height - dims.headerHeight; dims.contentWidth = this.props.space.width - dims.padding * 2; dims.legendFontSize = size * 0.5; dims.mapWidth = dims.contentWidth * .6; dims.mapLeft = dims.padding; dims.mapHeight = dims.contentHeight - dims.padding; // dims.contentWidth = dims.contentWidth / 2; // dims.contentHeight = dims.contentHeight / 2; var aspectRatio = dims.contentWidth / dims.contentHeight; var styleContent = []; var basePercent = .3; var percentMultiplier = 1 - basePercent; // console.log(percentMultiplier); styleContent.push('#' + this.id + ' path {'); styleContent.push('fill: rgba(' + color + ', .1);'); styleContent.push('stroke: #FFFFFF;'); styleContent.push('strokeWidth: 6px;'); styleContent.push('}'); this.chartData.states.forEach(function (state, stateKey) { var usePercent = basePercent + state.percent * percentMultiplier; styleContent.push('#' + _this3.id + ' path.' + state.abv + ' {'); styleContent.push('fill: rgba(' + cd.color.a.alpha(usePercent).rgba() + ');'); styleContent.push('}'); }); // console.log(styleContent); var titleLogo = null; var title = null; if (cd.integration) { titleLogo = e(Chart_integration_logo, { integration: cd.integration, title: this.chartData.title, size: dims.titleSize }); } else { title = e('div', { class: 'chart-pie-title-text' }, this.chartData.title); } parts.push(e('style', {}, styleContent.join('\n'))); parts.push(e('div', { style: { left: dims.padding * 2, right: dims.padding, top: dims.padding }, key: 'title', class: 'chart-usa-title' }, titleLogo, title)); parts.push(e('div', { class: 'chart-usa-map', style: { left: dims.mapLeft, top: dims.headerHeight, with: dims.mapWidth, height: dims.mapHeight }, dangerouslySetInnerHTML: { __html: this.state.mapHtml } })); return e('div', { id: this.id, class: 'chart-usa chart-box' }, parts); } }]); return Chart_usa; }(preact.Component), _initialiseProps = function _initialiseProps() { this.getChartData = function (props) { if (!Array.isArray(props.options)) { var chartData = props.options; chartData.__value_max = 0; chartData.__value_total = 0; } else {} chartData.color = { a: props.chroma, b: props.chroma2 }; if (!chartData.states) { chartData.states = []; }; chartData.states = chartData.states.map(function (state, stateKey) { state.value = state.value * 1; if (state.value > chartData.__value_max) { chartData.__value_max = state.value; } chartData.__value_total = chartData.__value_total + state.value; return state; }); if (chartData.__value_total == 0) chartData.__value_total = 1; // console.log(chartData.__value_total); var highestPercent = 0; chartData.states = chartData.states.map(function (state, stateKey) { state.percent = state.value / chartData.__value_total; if (state.percent > highestPercent) { highestPercent = state.percent; } return state; }); chartData.states = chartData.states.map(function (state, stateKey) { state.percent = state.percent / highestPercent; return state; }); // console.log(chartData); return chartData; }; }, _temp; }(); var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Chart_multi = function () { var _class, _temp, _initialiseProps; return _temp = _class = function (_preact$Component) { _inherits(Chart_multi, _preact$Component); function Chart_multi(props) { _classCallCheck(this, Chart_multi); var _this = _possibleConstructorReturn(this, (Chart_multi.__proto__ || Object.getPrototypeOf(Chart_multi)).call(this, props)); _initialiseProps.call(_this); _this.state = {}; _this.color = '74,78,83'; _this.chartData = _this.getChartData(_this.props); return _this; } _createClass(Chart_multi, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'componentWillUpdate', value: function componentWillUpdate(newProps) { this.chartData = this.getChartData(newProps); } }, { key: 'vfb', // Value from Bottom value: function vfb(value) { // console.log(this.chartData.value_max); var perc = value / this.chartData.value_max; var offset = perc * this.dims.periodsHeight; offset += this.dims.dotSize * 1.5; offset += this.dims.periodLabelHeight; return Math.floor(offset); } }, { key: 'render', value: function render() { var parts = []; var cd = this.chartData; var size = this.props.space.size; this.dims = {}; var dims = this.dims; dims.padding = size * 0.3; dims.titleSize = size * 2.5; dims.headerHeight = dims.titleSize; dims.contentHeight = this.props.space.height - dims.headerHeight; dims.contentWidth = this.props.space.width - dims.padding * 3; dims.legendFontSize = size * 0.5; dims.labelFontSize = size * 0.3; dims.labelsWidth = size * 1; dims.periodsWidth = Math.floor(dims.contentWidth - dims.labelsWidth); dims.periodLabelFontSize = dims.labelFontSize; dims.periodLabelHeight = dims.periodLabelFontSize * 2 + dims.padding * 2; dims.periodsStart = dims.labelsWidth + dims.padding * 1; dims.dotSize = Math.floor(size * 0.3); dims.lineSize = Math.floor(size * 0.1); if (dims.lineSize < 0.25) dims.lineSize = 0.5; if (dims.lineSize > 3) dims.lineSize = 3; dims.periodWidth = dims.periodsWidth / cd.periods.length; dims.periodsHeight = dims.contentHeight - dims.periodLabelHeight; var lines = {}; var stacks = {}; for (var segmentKey in cd.segments) { if (cd.segments.hasOwnProperty(segmentKey)) { var segment = cd.segments[segmentKey]; if (['line', 'curve'].indexOf(segment.type) !== -1) { lines[segmentKey] = { points: [] }; } if (['bar'].indexOf(segment.type) !== -1) { stacks[segment.stack] = { bars: [] }; } } } dims.stackbarWidth = dims.periodWidth * 0.6 / Object.keys(stacks).length; dims.stackbarSpacing = dims.periodWidth * 0.4 / (Object.keys(stacks).length + 1); var titleLogo = null; var title = null; if (cd.integration) { titleLogo = e(Chart_integration_logo, { integration: cd.integration, title: this.chartData.title, size: dims.titleSize }); } else { title = e('div', { class: 'chart-pie-title-text' }, this.chartData.title); } parts.push(e('div', { style: { left: dims.padding * 2, right: dims.padding, top: dims.padding }, key: 'title', class: 'chart-pie-title' }, titleLogo, title)); // console.log(stacks); var labelCount = 5; var labelInc = cd.value_max / labelCount; var labelCur = 0; for (var i = 0; i <= labelCount; i++) { parts.push(e('div', { style: { textAlign: 'right', width: dims.labelsWidth, fontSize: dims.labelFontSize, left: dims.padding, bottom: i * (dims.periodsHeight / labelCount) + dims.periodLabelHeight - dims.labelFontSize * 0.5 }, class: 'chart-multi-label' }, numeral(Math.ceil(i * labelInc / 10) * 10).format('0a'))); parts.push(e('div', { style: { width: dims.periodsWidth, left: dims.padding * 1.5 + dims.labelsWidth, height: 1, borderWidth: dims.lineSize, bottom: i * (dims.periodsHeight / labelCount) + dims.periodLabelHeight - dims.lineSize }, class: 'chart-multi-labelbar' }, '')); } cd.periods.forEach(function (period, periodKey) { var labelText = period.label_short; var labelTextBig = period.label_sep; if (dims.periodWidth < 20) { var labelTextBig = period.label_sep_short; } parts.push(e('div', { style: { fontSize: dims.periodLabelFontSize, bottom: dims.periodLabelHeight - dims.periodLabelFontSize - dims.padding * 0.75, width: dims.periodWidth, display: 'flex', justifyContent: 'center', left: dims.periodsStart + periodKey * dims.periodWidth }, class: 'chart-multi-period-label' }, e('div', { style: { position: 'relative' }, class: 'chart-multi-period-label-in' }, e('div', { class: 'chart-multi-period-label-in-small' }, labelText), e('div', { style: { position: 'absolute' }, class: 'chart-multi-period-label-in-sep' }, labelTextBig)))); for (var segmentKey in cd.segments) { if (cd.segments.hasOwnProperty(segmentKey)) { var segment = cd.segments[segmentKey]; var curVal = segment.values[periodKey]; if (!curVal) curVal = 0; if (['line', 'curve'].indexOf(segment.type) !== -1) { var linePoint = []; linePoint[0] = periodKey * dims.periodWidth + dims.periodWidth * 0.5; linePoint[1] = (1 - curVal / cd.value_max) * dims.periodsHeight; lines[segmentKey].points.push(linePoint); } if (['dot'].indexOf(segment.type) !== -1) { parts.push(e('div', { style: { bottom: segment.values[periodKey] / cd.value_max * dims.periodsHeight + dims.periodsStart - dims.dotSize * 0.75, width: dims.dotSize, height: dims.dotSize, backgroundColor: segment.color, left: dims.periodsStart + periodKey * dims.periodWidth + dims.periodWidth * 0.5 - dims.dotSize / 2 }, class: 'chart-multi-period-dot' }, '')); } if (['bar'].indexOf(segment.type) !== -1) { var _e; if (!stacks[segment.stack].bars[periodKey]) { stacks[segment.stack].bars[periodKey] = []; } stacks[segment.stack].bars[periodKey].push(e('div', (_e = { style: { height: segment.values[periodKey] / cd.value_max * dims.periodsHeight, // marginTop: dims.labelFontSize * .2, width: dims.stackbarWidth, backgroundColor: segment.color } }, _defineProperty(_e, 'data-value', segment.values[periodKey] + ' / ' + cd.value_max + ' / ' + dims.periodsHeight), _defineProperty(_e, 'class', 'chart-multi-period-barstack-bar'), _e))); } } } }); cd.periods.forEach(function (period, periodKey) { var stackIndex = 0; for (var stackKey in stacks) { if (stacks.hasOwnProperty(stackKey)) { parts.push(e('div', { style: { bottom: dims.periodLabelHeight, left: dims.periodsStart + periodKey * dims.periodWidth + stackIndex * dims.stackbarWidth + dims.stackbarSpacing * 0.3 * stackIndex + dims.stackbarSpacing + dims.stackbarSpacing * 0.35 * stackIndex }, class: 'chart-multi-period-barstack stack-' + stackKey }, stacks[stackKey].bars[periodKey])); stackIndex++; } } }); var legendSegments = []; for (var segmentKey in cd.segments) { if (cd.segments.hasOwnProperty(segmentKey)) { var segment = cd.segments[segmentKey]; legendSegments.push(e('div', { style: { fontSize: dims.legendFontSize * 0.75, display: 'flex', alignItems: 'center', marginLeft: dims.legendFontSize * 0.5, // lineHeight: '100%', marginTop: dims.legendFontSize * -0.125 } }, e('div', { style: { width: dims.legendFontSize * 0.7, height: dims.legendFontSize * 0.7, borderRadius: 0, backgroundColor: segment.color, marginRight: dims.legendFontSize * 0.25 // lineHeight: '100%' } }), e('div', { style: { // lineHeight: '100%' } }, segment.title))); if (['line', 'curve'].indexOf(segment.type) !== -1) { var _e2; var lineCommand = this.svgBezierCommand; if (segment.type == 'line') { lineCommand = this.svgLineCommand; } parts.push(e('svg', { viewBox: '0 0 ' + dims.periodsWidth + ' ' + dims.periodsHeight + '', style: { width: dims.periodsWidth, height: dims.periodsHeight, left: dims.periodsStart, top: dims.headerHeight } }, e('path', (_e2 = { // stroke: 'rgba('+this.color+', .6)', stroke: segment.color }, _defineProperty(_e2, 'stroke-width', dims.lineSize), _defineProperty(_e2, 'stroke-dasharray', dims.lineSize * 2 + ' ' + dims.lineSize * 2), _defineProperty(_e2, 'stroke-linecap', 'round'), _defineProperty(_e2, 'fill', 'none'), _defineProperty(_e2, 'd', this.svgPath(lines[segmentKey].points, lineCommand)), _e2)))); } } } parts.push(e('div', { style: { left: dims.padding, top: dims.headerHeight - dims.legendFontSize * 1.5, display: 'flex', width: dims.contentWidth, overflow: 'hidden', flexWrap: 'wrap', height: dims.legendFontSize * .9, justifyContent: 'flex-end' } }, legendSegments)); var aspectRatio = dims.contentWidth / dims.contentHeight; return e('div', { class: 'chart-multi chart-box' }, parts); } }]); return Chart_multi; }(preact.Component), _initialiseProps = function _initialiseProps() { var _this2 = this; this.getChartData = function (props) { var chartData = JSON.parse(JSON.stringify(props.options)); chartData.color = { a: props.chroma, b: props.chroma2 }; chartData.value_max = 0; chartData.palette = props.palette; if (!chartData.stacks) { chartData.stacks = {}; } if (!chartData.periods) { chartData.periods = []; } chartData.periods = chartData.periods.map(function (period, periodKey) { if (!period.segments) period.segments = {}; if (!period.stacks) period.stacks = {}; return period; }); // console.log(chartData.stacks); if (chartData.segments) { for (var segmentKey in chartData.segments) { if (chartData.segments.hasOwnProperty(segmentKey)) { var segment = chartData.segments[segmentKey]; if (segment.type == 'bar') { if (!segment.stack) { segment.stack = 0; } if (!chartData.stacks[segment.stack]) { chartData.stacks[segment.stack] = {}; } } if (segment.values) { segment.values.forEach(function (value, valueKey) { value = value * 1; if (!chartData.periods[valueKey]) { chartData.periods[valueKey] = { segments: {}, stacks: {} }; } if (!chartData.periods[valueKey].segments[segmentKey]) { chartData.periods[valueKey].segments[segmentKey] = { total: 0 }; } chartData.periods[valueKey].segments[segmentKey].total += value; if (chartData.periods[valueKey].segments[segmentKey].total > chartData.value_max) { chartData.value_max = chartData.periods[valueKey].segments[segmentKey].total; } if (segment.type == 'bar') { if (!segment.stack) { segment.stack = 0; } if (!chartData.periods[valueKey].stacks[segment.stack]) { chartData.periods[valueKey].stacks[segment.stack] = { total: 0 }; } chartData.periods[valueKey].stacks[segment.stack].total += value; if (chartData.periods[valueKey].stacks[segment.stack].total > chartData.value_max) { chartData.value_max = chartData.periods[valueKey].stacks[segment.stack].total; } } segment.values[valueKey] = value; }); } } } } _this2.addPeriodWeeks(chartData.periods); // console.log('palette', chartData.palette); var colorScale = chroma.scale(chartData.palette).mode('lch').colors(Object.keys(chartData.segments).length); var segIndex = 0; for (var segmentKey in chartData.segments) { if (chartData.segments.hasOwnProperty(segmentKey)) { chartData.segments[segmentKey].color = colorScale[segIndex]; segIndex++; } } // console.log('TEST'); // // console.log(chartData.value_max); // chartData.value_max = chartData.value_max * 1.1; return chartData; }; this.addPeriodWeeks = function (periods) { var periodMoment = moment().subtract(Object.keys(periods).length, 'weeks'); var curMonth = false; var periodsToggling = false; var periodsToggle = true; var skipFirstMonth = false; if (Object.keys(periods).length > 16) { periodsToggling = true; skipFirstMonth = true; } for (var periodKey in periods) { if (periods.hasOwnProperty(periodKey)) { if (!periods[periodKey].label) { periods[periodKey].label = periodMoment.format('MMM DD'); periods[periodKey].label_short = periodMoment.format('DD'); if (periodsToggling) { if (periodsToggle) { periods[periodKey].label_short = null; periodsToggle = false; } else { periodsToggle = true; } } periods[periodKey].label_sep = false; if (curMonth != periodMoment.format('MMMM')) { curMonth = periodMoment.format('MMMM'); if (skipFirstMonth) {} else { periods[periodKey].label_sep = curMonth; periods[periodKey].label_sep_short = periodMoment.format('MMM'); } skipFirstMonth = false; } } periodMoment.add(1, 'week'); if (!periods[periodKey].label_short && periods[periodKey].label_short !== null) { periods[periodKey].label_short = periods[periodKey].label; } // console.log(periods[periodKey]); } } }; this.svgLine = function (pointA, pointB) { var lengthX = pointB[0] - pointA[0]; var lengthY = pointB[1] - pointA[1]; return { length: Math.sqrt(Math.pow(lengthX, 2) + Math.pow(lengthY, 2)), angle: Math.atan2(lengthY, lengthX) }; }; this.svgControlPoint = function (current, previous, next, reverse) { // When 'current' is the first or last point of the array // 'previous' or 'next' don't exist. // Replace with 'current' var p = previous || current; var n = next || current; // The smoothing ratio var smoothing = 0.2; // Properties of the opposed-line var o = _this2.svgLine(p, n); // If is end-control-point, add PI to the angle to go backward var angle = o.angle + (reverse ? Math.PI : 0); var length = o.length * smoothing; // The control point position is relative to the current point var x = current[0] + Math.cos(angle) * length; var y = current[1] + Math.sin(angle) * length; return [x, y]; }; this.svgBezierCommand = function (point, i, a) { // start control point var _svgControlPoint = _this2.svgControlPoint(a[i - 1], a[i - 2], point), _svgControlPoint2 = _slicedToArray(_svgControlPoint, 2), cpsX = _svgControlPoint2[0], cpsY = _svgControlPoint2[1]; // end control point var _svgControlPoint3 = _this2.svgControlPoint(point, a[i - 1], a[i + 1], true), _svgControlPoint4 = _slicedToArray(_svgControlPoint3, 2), cpeX = _svgControlPoint4[0], cpeY = _svgControlPoint4[1]; return 'C ' + cpsX + ',' + cpsY + ' ' + cpeX + ',' + cpeY + ' ' + point[0] + ',' + point[1]; }; this.svgLineCommand = function (point) { return 'L ' + point[0] + ' ' + point[1]; }; this.svgPath = function (points, command) { // build the d attributes by looping over the points var d = points.reduce(function (acc, point, i, a) { return i === 0 ? // if first point 'M ' + point[0] + ',' + point[1] : // else acc + ' ' + command(point, i, a); }, ''); // return `` return d; }; }, _temp; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Chart_widgets = function () { var _class, _temp, _initialiseProps; return _temp = _class = function (_preact$Component) { _inherits(Chart_widgets, _preact$Component); function Chart_widgets(props) { _classCallCheck(this, Chart_widgets); var _this = _possibleConstructorReturn(this, (Chart_widgets.__proto__ || Object.getPrototypeOf(Chart_widgets)).call(this, props)); _initialiseProps.call(_this); _this.state = { mapHtml: '' }; _this.chartData = _this.getChartData(_this.props); _this.id = 'chart_widgets_' + ui.dom.uid(); return _this; } _createClass(Chart_widgets, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillMount', value: function componentWillMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'componentWillUpdate', value: function componentWillUpdate(newProps) { this.chartData = this.getChartData(newProps); } }, { key: 'render', value: function render() { var parts = []; var cd = this.chartData; var color = '74,78,83'; var size = this.props.space.size; var dims = {}; dims.padding = size * 0.5; dims.widgetMargin = dims.padding; dims.fontSize = size * 0.5; dims.valueSize = size * 2; var matrix = ui.layout.autoMatrix({ width: this.props.space.width, height: this.props.space.height, items: cd.items, padding: dims.padding }); matrix.rows.forEach(function (row, rowKey) { row.items.forEach(function (item, itemKey) { var itemComp = 'Chart_widgets_' + item.type; if (window[itemComp]) { parts.push(e('div', { class: 'chart-widgets-widget', style: { width: item.box.width, height: item.box.height, top: item.box.top, left: item.box.left } }, e(window[itemComp], { item: item, dims: dims }))); } }); }); return e('div', { id: this.id, class: 'chart-widgets chart-box' }, parts); } }]); return Chart_widgets; }(preact.Component), _initialiseProps = function _initialiseProps() { this.getChartData = function (props) { if (!Array.isArray(props.options)) { var chartData = props.options; chartData.__value_max = 0; chartData.__value_total = 0; } else {} chartData.color = { a: props.chroma, b: props.chroma2 }; // console.log(chartData); return chartData; }; }, _temp; }(); var Chart_widgets_number = function () { return function (_preact$Component2) { _inherits(Chart_widgets_number, _preact$Component2); function Chart_widgets_number(props) { _classCallCheck(this, Chart_widgets_number); return _possibleConstructorReturn(this, (Chart_widgets_number.__proto__ || Object.getPrototypeOf(Chart_widgets_number)).call(this, props)); } _createClass(Chart_widgets_number, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillMount', value: function componentWillMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'componentWillUpdate', value: function componentWillUpdate() {} }, { key: 'render', value: function render() { // console.log('rendering'); var sizeUse = this.props.item.box.height; if (this.props.item.box.width < sizeUse) { sizeUse = this.props.item.box.width * .8; } return e('div', { class: 'chart-widgets-number' }, e('div', { class: 'chart-widgets-number-title', style: { lineHeight: '100%', marginBottom: sizeUse * .1, fontSize: sizeUse * .15 } }, this.props.item.title), e('div', { class: 'chart-widgets-number-value', style: { lineHeight: '100%', fontSize: sizeUse * .4 } }, numeral(this.props.item.value).format('0a'))); } }]); return Chart_widgets_number; }(preact.Component); }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Chart_funnel = function () { var _class, _temp, _initialiseProps; return _temp = _class = function (_preact$Component) { _inherits(Chart_funnel, _preact$Component); function Chart_funnel(props) { _classCallCheck(this, Chart_funnel); var _this = _possibleConstructorReturn(this, (Chart_funnel.__proto__ || Object.getPrototypeOf(Chart_funnel)).call(this, props)); _initialiseProps.call(_this); _this.state = { mapHtml: '' }; _this.chartData = _this.getChartData(_this.props); _this.id = 'chart_funnel_' + ui.dom.uid(); return _this; } _createClass(Chart_funnel, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillMount', value: function componentWillMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'componentWillUpdate', value: function componentWillUpdate(newProps) { this.chartData = this.getChartData(newProps); } }, { key: 'render', value: function render() { var parts = []; var cd = this.chartData; var color = '74,78,83'; var space = this.props.space; var size = this.props.space.size; var dims = {}; dims.padding = size * 0.5; dims.titleSize = size * 2.5; dims.headerHeight = dims.titleSize; dims.contentHeight = this.props.space.height - dims.headerHeight; dims.contentWidth = this.props.space.width - dims.padding * 2; dims.visualWidth = (dims.contentWidth - dims.padding) * 0.5; dims.fontSize = size * 0.5; dims.legendFontSize = size * 0.5; dims.segmentHeight = (dims.contentHeight - dims.padding * 2) / cd.segments.length; dims.segmentSplit = 0; if (cd.segments.length > 1) { dims.segmentSplit = dims.padding / (cd.segments.length - 1); } var titleLogo = null; var title = null; if (cd.integration) { titleLogo = e(Chart_integration_logo, { integration: cd.integration, title: this.chartData.title, size: dims.titleSize }); } else { title = e('div', { class: 'chart-pie-title-text' }, this.chartData.title); } parts.push(e('div', { style: { left: dims.padding, right: dims.padding, top: dims.padding }, key: 'title', class: 'chart-funnel-title' }, titleLogo, title)); var segmentPaths = []; var partsAfter = []; cd.segments.forEach(function (segment, segmentKey) { var nextSegment = segment; if (cd.segments[segmentKey + 1]) { nextSegment = cd.segments[segmentKey + 1]; } var points = []; var top = dims.headerHeight + segmentKey * dims.segmentHeight + segmentKey * dims.segmentSplit; var bottom = top + dims.segmentHeight; var topWidth = segment.percent * dims.visualWidth; var topLeft = dims.padding + (dims.visualWidth - topWidth) / 2; var topRight = topLeft + topWidth; var bottomWidth = nextSegment.percent * dims.visualWidth; var bottomLeft = dims.padding + (dims.visualWidth - bottomWidth) / 2; var bottomRight = bottomLeft + bottomWidth; points.push([topLeft, top]); points.push([topRight, top]); points.push([bottomRight, bottom]); points.push([bottomLeft, bottom]); points = points.map(function (point) { return point.join(','); }).join(' '); segmentPaths.push(e('polygon', { points: points, style: { fill: segment.color } })); points = []; points.push([dims.visualWidth * 0.5 + dims.padding, top]); points.push([dims.contentWidth + dims.padding, top]); points.push([dims.contentWidth + dims.padding, bottom]); points.push([dims.visualWidth * 0.5 + dims.padding, bottom]); points = points.map(function (point) { return point.join(','); }).join(' '); segmentPaths.push(e('polygon', { points: points, style: { fill: chroma(segment.color).alpha(.2).hex() } })); parts.push(e('div', { style: { left: dims.visualWidth + dims.padding * 2, top: top, height: dims.segmentHeight, width: dims.visualWidth, fontSize: dims.fontSize, display: 'flex', alignItems: 'center' } }, e('div', { style: {} }, segment.title), e('div', { style: { marginLeft: 'auto', marginRight: dims.padding } }, segment.value))); if (segment.step_percent) { percSize = bottomWidth * .5; if (percSize > size * .5) percSize = size * .5; partsAfter.push(e('div', { style: { left: dims.padding, top: top, height: dims.segmentHeight, width: dims.visualWidth, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#FFFFFF', fontSize: percSize } }, e('div', { style: {} }, Math.floor(segment.step_percent * 100) + '%'))); } }); console.log(segmentPaths); parts.push(e('svg', { viewBox: '0 0 ' + space.width + ' ' + space.height }, segmentPaths)); partsAfter.forEach(function (part) { parts.push(part); }); return e('div', { id: this.id, class: 'chart-funnel chart-box' }, parts); } }]); return Chart_funnel; }(preact.Component), _initialiseProps = function _initialiseProps() { this.getChartData = function (props) { if (!Array.isArray(props.options)) { var chartData = props.options; chartData.__value_max = 0; chartData.__value_total = 0; } else {} chartData.color = { a: props.chroma, b: props.chroma2 }; chartData.palette = props.palette; var colorScale = chroma.scale(chartData.palette).mode('lch').colors(Object.keys(chartData.segments).length); var lastSegValue = false; chartData.segments = chartData.segments.map(function (segment, segmentKey) { segment.step_percent = 0; if (chartData.segments[segmentKey + 1] && segment.value) { segment.step_percent = chartData.segments[segmentKey + 1].value / segment.value; } segment.color = colorScale[segmentKey]; chartData.__value_total += segment.value; if (segment.value > chartData.__value_max) { chartData.__value_max = segment.value; } return segment; }); chartData.segments = chartData.segments.map(function (segment, segmentKey) { segment.percent = segment.value / chartData.__value_max; return segment; }); console.log(chartData); return chartData; }; }, _temp; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Chart_table = function () { var _class, _temp, _initialiseProps; return _temp = _class = function (_preact$Component) { _inherits(Chart_table, _preact$Component); function Chart_table(props) { _classCallCheck(this, Chart_table); var _this = _possibleConstructorReturn(this, (Chart_table.__proto__ || Object.getPrototypeOf(Chart_table)).call(this, props)); _initialiseProps.call(_this); _this.state = { mapHtml: '' }; _this.chartData = _this.getChartData(_this.props); _this.id = 'chart_table_' + ui.dom.uid(); return _this; } _createClass(Chart_table, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillMount', value: function componentWillMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'componentWillUpdate', value: function componentWillUpdate(newProps) { this.chartData = this.getChartData(newProps); } }, { key: 'render', value: function render() { var parts = ['table']; var cd = this.chartData; var color = '74,78,83'; var size = this.props.space.size; var dims = {}; dims.padding = size * 0.5; dims.titleSize = size * 1.5; dims.headerHeight = dims.titleSize + dims.padding * 2.5; dims.contentHeight = this.props.space.height - dims.headerHeight; dims.contentWidth = this.props.space.width - dims.padding * 2; dims.legendFontSize = size * 0.5; return e('div', { id: this.id, class: 'chart-table chart-box' }, parts); } }]); return Chart_table; }(preact.Component), _initialiseProps = function _initialiseProps() { this.getChartData = function (props) { if (!Array.isArray(props.options)) { var chartData = props.options; chartData.__value_max = 0; chartData.__value_total = 0; } else {} chartData.color = { a: props.chroma, b: props.chroma2 // console.log(chartData); };return chartData; }; }, _temp; }(); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Chart_leader = function () { var _class, _temp, _initialiseProps; return _temp = _class = function (_preact$Component) { _inherits(Chart_leader, _preact$Component); function Chart_leader(props) { _classCallCheck(this, Chart_leader); var _this = _possibleConstructorReturn(this, (Chart_leader.__proto__ || Object.getPrototypeOf(Chart_leader)).call(this, props)); _initialiseProps.call(_this); _this.state = { mapHtml: '' }; _this.chartData = _this.getChartData(_this.props); _this.id = 'chart_leader_' + ui.dom.uid(); _this.personSprite = 'url(\'https://vertex.dev.userlite.com/web/amplib/df/util/sprite.png?node=widgets&node_type=34&size=50&v=4\')'; return _this; } _createClass(Chart_leader, [{ key: 'componentDidMount', value: function componentDidMount() {} }, { key: 'componentWillMount', value: function componentWillMount() {} }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'componentWillUpdate', value: function componentWillUpdate(newProps) { this.chartData = this.getChartData(newProps); } }, { key: 'render', value: function render() { var parts = []; var cd = this.chartData; var peopleCount = Object.keys(cd.people).length; var valuesCount = Object.keys(cd.values).length; var color = '74,78,83'; var size = this.props.space.size; var dims = {}; dims.padding = size * 0.5; dims.titleSize = size * 2.5; dims.headerHeight = dims.titleSize; dims.contentHeight = this.props.space.height - dims.headerHeight - dims.padding; dims.contentWidth = this.props.space.width - dims.padding * 2; dims.legendFontSize = size * 0.5; dims.personHeight = dims.contentHeight / peopleCount; dims.fontSize = dims.personHeight * .35; dims.personWidth = dims.contentWidth * .35; dims.valuesWidth = dims.contentWidth - dims.personWidth; dims.valueWidth = dims.valuesWidth / valuesCount; dims.valueBarHeight = dims.personHeight * .15; dims.avatarSize = dims.fontSize * 1.5; // if (dims.fontSize > 14) dims.fontSize = 14; // dims.avatarSize = dims.personHeight * .75; var titleLogo = null; var title = null; if (cd.integration) { titleLogo = e(Chart_integration_logo, { integration: cd.integration, title: this.chartData.title, size: dims.titleSize }); } else { title = e('div', { class: 'chart-pie-title-text' }, this.chartData.title); } // console.log('dims.valueWidth', dims.valueWidth); var valueIndex = 0; for (var valueKey in cd.values) { if (cd.values.hasOwnProperty(valueKey)) { var curVal = cd.values[valueKey]; // console.log(curVal); parts.push(e('div', { style: { borderLeft: '1px solid ' + chroma(curVal.color).alpha(.3).hex(), height: dims.contentHeight, left: dims.personWidth + dims.padding + valueIndex * dims.valueWidth, width: 1, top: dims.headerHeight } }, '')); parts.push(e('div', { style: { left: dims.personWidth + dims.padding * 1 + valueIndex * dims.valueWidth, top: dims.headerHeight - dims.fontSize - dims.padding * .25, fontSize: dims.fontSize * .8 } }, cd.values[valueKey].title)); valueIndex++; } } var personIndex = 0; for (var personKey in cd.people) { if (cd.people.hasOwnProperty(personKey)) { var person = cd.people[personKey]; var peep = people[person.person]; // console.log(peep); var valueParts = []; var valueIndex = 0; for (var valueKey in cd.values) { if (cd.values.hasOwnProperty(valueKey)) { var curVal = cd.values[valueKey]; // console.log(curVal); parts.push(e('div', { style: { left: dims.personWidth + dims.padding * 1.4 + valueIndex * dims.valueWidth, width: dims.valueWidth - dims.padding, paddingRight: dims.padding, opacity: .8, color: curVal.color, top: dims.headerHeight + personIndex * dims.personHeight + dims.fontSize * .5, fontSize: dims.fontSize * .75 } }, person.values[valueKey])); parts.push(e('div', { style: { left: dims.personWidth + dims.padding + valueIndex * dims.valueWidth, width: dims.valueWidth - dims.padding, paddingRight: dims.padding, top: dims.headerHeight + personIndex * dims.personHeight + dims.personHeight * .6 } }, e('div', { style: { width: person.percents[valueKey] * 100 + '%', height: dims.valueBarHeight, background: curVal.color } }, ''))); valueIndex++; } } parts.push(e('div', { style: { height: dims.personHeight, top: dims.headerHeight + personIndex * dims.personHeight, left: dims.padding, display: 'flex', width: dims.personWidth, fontSize: dims.fontSize, alignItems: 'center' } }, e('div', { style: { height: dims.avatarSize, width: dims.avatarSize, flexShrink: 0, borderRadius: '50%', marginRight: dims.padding * .5, backgroundImage: this.personSprite, backgroundPosition: '0 -' + peep.sortorder * dims.avatarSize + 'px', backgroundSize: dims.avatarSize + 'px auto' } }, ''), e('div', { style: { width: dims.personWidth, paddingRight: dims.padding, lineHeight: '100%' } }, peep.title))); parts.push(e('div', { style: { height: 1, top: dims.headerHeight + personIndex * dims.personHeight - 1, left: dims.padding, width: dims.contentWidth, borderTop: '1px solid rgba(0,0,0,.05)' } }, '')); personIndex++; } } parts.push(e('div', { style: { left: dims.padding * 2, right: dims.padding, top: dims.padding }, key: 'title', class: 'chart-funnel-title' }, titleLogo, title)); return e('div', { id: this.id, class: 'chart-leader chart-box' }, parts); } }]); return Chart_leader; }(preact.Component), _initialiseProps = function _initialiseProps() { this.getChartData = function (props) { if (!Array.isArray(props.options)) { var chartData = props.options; chartData.__value_max = 0; chartData.__value_total = 0; } else {} chartData.color = { a: props.chroma, b: props.chroma2 }; chartData.palette = props.palette; var colorScale = chroma.scale(chartData.palette).mode('lch').colors(Object.keys(chartData.values).length); var valueIndex = 0; for (var valueKey in chartData.values) { if (chartData.values.hasOwnProperty(valueKey)) { chartData.values[valueKey].color = colorScale[valueIndex]; valueIndex++; chartData.values[valueKey].max = 0; for (var personKey in chartData.people) { if (chartData.people.hasOwnProperty(personKey)) { if (chartData.people[personKey].values.hasOwnProperty(valueKey)) { if (chartData.people[personKey].values[valueKey] > chartData.values[valueKey].max) chartData.values[valueKey].max = chartData.people[personKey].values[valueKey]; } } } for (var personKey in chartData.people) { if (chartData.people.hasOwnProperty(personKey)) { if (!chartData.people[personKey].percents) { chartData.people[personKey].percents = {}; } chartData.people[personKey].percents[valueKey] = 0; if (chartData.people[personKey].values.hasOwnProperty(valueKey)) { chartData.people[personKey].percents[valueKey] = chartData.people[personKey].values[valueKey] / chartData.values[valueKey].max; } } } } } // console.log(chartData); return chartData; }; }, _temp; }();