From 0d1957387c1ec195717a1c472c792b8641b2c2fd Mon Sep 17 00:00:00 2001 From: lxsang Date: Mon, 4 Jul 2022 22:42:48 +0200 Subject: [PATCH] minor improvement on gitgraph --- GitGraph/LibGitGraph.ts | 1 + GitGraph/README.md | 1 + GitGraph/build/debug/README.md | 1 + GitGraph/build/debug/libgitgraph.js | 2 +- GitGraph/build/debug/main.css | 2 +- GitGraph/build/debug/package.json | 2 +- GitGraph/build/release/GitGraph.zip | Bin 6780 -> 6807 bytes GitGraph/main.css | 2 +- GitGraph/package.json | 2 +- packages.json | 2 +- 10 files changed, 9 insertions(+), 6 deletions(-) diff --git a/GitGraph/LibGitGraph.ts b/GitGraph/LibGitGraph.ts index 5688f07..dd85a36 100644 --- a/GitGraph/LibGitGraph.ts +++ b/GitGraph/LibGitGraph.ts @@ -158,6 +158,7 @@ namespace OS { return this.error(API.throwe("Target element is undefined")); } $(this.options.target) + .addClass("git_grapth_container") .css("overflow-y", "auto") .css("overflow-x", "hidden") .css("display", "block") diff --git a/GitGraph/README.md b/GitGraph/README.md index 1e38d6c..177f706 100644 --- a/GitGraph/README.md +++ b/GitGraph/README.md @@ -14,4 +14,5 @@ graph.base_dir = "home://workspace/repo-git"; ``` ## Change logs: +- v0.1.2-b: add class to container element - v0.1.0-b: Initial version \ No newline at end of file diff --git a/GitGraph/build/debug/README.md b/GitGraph/build/debug/README.md index 1e38d6c..177f706 100644 --- a/GitGraph/build/debug/README.md +++ b/GitGraph/build/debug/README.md @@ -14,4 +14,5 @@ graph.base_dir = "home://workspace/repo-git"; ``` ## Change logs: +- v0.1.2-b: add class to container element - v0.1.0-b: Initial version \ No newline at end of file diff --git a/GitGraph/build/debug/libgitgraph.js b/GitGraph/build/debug/libgitgraph.js index c7b83f4..a71896b 100644 --- a/GitGraph/build/debug/libgitgraph.js +++ b/GitGraph/build/debug/libgitgraph.js @@ -1 +1 @@ -var OS;!function(t){let s;!function(s){s.LibGitGraph=class{constructor(t){this._base_dir=void 0,this.lines_data=[],this.commits={},this.oldest_commit_date=void 0,this.svg_element=void 0,this.commits_list_element=void 0,this.load_more_el=void 0,this.commit_detail_el=void 0,this.current_head=void 0,this._on_open_diff=void 0,this.options={commits_per_page:100,x_offset:24,y_offset:24,target:void 0,popup_height:250};for(const s in t)this.options[s]=t[s];this.current_y_offset=this.options.y_offset,this.init_graph()}set base_dir(t){this._base_dir=t,t&&this.render_next()}gen_color(t){let s=t+11;const e=[0,0,0];for(let t=0;t<24;t++)e[t%3]<<=1,e[t%3]|=1&s,s>>=1;return"#"+e.reduce((t,s)=>(s>15?s.toString(16):"0"+s.toString(16))+t,"")}meta(){return t.setting.system.packages.GitGraph}call(t){return new Promise(async(e,i)=>{t.args.base_dir=this._base_dir.path;let o={path:this.meta().path+"/api/api.lua",parameters:t},a=await s.apigateway(o,!1);a.error?i(s.throwe(__("LibGitGrapth server call error: {0}",a.error))):e(a.result)})}load(t){let s={action:"log",args:{n_commits:this.options.commits_per_page.toString(),before:t||null}};return this.call(s)}error(s){t.announcer.oserror(__("GitGraph error: {0}",s.toString()),s)}set on_open_diff(t){this._on_open_diff=t}init_graph(){if(!this.options.target)return this.error(s.throwe("Target element is undefined"));$(this.options.target).css("overflow-y","auto").css("overflow-x","hidden").css("display","block").css("position","relative"),this.svg_element=this.make_svg_el("svg",{width:this.options.x_offset,height:this.options.y_offset}),$(this.svg_element).css("display","block").css("position","absolute").css("left","0").css("top","0"),$(this.options.target).empty(),this.options.target.appendChild(this.svg_element);const t=$("
").css("position","absolute").css("left","0").css("top","0").css("width","100%").css("padding-top",this.options.y_offset/2+"px");this.commits_list_element=t[0],this.options.target.appendChild(this.commits_list_element);const e=$("

