├── .gitignore ├── README.md ├── coverage ├── clover.xml ├── coverage-final.json ├── lcov-report │ ├── base.css │ ├── block-navigation.js │ ├── index.html │ ├── prettify.css │ ├── prettify.js │ ├── sort-arrow-sprite.png │ └── sorter.js └── lcov.info ├── dist ├── 95bb59170cb3d15449c5d471ecb07c23.svg └── index.js ├── package.json ├── src ├── chartSlider │ ├── components │ │ ├── drag.svg │ │ └── dragger.jsx │ ├── decorator │ │ ├── dragging.jsx │ │ └── finalDrag.jsx │ ├── index.jsx │ └── index.less ├── decorator │ └── transformDecorator.jsx └── index.jsx └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | npm-debug.log 4 | .vscode 5 | coverage -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### rc-chart-slider 2 | 一个给react图表绘制用的漫游器 3 | 4 | ### 运行效果 5 | ![image](https://gw.alipayobjects.com/zos/rmsportal/YixcFSrFjFjYLhVjOHWO.gif) 6 | 7 | 效果是图表下面的漫游器,我没有单独截图,具体使用的参照可以看[demo](https://github.com/ProtoTeam/time-gantt/tree/master/demo) 8 | 9 | ### 文档 10 | #### DraggingDecorator 11 | ``` 12 | @DraggingDecorator(CHART_WIDTH) // 传入图表宽度 13 | ``` 14 | 15 | #### DragComponent 16 | ``` 17 | import { DragComponent } from 'rc-chart-slider'; 18 | 19 | 29 | ``` 30 | 31 | #### transformDecorator 32 | 回来给svg的图表根据showPercent和showStartPercent偏移一定的距离 33 | ``` 34 | import { transformDecorator } from 'rc-chart-slider'; 35 | @transformDecorator(CHART_WIDTH) // 传入图表宽度 36 | ``` -------------------------------------------------------------------------------- /coverage/clover.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /coverage/coverage-final.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /coverage/lcov-report/base.css: -------------------------------------------------------------------------------- 1 | body, html { 2 | margin:0; padding: 0; 3 | height: 100%; 4 | } 5 | body { 6 | font-family: Helvetica Neue, Helvetica, Arial; 7 | font-size: 14px; 8 | color:#333; 9 | } 10 | .small { font-size: 12px; } 11 | *, *:after, *:before { 12 | -webkit-box-sizing:border-box; 13 | -moz-box-sizing:border-box; 14 | box-sizing:border-box; 15 | } 16 | h1 { font-size: 20px; margin: 0;} 17 | h2 { font-size: 14px; } 18 | pre { 19 | font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace; 20 | margin: 0; 21 | padding: 0; 22 | -moz-tab-size: 2; 23 | -o-tab-size: 2; 24 | tab-size: 2; 25 | } 26 | a { color:#0074D9; text-decoration:none; } 27 | a:hover { text-decoration:underline; } 28 | .strong { font-weight: bold; } 29 | .space-top1 { padding: 10px 0 0 0; } 30 | .pad2y { padding: 20px 0; } 31 | .pad1y { padding: 10px 0; } 32 | .pad2x { padding: 0 20px; } 33 | .pad2 { padding: 20px; } 34 | .pad1 { padding: 10px; } 35 | .space-left2 { padding-left:55px; } 36 | .space-right2 { padding-right:20px; } 37 | .center { text-align:center; } 38 | .clearfix { display:block; } 39 | .clearfix:after { 40 | content:''; 41 | display:block; 42 | height:0; 43 | clear:both; 44 | visibility:hidden; 45 | } 46 | .fl { float: left; } 47 | @media only screen and (max-width:640px) { 48 | .col3 { width:100%; max-width:100%; } 49 | .hide-mobile { display:none!important; } 50 | } 51 | 52 | .quiet { 53 | color: #7f7f7f; 54 | color: rgba(0,0,0,0.5); 55 | } 56 | .quiet a { opacity: 0.7; } 57 | 58 | .fraction { 59 | font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; 60 | font-size: 10px; 61 | color: #555; 62 | background: #E8E8E8; 63 | padding: 4px 5px; 64 | border-radius: 3px; 65 | vertical-align: middle; 66 | } 67 | 68 | div.path a:link, div.path a:visited { color: #333; } 69 | table.coverage { 70 | border-collapse: collapse; 71 | margin: 10px 0 0 0; 72 | padding: 0; 73 | } 74 | 75 | table.coverage td { 76 | margin: 0; 77 | padding: 0; 78 | vertical-align: top; 79 | } 80 | table.coverage td.line-count { 81 | text-align: right; 82 | padding: 0 5px 0 20px; 83 | } 84 | table.coverage td.line-coverage { 85 | text-align: right; 86 | padding-right: 10px; 87 | min-width:20px; 88 | } 89 | 90 | table.coverage td span.cline-any { 91 | display: inline-block; 92 | padding: 0 5px; 93 | width: 100%; 94 | } 95 | .missing-if-branch { 96 | display: inline-block; 97 | margin-right: 5px; 98 | border-radius: 3px; 99 | position: relative; 100 | padding: 0 4px; 101 | background: #333; 102 | color: yellow; 103 | } 104 | 105 | .skip-if-branch { 106 | display: none; 107 | margin-right: 10px; 108 | position: relative; 109 | padding: 0 4px; 110 | background: #ccc; 111 | color: white; 112 | } 113 | .missing-if-branch .typ, .skip-if-branch .typ { 114 | color: inherit !important; 115 | } 116 | .coverage-summary { 117 | border-collapse: collapse; 118 | width: 100%; 119 | } 120 | .coverage-summary tr { border-bottom: 1px solid #bbb; } 121 | .keyline-all { border: 1px solid #ddd; } 122 | .coverage-summary td, .coverage-summary th { padding: 10px; } 123 | .coverage-summary tbody { border: 1px solid #bbb; } 124 | .coverage-summary td { border-right: 1px solid #bbb; } 125 | .coverage-summary td:last-child { border-right: none; } 126 | .coverage-summary th { 127 | text-align: left; 128 | font-weight: normal; 129 | white-space: nowrap; 130 | } 131 | .coverage-summary th.file { border-right: none !important; } 132 | .coverage-summary th.pct { } 133 | .coverage-summary th.pic, 134 | .coverage-summary th.abs, 135 | .coverage-summary td.pct, 136 | .coverage-summary td.abs { text-align: right; } 137 | .coverage-summary td.file { white-space: nowrap; } 138 | .coverage-summary td.pic { min-width: 120px !important; } 139 | .coverage-summary tfoot td { } 140 | 141 | .coverage-summary .sorter { 142 | height: 10px; 143 | width: 7px; 144 | display: inline-block; 145 | margin-left: 0.5em; 146 | background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent; 147 | } 148 | .coverage-summary .sorted .sorter { 149 | background-position: 0 -20px; 150 | } 151 | .coverage-summary .sorted-desc .sorter { 152 | background-position: 0 -10px; 153 | } 154 | .status-line { height: 10px; } 155 | /* yellow */ 156 | .cbranch-no { background: yellow !important; color: #111; } 157 | /* dark red */ 158 | .red.solid, .status-line.low, .low .cover-fill { background:#C21F39 } 159 | .low .chart { border:1px solid #C21F39 } 160 | .highlighted, 161 | .highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{ 162 | background: #C21F39 !important; 163 | } 164 | /* medium red */ 165 | .cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE } 166 | /* light red */ 167 | .low, .cline-no { background:#FCE1E5 } 168 | /* light green */ 169 | .high, .cline-yes { background:rgb(230,245,208) } 170 | /* medium green */ 171 | .cstat-yes { background:rgb(161,215,106) } 172 | /* dark green */ 173 | .status-line.high, .high .cover-fill { background:rgb(77,146,33) } 174 | .high .chart { border:1px solid rgb(77,146,33) } 175 | 176 | .medium .chart { border:1px solid #666; } 177 | .medium .cover-fill { background: #666; } 178 | 179 | .cstat-skip { background: #ddd; color: #111; } 180 | .fstat-skip { background: #ddd; color: #111 !important; } 181 | .cbranch-skip { background: #ddd !important; color: #111; } 182 | 183 | span.cline-neutral { background: #eaeaea; } 184 | .medium { background: #eaeaea; } 185 | 186 | .coverage-summary td.empty { 187 | opacity: .5; 188 | padding-top: 4px; 189 | padding-bottom: 4px; 190 | line-height: 1; 191 | color: #888; 192 | } 193 | 194 | .cover-fill, .cover-empty { 195 | display:inline-block; 196 | height: 12px; 197 | } 198 | .chart { 199 | line-height: 0; 200 | } 201 | .cover-empty { 202 | background: white; 203 | } 204 | .cover-full { 205 | border-right: none !important; 206 | } 207 | pre.prettyprint { 208 | border: none !important; 209 | padding: 0 !important; 210 | margin: 0 !important; 211 | } 212 | .com { color: #999 !important; } 213 | .ignore-none { color: #999; font-weight: normal; } 214 | 215 | .wrapper { 216 | min-height: 100%; 217 | height: auto !important; 218 | height: 100%; 219 | margin: 0 auto -48px; 220 | } 221 | .footer, .push { 222 | height: 48px; 223 | } 224 | -------------------------------------------------------------------------------- /coverage/lcov-report/block-navigation.js: -------------------------------------------------------------------------------- 1 | var jumpToCode = (function init () { 2 | // Classes of code we would like to highlight 3 | var missingCoverageClasses = [ '.cbranch-no', '.cstat-no', '.fstat-no' ]; 4 | 5 | // We don't want to select elements that are direct descendants of another match 6 | var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > ` 7 | 8 | // Selecter that finds elements on the page to which we can jump 9 | var selector = notSelector + missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b` 10 | 11 | // The NodeList of matching elements 12 | var missingCoverageElements = document.querySelectorAll(selector); 13 | 14 | var currentIndex; 15 | 16 | function toggleClass(index) { 17 | missingCoverageElements.item(currentIndex).classList.remove('highlighted'); 18 | missingCoverageElements.item(index).classList.add('highlighted'); 19 | } 20 | 21 | function makeCurrent(index) { 22 | toggleClass(index); 23 | currentIndex = index; 24 | missingCoverageElements.item(index) 25 | .scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center' }); 26 | } 27 | 28 | function goToPrevious() { 29 | var nextIndex = 0; 30 | if (typeof currentIndex !== 'number' || currentIndex === 0) { 31 | nextIndex = missingCoverageElements.length - 1; 32 | } else if (missingCoverageElements.length > 1) { 33 | nextIndex = currentIndex - 1; 34 | } 35 | 36 | makeCurrent(nextIndex); 37 | } 38 | 39 | function goToNext() { 40 | var nextIndex = 0; 41 | 42 | if (typeof currentIndex === 'number' && currentIndex < (missingCoverageElements.length - 1)) { 43 | nextIndex = currentIndex + 1; 44 | } 45 | 46 | makeCurrent(nextIndex); 47 | } 48 | 49 | return function jump(event) { 50 | switch (event.which) { 51 | case 78: // n 52 | case 74: // j 53 | goToNext(); 54 | break; 55 | case 66: // b 56 | case 75: // k 57 | case 80: // p 58 | goToPrevious(); 59 | break; 60 | } 61 | }; 62 | }()); 63 | window.addEventListener('keydown', jumpToCode); 64 | -------------------------------------------------------------------------------- /coverage/lcov-report/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for All files 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 |

