From 7bac29235a94f905c15aca8104cdb3fd712a8104 Mon Sep 17 00:00:00 2001 From: Damith Date: Thu, 18 Feb 2016 14:57:01 +0530 Subject: [PATCH] Added Mac fix for tooltip --- charts/chart.util.js | 8 +++++++- dist/VizGrammar.js | 10 ++++++++++ dist/VizGrammar.min.js | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/charts/chart.util.js b/charts/chart.util.js index afba3bc..79e51d7 100644 --- a/charts/chart.util.js +++ b/charts/chart.util.js @@ -167,7 +167,6 @@ function bindTooltip(div,markType,eventObj, config, metaData, keyList){ if (item != null && item.status != "exit" && item.mark.marktype == markType) { var canvas = $(".marks")[0]; - if($("#wrapper #tip").length) { $tip.remove(); } @@ -206,6 +205,13 @@ function bindTooltip(div,markType,eventObj, config, metaData, keyList){ var canvasWidth = canvas.width; var canvasHeight = canvas.height; + + var el = $('.marks[style*="width"]'); + + if(el.length > 0){ + canvasWidth = parseFloat($(".marks")[0].style.width); + canvasHeight = parseFloat($(".marks")[0].style.height); + } var dynamicWidth = $tip.width(); var dynamicHeight = $tip.height(); diff --git a/dist/VizGrammar.js b/dist/VizGrammar.js index b33690f..df5b18d 100644 --- a/dist/VizGrammar.js +++ b/dist/VizGrammar.js @@ -1753,6 +1753,9 @@ function bindTooltip(div,markType,eventObj, config, metaData, keyList){ if (item != null && item.status != "exit" && item.mark.marktype == markType) { var canvas = $(".marks")[0]; + if($("#wrapper #tip").length) { + $tip.remove(); + } $(div).wrap( "
" ); @@ -1788,6 +1791,13 @@ function bindTooltip(div,markType,eventObj, config, metaData, keyList){ var canvasWidth = canvas.width; var canvasHeight = canvas.height; + + var el = $('.marks[style*="width"]'); + + if(el.length > 0){ + canvasWidth = parseFloat($(".marks")[0].style.width); + canvasHeight = parseFloat($(".marks")[0].style.height); + } var dynamicWidth = $tip.width(); var dynamicHeight = $tip.height(); diff --git a/dist/VizGrammar.min.js b/dist/VizGrammar.min.js index 0e77f07..b7d10b7 100644 --- a/dist/VizGrammar.min.js +++ b/dist/VizGrammar.min.js @@ -13,4 +13,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -function getPieMark(a,b){var c;if("donut"==a.mode)var c=a.width/5;else var c=0;var d={type:"arc",from:{data:a.title},properties:{update:{x:{field:{group:"width"},mult:.5},y:{field:{group:"height"},mult:.5},startAngle:{field:"layout_start"},endAngle:{field:"layout_end"},innerRadius:{value:c},outerRadius:{value:.4*a.width},fill:{scale:"color",field:b.names[a.color]},fillOpacity:{value:1}},hover:{fillOpacity:{value:.8}}}};return d}function getPieText(a,b){var c={type:"text",from:{data:a.title},properties:{update:{x:{field:{group:"width"},mult:.5},y:{field:{group:"height"},mult:.5},radius:{value:.5*a.width},theta:{field:"layout_mid"},fill:{value:"#000"},align:{value:"center"},baseline:{value:"middle"},text:{field:b.names[a.x],mult:.5}}}};return c}function getAreaMark(a,b){var c={type:"area",from:{data:a.title},properties:{update:{x:{scale:"x",field:b.names[a.x]},y:{scale:"y",field:b.names[a.y]},y2:{scale:"y",value:0},fill:{value:a.markColor},strokeWidth:{value:2},fillOpacity:{value:1}},hover:{fillOpacity:{value:.5}}}};return c}function getBarMark(a,b){var c={type:"rect",from:{data:a.title},properties:{update:{x:{scale:"x",field:b.names[a.x]},width:{scale:"x",band:!0,offset:-1},y:{scale:"y",field:b.names[a.y]},y2:{scale:"y",value:0},fill:{value:"steelblue"},fillOpacity:{value:1}},hover:{fillOpacity:{value:.5}}}};return c}function getStackBarMark(a,b){var c={type:"rect",from:{data:"table",transform:[{type:"stack",groupby:[b.names[a.x]],sortby:[b.names[a.color]],field:b.names[a.y]}]},properties:{update:{x:{scale:"x",field:b.names[a.x]},width:{scale:"x",band:!0,offset:-1},y:{scale:"y",field:"layout_start"},y2:{scale:"y",field:"layout_end"},fill:{scale:"color",field:b.names[a.color]},fillOpacity:{value:1}},hover:{fillOpacity:{value:.5}}}};return c}function getLineMark(a,b){var c;return c=-1!=a.color?{type:"group",from:{data:a.title,transform:[{type:"facet",groupby:[b.names[a.color]]}]},marks:[{type:"line",properties:{update:{x:{scale:"x",field:b.names[a.x]},y:{scale:"y",field:b.names[a.y]},stroke:{scale:"color",field:b.names[a.color]},strokeWidth:{value:2},strokeOpacity:{value:1}},hover:{strokeOpacity:{value:.5}}}}]}:{type:"line",from:{data:a.title},properties:{update:{x:{scale:"x",field:b.names[a.x]},y:{scale:"y",field:b.names[a.y]},stroke:{value:a.markColor},strokeWidth:{value:2},strokeOpacity:{value:1}},hover:{strokeOpacity:{value:.5}}}}}function getTopoJson(a,b){var c,d=a.width,e=a.height,f=a.charts[0].mapType,g="mercator";"usa"==f?(d=a.width-160,e=a.height-130,c=a.height+270,g="albersUsa"):"europe"==f?(d=(a.width/2+100)/2,e=a.height+150,c=a.height+50):(c=a.width/640*120,d=a.width/2+10,e=a.height/2+40);var h=a.geoCodesUrl,i={name:"geoData",url:h,format:{type:"topojson",feature:"units"},transform:[{type:"geopath",value:"data",scale:c,translate:[d,e],projection:g},{type:"lookup",keys:["id"],on:a.title,onKey:b.names[a.x],as:["zipped"],"default":{v:null,country:"No data"}}]};return i}function getMapMark(a,b){var c=[{name:"map",type:"path",from:{data:"geoData"},properties:{enter:{path:{field:"layout_path"}},update:{fill:{rule:[{predicate:{name:"isNotNull",id:{field:"zipped.v"}},scale:"color",field:"zipped.v"},{value:"grey"}]}},hover:{fill:{value:"#989898"}}}},{type:"group",from:{data:a.title,transform:[{type:"filter",test:"datum."+b.names[a.x]+" == tooltipSignal.datum."+b.names[a.x]}]},properties:{update:{x:{signal:"tooltipSignal.x",offset:-5},y:{signal:"tooltipSignal.y",offset:20},width:{value:a.toolTip.width},height:{value:a.toolTip.height},fill:{value:a.toolTip.color}}},marks:[{type:"text",properties:{update:{x:{value:6},y:{value:14},text:{template:"{{tooltipSignal.datum.unitName}} {{tooltipSignal.datum.v}}"},fill:{value:"black"}}}}]}];return c}function getMapSignals(){var a=[{name:"tooltipSignal",init:{expr:"{x: 0, y: 0, datum: {} }"},streams:[{type:"@map:mouseover",expr:"{x: eventX(), y: eventY(), datum: eventItem().datum.zipped}"},{type:"@map:mouseout",expr:"{x: 0, y: 0, datum: {} }"}]}];return a}function getMapPredicates(){var a={name:"isNotNull",type:"!=",operands:[{value:null},{arg:"id"}]};return a}function getMapLegends(a,b){var c={fill:"color",title:b.names[a.y],properties:{gradient:{stroke:{value:"transparent"}},title:{fontSize:{value:14}},legend:{x:{value:0},y:{value:a.height-40}}}};return c}function loadGeoMapCodes(a){var b,c=new XMLHttpRequest;return c.overrideMimeType("application/json"),c.open("GET",a,!1),c.onreadystatechange=function(){4==c.readyState&&"200"==c.status&&(b=JSON.parse(c.responseText))},c.send(null),b}function getMapCode(a,b,c){if("world"==b||"europe"==b)for(d=0;d"),$("#wrapper").append("
"),$tip=$("#tip"),$tip.empty();var i=g.datum,j="";for(var k in i)if(i.hasOwnProperty(k))if(void 0!=f){for(var l=0;l"+f[l]+" ("+k+"):"+i[k]+"

";break}}else e.names[d.x]==k&&(j+="

X ("+k+"):"+i[k]+"

"),e.names[d.y]==k&&(j+="

Y ("+k+"):"+i[k]+"

");$tip.append(j);var n,o=h.width,p=h.height,q=$tip.width(),r=$tip.height(),s=g.bounds.x2+d.padding.left+q,t=p-g.bounds.y2-d.padding.top+r,u=g.bounds.y2+d.padding.top-r;n=s>o?g.bounds.x2+d.padding.left-q:g.bounds.x2+d.padding.left,t>p&&(u=g.bounds.y2+d.padding.top),$tip.css({left:n,top:u}).show()}else $("#wrapper #tip").length&&$tip.remove(),$(a).closest("#wrapper").length&&$(a).unwrap()})}var arc=function(a,b){this.metadata=a[0].metadata;var c=[];this.spec={},b=checkConfig(b,this.metadata),this.config=b,a[0].name=b.title,a[0].transform=[{type:"pie",field:this.metadata.names[b.x]}];var d=[];null==b.colorDomain&&(b.colorDomain={data:b.title,field:this.metadata.names[b.color]});var e={name:"color",type:"ordinal",domain:b.colorDomain,range:b.colorScale};d.push(e),c.push(getPieMark(b,this.metadata)),c.push(getPieText(b,this.metadata));var f="Legend";"table"!=b.title&&(f=b.title);var g=[{fill:"color",title:"Legend",offset:20,properties:{symbols:{fillOpacity:{value:.5},stroke:{value:"transparent"}}}}];this.spec.legends=g,this.spec.width=b.width,this.spec.height=b.height,this.spec.data=a,this.spec.scales=d,this.spec.padding=b.padding,this.spec.marks=c};arc.prototype.draw=function(a,b){var c=function(c){if(this.view=c({el:a}).renderer(this.config.renderer).update(),null!=b)for(var d=0;d=this.config.maxLength){for(var f=[],g=d.length-e,h=g;h=this.config.maxLength){for(var f=[],g=d.length-e,h=g;h=this.config.maxLength){for(var f=[],g=d.length-e,h=g;h-1&&(h=!0,f.splice(j,1)),h||f.splice(f.length-1,1)}else this.view.data(this.config.title).insert([a[i]]),this.view.update()}var k,l=function(a){return a[b]==k};for(i=0;i=this.config.maxLength){for(var f=[],g=d.length-e,h=g;h

"+c+"

";document.getElementById(a).innerHTML=d,this.view=b},number.prototype.insert=function(a){document.getElementById(this.view).innerHTML=a[a.length-1][this.metadata.names[this.config.x]]};var scatter=function(a,b){this.metadata=a[0].metadata;var c=[];this.spec={},b=checkConfig(b,this.metadata),this.config=b,a[0].name=b.title;var d={name:"x",type:this.metadata.types[b.x],range:"width",zero:b.zero,domain:{data:b.title,field:this.metadata.names[b.x]}},e={name:"y",type:this.metadata.types[b.y],range:"height",zero:b.zero,domain:{data:b.title,field:this.metadata.names[b.y]}},f={name:"size",type:"linear",range:[0,576],domain:{data:b.title,field:this.metadata.names[b.size]}},g={name:"color",type:"linear",range:[b.minColor,b.maxColor],domain:{data:b.title,field:this.metadata.names[b.color]}},h=[d,e,f,g],i=[{type:"x",scale:"x",grid:b.grid,title:b.xTitle},{type:"y",scale:"y",grid:b.grid,title:b.yTitle}];c.push(getScatterMark(b,this.metadata)),this.spec.width=b.width,this.spec.height=b.height,this.spec.axes=i,this.spec.data=a,this.spec.scales=h,this.spec.padding=b.padding,this.spec.marks=c};scatter.prototype.draw=function(a,b){var c=function(c){if(this.view=c({el:a}).renderer(this.config.renderer).update(),0!=this.config.tooltip&&bindTooltip(a,"symbol",this.view,this.config,this.metadata,["x","y","size"]),null!=b)for(var d=0;d=this.config.maxLength){for(var f=[],g=d.length-e,h=g;h-1&&(j=!0,g.splice(k,1)),j||g.splice(g.length-1,1)}else this.view.data(this.config.title).insert([a[i]]),this.view.update()}var l,m=function(a){return a[b]==l};for(i=0;ib.maxLength){var k=d3.select("tbody").selectAll("tr").data().slice(d3.select("tbody").selectAll("tr").data().length-b.maxLength,b.maxLength);d3.select("tbody").selectAll("tr").data(k,function(a){return a}).remove()}}; \ No newline at end of file +function getPieMark(a,b){var c;if("donut"==a.mode)var c=a.width/5;else var c=0;var d={type:"arc",from:{data:a.title},properties:{update:{x:{field:{group:"width"},mult:.5},y:{field:{group:"height"},mult:.5},startAngle:{field:"layout_start"},endAngle:{field:"layout_end"},innerRadius:{value:c},outerRadius:{value:.4*a.width},fill:{scale:"color",field:b.names[a.color]},fillOpacity:{value:1}},hover:{fillOpacity:{value:.8}}}};return d}function getPieText(a,b){var c={type:"text",from:{data:a.title},properties:{update:{x:{field:{group:"width"},mult:.5},y:{field:{group:"height"},mult:.5},radius:{value:.5*a.width},theta:{field:"layout_mid"},fill:{value:"#000"},align:{value:"center"},baseline:{value:"middle"},text:{field:b.names[a.x],mult:.5}}}};return c}function getAreaMark(a,b){var c={type:"area",from:{data:a.title},properties:{update:{x:{scale:"x",field:b.names[a.x]},y:{scale:"y",field:b.names[a.y]},y2:{scale:"y",value:0},fill:{value:a.markColor},strokeWidth:{value:2},fillOpacity:{value:1}},hover:{fillOpacity:{value:.5}}}};return c}function getBarMark(a,b){var c={type:"rect",from:{data:a.title},properties:{update:{x:{scale:"x",field:b.names[a.x]},width:{scale:"x",band:!0,offset:-1},y:{scale:"y",field:b.names[a.y]},y2:{scale:"y",value:0},fill:{value:"steelblue"},fillOpacity:{value:1}},hover:{fillOpacity:{value:.5}}}};return c}function getStackBarMark(a,b){var c={type:"rect",from:{data:"table",transform:[{type:"stack",groupby:[b.names[a.x]],sortby:[b.names[a.color]],field:b.names[a.y]}]},properties:{update:{x:{scale:"x",field:b.names[a.x]},width:{scale:"x",band:!0,offset:-1},y:{scale:"y",field:"layout_start"},y2:{scale:"y",field:"layout_end"},fill:{scale:"color",field:b.names[a.color]},fillOpacity:{value:1}},hover:{fillOpacity:{value:.5}}}};return c}function getLineMark(a,b){var c;return c=-1!=a.color?{type:"group",from:{data:a.title,transform:[{type:"facet",groupby:[b.names[a.color]]}]},marks:[{type:"line",properties:{update:{x:{scale:"x",field:b.names[a.x]},y:{scale:"y",field:b.names[a.y]},stroke:{scale:"color",field:b.names[a.color]},strokeWidth:{value:2},strokeOpacity:{value:1}},hover:{strokeOpacity:{value:.5}}}}]}:{type:"line",from:{data:a.title},properties:{update:{x:{scale:"x",field:b.names[a.x]},y:{scale:"y",field:b.names[a.y]},stroke:{value:a.markColor},strokeWidth:{value:2},strokeOpacity:{value:1}},hover:{strokeOpacity:{value:.5}}}}}function getTopoJson(a,b){var c,d=a.width,e=a.height,f=a.charts[0].mapType,g="mercator";"usa"==f?(d=a.width-160,e=a.height-130,c=a.height+270,g="albersUsa"):"europe"==f?(d=(a.width/2+100)/2,e=a.height+150,c=a.height+50):(c=a.width/640*120,d=a.width/2+10,e=a.height/2+40);var h=a.geoCodesUrl,i={name:"geoData",url:h,format:{type:"topojson",feature:"units"},transform:[{type:"geopath",value:"data",scale:c,translate:[d,e],projection:g},{type:"lookup",keys:["id"],on:a.title,onKey:b.names[a.x],as:["zipped"],"default":{v:null,country:"No data"}}]};return i}function getMapMark(a,b){var c=[{name:"map",type:"path",from:{data:"geoData"},properties:{enter:{path:{field:"layout_path"}},update:{fill:{rule:[{predicate:{name:"isNotNull",id:{field:"zipped.v"}},scale:"color",field:"zipped.v"},{value:"grey"}]}},hover:{fill:{value:"#989898"}}}},{type:"group",from:{data:a.title,transform:[{type:"filter",test:"datum."+b.names[a.x]+" == tooltipSignal.datum."+b.names[a.x]}]},properties:{update:{x:{signal:"tooltipSignal.x",offset:-5},y:{signal:"tooltipSignal.y",offset:20},width:{value:a.toolTip.width},height:{value:a.toolTip.height},fill:{value:a.toolTip.color}}},marks:[{type:"text",properties:{update:{x:{value:6},y:{value:14},text:{template:"{{tooltipSignal.datum.unitName}} {{tooltipSignal.datum.v}}"},fill:{value:"black"}}}}]}];return c}function getMapSignals(){var a=[{name:"tooltipSignal",init:{expr:"{x: 0, y: 0, datum: {} }"},streams:[{type:"@map:mouseover",expr:"{x: eventX(), y: eventY(), datum: eventItem().datum.zipped}"},{type:"@map:mouseout",expr:"{x: 0, y: 0, datum: {} }"}]}];return a}function getMapPredicates(){var a={name:"isNotNull",type:"!=",operands:[{value:null},{arg:"id"}]};return a}function getMapLegends(a,b){var c={fill:"color",title:b.names[a.y],properties:{gradient:{stroke:{value:"transparent"}},title:{fontSize:{value:14}},legend:{x:{value:0},y:{value:a.height-40}}}};return c}function loadGeoMapCodes(a){var b,c=new XMLHttpRequest;return c.overrideMimeType("application/json"),c.open("GET",a,!1),c.onreadystatechange=function(){4==c.readyState&&"200"==c.status&&(b=JSON.parse(c.responseText))},c.send(null),b}function getMapCode(a,b,c){if("world"==b||"europe"==b)for(d=0;d"),$("#wrapper").append("
"),$tip=$("#tip"),$tip.empty();var i=g.datum,j="";for(var k in i)if(i.hasOwnProperty(k))if(void 0!=f){for(var l=0;l"+f[l]+" ("+k+"):"+i[k]+"

";break}}else e.names[d.x]==k&&(j+="

X ("+k+"):"+i[k]+"

"),e.names[d.y]==k&&(j+="

Y ("+k+"):"+i[k]+"

");$tip.append(j);var n=h.width,o=h.height,p=$('.marks[style*="width"]');p.length>0&&(n=parseFloat($(".marks")[0].style.width),o=parseFloat($(".marks")[0].style.height));var q,r=$tip.width(),s=$tip.height(),t=g.bounds.x2+d.padding.left+r,u=o-g.bounds.y2-d.padding.top+s,v=g.bounds.y2+d.padding.top-s;q=t>n?g.bounds.x2+d.padding.left-r:g.bounds.x2+d.padding.left,u>o&&(v=g.bounds.y2+d.padding.top),$tip.css({left:q,top:v}).show()}else $("#wrapper #tip").length&&$tip.remove(),$(a).closest("#wrapper").length&&$(a).unwrap()})}var arc=function(a,b){this.metadata=a[0].metadata;var c=[];this.spec={},b=checkConfig(b,this.metadata),this.config=b,a[0].name=b.title,a[0].transform=[{type:"pie",field:this.metadata.names[b.x]}];var d=[];null==b.colorDomain&&(b.colorDomain={data:b.title,field:this.metadata.names[b.color]});var e={name:"color",type:"ordinal",domain:b.colorDomain,range:b.colorScale};d.push(e),c.push(getPieMark(b,this.metadata)),c.push(getPieText(b,this.metadata));var f="Legend";"table"!=b.title&&(f=b.title);var g=[{fill:"color",title:"Legend",offset:20,properties:{symbols:{fillOpacity:{value:.5},stroke:{value:"transparent"}}}}];this.spec.legends=g,this.spec.width=b.width,this.spec.height=b.height,this.spec.data=a,this.spec.scales=d,this.spec.padding=b.padding,this.spec.marks=c};arc.prototype.draw=function(a,b){var c=function(c){if(this.view=c({el:a}).renderer(this.config.renderer).update(),null!=b)for(var d=0;d=this.config.maxLength){for(var f=[],g=d.length-e,h=g;h=this.config.maxLength){for(var f=[],g=d.length-e,h=g;h=this.config.maxLength){for(var f=[],g=d.length-e,h=g;h-1&&(h=!0,f.splice(j,1)),h||f.splice(f.length-1,1)}else this.view.data(this.config.title).insert([a[i]]),this.view.update()}var k,l=function(a){return a[b]==k};for(i=0;i=this.config.maxLength){for(var f=[],g=d.length-e,h=g;h

"+c+"

";document.getElementById(a).innerHTML=d,this.view=b},number.prototype.insert=function(a){document.getElementById(this.view).innerHTML=a[a.length-1][this.metadata.names[this.config.x]]};var scatter=function(a,b){this.metadata=a[0].metadata;var c=[];this.spec={},b=checkConfig(b,this.metadata),this.config=b,a[0].name=b.title;var d={name:"x",type:this.metadata.types[b.x],range:"width",zero:b.zero,domain:{data:b.title,field:this.metadata.names[b.x]}},e={name:"y",type:this.metadata.types[b.y],range:"height",zero:b.zero,domain:{data:b.title,field:this.metadata.names[b.y]}},f={name:"size",type:"linear",range:[0,576],domain:{data:b.title,field:this.metadata.names[b.size]}},g={name:"color",type:"linear",range:[b.minColor,b.maxColor],domain:{data:b.title,field:this.metadata.names[b.color]}},h=[d,e,f,g],i=[{type:"x",scale:"x",grid:b.grid,title:b.xTitle},{type:"y",scale:"y",grid:b.grid,title:b.yTitle}];c.push(getScatterMark(b,this.metadata)),this.spec.width=b.width,this.spec.height=b.height,this.spec.axes=i,this.spec.data=a,this.spec.scales=h,this.spec.padding=b.padding,this.spec.marks=c};scatter.prototype.draw=function(a,b){var c=function(c){if(this.view=c({el:a}).renderer(this.config.renderer).update(),0!=this.config.tooltip&&bindTooltip(a,"symbol",this.view,this.config,this.metadata,["x","y","size"]),null!=b)for(var d=0;d=this.config.maxLength){for(var f=[],g=d.length-e,h=g;h-1&&(j=!0,g.splice(k,1)),j||g.splice(g.length-1,1)}else this.view.data(this.config.title).insert([a[i]]),this.view.update()}var l,m=function(a){return a[b]==l};for(i=0;ib.maxLength){var k=d3.select("tbody").selectAll("tr").data().slice(d3.select("tbody").selectAll("tr").data().length-b.maxLength,b.maxLength);d3.select("tbody").selectAll("tr").data(k,function(a){return a}).remove()}}; \ No newline at end of file