").css("height",this.options.y_offset+"px").css("display","block").css("padding","0").css("margin","0").css("line-height",this.options.y_offset+"px").css("vertical-align","middle");e.addClass("git_grapth_load_more"),e.on("click",t=>this.render_next()),e.text(__("More").__()),this.load_more_el=e[0],this.commits_list_element.appendChild(this.load_more_el);const i=$("

").css("position","absolute").css("top","0").css("height",this.options.popup_height+"px").css("display","none").css("user-select","text").addClass("git_grapth_commit_detail");this.commit_detail_el=i[0],this.options.target.appendChild(this.commit_detail_el)}render_next(){null!=this._base_dir&&this.load(this.oldest_commit_date).then(t=>{this.oldest_commit_date&&t.shift(),this.draw_graph(t)}).catch(t=>this.error(t))}make_svg_el(t,s){const e=document.createElementNS("http://www.w3.org/2000/svg",t);for(var i in s)e.setAttribute(i,s[i]);return e}max_line_off_x(){return 0==this.lines_data.length?0:Math.max.apply(Math,this.lines_data.map(t=>t.x_offset))}update_line_data(t,s){const e=t.hashes.parents.split(" "),i=this.lines_data.filter(s=>s.next_commit==t.hashes.commit);let o={src:[],dest:void 0};if(0===i.length){let i={next_commit:e[0],x_offset:this.max_line_off_x()+this.options.x_offset,current_commit:t.hashes.commit,beginning:!0,y_offset:s,color:this.gen_color(this.lines_data.length)};this.lines_data.push(i),o.dest=i}else{let a=Math.min.apply(Math,i.map(t=>t.x_offset)),n=void 0;for(let _ of i)_.x_offset==a?(n=_,n.next_commit=e[0],n.current_commit=t.hashes.commit,n.y_offset=s):(this.lines_data.splice(this.lines_data.indexOf(_),1),o.src.push(_));o.dest=n}if(2===e.length){let i=void 0;i=this.lines_data.filter(t=>t.next_commit==e[1])[0],i?i.y_offset=s+this.options.y_offset:(i={next_commit:e[1],x_offset:this.max_line_off_x()+this.options.x_offset,current_commit:t.hashes.commit,beginning:!0,y_offset:s+this.options.y_offset,color:this.gen_color(this.lines_data.length)},this.lines_data.push(i)),o.src.push(i)}return o}draw_line(t,s,e,i,o,a){let n={stroke:o,fill:"none","stroke-width":1.5};if(a&&(n["stroke-width"]=a),t==e)n.d=`M ${t},${s} L ${e},${i}`;else{let o=t,a=s,_=e,h=i,l=(Math.abs(_-o),Math.abs(h-a));s").css("display","block");return e[0].innerHTML=`${t.__()}: ${s}`,e[0]}open_popup(s){const e=s.domel;if(!e)return;$(this.commit_detail_el).empty();const i=$(e).position(),o=this.svg_element.getBBox(),a=o.x+o.width+this.options.x_offset/2,n=this.make_svg_el("svg",{width:a-s.cx+5,height:this.options.y_offset});$(n).css("display","block").css("position","absolute").css("left","0").css("top","-2px"),n.appendChild(this.draw_line(0,this.options.y_offset/2,a-s.cx,this.options.y_offset/2,s.color)),$(this.commit_detail_el).css("border","2px solid "+s.color).css("color",s.color).append($("
").css("position","absolute").css("height",this.options.y_offset).css("left",s.cx-a).css("padding-left",a-s.cx).append(n).append($("").text("[X]").css("cursor","pointer")).addClass("git_grapth_commit_detail_ctrl").on("click",t=>{$(this.commit_detail_el).css("display","none").empty()}));const _=$("
").css("display","block").css("overflow-y","auto").css("overflow-x","hidden").css("flex","1").css("border-right","1px solid "+s.color).addClass("git_grapth_commit_detail_left"),h=$("
").css("display","block").css("overflow-y","auto").css("overflow-x","hidden").css("flex","1").addClass("git_grapth_commit_detail_right");_.append(this.gen_commit_data_header(__("Commit"),s.hashes.commit)),_.append(this.gen_commit_data_header(__("Parents"),s.hashes.parents)),_.append(this.gen_commit_data_header(__("Author"),`${s.committer.name} <${s.committer.email}>`)),_.append(this.gen_commit_data_header(__("Date"),new Date(s.committer.date).toDateString())),_.append($("
").css("white-space","pre-wrap").text(s.message)),this.commit_detail_el.appendChild(_[0]),this.commit_detail_el.appendChild(h[0]),this.list_file(s.hashes.commit).then(e=>{const i=$("