@daoyi/nmtl-ui 2.0.1-beta.8 → 2.0.1-beta.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/Autocomplete-cf913b25.js +423 -0
- package/lib/components/Autocomplete.js +19 -1
- package/lib/components/Avatar.js +53 -1
- package/lib/components/BackTop.js +109 -1
- package/lib/components/BarChart.js +762 -1
- package/lib/components/Breadcrumbs.js +122 -1
- package/lib/components/Button-611f1770.js +92 -0
- package/lib/components/Button.js +6 -1
- package/lib/components/Carousel.js +4654 -1
- package/lib/components/Checkbox.js +37 -1
- package/lib/components/CollapseContent.js +179 -1
- package/lib/components/ContactModal-0a4c67b8.js +12020 -0
- package/lib/components/ContactModal.js +22 -3
- package/lib/components/Drawer-55c0f66f.js +156 -0
- package/lib/components/Drawer.js +11 -1
- package/lib/components/Dropdown.js +134 -1
- package/lib/components/Empty-67b4d7d7.js +45 -0
- package/lib/components/Empty.js +5 -1
- package/lib/components/ExportButton.js +112 -1
- package/lib/components/ExtraTools-e4f085bc.js +3537 -0
- package/lib/components/ExtraTools.js +10 -22
- package/lib/components/Filter.js +782 -12
- package/lib/components/Footer.js +271 -1
- package/lib/components/ForwardLink-edab5061.js +106 -0
- package/lib/components/ForwardLink.js +8 -0
- package/lib/components/Header.js +194 -1
- package/lib/components/Image.js +61 -1
- package/lib/components/Input.js +82 -1
- package/lib/components/InputMethod.js +33949 -12
- package/lib/components/KeywordSearch-0b5681d9.js +144 -0
- package/lib/components/KeywordSearch.js +21 -1
- package/lib/components/KeywordTicker.js +190 -1
- package/lib/components/Keywords.js +317 -1
- package/lib/components/Loading.js +28 -1
- package/lib/components/MUITheme.js +2624 -1
- package/lib/components/Modal-c33b7a7f.js +108 -0
- package/lib/components/Modal.js +9 -1
- package/lib/components/MoreButton-b2306abb.js +110 -0
- package/lib/components/MoreButton.js +6 -1
- package/lib/components/Pagination.js +3637 -0
- package/lib/components/Radio.js +78 -1
- package/lib/components/SNA.js +1691 -22
- package/lib/components/Select-9a745e5c.js +115 -0
- package/lib/components/Select.js +8 -1
- package/lib/components/Spin-96bc2c76.js +75 -0
- package/lib/components/Spin.js +6 -1
- package/lib/components/Table.js +51 -1
- package/lib/components/Tooltip-123cc349.js +70 -0
- package/lib/components/Tooltip.js +7 -1
- package/lib/components/_commonjsHelpers-70de2c37.js +28 -0
- package/lib/components/_rollupPluginBabelHelpers-a52356f6.js +142 -0
- package/lib/components/createSvgIcon-ad1104bb.js +576 -0
- package/lib/components/dataExport-04b77185.js +93 -0
- package/lib/components/debounce-127da66c.js +355 -0
- package/lib/components/defaultTheme-ed7746fe.js +1661 -0
- package/lib/components/globalConfig.js +175 -0
- package/lib/components/hoist-non-react-statics.cjs-3f408ad2.js +105 -0
- package/lib/components/index-848f4409.js +61 -0
- package/lib/components/index-983dcd15.js +481 -0
- package/lib/components/isObjectLike-e111475d.js +190 -0
- package/lib/components/style-inject.es-1f59c1d0.js +28 -1
- package/lib/components/toConsumableArray-dbe8af76.js +19 -0
- package/lib/components/transform-3a04288b.js +5475 -0
- package/lib/components/withTheme-2d778133.js +6 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/utils/_rollupPluginBabelHelpers-8dd26e1a.js +121 -0
- package/lib/utils/arrayMerge.js +4953 -1
- package/lib/utils/chunkArray.js +15 -1
- package/lib/utils/convert2HtmlEntities.js +42 -1
- package/lib/utils/domToImage.js +802 -1
- package/lib/utils/downloadGephi.js +106 -1
- package/lib/utils/exportXlsx.js +219 -1
- package/lib/utils/historyAppendSearch.js +502 -1
- package/lib/utils/isDevelopMode.js +5 -1
- package/lib/utils/parseYMD.js +36 -1
- package/lib/utils/removeDuplicateItem.js +11 -1
- package/lib/utils/sendEmail.js +39 -1
- package/lib/utils/snaDefine-6a2bcd94.js +5 -0
- package/lib/utils/snaDefine.js +1 -1
- package/lib/utils/snaPreProcess.js +84 -1
- package/package.json +17 -21
- package/lib/components/Empty-54b79907.js +0 -1
- package/lib/components/KeywordSearch-5a393f12.js +0 -1
- package/lib/components/Select-f2441b83.js +0 -1
- package/lib/components/_rollupPluginBabelHelpers-1b8c042f.js +0 -1
- package/lib/components/_rollupPluginBabelHelpers-ec4e2a53.js +0 -1
- package/lib/components/createSvgIcon-62b64929.js +0 -1
- package/lib/components/createSvgIcon-e24792d4.js +0 -1
- package/lib/components/createTheme-7fffa109.js +0 -1
- package/lib/components/dataExport-9fccd4f0.js +0 -1
- package/lib/components/debounce-c993109b.js +0 -1
- package/lib/components/hoist-non-react-statics.cjs-d6a9befd.js +0 -1
- package/lib/components/index-11391ca3.js +0 -7
- package/lib/components/index-b2745105.js +0 -7
- package/lib/components/isObjectLike-2f1983fe.js +0 -1
- package/lib/components/style-inject.es-c875d022.js +0 -1
- package/lib/components/transform-0eb2d36e.js +0 -1
- package/lib/utils/_commonjsHelpers-e2cda605.js +0 -1
- package/lib/utils/_rollupPluginBabelHelpers-928a52ce.js +0 -1
|
@@ -1 +1,762 @@
|
|
|
1
|
-
import t,{useEffect as n}from"react";import{c as r}from"./index-b2745105.js";import e from"prop-types";import{q as a,f as i,g as o,h as u,j as c,p as l,r as s,u as f,v as h,w as d,s as m}from"./transform-0eb2d36e.js";import{s as g}from"./style-inject.es-1f59c1d0.js";function p(t,n,r){t=+t,n=+n,r=(a=arguments.length)<2?(n=t,t=0,1):a<3?1:+r;for(var e=-1,a=0|Math.max(0,Math.ceil((n-t)/r)),i=new Array(a);++e<a;)i[e]=t+e*r;return i}var v=Math.sqrt(50),M=Math.sqrt(10),y=Math.sqrt(2);function b(t,n,r){var e=(n-t)/Math.max(0,r),a=Math.floor(Math.log(e)/Math.LN10),i=e/Math.pow(10,a);return a>=0?(i>=v?10:i>=M?5:i>=y?2:1)*Math.pow(10,a):-Math.pow(10,-a)/(i>=v?10:i>=M?5:i>=y?2:1)}var w=Array.prototype.slice;function x(t){return t}function k(t){return"translate("+(t+.5)+",0)"}function N(t){return"translate(0,"+(t+.5)+")"}function A(t){return function(n){return+t(n)}}function C(t){var n=Math.max(0,t.bandwidth()-1)/2;return t.round()&&(n=Math.round(n)),function(r){return+t(r)+n}}function S(){return!this.__axis}function j(t,n){var r=[],e=null,a=null,i=6,o=6,u=3,c=1===t||4===t?-1:1,l=4===t||2===t?"x":"y",s=1===t||3===t?k:N;function f(f){var h=null==e?n.ticks?n.ticks.apply(n,r):n.domain():e,d=null==a?n.tickFormat?n.tickFormat.apply(n,r):x:a,m=Math.max(i,0)+u,g=n.range(),p=+g[0]+.5,v=+g[g.length-1]+.5,M=(n.bandwidth?C:A)(n.copy()),y=f.selection?f.selection():f,b=y.selectAll(".domain").data([null]),w=y.selectAll(".tick").data(h,n).order(),k=w.exit(),N=w.enter().append("g").attr("class","tick"),j=w.select("line"),z=w.select("text");b=b.merge(b.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),w=w.merge(N),j=j.merge(N.append("line").attr("stroke","currentColor").attr(l+"2",c*i)),z=z.merge(N.append("text").attr("fill","currentColor").attr(l,c*m).attr("dy",1===t?"0em":3===t?"0.71em":"0.32em")),f!==y&&(b=b.transition(f),w=w.transition(f),j=j.transition(f),z=z.transition(f),k=k.transition(f).attr("opacity",1e-6).attr("transform",(function(t){return isFinite(t=M(t))?s(t):this.getAttribute("transform")})),N.attr("opacity",1e-6).attr("transform",(function(t){var n=this.parentNode.__axis;return s(n&&isFinite(n=n(t))?n:M(t))}))),k.remove(),b.attr("d",4===t||2==t?o?"M"+c*o+","+p+"H0.5V"+v+"H"+c*o:"M0.5,"+p+"V"+v:o?"M"+p+","+c*o+"V0.5H"+v+"V"+c*o:"M"+p+",0.5H"+v),w.attr("opacity",1).attr("transform",(function(t){return s(M(t))})),j.attr(l+"2",c*i),z.attr(l,c*m).text(d),y.filter(S).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",2===t?"start":4===t?"end":"middle"),y.each((function(){this.__axis=M}))}return f.scale=function(t){return arguments.length?(n=t,f):n},f.ticks=function(){return r=w.call(arguments),f},f.tickArguments=function(t){return arguments.length?(r=null==t?[]:w.call(t),f):r.slice()},f.tickValues=function(t){return arguments.length?(e=null==t?null:w.call(t),f):e&&e.slice()},f.tickFormat=function(t){return arguments.length?(a=t,f):a},f.tickSize=function(t){return arguments.length?(i=o=+t,f):i},f.tickSizeInner=function(t){return arguments.length?(i=+t,f):i},f.tickSizeOuter=function(t){return arguments.length?(o=+t,f):o},f.tickPadding=function(t){return arguments.length?(u=+t,f):u},f}function z(t,n){n||(n=[]);var r,e=t?Math.min(n.length,t.length):0,a=n.slice();return function(i){for(r=0;r<e;++r)a[r]=t[r]*(1-i)+n[r]*i;return a}}function E(t,n){var r,e=n?n.length:0,a=t?Math.min(e,t.length):0,i=new Array(a),o=new Array(e);for(r=0;r<a;++r)i[r]=I(t[r],n[r]);for(;r<e;++r)o[r]=n[r];return function(t){for(r=0;r<a;++r)o[r]=i[r](t);return o}}function F(t,n){var r=new Date;return t=+t,n=+n,function(e){return r.setTime(t*(1-e)+n*e),r}}function _(t,n){var r,e={},a={};for(r in null!==t&&"object"==typeof t||(t={}),null!==n&&"object"==typeof n||(n={}),n)r in t?e[r]=I(t[r],n[r]):a[r]=n[r];return function(t){for(r in e)a[r]=e[r](t);return a}}function I(t,n){var r,e,l=typeof n;return null==n||"boolean"===l?a(n):("number"===l?i:"string"===l?(r=o(n))?(n=r,u):c:n instanceof o?u:n instanceof Date?F:(e=n,!ArrayBuffer.isView(e)||e instanceof DataView?Array.isArray(n)?E:"function"!=typeof n.valueOf&&"function"!=typeof n.toString||isNaN(n)?_:i:z))(t,n)}function L(t,n){return t=+t,n=+n,function(r){return Math.round(t*(1-r)+n*r)}}function V(t,n){if((r=(t=n?t.toExponential(n-1):t.toExponential()).indexOf("e"))<0)return null;var r,e=t.slice(0,r);return[e.length>1?e[0]+e.slice(2):e,+t.slice(r+1)]}function D(t){return(t=V(Math.abs(t)))?t[1]:NaN}var O,P=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function B(t){if(!(n=P.exec(t)))throw new Error("invalid format: "+t);var n;return new $({fill:n[1],align:n[2],sign:n[3],symbol:n[4],zero:n[5],width:n[6],comma:n[7],precision:n[8]&&n[8].slice(1),trim:n[9],type:n[10]})}function $(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function q(t,n){var r=V(t,n);if(!r)return t+"";var e=r[0],a=r[1];return a<0?"0."+new Array(-a).join("0")+e:e.length>a+1?e.slice(0,a+1)+"."+e.slice(a+1):e+new Array(a-e.length+2).join("0")}B.prototype=$.prototype,$.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var H={"%":function(t,n){return(100*t).toFixed(n)},b:function(t){return Math.round(t).toString(2)},c:function(t){return t+""},d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:function(t,n){return t.toExponential(n)},f:function(t,n){return t.toFixed(n)},g:function(t,n){return t.toPrecision(n)},o:function(t){return Math.round(t).toString(8)},p:function(t,n){return q(100*t,n)},r:q,s:function(t,n){var r=V(t,n);if(!r)return t+"";var e=r[0],a=r[1],i=a-(O=3*Math.max(-8,Math.min(8,Math.floor(a/3))))+1,o=e.length;return i===o?e:i>o?e+new Array(i-o+1).join("0"):i>0?e.slice(0,i)+"."+e.slice(i):"0."+new Array(1-i).join("0")+V(t,Math.max(0,n+i-1))[0]},X:function(t){return Math.round(t).toString(16).toUpperCase()},x:function(t){return Math.round(t).toString(16)}};function Y(t){return t}var T,R,W,X=Array.prototype.map,G=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function U(t){var n,r,e=void 0===t.grouping||void 0===t.thousands?Y:(n=X.call(t.grouping,Number),r=t.thousands+"",function(t,e){for(var a=t.length,i=[],o=0,u=n[0],c=0;a>0&&u>0&&(c+u+1>e&&(u=Math.max(1,e-c)),i.push(t.substring(a-=u,a+u)),!((c+=u+1)>e));)u=n[o=(o+1)%n.length];return i.reverse().join(r)}),a=void 0===t.currency?"":t.currency[0]+"",i=void 0===t.currency?"":t.currency[1]+"",o=void 0===t.decimal?".":t.decimal+"",u=void 0===t.numerals?Y:function(t){return function(n){return n.replace(/[0-9]/g,(function(n){return t[+n]}))}}(X.call(t.numerals,String)),c=void 0===t.percent?"%":t.percent+"",l=void 0===t.minus?"-":t.minus+"",s=void 0===t.nan?"NaN":t.nan+"";function f(t){var n=(t=B(t)).fill,r=t.align,f=t.sign,h=t.symbol,d=t.zero,m=t.width,g=t.comma,p=t.precision,v=t.trim,M=t.type;"n"===M?(g=!0,M="g"):H[M]||(void 0===p&&(p=12),v=!0,M="g"),(d||"0"===n&&"="===r)&&(d=!0,n="0",r="=");var y="$"===h?a:"#"===h&&/[boxX]/.test(M)?"0"+M.toLowerCase():"",b="$"===h?i:/[%p]/.test(M)?c:"",w=H[M],x=/[defgprs%]/.test(M);function k(t){var a,i,c,h=y,k=b;if("c"===M)k=w(t)+k,t="";else{var N=(t=+t)<0||1/t<0;if(t=isNaN(t)?s:w(Math.abs(t),p),v&&(t=function(t){t:for(var n,r=t.length,e=1,a=-1;e<r;++e)switch(t[e]){case".":a=n=e;break;case"0":0===a&&(a=e),n=e;break;default:if(!+t[e])break t;a>0&&(a=0)}return a>0?t.slice(0,a)+t.slice(n+1):t}(t)),N&&0==+t&&"+"!==f&&(N=!1),h=(N?"("===f?f:l:"-"===f||"("===f?"":f)+h,k=("s"===M?G[8+O/3]:"")+k+(N&&"("===f?")":""),x)for(a=-1,i=t.length;++a<i;)if(48>(c=t.charCodeAt(a))||c>57){k=(46===c?o+t.slice(a+1):t.slice(a))+k,t=t.slice(0,a);break}}g&&!d&&(t=e(t,1/0));var A=h.length+t.length+k.length,C=A<m?new Array(m-A+1).join(n):"";switch(g&&d&&(t=e(C+t,C.length?m-k.length:1/0),C=""),r){case"<":t=h+t+k+C;break;case"=":t=h+C+t+k;break;case"^":t=C.slice(0,A=C.length>>1)+h+t+k+C.slice(A);break;default:t=C+h+t+k}return u(t)}return p=void 0===p?6:/[gprs]/.test(M)?Math.max(1,Math.min(21,p)):Math.max(0,Math.min(20,p)),k.toString=function(){return t+""},k}return{format:f,formatPrefix:function(t,n){var r=f(((t=B(t)).type="f",t)),e=3*Math.max(-8,Math.min(8,Math.floor(D(n)/3))),a=Math.pow(10,-e),i=G[8+e/3];return function(t){return r(a*t)+i}}}}function Z(){var t,n,r=l().unknown(void 0),e=r.domain,a=r.range,i=[0,1],o=!1,u=0,c=0,f=.5;function h(){var r=e().length,l=i[1]<i[0],s=i[l-0],h=i[1-l];t=(h-s)/Math.max(1,r-u+2*c),o&&(t=Math.floor(t)),s+=(h-s-t*(r-u))*f,n=t*(1-u),o&&(s=Math.round(s),n=Math.round(n));var d=p(r).map((function(n){return s+t*n}));return a(l?d.reverse():d)}return delete r.unknown,r.domain=function(t){return arguments.length?(e(t),h()):e()},r.range=function(t){return arguments.length?(i=[+t[0],+t[1]],h()):i.slice()},r.rangeRound=function(t){return i=[+t[0],+t[1]],o=!0,h()},r.bandwidth=function(){return n},r.step=function(){return t},r.round=function(t){return arguments.length?(o=!!t,h()):o},r.padding=function(t){return arguments.length?(u=Math.min(1,c=+t),h()):u},r.paddingInner=function(t){return arguments.length?(u=Math.min(1,t),h()):u},r.paddingOuter=function(t){return arguments.length?(c=+t,h()):c},r.align=function(t){return arguments.length?(f=Math.max(0,Math.min(1,t)),h()):f},r.copy=function(){return Z(e(),i).round(o).paddingInner(u).paddingOuter(c).align(f)},s.apply(h(),arguments)}function J(t){return+t}T=U({decimal:".",thousands:",",grouping:[3],currency:["$",""],minus:"-"}),R=T.format,W=T.formatPrefix;var K=[0,1];function Q(t){return t}function tt(t,n){return(n-=t=+t)?function(r){return(r-t)/n}:(r=isNaN(n)?NaN:.5,function(){return r});var r}function nt(t){var n,r=t[0],e=t[t.length-1];return r>e&&(n=r,r=e,e=n),function(t){return Math.max(r,Math.min(e,t))}}function rt(t,n,r){var e=t[0],a=t[1],i=n[0],o=n[1];return a<e?(e=tt(a,e),i=r(o,i)):(e=tt(e,a),i=r(i,o)),function(t){return i(e(t))}}function et(t,n,r){var e=Math.min(t.length,n.length)-1,a=new Array(e),i=new Array(e),o=-1;for(t[e]<t[0]&&(t=t.slice().reverse(),n=n.slice().reverse());++o<e;)a[o]=tt(t[o],t[o+1]),i[o]=r(n[o],n[o+1]);return function(n){var r=d(t,n,1,e)-1;return i[r](a[r](n))}}function at(t,n){return n.domain(t.domain()).range(t.range()).interpolate(t.interpolate()).clamp(t.clamp()).unknown(t.unknown())}function it(t,n){return function(){var t,n,r,e,a,o,u=K,c=K,l=I,s=Q;function d(){return e=Math.min(u.length,c.length)>2?et:rt,a=o=null,m}function m(n){return isNaN(n=+n)?r:(a||(a=e(u.map(t),c,l)))(t(s(n)))}return m.invert=function(r){return s(n((o||(o=e(c,u.map(t),i)))(r)))},m.domain=function(t){return arguments.length?(u=f.call(t,J),s===Q||(s=nt(u)),d()):u.slice()},m.range=function(t){return arguments.length?(c=h.call(t),d()):c.slice()},m.rangeRound=function(t){return c=h.call(t),l=L,d()},m.clamp=function(t){return arguments.length?(s=t?nt(u):Q,m):s!==Q},m.interpolate=function(t){return arguments.length?(l=t,d()):l},m.unknown=function(t){return arguments.length?(r=t,m):r},function(r,e){return t=r,n=e,d()}}()(t,n)}function ot(t,n,r,e){var a,i=function(t,n,r){var e=Math.abs(n-t)/Math.max(0,r),a=Math.pow(10,Math.floor(Math.log(e)/Math.LN10)),i=e/a;return i>=v?a*=10:i>=M?a*=5:i>=y&&(a*=2),n<t?-a:a}(t,n,r);switch((e=B(null==e?",f":e)).type){case"s":var o=Math.max(Math.abs(t),Math.abs(n));return null!=e.precision||isNaN(a=function(t,n){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(D(n)/3)))-D(Math.abs(t)))}(i,o))||(e.precision=a),W(e,o);case"":case"e":case"g":case"p":case"r":null!=e.precision||isNaN(a=function(t,n){return t=Math.abs(t),n=Math.abs(n)-t,Math.max(0,D(n)-D(t))+1}(i,Math.max(Math.abs(t),Math.abs(n))))||(e.precision=a-("e"===e.type));break;case"f":case"%":null!=e.precision||isNaN(a=function(t){return Math.max(0,-D(Math.abs(t)))}(i))||(e.precision=a-2*("%"===e.type))}return R(e)}function ut(t){var n=t.domain;return t.ticks=function(t){var r=n();return function(t,n,r){var e,a,i,o,u=-1;if(r=+r,(t=+t)==(n=+n)&&r>0)return[t];if((e=n<t)&&(a=t,t=n,n=a),0===(o=b(t,n,r))||!isFinite(o))return[];if(o>0)for(t=Math.ceil(t/o),n=Math.floor(n/o),i=new Array(a=Math.ceil(n-t+1));++u<a;)i[u]=(t+u)*o;else for(t=Math.floor(t*o),n=Math.ceil(n*o),i=new Array(a=Math.ceil(t-n+1));++u<a;)i[u]=(t-u)/o;return e&&i.reverse(),i}(r[0],r[r.length-1],null==t?10:t)},t.tickFormat=function(t,r){var e=n();return ot(e[0],e[e.length-1],null==t?10:t,r)},t.nice=function(r){null==r&&(r=10);var e,a=n(),i=0,o=a.length-1,u=a[i],c=a[o];return c<u&&(e=u,u=c,c=e,e=i,i=o,o=e),(e=b(u,c,r))>0?e=b(u=Math.floor(u/e)*e,c=Math.ceil(c/e)*e,r):e<0&&(e=b(u=Math.ceil(u*e)/e,c=Math.floor(c*e)/e,r)),e>0?(a[i]=Math.floor(u/e)*e,a[o]=Math.ceil(c/e)*e,n(a)):e<0&&(a[i]=Math.ceil(u*e)/e,a[o]=Math.floor(c*e)/e,n(a)),t},t}function ct(){var t=it(Q,Q);return t.copy=function(){return at(t,ct())},s.apply(t,arguments),ut(t)}g("#barChart {\n width: 100%; }\n");var lt=function(e){var a=e.className,i=e.barChartData,o=e.setSelectedYear,u=e.fontColor,c=e.barColor,l=e.width;if(!i||0===i.length)return null;var s=100,f=30,h=90,d=30,g=window.innerWidth<767?2*window.innerWidth-s-h:700-s-h,v=function(t){var n=0;t.forEach((function(t){parseInt(t.count,10)>n&&(n=parseInt(t.count,10))})),m("div#barChart").html("");var r,e=m("#barChart").append("svg").attr("width",l+d+f).attr("height",g+s+h).append("g").attr("transform","translate(".concat(d,",").concat(s,")")),a=Z().range([0,l]).domain(t.map((function(t){return t.year}))).padding(.2);e.append("g").attr("transform","translate(0,".concat(g,")")).call((r=a,j(3,r))).style("color",u).selectAll("text").attr("transform","translate(-10,0)rotate(-45)").style("text-anchor","end").style("color",u).style("font-size",16);var i=ct().domain([0,n]).range([g,0]);e.selectAll("mybar").data(t).enter().append("rect").attr("x",(function(t){return a(t.year)})).attr("width",a.bandwidth()).attr("fill",c).attr("title",(function(t){return t.count})).attr("height",(function(){return g-i(0)})).attr("y",(function(){return i(0)})).style("cursor","pointer").on("click",(function(t){return o(t.year)})).append("svg:title").text((function(t){return"數量:".concat(t.count)})),e.selectAll("rect").transition().duration(800).attr("y",(function(t){return i(t.count)})).attr("height",(function(t){return g-i(t.count)})).delay((function(t,n){return 10*n})),e.append("g").call(function(t){return j(4,t)}(i).tickValues(p(i.domain()[0],i.domain()[1]+1,1)).tickFormat((function(t){return Math.round(t)}))).attr("id","yaxis").style("color",u).style("font-size",15)};function M(){var t=document.getElementById("barChart__block");0===t.scrollLeft&&document.getElementById("yaxis").setAttribute("transform","translate(0, 0 )"),t.scrollLeft>0&&document.getElementById("yaxis").setAttribute("transform","translate(".concat(t.scrollLeft,", 0)"))}return n((function(){i.length>0&&v(i),document.getElementById("barChart__block").addEventListener("scroll",M)}),[i]),t.createElement("div",{id:"barChart",className:r("barChart",a)})};lt.defaultProps={className:void 0,barChartData:[],setSelectedYear:function(){return null},fontColor:"#000",barColor:"#69b3a2",width:2e3},lt.propTypes={className:e.string,barChartData:e.arrayOf(e.any),setSelectedYear:e.func,fontColor:e.string,barColor:e.string,width:e.number};export{lt as default};
|
|
1
|
+
import React__default, { useEffect } from 'react';
|
|
2
|
+
import { c as classNames } from './index-848f4409.js';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { g as constant$1, h as interpolateNumber, j as color, k as interpolateRgb, l as interpolateString, n as exponent, o as ordinal, p as initRange, r as map, s as slice$1, u as bisectRight, v as formatSpecifier, w as formatPrefix, x as format, d as d3Select } from './transform-3a04288b.js';
|
|
5
|
+
import { s as styleInject } from './style-inject.es-1f59c1d0.js';
|
|
6
|
+
|
|
7
|
+
function sequence(start, stop, step) {
|
|
8
|
+
start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
|
|
9
|
+
|
|
10
|
+
var i = -1,
|
|
11
|
+
n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
|
|
12
|
+
range = new Array(n);
|
|
13
|
+
|
|
14
|
+
while (++i < n) {
|
|
15
|
+
range[i] = start + i * step;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return range;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var e10 = Math.sqrt(50),
|
|
22
|
+
e5 = Math.sqrt(10),
|
|
23
|
+
e2 = Math.sqrt(2);
|
|
24
|
+
|
|
25
|
+
function ticks(start, stop, count) {
|
|
26
|
+
var reverse,
|
|
27
|
+
i = -1,
|
|
28
|
+
n,
|
|
29
|
+
ticks,
|
|
30
|
+
step;
|
|
31
|
+
|
|
32
|
+
stop = +stop, start = +start, count = +count;
|
|
33
|
+
if (start === stop && count > 0) return [start];
|
|
34
|
+
if (reverse = stop < start) n = start, start = stop, stop = n;
|
|
35
|
+
if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
|
|
36
|
+
|
|
37
|
+
if (step > 0) {
|
|
38
|
+
start = Math.ceil(start / step);
|
|
39
|
+
stop = Math.floor(stop / step);
|
|
40
|
+
ticks = new Array(n = Math.ceil(stop - start + 1));
|
|
41
|
+
while (++i < n) ticks[i] = (start + i) * step;
|
|
42
|
+
} else {
|
|
43
|
+
start = Math.floor(start * step);
|
|
44
|
+
stop = Math.ceil(stop * step);
|
|
45
|
+
ticks = new Array(n = Math.ceil(start - stop + 1));
|
|
46
|
+
while (++i < n) ticks[i] = (start - i) / step;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (reverse) ticks.reverse();
|
|
50
|
+
|
|
51
|
+
return ticks;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function tickIncrement(start, stop, count) {
|
|
55
|
+
var step = (stop - start) / Math.max(0, count),
|
|
56
|
+
power = Math.floor(Math.log(step) / Math.LN10),
|
|
57
|
+
error = step / Math.pow(10, power);
|
|
58
|
+
return power >= 0
|
|
59
|
+
? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
|
|
60
|
+
: -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function tickStep(start, stop, count) {
|
|
64
|
+
var step0 = Math.abs(stop - start) / Math.max(0, count),
|
|
65
|
+
step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
|
|
66
|
+
error = step0 / step1;
|
|
67
|
+
if (error >= e10) step1 *= 10;
|
|
68
|
+
else if (error >= e5) step1 *= 5;
|
|
69
|
+
else if (error >= e2) step1 *= 2;
|
|
70
|
+
return stop < start ? -step1 : step1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var slice = Array.prototype.slice;
|
|
74
|
+
|
|
75
|
+
function identity$1(x) {
|
|
76
|
+
return x;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var top = 1,
|
|
80
|
+
right = 2,
|
|
81
|
+
bottom = 3,
|
|
82
|
+
left = 4,
|
|
83
|
+
epsilon = 1e-6;
|
|
84
|
+
|
|
85
|
+
function translateX(x) {
|
|
86
|
+
return "translate(" + (x + 0.5) + ",0)";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function translateY(y) {
|
|
90
|
+
return "translate(0," + (y + 0.5) + ")";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function number$1(scale) {
|
|
94
|
+
return function(d) {
|
|
95
|
+
return +scale(d);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function center(scale) {
|
|
100
|
+
var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
|
|
101
|
+
if (scale.round()) offset = Math.round(offset);
|
|
102
|
+
return function(d) {
|
|
103
|
+
return +scale(d) + offset;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function entering() {
|
|
108
|
+
return !this.__axis;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function axis(orient, scale) {
|
|
112
|
+
var tickArguments = [],
|
|
113
|
+
tickValues = null,
|
|
114
|
+
tickFormat = null,
|
|
115
|
+
tickSizeInner = 6,
|
|
116
|
+
tickSizeOuter = 6,
|
|
117
|
+
tickPadding = 3,
|
|
118
|
+
k = orient === top || orient === left ? -1 : 1,
|
|
119
|
+
x = orient === left || orient === right ? "x" : "y",
|
|
120
|
+
transform = orient === top || orient === bottom ? translateX : translateY;
|
|
121
|
+
|
|
122
|
+
function axis(context) {
|
|
123
|
+
var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
|
|
124
|
+
format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
|
|
125
|
+
spacing = Math.max(tickSizeInner, 0) + tickPadding,
|
|
126
|
+
range = scale.range(),
|
|
127
|
+
range0 = +range[0] + 0.5,
|
|
128
|
+
range1 = +range[range.length - 1] + 0.5,
|
|
129
|
+
position = (scale.bandwidth ? center : number$1)(scale.copy()),
|
|
130
|
+
selection = context.selection ? context.selection() : context,
|
|
131
|
+
path = selection.selectAll(".domain").data([null]),
|
|
132
|
+
tick = selection.selectAll(".tick").data(values, scale).order(),
|
|
133
|
+
tickExit = tick.exit(),
|
|
134
|
+
tickEnter = tick.enter().append("g").attr("class", "tick"),
|
|
135
|
+
line = tick.select("line"),
|
|
136
|
+
text = tick.select("text");
|
|
137
|
+
|
|
138
|
+
path = path.merge(path.enter().insert("path", ".tick")
|
|
139
|
+
.attr("class", "domain")
|
|
140
|
+
.attr("stroke", "currentColor"));
|
|
141
|
+
|
|
142
|
+
tick = tick.merge(tickEnter);
|
|
143
|
+
|
|
144
|
+
line = line.merge(tickEnter.append("line")
|
|
145
|
+
.attr("stroke", "currentColor")
|
|
146
|
+
.attr(x + "2", k * tickSizeInner));
|
|
147
|
+
|
|
148
|
+
text = text.merge(tickEnter.append("text")
|
|
149
|
+
.attr("fill", "currentColor")
|
|
150
|
+
.attr(x, k * spacing)
|
|
151
|
+
.attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
|
|
152
|
+
|
|
153
|
+
if (context !== selection) {
|
|
154
|
+
path = path.transition(context);
|
|
155
|
+
tick = tick.transition(context);
|
|
156
|
+
line = line.transition(context);
|
|
157
|
+
text = text.transition(context);
|
|
158
|
+
|
|
159
|
+
tickExit = tickExit.transition(context)
|
|
160
|
+
.attr("opacity", epsilon)
|
|
161
|
+
.attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
|
|
162
|
+
|
|
163
|
+
tickEnter
|
|
164
|
+
.attr("opacity", epsilon)
|
|
165
|
+
.attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
tickExit.remove();
|
|
169
|
+
|
|
170
|
+
path
|
|
171
|
+
.attr("d", orient === left || orient == right
|
|
172
|
+
? (tickSizeOuter ? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter : "M0.5," + range0 + "V" + range1)
|
|
173
|
+
: (tickSizeOuter ? "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter : "M" + range0 + ",0.5H" + range1));
|
|
174
|
+
|
|
175
|
+
tick
|
|
176
|
+
.attr("opacity", 1)
|
|
177
|
+
.attr("transform", function(d) { return transform(position(d)); });
|
|
178
|
+
|
|
179
|
+
line
|
|
180
|
+
.attr(x + "2", k * tickSizeInner);
|
|
181
|
+
|
|
182
|
+
text
|
|
183
|
+
.attr(x, k * spacing)
|
|
184
|
+
.text(format);
|
|
185
|
+
|
|
186
|
+
selection.filter(entering)
|
|
187
|
+
.attr("fill", "none")
|
|
188
|
+
.attr("font-size", 10)
|
|
189
|
+
.attr("font-family", "sans-serif")
|
|
190
|
+
.attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
|
|
191
|
+
|
|
192
|
+
selection
|
|
193
|
+
.each(function() { this.__axis = position; });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
axis.scale = function(_) {
|
|
197
|
+
return arguments.length ? (scale = _, axis) : scale;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
axis.ticks = function() {
|
|
201
|
+
return tickArguments = slice.call(arguments), axis;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
axis.tickArguments = function(_) {
|
|
205
|
+
return arguments.length ? (tickArguments = _ == null ? [] : slice.call(_), axis) : tickArguments.slice();
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
axis.tickValues = function(_) {
|
|
209
|
+
return arguments.length ? (tickValues = _ == null ? null : slice.call(_), axis) : tickValues && tickValues.slice();
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
axis.tickFormat = function(_) {
|
|
213
|
+
return arguments.length ? (tickFormat = _, axis) : tickFormat;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
axis.tickSize = function(_) {
|
|
217
|
+
return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
axis.tickSizeInner = function(_) {
|
|
221
|
+
return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
axis.tickSizeOuter = function(_) {
|
|
225
|
+
return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
axis.tickPadding = function(_) {
|
|
229
|
+
return arguments.length ? (tickPadding = +_, axis) : tickPadding;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
return axis;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function axisBottom(scale) {
|
|
236
|
+
return axis(bottom, scale);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function axisLeft(scale) {
|
|
240
|
+
return axis(left, scale);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function numberArray(a, b) {
|
|
244
|
+
if (!b) b = [];
|
|
245
|
+
var n = a ? Math.min(b.length, a.length) : 0,
|
|
246
|
+
c = b.slice(),
|
|
247
|
+
i;
|
|
248
|
+
return function(t) {
|
|
249
|
+
for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
|
|
250
|
+
return c;
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function isNumberArray(x) {
|
|
255
|
+
return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function genericArray(a, b) {
|
|
259
|
+
var nb = b ? b.length : 0,
|
|
260
|
+
na = a ? Math.min(nb, a.length) : 0,
|
|
261
|
+
x = new Array(na),
|
|
262
|
+
c = new Array(nb),
|
|
263
|
+
i;
|
|
264
|
+
|
|
265
|
+
for (i = 0; i < na; ++i) x[i] = interpolateValue(a[i], b[i]);
|
|
266
|
+
for (; i < nb; ++i) c[i] = b[i];
|
|
267
|
+
|
|
268
|
+
return function(t) {
|
|
269
|
+
for (i = 0; i < na; ++i) c[i] = x[i](t);
|
|
270
|
+
return c;
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function date(a, b) {
|
|
275
|
+
var d = new Date;
|
|
276
|
+
return a = +a, b = +b, function(t) {
|
|
277
|
+
return d.setTime(a * (1 - t) + b * t), d;
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function object(a, b) {
|
|
282
|
+
var i = {},
|
|
283
|
+
c = {},
|
|
284
|
+
k;
|
|
285
|
+
|
|
286
|
+
if (a === null || typeof a !== "object") a = {};
|
|
287
|
+
if (b === null || typeof b !== "object") b = {};
|
|
288
|
+
|
|
289
|
+
for (k in b) {
|
|
290
|
+
if (k in a) {
|
|
291
|
+
i[k] = interpolateValue(a[k], b[k]);
|
|
292
|
+
} else {
|
|
293
|
+
c[k] = b[k];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return function(t) {
|
|
298
|
+
for (k in i) c[k] = i[k](t);
|
|
299
|
+
return c;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function interpolateValue(a, b) {
|
|
304
|
+
var t = typeof b, c;
|
|
305
|
+
return b == null || t === "boolean" ? constant$1(b)
|
|
306
|
+
: (t === "number" ? interpolateNumber
|
|
307
|
+
: t === "string" ? ((c = color(b)) ? (b = c, interpolateRgb) : interpolateString)
|
|
308
|
+
: b instanceof color ? interpolateRgb
|
|
309
|
+
: b instanceof Date ? date
|
|
310
|
+
: isNumberArray(b) ? numberArray
|
|
311
|
+
: Array.isArray(b) ? genericArray
|
|
312
|
+
: typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
|
|
313
|
+
: interpolateNumber)(a, b);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function interpolateRound(a, b) {
|
|
317
|
+
return a = +a, b = +b, function(t) {
|
|
318
|
+
return Math.round(a * (1 - t) + b * t);
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function precisionFixed(step) {
|
|
323
|
+
return Math.max(0, -exponent(Math.abs(step)));
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function precisionPrefix(step, value) {
|
|
327
|
+
return Math.max(0, Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3 - exponent(Math.abs(step)));
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function precisionRound(step, max) {
|
|
331
|
+
step = Math.abs(step), max = Math.abs(max) - step;
|
|
332
|
+
return Math.max(0, exponent(max) - exponent(step)) + 1;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function band() {
|
|
336
|
+
var scale = ordinal().unknown(undefined),
|
|
337
|
+
domain = scale.domain,
|
|
338
|
+
ordinalRange = scale.range,
|
|
339
|
+
range = [0, 1],
|
|
340
|
+
step,
|
|
341
|
+
bandwidth,
|
|
342
|
+
round = false,
|
|
343
|
+
paddingInner = 0,
|
|
344
|
+
paddingOuter = 0,
|
|
345
|
+
align = 0.5;
|
|
346
|
+
|
|
347
|
+
delete scale.unknown;
|
|
348
|
+
|
|
349
|
+
function rescale() {
|
|
350
|
+
var n = domain().length,
|
|
351
|
+
reverse = range[1] < range[0],
|
|
352
|
+
start = range[reverse - 0],
|
|
353
|
+
stop = range[1 - reverse];
|
|
354
|
+
step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
|
|
355
|
+
if (round) step = Math.floor(step);
|
|
356
|
+
start += (stop - start - step * (n - paddingInner)) * align;
|
|
357
|
+
bandwidth = step * (1 - paddingInner);
|
|
358
|
+
if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
|
|
359
|
+
var values = sequence(n).map(function(i) { return start + step * i; });
|
|
360
|
+
return ordinalRange(reverse ? values.reverse() : values);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
scale.domain = function(_) {
|
|
364
|
+
return arguments.length ? (domain(_), rescale()) : domain();
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
scale.range = function(_) {
|
|
368
|
+
return arguments.length ? (range = [+_[0], +_[1]], rescale()) : range.slice();
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
scale.rangeRound = function(_) {
|
|
372
|
+
return range = [+_[0], +_[1]], round = true, rescale();
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
scale.bandwidth = function() {
|
|
376
|
+
return bandwidth;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
scale.step = function() {
|
|
380
|
+
return step;
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
scale.round = function(_) {
|
|
384
|
+
return arguments.length ? (round = !!_, rescale()) : round;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
scale.padding = function(_) {
|
|
388
|
+
return arguments.length ? (paddingInner = Math.min(1, paddingOuter = +_), rescale()) : paddingInner;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
scale.paddingInner = function(_) {
|
|
392
|
+
return arguments.length ? (paddingInner = Math.min(1, _), rescale()) : paddingInner;
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
scale.paddingOuter = function(_) {
|
|
396
|
+
return arguments.length ? (paddingOuter = +_, rescale()) : paddingOuter;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
scale.align = function(_) {
|
|
400
|
+
return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
scale.copy = function() {
|
|
404
|
+
return band(domain(), range)
|
|
405
|
+
.round(round)
|
|
406
|
+
.paddingInner(paddingInner)
|
|
407
|
+
.paddingOuter(paddingOuter)
|
|
408
|
+
.align(align);
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
return initRange.apply(rescale(), arguments);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function constant(x) {
|
|
415
|
+
return function() {
|
|
416
|
+
return x;
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function number(x) {
|
|
421
|
+
return +x;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
var unit = [0, 1];
|
|
425
|
+
|
|
426
|
+
function identity(x) {
|
|
427
|
+
return x;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function normalize(a, b) {
|
|
431
|
+
return (b -= (a = +a))
|
|
432
|
+
? function(x) { return (x - a) / b; }
|
|
433
|
+
: constant(isNaN(b) ? NaN : 0.5);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function clamper(domain) {
|
|
437
|
+
var a = domain[0], b = domain[domain.length - 1], t;
|
|
438
|
+
if (a > b) t = a, a = b, b = t;
|
|
439
|
+
return function(x) { return Math.max(a, Math.min(b, x)); };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// normalize(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
|
|
443
|
+
// interpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding range value x in [a,b].
|
|
444
|
+
function bimap(domain, range, interpolate) {
|
|
445
|
+
var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
|
|
446
|
+
if (d1 < d0) d0 = normalize(d1, d0), r0 = interpolate(r1, r0);
|
|
447
|
+
else d0 = normalize(d0, d1), r0 = interpolate(r0, r1);
|
|
448
|
+
return function(x) { return r0(d0(x)); };
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function polymap(domain, range, interpolate) {
|
|
452
|
+
var j = Math.min(domain.length, range.length) - 1,
|
|
453
|
+
d = new Array(j),
|
|
454
|
+
r = new Array(j),
|
|
455
|
+
i = -1;
|
|
456
|
+
|
|
457
|
+
// Reverse descending domains.
|
|
458
|
+
if (domain[j] < domain[0]) {
|
|
459
|
+
domain = domain.slice().reverse();
|
|
460
|
+
range = range.slice().reverse();
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
while (++i < j) {
|
|
464
|
+
d[i] = normalize(domain[i], domain[i + 1]);
|
|
465
|
+
r[i] = interpolate(range[i], range[i + 1]);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return function(x) {
|
|
469
|
+
var i = bisectRight(domain, x, 1, j) - 1;
|
|
470
|
+
return r[i](d[i](x));
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function copy(source, target) {
|
|
475
|
+
return target
|
|
476
|
+
.domain(source.domain())
|
|
477
|
+
.range(source.range())
|
|
478
|
+
.interpolate(source.interpolate())
|
|
479
|
+
.clamp(source.clamp())
|
|
480
|
+
.unknown(source.unknown());
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function transformer() {
|
|
484
|
+
var domain = unit,
|
|
485
|
+
range = unit,
|
|
486
|
+
interpolate = interpolateValue,
|
|
487
|
+
transform,
|
|
488
|
+
untransform,
|
|
489
|
+
unknown,
|
|
490
|
+
clamp = identity,
|
|
491
|
+
piecewise,
|
|
492
|
+
output,
|
|
493
|
+
input;
|
|
494
|
+
|
|
495
|
+
function rescale() {
|
|
496
|
+
piecewise = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
|
|
497
|
+
output = input = null;
|
|
498
|
+
return scale;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function scale(x) {
|
|
502
|
+
return isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate)))(transform(clamp(x)));
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
scale.invert = function(y) {
|
|
506
|
+
return clamp(untransform((input || (input = piecewise(range, domain.map(transform), interpolateNumber)))(y)));
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
scale.domain = function(_) {
|
|
510
|
+
return arguments.length ? (domain = map.call(_, number), clamp === identity || (clamp = clamper(domain)), rescale()) : domain.slice();
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
scale.range = function(_) {
|
|
514
|
+
return arguments.length ? (range = slice$1.call(_), rescale()) : range.slice();
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
scale.rangeRound = function(_) {
|
|
518
|
+
return range = slice$1.call(_), interpolate = interpolateRound, rescale();
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
scale.clamp = function(_) {
|
|
522
|
+
return arguments.length ? (clamp = _ ? clamper(domain) : identity, scale) : clamp !== identity;
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
scale.interpolate = function(_) {
|
|
526
|
+
return arguments.length ? (interpolate = _, rescale()) : interpolate;
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
scale.unknown = function(_) {
|
|
530
|
+
return arguments.length ? (unknown = _, scale) : unknown;
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
return function(t, u) {
|
|
534
|
+
transform = t, untransform = u;
|
|
535
|
+
return rescale();
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function continuous(transform, untransform) {
|
|
540
|
+
return transformer()(transform, untransform);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function tickFormat(start, stop, count, specifier) {
|
|
544
|
+
var step = tickStep(start, stop, count),
|
|
545
|
+
precision;
|
|
546
|
+
specifier = formatSpecifier(specifier == null ? ",f" : specifier);
|
|
547
|
+
switch (specifier.type) {
|
|
548
|
+
case "s": {
|
|
549
|
+
var value = Math.max(Math.abs(start), Math.abs(stop));
|
|
550
|
+
if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
|
|
551
|
+
return formatPrefix(specifier, value);
|
|
552
|
+
}
|
|
553
|
+
case "":
|
|
554
|
+
case "e":
|
|
555
|
+
case "g":
|
|
556
|
+
case "p":
|
|
557
|
+
case "r": {
|
|
558
|
+
if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
case "f":
|
|
562
|
+
case "%": {
|
|
563
|
+
if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return format(specifier);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function linearish(scale) {
|
|
571
|
+
var domain = scale.domain;
|
|
572
|
+
|
|
573
|
+
scale.ticks = function(count) {
|
|
574
|
+
var d = domain();
|
|
575
|
+
return ticks(d[0], d[d.length - 1], count == null ? 10 : count);
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
scale.tickFormat = function(count, specifier) {
|
|
579
|
+
var d = domain();
|
|
580
|
+
return tickFormat(d[0], d[d.length - 1], count == null ? 10 : count, specifier);
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
scale.nice = function(count) {
|
|
584
|
+
if (count == null) count = 10;
|
|
585
|
+
|
|
586
|
+
var d = domain(),
|
|
587
|
+
i0 = 0,
|
|
588
|
+
i1 = d.length - 1,
|
|
589
|
+
start = d[i0],
|
|
590
|
+
stop = d[i1],
|
|
591
|
+
step;
|
|
592
|
+
|
|
593
|
+
if (stop < start) {
|
|
594
|
+
step = start, start = stop, stop = step;
|
|
595
|
+
step = i0, i0 = i1, i1 = step;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
step = tickIncrement(start, stop, count);
|
|
599
|
+
|
|
600
|
+
if (step > 0) {
|
|
601
|
+
start = Math.floor(start / step) * step;
|
|
602
|
+
stop = Math.ceil(stop / step) * step;
|
|
603
|
+
step = tickIncrement(start, stop, count);
|
|
604
|
+
} else if (step < 0) {
|
|
605
|
+
start = Math.ceil(start * step) / step;
|
|
606
|
+
stop = Math.floor(stop * step) / step;
|
|
607
|
+
step = tickIncrement(start, stop, count);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (step > 0) {
|
|
611
|
+
d[i0] = Math.floor(start / step) * step;
|
|
612
|
+
d[i1] = Math.ceil(stop / step) * step;
|
|
613
|
+
domain(d);
|
|
614
|
+
} else if (step < 0) {
|
|
615
|
+
d[i0] = Math.ceil(start * step) / step;
|
|
616
|
+
d[i1] = Math.floor(stop * step) / step;
|
|
617
|
+
domain(d);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
return scale;
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
return scale;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
function linear() {
|
|
627
|
+
var scale = continuous(identity, identity);
|
|
628
|
+
|
|
629
|
+
scale.copy = function() {
|
|
630
|
+
return copy(scale, linear());
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
initRange.apply(scale, arguments);
|
|
634
|
+
|
|
635
|
+
return linearish(scale);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
var css_248z = "#barChart {\n width: 100%; }\n";
|
|
639
|
+
styleInject(css_248z);
|
|
640
|
+
|
|
641
|
+
var BarChart = function BarChart(_ref) {
|
|
642
|
+
var className = _ref.className,
|
|
643
|
+
barChartData = _ref.barChartData,
|
|
644
|
+
setSelectedYear = _ref.setSelectedYear,
|
|
645
|
+
fontColor = _ref.fontColor,
|
|
646
|
+
barColor = _ref.barColor,
|
|
647
|
+
width = _ref.width,
|
|
648
|
+
scaleTicks = _ref.scaleTicks;
|
|
649
|
+
if (!barChartData || barChartData.length === 0) {
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
// set the dimensions and margins of the graph
|
|
653
|
+
var margin = {
|
|
654
|
+
top: 100,
|
|
655
|
+
right: 30,
|
|
656
|
+
bottom: 90,
|
|
657
|
+
left: 35
|
|
658
|
+
};
|
|
659
|
+
var height = window.innerWidth < 767 ? window.innerWidth * 2 - margin.top - margin.bottom : 700 - margin.top - margin.bottom;
|
|
660
|
+
|
|
661
|
+
// Parse the Data
|
|
662
|
+
var readData = function readData(data) {
|
|
663
|
+
var maxValue = 0;
|
|
664
|
+
data.forEach(function (item) {
|
|
665
|
+
if (parseInt(item.count, 10) > maxValue) {
|
|
666
|
+
maxValue = parseInt(item.count, 10);
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
d3Select('div#barChart').html('');
|
|
670
|
+
var svg = d3Select('#barChart').append('svg').attr('width', width + margin.left + margin.right).attr('height', height + margin.top + margin.bottom).append('g').attr('transform', "translate(".concat(margin.left, ",").concat(margin.top, ")"));
|
|
671
|
+
// X axis
|
|
672
|
+
var x = band().range([0, width]).domain(data.map(function (d) {
|
|
673
|
+
return d.year;
|
|
674
|
+
})).padding(0.2);
|
|
675
|
+
svg.append('g').attr('id', 'xaxis').attr('transform', "translate(0,".concat(height, ")")).call(axisBottom(x)).style('color', fontColor).selectAll('text').attr('transform', 'translate(-10,0)rotate(-45)').style('text-anchor', 'end').style('color', fontColor).style('font-size', 16).style('cursor', 'pointer').on('click', function (d) {
|
|
676
|
+
setSelectedYear(d);
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
// Add Y axis
|
|
680
|
+
var y = linear().domain([0, maxValue]).range([height, 0]);
|
|
681
|
+
|
|
682
|
+
// Bars
|
|
683
|
+
svg.selectAll('mybar').data(data).enter().append('rect').attr('x', function (d) {
|
|
684
|
+
return x(d.year);
|
|
685
|
+
}).attr('width', x.bandwidth()).attr('fill', barColor).attr('title', function (d) {
|
|
686
|
+
return d.count;
|
|
687
|
+
})
|
|
688
|
+
// no bar at the beginning thus:
|
|
689
|
+
.attr('height', function () {
|
|
690
|
+
return height - y(0);
|
|
691
|
+
}) // always equal to 0
|
|
692
|
+
.attr('y', function () {
|
|
693
|
+
return y(0);
|
|
694
|
+
}).style('cursor', 'pointer').on('click', function (d) {
|
|
695
|
+
return setSelectedYear(d.year);
|
|
696
|
+
}).append('svg:title').text(function (d) {
|
|
697
|
+
return "\u6578\u91CF:".concat(d.count);
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
// Animation
|
|
701
|
+
svg.selectAll('rect').transition().duration(800).attr('y', function (d) {
|
|
702
|
+
return y(d.count);
|
|
703
|
+
}).attr('height', function (d) {
|
|
704
|
+
return height - y(d.count);
|
|
705
|
+
}).delay(function (d, i) {
|
|
706
|
+
return i * 10;
|
|
707
|
+
});
|
|
708
|
+
svg.append('g').call(axisLeft(y).tickValues(sequence(y.domain()[0], y.domain()[1] + 1, scaleTicks)).tickFormat(function (d) {
|
|
709
|
+
return Math.round(d);
|
|
710
|
+
})).attr('id', 'yaxis').style('color', fontColor).style('font-size', 15);
|
|
711
|
+
};
|
|
712
|
+
function shiftYaxis() {
|
|
713
|
+
var element = document.getElementById('barChart__block');
|
|
714
|
+
if (element.scrollLeft === 0) {
|
|
715
|
+
document.getElementById('yaxis').setAttribute('transform', 'translate(0, 0 )');
|
|
716
|
+
}
|
|
717
|
+
if (element.scrollLeft > 0) {
|
|
718
|
+
document.getElementById('yaxis').setAttribute('transform', "translate(".concat(element.scrollLeft, ", 0)"));
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
useEffect(function () {
|
|
722
|
+
if (barChartData.length > 0) {
|
|
723
|
+
readData(barChartData);
|
|
724
|
+
}
|
|
725
|
+
document.getElementById('barChart__block').addEventListener('scroll', shiftYaxis);
|
|
726
|
+
}, [barChartData]);
|
|
727
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
|
728
|
+
id: "barChart",
|
|
729
|
+
className: classNames('barChart', className)
|
|
730
|
+
});
|
|
731
|
+
};
|
|
732
|
+
BarChart.defaultProps = {
|
|
733
|
+
className: undefined,
|
|
734
|
+
barChartData: [],
|
|
735
|
+
setSelectedYear: function setSelectedYear() {
|
|
736
|
+
return null;
|
|
737
|
+
},
|
|
738
|
+
fontColor: '#000',
|
|
739
|
+
barColor: '#69b3a2',
|
|
740
|
+
width: 2000,
|
|
741
|
+
scaleTicks: 1
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
/* Write props detail information and 'npm run updateStory' will help you generate stories's argTypes */
|
|
745
|
+
BarChart.propTypes = {
|
|
746
|
+
/** Css Name */
|
|
747
|
+
className: PropTypes.string,
|
|
748
|
+
/** 資料來源 */
|
|
749
|
+
barChartData: PropTypes.arrayOf(PropTypes.any),
|
|
750
|
+
/** 設定點選年分 */
|
|
751
|
+
setSelectedYear: PropTypes.func,
|
|
752
|
+
/** X、Y尺度字的顏色 */
|
|
753
|
+
fontColor: PropTypes.string,
|
|
754
|
+
/** 長條圖的顏色 */
|
|
755
|
+
barColor: PropTypes.string,
|
|
756
|
+
/** 圖表的寬度,影響bar的粗度 */
|
|
757
|
+
width: PropTypes.number,
|
|
758
|
+
/** 刻度的級距,以一個刻度相差多少 */
|
|
759
|
+
scaleTicks: PropTypes.number
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
export { BarChart as default };
|