19 | All files 20 |

21 |
22 |
23 | Unknown% 24 | Statements 25 | 0/0 26 |
27 |
28 | Unknown% 29 | Branches 30 | 0/0 31 |
32 |
33 | Unknown% 34 | Functions 35 | 0/0 36 |
37 |
38 | Unknown% 39 | Lines 40 | 0/0 41 |
42 |
43 |

44 | Press n or j to go to the next uncovered block, b, p or k for the previous block. 45 |

46 |
47 |
48 |
49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
FileStatementsBranchesFunctionsLines
66 |
67 |
68 | 72 | 73 | 74 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /coverage/lcov-report/prettify.css: -------------------------------------------------------------------------------- 1 | .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} 2 | -------------------------------------------------------------------------------- /coverage/lcov-report/prettify.js: -------------------------------------------------------------------------------- 1 | window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); 2 | -------------------------------------------------------------------------------- /coverage/lcov-report/sort-arrow-sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProtoTeam/rc-chart-slider/f14afe313f7402bae2502175da345922660b00e5/coverage/lcov-report/sort-arrow-sprite.png -------------------------------------------------------------------------------- /coverage/lcov-report/sorter.js: -------------------------------------------------------------------------------- 1 | var addSorting = (function () { 2 | "use strict"; 3 | var cols, 4 | currentSort = { 5 | index: 0, 6 | desc: false 7 | }; 8 | 9 | // returns the summary table element 10 | function getTable() { return document.querySelector('.coverage-summary'); } 11 | // returns the thead element of the summary table 12 | function getTableHeader() { return getTable().querySelector('thead tr'); } 13 | // returns the tbody element of the summary table 14 | function getTableBody() { return getTable().querySelector('tbody'); } 15 | // returns the th element for nth column 16 | function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; } 17 | 18 | // loads all columns 19 | function loadColumns() { 20 | var colNodes = getTableHeader().querySelectorAll('th'), 21 | colNode, 22 | cols = [], 23 | col, 24 | i; 25 | 26 | for (i = 0; i < colNodes.length; i += 1) { 27 | colNode = colNodes[i]; 28 | col = { 29 | key: colNode.getAttribute('data-col'), 30 | sortable: !colNode.getAttribute('data-nosort'), 31 | type: colNode.getAttribute('data-type') || 'string' 32 | }; 33 | cols.push(col); 34 | if (col.sortable) { 35 | col.defaultDescSort = col.type === 'number'; 36 | colNode.innerHTML = colNode.innerHTML + ''; 37 | } 38 | } 39 | return cols; 40 | } 41 | // attaches a data attribute to every tr element with an object 42 | // of data values keyed by column name 43 | function loadRowData(tableRow) { 44 | var tableCols = tableRow.querySelectorAll('td'), 45 | colNode, 46 | col, 47 | data = {}, 48 | i, 49 | val; 50 | for (i = 0; i < tableCols.length; i += 1) { 51 | colNode = tableCols[i]; 52 | col = cols[i]; 53 | val = colNode.getAttribute('data-value'); 54 | if (col.type === 'number') { 55 | val = Number(val); 56 | } 57 | data[col.key] = val; 58 | } 59 | return data; 60 | } 61 | // loads all row data 62 | function loadData() { 63 | var rows = getTableBody().querySelectorAll('tr'), 64 | i; 65 | 66 | for (i = 0; i < rows.length; i += 1) { 67 | rows[i].data = loadRowData(rows[i]); 68 | } 69 | } 70 | // sorts the table using the data for the ith column 71 | function sortByIndex(index, desc) { 72 | var key = cols[index].key, 73 | sorter = function (a, b) { 74 | a = a.data[key]; 75 | b = b.data[key]; 76 | return a < b ? -1 : a > b ? 1 : 0; 77 | }, 78 | finalSorter = sorter, 79 | tableBody = document.querySelector('.coverage-summary tbody'), 80 | rowNodes = tableBody.querySelectorAll('tr'), 81 | rows = [], 82 | i; 83 | 84 | if (desc) { 85 | finalSorter = function (a, b) { 86 | return -1 * sorter(a, b); 87 | }; 88 | } 89 | 90 | for (i = 0; i < rowNodes.length; i += 1) { 91 | rows.push(rowNodes[i]); 92 | tableBody.removeChild(rowNodes[i]); 93 | } 94 | 95 | rows.sort(finalSorter); 96 | 97 | for (i = 0; i < rows.length; i += 1) { 98 | tableBody.appendChild(rows[i]); 99 | } 100 | } 101 | // removes sort indicators for current column being sorted 102 | function removeSortIndicators() { 103 | var col = getNthColumn(currentSort.index), 104 | cls = col.className; 105 | 106 | cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); 107 | col.className = cls; 108 | } 109 | // adds sort indicators for current column being sorted 110 | function addSortIndicators() { 111 | getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted'; 112 | } 113 | // adds event listeners for all sorter widgets 114 | function enableUI() { 115 | var i, 116 | el, 117 | ithSorter = function ithSorter(i) { 118 | var col = cols[i]; 119 | 120 | return function () { 121 | var desc = col.defaultDescSort; 122 | 123 | if (currentSort.index === i) { 124 | desc = !currentSort.desc; 125 | } 126 | sortByIndex(i, desc); 127 | removeSortIndicators(); 128 | currentSort.index = i; 129 | currentSort.desc = desc; 130 | addSortIndicators(); 131 | }; 132 | }; 133 | for (i =0 ; i < cols.length; i += 1) { 134 | if (cols[i].sortable) { 135 | // add the click event handler on the th so users 136 | // dont have to click on those tiny arrows 137 | el = getNthColumn(i).querySelector('.sorter').parentElement; 138 | if (el.addEventListener) { 139 | el.addEventListener('click', ithSorter(i)); 140 | } else { 141 | el.attachEvent('onclick', ithSorter(i)); 142 | } 143 | } 144 | } 145 | } 146 | // adds sorting functionality to the UI 147 | return function () { 148 | if (!getTable()) { 149 | return; 150 | } 151 | cols = loadColumns(); 152 | loadData(cols); 153 | addSortIndicators(); 154 | enableUI(); 155 | }; 156 | })(); 157 | 158 | window.addEventListener('load', addSorting); 159 | -------------------------------------------------------------------------------- /coverage/lcov.info: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProtoTeam/rc-chart-slider/f14afe313f7402bae2502175da345922660b00e5/coverage/lcov.info -------------------------------------------------------------------------------- /dist/95bb59170cb3d15449c5d471ecb07c23.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=9)}([function(e,t){var n,r,o=e.exports={};function a(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}function u(e){if(n===setTimeout)return setTimeout(e,0);if((n===a||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:a}catch(e){n=a}try{r="function"==typeof clearTimeout?clearTimeout:i}catch(e){r=i}}();var c,s=[],l=!1,f=-1;function p(){l&&c&&(l=!1,c.length?s=c.concat(s):f=-1,s.length&&d())}function d(){if(!l){var e=u(p);l=!0;for(var t=s.length;t;){for(c=s,s=[];++f1)for(var n=1;n2?n-2:0),o=2;o1?t-1:0),r=1;rx.length&&x.push(e)}function E(e,t,n,r){var o=typeof e;"undefined"!==o&&"boolean"!==o||(e=null);var a=!1;if(null===e)a=!0;else switch(o){case"string":case"number":a=!0;break;case"object":switch(e.$$typeof){case u:case c:a=!0}}if(a)return n(r,e,""===t?"."+R(e,0):t),1;if(a=0,t=""===t?".":t+":",Array.isArray(e))for(var i=0;i2?n-2:0),o=2;o1?t-1:0),r=1;r1){for(var p=Array(f),d=0;d.")}return t}(t);if(!le[n]){le[n]=!0;var r="";e&&e._owner&&e._owner!==I.current&&(r=" It was passed a child from "+oe(e._owner)+"."),ie=e,a(!1,'Each child in an array or iterator should have a unique "key" prop.%s%s See https://fb.me/react-warning-keys for more information.%s',n,r,ce()),ie=null}}}function pe(e,t){if("object"==typeof e)if(Array.isArray(e))for(var n=0;n1){for(var d=Array(p),y=0;y=0&&l.splice(t,1)}function v(e){var t=document.createElement("style");return e.attrs.type="text/css",g(t,e.attrs),y(e,t),t}function g(e,t){Object.keys(t).forEach(function(n){e.setAttribute(n,t[n])})}function b(e,t){var n,r,o,a;if(t.transform&&e.css){if(!(a=t.transform(e.css)))return function(){};e.css=a}if(t.singleton){var i=s++;n=c||(c=v(t)),r=w.bind(null,n,i,!1),o=w.bind(null,n,i,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(e){var t=document.createElement("link");return e.attrs.type="text/css",e.attrs.rel="stylesheet",g(t,e.attrs),y(e,t),t}(t),r=function(e,t,n){var r=n.css,o=n.sourceMap,a=void 0===t.convertToAbsoluteUrls&&o;(t.convertToAbsoluteUrls||a)&&(r=f(r));o&&(r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var i=new Blob([r],{type:"text/css"}),u=e.href;e.href=URL.createObjectURL(i),u&&URL.revokeObjectURL(u)}.bind(null,n,t),o=function(){h(n),n.href&&URL.revokeObjectURL(n.href)}):(n=v(t),r=function(e,t){var n=t.css,r=t.media;r&&e.setAttribute("media",r);if(e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}.bind(null,n),o=function(){h(n)});return r(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;r(e=t)}else o()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=i()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var n=d(e,t);return p(n,t),function(e){for(var r=[],o=0;o1&&(u=1-i),n.setState({data:Object.assign({},a,{showStartPercent:u})}),o&&o({showPercent:i,showStartPercent:u})}},n.dragSetShowNum=function(t,r,o){if(!1!==n.isDragging){var a=n.props.data,i=a.showPercent,u=a.showStartPercent,c=1*(t/e).toFixed(6),s=void 0,l=void 0;"left"===r?(l=i-c,(s=u+c)<0&&(s=0,l=u+i),s>=u+i&&(s=u+i-.01,l=.01)):(s=u,(l=i+c)<=0&&(l=.01),l+s>=1&&(l=1-s)),n.setState({data:Object.assign({},a,{showStartPercent:s,showPercent:l})}),o&&o({showStartPercent:s,showPercent:l})}},n.setClickDrag=function(e,t){var r=n.props.data,o=r.showPercent,a=r.showStartPercent+e;o+a>1?a=1-o:a<0&&(a=0),n.props.finalDrag({showStartPercent:a,showPercent:o}),t&&t({showStartPercent:a,showPercent:o})},n.finalDrag=function(){var e=n.state.data,t=e.showStartPercent,r=e.showPercent;n.props.finalDrag({showStartPercent:t,showPercent:r})},n.state={data:t.data},n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(u,a.PureComponent),o(u,[{key:"componentWillReceiveProps",value:function(e){this.setState({data:e.data})}},{key:"render",value:function(){var e={setClickDrag:this.setClickDrag,dragSetShowIndex:this.dragSetShowIndex,dragSetShowNum:this.dragSetShowNum,finalDrag:this.finalDrag,changeDragStatus:this.changeDragStatus};return i.default.createElement("div",null,i.default.createElement(t,r({},this.props,{data:this.state.data,_dragActions:e})))}}]),u}(),c.propTypes={},n=s))||n}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r,o=Object.assign||function(e){for(var t=1;t -------------------------------------------------------------------------------- /src/chartSlider/components/dragger.jsx: -------------------------------------------------------------------------------- 1 | import React, { PureComponent } from 'react'; 2 | 3 | class Dragger extends PureComponent { 4 | constructor(props) { 5 | super(props); 6 | this.beginning = false; 7 | this.dragStartClientX = null; 8 | } 9 | 10 | componentDidMount() { 11 | document.addEventListener('mousemove', this.onMouseMove.bind(this), false); 12 | document.addEventListener('mouseup', this.onMouseUp, false); 13 | } 14 | 15 | componentWillUnmount() { 16 | document.removeEventListener('mousemove', this.onMouseMove, false); 17 | document.removeEventListener('mouseup', this.onMouseUp, false); 18 | } 19 | 20 | onMouseDown = () => { 21 | document.body.style.cursor = 'ew-resize'; 22 | document.body.style.userSelect = 'none'; 23 | this.beginning = true; 24 | this.props.changeDragStatus(true); 25 | }; 26 | 27 | onMouseUp = () => { 28 | if (!this.beginning) return; 29 | document.body.style.cursor = 'auto'; 30 | document.body.style.userSelect = 'initial'; 31 | this.beginning = false; 32 | this.dragStartClientX = null; 33 | this.props.changeDragStatus(false); 34 | this.props.finalDrag(); 35 | }; 36 | 37 | onMouseMove = e => { 38 | if (!this.beginning) return; 39 | if (this.dragStartClientX === null) { 40 | this.dragStartClientX = e.clientX; 41 | return; 42 | } 43 | const dragWidth = e.clientX - this.dragStartClientX; 44 | this.props.drag(dragWidth, this.props.direction, this.props.callback); 45 | }; 46 | 47 | render() { 48 | return ( 49 |
50 | ); 51 | } 52 | } 53 | 54 | export default Dragger; 55 | -------------------------------------------------------------------------------- /src/chartSlider/decorator/dragging.jsx: -------------------------------------------------------------------------------- 1 | import React, { PureComponent } from 'react'; 2 | import FinalDrag from './finalDrag.jsx'; 3 | 4 | /** 5 | * 装饰器 6 | */ 7 | const dragging = CHART_WIDTH => 8 | OldComponent => 9 | @FinalDrag() 10 | class Dragging extends PureComponent { 11 | static propTypes = { 12 | }; 13 | 14 | constructor(props) { 15 | super(props); 16 | this.state = { 17 | data: props.data, 18 | }; 19 | } 20 | 21 | componentWillReceiveProps(nextProps) { 22 | this.setState({ 23 | data: nextProps.data, 24 | }); 25 | } 26 | 27 | changeDragStatus = status => { 28 | this.isDragging = status; 29 | }; 30 | 31 | /** 32 | * 拖拽中的效果展示 33 | */ 34 | dragSetShowIndex = (width, direction, callback) => { 35 | if(this.isDragging === false) return; 36 | const { data } = this.props; 37 | const { showPercent, showStartPercent } = data; 38 | 39 | let newShowStartPercent = showStartPercent + (width / CHART_WIDTH).toFixed(6) * 1; 40 | if (newShowStartPercent < 0) { 41 | newShowStartPercent = 0; 42 | } 43 | if ((showPercent + newShowStartPercent) > 1) { 44 | newShowStartPercent = 1 - showPercent; 45 | } 46 | this.setState({ 47 | data: Object.assign({}, data, { 48 | showStartPercent: newShowStartPercent, 49 | }), 50 | }); 51 | if (callback) { 52 | callback({ 53 | showPercent, 54 | showStartPercent: newShowStartPercent, 55 | }); 56 | } 57 | }; 58 | 59 | /** 60 | * 左右句柄拖拽 61 | */ 62 | dragSetShowNum = (dragWidth, direction, callback) => { 63 | if(this.isDragging === false) return; 64 | const { data } = this.props; 65 | const { showPercent, showStartPercent } = data; 66 | 67 | const diff = (dragWidth / CHART_WIDTH).toFixed(6) * 1; 68 | let newIndex; 69 | let newShowNum; 70 | 71 | if (direction === 'left') { 72 | newIndex = showStartPercent + diff; 73 | newShowNum = showPercent - diff; 74 | if (newIndex < 0) { 75 | newIndex = 0; 76 | newShowNum = showStartPercent + showPercent; 77 | } 78 | if (newIndex >= showStartPercent + showPercent) { 79 | newIndex = showStartPercent + showPercent - 0.01; 80 | newShowNum = 0.01; 81 | } 82 | } else { 83 | newIndex = showStartPercent; 84 | newShowNum = showPercent + diff; 85 | if (newShowNum <= 0) newShowNum = 0.01; 86 | if ((newShowNum + newIndex) >= 1) { 87 | newShowNum = 1 - newIndex; 88 | } 89 | } 90 | this.setState({ 91 | data: Object.assign({}, data, { 92 | showStartPercent: newIndex, 93 | showPercent: newShowNum, 94 | }), 95 | }); 96 | if (callback) { 97 | callback({ 98 | showStartPercent: newIndex, 99 | showPercent: newShowNum, 100 | }); 101 | } 102 | }; 103 | 104 | /** 105 | * 点击拖拽时触发 106 | */ 107 | setClickDrag = (diff, callback) => { 108 | const { data } = this.props; 109 | const { showPercent, showStartPercent } = data; 110 | let newShowPercent = showStartPercent + diff; 111 | if ((showPercent + newShowPercent) > 1) { 112 | newShowPercent = 1 - showPercent; 113 | } else if (newShowPercent < 0) { 114 | newShowPercent = 0; 115 | } 116 | this.props.finalDrag({ 117 | showStartPercent: newShowPercent, 118 | showPercent, 119 | }); 120 | if (callback) { 121 | callback({ 122 | showStartPercent: newShowPercent, 123 | showPercent, 124 | }); 125 | } 126 | }; 127 | 128 | /** 129 | * 拖拽结束时触发 130 | */ 131 | finalDrag = () => { 132 | const { showStartPercent, showPercent } = this.state.data; 133 | this.props.finalDrag({ 134 | showStartPercent, 135 | showPercent, 136 | }); 137 | }; 138 | 139 | render() { 140 | const _dragActions = { 141 | setClickDrag: this.setClickDrag, 142 | dragSetShowIndex: this.dragSetShowIndex, 143 | dragSetShowNum: this.dragSetShowNum, 144 | finalDrag: this.finalDrag, 145 | changeDragStatus: this.changeDragStatus, 146 | }; 147 | return ( 148 |
149 | 154 |
155 | ); 156 | } 157 | }; 158 | 159 | export default dragging; 160 | -------------------------------------------------------------------------------- /src/chartSlider/decorator/finalDrag.jsx: -------------------------------------------------------------------------------- 1 | import React, { PureComponent } from 'react'; 2 | 3 | /** 4 | * 装饰器 5 | */ 6 | const finalDrag = () => 7 | OldComponent => 8 | class extends PureComponent { 9 | static propTypes = { 10 | }; 11 | 12 | constructor(props) { 13 | super(props); 14 | this.state = { 15 | data: props.data, 16 | }; 17 | } 18 | 19 | componentWillReceiveProps(nextProps) { 20 | this.setState({ 21 | data: nextProps.data, 22 | }); 23 | } 24 | 25 | finalDrag = params => { 26 | const { showStartPercent, showPercent } = params; 27 | this.setState({ 28 | data: Object.assign({}, this.props.data, { showStartPercent, showPercent }) 29 | }); 30 | }; 31 | 32 | render() { 33 | return ( 34 |
35 | 40 |
41 | ); 42 | } 43 | }; 44 | 45 | export default finalDrag; 46 | -------------------------------------------------------------------------------- /src/chartSlider/index.jsx: -------------------------------------------------------------------------------- 1 | import React, { PureComponent } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import Dragger from './components/dragger.jsx'; 4 | import './index.less'; 5 | 6 | const DefaultClickJumpPercent = 4 / 48; 7 | 8 | class DragComponent extends PureComponent { 9 | static propTypes = { 10 | className: PropTypes.string, 11 | }; 12 | 13 | /** 14 | * 点击左右空白区域触发的点击拖拽 15 | */ 16 | clickDrag = direction => { 17 | const { clickJumpPercent, _dragActions } = this.props; 18 | let cjp = clickJumpPercent ? clickJumpPercent : DefaultClickJumpPercent; 19 | _dragActions.setClickDrag(direction === 'left' ? -1 * cjp : cjp); 20 | }; 21 | 22 | renderDragger = (direction, dragCallback) => { 23 | const { changeDragStatus, finalDrag } = this.props._dragActions; 24 | return ( 25 | 32 | ); 33 | }; 34 | 35 | render() { 36 | const { data, width } = this.props; 37 | const { dragSetShowNum, dragSetShowIndex } = this.props._dragActions; 38 | const { showPercent, showStartPercent } = data; 39 | const areaWidth = width * showPercent; 40 | const positionLeft = showStartPercent * width; 41 | return ( 42 |
43 |
{ this.clickDrag('left'); }} /> 44 |
48 |
49 | {this.renderDragger('left', dragSetShowNum)} 50 |
51 |
52 | {this.renderDragger('right', dragSetShowNum)} 53 |
54 |
55 | {this.renderDragger('', dragSetShowIndex)} 56 |
57 |
58 |
{ this.clickDrag('right'); }} /> 59 |
60 | ); 61 | } 62 | } 63 | 64 | export default DragComponent; 65 | -------------------------------------------------------------------------------- /src/chartSlider/index.less: -------------------------------------------------------------------------------- 1 | .chart-slider{ 2 | display: flex; 3 | height: 30px; 4 | background: rgba(0, 0, 0, 0.005); 5 | position: absolute; 6 | width: 100%; 7 | .left-area{ 8 | flex: 0 0; 9 | min-height: 100%; 10 | } 11 | .drag-area{ 12 | flex: 0 0; 13 | min-height: 100%; 14 | background: rgba(0, 0, 0, 0.06); 15 | position: relative; 16 | .center-drag{ 17 | width: 100%; 18 | height: 100%; 19 | cursor: col-resize; 20 | } 21 | .left-drag, .right-drag{ 22 | display: inline-block; 23 | width: 13px; 24 | height: 100%; 25 | position: absolute; 26 | background: -9px 0 url('./components/drag.svg') no-repeat; 27 | background-size: auto 30px; 28 | cursor: ew-resize; 29 | } 30 | .left-drag{ 31 | left: -6px; 32 | } 33 | .right-drag{ 34 | right: -6px; 35 | } 36 | } 37 | .right-area{ 38 | flex: 1 0; 39 | min-height: 100%; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/decorator/transformDecorator.jsx: -------------------------------------------------------------------------------- 1 | import React, { PureComponent } from 'react'; 2 | 3 | const calTransformWidth = (showPercent, showStartPercent, CHART_WIDTH) => { 4 | return `translate(${ showStartPercent * CHART_WIDTH / showPercent * -1 }, 0)`; 5 | }; 6 | 7 | /** 8 | * 装饰器 9 | */ 10 | const transformDecorator = CHART_WIDTH => 11 | OldComponent => 12 | class extends PureComponent { 13 | static propTypes = {}; 14 | 15 | render() { 16 | const { data } = this.props; 17 | return ( 18 | 21 | 24 | 25 | ); 26 | } 27 | }; 28 | 29 | export default transformDecorator; 30 | -------------------------------------------------------------------------------- /src/index.jsx: -------------------------------------------------------------------------------- 1 | import DragComponentImport from './chartSlider/index.jsx'; 2 | import DraggingDecoratorImport from './chartSlider/decorator/dragging.jsx'; 3 | import transformDecoratorImport from './decorator/transformDecorator.jsx' 4 | 5 | export const DragComponent = DragComponentImport; 6 | export const DraggingDecorator = DraggingDecoratorImport; 7 | export const transformDecorator = transformDecoratorImport; -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var UglifyJsPlugin = require('uglifyjs-webpack-plugin') 3 | var webpack = require('webpack'); 4 | 5 | module.exports = { 6 | entry: './src/index.jsx', 7 | output: { 8 | filename: 'index.js', 9 | path: path.resolve(__dirname, 'dist'), 10 | libraryTarget: 'umd', 11 | }, 12 | module: { 13 | loaders: [ 14 | { 15 | test: /.jsx?$/, 16 | loader: 'babel-loader', 17 | exclude: /node_modules/, 18 | query: { 19 | presets: [ 20 | "es2015", 21 | "react", 22 | "stage-2", 23 | "stage-1", 24 | "stage-0" 25 | ], 26 | plugins: [ 27 | "transform-decorators-legacy", 28 | "dynamic-import-webpack", 29 | ['import', { 30 | libraryName: 'antd', 31 | style: 'css', 32 | }] 33 | ] 34 | } 35 | }, 36 | { 37 | test: /\.less$/, 38 | use: [{ 39 | loader: "style-loader" // creates style nodes from JS strings 40 | }, { 41 | loader: "css-loader" // translates CSS into CommonJS 42 | }, { 43 | loader: "less-loader" // compiles Less to CSS 44 | }] 45 | }, 46 | { 47 | test: /\.css$/, 48 | use: [{ 49 | loader: "style-loader" // creates style nodes from JS strings 50 | }, { 51 | loader: "css-loader" // translates CSS into CommonJS 52 | }] 53 | }, 54 | { 55 | test: /\.svg/, 56 | use: ['url-loader'] 57 | } 58 | ] 59 | }, 60 | externals: {}, 61 | plugins: [ 62 | new UglifyJsPlugin(), 63 | ] 64 | }; --------------------------------------------------------------------------------