diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/build/webpack.base.conf.js b/build/webpack.base.conf.js new file mode 100755 index 0000000..f189e91 --- /dev/null +++ b/build/webpack.base.conf.js @@ -0,0 +1,35 @@ +const path = require('path'); + + +function resolve(dir) { + return path.join(__dirname, '..', dir) +} + +module.exports = { + context: resolve('src'), + entry: './index.ts', + plugins: [], + module: { + rules: [ + { + test: /\.ts$/, + use: 'ts-loader', + exclude: /node_modules/ + }, + { + test: /\.css$/, + use: ['style-loader', 'css-loader'], + exclude: /node_modules/ + } + ], + }, + resolve: { + extensions: ['.ts', '.js'], + }, + output: { + filename: 'index.js', + path: resolve('dist'), + libraryTarget: 'umd', + umdNamedDefine: true + } +}; diff --git a/build/webpack.dev.conf.js b/build/webpack.dev.conf.js new file mode 100755 index 0000000..9a05316 --- /dev/null +++ b/build/webpack.dev.conf.js @@ -0,0 +1,8 @@ +const baseWebpackConfig = require('./webpack.base.conf'); + +var conf = baseWebpackConfig; +conf.devtool = 'inline-source-map'; +conf.watch = true; +conf.mode = 'development'; + +module.exports = conf; diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js new file mode 100755 index 0000000..94cb91d --- /dev/null +++ b/build/webpack.prod.conf.js @@ -0,0 +1,6 @@ +const baseWebpackConfig = require('./webpack.base.conf'); + +var conf = baseWebpackConfig; +conf.mode = 'production'; + +module.exports = baseWebpackConfig; diff --git a/demo.html b/demo.html new file mode 100755 index 0000000..74aabd9 --- /dev/null +++ b/demo.html @@ -0,0 +1,35 @@ + + +
+ + + + + + + + + + + diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..48c1082 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,73 @@ +import { ChartwerkPod, TickOrientation, TimeFormat, AxisFormat } from '@chartwerk/core'; +import { BarTimeSerie, BarOptions, RowValues } from './types'; +import * as d3 from 'd3'; +export declare class ChartwerkBarPod extends ChartwerkPod>1)+h+t+M+S.slice(k);break;default:t=S+h+t+M}return a(t)}return g=void 0===g?6:/[gprs]/.test(_)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),M.toString=function(){return t+""},M}return{format:l,formatPrefix:function(t,n){var e=l(((t=Ga(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(Wa(n)/3))),i=Math.pow(10,-r),o=oc[8+r/3];return function(t){return e(i*t)+o}}}};function ac(t){return Qa=uc(t),Ja=Qa.format,tc=Qa.formatPrefix,Qa}ac({decimal:".",thousands:",",grouping:[3],currency:["$",""],minus:"-"});var cc=function(t){return Math.max(0,-Wa(Math.abs(t)))},fc=function(t,n){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Wa(n)/3)))-Wa(Math.abs(t)))},sc=function(t,n){return t=Math.abs(t),n=Math.abs(n)-t,Math.max(0,Wa(n)-Wa(t))+1},lc=function(){return new hc};function hc(){this.reset()}hc.prototype={constructor:hc,reset:function(){this.s=this.t=0},add:function(t){pc(dc,t,this.t),pc(this,dc.s,this.s),this.s?this.t+=dc.t:this.s=dc.t},valueOf:function(){return this.s}};var dc=new hc;function pc(t,n,e){var r=t.s=n+e,i=r-n,o=r-i;t.t=n-o+(e-i)}var vc=Math.PI,gc=vc/2,yc=vc/4,_c=2*vc,bc=180/vc,mc=vc/180,xc=Math.abs,wc=Math.atan,Mc=Math.atan2,Ac=Math.cos,kc=Math.ceil,Sc=Math.exp,Cc=(Math.floor,Math.log),Tc=Math.pow,Ec=Math.sin,Nc=Math.sign||function(t){return t>0?1:t<0?-1:0},jc=Math.sqrt,Oc=Math.tan;function Pc(t){return t>1?0:t<-1?vc:Math.acos(t)}function zc(t){return t>1?gc:t<-1?-gc:Math.asin(t)}function Rc(t){return(t=Ec(t/2))*t}function Ic(){}function Fc(t,n){t&&Bc.hasOwnProperty(t.type)&&Bc[t.type](t,n)}var Lc={Feature:function(t,n){Fc(t.geometry,n)},FeatureCollection:function(t,n){for(var e=t.features,r=-1,i=e.length;++r=0?1:-1,i=r*e,o=Ac(n=(n*=mc)/2+yc),u=Ec(n),a=$c*u,c=Hc*o+a*Ac(i),f=a*r*Ec(i);Xc.add(Mc(f,c)),Yc=t,Hc=o,$c=u}var nf=function(t){return Gc.reset(),Wc(t,Zc),2*Gc};function ef(t){return[Mc(t[1],t[0]),zc(t[2])]}function rf(t){var n=t[0],e=t[1],r=Ac(e);return[r*Ac(n),r*Ec(n),Ec(e)]}function of(t,n){return t[0]*n[0]+t[1]*n[1]+t[2]*n[2]}function uf(t,n){return[t[1]*n[2]-t[2]*n[1],t[2]*n[0]-t[0]*n[2],t[0]*n[1]-t[1]*n[0]]}function af(t,n){t[0]+=n[0],t[1]+=n[1],t[2]+=n[2]}function cf(t,n){return[t[0]*n,t[1]*n,t[2]*n]}function ff(t){var n=jc(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=n,t[1]/=n,t[2]/=n}var sf,lf,hf,df,pf,vf,gf,yf,_f,bf,mf=lc(),xf={point:wf,lineStart:Af,lineEnd:kf,polygonStart:function(){xf.point=Sf,xf.lineStart=Cf,xf.lineEnd=Tf,mf.reset(),Zc.polygonStart()},polygonEnd:function(){Zc.polygonEnd(),xf.point=wf,xf.lineStart=Af,xf.lineEnd=kf,Xc<0?(sf=-(hf=180),lf=-(df=90)):mf>1e-6?df=90:mf<-1e-6&&(lf=-90),bf[0]=sf,bf[1]=hf},sphere:function(){sf=-(hf=180),lf=-(df=90)}};function wf(t,n){_f.push(bf=[sf=t,hf=t]),n >>1;f[v]1e-12)if(p>jm-1e-12)a.moveTo(l*Am(h),l*Cm(h)),a.arc(0,0,l,h,d,!v),s>1e-12&&(a.moveTo(s*Am(d),s*Cm(d)),a.arc(0,0,s,d,h,v));else{var g,y,_=h,b=d,m=h,x=d,w=p,M=p,A=u.apply(this,arguments)/2,k=A>1e-12&&(r?+r.apply(this,arguments):Tm(s*s+l*l)),S=Sm(wm(l-s)/2,+e.apply(this,arguments)),C=S,T=S;if(k>1e-12){var E=Pm(k/s*Cm(A)),N=Pm(k/l*Cm(A));(w-=2*E)>1e-12?(m+=E*=v?1:-1,x-=E):(w=0,m=x=(h+d)/2),(M-=2*N)>1e-12?(_+=N*=v?1:-1,b-=N):(M=0,_=b=(h+d)/2)}var j=l*Am(_),O=l*Cm(_),P=s*Am(x),z=s*Cm(x);if(S>1e-12){var R,I=l*Am(b),F=l*Cm(b),L=s*Am(m),B=s*Cm(m);if(p1e-12?T>1e-12?(g=Um(L,B,j,O,l,T,v),y=Um(I,F,P,z,l,T,v),a.moveTo(g.cx+g.x01,g.cy+g.y01),T1e-12&&w>1e-12?C>1e-12?(g=Um(P,z,I,F,s,-C,v),y=Um(j,O,L,B,s,-C,v),a.lineTo(g.cx+g.x01,g.cy+g.y01),C=s;--l)a.point(g[l],y[l]);a.lineEnd(),a.areaEnd()}v&&(g[f]=+t(h,f,c),y[f]=+e(h,f,c),a.point(n?+n(h,f,c):g[f],r?+r(h,f,c):y[f]))}if(d)return a=null,d+""||null}function f(){return $m().defined(i).curve(u).context(o)}return c.x=function(e){return arguments.length?(t="function"==typeof e?e:xm(+e),n=null,c):t},c.x0=function(n){return arguments.length?(t="function"==typeof n?n:xm(+n),c):t},c.x1=function(t){return arguments.length?(n=null==t?null:"function"==typeof t?t:xm(+t),c):n},c.y=function(t){return arguments.length?(e="function"==typeof t?t:xm(+t),r=null,c):e},c.y0=function(t){return arguments.length?(e="function"==typeof t?t:xm(+t),c):e},c.y1=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:xm(+t),c):r},c.lineX0=c.lineY0=function(){return f().x(t).y(e)},c.lineY1=function(){return f().x(t).y(r)},c.lineX1=function(){return f().x(n).y(e)},c.defined=function(t){return arguments.length?(i="function"==typeof t?t:xm(!!t),c):i},c.curve=function(t){return arguments.length?(u=t,null!=o&&(a=u(o)),c):u},c.context=function(t){return arguments.length?(null==t?o=a=null:a=u(o=t),c):o},c},Xm=function(t,n){return n0){if(o>l)return;o>s&&(s=o)}if(o=r-c,h||!(o<0)){if(o/=h,h<0){if(o>l)return;o>s&&(s=o)}else if(h>0){if(o0)){if(o/=d,d<0){if(o0){if(o>l)return;o>s&&(s=o)}if(o=i-f,d||!(o<0)){if(o/=d,d<0){if(o>l)return;o>s&&(s=o)}else if(d>0){if(o0||l<1)||(s>0&&(t[0]=[c+s*h,f+s*d]),l<1&&(t[1]=[c+l*h,f+l*d]),!0)}}}}}function Kw(t,n,e,r,i){var o=t[1];if(o)return!0;var u,a,c=t[0],f=t.left,s=t.right,l=f[0],h=f[1],d=s[0],p=s[1],v=(l+d)/2,g=(h+p)/2;if(p===h){if(vr?(r+i)/2:Math.min(0,r)||Math.max(0,i),u>o?(o+u)/2:Math.min(0,o)||Math.max(0,u))}var IM,FM=function(){var t,n,e=NM,r=jM,i=RM,o=PM,u=zM,a=[0,1/0],c=[[-1/0,-1/0],[1/0,1/0]],f=250,s=vp,l=dt("start","zoom","end"),h=0;function d(t){t.property("__zoom",OM).on("wheel.zoom",m).on("mousedown.zoom",x).on("dblclick.zoom",w).filter(u).on("touchstart.zoom",M).on("touchmove.zoom",A).on("touchend.zoom touchcancel.zoom",k).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(t,n){return(n=Math.max(a[0],Math.min(a[1],n)))===t.k?t:new kM(n,t.x,t.y)}function v(t,n,e){var r=n[0]-e[0]*t.k,i=n[1]-e[1]*t.k;return r===t.x&&i===t.y?t:new kM(t.k,r,i)}function g(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function y(t,n,e){t.on("start.zoom",(function(){_(this,arguments).start()})).on("interrupt.zoom end.zoom",(function(){_(this,arguments).end()})).tween("zoom",(function(){var t=this,i=arguments,o=_(t,i),u=r.apply(t,i),a=null==e?g(u):"function"==typeof e?e.apply(t,i):e,c=Math.max(u[1][0]-u[0][0],u[1][1]-u[0][1]),f=t.__zoom,l="function"==typeof n?n.apply(t,i):n,h=s(f.invert(a).concat(c/f.k),l.invert(a).concat(c/l.k));return function(t){if(1===t)t=l;else{var n=h(t),e=c/n[2];t=new kM(e,a[0]-n[0]*e,a[1]-n[1]*e)}o.zoom(null,t)}}))}function _(t,n,e){return!e&&t.__zooming||new b(t,n)}function b(t,n){this.that=t,this.args=n,this.active=0,this.extent=r.apply(t,n),this.taps=0}function m(){if(e.apply(this,arguments)){var t=_(this,arguments),n=this.__zoom,r=Math.max(a[0],Math.min(a[1],n.k*Math.pow(2,o.apply(this,arguments)))),u=Re(this);if(t.wheel)t.mouse[0][0]===u[0]&&t.mouse[0][1]===u[1]||(t.mouse[1]=n.invert(t.mouse[0]=u)),clearTimeout(t.wheel);else{if(n.k===r)return;t.mouse=[u,n.invert(u)],fr(this),t.start()}EM(),t.wheel=setTimeout(f,150),t.zoom("mouse",i(v(p(n,r),t.mouse[0],t.mouse[1]),t.extent,c))}function f(){t.wheel=null,t.end()}}function x(){if(!n&&e.apply(this,arguments)){var t=_(this,arguments,!0),r=Sn(hn.view).on("mousemove.zoom",f,!0).on("mouseup.zoom",s,!0),o=Re(this),u=hn.clientX,a=hn.clientY;En(hn.view),TM(),t.mouse=[o,this.__zoom.invert(o)],fr(this),t.start()}function f(){if(EM(),!t.moved){var n=hn.clientX-u,e=hn.clientY-a;t.moved=n*n+e*e>h}t.zoom("mouse",i(v(t.that.__zoom,t.mouse[0]=Re(t.that),t.mouse[1]),t.extent,c))}function s(){r.on("mousemove.zoom mouseup.zoom",null),Nn(hn.view,t.moved),EM(),t.end()}}function w(){if(e.apply(this,arguments)){var t=this.__zoom,n=Re(this),o=t.invert(n),u=t.k*(hn.shiftKey?.5:2),a=i(v(p(t,u),n,o),r.apply(this,arguments),c);EM(),f>0?Sn(this).transition().duration(f).call(y,a,n):Sn(this).call(d.transform,a)}}function M(){if(e.apply(this,arguments)){var n,r,i,o,u=hn.touches,a=u.length,c=_(this,arguments,hn.changedTouches.length===a);for(TM(),r=0;r0){var n=this.seriesForMatching.map((function(n){var e=LM.map(n,(function(t){return LM.map(t.datapoints,(function(t){return t[0]}))})),r=LM.zip.apply(LM,e);return t=LM.max(LM.map(r,(function(t){return LM.sum(t)})))}));return LM.max(n)}var e=LM.map(this.visibleSeries,(function(t){return LM.map(t.datapoints,(function(t){return t[0]}))})),r=LM.zip.apply(LM,e);t=LM.max(LM.map(r,(function(t){return LM.sum(t)})))}else t=LM.max(this.visibleSeries.map((function(t){return LM.maxBy(t.datapoints,(function(t){return t[0]}))[0]})));return Math.max(t,0)}},enumerable:!1,configurable:!0}),n}(i.ChartwerkPod),VM={render:function(t){return t("div",{class:{"chartwerk-bar-chart":!0},attrs:{id:this.id}})},mixins:[i.VueChartwerkPodMixin],methods:{render:function(){new qM(document.getElementById(this.id),this.series,this.options).render()}}}}])}));
\ No newline at end of file
diff --git a/dist/types.d.ts b/dist/types.d.ts
new file mode 100644
index 0000000..e6abbfd
--- /dev/null
+++ b/dist/types.d.ts
@@ -0,0 +1,22 @@
+import { TimeSerie, Options } from '@chartwerk/core';
+export declare type BarSerieParams = {
+ matchedKey: string;
+ colorFormatter: (serie: BarTimeSerie) => string;
+};
+export declare type BarTimeSerie = TimeSerie & Partial