Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vizabi-barrankchart

Package Overview
Dependencies
Maintainers
3
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vizabi-barrankchart - npm Package Compare versions

Comparing version 1.0.8-4 to 1.0.8-5

2

build/dist/barrankchart.js

@@ -1,2 +0,2 @@

!function(t){function e(a){if(i[a])return i[a].exports;var r=i[a]={i:a,l:!1,exports:{}};return t[a].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var i={};e.m=t,e.c=i,e.i=function(t){return t},e.d=function(t,i,a){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:a})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=4)}([function(t,e,i){"use strict";function a(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),i(2);var r=i(1),n=a(r);e.default=Vizabi.Tool.extend("BarRankChart",{init:function(t,e){this.name="barrankchart",this.components=[{component:n.default,placeholder:".vzb-tool-viz",model:["state.time","state.entities","state.marker","locale","ui"]},{component:Vizabi.Component.get("timeslider"),placeholder:".vzb-tool-timeslider",model:["state.time","state.entities","state.marker","ui"]},{component:Vizabi.Component.get("dialogs"),placeholder:".vzb-tool-dialogs",model:["state","ui","locale"]},{component:Vizabi.Component.get("buttonlist"),placeholder:".vzb-tool-buttonlist",model:["state","ui","locale"]},{component:Vizabi.Component.get("treemenu"),placeholder:".vzb-tool-treemenu",model:["state.marker","state.marker_tags","state.time","locale"]},{component:Vizabi.Component.get("datanotes"),placeholder:".vzb-tool-datanotes",model:["state.marker","locale"]},{component:Vizabi.Component.get("datawarning"),placeholder:".vzb-tool-datawarning",model:["locale"]},{component:Vizabi.Component.get("steppedspeedslider"),placeholder:".vzb-tool-stepped-speed-slider",model:["state.time","locale"]}],this._super(t,e)},default_model:{state:{entities:{dim:"id"},time:{},marker:{axis_x:{allow:{scales:["linear","log"]}},axis_y:{allow:{scales:["ordinal","nominal"]}},color:{}}},locale:{},ui:{chart:{},datawarning:{doubtDomain:[],doubtRange:[]},buttons:["colors","find","show","moreoptions","fullscreen","presentation"],dialogs:{popup:["timedisplay","colors","find","axes","show","moreoptions"],sidebar:["timedisplay","colors","find"],moreoptions:["opacity","speed","colors","presentation","about"]},presentation:!1}}})},function(t,e,i){"use strict";function a(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){var i=[],a=!0,r=!1,n=void 0;try{for(var o,l=t[Symbol.iterator]();!(a=(o=l.next()).done)&&(i.push(o.value),!e||i.length!==e);a=!0);}catch(t){r=!0,n=t}finally{try{!a&&l.return&&l.return()}finally{if(r)throw n}}return i}return function(e,i){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n=Vizabi.utils,o=Vizabi.helpers["d3.axisWithLabelPicker"],l=Vizabi.iconset.question,s=Vizabi.iconset.warn,h="#333",d="#fdfdfd",c=Vizabi.Component.extend({init:function(t,e){var a=this;this.name="barrankchart-component",this.template=i(3),this.model_expects=[{name:"time",type:"time"},{name:"entities",type:"entities"},{name:"marker",type:"model"},{name:"locale",type:"locale"},{name:"ui",type:"ui"}],this.model_binds={"change:time.value":function(){a.model._ready&&a._readyOnce&&a.onTimeChange()},"change:marker.select":function(){a._readyOnce&&(a._selectBars(),a._updateOpacity(),a._updateDoubtOpacity(),a._scroll())},"change:marker.axis_x.scaleType":function(){a._readyOnce&&(a.loadData(),a.draw(!0))},"change:marker.color.palette":function(){a._drawColors()},"change:marker.highlight":function(){a._updateOpacity()},"change:marker.opacitySelectDim":function(){a._updateOpacity()},"change:marker.opacityRegular":function(){a._updateOpacity()}},this._super(t,e),this.xScale=null,this.cScale=d3.scaleOrdinal(d3.schemeCategory10),this.xAxis=o("bottom")},onTimeChange:function(){var t=this;this.model.marker.getFrame(this.model.time.value,function(e){t.values=e,t.values&&(t.loadData(),t.draw())})},readyOnce:function(){this.element=d3.select(this.element),this.header=this.element.select(".vzb-br-header"),this.infoEl=this.element.select(".vzb-br-axis-info"),this.barViewport=this.element.select(".vzb-br-barsviewport"),this.barSvg=this.element.select(".vzb-br-bars-svg"),this.barContainer=this.element.select(".vzb-br-bars"),this.dataWarningEl=this.element.select(".vzb-data-warning"),this.wScale=d3.scale.linear().domain(this.model.ui.datawarning.doubtDomain).range(this.model.ui.datawarning.doubtRange),this.xAxis.tickFormat(this.model.marker.axis_x.getTickFormatter()),this._localeId=this.model.locale.id,this._entityLabels={},this._presentation=!this.model.ui.presentation,this._formatter=this.model.marker.axis_x.getTickFormatter(),this.ready(),this._selectBars()},ready:function(){var t=this;this.model.marker.getFrame(this.model.time.value,function(e){t.values=e,t.values&&(t.loadData(),t.draw(!0),t._updateOpacity(),t._drawColors())})},resize:function(){this.draw(!0)},loadData:function(){var t=this,e=this;this.translator=this.model.locale.getTFunction(),this.sortedEntities=this._sortByIndicator(this.values.axis_x),this.header.select(".vzb-br-title").select("text").on("click",function(){return t.parent.findChildByName("gapminder-treemenu").markerID("axis_x").alignX("left").alignY("top").updateView().toggle()}),this.xScale=this.model.marker.axis_x.getScale(),this.cScale=this.model.marker.color.getScale(),n.setIcon(this.dataWarningEl,s).select("svg").attr("width",0).attr("height",0),this.dataWarningEl.append("text").text(this.translator("hints/dataWarning")),this.dataWarningEl.on("click",function(){return t.parent.findChildByName("gapminder-datawarning").toggle()}).on("mouseover",function(){return t._updateDoubtOpacity(1)}).on("mouseout",function(){return t._updateDoubtOpacity()}),n.setIcon(this.infoEl,l).select("svg").attr("width",0).attr("height",0),this.infoEl.on("click",function(){t.parent.findChildByName("gapminder-datanotes").pin()}),this.infoEl.on("mouseover",function(){var t=this.getBBox(),i=n.makeAbsoluteContext(this,this.farthestViewportElement),a=i(t.x-10,t.y+t.height+10);e.parent.findChildByName("gapminder-datanotes").setHook("axis_y").show().setPos(a.x,a.y)}),this.infoEl.on("mouseout",function(){e.parent.findChildByName("gapminder-datanotes").hide()})},draw:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.time_1=null==this.time?this.model.time.value:this.time,this.time=this.model.time.value;var e=this.model.time.playing&&this.time-this.time_1>0?this.model.time.delayAnimations:0;this.drawAxes(e,t)||this.drawData(e,t)},drawAxes:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e={small:{margin:{top:60,right:5,left:5,bottom:20},headerMargin:{top:10,right:20,bottom:20,left:20},infoElHeight:16,infoElMargin:5,barHeight:18,barMargin:3,barRectMargin:5,barValueMargin:5,scrollMargin:20},medium:{margin:{top:60,right:5,left:5,bottom:20},headerMargin:{top:10,right:20,bottom:20,left:20},infoElHeight:16,infoElMargin:5,barHeight:21,barMargin:3,barRectMargin:5,barValueMargin:5,scrollMargin:25},large:{margin:{top:60,right:5,left:5,bottom:20},headerMargin:{top:10,right:20,bottom:20,left:20},infoElHeight:16,infoElMargin:5,barHeight:28,barMargin:4,barRectMargin:5,barValueMargin:5,scrollMargin:25}},i={medium:{margin:{top:60,right:10,left:10,bottom:40},headerMargin:{top:10,right:20,bottom:20,left:20},infoElHeight:25,infoElMargin:10,barHeight:25,barMargin:6},large:{margin:{top:60,right:10,left:10,bottom:40},headerMargin:{top:10,right:20,bottom:20,left:20},infoElHeight:16,infoElMargin:10,barHeight:30,barMargin:6}};this.activeProfile=this.getActiveProfile(e,i);var a=this.activeProfile,r=a.margin,o=a.headerMargin,l=a.infoElHeight,s=a.infoElMargin;if(this.height=parseInt(this.element.style("height"),10)||0,this.width=parseInt(this.element.style("width"),10)||0,!this.height||!this.width)return n.warn("Dialog resize() abort: vizabi container is too little or has display:none");this.barViewport.style("height",this.height-r.bottom-r.top+"px"),this.header.attr("height",r.top);var h=this.header.select(".vzb-br-title"),d=this.model.marker.axis_x.getConceptprops(),c=d.name,g=d.unit,m=h.select("text");if(g){m.text(c+", "+g);o.left+h.node().getBBox().width+s+l>this.width-o.right&&m.text(c)}var b=h.node().getBBox(),u=o.left,f=o.top+b.height;h.attr("transform","translate("+u+", "+f+")");var p=this.infoEl;p.select("svg").attr("width",l+"px").attr("height",l+"px");var v=u+h.node().getBBox().width+s,x=o.top+l/4;p.attr("transform","translate("+v+", "+x+")");var y=this.header.select(".vzb-br-total");t?y.select("text").transition("text").delay(t).text(this.model.time.formatDate(this.time)):y.select("text").interrupt().text(this.model.time.formatDate(this.time)),y.style("opacity",Number("large"!==this.getLayoutProfile()));var _=y.node().getBBox(),w=this.width-o.right-_.width,z=o.top+_.height;y.attr("transform","translate("+w+", "+z+")").classed("vzb-transparent",b.width+_.width+10>this.width),this.element.select(".vzb-data-warning-svg").style("height",r.bottom+"px");var k=this.dataWarningEl.select("text").node().getBBox();this.dataWarningEl.attr("transform","translate("+(this.width-r.right-k.width)+", "+k.height+")").select("text"),this.dataWarningEl.select("svg").attr("width",k.height).attr("height",k.height).attr("x",-k.height-5).attr("y",1-k.height),this._updateDoubtOpacity()},drawData:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this._createAndDeleteBars(this.barContainer.selectAll(".vzb-br-bar").data(this.sortedEntities,function(t){return t.entity}));var a=this.model.ui.presentation,r=this._presentation!==a;r&&(this._presentation=a);var n=void 0===this._entitiesCount||this._entitiesCount!==this.sortedEntities.length;(r||n)&&n&&(this._entitiesCount=this.sortedEntities.length),this._resizeSvg(),this._scroll(e);var o=this.activeProfile,l=o.barRectMargin,s=o.barValueMargin,h=o.scrollMargin,d=o.margin,c=this.model.marker.axis_x,g=c.getLimits(c.which),m=Math.abs(g.max)>=Math.abs(g.min),b=this.width-d.right-d.left-this._getWidestLabelWidth()-l-h;this.xScale.range([0,b]);var u=this.model.marker.axis_x.scaleType,f=("log"===u?0:this.xScale(0))||0,p=this._getWidestLabelWidth();f>(m?d.left:d.right)+this._getWidestLabelWidth()&&(p=f),f<0&&(this.xScale.range([0,b-Math.abs(f)]),f=("log"===u?0:this.xScale(0))||0);var v=function(e){return t.xScale(e)-f},x=m?"end":"start",y=m?"start":"end",_=m?d.left+p:this.width-p-h-d.right,w=m?_+l:_-l,z=m?w+s:w-s,k=this._getWidestLabelWidth(!0)+(m?d.left:d.right)<p;this.sortedEntities.forEach(function(a){var n=a.value;if((i||r||a.isNew)&&(a.barLabel.attr("x",_).attr("y",t.activeProfile.barHeight/2).attr("text-anchor",x).text(k?a.labelFull:a.labelSmall),a.barRect.attr("rx",t.activeProfile.barHeight/4).attr("ry",t.activeProfile.barHeight/4).attr("height",t.activeProfile.barHeight),a.barValue.attr("x",z).attr("y",t.activeProfile.barHeight/2).attr("text-anchor",y)),i||a.changedWidth||r){var o=Math.max(0,n&&v(Math.abs(n)));(i||a.changedWidth||r)&&a.barRect.transition().duration(e).ease(d3.easeLinear).attr("width",o),a.barRect.attr("x",w-(n<0?o:0)),(i||a.changedValue)&&a.barValue.text(t._formatter(n)||t.translator("hints/nodata"))}(i||a.changedIndex||r)&&a.self.transition().duration(e).ease(d3.easeLinear).attr("transform","translate(0, "+t._getBarPosition(a.index)+")")})},_resizeSvg:function(){var t=this.activeProfile,e=t.barHeight,i=t.barMargin;this.barSvg.attr("height",(e+i)*this.sortedEntities.length+"px")},_scroll:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=this.barContainer.select(".vzb-selected");if(!e.empty()){var i=e.datum(),a=this._getBarPosition(i.index),r=this.activeProfile.margin,n=this.height-r.top-r.bottom,o=a-(n+this.activeProfile.barHeight)/2;this.barViewport.transition().duration(t).tween("scrollfor"+i.entity,this._scrollTopTween(o))}},_createAndDeleteBars:function(t){var e=this,i=r(this.sortedEntities,1),a=i[0];this._entityLabels[a.entity]||(this._entityLabels[a.entity]=a.label);var n=this._entityLabels[a.entity]!==this.values.label[a.entity]&&this.model.locale.id!==this._localeId;n&&(this._localeId=this.model.locale.id,this._entityLabels[a.entity]=this.values.label[a.entity]),t.exit().remove(),t=(n?t:t.enter().append("g")).each(function(t){var i=d3.select(this),a=e.values.label[t.entity],r=a.length<12?a:a.substring(0,9)+"...";t.barLabel&&t.barLabel.remove();var o=i.append("text").attr("class","vzb-br-label").attr("dy",".325em"),l=o.text(a).node().getBBox().width,s=o.text(r).node().getBBox().width;if(Object.assign(t,{labelFullWidth:l,labelSmallWidth:s,labelFull:a,labelSmall:r,barLabel:o}),!n){i.attr("class","vzb-br-bar").classed("vzb-selected",e.model.marker.isSelected(t)).attr("id","vzb-br-bar-"+t.entity+"-"+e._id).on("mousemove",function(t){return e.model.marker.highlightMarker(t)}).on("mouseout",function(){return e.model.marker.clearHighlighted()}).on("click",function(t){e.model.marker.selectMarker(t)});var h=i.append("rect").attr("stroke","transparent"),d=i.append("text").attr("class","vzb-br-value").attr("dy",".325em");Object.assign(t,{self:i,isNew:!0,barRect:h,barValue:d})}}).merge(t)},_getWidestLabelWidth:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=t?"labelFullWidth":"labelSmallWidth",i=t?"labelFull":"labelSmall",a=this.sortedEntities.reduce(function(t,i){return t[e]<i[e]?i:t}),r=a.barLabel.text(),n=a.barLabel.text(a[i]).node().getBBox().width;return a.barLabel.text(r),n},_drawColors:function(){var t=this,e=this;this.barContainer.selectAll(".vzb-br-bar>rect").each(function(t){var i=t.entity,a=d3.select(this),r=e.values.color[i];r||0===r?a.style("fill",e._getColor(r)).attr("stroke","transparent"):a.style("fill",d).attr("stroke",h)}),this.barContainer.selectAll(".vzb-br-bar>text").style("fill",function(e){var i=e.entity;return t._getDarkerColor(t.values.color[i])})},_getColor:function(t){return d3.rgb(this.cScale(t))},_getDarkerColor:function(t){return this._getColor(t).darker(2)},_scrollTopTween:function(t){return function(){var e=this,i=d3.interpolateNumber(this.scrollTop,t);return function(t){e.scrollTop=i(t)}}},_getBarPosition:function(t){return(this.activeProfile.barHeight+this.activeProfile.barMargin)*t},_entities:{},_sortByIndicator:function(t){var e=this;return Object.keys(t).map(function(i){var r,n=e._entities[i],o=t[i],l=e.values.label[i],s=e._formatter(o);return n?Object.assign(n,{value:o,label:l,formattedValue:s,changedValue:s!==n.formattedValue,changedWidth:o!==n.value,isNew:!1}):e._entities[i]=(r={entity:i,value:o,formattedValue:s},a(r,e.model.entities.dim,i),a(r,"changedValue",!0),a(r,"changedWidth",!0),a(r,"isNew",!0),r)}).sort(function(t,e){var i=t.value;return e.value-i}).map(function(t,e){return Object.assign(t,{index:e,changedIndex:e!==t.index})})},_selectBars:function(){var t=this,e=this.model.entities.dim,i=this.model.marker.select;this.barContainer.classed("vzb-dimmed-selected",!1),this.barContainer.selectAll(".vzb-br-bar.vzb-selected").classed("vzb-selected",!1),i.length&&(this.barContainer.classed("vzb-dimmed-selected",!0),i.forEach(function(i){t.barContainer.select("#vzb-br-bar-"+i[e]+"-"+t._id).classed("vzb-selected",!0)}))},_updateOpacity:function(){var t=this.model.marker,e=t.highlight,i=t.select,a=t.opacityHighlightDim,r=t.opacitySelectDim,n=t.opacityRegular,o=e.length>0,l=i.length>0;this.barContainer.selectAll(".vzb-br-bar").style("opacity",function(e){return o&&t.isHighlighted(e)?1:l?t.isSelected(e)?n:r:o?a:n})},_updateDoubtOpacity:function(t){this.dataWarningEl.style("opacity",t||(this.model.marker.select.length?1:this.wScale(+this.model.time.value.getUTCFullYear().toString())))}});e.default=c},function(t,e){},function(t,e){t.exports='<!-- Bar Chart Component -->\n<div class="vzb-barrankchart">\n <svg class="vzb-br-header">\n <g class="vzb-br-title">\n <text></text>\n </g>\n <g class="vzb-br-total">\n <text></text>\n </g>\n <g class="vzb-br-axis-info vzb-noexport"></g>\n </svg>\n\n <div class="vzb-br-barsviewport vzb-dialog-scrollable">\n <svg class="vzb-br-bars-svg">\n <g class="vzb-br-bars"></g>\n </svg>\n </div>\n\n <svg class="vzb-data-warning-svg">\n <g class="vzb-data-warning vzb-noexport">\n <svg></svg>\n <text></text>\n </g>\n </svg>\n</div>\n'},function(t,e,i){t.exports=i(0)}]);
!function(t){function e(a){if(i[a])return i[a].exports;var r=i[a]={i:a,l:!1,exports:{}};return t[a].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var i={};e.m=t,e.c=i,e.i=function(t){return t},e.d=function(t,i,a){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:a})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=4)}([function(t,e,i){"use strict";function a(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),i(2);var r=i(1),n=a(r);e.default=Vizabi.Tool.extend("BarRankChart",{init:function(t,e){this.name="barrankchart",this.components=[{component:n.default,placeholder:".vzb-tool-viz",model:["state.time","state.entities","state.marker","locale","ui"]},{component:Vizabi.Component.get("timeslider"),placeholder:".vzb-tool-timeslider",model:["state.time","state.entities","state.marker","ui"]},{component:Vizabi.Component.get("dialogs"),placeholder:".vzb-tool-dialogs",model:["state","ui","locale"]},{component:Vizabi.Component.get("buttonlist"),placeholder:".vzb-tool-buttonlist",model:["state","ui","locale"]},{component:Vizabi.Component.get("treemenu"),placeholder:".vzb-tool-treemenu",model:["state.marker","state.marker_tags","state.time","locale"]},{component:Vizabi.Component.get("datanotes"),placeholder:".vzb-tool-datanotes",model:["state.marker","locale"]},{component:Vizabi.Component.get("datawarning"),placeholder:".vzb-tool-datawarning",model:["locale"]},{component:Vizabi.Component.get("steppedspeedslider"),placeholder:".vzb-tool-stepped-speed-slider",model:["state.time","locale"]}],this._super(t,e)},default_model:{state:{entities:{dim:"id"},time:{},marker:{axis_x:{allow:{scales:["linear","log"]}},axis_y:{allow:{scales:["ordinal","nominal"]}},color:{}}},locale:{},ui:{chart:{},datawarning:{doubtDomain:[],doubtRange:[]},buttons:["colors","find","show","moreoptions","fullscreen","presentation"],dialogs:{popup:["timedisplay","colors","find","axes","show","moreoptions"],sidebar:["timedisplay","colors","find"],moreoptions:["opacity","speed","colors","presentation","about"]},presentation:!1}}})},function(t,e,i){"use strict";function a(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t,e){var i=[],a=!0,r=!1,n=void 0;try{for(var o,l=t[Symbol.iterator]();!(a=(o=l.next()).done)&&(i.push(o.value),!e||i.length!==e);a=!0);}catch(t){r=!0,n=t}finally{try{!a&&l.return&&l.return()}finally{if(r)throw n}}return i}return function(e,i){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n=Vizabi.utils,o=Vizabi.helpers["d3.axisWithLabelPicker"],l=Vizabi.iconset.question,s=Vizabi.iconset.warn,h="#333",d="#fdfdfd",c=Vizabi.Component.extend({init:function(t,e){var a=this;this.name="barrankchart-component",this.template=i(3),this.model_expects=[{name:"time",type:"time"},{name:"entities",type:"entities"},{name:"marker",type:"model"},{name:"locale",type:"locale"},{name:"ui",type:"ui"}],this.model_binds={"change:time.value":function(){a.model._ready&&a._readyOnce&&a.onTimeChange()},"change:marker.select":function(){a._readyOnce&&(a._selectBars(),a._updateOpacity(),a._updateDoubtOpacity(),a._scroll())},"change:marker.axis_x.scaleType":function(){a._readyOnce&&a.loadData()&&a.draw(!0)},"change:marker.color.palette":function(){a._drawColors()},"change:marker.highlight":function(){a._updateOpacity()},"change:marker.opacitySelectDim":function(){a._updateOpacity()},"change:marker.opacityRegular":function(){a._updateOpacity()}},this._super(t,e),this.xScale=null,this.cScale=d3.scaleOrdinal(d3.schemeCategory10),this.xAxis=o("bottom")},onTimeChange:function(){var t=this;this.model.marker.getFrame(this.model.time.value,function(e){t.values=e,t.values&&t.loadData()&&t.draw()})},readyOnce:function(){this.element=d3.select(this.element),this.header=this.element.select(".vzb-br-header"),this.infoEl=this.element.select(".vzb-br-axis-info"),this.barViewport=this.element.select(".vzb-br-barsviewport"),this.barSvg=this.element.select(".vzb-br-bars-svg"),this.barContainer=this.element.select(".vzb-br-bars"),this.dataWarningEl=this.element.select(".vzb-data-warning"),this.wScale=d3.scale.linear().domain(this.model.ui.datawarning.doubtDomain).range(this.model.ui.datawarning.doubtRange),this.xAxis.tickFormat(this.model.marker.axis_x.getTickFormatter()),this._localeId=this.model.locale.id,this._entityLabels={},this._presentation=!this.model.ui.presentation,this._formatter=this.model.marker.axis_x.getTickFormatter(),this.ready(),this._selectBars()},ready:function(){var t=this;this.model.marker.getFrame(this.model.time.value,function(e){t.values=e,t.values&&t.loadData()&&(t.draw(!0),t._updateOpacity(),t._drawColors())})},resize:function(){this.draw(!0)},loadData:function(){var t=this,e=this;this.translator=this.model.locale.getTFunction();var i=this.values.axis_x;return!!Object.keys(i).length&&(this.sortedEntities=this._sortByIndicator(i),this.header.select(".vzb-br-title").select("text").on("click",function(){return t.parent.findChildByName("gapminder-treemenu").markerID("axis_x").alignX("left").alignY("top").updateView().toggle()}),this.xScale=this.model.marker.axis_x.getScale(),this.cScale=this.model.marker.color.getScale(),n.setIcon(this.dataWarningEl,s).select("svg").attr("width",0).attr("height",0),this.dataWarningEl.append("text").text(this.translator("hints/dataWarning")),this.dataWarningEl.on("click",function(){return t.parent.findChildByName("gapminder-datawarning").toggle()}).on("mouseover",function(){return t._updateDoubtOpacity(1)}).on("mouseout",function(){return t._updateDoubtOpacity()}),n.setIcon(this.infoEl,l).select("svg").attr("width",0).attr("height",0),this.infoEl.on("click",function(){t.parent.findChildByName("gapminder-datanotes").pin()}),this.infoEl.on("mouseover",function(){var t=this.getBBox(),i=n.makeAbsoluteContext(this,this.farthestViewportElement),a=i(t.x-10,t.y+t.height+10);e.parent.findChildByName("gapminder-datanotes").setHook("axis_y").show().setPos(a.x,a.y)}),this.infoEl.on("mouseout",function(){e.parent.findChildByName("gapminder-datanotes").hide()}),!0)},draw:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.time_1=null==this.time?this.model.time.value:this.time,this.time=this.model.time.value;var e=this.model.time.playing&&this.time-this.time_1>0?this.model.time.delayAnimations:0;this.drawAxes(e,t)||this.drawData(e,t)},drawAxes:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e={small:{margin:{top:60,right:5,left:5,bottom:20},headerMargin:{top:10,right:20,bottom:20,left:20},infoElHeight:16,infoElMargin:5,barHeight:18,barMargin:3,barRectMargin:5,barValueMargin:5,scrollMargin:20},medium:{margin:{top:60,right:5,left:5,bottom:20},headerMargin:{top:10,right:20,bottom:20,left:20},infoElHeight:16,infoElMargin:5,barHeight:21,barMargin:3,barRectMargin:5,barValueMargin:5,scrollMargin:25},large:{margin:{top:60,right:5,left:5,bottom:20},headerMargin:{top:10,right:20,bottom:20,left:20},infoElHeight:16,infoElMargin:5,barHeight:28,barMargin:4,barRectMargin:5,barValueMargin:5,scrollMargin:25}},i={medium:{margin:{top:60,right:10,left:10,bottom:40},headerMargin:{top:10,right:20,bottom:20,left:20},infoElHeight:25,infoElMargin:10,barHeight:25,barMargin:6},large:{margin:{top:60,right:10,left:10,bottom:40},headerMargin:{top:10,right:20,bottom:20,left:20},infoElHeight:16,infoElMargin:10,barHeight:30,barMargin:6}};this.activeProfile=this.getActiveProfile(e,i);var a=this.activeProfile,r=a.margin,o=a.headerMargin,l=a.infoElHeight,s=a.infoElMargin;if(this.height=parseInt(this.element.style("height"),10)||0,this.width=parseInt(this.element.style("width"),10)||0,!this.height||!this.width)return n.warn("Dialog resize() abort: vizabi container is too little or has display:none");this.barViewport.style("height",this.height-r.bottom-r.top+"px"),this.header.attr("height",r.top);var h=this.header.select(".vzb-br-title"),d=this.model.marker.axis_x.getConceptprops(),c=d.name,g=d.unit,m=h.select("text");if(g){m.text(c+", "+g);o.left+h.node().getBBox().width+s+l>this.width-o.right&&m.text(c)}var b=h.node().getBBox(),u=o.left,f=o.top+b.height;h.attr("transform","translate("+u+", "+f+")");var p=this.infoEl;p.select("svg").attr("width",l+"px").attr("height",l+"px");var v=u+h.node().getBBox().width+s,x=o.top+l/4;p.attr("transform","translate("+v+", "+x+")");var y=this.header.select(".vzb-br-total");t?y.select("text").transition("text").delay(t).text(this.model.time.formatDate(this.time)):y.select("text").interrupt().text(this.model.time.formatDate(this.time)),y.style("opacity",Number("large"!==this.getLayoutProfile()));var _=y.node().getBBox(),w=this.width-o.right-_.width,z=o.top+_.height;y.attr("transform","translate("+w+", "+z+")").classed("vzb-transparent",b.width+_.width+10>this.width),this.element.select(".vzb-data-warning-svg").style("height",r.bottom+"px");var k=this.dataWarningEl.select("text").node().getBBox();this.dataWarningEl.attr("transform","translate("+(this.width-r.right-k.width)+", "+k.height+")").select("text"),this.dataWarningEl.select("svg").attr("width",k.height).attr("height",k.height).attr("x",-k.height-5).attr("y",1-k.height),this._updateDoubtOpacity()},drawData:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this._createAndDeleteBars(this.barContainer.selectAll(".vzb-br-bar").data(this.sortedEntities,function(t){return t.entity}));var a=this.model.ui.presentation,r=this._presentation!==a;r&&(this._presentation=a);var n=void 0===this._entitiesCount||this._entitiesCount!==this.sortedEntities.length;(r||n)&&n&&(this._entitiesCount=this.sortedEntities.length),this._resizeSvg(),this._scroll(e);var o=this.activeProfile,l=o.barRectMargin,s=o.barValueMargin,h=o.scrollMargin,d=o.margin,c=this.model.marker.axis_x,g=c.getLimits(c.which),m=Math.abs(g.max)>=Math.abs(g.min),b=this.width-d.right-d.left-this._getWidestLabelWidth()-l-h;this.xScale.range([0,b]);var u=this.model.marker.axis_x.scaleType,f=("log"===u?0:this.xScale(0))||0,p=this._getWidestLabelWidth();f>(m?d.left:d.right)+this._getWidestLabelWidth()&&(p=f),f<0&&(this.xScale.range([0,b-Math.abs(f)]),f=("log"===u?0:this.xScale(0))||0);var v=function(e){return t.xScale(e)-f},x=m?"end":"start",y=m?"start":"end",_=m?d.left+p:this.width-p-h-d.right,w=m?_+l:_-l,z=m?w+s:w-s,k=this._getWidestLabelWidth(!0)+(m?d.left:d.right)<p;this.sortedEntities.forEach(function(a){var n=a.value;if((i||r||a.isNew)&&(a.barLabel.attr("x",_).attr("y",t.activeProfile.barHeight/2).attr("text-anchor",x).text(k?a.labelFull:a.labelSmall),a.barRect.attr("rx",t.activeProfile.barHeight/4).attr("ry",t.activeProfile.barHeight/4).attr("height",t.activeProfile.barHeight),a.barValue.attr("x",z).attr("y",t.activeProfile.barHeight/2).attr("text-anchor",y)),i||a.changedWidth||r){var o=Math.max(0,n&&v(Math.abs(n)));(i||a.changedWidth||r)&&a.barRect.transition().duration(e).ease(d3.easeLinear).attr("width",o),a.barRect.attr("x",w-(n<0?o:0)),(i||a.changedValue)&&a.barValue.text(t._formatter(n)||t.translator("hints/nodata"))}(i||a.changedIndex||r)&&a.self.transition().duration(e).ease(d3.easeLinear).attr("transform","translate(0, "+t._getBarPosition(a.index)+")")})},_resizeSvg:function(){var t=this.activeProfile,e=t.barHeight,i=t.barMargin;this.barSvg.attr("height",(e+i)*this.sortedEntities.length+"px")},_scroll:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=this.barContainer.select(".vzb-selected");if(!e.empty()){var i=e.datum(),a=this._getBarPosition(i.index),r=this.activeProfile.margin,n=this.height-r.top-r.bottom,o=a-(n+this.activeProfile.barHeight)/2;this.barViewport.transition().duration(t).tween("scrollfor"+i.entity,this._scrollTopTween(o))}},_createAndDeleteBars:function(t){var e=this,i=r(this.sortedEntities,1),a=i[0];this._entityLabels[a.entity]||(this._entityLabels[a.entity]=a.label);var n=this._entityLabels[a.entity]!==this.values.label[a.entity]&&this.model.locale.id!==this._localeId;n&&(this._localeId=this.model.locale.id,this._entityLabels[a.entity]=this.values.label[a.entity]),t.exit().remove(),t=(n?t:t.enter().append("g")).each(function(t){var i=d3.select(this),a=e.values.label[t.entity],r=a.length<12?a:a.substring(0,9)+"...";t.barLabel&&t.barLabel.remove();var o=i.append("text").attr("class","vzb-br-label").attr("dy",".325em"),l=o.text(a).node().getBBox().width,s=o.text(r).node().getBBox().width;if(Object.assign(t,{labelFullWidth:l,labelSmallWidth:s,labelFull:a,labelSmall:r,barLabel:o}),!n){i.attr("class","vzb-br-bar").classed("vzb-selected",e.model.marker.isSelected(t)).attr("id","vzb-br-bar-"+t.entity+"-"+e._id).on("mousemove",function(t){return e.model.marker.highlightMarker(t)}).on("mouseout",function(){return e.model.marker.clearHighlighted()}).on("click",function(t){e.model.marker.selectMarker(t)});var h=i.append("rect").attr("stroke","transparent"),d=i.append("text").attr("class","vzb-br-value").attr("dy",".325em");Object.assign(t,{self:i,isNew:!0,barRect:h,barValue:d})}}).merge(t)},_getWidestLabelWidth:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=t?"labelFullWidth":"labelSmallWidth",i=t?"labelFull":"labelSmall",a=this.sortedEntities.reduce(function(t,i){return t[e]<i[e]?i:t}),r=a.barLabel.text(),n=a.barLabel.text(a[i]).node().getBBox().width;return a.barLabel.text(r),n},_drawColors:function(){var t=this,e=this;this.barContainer.selectAll(".vzb-br-bar>rect").each(function(t){var i=t.entity,a=d3.select(this),r=e.values.color[i];r||0===r?a.style("fill",e._getColor(r)).attr("stroke","transparent"):a.style("fill",d).attr("stroke",h)}),this.barContainer.selectAll(".vzb-br-bar>text").style("fill",function(e){var i=e.entity;return t._getDarkerColor(t.values.color[i])})},_getColor:function(t){return d3.rgb(this.cScale(t))},_getDarkerColor:function(t){return this._getColor(t).darker(2)},_scrollTopTween:function(t){return function(){var e=this,i=d3.interpolateNumber(this.scrollTop,t);return function(t){e.scrollTop=i(t)}}},_getBarPosition:function(t){return(this.activeProfile.barHeight+this.activeProfile.barMargin)*t},_entities:{},_sortByIndicator:function(t){var e=this;return Object.keys(t).map(function(i){var r,n=e._entities[i],o=t[i],l=e.values.label[i],s=e._formatter(o);return n?Object.assign(n,{value:o,label:l,formattedValue:s,changedValue:s!==n.formattedValue,changedWidth:o!==n.value,isNew:!1}):e._entities[i]=(r={entity:i,value:o,formattedValue:s},a(r,e.model.entities.dim,i),a(r,"changedValue",!0),a(r,"changedWidth",!0),a(r,"isNew",!0),r)}).sort(function(t,e){var i=t.value;return e.value-i}).map(function(t,e){return Object.assign(t,{index:e,changedIndex:e!==t.index})})},_selectBars:function(){var t=this,e=this.model.entities.dim,i=this.model.marker.select;this.barContainer.classed("vzb-dimmed-selected",!1),this.barContainer.selectAll(".vzb-br-bar.vzb-selected").classed("vzb-selected",!1),i.length&&(this.barContainer.classed("vzb-dimmed-selected",!0),i.forEach(function(i){t.barContainer.select("#vzb-br-bar-"+i[e]+"-"+t._id).classed("vzb-selected",!0)}))},_updateOpacity:function(){var t=this.model.marker,e=t.highlight,i=t.select,a=t.opacityHighlightDim,r=t.opacitySelectDim,n=t.opacityRegular,o=e.length>0,l=i.length>0;this.barContainer.selectAll(".vzb-br-bar").style("opacity",function(e){return o&&t.isHighlighted(e)?1:l?t.isSelected(e)?n:r:o?a:n})},_updateDoubtOpacity:function(t){this.dataWarningEl.style("opacity",t||(this.model.marker.select.length?1:this.wScale(+this.model.time.value.getUTCFullYear().toString())))}});e.default=c},function(t,e){},function(t,e){t.exports='<!-- Bar Chart Component -->\n<div class="vzb-barrankchart">\n <svg class="vzb-br-header">\n <g class="vzb-br-title">\n <text></text>\n </g>\n <g class="vzb-br-total">\n <text></text>\n </g>\n <g class="vzb-br-axis-info vzb-noexport"></g>\n </svg>\n\n <div class="vzb-br-barsviewport vzb-dialog-scrollable">\n <svg class="vzb-br-bars-svg">\n <g class="vzb-br-bars"></g>\n </svg>\n </div>\n\n <svg class="vzb-data-warning-svg">\n <g class="vzb-data-warning vzb-noexport">\n <svg></svg>\n <text></text>\n </g>\n </svg>\n</div>\n'},function(t,e,i){t.exports=i(0)}]);
//# sourceMappingURL=barrankchart.js.map
{
"name": "vizabi-barrankchart",
"version": "1.0.8-4",
"version": "1.0.8-5",
"description": "Bar rank chart tool for Vizabi 📊",

@@ -5,0 +5,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc