rave-legends.js 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521
  1. // During the rave-legends.js build, this file is added to the top.
  2. // Create an inner self-executing function that will be run with the global scope
  3. // On browsers, this is 'window'. Everywhere else should use 'this' if available.
  4. // Need to run eval('this') "indirectly" by having eval returned by (1,eval). OBVIOUSLY :)
  5. (function (global, factory) {
  6. // dynamically determine how 'rave' variable should be loaded depeneding on loader type
  7. var _rave;
  8. if (typeof module === "object" && typeof module.exports === "object" && typeof require == "function") {
  9. // CommonJS/node.js
  10. var rave = require("rave");
  11. require("rave-utilities");
  12. require("rave-layouts");
  13. var navigation = factory(global,rave);
  14. module.exports = rave;
  15. } else if (typeof define === "function" && define.amd) {
  16. // AMD
  17. define(['rave','rave-utilities','rave-layouts'], function(rave) {
  18. return factory(global,rave);
  19. });
  20. } else {
  21. // probably loading via script tag. run as is, setting stuff on rave
  22. factory(global,global['rave']);
  23. }
  24. }((1, eval)('this'), function (_global, _rave) {(function() {
  25. var $ = {};
  26. // $source: com/ibm/rave/ext/internal/legend/nativeImpl/ModuleHeader
  27. /************************************************************************
  28. ** IBM Confidential
  29. **
  30. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  31. **
  32. ** (C) Copyright IBM Corp. 2015
  33. **
  34. ** The source code for this program is not published or otherwise divested of its trade secrets,
  35. ** irrespective of what has been deposited with the U.S. Copyright Office.
  36. ************************************************************************/
  37. // setup
  38. var global = typeof _global !== "undefined" ? _global : (1, eval)('this');
  39. var rave = typeof _rave !== "undefined" ? _rave : global['rave'];
  40. com_ibm_rave_core_Rave = rave;
  41. rave["internal"]["Declare"] = rave["_"]["com_ibm_rave_core_nativeImpl_Declare"];
  42. // $source: com/ibm/rave/ext/legend/RaveLegend
  43. /************************************************************************
  44. ** IBM Confidential
  45. **
  46. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  47. **
  48. ** (C) Copyright IBM Corp. 2017
  49. **
  50. ** The source code for this program is not published or otherwise divested of its trade secrets,
  51. ** irrespective of what has been deposited with the U.S. Copyright Office.
  52. ************************************************************************/
  53. // GENERATED
  54. //@import com/ibm/rave/ext/legend/swatch/SwatchLegend (runtime) // new
  55. //@import com/ibm/rave/ext/legend/continuous/ContinuousLegend (runtime) // new
  56. //@import com/ibm/rave/ext/legend/size/NestedSizeLegend (runtime) // new
  57. /**
  58. * A factory of extended legends for rave capability.
  59. */
  60. var com_ibm_rave_ext_legend_RaveLegend = rave['internal']['Declare']({
  61. /**
  62. * Creates and return a swatch legend
  63. * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) a new instance of {@link SwatchLegend}
  64. * @see SwatchLegend
  65. */
  66. /** @expose */
  67. swatch : function() {
  68. return new com_ibm_rave_ext_legend_swatch_SwatchLegend();
  69. },
  70. /**
  71. * Creates and return a continuous legend
  72. * @return (com.ibm.rave.ext.legend.continuous.ContinuousLegend) a new instance of {@link SwatchLegend}
  73. * @see ContinuousLegend
  74. */
  75. /** @expose */
  76. continuous : function() {
  77. return new com_ibm_rave_ext_legend_continuous_ContinuousLegend();
  78. },
  79. /**
  80. * Create a new nested size legend component.
  81. * @see NestedSizeLegend
  82. */
  83. /** @expose */
  84. nestedSize : function() {
  85. return new com_ibm_rave_ext_legend_size_NestedSizeLegend();
  86. }
  87. //constructor : function() {}
  88. });
  89. com_ibm_rave_ext_legend_RaveLegend.getRegistrationStatus = function() {
  90. var registrationStatus = rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().getData("RAVELEGEND_EXTENSION_REGISTRATION_STATUS_KEY");
  91. if (!registrationStatus) {
  92. registrationStatus = new com_ibm_rave_ext_legend_RaveLegend.RegistrationStatus();
  93. rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().putData("RAVELEGEND_EXTENSION_REGISTRATION_STATUS_KEY", registrationStatus);
  94. }
  95. return registrationStatus;
  96. };
  97. /**
  98. * Register the factory for this legend provider
  99. * @return (boolean) true if registration was successful, false otherwise
  100. * @see Capabilities
  101. */
  102. /** @expose */
  103. com_ibm_rave_ext_legend_RaveLegend.init = function() {
  104. var registrationStatus = com_ibm_rave_ext_legend_RaveLegend.getRegistrationStatus();
  105. if (!registrationStatus.registered) {
  106. registrationStatus.registered = rave.capabilities.extension("legend", function() {
  107. return new com_ibm_rave_ext_legend_RaveLegend();
  108. });
  109. }
  110. return registrationStatus.registered;
  111. };
  112. com_ibm_rave_ext_legend_RaveLegend.RegistrationStatus = rave['internal']['Declare']({
  113. registered : false
  114. });
  115. /**
  116. * RaveLegend extension id
  117. */
  118. /** @expose */
  119. com_ibm_rave_ext_legend_RaveLegend.LEGEND = "legend";
  120. //com_ibm_rave_ext_legend_RaveLegend.EXTENSION_REGISTRATION_STATUS_KEY = "RAVELEGEND_EXTENSION_REGISTRATION_STATUS_KEY";
  121. // Auto initialization
  122. com_ibm_rave_ext_legend_RaveLegend.init();
  123. if (!rave.capabilities["legend"]) {
  124. rave.capabilities["legend"] = function() {
  125. return new com_ibm_rave_ext_legend_RaveLegend();
  126. };
  127. } else {
  128. console.log("Could not register extension: RaveLegend");
  129. }
  130. // $source: com/ibm/rave/ext/legend/AbstractLegend
  131. /************************************************************************
  132. ** IBM Confidential
  133. **
  134. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  135. **
  136. ** (C) Copyright IBM Corp. 2017
  137. **
  138. ** The source code for this program is not published or otherwise divested of its trade secrets,
  139. ** irrespective of what has been deposited with the U.S. Copyright Office.
  140. ************************************************************************/
  141. // GENERATED
  142. //@import com/ibm/rave/ext/legend/ExtraLegendEntry (runtime) // new
  143. /**
  144. * A class that would generate and draw a legend
  145. */
  146. var com_ibm_rave_ext_legend_AbstractLegend = rave['internal']['Declare']({
  147. //_scale : null,
  148. //_orient : null,
  149. //_labelPadding : null,
  150. //_scaleArguments : null,
  151. //_size : null,
  152. //_dataValues : null,
  153. //_labelFormat : null,
  154. //_title : null,
  155. //_labelTruncationText : null,
  156. //_legendTruncationIndicator : null,
  157. //_legendBorderColor : null,
  158. //_legendBackgroundColor : null,
  159. //_shapeBorderColor : null,
  160. //_titleAlignment : null,
  161. //_titleInsets : null,
  162. //_entryInsets : null,
  163. //_legendInsets : null,
  164. //_titleFontSize : null,
  165. //_titleFontFamily : null,
  166. //_titleFill : null,
  167. /** @expose */
  168. _extraLegendEntries : null,
  169. _reverse : false,
  170. _minDataLen : 0,
  171. /** @expose */
  172. _spaceUsed : 0,
  173. _$functionClassMethod : function() {
  174. var _$self = function(args) {
  175. if (args !== null || arguments.length > 1){
  176. args = Array.prototype.slice.call(arguments, 0);
  177. }
  178. {
  179. _$self.legend(args[0]);
  180. return null;
  181. }
  182. };
  183. return _$self;
  184. },
  185. constructor : function() {
  186. this._orient = "vertical";
  187. this._labelPadding = 3.0;
  188. this._scaleArguments = com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_SCALE_ARGS;
  189. this._size = com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_LEGEND_SIZE;
  190. this._labelTruncationText = "...";
  191. this._titleAlignment = "middle";
  192. this._titleInsets = com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
  193. this._entryInsets = com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
  194. this._legendInsets = com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
  195. {
  196. this._extraLegendEntries = rave.map();
  197. }
  198. },
  199. /** @expose */
  200. extraLegendEntries : function() {
  201. return this._extraLegendEntries;
  202. },
  203. minDataLen$0 : function() {
  204. return this._minDataLen;
  205. },
  206. minDataLen$1 : function(minDataLen) {
  207. this._minDataLen = minDataLen;
  208. },
  209. /**
  210. * Set the scale to be used by this legend. This scale's range must be a color object or a color string for all legends except axis legend where the range must be a numeric value If data values aren't specified on this legend, then this scale's ticksInRange, ticks or domain methods (depending on their availabilities on the scale) would be used to generate legend entries. Moreover, if label format isn't set on this legend, then this scale's tickFormat (if available) could be used to extract the legend entries labels.
  211. * @param (rave['internal']['AbstractScale']) scale The scale object to assign to this legend
  212. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  213. * @see #this.dataValues()
  214. * @see #this.labelFormat()
  215. */
  216. scale$0 : function(scale) {
  217. this._scale = scale;
  218. return this;
  219. },
  220. /**
  221. * Get the scale assigned to this legend.
  222. * @return (rave['internal']['AbstractScale']) the scale assigned to this legend.
  223. */
  224. scale$1 : function() {
  225. return this._scale;
  226. },
  227. /**
  228. * Set the legend orientation. Can be one of: <ul> <li>horizontal</li> <li>vertical</li> </ul> The default orientation is vertical.
  229. * @param (String) orientation The orientation to assign to this legend.
  230. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  231. */
  232. orient$0 : function(orientation) {
  233. if ("horizontal" == orientation || "vertical" == orientation) {
  234. this._orient = orientation;
  235. } else {
  236. this._orient = "vertical";
  237. }
  238. return this;
  239. },
  240. /**
  241. * Get the current orientation.
  242. * @return (String) Orientation String.
  243. */
  244. orient$1 : function() {
  245. return this._orient;
  246. },
  247. /**
  248. * Get the current legend title. Default is null
  249. * @return (String) Title String.
  250. */
  251. title$0 : function() {
  252. return this._title;
  253. },
  254. /**
  255. * Set the legend title. If the value passed is null or an empty string then no title would be drawn for this legend.
  256. * @param (String) t The title to assign to this legend.
  257. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  258. */
  259. title$1 : function(t) {
  260. this._title = t;
  261. return this;
  262. },
  263. /**
  264. * Get the current legend size: width and height. The default is 100x100
  265. * @return (Array) the legend size.
  266. */
  267. size$0 : function() {
  268. return this._size;
  269. },
  270. /**
  271. * Set the legend size: its bounding box width and height.
  272. * @param (Array) t The dimension object representing the width and height to assign to this legend.
  273. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  274. */
  275. size$1 : function(t) {
  276. this._size = t;
  277. return this;
  278. },
  279. /**
  280. * Set the legend's entries generation arguments. These arguments will be passed to the scale's ticks method to generate legend entries if needed.
  281. * @param (java.lang.Object[]) scaleArgs Argument list to control entries generation.
  282. * @return (com.ibm.rave.ext.legend.AbstractLegend) This legend instance.
  283. * @see #this.scale(rave['internal']['AbstractScale'] this.scale)
  284. */
  285. scaleArguments$0 : function(scaleArgs) {
  286. if (scaleArgs !== null || arguments.length > 1){
  287. scaleArgs = Array.prototype.slice.call(arguments);
  288. }
  289. {
  290. this._scaleArguments = scaleArgs;
  291. return this;
  292. }
  293. },
  294. /**
  295. * Get the currently assigned legend entries arguments. Default is [5].
  296. * @return (java.lang.Object[]) Array of legend entries argument values.
  297. */
  298. scaleArguments$1 : function() {
  299. return this._scaleArguments;
  300. },
  301. /**
  302. * Manually specify array of legend entries values which will override the default legend entries generation behavior. A new entry will be generated for each value in the array.
  303. * @param (Array) values Array of legend entries values.
  304. * @return (com.ibm.rave.ext.legend.AbstractLegend) This legend instance.
  305. */
  306. dataValues$0 : function(values) {
  307. this._dataValues = values;
  308. return this;
  309. },
  310. /**
  311. * Get the currently assigned legend entries values.
  312. * @return (Array) Array of legend entries values, or null if none have been assigned (see {@link #this.dataValues(Array)} ).
  313. */
  314. dataValues$1 : function() {
  315. return this._dataValues;
  316. },
  317. /**
  318. * Specify legend entries label value. This value would be used for all legend entries
  319. * @param (String) format the string to be used as a label for legend entries
  320. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  321. */
  322. labelFormat$0 : function(format) {
  323. this._labelFormat = format;
  324. return this;
  325. },
  326. /**
  327. * Specify legend entries label generating functor.
  328. * @param (rave['internal']['ValueFunction']) valueFunction "anonymous" function class, when executed, returns the formatted legend entries label value.
  329. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  330. */
  331. labelFormat$1 : function(valueFunction) {
  332. this._labelFormat = valueFunction;
  333. return this;
  334. },
  335. /**
  336. * Get the currently assigned legend entries label format.
  337. * @return (Object) The legend entries label format object, or null if a format has not been specified.
  338. */
  339. labelFormat$2 : function() {
  340. return this._labelFormat;
  341. },
  342. /**
  343. * Specify the padding distance in pixels between a legend entry shape and its label. Default is 3 pixels
  344. * @param (Object) padding Padding value in pixels. It could be either a Double value, or a string that could be parsed to a double value.
  345. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  346. */
  347. labelPadding$0 : function(padding) {
  348. this._labelPadding = padding;
  349. return this;
  350. },
  351. /**
  352. * Get the currently assigned padding in pixels between a legend entry shape and its label. Default is 3.
  353. * @return (Object) Padding value.
  354. */
  355. labelPadding$1 : function() {
  356. return this._labelPadding;
  357. },
  358. /**
  359. * Gets the value of the color assigned to the legend's border. Default is null indicating that there is no border will be drawn.
  360. * @return (Object) the current value assigned for the legend's border color
  361. */
  362. borderColor$0 : function() {
  363. return this._legendBorderColor;
  364. },
  365. /**
  366. * Sets the value of the color assigned to the legend's border. The value to set could either be a Color object, or a string that could be parsed into a color object. The format of this string could be any of the formats supported by CSS to represent colors. If the string passed could not be parsed successfully, then a black color will be used. If null or an empty string is passed, then no border is drawn.
  367. * @param (Object) borderColor The border color value to set.
  368. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  369. * @see Color
  370. */
  371. borderColor$1 : function(borderColor) {
  372. this._legendBorderColor = borderColor;
  373. return this;
  374. },
  375. /**
  376. * Gets the value of the color assigned to the legend entry shape border. Default is null indicating that there is no border will be drawn.
  377. * @return (Object) the current value assigned for the swatch's border color
  378. */
  379. shapeBorderColor$0 : function() {
  380. return this._shapeBorderColor;
  381. },
  382. /**
  383. * Sets the value of the color assigned to the legend entry shape border. The value to set could either be a Color object, or a string that could be parsed into a color object. The format of this string could be any of the formats supported by CSS to represent colors. If the string passed could not be parsed successfully, then a black color will be used. If null or an empty string is passed, then no border is drawn.
  384. * @param (Object) shapeBorderColor The border color value to set.
  385. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  386. * @see Color
  387. */
  388. shapeBorderColor$1 : function(shapeBorderColor) {
  389. this._shapeBorderColor = shapeBorderColor;
  390. return this;
  391. },
  392. /**
  393. * Gets the value of the color assigned to the legend's background. Default is null indicating that the legend's background will be transparent.
  394. * @return (Object) the current value assigned for the legend's background color
  395. */
  396. backgroundColor$0 : function() {
  397. return this._legendBackgroundColor;
  398. },
  399. /**
  400. * Sets the value of the color assigned to the legend's background. The value to set could either be a Color object, or a string that could be parsed into a color object. The format of this string could be any of the formats supported by CSS to represent colors. If the string passed could not be parsed successfully, then a black color will be used. If null or an empty string is passed, then no border is drawn.
  401. * @param (Object) backgroundColor The background color value to set.
  402. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  403. * @see Color
  404. */
  405. backgroundColor$1 : function(backgroundColor) {
  406. this._legendBackgroundColor = backgroundColor;
  407. return this;
  408. },
  409. /**
  410. * Gets the current value assigned to the legend's title alignment
  411. * @return (String) the current value assigned to the legend's title alignment
  412. */
  413. titleAlignment$0 : function() {
  414. return this._titleAlignment;
  415. },
  416. /**
  417. * Sets the current value assigned to the legend's title horizontal alignment. Default is middle Can be one of: <ul> <li>start</li> <li>middle</li> <li>end</li> </ul> If a non valid value is passed then the default alignment will be used.
  418. * @param (String) titleAlignment the alignment value to set
  419. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  420. */
  421. titleAlignment$1 : function(titleAlignment) {
  422. if ("start" == titleAlignment || "middle" == titleAlignment || "end" == titleAlignment) {
  423. this._titleAlignment = titleAlignment;
  424. } else {
  425. this._titleAlignment = "middle";
  426. }
  427. return this;
  428. },
  429. /**
  430. * Gets the current insets used for the legend's title.
  431. * @return (Object) the current insets used for the legend's title
  432. */
  433. titleInsets$0 : function() {
  434. return this._titleInsets;
  435. },
  436. /**
  437. * Sets the current insets to be used for the legend's title. Default insets uses padding of 3 pixels in all directions: top, bottom, left and right. If null is passed then the default insets value will be used.
  438. * @param (Object) titleInsets the insets to set
  439. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  440. */
  441. titleInsets$1 : function(titleInsets) {
  442. this._titleInsets = (titleInsets) ? this.sanitizeInsets(titleInsets) : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
  443. return this;
  444. },
  445. /**
  446. * Get the current legend title fill color. Default is null.
  447. * @return (String) Title fill string.
  448. */
  449. titleFill$0 : function() {
  450. return this._titleFill;
  451. },
  452. /**
  453. * Set the legend title fill color. If the value is null, the title will use the default fill color from the CSS.
  454. * @param (String) f The title fill color
  455. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  456. */
  457. titleFill$1 : function(f) {
  458. this._titleFill = f;
  459. return this;
  460. },
  461. /**
  462. * Get the current legend title font size. Default is null.
  463. * @return (String) Title font size string.
  464. */
  465. titleFontSize$0 : function() {
  466. return this._titleFontSize;
  467. },
  468. /**
  469. * Set the legend title font size. Sizes are CSS size strings. If the value is null, the title will use the default font size from the CSS.
  470. * @param (String) s The title font size
  471. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  472. */
  473. titleFontSize$1 : function(s) {
  474. this._titleFontSize = s;
  475. return this;
  476. },
  477. /**
  478. * Get the current legend title font family. Default is null.
  479. * @return (String) Title font family string.
  480. */
  481. titleFontFamily$0 : function() {
  482. return this._titleFontFamily;
  483. },
  484. /**
  485. * Set the legend title font family. The argument is a comma-separated list of font names; for platform independence each name should be double-quoted. If the value is null, the title will use the default font family from the CSS.
  486. * @param (String) f The title font family
  487. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  488. */
  489. titleFontFamily$1 : function(f) {
  490. this._titleFontFamily = f;
  491. return this;
  492. },
  493. /**
  494. * Gets the current insets used for the legend's entry.
  495. * @return (Object) the current insets used for the legend's entry
  496. */
  497. entryInsets$0 : function() {
  498. return this._entryInsets;
  499. },
  500. /**
  501. * Sets the current insets to be used for each legend's entry. Default insets uses padding of 3 pixels in all directions: top, bottom, left and right If null is passed then the default insets value will be used.
  502. * @param (Object) entryInsets the insets to set
  503. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  504. */
  505. entryInsets$1 : function(entryInsets) {
  506. this._entryInsets = (entryInsets) ? this.sanitizeInsets(entryInsets) : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
  507. return this;
  508. },
  509. /**
  510. * Gets the current insets used for the legend.
  511. * @return (Object) the current insets used for the legend
  512. */
  513. insets$0 : function() {
  514. return this._legendInsets;
  515. },
  516. /**
  517. * Sets the current insets to be used for each legend. Default insets uses padding of 3 pixels in all directions: top, bottom, left and right If null is passed then the default insets value will be used.
  518. * @param (Object) legendInsets the insets to set
  519. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  520. */
  521. insets$1 : function(legendInsets) {
  522. this._legendInsets = (legendInsets) ? this.sanitizeInsets(legendInsets) : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
  523. return this;
  524. },
  525. /**
  526. * Utility method used to fill any missing values from the insets
  527. * @param (Object) legendInsets insets to sanitize
  528. * @return (Object) the filled insets
  529. */
  530. sanitizeInsets : function(legendInsets) {
  531. legendInsets["top"] = ((typeof legendInsets["top"] === "number" || legendInsets["top"] instanceof Number)) ? legendInsets["top"] : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS["top"];
  532. legendInsets["bottom"] = ((typeof legendInsets["bottom"] === "number" || legendInsets["bottom"] instanceof Number)) ? legendInsets["bottom"] : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS["bottom"];
  533. legendInsets["left"] = ((typeof legendInsets["left"] === "number" || legendInsets["left"] instanceof Number)) ? legendInsets["left"] : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS["left"];
  534. legendInsets["right"] = ((typeof legendInsets["right"] === "number" || legendInsets["right"] instanceof Number)) ? legendInsets["right"] : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS["right"];
  535. return legendInsets;
  536. },
  537. /**
  538. * Gets the value of reverse configuration
  539. * @return (boolean) whether the legend would reverse legend entry values or not
  540. */
  541. reverse$0 : function() {
  542. return this._reverse;
  543. },
  544. /**
  545. * Get the current text used for truncation for legend labels and title. Default is an ellipses
  546. * @return (String) Title String.
  547. */
  548. labelTruncationText$0 : function() {
  549. return this._labelTruncationText;
  550. },
  551. /**
  552. * Set the text used for truncation of legend labels and title. Default is an ellipses.
  553. * @param (String) labelTruncationText The text to use when truncating legend labels.
  554. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  555. */
  556. labelTruncationText$1 : function(labelTruncationText) {
  557. this._labelTruncationText = labelTruncationText;
  558. return this;
  559. },
  560. /**
  561. * Get the current truncation indicator to be used in case the size of this legend wasn't big enough to fit all entries. Default is null and a simple ellipses will be used instead;
  562. * @return (Object) The truncation indicator.
  563. * @see (Object) LegendTruncationIndicator
  564. */
  565. truncationIndicator$0 : function() {
  566. return this._legendTruncationIndicator;
  567. },
  568. /**
  569. * Set the truncation indicator of legend. Default is null and a simple ellipses will be used instead.
  570. * @param (Object) legendTruncationIndicator The truncation indicator object.
  571. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
  572. * @see (Object) LegendTruncationIndicator
  573. */
  574. truncationIndicator$1 : function(legendTruncationIndicator) {
  575. this._legendTruncationIndicator = legendTruncationIndicator;
  576. return this;
  577. },
  578. /**
  579. * Sets the value of reverse configuration. If it is true, then the legend will reverse the order of the entries values so that the entries will be drawn in reverse order, else, the legend will render the entries in the same order it got them. Default value is false.
  580. * @param (boolean) reverse the value to set reverse for
  581. * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance
  582. */
  583. reverse$1 : function(reverse) {
  584. this._reverse = reverse;
  585. return this;
  586. },
  587. addTruncationIndicator$0 : function(gSelection, titleVerticalShift, availableWidth, availableHeight, textFlow) {
  588. var midHorizontalPoint = ((this.size()[0] - (this.insets()["left"] + this.insets()["right"])) / 2.0) + this.insets()["left"];
  589. return this.addTruncationIndicator$1(gSelection.append("g").attr("class", "legendTruncationEntry"), midHorizontalPoint, titleVerticalShift - this.insets()["bottom"] + 3.0, availableWidth + this.entryInsets()["left"] + this.entryInsets()["right"], availableHeight + this.entryInsets()["top"] + this.entryInsets()["bottom"] - 3.0, textFlow, true);
  590. },
  591. addTruncationIndicator$1 : function(truncationSelector, midHorizontalPoint, y, availableWidth, availableHeight, textFlow, transform) {
  592. var truncationSymbol = this.getLegendTruncationIndicatorShapeSymbol();
  593. var truncationText = this.getLegendTruncationIndicatorText();
  594. var shapeWidth = 0;
  595. if (truncationSymbol) {
  596. var shape = truncationSelector.append("path").attr("class", "legendTruncationShape").attr("d", truncationSymbol);
  597. var shapeColor = this.getLegendTruncationIndicatorShapeColor();
  598. if ((shapeColor)) {
  599. shape.style("fill", shapeColor);
  600. } else {
  601. shape.style("fill-opacity", 0);
  602. }
  603. var borderColor = this.getLegendTruncationIndicatorShapeBorderColor();
  604. if ((borderColor)) {
  605. shape.attr("stroke", borderColor);
  606. }
  607. var shapeBbox = shape.node().getBBox();
  608. shapeWidth = shapeBbox.width;
  609. shape.attr("transform", "translate(" + (shapeWidth / 2.0) + ",0)");
  610. }
  611. var text = truncationSelector.append("text").attr("class", "legendTruncationLabel").text(truncationText);
  612. textFlow.wrap(true);
  613. textFlow.extent(~~(availableWidth - shapeWidth - 3.0), ~~availableHeight);
  614. textFlow.flow(text);
  615. var textX = (truncationSymbol) ? (3.0 + shapeWidth) : 0;
  616. text.attr("text-anchor", "start").attr("x", textX).attr("dy", this.getTextDyPlacement(text.node()));
  617. text.selectAll("tspan").attr("x", textX).attr("width", null);
  618. text.select("tspan").attr("x", null).attr("dy", null);
  619. var trunctationBBox = truncationSelector.node().getBBox();
  620. if (trunctationBBox.height > availableHeight || trunctationBBox.width > availableWidth) {
  621. if (truncationSymbol) {
  622. truncationSelector.select("path").remove();
  623. trunctationBBox = truncationSelector.node().getBBox();
  624. if (trunctationBBox.height > availableHeight || trunctationBBox.width > availableWidth) {
  625. truncationSelector.remove();
  626. return null;
  627. }
  628. text.attr("x", 0);
  629. text.selectAll("tspan").attr("x", 0);
  630. text.select("tspan").attr("x", null);
  631. } else {
  632. truncationSelector.remove();
  633. return null;
  634. }
  635. }
  636. if (transform) {
  637. truncationSelector.attr("transform", "translate(" + (midHorizontalPoint - (trunctationBBox.width / 2.0)) + "," + y + ")");
  638. }
  639. return truncationSelector;
  640. },
  641. /** @expose */
  642. getLegendTruncationIndicatorShapeSymbol : function() {
  643. if ((this._legendTruncationIndicator)) {
  644. if ((this._legendTruncationIndicator["shape"])) {
  645. var size = (this._legendTruncationIndicator["shapeSize"]) ? + (this._legendTruncationIndicator["shapeSize"]) : 400.0;
  646. var shapeSymbol;
  647. if (typeof this._legendTruncationIndicator["shape"] === "function") {
  648. shapeSymbol = (this._legendTruncationIndicator["shape"]).size(size);
  649. } else {
  650. shapeSymbol = rave.svg.symbol().size(size).type(this._legendTruncationIndicator["shape"]);
  651. }
  652. return shapeSymbol;
  653. }
  654. }
  655. return null;
  656. },
  657. /** @expose */
  658. getLegendTruncationIndicatorShapeColor : function() {
  659. if ((this._legendTruncationIndicator)) {
  660. if ((this._legendTruncationIndicator["shape"])) {
  661. return (this._legendTruncationIndicator["shapeColor"]) ? rave.rgb(this._legendTruncationIndicator["shapeColor"]).toString() : null;
  662. }
  663. }
  664. return null;
  665. },
  666. /** @expose */
  667. getLegendTruncationIndicatorShapeBorderColor : function() {
  668. if ((this._legendTruncationIndicator)) {
  669. if ((this._legendTruncationIndicator["shape"])) {
  670. return (this._legendTruncationIndicator["shapeBorderColor"]) ? rave.rgb(this._legendTruncationIndicator["shapeBorderColor"]).toString() : null;
  671. }
  672. }
  673. return null;
  674. },
  675. /** @expose */
  676. getLegendTruncationIndicatorText : function() {
  677. if ((this._legendTruncationIndicator)) {
  678. return (this._legendTruncationIndicator["text"]) ? this._legendTruncationIndicator["text"] : null;
  679. }
  680. return "...";
  681. },
  682. /** @expose */
  683. prepareLegendGroup : function(context) {
  684. var gSelection = rave.select(context);
  685. gSelection.selectAll(".legendGroup").remove();
  686. gSelection = gSelection.append("g").attr("class", "legendGroup");
  687. return gSelection;
  688. },
  689. /** @expose */
  690. getTextDyPlacement : function(node) {
  691. var numChildren = node.rave_getChildNodes().length;
  692. if (numChildren < 2) {
  693. return ".35em";
  694. }
  695. if (numChildren == 2) {
  696. return "-" + ((1.0 - 1) / 2) + "em";
  697. }
  698. var spacing = (numChildren - 1) * (1.0 - 1);
  699. var dy = (numChildren * 0.7) - 0.35;
  700. var placement = (dy + spacing) / 2;
  701. return "-" + (placement) + "em";
  702. },
  703. /** @expose */
  704. getLabelFormat : function() {
  705. var labelFormat = this._labelFormat;
  706. if (labelFormat == null) {
  707. labelFormat = com_ibm_rave_ext_legend_AbstractLegend._IDENTITY_FN;
  708. }
  709. return labelFormat;
  710. },
  711. /** @expose */
  712. prepareLegendTitle : function(gSelection, textFlow) {
  713. this._spaceUsed = 0;
  714. if ((this._title)) {
  715. var titleSelector = gSelection.append("text").attr("class", "legendTitle").text(this._title).style("font-size", this._titleFontSize).style("font-family", this._titleFontFamily).style("fill", this._titleFill);
  716. var vertical = this._legendInsets["top"] + this._titleInsets["top"] + this._legendInsets["bottom"] + this._titleInsets["bottom"];
  717. var availableHeight = this._size[1] - vertical;
  718. var left = this._titleInsets["left"] + this._legendInsets["left"];
  719. var right = this._titleInsets["right"] + this._legendInsets["right"];
  720. var availableWidth;
  721. if ("start" == this._titleAlignment) {
  722. availableWidth = this._size[0] - left - this._legendInsets["right"];
  723. } else if ("middle" == this._titleAlignment) {
  724. availableWidth = this._size[0] - (this._legendInsets["left"] + this._legendInsets["right"]);
  725. } else {
  726. availableWidth = this._size[0] - right - this._legendInsets["left"];
  727. }
  728. if (availableHeight <= 4.0 || availableWidth <= 4.0) {
  729. titleSelector.remove();
  730. return titleSelector;
  731. }
  732. textFlow.extent(~~availableWidth, ~~availableHeight);
  733. textFlow.flow(titleSelector);
  734. titleSelector.attr("dy", ".7em").attr("text-anchor", this._titleAlignment);
  735. var titleBbox = titleSelector.node().getBBox();
  736. if (titleBbox.height > availableHeight || titleBbox.width > availableWidth) {
  737. titleSelector.text("...");
  738. titleBbox = titleSelector.node().getBBox();
  739. if (titleBbox.height <= availableHeight && titleBbox.width <= availableWidth) {
  740. if (this._orient == "vertical") {
  741. this._spaceUsed = titleBbox.width + this._titleInsets["left"] + this._titleInsets["right"];
  742. } else {
  743. this._spaceUsed = titleBbox.height + this._titleInsets["top"] + this._titleInsets["bottom"];
  744. }
  745. titleSelector.remove();
  746. var titleTruncationSelector = gSelection.append("text").attr("class", "legendTruncationTitle").text("...").attr("y", this._legendInsets["top"] + this._titleInsets["top"]).attr("dy", ".7em").attr("text-anchor", "middle").attr("x", this._legendInsets["left"] + this._titleInsets["left"] + (availableWidth / 2.0));
  747. return titleTruncationSelector;
  748. }
  749. titleSelector.remove();
  750. } else {
  751. if (this._orient == "vertical") {
  752. this._spaceUsed = titleBbox.width + this._titleInsets["left"] + this._titleInsets["right"];
  753. } else {
  754. this._spaceUsed = titleBbox.height + this._titleInsets["top"] + this._titleInsets["bottom"];
  755. }
  756. }
  757. return titleSelector;
  758. }
  759. return null;
  760. },
  761. /** @expose */
  762. calculateTitleVerticalShift : function(titleSelector) {
  763. var titleHeight = 0;
  764. var top = this._legendInsets["top"];
  765. var bottom = this._legendInsets["bottom"];
  766. if (titleSelector) {
  767. bottom += this._titleInsets["bottom"];
  768. top += this._titleInsets["top"];
  769. titleSelector.attr("y", top);
  770. var node = titleSelector.node();
  771. var titleBBox = node.getBBox();
  772. titleHeight = titleBBox.height;
  773. }
  774. return top + bottom + titleHeight;
  775. },
  776. alignTitleHorizontally$0 : function(titleSelector) {
  777. if (titleSelector) {
  778. var left = this._titleInsets["left"] + this._legendInsets["left"];
  779. var right = this._titleInsets["right"] + this._legendInsets["right"];
  780. var x;
  781. if ("start" == this._titleAlignment) {
  782. x = left;
  783. } else if ("middle" == this._titleAlignment) {
  784. x = (this._size[0] / 2.0);
  785. } else {
  786. x = (this._size[0] - right);
  787. }
  788. titleSelector.attr("x", x);
  789. titleSelector.selectAll("tspan").attr("x", x).attr("width", null);
  790. titleSelector.select("tspan").attr("x", null).attr("dy", null);
  791. }
  792. },
  793. alignTitleHorizontally$1 : function(titleSelector, width) {
  794. if (titleSelector) {
  795. var x;
  796. if ("start" == this._titleAlignment) {
  797. x = this._titleInsets["left"] + this._legendInsets["left"];
  798. } else if ("end" == this._titleAlignment) {
  799. var diff = this.size()[0] - width;
  800. if (diff > (this._titleInsets["right"] + this._legendInsets["right"])) {
  801. x = width;
  802. } else {
  803. x = width + (diff - (this._titleInsets["right"] + this._legendInsets["right"]));
  804. }
  805. } else {
  806. x = (width / 2.0) + this._legendInsets["left"];
  807. }
  808. titleSelector.attr("x", x);
  809. titleSelector.selectAll("tspan").attr("x", x).attr("width", null);
  810. titleSelector.select("tspan").attr("x", null).attr("dy", null);
  811. }
  812. },
  813. /** @expose */
  814. createTextFlowComponent : function() {
  815. var textFlow = rave.capabilities.extension("textflow");
  816. textFlow.wrap(true).spacing(1.0).truncate(true).dropTextOnFail(false).textTruncateIndicator(this.labelTruncationText());
  817. return textFlow;
  818. },
  819. /** @expose */
  820. prepareLegendBounds : function(gSelection) {
  821. var legendBounds = gSelection.append("rect").attr("class", "legendBBox").attr("width", this._size[0]).attr("height", this._size[1]);
  822. if ((this._legendBorderColor)) {
  823. legendBounds.attr("stroke", rave.rgb(this._legendBorderColor).toString());
  824. }
  825. if ((this._legendBackgroundColor)) {
  826. legendBounds.style("fill", rave.rgb(this._legendBackgroundColor).toString());
  827. } else {
  828. legendBounds.style("fill-opacity", 0);
  829. }
  830. },
  831. /** @expose */
  832. getDataFromScale : function() {
  833. if (!this._scale) {
  834. return null;
  835. }
  836. var ticksData;
  837. if (this._scale.ticksInRange) {
  838. ticksData = this._scale.ticksInRange();
  839. }
  840. if (!ticksData || ticksData.length == 0) {
  841. if (this._scale.ticks) {
  842. ticksData = this._scale.ticks.apply(this._scale.ticks, this._scaleArguments);
  843. }
  844. }
  845. if (!ticksData || ticksData.length == 0) {
  846. ticksData = this._scale.domain();
  847. }
  848. return ticksData;
  849. },
  850. /** @expose */
  851. getData : function() {
  852. var ticksData = this._dataValues;
  853. if (!ticksData) {
  854. ticksData = this.getDataFromScale();
  855. }
  856. if (!ticksData || ticksData.length < this._minDataLen) {
  857. return null;
  858. }
  859. var ticksDataClone = [];
  860. for (var i = 0; i < ticksData.length; ++i) {
  861. ticksDataClone.push(ticksData[i]);
  862. }
  863. if (this._reverse) {
  864. ticksDataClone.reverse();
  865. }
  866. return ticksDataClone;
  867. },
  868. /**
  869. * Draws or redraws this legend into the specified selection of elements. The legend may be drawn into multiple elements simultaneously, but note that these legends would share the same backing data; typically, a legend is drawn into only one element at a time. This function will create its own subgroup and draw the legend into that, if that group exists already then all it will be removed with all its children and added anew.
  870. * @param (rave['internal']['Selector']) g a selection that holds the elements into which the legend is drawn. Typically a group element.
  871. */
  872. /** @expose */
  873. legend : function(g) {},
  874. /**
  875. * Creates an extra legend entry with the specified label. If there is an existing extra legend entry with the specified label, the old value is replaced. This is an example of how two extra entries can be added to the legend using the API: <p> legend.extraEntry("someLabel0").color("someColor").size(someSize).shape("someShape"); </p> <p> legend.extraEntry("someLabel1").color("someColor").size(someSize).shape("someShape"); </p>
  876. * @param (Object) label The label for the extra legend entry. Null and white spaces are not allowed.
  877. */
  878. /** @expose */
  879. extraEntry : function(label) {
  880. var ele = new com_ibm_rave_ext_legend_ExtraLegendEntry();
  881. if (label != null) {
  882. var extraEntryLabel = label.toString();
  883. if (extraEntryLabel.replace(new RegExp("\\s+","g"), "").length > 0) {
  884. this._extraLegendEntries.set(extraEntryLabel, ele);
  885. }
  886. }
  887. return ele;
  888. },
  889. /**
  890. * Clears all the extra legend entries.
  891. */
  892. /** @expose */
  893. clearExtraLegendEntries : function() {
  894. var extraEntryKeys = this._extraLegendEntries.keys();
  895. for (var __i_enFor0 = 0, __exp_enFor0 = extraEntryKeys, __len_enFor0 = __exp_enFor0.length;
  896. __i_enFor0 < __len_enFor0; ++__i_enFor0) {
  897. var key = __exp_enFor0[__i_enFor0];
  898. this._extraLegendEntries.remove(key);
  899. }
  900. },
  901. /**
  902. * When a legend component 'draws', it keeps track of how much space it used. If the legends orientation is VERTICAL_ORIENT, returned space is the width used. If the legends orientation is HORIZONTAL_ORIENT, returned space is the height used.
  903. * @return (double) space used (in pixels)
  904. */
  905. /** @expose */
  906. getUsedSize : function() {
  907. if (this._orient == "vertical") {
  908. return this._spaceUsed + this._legendInsets["left"] + this._legendInsets["right"] + 2;
  909. }
  910. return this._spaceUsed + this._legendInsets["top"] + this._legendInsets["bottom"] + 2;
  911. },
  912. /** @expose */
  913. minDataLen : function(a0) {
  914. var args = arguments;
  915. if (args.length == 0) {
  916. return this.minDataLen$0();
  917. }
  918. return this.minDataLen$1(a0);
  919. },
  920. /** @expose */
  921. scale : function(a0) {
  922. var args = arguments;
  923. if (args.length == 0) {
  924. return this.scale$1();
  925. }
  926. return this.scale$0(a0);
  927. },
  928. /** @expose */
  929. orient : function(a0) {
  930. var args = arguments;
  931. if (args.length == 0) {
  932. return this.orient$1();
  933. }
  934. return this.orient$0(a0);
  935. },
  936. /** @expose */
  937. title : function(a0) {
  938. var args = arguments;
  939. if (args.length == 0) {
  940. return this.title$0();
  941. }
  942. return this.title$1(a0);
  943. },
  944. /** @expose */
  945. size : function(a0) {
  946. var args = arguments;
  947. if (args.length == 0) {
  948. return this.size$0();
  949. }
  950. return this.size$1(a0);
  951. },
  952. /** @expose */
  953. scaleArguments : function(a0) {
  954. var args = arguments;
  955. if (args.length == 0) {
  956. return this.scaleArguments$1();
  957. }
  958. return this.scaleArguments$0.apply(this, args);
  959. },
  960. /** @expose */
  961. dataValues : function(a0) {
  962. var args = arguments;
  963. if (args.length == 0) {
  964. return this.dataValues$1();
  965. }
  966. return this.dataValues$0(a0);
  967. },
  968. /** @expose */
  969. labelFormat : function(a0) {
  970. var args = arguments;
  971. if (args.length == 0) {
  972. return this.labelFormat$2();
  973. }
  974. if (args.length == 1 && (a0 == null || typeof a0 === "string")) {
  975. return this.labelFormat$0(a0);
  976. }
  977. return this.labelFormat$1(a0);
  978. },
  979. /** @expose */
  980. labelPadding : function(a0) {
  981. var args = arguments;
  982. if (args.length == 0) {
  983. return this.labelPadding$1();
  984. }
  985. return this.labelPadding$0(a0);
  986. },
  987. /** @expose */
  988. borderColor : function(a0) {
  989. var args = arguments;
  990. if (args.length == 0) {
  991. return this.borderColor$0();
  992. }
  993. return this.borderColor$1(a0);
  994. },
  995. /** @expose */
  996. shapeBorderColor : function(a0) {
  997. var args = arguments;
  998. if (args.length == 0) {
  999. return this.shapeBorderColor$0();
  1000. }
  1001. return this.shapeBorderColor$1(a0);
  1002. },
  1003. /** @expose */
  1004. backgroundColor : function(a0) {
  1005. var args = arguments;
  1006. if (args.length == 0) {
  1007. return this.backgroundColor$0();
  1008. }
  1009. return this.backgroundColor$1(a0);
  1010. },
  1011. /** @expose */
  1012. titleAlignment : function(a0) {
  1013. var args = arguments;
  1014. if (args.length == 0) {
  1015. return this.titleAlignment$0();
  1016. }
  1017. return this.titleAlignment$1(a0);
  1018. },
  1019. /** @expose */
  1020. titleInsets : function(a0) {
  1021. var args = arguments;
  1022. if (args.length == 0) {
  1023. return this.titleInsets$0();
  1024. }
  1025. return this.titleInsets$1(a0);
  1026. },
  1027. /** @expose */
  1028. titleFill : function(a0) {
  1029. var args = arguments;
  1030. if (args.length == 0) {
  1031. return this.titleFill$0();
  1032. }
  1033. return this.titleFill$1(a0);
  1034. },
  1035. /** @expose */
  1036. titleFontSize : function(a0) {
  1037. var args = arguments;
  1038. if (args.length == 0) {
  1039. return this.titleFontSize$0();
  1040. }
  1041. return this.titleFontSize$1(a0);
  1042. },
  1043. /** @expose */
  1044. titleFontFamily : function(a0) {
  1045. var args = arguments;
  1046. if (args.length == 0) {
  1047. return this.titleFontFamily$0();
  1048. }
  1049. return this.titleFontFamily$1(a0);
  1050. },
  1051. /** @expose */
  1052. entryInsets : function(a0) {
  1053. var args = arguments;
  1054. if (args.length == 0) {
  1055. return this.entryInsets$0();
  1056. }
  1057. return this.entryInsets$1(a0);
  1058. },
  1059. /** @expose */
  1060. insets : function(a0) {
  1061. var args = arguments;
  1062. if (args.length == 0) {
  1063. return this.insets$0();
  1064. }
  1065. return this.insets$1(a0);
  1066. },
  1067. /** @expose */
  1068. reverse : function(a0) {
  1069. var args = arguments;
  1070. if (args.length == 0) {
  1071. return this.reverse$0();
  1072. }
  1073. return this.reverse$1(a0);
  1074. },
  1075. /** @expose */
  1076. labelTruncationText : function(a0) {
  1077. var args = arguments;
  1078. if (args.length == 0) {
  1079. return this.labelTruncationText$0();
  1080. }
  1081. return this.labelTruncationText$1(a0);
  1082. },
  1083. /** @expose */
  1084. truncationIndicator : function(a0) {
  1085. var args = arguments;
  1086. if (args.length == 0) {
  1087. return this.truncationIndicator$0();
  1088. }
  1089. return this.truncationIndicator$1(a0);
  1090. },
  1091. /** @expose */
  1092. addTruncationIndicator : function(a0, a1, a2, a3, a4, a5, a6) {
  1093. var args = arguments;
  1094. if (args.length == 5) {
  1095. return this.addTruncationIndicator$0(a0, a1, a2, a3, a4);
  1096. }
  1097. return this.addTruncationIndicator$1(a0, a1, a2, a3, a4, a5, a6);
  1098. },
  1099. /** @expose */
  1100. alignTitleHorizontally : function(a0, a1) {
  1101. var args = arguments;
  1102. if (args.length == 1) {
  1103. return this.alignTitleHorizontally$0(a0);
  1104. }
  1105. return this.alignTitleHorizontally$1(a0, a1);
  1106. }
  1107. });
  1108. com_ibm_rave_ext_legend_AbstractLegend.createDefaultInsets = function() {
  1109. var result = {};
  1110. result["top"] = 3;
  1111. result["left"] = 3;
  1112. result["bottom"] = 3;
  1113. result["right"] = 3;
  1114. return result;
  1115. };
  1116. /** @expose */
  1117. com_ibm_rave_ext_legend_AbstractLegend.EM_1 = "1em";
  1118. /** @expose */
  1119. com_ibm_rave_ext_legend_AbstractLegend.EM_07 = ".7em";
  1120. /** @expose */
  1121. com_ibm_rave_ext_legend_AbstractLegend.EM_035 = ".35em";
  1122. /** @expose */
  1123. com_ibm_rave_ext_legend_AbstractLegend.EM_0 = "0em";
  1124. /** @expose */
  1125. com_ibm_rave_ext_legend_AbstractLegend.HORIZONTAL_ORIENT = "horizontal";
  1126. /** @expose */
  1127. com_ibm_rave_ext_legend_AbstractLegend.VERTICAL_ORIENT = "vertical";
  1128. /** @expose */
  1129. com_ibm_rave_ext_legend_AbstractLegend.START_ALIGN = "start";
  1130. /** @expose */
  1131. com_ibm_rave_ext_legend_AbstractLegend.MIDDLE_ALIGN = "middle";
  1132. /** @expose */
  1133. com_ibm_rave_ext_legend_AbstractLegend.END_ALIGN = "end";
  1134. /** @expose */
  1135. com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_TRUNCATION_TEXT = "...";
  1136. /** @expose */
  1137. com_ibm_rave_ext_legend_AbstractLegend.FONT = "font";
  1138. /** @expose */
  1139. com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_LABEL_PADDING = 3.0;
  1140. /** @expose */
  1141. com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS_VALUE = 3;
  1142. /** @expose */
  1143. com_ibm_rave_ext_legend_AbstractLegend.MIN_TEXT_DIM = 4.0;
  1144. /** @expose */
  1145. com_ibm_rave_ext_legend_AbstractLegend.LINE_SPACING_RATIO = 1.0;
  1146. /** @expose */
  1147. com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_ORIENT = "vertical";
  1148. /** @expose */
  1149. com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_TITLE_ALIGN = "middle";
  1150. /** @expose */
  1151. com_ibm_rave_ext_legend_AbstractLegend.LEGEND_ENTRY_CLASS_SELECTOR = "." + "legendEntry";
  1152. /** @expose */
  1153. com_ibm_rave_ext_legend_AbstractLegend.LEGEND_GROUP_CLASS_SELECTOR = "." + "legendGroup";
  1154. /** @expose */
  1155. com_ibm_rave_ext_legend_AbstractLegend.LEGEND_SHAPE_CLASS_SELECTOR = "." + "legendShape";
  1156. /** @expose */
  1157. com_ibm_rave_ext_legend_AbstractLegend.LEGEND_TICK_LINE_CLASS_SELECTOR = "." + "legendTickLine";
  1158. /** @expose */
  1159. com_ibm_rave_ext_legend_AbstractLegend.LEGEND_LABEL_CLASS_SELECTOR = "." + "legendLabel";
  1160. /** @expose */
  1161. com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_TRUNCATION_SHAPE_SIZE = 20.0 * 20.0;
  1162. /** @expose */
  1163. com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_SCALE_ARGS = [5.0];
  1164. /** @expose */
  1165. com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_LEGEND_SIZE = [100, 100];
  1166. /** @expose */
  1167. com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS = com_ibm_rave_ext_legend_AbstractLegend.createDefaultInsets();
  1168. /** @expose */
  1169. com_ibm_rave_ext_legend_AbstractLegend._IDENTITY_FN = function(data, index, groupIndex) {
  1170. return ""+(data);
  1171. };
  1172. // $source: com/ibm/rave/ext/legend/ExtraLegendEntry
  1173. /************************************************************************
  1174. ** IBM Confidential
  1175. **
  1176. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  1177. **
  1178. ** (C) Copyright IBM Corp. 2017
  1179. **
  1180. ** The source code for this program is not published or otherwise divested of its trade secrets,
  1181. ** irrespective of what has been deposited with the U.S. Copyright Office.
  1182. ************************************************************************/
  1183. // GENERATED
  1184. var com_ibm_rave_ext_legend_ExtraLegendEntry = rave['internal']['Declare']({
  1185. //_color : null,
  1186. //_shape : null,
  1187. _size : 0,
  1188. _colorSet : false,
  1189. _sizeSet : false,
  1190. _shapeSet : false,
  1191. /** @expose */
  1192. constructor : function() {
  1193. this._color = null;
  1194. this._size = 0;
  1195. this._shape = null;
  1196. this._colorSet = false;
  1197. this._sizeSet = false;
  1198. this._shapeSet = false;
  1199. },
  1200. /**
  1201. * Sets the color for the extra legend entry.
  1202. * @param (String) color The color of the symbol for the legend entry.
  1203. */
  1204. color$0 : function(color) {
  1205. if (color != null) {
  1206. this._color = color;
  1207. this._colorSet = true;
  1208. }
  1209. return this;
  1210. },
  1211. /**
  1212. * Sets the size for the extra legend entry.
  1213. * @param (double) size The size (in square pixels) of the symbol for the legend entry.
  1214. */
  1215. size$0 : function(size) {
  1216. if (size >= 0) {
  1217. this._size = size;
  1218. this._sizeSet = true;
  1219. }
  1220. return this;
  1221. },
  1222. /**
  1223. * Sets the shape for the extra legend entry.
  1224. * @param (String) shape The shape of the symbol for the legend entry. Acceptable shapes are: "square", "circle", "triangle-up", "triangle-down", "triangle-left", "triangle-right", "diamond", "cross", "horizontal-rectangle", and "vertical-rectangle".
  1225. */
  1226. shape$0 : function(shape) {
  1227. if ((shape != null) && (shape == "square" || shape == "circle" || shape == "triangle-up" || shape == "triangle-down" || shape == "triangle-left" || shape == "triangle-right" || shape == "diamond" || shape == "cross" || shape == "horizontal-rectangle" || shape == "vertical-rectangle")) {
  1228. this._shape = shape;
  1229. this._shapeSet = true;
  1230. }
  1231. return this;
  1232. },
  1233. /**
  1234. * @return (String) The color of the symbol in the extra legend entry.
  1235. */
  1236. color$1 : function() {
  1237. return this._color;
  1238. },
  1239. /**
  1240. * @return (double) The size of the symbol in the extra legend entry.
  1241. */
  1242. size$1 : function() {
  1243. return this._size;
  1244. },
  1245. /**
  1246. * @return (String) The shape of the symbol in the extra legend entry.
  1247. */
  1248. shape$1 : function() {
  1249. return this._shape;
  1250. },
  1251. /**
  1252. * @return (boolean) Checks whether a color was explicitly set for the symbol of the extra legend entry.
  1253. */
  1254. /** @expose */
  1255. colorSet : function() {
  1256. return this._colorSet;
  1257. },
  1258. /**
  1259. * @return (boolean) Checks whether a size was explicitly set for the symbol of the extra legend entry.
  1260. */
  1261. /** @expose */
  1262. sizeSet : function() {
  1263. return this._sizeSet;
  1264. },
  1265. /**
  1266. * @return (boolean) Checks whether a shape was explicitly set for the symbol of the extra legend entry.
  1267. */
  1268. /** @expose */
  1269. shapeSet : function() {
  1270. return this._shapeSet;
  1271. },
  1272. /** @expose */
  1273. color : function(a0) {
  1274. var args = arguments;
  1275. if (args.length == 0) {
  1276. return this.color$1();
  1277. }
  1278. return this.color$0(a0);
  1279. },
  1280. /** @expose */
  1281. size : function(a0) {
  1282. var args = arguments;
  1283. if (args.length == 0) {
  1284. return this.size$1();
  1285. }
  1286. return this.size$0(a0);
  1287. },
  1288. /** @expose */
  1289. shape : function(a0) {
  1290. var args = arguments;
  1291. if (args.length == 0) {
  1292. return this.shape$1();
  1293. }
  1294. return this.shape$0(a0);
  1295. }
  1296. });
  1297. // $source: com/ibm/rave/ext/internal/legend/nativeImpl/Module
  1298. /************************************************************************
  1299. ** IBM Confidential
  1300. **
  1301. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  1302. **
  1303. ** (C) Copyright IBM Corp. 2015
  1304. **
  1305. ** The source code for this program is not published or otherwise divested of its trade secrets,
  1306. ** irrespective of what has been deposited with the U.S. Copyright Office.
  1307. ************************************************************************/
  1308. // @OnDemandLoad("rave-legends")
  1309. // Must be the first import
  1310. // @import ./ModuleHeader
  1311. // @import com/ibm/rave/ext/legend/RaveLegend
  1312. var com_ibm_rave_ext_text_internal_wrap_TextOperation = rave["internal"]["com_ibm_rave_ext_text_internal_wrap_TextOperation"],
  1313. com_ibm_rave_ext_text_internal_wrap_TextData = rave["internal"]["com_ibm_rave_ext_text_internal_wrap_TextData"],
  1314. com_ibm_rave_ext_text_internal_wrap_FontStyleStruct = rave["internal"]["com_ibm_rave_ext_text_internal_wrap_FontStyleStruct"];
  1315. // $source: com/ibm/rave/ext/legend/swatch/SwatchLegend
  1316. /************************************************************************
  1317. ** IBM Confidential
  1318. **
  1319. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  1320. **
  1321. ** (C) Copyright IBM Corp. 2017
  1322. **
  1323. ** The source code for this program is not published or otherwise divested of its trade secrets,
  1324. ** irrespective of what has been deposited with the U.S. Copyright Office.
  1325. ************************************************************************/
  1326. // GENERATED
  1327. //@import com/ibm/rave/ext/legend/AbstractLegend (loadtime) // superclass
  1328. //@import com/ibm/rave/ext/text/internal/wrap/TextOperation (runtime) // getOperation
  1329. //@import com/ibm/rave/ext/text/internal/wrap/FontStyleStruct (runtime) // new
  1330. /**
  1331. * A class that would generate and draw a swatch legend based on passed parameters
  1332. */
  1333. var com_ibm_rave_ext_legend_swatch_SwatchLegend = rave['internal']['Declare'](com_ibm_rave_ext_legend_AbstractLegend, {
  1334. //_shape : null,
  1335. //_swatchSize : null,
  1336. //_layoutMethod : null,
  1337. _wrapLabels : true,
  1338. _rows : 0,
  1339. _columns : 0,
  1340. constructor : function() {
  1341. this._layoutMethod = "grid";
  1342. {
  1343. this.minDataLen(1);
  1344. this.shape("square");
  1345. this.swatchSize(400.0);
  1346. }
  1347. },
  1348. /**
  1349. * Get the current swatch shape type assigned to this legend
  1350. * @return (Object) Shape string or shape generator i.e., Symbol.
  1351. * @see Symbol
  1352. */
  1353. shape$0 : function() {
  1354. return this._shape;
  1355. },
  1356. /**
  1357. * Sets the shape type to be used to draw legend swatchs. Could be either Symbol functor that generates the shape path to be drawn, or one of the following strings: <li>square</li> <li>circle</li> <li>triangle-up</li> <li>triangle-down</li> <li>diamond</li> <li>cross</li> <li>rectangle and horizontal-rectangle</li> <li>vertical-rectangle</li> <li>triangle-left</li> <li>triangle-right</li> Default swatch shape is square
  1358. * @param (Object) shape The shape to assign to this legend.
  1359. * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance.
  1360. */
  1361. shape$1 : function(shape) {
  1362. this._shape = (shape) ? shape : "square";
  1363. return this;
  1364. },
  1365. /**
  1366. * Get the value of the currently assigned area in pixels for the bounding box of legend swatchs shape. Default is 400 e.g. in case of a square shape, then it will be a box of 20x20 pixels. In case of a circle shape, the circle's diameter (bounding box side) will be equal to the squareroot of the area divided by pi.
  1367. * @return (Object) Legend entry shape area size object.
  1368. */
  1369. swatchSize$0 : function() {
  1370. return this._swatchSize;
  1371. },
  1372. /**
  1373. * Specify the value of the area (in pixels) of the bounding box of swatchs shape. Could be either a value functions that will be called for each swatch or a numeric value or a string that could be parsed into a numeric value
  1374. * @param (Object) size The value of area of swatch's bounding box.
  1375. * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance.
  1376. */
  1377. swatchSize$1 : function(size) {
  1378. this._swatchSize = size;
  1379. return this;
  1380. },
  1381. /**
  1382. * Returns whether legend's entry label is to be wrapped -if necessary- or not. Default is true
  1383. * @return (boolean) true if the label wrapping is allowed, false otherwise
  1384. */
  1385. wrapLabels$0 : function() {
  1386. return this._wrapLabels;
  1387. },
  1388. /**
  1389. * Enables or disables label wrapping for legend entries. Label wrapping could occur if there isn't enough width available to display the label text as one line and there is enough height to accommodate the newly added text lines. If wrapping is disabled or if there isn't enough height, the legend would truncate the label text instead.
  1390. * @param (boolean) wrapLabels a boolean value indicating whether to allow label wrapping or not
  1391. * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance
  1392. */
  1393. wrapLabels$1 : function(wrapLabels) {
  1394. this._wrapLabels = wrapLabels;
  1395. return this;
  1396. },
  1397. /**
  1398. * Sets the number of rows. If the legend orientation is horizontal, the layout will expand to have the given number of rows. If the legend orientation is vertical no more than this number of swatchs will be placed in any column. Passing a negative number means using the default value of zero This method takes a whole number or a string that could be parsed into a whole number The number of rows will also be impacted by the legend size as well.
  1399. * @param (Object) rows the number of rows
  1400. * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance
  1401. */
  1402. rows$0 : function(rows) {
  1403. this._rows = ~~ (rows);
  1404. return this;
  1405. },
  1406. /**
  1407. * Returns the number of rows. Default value is zero indicating that there is no limit on the number of rows, subject to available legend size
  1408. * @return (int) number of rows
  1409. */
  1410. rows$1 : function() {
  1411. return this._rows;
  1412. },
  1413. /**
  1414. * Sets the number of columns. If the legend orientation is vertical, the layout will expand to have the given number of columns. If the legend orientation is horizontal, no more than this number of swatchs will be placed in any row. Passing a negative number means using the default value of zero This method takes a whole number or a string that could be parsed into a whole number The number of columns will also be impacted by the legend size as well.
  1415. * @param (Object) columns number of columns
  1416. * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance
  1417. */
  1418. columns$0 : function(columns) {
  1419. this._columns = ~~ (columns);
  1420. return this;
  1421. },
  1422. /**
  1423. * Returns the number of columns. Default value is zero indicating that there is no limit on the number of columns, subject to available legend size
  1424. * @return (int) number of columns
  1425. */
  1426. columns$1 : function() {
  1427. return this._columns;
  1428. },
  1429. /**
  1430. * Returns layout method which controls the spacing of legend entries in the direction of legend orientation. Default is grid
  1431. * @return (String) layout method
  1432. */
  1433. layoutMethod$0 : function() {
  1434. return this._layoutMethod;
  1435. },
  1436. /**
  1437. * Sets layout method used by the legend, which controls the spacing of legend entries in the direction of legend orientation. It could be either "packed" of "grid". The method "grid" (the default) makes all legend entries use the same spacing as the largest entry so that the bounding box of each entry will have the same width and height, and also, it will try to layout entries in as many columns and rows as needed. The method "packed" makes each legend entry use its own size, which usually results in the legend entries occupying lesser space if entries vary in size, also, if the legend orientation is vertical it would restrict the number of columns to one, and if the legend orientation was horizontal, it would restrict the number of rows to one . These restrictions imposed by the "packed' method will apply regardless of the size available for the legend and regardless of the values of rows and columns properties on the legend. The "packed" method is usually used for size legend where entries have varying sizes since if they don't, then no space would be saved when laying out the entries and it would only result in restricting the count of column or row used to one. Default method used is "grid"
  1438. * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance
  1439. */
  1440. layoutMethod$1 : function(layoutMethod) {
  1441. if ("packed" == layoutMethod) {
  1442. this._layoutMethod = "packed";
  1443. } else {
  1444. this._layoutMethod = "grid";
  1445. }
  1446. return this;
  1447. },
  1448. getSwatchSizeFunction : function() {
  1449. var swatchSizeFn;
  1450. if (typeof this._swatchSize === "function") {
  1451. swatchSizeFn = this._swatchSize;
  1452. } else {
  1453. var swatchSize = + (this._swatchSize);
  1454. swatchSizeFn = function(data, index, groupIndex) {
  1455. return swatchSize;
  1456. };
  1457. }
  1458. return swatchSizeFn;
  1459. },
  1460. getShapeSymbol : function(swatchSizeFn) {
  1461. var shapeSymbol;
  1462. if (typeof this._shape === "function") {
  1463. shapeSymbol = (this._shape).size(swatchSizeFn);
  1464. } else {
  1465. shapeSymbol = rave.svg.symbol().size(swatchSizeFn).type(this._shape);
  1466. }
  1467. return shapeSymbol;
  1468. },
  1469. getLegendEntrySelectors : function(gSelection, swatchsData, shapeSymbol, labelFormat) {
  1470. var self = this;
  1471. var es = new com_ibm_rave_ext_legend_swatch_SwatchLegend.LegendEntrySelectors();
  1472. if (!(self._extraLegendEntries.empty())) {
  1473. var keys = self._extraLegendEntries.keys();
  1474. for (var i = 0; i < keys.length; ++i) {
  1475. if (!(swatchsData.indexOf(keys[i])> -1)) {
  1476. swatchsData.push(keys[i]);
  1477. }
  1478. }
  1479. }
  1480. es.legendEntry = gSelection.selectAll(".legendEntry").data(swatchsData).enter().append("g").attr("class", "legendEntry");
  1481. es.shape = es.legendEntry.append("path").attr("class", "legendShape").attr("d", function(data, index, groupIndex) {
  1482. var ele = self._extraLegendEntries.get((data));
  1483. if (ele) {
  1484. var extraSymbolSize = 0.0;
  1485. var extraSymbolShape = null;
  1486. if (ele.sizeSet()) {
  1487. extraSymbolSize = ele.size();
  1488. } else {
  1489. extraSymbolSize = (shapeSymbol.size().call(this, data, index, groupIndex));
  1490. ele.size(extraSymbolSize);
  1491. }
  1492. if (ele.shapeSet()) {
  1493. extraSymbolShape = ele.shape();
  1494. } else {
  1495. extraSymbolShape = shapeSymbol.type().call(this, data, index, groupIndex);
  1496. ele.shape(extraSymbolShape);
  1497. }
  1498. var extraLegendEntrySymbol = rave.svg.symbol().size(extraSymbolSize).type(extraSymbolShape);
  1499. return extraLegendEntrySymbol.call(this, data, index, groupIndex);
  1500. }
  1501. return shapeSymbol.call(this, data, index, groupIndex);
  1502. }).style("fill", function(data, index, groupIndex) {
  1503. var customColor = null;
  1504. var ele = self._extraLegendEntries.get((data));
  1505. customColor = self.scale().call(this, data, index, groupIndex);
  1506. if (ele) {
  1507. if (ele.colorSet()) {
  1508. return self._extraLegendEntries.get((data)).color();
  1509. }
  1510. ele.color((customColor));
  1511. }
  1512. return customColor;
  1513. });
  1514. es.text = es.legendEntry.append("text").attr("class", "legendLabel");
  1515. if (typeof labelFormat === "function") {
  1516. es.text.text(labelFormat);
  1517. } else {
  1518. es.text.text(labelFormat);
  1519. }
  1520. if ((this.shapeBorderColor())) {
  1521. es.shape.attr("stroke", rave.rgb(this.shapeBorderColor()).toString());
  1522. }
  1523. return es;
  1524. },
  1525. getLegendEntryBBoxes : function(es) {
  1526. var eb = new com_ibm_rave_ext_legend_swatch_SwatchLegend.LegendEntryBBoxes();
  1527. es.text.each(function(data, index, groupIndex) {
  1528. var labelBbox = this.getBBox();
  1529. eb.labelBboxes.push(labelBbox);
  1530. eb.labelTexts.push(this.rave_getText());
  1531. });
  1532. es.shape.each(function(data, index, groupIndex) {
  1533. eb.shapeBboxes.push(this.getBBox());
  1534. });
  1535. return eb;
  1536. },
  1537. createLayout : function(isHorizontal, availableWidth, availableHeight) {
  1538. var layout = rave.layout.extension("fill");
  1539. layout.cellSize(com_ibm_rave_ext_legend_swatch_SwatchLegend._NULL_SETVALUE_FN).direction(isHorizontal ? "row" : "column").size([availableWidth, availableHeight]).method(this._layoutMethod).valign("start").halign("start");
  1540. if ("packed" == this._layoutMethod) {
  1541. if (isHorizontal) {
  1542. layout.rows(1);
  1543. } else {
  1544. layout.columns(1);
  1545. }
  1546. } else {
  1547. if (this._rows > 0) {
  1548. layout.rows(this._rows);
  1549. }
  1550. if (this._columns > 0) {
  1551. layout.columns(this._columns);
  1552. }
  1553. }
  1554. return layout;
  1555. },
  1556. buildFillNodes : function(swatchPadding, eb) {
  1557. var entryInsets = this.entryInsets();
  1558. var nodes = [];
  1559. for (var i = 0; i < eb.shapeBboxes.length; ++i) {
  1560. var fillNode = {};
  1561. var shapeBbox = eb.shapeBboxes[i];
  1562. var labelBbox = eb.labelBboxes[i];
  1563. fillNode["height"] = Math.max(shapeBbox.height, labelBbox.height) + (entryInsets["top"] + entryInsets["bottom"]);
  1564. fillNode["width"] = shapeBbox.width + labelBbox.width + entryInsets["left"] + entryInsets["right"] + swatchPadding;
  1565. fillNode["data"] = i;
  1566. nodes.push(fillNode);
  1567. }
  1568. return nodes;
  1569. },
  1570. buildGridDescrs : function(isHorizontal, eb, swatchPadding, availableWidth, availableHeight) {
  1571. var entryInsets = this.entryInsets();
  1572. var numEntries = eb.shapeBboxes.length;
  1573. var fillNodes = [];
  1574. for (var i = 0; i < numEntries; ++i) {
  1575. var fillNode = {};
  1576. var shapeBbox = eb.shapeBboxes[i];
  1577. fillNode["height"] = entryInsets["top"] + entryInsets["bottom"];
  1578. fillNode["width"] = shapeBbox.width + entryInsets["left"] + entryInsets["right"] + swatchPadding;
  1579. fillNode["data"] = i;
  1580. fillNodes.push(fillNode);
  1581. }
  1582. var maxRows = numEntries;
  1583. var maxColumns = numEntries;
  1584. var packed = "packed" == this._layoutMethod;
  1585. if (packed) {
  1586. if (isHorizontal) {
  1587. maxRows = 1;
  1588. } else {
  1589. maxColumns = 1;
  1590. }
  1591. } else {
  1592. if (this._rows > 0) {
  1593. maxRows = this._rows;
  1594. }
  1595. if (this._columns > 0) {
  1596. maxColumns = this._columns;
  1597. }
  1598. }
  1599. if (isHorizontal) {
  1600. if (maxColumns > 1) {
  1601. var calculatedMaxCol = maxColumns;
  1602. var totWidth = 0;
  1603. var firstLabelBboxHeight = eb.labelBboxes[0].height;
  1604. for (var i = 0; i < numEntries; ++i) {
  1605. var fillNode = fillNodes[i];
  1606. totWidth += fillNode["width"] + firstLabelBboxHeight;
  1607. if (availableWidth < totWidth) {
  1608. calculatedMaxCol = i;
  1609. break;
  1610. }
  1611. }
  1612. maxColumns = Math.min(maxColumns, calculatedMaxCol);
  1613. }
  1614. } else {
  1615. if (maxRows > 1) {
  1616. var calculatedMaxRow = maxRows;
  1617. var totHeight = 0;
  1618. for (var i = 0; i < numEntries; ++i) {
  1619. var fillNode = fillNodes[i];
  1620. var shapeBbox = eb.shapeBboxes[i];
  1621. var labelBbox = eb.labelBboxes[i];
  1622. totHeight += fillNode["height"] + Math.max(labelBbox.height, shapeBbox.height);
  1623. if (availableHeight < totHeight) {
  1624. calculatedMaxRow = i;
  1625. break;
  1626. }
  1627. }
  1628. maxRows = Math.min(maxRows, calculatedMaxRow);
  1629. }
  1630. }
  1631. var maxNumNodes = Math.min(numEntries, (maxRows * maxColumns));
  1632. var maxIteration = (isHorizontal) ? maxColumns : maxRows;
  1633. var crl;
  1634. var gridDescrs = [];
  1635. var lastSeenNumColumns = -1;
  1636. var lastSeenNumRows = -1;
  1637. var largestSeenFailureIndex = 0;
  1638. var numColumns;
  1639. var numRows;
  1640. for (var i = maxIteration; i > 0; --i) {
  1641. if (isHorizontal) {
  1642. numColumns = i;
  1643. numRows = Math.ceil(maxNumNodes / numColumns);
  1644. } else {
  1645. numRows = i;
  1646. numColumns = Math.ceil(maxNumNodes / numRows);
  1647. }
  1648. if (numColumns <= maxColumns && numRows <= maxRows) {
  1649. numColumns = this.getMaxColumn(isHorizontal, maxNumNodes, numColumns, numRows);
  1650. numRows = this.getMaxRow(isHorizontal, maxNumNodes, numColumns, numRows);
  1651. if (numColumns != lastSeenNumColumns || numRows != lastSeenNumRows) {
  1652. crl = this.buildColumnRowLists(isHorizontal, numColumns, numRows, fillNodes, maxNumNodes, eb);
  1653. lastSeenNumColumns = numColumns;
  1654. lastSeenNumRows = numRows;
  1655. var cellHeight = availableHeight / numRows;
  1656. var cellWidth = availableWidth / numColumns;
  1657. var gridDescr = this.createGridDescr(numColumns, numRows, cellHeight, cellWidth, eb, fillNodes, maxNumNodes, crl.columnListShapes, crl.rowListShapes);
  1658. if (packed) {
  1659. gridDescrs.push(gridDescr);
  1660. } else if (maxNumNodes > largestSeenFailureIndex) {
  1661. if (gridDescr.firstFailureIndex > largestSeenFailureIndex) {
  1662. largestSeenFailureIndex = gridDescr.firstFailureIndex;
  1663. }
  1664. if (gridDescr.firstFailureIndex < maxNumNodes) {
  1665. var rowIndex = this.determineRow(isHorizontal, gridDescr.firstFailureIndex, gridDescr.numColumns, gridDescr.numRows);
  1666. var colIndex = this.determineColumn(isHorizontal, gridDescr.firstFailureIndex, gridDescr.numColumns, gridDescr.numRows);
  1667. var columnListIndex = crl.columnListShapes[colIndex];
  1668. var labelBbox = eb.labelBboxes[columnListIndex];
  1669. var colFillNode = fillNodes[columnListIndex];
  1670. var minCellWidth = colFillNode["width"] + labelBbox.height;
  1671. var rowListIndex = crl.rowListShapes[rowIndex];
  1672. labelBbox = eb.labelBboxes[rowListIndex];
  1673. var shapeBbox = eb.shapeBboxes[rowListIndex];
  1674. var rowFillNode = fillNodes[rowListIndex];
  1675. var minCellHeight = rowFillNode["height"] + Math.max(labelBbox.height, shapeBbox.height);
  1676. var gridDescr2 = this.adjustFailedGridDescr(gridDescr, fillNodes, maxNumNodes, isHorizontal, eb, availableWidth, availableHeight, minCellWidth, minCellHeight, largestSeenFailureIndex);
  1677. if (gridDescr2) {
  1678. gridDescr = gridDescr2;
  1679. if (gridDescr.firstFailureIndex > largestSeenFailureIndex) {
  1680. largestSeenFailureIndex = gridDescr.firstFailureIndex;
  1681. }
  1682. }
  1683. }
  1684. if (gridDescr.firstFailureIndex > 0 && gridDescr.firstFailureIndex >= largestSeenFailureIndex) {
  1685. gridDescrs.push(gridDescr);
  1686. }
  1687. } else if (maxNumNodes == gridDescr.firstFailureIndex) {
  1688. gridDescrs.push(gridDescr);
  1689. }
  1690. }
  1691. }
  1692. }
  1693. return gridDescrs;
  1694. },
  1695. getMaxColumn : function(isHorizontal, numNodes, numCols, numRows) {
  1696. if (isHorizontal) {
  1697. if (numNodes >= numCols) {
  1698. return numCols;
  1699. } else {
  1700. return numNodes;
  1701. }
  1702. }
  1703. return Math.ceil(numNodes / numRows);
  1704. },
  1705. getMaxRow : function(isHorizontal, numNodes, numCols, numRows) {
  1706. if (isHorizontal) {
  1707. return Math.ceil(numNodes / numCols);
  1708. }
  1709. if (numNodes >= numRows) {
  1710. return numRows;
  1711. } else {
  1712. return numNodes;
  1713. }
  1714. },
  1715. adjustFailedGridDescr : function(gridDescr, fillNodes, numNodes, isHorizontal, eb, availableWidth, availableHeight, minCellWidth, minCellHeight, largestSeenFailureIndex) {
  1716. var _fillNodes = fillNodes;
  1717. var bestGridDescr;
  1718. var lastSeenCellWidth = gridDescr.cellWidth;
  1719. var lastSeenCellHeight = gridDescr.cellHeight;
  1720. var increaseWidth = lastSeenCellWidth < minCellWidth;
  1721. var increaseHeight = lastSeenCellHeight < minCellHeight;
  1722. if (increaseWidth && increaseHeight) {
  1723. return null;
  1724. }
  1725. var minNodeCount = Math.max(2, largestSeenFailureIndex);
  1726. var _numNodes = numNodes;
  1727. var numRowCol;
  1728. var availableLength;
  1729. var lastSeenlength;
  1730. var minIncrease;
  1731. if (isHorizontal) {
  1732. if (increaseHeight) {
  1733. numRowCol = gridDescr.numColumns;
  1734. availableLength = availableHeight;
  1735. lastSeenlength = lastSeenCellHeight;
  1736. minIncrease = Math.max(1, minCellHeight - lastSeenCellHeight);
  1737. } else {
  1738. numRowCol = 1;
  1739. availableLength = availableWidth;
  1740. lastSeenlength = lastSeenCellWidth;
  1741. minIncrease = Math.max(1, minCellWidth - lastSeenCellWidth);
  1742. }
  1743. } else {
  1744. if (increaseWidth) {
  1745. numRowCol = gridDescr.numRows;
  1746. availableLength = availableWidth;
  1747. lastSeenlength = lastSeenCellWidth;
  1748. minIncrease = Math.max(1, minCellWidth - lastSeenCellWidth);
  1749. } else {
  1750. numRowCol = 1;
  1751. availableLength = availableHeight;
  1752. lastSeenlength = lastSeenCellHeight;
  1753. minIncrease = Math.max(1, minCellHeight - lastSeenCellHeight);
  1754. }
  1755. }
  1756. _numNodes = Math.floor(availableLength / (lastSeenlength + minIncrease)) * numRowCol;
  1757. minIncrease = 1;
  1758. while (_numNodes >= minNodeCount) {
  1759. var numColumns = this.getMaxColumn(isHorizontal, _numNodes, gridDescr.numColumns, gridDescr.numRows);
  1760. var numRows = this.getMaxRow(isHorizontal, _numNodes, gridDescr.numColumns, gridDescr.numRows);
  1761. if (numRows != gridDescr.numRows || numColumns != gridDescr.numColumns) {
  1762. if ((!bestGridDescr) || (numRows != bestGridDescr.numRows || numColumns != bestGridDescr.numColumns)) {
  1763. var cellHeight = availableHeight / numRows;
  1764. var cellWidth = availableWidth / numColumns;
  1765. if ((cellHeight - lastSeenCellHeight) >= minIncrease || (cellWidth - lastSeenCellWidth) >= minIncrease) {
  1766. lastSeenCellHeight = cellHeight;
  1767. lastSeenCellWidth = cellWidth;
  1768. lastSeenlength = (increaseHeight) ? lastSeenCellHeight : lastSeenCellWidth;
  1769. if (cellHeight >= minCellHeight && cellWidth >= minCellWidth) {
  1770. var crl = this.buildColumnRowLists(isHorizontal, gridDescr.numColumns, gridDescr.numRows, _fillNodes, _numNodes, eb);
  1771. var gridDescr2 = this.createGridDescr(gridDescr.numColumns, gridDescr.numRows, cellHeight, cellWidth, eb, _fillNodes, _numNodes, crl.columnListShapes, crl.rowListShapes);
  1772. if (gridDescr2.firstFailureIndex >= largestSeenFailureIndex) {
  1773. if (!bestGridDescr || bestGridDescr.firstFailureIndex < gridDescr2.firstFailureIndex) {
  1774. bestGridDescr = gridDescr2;
  1775. for (var j = crl.rowListShapes.length; j < gridDescr.numRows; ++j) {
  1776. bestGridDescr.heightAvailableForTextPerRow.push(4.0);
  1777. }
  1778. for (var j = crl.columnListShapes.length; j < gridDescr.numColumns; ++j) {
  1779. bestGridDescr.widthAvailableForTextPerColumn.push(4.0);
  1780. }
  1781. if (bestGridDescr.firstFailureIndex == _numNodes) {
  1782. return bestGridDescr;
  1783. } else if (bestGridDescr.firstFailureIndex > minNodeCount) {
  1784. minNodeCount = bestGridDescr.firstFailureIndex;
  1785. }
  1786. }
  1787. }
  1788. }
  1789. }
  1790. }
  1791. }
  1792. _numNodes = Math.floor(availableLength / (lastSeenlength + minIncrease)) * numRowCol;
  1793. }
  1794. return bestGridDescr;
  1795. },
  1796. createGridDescr : function(numColumns, numRows, cellHeight, cellWidth, eb, fillNodes, nodeCount, columnListShapes, rowListShapes) {
  1797. var widthAvailableForTextPerColumn = [];
  1798. var heightAvailableForTextPerRow = [];
  1799. var firstFailureIndex = nodeCount;
  1800. for (var j = 0; j < columnListShapes.length; ++j) {
  1801. var columnListIndex = columnListShapes[j];
  1802. var labelBbox = eb.labelBboxes[columnListIndex];
  1803. var colFillNode = fillNodes[columnListIndex];
  1804. var widthAvailableForText = cellWidth - colFillNode["width"];
  1805. if (widthAvailableForText < labelBbox.height) {
  1806. if (columnListIndex < firstFailureIndex) {
  1807. firstFailureIndex = columnListIndex;
  1808. }
  1809. }
  1810. widthAvailableForTextPerColumn.push((widthAvailableForText > 4.0) ? widthAvailableForText : 4.0);
  1811. }
  1812. for (var k = 0; k < rowListShapes.length; ++k) {
  1813. var rowListIndex = rowListShapes[k];
  1814. var shapeBbox = eb.shapeBboxes[rowListIndex];
  1815. var labelBbox = eb.labelBboxes[rowListIndex];
  1816. var rowFillNode = fillNodes[rowListIndex];
  1817. var heightAvailableForText = cellHeight - rowFillNode["height"];
  1818. if (heightAvailableForText < Math.max(labelBbox.height, shapeBbox.height)) {
  1819. if (rowListIndex < firstFailureIndex) {
  1820. firstFailureIndex = rowListIndex;
  1821. }
  1822. }
  1823. heightAvailableForTextPerRow.push((heightAvailableForText > 4.0) ? heightAvailableForText : 4.0);
  1824. }
  1825. return new com_ibm_rave_ext_legend_swatch_SwatchLegend.GridDescr(numColumns, numRows, columnListShapes.length, rowListShapes.length, firstFailureIndex, cellWidth, cellHeight, widthAvailableForTextPerColumn, heightAvailableForTextPerRow);
  1826. },
  1827. applyTextWrapping : function(isHorizontal, textFlow, eb, es, swatchPadding, availableWidth, availableHeight) {
  1828. var gridDescrs = this.buildGridDescrs(isHorizontal, eb, swatchPadding, availableWidth, availableHeight);
  1829. if (gridDescrs.length > 0) {
  1830. if (gridDescrs.length > 1) {
  1831. gridDescrs.sort(function(obj1, obj2) {
  1832. var result = obj2.firstFailureIndex - obj1.firstFailureIndex;
  1833. if (result == 0) {
  1834. if (isHorizontal) {
  1835. return obj2.numColumnsUsed - obj1.numColumnsUsed;
  1836. } else {
  1837. return obj2.numRowsUsed - obj1.numRowsUsed;
  1838. }
  1839. }
  1840. return result;
  1841. });
  1842. }
  1843. var text_operation = com_ibm_rave_ext_text_internal_wrap_TextOperation.getOperation((this._wrapLabels) ? 1 : 0, this.labelTruncationText());
  1844. text_operation.font(com_ibm_rave_ext_legend_swatch_SwatchLegend.createFontStruct(es.text.node().rave_getComputedStyles()));
  1845. text_operation.em(1.0);
  1846. var bestFailedResult = null;
  1847. var bestSuccessResult = null;
  1848. var numEntries = eb.shapeBboxes.length;
  1849. var success;
  1850. var noTruncation;
  1851. for (var i = 0; i < gridDescrs.length; ++i) {
  1852. success = true;
  1853. noTruncation = 0;
  1854. var gridDescr = gridDescrs[i];
  1855. if (bestFailedResult) {
  1856. if (gridDescr.firstFailureIndex < bestFailedResult.gridDescr.firstFailureIndex) {
  1857. continue;
  1858. }
  1859. if (gridDescr.cellHeight == bestFailedResult.gridDescr.cellHeight && gridDescr.cellWidth == bestFailedResult.gridDescr.cellWidth) {
  1860. continue;
  1861. }
  1862. }
  1863. var j;
  1864. for (j = 0; j < gridDescr.firstFailureIndex; ++j) {
  1865. var labelBbox = eb.labelBboxes[j];
  1866. var rowIndex = this.determineRow(isHorizontal, j, gridDescr.numColumns, gridDescr.numRows);
  1867. var colIndex = this.determineColumn(isHorizontal, j, gridDescr.numColumns, gridDescr.numRows);
  1868. var width = (colIndex < gridDescr.widthAvailableForTextPerColumn.length) ? gridDescr.widthAvailableForTextPerColumn[colIndex] : 4.0;
  1869. var height = (rowIndex < gridDescr.heightAvailableForTextPerRow.length) ? gridDescr.heightAvailableForTextPerRow[rowIndex] : 4.0;
  1870. if (width < labelBbox.height || height < labelBbox.height) {
  1871. success = false;
  1872. break;
  1873. }
  1874. text_operation.size(width, height);
  1875. text_operation.fontSize(labelBbox.height);
  1876. var text = eb.labelTexts[j];
  1877. if (text.length === 0) {
  1878. noTruncation++;
  1879. break;
  1880. }
  1881. text_operation.text(text);
  1882. var result = text_operation();
  1883. if (result.lines.length == 0 || result.clipped || result.tooTall || result.truncated) {
  1884. success = false;
  1885. if (result.lines.length == 0) {
  1886. break;
  1887. }
  1888. } else {
  1889. noTruncation++;
  1890. }
  1891. }
  1892. if (success && gridDescr.firstFailureIndex == numEntries) {
  1893. bestSuccessResult = new com_ibm_rave_ext_legend_swatch_SwatchLegend.TextResult(numEntries, noTruncation, gridDescr);
  1894. break;
  1895. } else {
  1896. if (!bestFailedResult || (gridDescr.firstFailureIndex > bestFailedResult.gridDescr.firstFailureIndex) || (gridDescr.firstFailureIndex == bestFailedResult.gridDescr.firstFailureIndex && j > bestFailedResult.entriesCount) || (gridDescr.firstFailureIndex == bestFailedResult.gridDescr.firstFailureIndex && j == bestFailedResult.entriesCount && noTruncation > bestFailedResult.noTruncation)) {
  1897. bestFailedResult = new com_ibm_rave_ext_legend_swatch_SwatchLegend.TextResult(j, noTruncation, gridDescr);
  1898. }
  1899. }
  1900. }
  1901. var textResult = (bestSuccessResult) ? bestSuccessResult : bestFailedResult;
  1902. if (textResult) {
  1903. textFlow.wrap(this._wrapLabels);
  1904. if (textResult.entriesCount > 0) {
  1905. var self = this;
  1906. es.text.each(function(data, index, groupIndex) {
  1907. if (index < textResult.entriesCount) {
  1908. var rowIndex = self.determineRow(isHorizontal, index, textResult.gridDescr.numColumns, textResult.gridDescr.numRows);
  1909. var colIndex = self.determineColumn(isHorizontal, index, textResult.gridDescr.numColumns, textResult.gridDescr.numRows);
  1910. var width = (colIndex < textResult.gridDescr.widthAvailableForTextPerColumn.length) ? textResult.gridDescr.widthAvailableForTextPerColumn[colIndex] : 4.0;
  1911. var height = (rowIndex < textResult.gridDescr.heightAvailableForTextPerRow.length) ? textResult.gridDescr.heightAvailableForTextPerRow[rowIndex] : 4.0;
  1912. textFlow.extent(~~width, ~~height);
  1913. textFlow.flow(rave.select(this));
  1914. var text = this.rave_getText();
  1915. var labelBbox = this.getBBox();
  1916. eb.labelBboxes[index] = labelBbox;
  1917. eb.labelTexts[index] = text;
  1918. }
  1919. });
  1920. }
  1921. }
  1922. return textResult;
  1923. }
  1924. return null;
  1925. },
  1926. layoutLegendEntries : function(isHorizontal, textFlow, eb, es, swatchPadding, availableWidth, availableHeight) {
  1927. var textResult = this.applyTextWrapping(isHorizontal, textFlow, eb, es, swatchPadding, availableWidth, availableHeight);
  1928. var lr = new com_ibm_rave_ext_legend_swatch_SwatchLegend.LayoutResults();
  1929. lr.textResult = textResult;
  1930. lr.layout = this.createLayout(isHorizontal, availableWidth, availableHeight);
  1931. lr.nodes = this.buildFillNodes(swatchPadding, eb);
  1932. var firstFailureIndex = lr.nodes.length;
  1933. var entrySpaceUsed = 0;
  1934. if (textResult && !("packed" == this._layoutMethod)) {
  1935. var entryInsets = this.entryInsets();
  1936. var isVertical = this.orient() == "vertical";
  1937. var entriesCount = textResult.entriesCount;
  1938. firstFailureIndex = textResult.gridDescr.firstFailureIndex;
  1939. var largestWidth = -1;
  1940. var largestHeight = -1;
  1941. for (var i = 0; i < entriesCount; ++i) {
  1942. var node = lr.nodes[i];
  1943. if (node["width"] > largestWidth) {
  1944. largestWidth = node["width"];
  1945. if (isVertical) {
  1946. entrySpaceUsed = largestWidth;
  1947. }
  1948. }
  1949. if (node["height"] > largestHeight) {
  1950. largestHeight = node["height"];
  1951. if (!isVertical) {
  1952. entrySpaceUsed = largestHeight;
  1953. }
  1954. }
  1955. }
  1956. if (isVertical) {
  1957. entrySpaceUsed *= lr.textResult.gridDescr.numColumnsUsed;
  1958. entrySpaceUsed += (entryInsets["left"] + entryInsets["right"]);
  1959. if (entrySpaceUsed > this._spaceUsed) {
  1960. this._spaceUsed = entrySpaceUsed;
  1961. }
  1962. } else {
  1963. entrySpaceUsed *= lr.textResult.gridDescr.numRowsUsed;
  1964. entrySpaceUsed += (entryInsets["top"] + entryInsets["bottom"]);
  1965. this._spaceUsed += entrySpaceUsed;
  1966. }
  1967. if (textResult.entriesCount == lr.nodes.length && firstFailureIndex == lr.nodes.length) {
  1968. if (textResult.gridDescr.cellHeight >= largestHeight && textResult.gridDescr.cellWidth >= largestWidth) {
  1969. lr.layout.rows(lr.textResult.gridDescr.numRowsUsed);
  1970. lr.layout.columns(lr.textResult.gridDescr.numColumnsUsed);
  1971. }
  1972. }
  1973. }
  1974. lr.elements = lr.layout(lr.nodes);
  1975. lr.numCols = lr.layout.numberOfHorizontalCells();
  1976. lr.numRows = lr.layout.numberOfVerticalCells();
  1977. if (firstFailureIndex != lr.nodes.length) {
  1978. if (lr.elements.length < firstFailureIndex && !("packed" == this._layoutMethod)) {
  1979. var elements = lr.layout(lr.nodes.slice(0, firstFailureIndex));
  1980. if (elements.length > lr.elements.length) {
  1981. lr.elements = elements;
  1982. lr.numCols = lr.layout.numberOfHorizontalCells();
  1983. lr.numRows = lr.layout.numberOfVerticalCells();
  1984. }
  1985. }
  1986. }
  1987. lr.crl = this.buildColumnRowLists(isHorizontal, lr.numCols, lr.numRows, lr.elements, lr.elements.length, eb);
  1988. return lr;
  1989. },
  1990. buildColumnRowLists : function(isHorizontal, numCols, numRows, fillNodes, nodeCount, eb) {
  1991. var crl = new com_ibm_rave_ext_legend_swatch_SwatchLegend.ColumnRowLists();
  1992. for (var i = 0; i < nodeCount; ++i) {
  1993. var node = fillNodes[i];
  1994. var currentNodeIndex = node["data"];
  1995. var currentColumnNumber = this.determineColumn(isHorizontal, currentNodeIndex, numCols, numRows);
  1996. if (currentColumnNumber < crl.columnListShapes.length) {
  1997. var curColIndex = crl.columnListShapes[currentColumnNumber];
  1998. var currentShape = eb.shapeBboxes[currentNodeIndex];
  1999. var curColShape = eb.shapeBboxes[curColIndex];
  2000. if ((currentShape.width > curColShape.width)) {
  2001. crl.columnListShapes[currentColumnNumber] = currentNodeIndex;
  2002. }
  2003. } else {
  2004. crl.columnListShapes[currentColumnNumber] = currentNodeIndex;
  2005. }
  2006. var currentRowNumber = this.determineRow(isHorizontal, currentNodeIndex, numCols, numRows);
  2007. if (currentRowNumber < crl.rowListShapes.length) {
  2008. var curRowIndex = crl.rowListShapes[currentRowNumber];
  2009. var currentShape = eb.shapeBboxes[currentNodeIndex];
  2010. var curRowShape = eb.shapeBboxes[curRowIndex];
  2011. if ((currentShape.height > curRowShape.height)) {
  2012. crl.rowListShapes[currentRowNumber] = currentNodeIndex;
  2013. }
  2014. } else {
  2015. crl.rowListShapes[currentRowNumber] = currentNodeIndex;
  2016. }
  2017. }
  2018. return crl;
  2019. },
  2020. handleFailedLayout : function(isHorizontal, gSelection, lr, es, eb, swatchsData, availableWidth, availableHeight, titleVerticalShift, textFlow) {
  2021. var removedFillNode;
  2022. if (lr.elements.length > 0) {
  2023. removedFillNode = lr.elements.pop();
  2024. }
  2025. if (lr.elements.length == 0 || !removedFillNode) {
  2026. gSelection.selectAll(".legendEntry").remove();
  2027. this.addTruncationIndicator(gSelection, titleVerticalShift, availableWidth, availableHeight, textFlow);
  2028. return false;
  2029. }
  2030. var newSwatchsData = [];
  2031. for (var i = 0; i < lr.elements.length; ++i) {
  2032. newSwatchsData[i] = swatchsData[i];
  2033. }
  2034. es.legendEntry = gSelection.selectAll(".legendEntry").data(newSwatchsData);
  2035. es.legendEntry.exit().remove();
  2036. es.shape = es.legendEntry.select("path");
  2037. es.text = es.legendEntry.select("text");
  2038. lr.crl = this.buildColumnRowLists(isHorizontal, lr.numCols, lr.numRows, lr.elements, lr.elements.length, eb);
  2039. lr.numCols = lr.crl.columnListShapes.length;
  2040. lr.numRows = lr.crl.rowListShapes.length;
  2041. var truncationSelector = gSelection.append("g").attr("class", "legendTruncationEntry");
  2042. var removedFillNodeIndex = lr.elements.length;
  2043. var rowVal = this.determineRow(isHorizontal, removedFillNodeIndex, lr.numCols, lr.numRows);
  2044. var width = availableWidth - removedFillNode["x"];
  2045. var height = availableHeight - removedFillNode["y"];
  2046. var midHorizontalPoint = (removedFillNode["x"] + this.entryInsets()["left"] + this.insets()["left"]) + (width / 2.0);
  2047. var yShift;
  2048. if (rowVal == 0 || rowVal == lr.numRows - 1) {
  2049. yShift = removedFillNode["height"] - this.entryInsets()["bottom"];
  2050. } else {
  2051. yShift = removedFillNode["height"] - this.entryInsets()["bottom"] - this.entryInsets()["top"];
  2052. }
  2053. this.addTruncationIndicator(truncationSelector, midHorizontalPoint, (removedFillNode["y"] + titleVerticalShift - this.insets()["bottom"] + (yShift / 2.0)), width, height, textFlow, true);
  2054. return true;
  2055. },
  2056. alignLabelsShapes : function(isHorizontal, eb, es, lr, swatchPadding) {
  2057. var self = this;
  2058. es.shape.attr("transform", function(data, index, groupIndex) {
  2059. var val = self.determineColumn(isHorizontal, index, lr.numCols, lr.numRows);
  2060. var shapeBbox = eb.shapeBboxes[lr.crl.columnListShapes[val]];
  2061. return "translate(" + (shapeBbox.width / 2.0) + ",0)";
  2062. });
  2063. es.text.each(function(data, index, groupIndex) {
  2064. var textSelection = rave.select(this);
  2065. var val = self.determineColumn(isHorizontal, index, lr.numCols, lr.numRows);
  2066. var shapeBbox = eb.shapeBboxes[lr.crl.columnListShapes[val]];
  2067. var x = swatchPadding + shapeBbox.width;
  2068. textSelection.attr("x", x).attr("text-anchor", "start").attr("dy", self.getTextDyPlacement(this));
  2069. textSelection.selectAll("tspan").attr("x", x).attr("width", null);
  2070. textSelection.select("tspan").attr("x", null).attr("dy", null);
  2071. });
  2072. },
  2073. buildRowListFillNodes : function(isHorizontal, numCols, numRows, fillNodes) {
  2074. var rowListFillNodes = [];
  2075. for (var i = 0; i < fillNodes.length; ++i) {
  2076. var node = fillNodes[i];
  2077. var currentNodeIndex = node["data"];
  2078. var currentRowNumber = this.determineRow(isHorizontal, currentNodeIndex, numCols, numRows);
  2079. if (currentRowNumber < rowListFillNodes.length) {
  2080. var curRowIndex = rowListFillNodes[currentRowNumber];
  2081. var curRowNode = fillNodes[curRowIndex];
  2082. if (node["height"] > curRowNode["height"]) {
  2083. rowListFillNodes[currentRowNumber] = currentNodeIndex;
  2084. }
  2085. } else {
  2086. rowListFillNodes[currentRowNumber] = currentNodeIndex;
  2087. }
  2088. }
  2089. return rowListFillNodes;
  2090. },
  2091. transformShapes : function(isHorizontal, es, lr, titleVerticalShift) {
  2092. var self = this;
  2093. var entryInsets = this.entryInsets();
  2094. var legendInsets = this.insets();
  2095. var rowListFillNodes = this.buildRowListFillNodes(isHorizontal, lr.numCols, lr.numRows, lr.elements);
  2096. es.legendEntry.attr("transform", function(data, index, groupIndex) {
  2097. var fillNode = lr.elements[index];
  2098. var val = self.determineRow(isHorizontal, index, lr.numCols, lr.numRows);
  2099. var nodeHeight = lr.elements[rowListFillNodes[val]]["height"];
  2100. var height = (nodeHeight - entryInsets["bottom"] - entryInsets["top"]);
  2101. var x = (fillNode["x"] + entryInsets["left"] + legendInsets["left"]);
  2102. var y = (fillNode["y"] + entryInsets["top"] + titleVerticalShift - legendInsets["bottom"] + (height / 2.0));
  2103. return "translate(" + x + "," + y + ")";
  2104. });
  2105. },
  2106. verifyResults : function(isHorizontal, eb, lr, availableWidth, availableHeight) {
  2107. var columnNodesHorizontalExtent = [];
  2108. for (var row = 0; row < lr.numRows; ++row) {
  2109. var column = [];
  2110. columnNodesHorizontalExtent.push(column);
  2111. }
  2112. var firstFailure = -1;
  2113. for (var i = 0; i < lr.elements.length; ++i) {
  2114. var fillNode = lr.elements[i];
  2115. if ((fillNode["data"]) != i) {
  2116. firstFailure = i;
  2117. break;
  2118. }
  2119. if (((fillNode["x"] + fillNode["width"]) - availableWidth) > 1) {
  2120. firstFailure = i;
  2121. break;
  2122. }
  2123. if (((fillNode["y"] + fillNode["height"]) - availableHeight) > 1) {
  2124. firstFailure = i;
  2125. break;
  2126. }
  2127. var colIndex = this.determineColumn(isHorizontal, i, lr.numCols, lr.numRows);
  2128. var columnListIndex = lr.crl.columnListShapes[colIndex];
  2129. var currentShapeBbox = eb.shapeBboxes[i];
  2130. var shapeBbox = eb.shapeBboxes[columnListIndex];
  2131. var width = (fillNode["width"] - currentShapeBbox.width) + shapeBbox.width;
  2132. var horizontalExtent = fillNode["x"] + width;
  2133. if ((horizontalExtent - availableWidth) > 1) {
  2134. firstFailure = i;
  2135. break;
  2136. }
  2137. var rowIndex = this.determineRow(isHorizontal, i, lr.numCols, lr.numRows);
  2138. var columnsPerRow = columnNodesHorizontalExtent[rowIndex];
  2139. columnsPerRow.push(horizontalExtent);
  2140. if (colIndex > 0) {
  2141. var precedingNodeExtent = columnsPerRow[colIndex - 1];
  2142. if ((precedingNodeExtent - fillNode["x"]) > 1) {
  2143. firstFailure = i;
  2144. break;
  2145. }
  2146. }
  2147. }
  2148. if (firstFailure != -1) {
  2149. lr.elements = lr.elements.slice(0, firstFailure);
  2150. lr.crl = this.buildColumnRowLists(isHorizontal, lr.numCols, lr.numRows, lr.elements, lr.elements.length, eb);
  2151. lr.numCols = lr.crl.columnListShapes.length;
  2152. lr.numRows = lr.crl.rowListShapes.length;
  2153. }
  2154. },
  2155. alignSwatchLegendTitleHorizontally : function(isHorizontal, titleSelector, eb, lr) {
  2156. if (titleSelector) {
  2157. var legendProperWidth = 0;
  2158. var lastColIndex = lr.numCols - 1;
  2159. var columnListIndex = lr.crl.columnListShapes[lastColIndex];
  2160. var shapeBbox = eb.shapeBboxes[columnListIndex];
  2161. for (var i = 0; i < lr.elements.length; ++i) {
  2162. var colIndex = this.determineColumn(isHorizontal, i, lr.numCols, lr.numRows);
  2163. if (colIndex == lastColIndex) {
  2164. var fillNode = lr.elements[i];
  2165. var currentShapeBbox = eb.shapeBboxes[i];
  2166. var fillNodeWidth = (fillNode["width"] - currentShapeBbox.width) + shapeBbox.width;
  2167. var horizontalExtent = fillNode["x"] + fillNodeWidth;
  2168. if (horizontalExtent > legendProperWidth) {
  2169. legendProperWidth = horizontalExtent;
  2170. }
  2171. }
  2172. }
  2173. if (legendProperWidth > 0) {
  2174. var titleBbox = titleSelector.node().getBBox();
  2175. var w = Math.max(titleBbox.width, legendProperWidth);
  2176. this.alignTitleHorizontally(titleSelector, w);
  2177. } else {
  2178. this.alignTitleHorizontally(titleSelector);
  2179. }
  2180. }
  2181. },
  2182. determineColumn : function(isHorizontal, index, numCols, numRows) {
  2183. if (isHorizontal) {
  2184. return index % numCols;
  2185. }
  2186. return ~~ (index / numRows);
  2187. },
  2188. determineRow : function(isHorizontal, index, numCols, numRows) {
  2189. if (isHorizontal) {
  2190. return ~~ (index / numCols);
  2191. }
  2192. return index % numRows;
  2193. },
  2194. /**
  2195. * Draws or redraws this legend into the specified selection of elements. The legend may be drawn into multiple elements simultaneously, but note that these legends would share the same backing data; typically, a legend is drawn into only one element at a time. This function will create its own subgroup and draw the legend into that, if that group exists already then all it will be removed with all its children and added anew.
  2196. * @param (rave['internal']['Selector']) g a selection that holds the elements into which the legend is drawn. Typically a group element.
  2197. */
  2198. /** @expose */
  2199. legend : function(g) {
  2200. var self = this;
  2201. g.each(function(data, index, groupIndex) {
  2202. self._spaceUsed = 0;
  2203. var gSelection = self.prepareLegendGroup(this);
  2204. self.prepareLegendBounds(gSelection);
  2205. var labelFormat = self.getLabelFormat();
  2206. var swatchSizeFn = self.getSwatchSizeFunction();
  2207. var shapeSymbol = self.getShapeSymbol(swatchSizeFn);
  2208. var textFlow = self.createTextFlowComponent();
  2209. var titleSelector = self.prepareLegendTitle(gSelection, textFlow);
  2210. if (titleSelector && !titleSelector.node().rave_getParentNode()) {
  2211. return;
  2212. }
  2213. var titleVerticalShift = self.calculateTitleVerticalShift(titleSelector);
  2214. var availableWidth = self.size()[0] - self.insets()["left"] - self.insets()["right"];
  2215. var availableHeight = self.size()[1] - titleVerticalShift;
  2216. if (availableHeight <= 0 || availableWidth <= 0) {
  2217. self.alignTitleHorizontally(titleSelector);
  2218. return;
  2219. }
  2220. if (!((self.scale()))) {
  2221. self.alignTitleHorizontally(titleSelector);
  2222. return;
  2223. }
  2224. var swatchsData = self.getData();
  2225. if (!swatchsData) {
  2226. self.alignTitleHorizontally(titleSelector);
  2227. return;
  2228. }
  2229. var es = self.getLegendEntrySelectors(gSelection, swatchsData, shapeSymbol, labelFormat);
  2230. var eb = self.getLegendEntryBBoxes(es);
  2231. if (eb.shapeBboxes.length == 0) {
  2232. self.alignTitleHorizontally(titleSelector);
  2233. return;
  2234. }
  2235. var swatchPadding = + (self.labelPadding());
  2236. for (var i = 0; i < Math.min(eb.labelBboxes.length, 2); ++i) {
  2237. var labelBBox = eb.labelBboxes[i];
  2238. var shapeBBox = eb.shapeBboxes[i];
  2239. var test1 = availableHeight < Math.max(labelBBox.height, shapeBBox.height);
  2240. var test2 = availableWidth < ((labelBBox.height / 2.0) + shapeBBox.width + self.entryInsets()["left"] + self.entryInsets()["right"] + swatchPadding);
  2241. if (test1 || test2) {
  2242. es.legendEntry.remove();
  2243. self.addTruncationIndicator(gSelection, titleVerticalShift, availableWidth, availableHeight, textFlow);
  2244. self.alignTitleHorizontally(titleSelector);
  2245. return;
  2246. }
  2247. }
  2248. var isHorizontal = "horizontal" == self.orient();
  2249. var lr = self.layoutLegendEntries(isHorizontal, textFlow, eb, es, swatchPadding, availableWidth, availableHeight);
  2250. self.verifyResults(isHorizontal, eb, lr, availableWidth, availableHeight);
  2251. if (lr.nodes.length != lr.elements.length) {
  2252. if (!(self.handleFailedLayout(isHorizontal, gSelection, lr, es, eb, swatchsData, availableWidth, availableHeight, titleVerticalShift, textFlow))) {
  2253. self.alignTitleHorizontally(titleSelector);
  2254. return;
  2255. }
  2256. }
  2257. self.alignLabelsShapes(isHorizontal, eb, es, lr, swatchPadding);
  2258. self.transformShapes(isHorizontal, es, lr, titleVerticalShift);
  2259. self.alignSwatchLegendTitleHorizontally(isHorizontal, titleSelector, eb, lr);
  2260. });
  2261. },
  2262. /** @expose */
  2263. shape : function(a0) {
  2264. var args = arguments;
  2265. if (args.length == 0) {
  2266. return this.shape$0();
  2267. }
  2268. return this.shape$1(a0);
  2269. },
  2270. /** @expose */
  2271. swatchSize : function(a0) {
  2272. var args = arguments;
  2273. if (args.length == 0) {
  2274. return this.swatchSize$0();
  2275. }
  2276. return this.swatchSize$1(a0);
  2277. },
  2278. /** @expose */
  2279. wrapLabels : function(a0) {
  2280. var args = arguments;
  2281. if (args.length == 0) {
  2282. return this.wrapLabels$0();
  2283. }
  2284. return this.wrapLabels$1(a0);
  2285. },
  2286. /** @expose */
  2287. rows : function(a0) {
  2288. var args = arguments;
  2289. if (args.length == 0) {
  2290. return this.rows$1();
  2291. }
  2292. return this.rows$0(a0);
  2293. },
  2294. /** @expose */
  2295. columns : function(a0) {
  2296. var args = arguments;
  2297. if (args.length == 0) {
  2298. return this.columns$1();
  2299. }
  2300. return this.columns$0(a0);
  2301. },
  2302. /** @expose */
  2303. layoutMethod : function(a0) {
  2304. var args = arguments;
  2305. if (args.length == 0) {
  2306. return this.layoutMethod$0();
  2307. }
  2308. return this.layoutMethod$1(a0);
  2309. }
  2310. });
  2311. com_ibm_rave_ext_legend_swatch_SwatchLegend.createFontStruct = function(style) {
  2312. var struct = new com_ibm_rave_ext_text_internal_wrap_FontStyleStruct();
  2313. struct.fontStyle = style["font-style"];
  2314. struct.fontVariant = style["font-variant"];
  2315. struct.fontWeight = style["font-weight"];
  2316. struct.fontSize = style["font-size"];
  2317. struct.lineHeight = style["line-height"];
  2318. struct.fontFamily = style["font-family"];
  2319. return struct;
  2320. };
  2321. com_ibm_rave_ext_legend_swatch_SwatchLegend.LegendEntrySelectors = function(){};
  2322. com_ibm_rave_ext_legend_swatch_SwatchLegend.LegendEntryBBoxes = function() {
  2323. this.shapeBboxes = [];
  2324. this.labelBboxes = [];
  2325. this.labelTexts = [];
  2326. };
  2327. com_ibm_rave_ext_legend_swatch_SwatchLegend.ColumnRowLists = function() {
  2328. this.columnListShapes = [];
  2329. this.rowListShapes = [];
  2330. };
  2331. com_ibm_rave_ext_legend_swatch_SwatchLegend.LayoutResults = function(){};
  2332. com_ibm_rave_ext_legend_swatch_SwatchLegend.GridDescr = function(numColumns, numRows, numColumnsUsed, numRowsUsed, firstFailureIndex, cellWidth, cellHeight, widthAvailableForTextPerColumn, heightAvailableForTextPerRow) {
  2333. this.numColumns = numColumns;
  2334. this.numRows = numRows;
  2335. this.numColumnsUsed = numColumnsUsed;
  2336. this.numRowsUsed = numRowsUsed;
  2337. this.firstFailureIndex = firstFailureIndex;
  2338. this.cellWidth = cellWidth;
  2339. this.cellHeight = cellHeight;
  2340. this.widthAvailableForTextPerColumn = widthAvailableForTextPerColumn;
  2341. this.heightAvailableForTextPerRow = heightAvailableForTextPerRow;
  2342. };
  2343. com_ibm_rave_ext_legend_swatch_SwatchLegend.TextResult = function(entriesCount, noTruncation, gridDescr) {
  2344. this.entriesCount = entriesCount;
  2345. this.noTruncation = noTruncation;
  2346. this.gridDescr = gridDescr;
  2347. };
  2348. com_ibm_rave_ext_legend_swatch_SwatchLegend.MIN_DATA_COUNT = 1;
  2349. com_ibm_rave_ext_legend_swatch_SwatchLegend.TOLERANCE_PIXELS = 1;
  2350. com_ibm_rave_ext_legend_swatch_SwatchLegend.MIN_ADJUSTED_NODE_COUNT = 2;
  2351. //com_ibm_rave_ext_legend_swatch_SwatchLegend.DEFAULT_SHAPE = "square";
  2352. //com_ibm_rave_ext_legend_swatch_SwatchLegend.PACKED = "packed";
  2353. //com_ibm_rave_ext_legend_swatch_SwatchLegend.GRID = "grid";
  2354. //com_ibm_rave_ext_legend_swatch_SwatchLegend.FONT_STYLE = "font-style";
  2355. //com_ibm_rave_ext_legend_swatch_SwatchLegend.FONT_VARIANT = "font-variant";
  2356. //com_ibm_rave_ext_legend_swatch_SwatchLegend.FONT_WEIGHT = "font-weight";
  2357. //com_ibm_rave_ext_legend_swatch_SwatchLegend.FONT_SIZE = "font-size";
  2358. //com_ibm_rave_ext_legend_swatch_SwatchLegend.LINE_HEIGHT = "line-height";
  2359. //com_ibm_rave_ext_legend_swatch_SwatchLegend.FONT_FAMILY = "font-family";
  2360. com_ibm_rave_ext_legend_swatch_SwatchLegend.DEFAULT_SWATCH_SIZE = 20.0 * 20.0;
  2361. //com_ibm_rave_ext_legend_swatch_SwatchLegend.DEFAULT_LABEL_VALIGN = "middle";
  2362. //com_ibm_rave_ext_legend_swatch_SwatchLegend.DEFAULT_LABEL_HALIGN = "start";
  2363. com_ibm_rave_ext_legend_swatch_SwatchLegend._NULL_SETVALUE_FN = function(node) {};
  2364. // $source: com/ibm/rave/ext/legend/continuous/ContinuousLegend
  2365. /************************************************************************
  2366. ** IBM Confidential
  2367. **
  2368. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  2369. **
  2370. ** (C) Copyright IBM Corp. 2017
  2371. **
  2372. ** The source code for this program is not published or otherwise divested of its trade secrets,
  2373. ** irrespective of what has been deposited with the U.S. Copyright Office.
  2374. ************************************************************************/
  2375. // GENERATED
  2376. //@import com/ibm/rave/ext/legend/AbstractLegend (loadtime) // superclass
  2377. /**
  2378. * A class that would generate and draw an axis-based legend
  2379. */
  2380. var com_ibm_rave_ext_legend_continuous_ContinuousLegend = rave['internal']['Declare'](com_ibm_rave_ext_legend_AbstractLegend, {
  2381. //_method : null,
  2382. //_shapeRectSize : null,
  2383. _tickLen : 6.00,
  2384. _startAt : 0.0,
  2385. constructor : function() {
  2386. this._method = "continuous";
  2387. {
  2388. this.minDataLen(2);
  2389. }
  2390. },
  2391. /**
  2392. * Sets which method to use to render this legend. Default value is continuous Possible values are: <ul> <li>axis</li> <li>stagger</li> <li>continuous</li> </ul>
  2393. * @param (String) method the method used to draw this legend
  2394. * @return (com.ibm.rave.ext.legend.continuous.ContinuousLegend) this legend instance.
  2395. */
  2396. method$0 : function(method) {
  2397. if ("axis" == method || "stagger" == method || "continuous" == method) {
  2398. this._method = method;
  2399. } else {
  2400. this._method = "continuous";
  2401. }
  2402. return this;
  2403. },
  2404. /**
  2405. * Get the current method used to render this legend.
  2406. * @return (String) method String.
  2407. */
  2408. method$1 : function() {
  2409. return this._method;
  2410. },
  2411. /**
  2412. * Specify the size (length) of the tick marks.
  2413. * @param (Object) length The size of ticks
  2414. * @return (com.ibm.rave.ext.legend.continuous.ContinuousLegend) this legend instance.
  2415. */
  2416. ticklength$0 : function(length) {
  2417. this._tickLen = + (length);
  2418. return this;
  2419. },
  2420. /**
  2421. * Get the currently assigned tick length (in pixels). Default is 6.
  2422. * @return (double) Tick length in pixels.
  2423. */
  2424. ticklength$1 : function() {
  2425. return this._tickLen;
  2426. },
  2427. /**
  2428. * Specify the starting point (in pixels) for the first tick of axis legend. This value is ignored for other legend methods (e.g., continuous and stagger)
  2429. * @param (Object) startAt The starting point for the first tick for axis legend
  2430. * @return (com.ibm.rave.ext.legend.continuous.ContinuousLegend) this legend instance.
  2431. */
  2432. startAt$0 : function(startAt) {
  2433. this._startAt = + (startAt);
  2434. return this;
  2435. },
  2436. /**
  2437. * Get starting point (in pixels) for the first tick of axis legend. Default is 0.
  2438. * @return (double) Tick length in pixels.
  2439. */
  2440. startAt$1 : function() {
  2441. return this._startAt;
  2442. },
  2443. /**
  2444. * Get the value of the width and height in pixels for the bounding box of legend rectangular shape. Applicable only to stagger and continuous legends since the axis legend sets its length to the last value of the scale's range
  2445. * @return (Array) legend shape bounding box.
  2446. */
  2447. shapeRectSize$0 : function() {
  2448. return this._shapeRectSize;
  2449. },
  2450. /**
  2451. * Set the value of the width and height in pixels for the bounding box of legend rectangular shape. Applicable only to stagger and continuous legends. For stagger and continuous methods the values passed will be used for the bounding box of the colored rectangle regardless of the orientation. If the either of width or height value passed is a non-positive number (i.e., zero or a negative number) then the default calculation for the value of that dimension will be used. This allows client to set one dimension to a fixed value while leaving the other to be calculated dynamically. Default value for major dimension (width in case of horizontal orientation, height for vertical orientation), is the remaining length of the legends' relevant extent (as per its size/bounding box) after accounting for padding and the size occupied by the legend's title the size occupied by the legend's tick's length and label -if applicable. As for minor dimension (width in case of vertical orientation, height for horizontal orientation) it would be the lesser of 40 pixels or the remaining length of legends' relevant extent (as per its size/bounding box) after accounting for padding and the size occupied by the legend's title, the legend's tick's length and label -if applicable.
  2452. * @param (Array) size The dimensions of legend's shape bounding box.
  2453. * @return (com.ibm.rave.ext.legend.continuous.ContinuousLegend) this legend instance.
  2454. */
  2455. shapeRectSize$1 : function(size) {
  2456. this._shapeRectSize = size;
  2457. return this;
  2458. },
  2459. getOrientationValues : function(isHorizontal, digitBbox, tickPadding, availableWidth, availableHeight) {
  2460. var shapeAvailableHeight;
  2461. var shapeAvailableWidth;
  2462. if (isHorizontal) {
  2463. shapeAvailableHeight = availableHeight - (this._tickLen + tickPadding + digitBbox.height);
  2464. shapeAvailableWidth = availableWidth - (digitBbox.width * 6);
  2465. } else {
  2466. shapeAvailableWidth = availableWidth - (this._tickLen + tickPadding + digitBbox.width * 6);
  2467. shapeAvailableHeight = availableHeight - digitBbox.height;
  2468. }
  2469. var vals = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.OrientationValues();
  2470. if (isHorizontal) {
  2471. vals.shape_changing_coord2 = "x2";
  2472. vals.shape_const_coord2 = "y2";
  2473. vals.tick_len_coord1 = "y1";
  2474. vals.tick_len_coord2 = "y2";
  2475. vals.tick_place_coord1 = "x1";
  2476. vals.tick_place_coord2 = "x2";
  2477. vals.label_place_coord = "x";
  2478. vals.label_shift_coord = "y";
  2479. vals.label_anchor = "middle";
  2480. vals.label_adjust_dy_value = ".7em";
  2481. vals.shape_major_dimension = "width";
  2482. vals.shape_minor_dimension = "height";
  2483. if ((this._shapeRectSize)) {
  2484. vals.shapeRectSize = [this._shapeRectSize[0], this._shapeRectSize[1]];
  2485. if (vals.shapeRectSize[1] <= 0) {
  2486. vals.shapeRectSize[1] = Math.min(shapeAvailableHeight, 40);
  2487. }
  2488. if (vals.shapeRectSize[0] <= 0) {
  2489. vals.shapeRectSize[0] = shapeAvailableWidth;
  2490. }
  2491. } else {
  2492. vals.shapeRectSize = [shapeAvailableWidth, Math.min(shapeAvailableHeight, 40)];
  2493. }
  2494. if ("axis" == this._method) {
  2495. vals.shape_major_dimension_len = (this.scale().range()[this.scale().range().length - 1]);
  2496. vals.shape_major_dimension_len += this._startAt;
  2497. } else {
  2498. vals.shape_major_dimension_len = vals.shapeRectSize[0];
  2499. }
  2500. vals.shape_minor_dimension_len = vals.shapeRectSize[1];
  2501. vals.tickPlacementScaleRange = [0, vals.shape_major_dimension_len];
  2502. } else {
  2503. vals.shape_changing_coord2 = "y2";
  2504. vals.shape_const_coord2 = "x2";
  2505. vals.tick_len_coord1 = "x1";
  2506. vals.tick_len_coord2 = "x2";
  2507. vals.tick_place_coord1 = "y1";
  2508. vals.tick_place_coord2 = "y2";
  2509. vals.label_place_coord = "y";
  2510. vals.label_shift_coord = "x";
  2511. vals.label_anchor = "start";
  2512. vals.label_adjust_dy_value = ".35em";
  2513. vals.shape_major_dimension = "height";
  2514. vals.shape_minor_dimension = "width";
  2515. if ((this._shapeRectSize)) {
  2516. vals.shapeRectSize = [this._shapeRectSize[0], this._shapeRectSize[1]];
  2517. if (vals.shapeRectSize[1] <= 0) {
  2518. vals.shapeRectSize[1] = shapeAvailableHeight;
  2519. }
  2520. if (vals.shapeRectSize[0] <= 0) {
  2521. vals.shapeRectSize[0] = Math.min(shapeAvailableWidth, 40);
  2522. }
  2523. } else {
  2524. vals.shapeRectSize = [Math.min(shapeAvailableWidth, 40), shapeAvailableHeight];
  2525. }
  2526. if ("axis" == this._method) {
  2527. vals.shape_major_dimension_len = (this.scale().range()[this.scale().range().length - 1]);
  2528. vals.shape_major_dimension_len += this._startAt;
  2529. } else {
  2530. vals.shape_major_dimension_len = vals.shapeRectSize[1];
  2531. }
  2532. vals.shape_minor_dimension_len = vals.shapeRectSize[0];
  2533. vals.tickPlacementScaleRange = [vals.shape_major_dimension_len, 0];
  2534. }
  2535. vals.tickShift = ("axis" == this._method) ? 1 : vals.shape_minor_dimension_len;
  2536. return vals;
  2537. },
  2538. getTickPlacementValues : function(isHorizontal, ticksData, ov) {
  2539. var vals = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickPlacementValues();
  2540. vals.extent = rave.extent(ticksData);
  2541. if (this.reverse()) {
  2542. vals.extent = [vals.extent[1], vals.extent[0]];
  2543. }
  2544. var horizontal = (this.reverse()) ? !isHorizontal : isHorizontal;
  2545. var placementScale = rave.scale.linear().domain(vals.extent).range(ov.tickPlacementScaleRange);
  2546. if ("axis" == this._method) {
  2547. vals.ticksPlacementData = placementScale.ticks();
  2548. var self = this;
  2549. if (horizontal) {
  2550. vals.tickPlacementValueFunction = function(data, index, groupIndex) {
  2551. var val = self.scale().call(this, data, index, groupIndex);
  2552. return val + self._startAt;
  2553. };
  2554. } else {
  2555. vals.tickPlacementValueFunction = function(data, index, groupIndex) {
  2556. var val = self.scale().call(this, data, index, groupIndex);
  2557. return ov.shape_major_dimension_len - val - self._startAt;
  2558. };
  2559. }
  2560. } else if ("stagger" == this._method) {
  2561. var stagger_rect_major_dim_len;
  2562. var numRects = ~~(ov.shape_major_dimension_len / 20.0);
  2563. if (numRects < 2) {
  2564. numRects = 1;
  2565. stagger_rect_major_dim_len = ov.shape_major_dimension_len;
  2566. vals.ticksPlacementData = vals.extent;
  2567. } else {
  2568. if (numRects > 15) {
  2569. numRects = 15;
  2570. }
  2571. var extentStart = + (vals.extent[0]);
  2572. var extentEnd = + (vals.extent[1]);
  2573. var diff = extentEnd - extentStart;
  2574. if (diff == 0) {
  2575. stagger_rect_major_dim_len = ov.shape_major_dimension_len;
  2576. vals.ticksPlacementData = [];
  2577. } else {
  2578. var step = diff / (numRects + 1);
  2579. var ticks = rave.range(extentStart, extentEnd, step);
  2580. this.fixTicksDecimalPlaces(ticks, 4);
  2581. if (ticks[ticks.length - 1] != extentEnd) {
  2582. ticks[ticks.length - 1] = extentEnd;
  2583. }
  2584. vals.ticksPlacementData = ticks;
  2585. stagger_rect_major_dim_len = ov.shape_major_dimension_len / (ticks.length - 1);
  2586. }
  2587. }
  2588. if (horizontal) {
  2589. vals.tickPlacementValueFunction = function(data, index, groupIndex) {
  2590. return stagger_rect_major_dim_len * index;
  2591. };
  2592. } else {
  2593. vals.tickPlacementValueFunction = function(data, index, groupIndex) {
  2594. return ov.shape_major_dimension_len - (stagger_rect_major_dim_len * index);
  2595. };
  2596. }
  2597. } else {
  2598. vals.tickPlacementValueFunction = placementScale;
  2599. vals.ticksPlacementData = placementScale.ticks();
  2600. }
  2601. return vals;
  2602. },
  2603. fixTicksDecimalPlaces : function(ticks, numPlaces) {
  2604. for (var i = 0; i < ticks.length; ++i) {
  2605. var tickValue = ticks[i];
  2606. tickValue = this.fixDecimalPlaces(tickValue, numPlaces);
  2607. ticks[i] = tickValue;
  2608. }
  2609. },
  2610. fixDecimalPlaces : function(val, numPlaces) {
  2611. if (val == 0) {
  2612. return 0;
  2613. }
  2614. var f = Math.pow(10, numPlaces);
  2615. while ((~~(val * f)) == 0) {
  2616. f *= 10;
  2617. }
  2618. return (~~(val * f)) / f;
  2619. },
  2620. getTickEntrySelectors : function(gSelection, labelFormat, tickColor, tickPadding, ov, tv) {
  2621. var ts = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickEntrySelectors();
  2622. ts.tickEntry = gSelection.selectAll(".legendEntry").data(tv.ticksPlacementData).enter().append("g").attr("class", "legendEntry");
  2623. ts.tick = ts.tickEntry.append("line").attr("class", "legendTickLine").attr(ov.tick_len_coord1, ov.tickShift).attr(ov.tick_len_coord2, ov.tickShift + this._tickLen).attr(ov.tick_place_coord1, tv.tickPlacementValueFunction).attr(ov.tick_place_coord2, tv.tickPlacementValueFunction).style("stroke", tickColor);
  2624. ts.text = ts.tickEntry.append("text").attr("class", "legendLabel").attr(ov.label_place_coord, tv.tickPlacementValueFunction).attr(ov.label_shift_coord, ov.tickShift + this._tickLen + tickPadding).attr("dy", ov.label_adjust_dy_value).attr("text-anchor", ov.label_anchor);
  2625. if (typeof labelFormat === "function") {
  2626. ts.text.text(labelFormat);
  2627. } else {
  2628. ts.text.text(labelFormat);
  2629. }
  2630. return ts;
  2631. },
  2632. updateTickEntrySelectors : function(gSelection) {
  2633. var ts = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickEntrySelectors();
  2634. ts.tickEntry = gSelection.selectAll(".legendEntry");
  2635. ts.tick = gSelection.selectAll("." + "legendTickLine");
  2636. ts.text = gSelection.selectAll("." + "legendLabel");
  2637. return ts;
  2638. },
  2639. getTickEntryBBoxes : function(ts) {
  2640. var tb = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickEntryBBoxes();
  2641. ts.text.each(function(data, index, groupIndex) {
  2642. var labelBbox = this.getBBox();
  2643. if (labelBbox.width > tb.largestLabelWidth) {
  2644. tb.largestLabelWidth = labelBbox.width;
  2645. }
  2646. if (labelBbox.height > tb.largestLabelHeight) {
  2647. tb.largestLabelHeight = labelBbox.height;
  2648. }
  2649. tb.labelBboxes.push(labelBbox);
  2650. tb.labelTexts.push(this.rave_getText());
  2651. tb.labelBboxesPoints.push([+ (this.getAttribute("x")), + (this.getAttribute("y"))]);
  2652. });
  2653. ts.tick.each(function(data, index, groupIndex) {
  2654. tb.tickBboxes.push(this.getBBox());
  2655. });
  2656. return tb;
  2657. },
  2658. getShapeSelectors : function(isHorizontal, gSelection, ov, tv, ticksData, axisColor, borderColor) {
  2659. var ss = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.ShapeSelectors();
  2660. if ("axis" == this._method) {
  2661. ss.shapeSelector = gSelection.append("line").attr("class", "legendShape").attr("x1", 0).attr("y1", 0).attr(ov.shape_changing_coord2, ov.shape_major_dimension_len).attr(ov.shape_const_coord2, 0).style("stroke", axisColor);
  2662. } else if ("stagger" == this._method) {
  2663. var staggerRectData;
  2664. if (tv.ticksPlacementData.length > 1) {
  2665. staggerRectData = [];
  2666. var tickValue = + (tv.ticksPlacementData[0]);
  2667. for (var i = 1; i < tv.ticksPlacementData.length; ++i) {
  2668. var nextTickValue = + (tv.ticksPlacementData[i]);
  2669. staggerRectData[i - 1] = (tickValue + nextTickValue) / 2.0;
  2670. tickValue = nextTickValue;
  2671. }
  2672. } else {
  2673. staggerRectData = [+ (tv.ticksPlacementData[0])];
  2674. }
  2675. var colors = [];
  2676. for (var i = 0; i < ticksData.length; ++i) {
  2677. var color = this.scale().call(null, ticksData[i], -1, -1);
  2678. colors.push(color);
  2679. }
  2680. var colorScale = this.scale().copy();
  2681. colorScale.domain(ticksData);
  2682. colorScale.range(colors);
  2683. var staggerRectColor = [];
  2684. if (isHorizontal) {
  2685. for (var i = 0; i < staggerRectData.length; ++i) {
  2686. staggerRectColor.push(colorScale.call(null, staggerRectData[i], -1, -1).toString());
  2687. }
  2688. } else {
  2689. for (var i = staggerRectData.length - 1; i >= 0; --i) {
  2690. staggerRectColor.push(colorScale.call(null, staggerRectData[i], -1, -1).toString());
  2691. }
  2692. }
  2693. if (this.reverse()) {
  2694. staggerRectColor.reverse();
  2695. }
  2696. var stagger_rect_major_dim_len = ov.shape_major_dimension_len / (staggerRectData.length);
  2697. ss.shapeSelector = gSelection.selectAll(".legendShape").data(staggerRectData).enter().append("rect").attr("class", "legendShape").attr(ov.shape_major_dimension, stagger_rect_major_dim_len).attr(ov.shape_minor_dimension, ov.shape_minor_dimension_len).style("fill", function(data, index, groupIndex) {
  2698. return staggerRectColor[index];
  2699. }).attr(ov.label_place_coord, function(data, index, groupIndex) {
  2700. return stagger_rect_major_dim_len * index;
  2701. });
  2702. if (borderColor != null) {
  2703. ss.boundsSelector = gSelection.append("rect").attr("class", "legendStaggerBorder").attr(ov.shape_minor_dimension, ov.shape_minor_dimension_len).attr(ov.shape_major_dimension, ov.shape_major_dimension_len).style("fill-opacity", 0).attr("stroke", borderColor);
  2704. }
  2705. } else {
  2706. var gradientIdCount = com_ibm_rave_ext_legend_continuous_ContinuousLegend.getGradientIdCount();
  2707. var gradientID = "legendGradient" + gradientIdCount.idCount++;
  2708. var gradient = gSelection.append("defs").append("linearGradient").attr("id", gradientID).attr("x1", "0%").attr("y1", "0%").attr(ov.shape_const_coord2, "0%").attr(ov.shape_changing_coord2, "100%").attr("spreadMethod", "pad");
  2709. if (isHorizontal) {
  2710. var stopsScale = rave.scale.linear().domain(tv.extent).range([0, 100]);
  2711. for (var i = 0; i < ticksData.length; ++i) {
  2712. var stop = stopsScale.call(null, ticksData[i], -1, -1);
  2713. gradient.append("stop").attr("offset", stop + "%").attr("stop-color", this.scale().call(null, ticksData[i], -1, -1)).attr("stop-opacity", 1);
  2714. }
  2715. } else {
  2716. var stopsScale = rave.scale.linear().domain(tv.extent).range([100, 0]);
  2717. for (var i = ticksData.length - 1; i >= 0; --i) {
  2718. var stop = stopsScale.call(null, ticksData[i], -1, -1);
  2719. gradient.append("stop").attr("offset", stop + "%").attr("stop-color", this.scale().call(null, ticksData[i], -1, -1)).attr("stop-opacity", 1);
  2720. }
  2721. }
  2722. ss.shapeSelector = gSelection.append("rect").attr("class", "legendShape").attr(ov.shape_minor_dimension, ov.shape_minor_dimension_len).attr(ov.shape_major_dimension, ov.shape_major_dimension_len);
  2723. if (borderColor != null) {
  2724. ss.shapeSelector.attr("stroke", borderColor);
  2725. }
  2726. ss.shapeSelector.style("fill", "url(#" + gradientID + ")");
  2727. }
  2728. return ss;
  2729. },
  2730. transformShapes : function(isHorizontal, tb, ov, ts, ss, titleSelector, titleVerticalShift) {
  2731. var label_vertical_shift = 0;
  2732. var label_horizontal_shift = 0;
  2733. if (isHorizontal) {
  2734. if ((tb.labelBboxes[0].width / 2.0) - tb.labelBboxesPoints[0][0] > 0) {
  2735. label_horizontal_shift = tb.labelBboxes[0].width / 2.0;
  2736. }
  2737. } else {
  2738. if ((tb.labelBboxes[tb.labelBboxes.length - 1].height / 2.0) - tb.labelBboxesPoints[tb.labelBboxesPoints.length - 1][1] > 0) {
  2739. label_vertical_shift = tb.labelBboxes[tb.labelBboxes.length - 1].height / 2.0;
  2740. }
  2741. }
  2742. var horizontal_shift = (this.entryInsets()["left"] + this.insets()["left"] + label_horizontal_shift);
  2743. var vertical_shift = (titleVerticalShift - this.insets()["bottom"] + label_vertical_shift + this.entryInsets()["top"]);
  2744. var transformStr = "translate(" + (horizontal_shift) + "," + (vertical_shift) + ")";
  2745. if ((ss.boundsSelector)) {
  2746. ss.boundsSelector.attr("transform", transformStr);
  2747. }
  2748. ss.shapeSelector.attr("transform", transformStr);
  2749. ts.tickEntry.attr("transform", transformStr);
  2750. this.alignContinuousLegendTitleHorizontally(isHorizontal, horizontal_shift, ov, titleSelector);
  2751. },
  2752. alignContinuousLegendTitleHorizontally : function(isHorizontal, horizontal_shift, ov, titleSelector) {
  2753. if (titleSelector) {
  2754. var titleBbox = titleSelector.node().getBBox();
  2755. var legendProperWidth = (isHorizontal) ? ov.shape_major_dimension_len : ov.shape_minor_dimension_len;
  2756. var title_horizontal_shift = horizontal_shift;
  2757. if ("start" == this.titleAlignment()) {
  2758. title_horizontal_shift = 0;
  2759. } else if ("end" == this.titleAlignment()) {
  2760. title_horizontal_shift += (titleBbox.width > legendProperWidth) ? (this.titleInsets()["right"] + this.insets()["right"]) : 0;
  2761. } else {
  2762. title_horizontal_shift *= 2;
  2763. title_horizontal_shift -= this.insets()["left"];
  2764. }
  2765. legendProperWidth += title_horizontal_shift;
  2766. var w = Math.max(titleBbox.width, legendProperWidth);
  2767. this.alignTitleHorizontally(titleSelector, w);
  2768. }
  2769. },
  2770. cleanUpTextFlowSettings : function(text, ov) {
  2771. text.selectAll("tspan").attr("x", null).attr("dy", null).attr("width", null);
  2772. text.attr("dy", ov.label_adjust_dy_value).attr("text-anchor", ov.label_anchor);
  2773. },
  2774. getLegendProperDim : function(isHorizontal, ov, tb, tickPadding) {
  2775. var legend_shape_width;
  2776. var legend_shape_height;
  2777. if (isHorizontal) {
  2778. legend_shape_width = ov.shape_major_dimension_len;
  2779. if ((tb.labelBboxes[0].width / 2.0) + tb.labelBboxesPoints[0][0] >= ov.shape_major_dimension_len) {
  2780. legend_shape_width += tb.labelBboxes[0].width / 2.0;
  2781. }
  2782. if ((tb.labelBboxes[tb.labelBboxes.length - 1].width / 2.0) + tb.labelBboxesPoints[tb.labelBboxesPoints.length - 1][0] >= ov.shape_major_dimension_len) {
  2783. legend_shape_width += tb.labelBboxes[tb.labelBboxes.length - 1].width / 2.0;
  2784. }
  2785. legend_shape_height = ov.tickShift + tb.largestLabelHeight + +this._tickLen + tickPadding;
  2786. } else {
  2787. legend_shape_height = ov.shape_major_dimension_len;
  2788. if ((tb.labelBboxes[0].height / 2.0) + tb.labelBboxesPoints[0][1] >= ov.shape_major_dimension_len) {
  2789. legend_shape_height += tb.labelBboxes[0].height / 2.0;
  2790. }
  2791. if ((tb.labelBboxes[tb.labelBboxes.length - 1].height / 2.0) + tb.labelBboxesPoints[tb.labelBboxesPoints.length - 1][1] >= ov.shape_major_dimension_len) {
  2792. legend_shape_height += tb.labelBboxes[tb.labelBboxes.length - 1].height / 2.0;
  2793. }
  2794. legend_shape_width = ov.tickShift + tb.largestLabelWidth + this._tickLen + tickPadding;
  2795. }
  2796. return [legend_shape_width, legend_shape_height];
  2797. },
  2798. verifyResults : function(gSelection, titleSelector, titleVerticalShift, isHorizontal, tickPadding, ov, tb, ts, ss, availableWidth, availableHeight, textFlow) {
  2799. var _tb = tb;
  2800. var _ts = ts;
  2801. var legendDim = this.getLegendProperDim(isHorizontal, ov, _tb, tickPadding);
  2802. var entryInsets = this.entryInsets();
  2803. if (isHorizontal) {
  2804. this._spaceUsed += legendDim[1] + (entryInsets["top"] + entryInsets["bottom"]);
  2805. } else {
  2806. if (legendDim[0] > this._spaceUsed) {
  2807. this._spaceUsed = legendDim[0] + (entryInsets["left"] + entryInsets["right"]);
  2808. }
  2809. }
  2810. if (legendDim[0] > availableWidth || legendDim[1] > availableHeight) {
  2811. if (legendDim[0] > availableWidth) {
  2812. textFlow.wrap(false);
  2813. if (isHorizontal) {
  2814. var extraWidth = Math.ceil(legendDim[0] - availableWidth) * 2;
  2815. if ((_tb.labelBboxes[0].width / 2.0) + _tb.labelBboxesPoints[0][0] >= ov.shape_major_dimension_len) {
  2816. var halfFirstlabel = _tb.labelBboxes[0].width / 2.0;
  2817. var halfLastLabel = 0;
  2818. if ((_tb.labelBboxes[_tb.labelBboxes.length - 1].width / 2.0) + _tb.labelBboxesPoints[_tb.labelBboxesPoints.length - 1][0] > ov.shape_major_dimension_len) {
  2819. halfLastLabel = _tb.labelBboxes[_tb.labelBboxes.length - 1].width / 2.0;
  2820. }
  2821. var firstLabelRatio = halfFirstlabel / (halfFirstlabel + halfLastLabel);
  2822. var firstLabelReduction = Math.ceil(firstLabelRatio * extraWidth);
  2823. var firstLabelSelection = rave.select(_ts.text.node());
  2824. textFlow.extent(~~(_tb.labelBboxes[0].width - firstLabelReduction), ~~_tb.largestLabelHeight);
  2825. textFlow.flow(firstLabelSelection);
  2826. this.cleanUpTextFlowSettings(firstLabelSelection, ov);
  2827. if (extraWidth - firstLabelReduction > 0) {
  2828. var lastLabelReduction = Math.ceil(extraWidth - firstLabelReduction);
  2829. var lastLabelSelection = rave.select(_ts.text[0][_ts.text.size() - 1]);
  2830. textFlow.extent(~~(_tb.labelBboxes[_tb.labelBboxes.length - 1].width - lastLabelReduction), ~~_tb.largestLabelHeight);
  2831. textFlow.flow(lastLabelSelection);
  2832. this.cleanUpTextFlowSettings(lastLabelSelection, ov);
  2833. }
  2834. }
  2835. } else {
  2836. var truncationWidth = _tb.largestLabelWidth - (legendDim[0] - availableWidth);
  2837. textFlow.extent(~~truncationWidth, ~~_tb.largestLabelHeight);
  2838. textFlow.flow(_ts.text);
  2839. this.cleanUpTextFlowSettings(_ts.text, ov);
  2840. }
  2841. this.transformShapes(isHorizontal, _tb, ov, _ts, ss, titleSelector, titleVerticalShift);
  2842. _tb = this.getTickEntryBBoxes(_ts);
  2843. legendDim = this.getLegendProperDim(isHorizontal, ov, _tb, tickPadding);
  2844. }
  2845. if (legendDim[0] > availableWidth || legendDim[1] > availableHeight) {
  2846. this.alignTitleHorizontally(titleSelector);
  2847. _ts.tickEntry.remove();
  2848. ss.shapeSelector.remove();
  2849. if (ss.boundsSelector) {
  2850. ss.boundsSelector.remove();
  2851. }
  2852. this.addTruncationIndicator(gSelection, titleVerticalShift, availableWidth, availableHeight, textFlow);
  2853. return false;
  2854. } else {
  2855. _ts = this.updateTickEntrySelectors(gSelection);
  2856. _tb = this.getTickEntryBBoxes(_ts);
  2857. this.transformShapes(isHorizontal, _tb, ov, _ts, ss, titleSelector, titleVerticalShift);
  2858. }
  2859. }
  2860. return true;
  2861. },
  2862. /** @expose */
  2863. getDataFromScale : function() {
  2864. if (!this.scale()) {
  2865. return null;
  2866. }
  2867. return this.scale().domain();
  2868. },
  2869. /**
  2870. * Draws or redraws this legend into the specified selection of elements. The legend may be drawn into multiple elements simultaneously, but note that these legends would share the same backing data; typically, a legend is drawn into only one element at a time. This function will create its own subgroup and draw the legend into that, if that group exists already then all it will be removed with all its children and added anew.
  2871. * @param (rave['internal']['Selector']) g a selection that holds the elements into which the legend is drawn. Typically a group element.
  2872. */
  2873. /** @expose */
  2874. legend : function(g) {
  2875. var self = this;
  2876. g.each(function(data, index, groupIndex) {
  2877. self._spaceUsed = 0;
  2878. var gSelection = self.prepareLegendGroup(this);
  2879. self.prepareLegendBounds(gSelection);
  2880. var labelFormat = self.getLabelFormat();
  2881. var textFlow = self.createTextFlowComponent();
  2882. var titleSelector = self.prepareLegendTitle(gSelection, textFlow);
  2883. if (titleSelector && !titleSelector.node().rave_getParentNode()) {
  2884. return;
  2885. }
  2886. var titleVerticalShift = self.calculateTitleVerticalShift(titleSelector);
  2887. var tickPadding = + (self.labelPadding());
  2888. var isHorizontal = "horizontal" == self.orient();
  2889. var availableWidth = self.size()[0] - self.insets()["left"] - self.insets()["right"] - self.entryInsets()["left"] - self.entryInsets()["right"];
  2890. var availableHeight = self.size()[1] - titleVerticalShift - self.entryInsets()["top"] - self.entryInsets()["bottom"];
  2891. if (availableHeight <= 0 || availableWidth <= 0) {
  2892. self.alignTitleHorizontally(titleSelector);
  2893. return;
  2894. }
  2895. if (!((self.scale()))) {
  2896. self.alignTitleHorizontally(titleSelector);
  2897. return;
  2898. }
  2899. var ticksData = self.getData();
  2900. if (!ticksData) {
  2901. self.alignTitleHorizontally(titleSelector);
  2902. return;
  2903. }
  2904. ticksData = self.sanitizeData(ticksData);
  2905. var digitBbox = self.getSingleDigitBbox(gSelection);
  2906. var ov = self.getOrientationValues(isHorizontal, digitBbox, tickPadding, availableWidth, availableHeight);
  2907. var tickColor = "black";
  2908. var axisColor = "black";
  2909. var borderColor = null;
  2910. if ((self.shapeBorderColor())) {
  2911. borderColor = rave.rgb(self.shapeBorderColor()).toString();
  2912. tickColor = borderColor;
  2913. axisColor = borderColor;
  2914. }
  2915. var tv = self.getTickPlacementValues(isHorizontal, ticksData, ov);
  2916. if (!tv.ticksPlacementData || tv.ticksPlacementData.length == 0) {
  2917. self.alignTitleHorizontally(titleSelector);
  2918. return;
  2919. }
  2920. var ts = self.getTickEntrySelectors(gSelection, labelFormat, tickColor, tickPadding, ov, tv);
  2921. var tb = self.getTickEntryBBoxes(ts);
  2922. if (tb.labelBboxes.length == 0) {
  2923. self.alignTitleHorizontally(titleSelector);
  2924. return;
  2925. }
  2926. var ss = self.getShapeSelectors(isHorizontal, gSelection, ov, tv, ticksData, axisColor, borderColor);
  2927. self.transformShapes(isHorizontal, tb, ov, ts, ss, titleSelector, titleVerticalShift);
  2928. self.handleCollidingLabels(ts);
  2929. ts = self.updateTickEntrySelectors(gSelection);
  2930. tb = self.getTickEntryBBoxes(ts);
  2931. self.verifyResults(gSelection, titleSelector, titleVerticalShift, isHorizontal, tickPadding, ov, tb, ts, ss, availableWidth, availableHeight, textFlow);
  2932. self.createSwatchExtraEntries(gSelection, self.size()[0], self.size()[1], self.getLegendProperDim(isHorizontal, ov, tb, tickPadding)[0], self.getLegendProperDim(isHorizontal, ov, tb, tickPadding)[1], availableWidth, availableHeight, self.insets(), titleVerticalShift);
  2933. });
  2934. },
  2935. getSingleDigitBbox : function(gSelection) {
  2936. var selector = gSelection.append("text").text("0");
  2937. var digitBbox = selector.node().getBBox();
  2938. selector.remove();
  2939. return digitBbox;
  2940. },
  2941. sanitizeData : function(ticksData) {
  2942. if (this.dataValues()) {
  2943. var hasInvalidValues = false;
  2944. var domainExtent = rave.extent(this.scale().domain());
  2945. var minVal = + (domainExtent[0]);
  2946. var maxVal = + (domainExtent[1]);
  2947. var newData = [];
  2948. for (var i = 0; i < ticksData.length; ++i) {
  2949. var val = + (ticksData[i]);
  2950. if (val > maxVal || val < minVal) {
  2951. hasInvalidValues = true;
  2952. continue;
  2953. }
  2954. newData.push(val);
  2955. }
  2956. if (newData.length > 0) {
  2957. return newData;
  2958. } else if (hasInvalidValues) {
  2959. return this.scale().domain();
  2960. }
  2961. }
  2962. return ticksData;
  2963. },
  2964. handleCollidingLabels : function(ts) {
  2965. var ravePosition = rave.capabilities.extension("position");
  2966. var dropOverlap = ravePosition.drop();
  2967. dropOverlap.remove(true).dropOverlap(ts.text);
  2968. },
  2969. createSwatchExtraEntries : function(gSelection, overallWidth, overallHeight, legendWidth, legendHeight, availableWidth, availableHeight, insets, verticalTitleShift) {
  2970. var self = this;
  2971. var extraLegendRect;
  2972. if (self.orient() == "vertical") {
  2973. extraLegendRect = new rave['internal']['RectStruct'](((insets["left"] * 2) + legendWidth), (overallHeight - availableHeight), (availableWidth - legendWidth), (legendHeight));
  2974. } else {
  2975. extraLegendRect = new rave['internal']['RectStruct']((overallWidth - availableWidth), ((insets["top"] * 2) + legendHeight + verticalTitleShift), legendWidth, (availableHeight - legendHeight));
  2976. }
  2977. if (!(self._extraLegendEntries.empty())) {
  2978. var swatchData = [];
  2979. for (var __i_enFor0 = 0, __exp_enFor0 = self._extraLegendEntries.keys(), __len_enFor0 = __exp_enFor0.length;
  2980. __i_enFor0 < __len_enFor0; ++__i_enFor0) {
  2981. var key = __exp_enFor0[__i_enFor0];
  2982. swatchData.push(key);
  2983. }
  2984. var rl = rave.capabilities.extension("legend");
  2985. var swatchLegend = rl.swatch().size([extraLegendRect.width, extraLegendRect.height]).orient(self.orient()).scale(rave.scale.category20b().domain((swatchData)));
  2986. for (var i = 0; i < self._extraLegendEntries.size(); ++i) {
  2987. var ele = swatchLegend.extraEntry(self._extraLegendEntries.keys()[i]);
  2988. if ((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).colorSet()) {
  2989. ele.color((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).color());
  2990. }
  2991. if ((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).sizeSet()) {
  2992. ele.size((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).size());
  2993. }
  2994. if ((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).shapeSet()) {
  2995. ele.shape((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).shape());
  2996. }
  2997. }
  2998. var swatchLegendSelector = gSelection.append("g").attr("class", "extraLegend").attr("transform", "translate(" + extraLegendRect.x + "," + extraLegendRect.y + ")").attr("width", extraLegendRect.width).attr("height", extraLegendRect.height).call(swatchLegend);
  2999. if (swatchLegendSelector.selectAll(".legendEntry").size() == 0) {
  3000. gSelection.selectAll(".extraLegend").remove();
  3001. }
  3002. }
  3003. },
  3004. /** @expose */
  3005. method : function(a0) {
  3006. var args = arguments;
  3007. if (args.length == 0) {
  3008. return this.method$1();
  3009. }
  3010. return this.method$0(a0);
  3011. },
  3012. /** @expose */
  3013. ticklength : function(a0) {
  3014. var args = arguments;
  3015. if (args.length == 0) {
  3016. return this.ticklength$1();
  3017. }
  3018. return this.ticklength$0(a0);
  3019. },
  3020. /** @expose */
  3021. startAt : function(a0) {
  3022. var args = arguments;
  3023. if (args.length == 0) {
  3024. return this.startAt$1();
  3025. }
  3026. return this.startAt$0(a0);
  3027. },
  3028. /** @expose */
  3029. shapeRectSize : function(a0) {
  3030. var args = arguments;
  3031. if (args.length == 0) {
  3032. return this.shapeRectSize$0();
  3033. }
  3034. return this.shapeRectSize$1(a0);
  3035. }
  3036. });
  3037. com_ibm_rave_ext_legend_continuous_ContinuousLegend.getGradientIdCount = function() {
  3038. var gradientIdCount = rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().getData("GRADIENT_ID_COUNT_KEY");
  3039. if (!gradientIdCount) {
  3040. gradientIdCount = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.GradientIdCount();
  3041. rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().putData("GRADIENT_ID_COUNT_KEY", gradientIdCount);
  3042. }
  3043. return gradientIdCount;
  3044. };
  3045. com_ibm_rave_ext_legend_continuous_ContinuousLegend.OrientationValues = function(){};
  3046. com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickPlacementValues = function(){};
  3047. com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickEntrySelectors = function(){};
  3048. com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickEntryBBoxes = function() {
  3049. this.largestLabelWidth = 0;
  3050. this.largestLabelHeight = 0;
  3051. this.tickBboxes = [];
  3052. this.labelBboxes = [];
  3053. this.labelTexts = [];
  3054. this.labelBboxesPoints = [];
  3055. };
  3056. com_ibm_rave_ext_legend_continuous_ContinuousLegend.ShapeSelectors = function(){};
  3057. com_ibm_rave_ext_legend_continuous_ContinuousLegend.GradientIdCount = rave['internal']['Declare']({
  3058. idCount : 0
  3059. });
  3060. //com_ibm_rave_ext_legend_continuous_ContinuousLegend.AXIS_METHOD = "axis";
  3061. //com_ibm_rave_ext_legend_continuous_ContinuousLegend.STAGGER_METHOD = "stagger";
  3062. //com_ibm_rave_ext_legend_continuous_ContinuousLegend.CONTINUOUS_METHOD = "continuous";
  3063. //com_ibm_rave_ext_legend_continuous_ContinuousLegend.AXIS_DEFAULT_COLOR = "black";
  3064. //com_ibm_rave_ext_legend_continuous_ContinuousLegend.GRADIENT_ID = "legendGradient";
  3065. com_ibm_rave_ext_legend_continuous_ContinuousLegend.AXIS_DEFAULT_MINOR_DIMENSION_LEN = 1;
  3066. com_ibm_rave_ext_legend_continuous_ContinuousLegend.MAX_TICK_LABEL_DIGITS = 6;
  3067. com_ibm_rave_ext_legend_continuous_ContinuousLegend.MINOR_SHAPE_MAX_LENGTH = 40;
  3068. com_ibm_rave_ext_legend_continuous_ContinuousLegend.MIN_DATA_COUNT = 2;
  3069. com_ibm_rave_ext_legend_continuous_ContinuousLegend.DEFAULT_STAGGER_RECT_SIDE_LEN = 20.0;
  3070. com_ibm_rave_ext_legend_continuous_ContinuousLegend.MAX_STAGGER_SQUARE_COUNT = 15;
  3071. com_ibm_rave_ext_legend_continuous_ContinuousLegend.PREFERRED_DECIMAL_PLACES_COUNT = 4;
  3072. //com_ibm_rave_ext_legend_continuous_ContinuousLegend.GRADIENT_ID_COUNT_KEY = "GRADIENT_ID_COUNT_KEY";
  3073. //com_ibm_rave_ext_legend_continuous_ContinuousLegend.DEFAULT_METHOD = "continuous";
  3074. // $source: com/ibm/rave/ext/legend/size/NestedSizeLegend
  3075. /************************************************************************
  3076. ** IBM Confidential
  3077. **
  3078. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  3079. **
  3080. ** (C) Copyright IBM Corp. 2017
  3081. **
  3082. ** The source code for this program is not published or otherwise divested of its trade secrets,
  3083. ** irrespective of what has been deposited with the U.S. Copyright Office.
  3084. ************************************************************************/
  3085. // GENERATED
  3086. //@import com/ibm/rave/ext/legend/AbstractLegend (loadtime) // superclass
  3087. /**
  3088. * A nested size legend displays a set of shapes representing a range of sizes. Each shape is displayed with a corresponding value label, representing the size which would appear for in a visualization for that particular value. Note that this size legend assumes size values are given as <em>area</em> (in pixels), not diameter, width/height, etc. This is consistent with the Rave.svg.symbol generator, which accepts area values when generating shapes.
  3089. */
  3090. var com_ibm_rave_ext_legend_size_NestedSizeLegend = rave['internal']['Declare'](com_ibm_rave_ext_legend_AbstractLegend, {
  3091. //_shapeDisplay : null,
  3092. //_defs : null,
  3093. //_clipId : null,
  3094. _tickPadding : 20.0,
  3095. constructor : function() {
  3096. this._shapeDisplay = "full";
  3097. {
  3098. this.scaleArguments(3);
  3099. }
  3100. },
  3101. /** @expose */
  3102. legend : function(g) {
  3103. var self = this;
  3104. g.each(function(data, index, groupIndex) {
  3105. var gSelection = self.prepareLegendGroup(this);
  3106. self.prepareLegendBounds(gSelection);
  3107. var labelFormat = self.getLabelFormat();
  3108. var textFlow = self.createTextFlowComponent();
  3109. var titleSelector = self.prepareLegendTitle(gSelection, textFlow);
  3110. if (titleSelector && !titleSelector.node().rave_getParentNode()) {
  3111. return;
  3112. }
  3113. var titleVerticalShift = self.calculateTitleVerticalShift(titleSelector);
  3114. var availableWidth = self.size()[0] - self.insets()["left"] - self.insets()["right"];
  3115. var availableHeight = self.size()[1] - self.insets()["top"] - self.insets()["bottom"] - titleVerticalShift;
  3116. self.alignTitleHorizontally(titleSelector);
  3117. if (availableHeight <= 0 || availableWidth <= 0 || !((self.scale()))) {
  3118. return;
  3119. }
  3120. var scaleData = self.getData();
  3121. if (!scaleData) {
  3122. return;
  3123. }
  3124. var ticks = (scaleData).reverse();
  3125. var maxArea = + (self.scale().call(null, ticks[0], 0, 0));
  3126. var minArea = + (self.scale().call(null, ticks[ticks.length - 1], 0, 0));
  3127. var maxSymbolHeight = 2 * com_ibm_rave_ext_legend_size_NestedSizeLegend.areaToCircleRadius(Math.max(maxArea, minArea));
  3128. var symbol = rave.svg.symbol().type("circle").size(function(data, index, groupIndex) {
  3129. return + (self.scale().call(null, data, 0, 0));
  3130. });
  3131. var container = new rave['internal']['RectStruct'](self.insets()["left"], self.insets()["top"] + titleVerticalShift, availableWidth, availableHeight);
  3132. var entryBounds = new rave['internal']['RectStruct'](container.x + self.entryInsets()["left"], container.y + self.entryInsets()["top"], container.width - self.entryInsets()["left"] - self.entryInsets()["right"], container.height - self.entryInsets()["top"] - self.entryInsets()["bottom"]);
  3133. var entryShiftX = 0;
  3134. if ("full" == self._shapeDisplay) {
  3135. entryShiftX = entryShiftX + (maxSymbolHeight / 2.0);
  3136. }
  3137. var legendContainer = gSelection.append("g").classed("legendContainer", true).attr("clip-path", self._clipId != null ? "url(#" + self._clipId + ")" : null);
  3138. if (self._defs && self._clipId != null) {
  3139. var clipPath = self._defs.selectAll("#" + self._clipId).data([0]);
  3140. clipPath.enter().append("clipPath").attr("id", self._clipId).append("rect");
  3141. clipPath.select("rect").attr("x", entryBounds.x).attr("width", entryBounds.width).attr("y", titleVerticalShift).attr("height", availableHeight);
  3142. }
  3143. var transformEntry = function(data, index, groupIndex) {
  3144. var x = com_ibm_rave_ext_legend_size_NestedSizeLegend.areaToCircleRadius(+ (self.scale().call(null, data, 0, 0)));
  3145. return "translate(0, " + (maxSymbolHeight - x) + ")";
  3146. };
  3147. var transformCenterEntry = function(data, index, groupIndex) {
  3148. var x = 2 * com_ibm_rave_ext_legend_size_NestedSizeLegend.areaToCircleRadius(+ (self.scale().call(null, data, 0, 0)));
  3149. return "translate(0, " + (maxSymbolHeight - x) + ")";
  3150. };
  3151. var legendEntries = legendContainer.selectAll(".legendEntry").data(ticks);
  3152. var legendEntriesEnter = legendEntries.enter().append("g").classed("legendEntry", true);
  3153. legendEntriesEnter.append("path").classed("legendShape", true);
  3154. legendEntriesEnter.append("line").classed("legendTickLine", true);
  3155. legendEntriesEnter.append("text").classed("legendLabel", true);
  3156. legendEntries.attr("transform", "translate(" + (entryBounds.x + entryShiftX) + "," + entryBounds.y + ")");
  3157. legendEntries.select(".legendShape").attr("d", symbol).attr("transform", transformEntry).style("stroke", (self.shapeBorderColor()) ? rave.rgb(self.shapeBorderColor()).toString() : null);
  3158. legendEntries.select(".legendTickLine").attr("x1", 0).attr("x2", maxSymbolHeight / 2 + self._tickPadding).attr("transform", transformCenterEntry);
  3159. var labelX = maxSymbolHeight / 2 + + (self.labelPadding()) + self._tickPadding;
  3160. var label = legendEntries.select(".legendLabel");
  3161. label.attr("x", labelX).attr("transform", transformCenterEntry).attr("dy", function(data, index, groupIndex) {
  3162. return self.getTextDyPlacement(this);
  3163. }).text(labelFormat);
  3164. textFlow.extent(~~ (Math.max(0, entryBounds.width - labelX - entryShiftX)), ~~ (label.node().getBBox().height)).flow(label);
  3165. });
  3166. },
  3167. /**
  3168. * Tick padding controls the distance between the largest legend symbol (i.e. circle) and the symbol labels. This has the effect of controlling the length of the line connecting each legend symbol to it's label.
  3169. * @param (double) padding Distance (in pixels) between the largest symbol's perimeter and labels.
  3170. * @return (com.ibm.rave.ext.legend.size.NestedSizeLegend) This legend component.
  3171. */
  3172. tickPadding$0 : function(padding) {
  3173. this._tickPadding = Math.max(0.0, padding);
  3174. return this;
  3175. },
  3176. /**
  3177. * Retrieve current tick padding value. Default is 20.
  3178. */
  3179. tickPadding$1 : function() {
  3180. return this._tickPadding;
  3181. },
  3182. /**
  3183. * Shapes can be displayed in "full" or "half". <em>Full</em> (the default) will center the shapes such that its left-most extent appears inside the left-most bounds of the legend. <em>Half</em> will center the shapes at the left-most boundary of the legend; such that a clipping rectangle can be used to visually cut the shapes in half. When using the "half" method, it is recommended to add a clip path, to prevent the legend elements from overflowing outside the bounds of the legend. See {@link #this.clip(rave['internal']['Selector'], String)} .
  3184. * @param (String) display Can be "full" or "half". Defaults to "full" when an invalid value is entered.
  3185. * @return (com.ibm.rave.ext.legend.size.NestedSizeLegend) This NestedSizeLegend component.
  3186. */
  3187. shapeDisplay$0 : function(display) {
  3188. this._shapeDisplay = "half" == display ? display : "full";
  3189. return this;
  3190. },
  3191. /**
  3192. * Retrieve current shape display method. Default is "full".
  3193. */
  3194. shapeDisplay$1 : function() {
  3195. return this._shapeDisplay;
  3196. },
  3197. /**
  3198. * A clip path can be applied automatically to hide any legend elements from overlapping the legend bounds. Both a <defs> element and a unique ID must be supplied in order for the clip path to be generated.
  3199. * @param (rave['internal']['Selector']) defs A selector into which a <clippath> element will be added.
  3200. * @param (String) id An id unique to the entire document containing the legend.
  3201. * @return (com.ibm.rave.ext.legend.size.NestedSizeLegend) This NestedSizeLegend component.
  3202. */
  3203. /** @expose */
  3204. clip : function(defs, id) {
  3205. this._defs = defs;
  3206. this._clipId = id;
  3207. return this;
  3208. },
  3209. /** @expose */
  3210. tickPadding : function(a0) {
  3211. var args = arguments;
  3212. if (args.length == 0) {
  3213. return this.tickPadding$1();
  3214. }
  3215. return this.tickPadding$0(a0);
  3216. },
  3217. /** @expose */
  3218. shapeDisplay : function(a0) {
  3219. var args = arguments;
  3220. if (args.length == 0) {
  3221. return this.shapeDisplay$1();
  3222. }
  3223. return this.shapeDisplay$0(a0);
  3224. }
  3225. });
  3226. com_ibm_rave_ext_legend_size_NestedSizeLegend.areaToCircleRadius = function(area) {
  3227. return Math.sqrt(area / Math.PI);
  3228. };
  3229. com_ibm_rave_ext_legend_size_NestedSizeLegend.SHAPE_SYMBOL_TYPE = "circle";
  3230. com_ibm_rave_ext_legend_size_NestedSizeLegend.SHAPE_DISPLAY_FULL = "full";
  3231. com_ibm_rave_ext_legend_size_NestedSizeLegend.SHAPE_DISPLAY_HALF = "half";
  3232. com_ibm_rave_ext_legend_size_NestedSizeLegend.TICK_PADDING_DEFAULT = 20.0;
  3233. })();
  3234. // This is the end of the factory method defined in the header. Added only during a full compiled JS build.
  3235. return rave;
  3236. }));