rave-utilities.js 143 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273
  1. // During the rave-utilities.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. var navigation = factory(global,rave);
  12. module.exports = rave;
  13. } else if (typeof define === "function" && define.amd) {
  14. // AMD
  15. define(['rave'], function(rave) {
  16. return factory(global,rave);
  17. });
  18. } else {
  19. // probably loading via script tag. run as is, setting stuff on rave
  20. factory(global,global['rave']);
  21. }
  22. }((1, eval)('this'), function (_global, _rave) {(function() {
  23. var $ = {};
  24. // $source: com/ibm/rave/ext/utilities/internal/nativeImpl/ModuleHeader
  25. /************************************************************************
  26. ** IBM Confidential
  27. **
  28. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  29. **
  30. ** (C) Copyright IBM Corp. 2014
  31. **
  32. ** The source code for this program is not published or otherwise divested of its trade secrets,
  33. ** irrespective of what has been deposited with the U.S. Copyright Office.
  34. ************************************************************************/
  35. // setup
  36. var global = typeof _global !== "undefined" ? _global : (1, eval)('this');
  37. var rave = typeof _rave !== "undefined" ? _rave : global['rave'];
  38. com_ibm_rave_core_Rave = rave;
  39. rave["internal"]["Declare"] = rave["_"]["com_ibm_rave_core_nativeImpl_Declare"];
  40. // $source: com/ibm/rave/ext/axis/RaveAxis
  41. /************************************************************************
  42. ** IBM Confidential
  43. **
  44. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  45. **
  46. ** (C) Copyright IBM Corp. 2017
  47. **
  48. ** The source code for this program is not published or otherwise divested of its trade secrets,
  49. ** irrespective of what has been deposited with the U.S. Copyright Office.
  50. ************************************************************************/
  51. // GENERATED
  52. //@import com/ibm/rave/ext/axis/tickLabelDrop/TickLabelDrop (runtime) // new
  53. /**
  54. * A factory of extended axis capabilities.
  55. */
  56. var com_ibm_rave_ext_axis_RaveAxis = rave['internal']['Declare']({
  57. /**
  58. * @return (com.ibm.rave.ext.axis.tickLabelDrop.TickLabelDrop) a new instance of {@link TickLabelDrop}
  59. * @see TickLabelDrop
  60. */
  61. /** @expose */
  62. tickLabelDrop : function() {
  63. return new com_ibm_rave_ext_axis_tickLabelDrop_TickLabelDrop();
  64. }
  65. //constructor : function() {}
  66. });
  67. com_ibm_rave_ext_axis_RaveAxis.getRegistrationStatus = function() {
  68. var registrationStatus = rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().getData("RAVEAXIS_EXTENSION_REGISTRATION_STATUS_KEY");
  69. if (!registrationStatus) {
  70. registrationStatus = new com_ibm_rave_ext_axis_RaveAxis.RegistrationStatus();
  71. rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().putData("RAVEAXIS_EXTENSION_REGISTRATION_STATUS_KEY", registrationStatus);
  72. }
  73. return registrationStatus;
  74. };
  75. /**
  76. * Register all extended axis capabilities.
  77. * @return (boolean) true if registration was successful, false otherwise
  78. */
  79. /** @expose */
  80. com_ibm_rave_ext_axis_RaveAxis.init = function() {
  81. var registrationStatus = com_ibm_rave_ext_axis_RaveAxis.getRegistrationStatus();
  82. if (!registrationStatus.registered) {
  83. registrationStatus.registered = rave.capabilities.extension("axis", function() {
  84. return com_ibm_rave_ext_axis_RaveAxis.INSTANCE;
  85. });
  86. }
  87. return registrationStatus.registered;
  88. };
  89. com_ibm_rave_ext_axis_RaveAxis.RegistrationStatus = rave['internal']['Declare']({
  90. registered : false
  91. });
  92. //com_ibm_rave_ext_axis_RaveAxis.AXIS_EXT = "axis";
  93. //com_ibm_rave_ext_axis_RaveAxis.EXTENSION_REGISTRATION_STATUS_KEY = "RAVEAXIS_EXTENSION_REGISTRATION_STATUS_KEY";
  94. com_ibm_rave_ext_axis_RaveAxis.INSTANCE = new com_ibm_rave_ext_axis_RaveAxis();
  95. // Auto initialization
  96. com_ibm_rave_ext_axis_RaveAxis.init();
  97. if (!rave.capabilities["axis"]) {
  98. rave.capabilities["axis"] = function() {
  99. return com_ibm_rave_ext_axis_RaveAxis.INSTANCE;
  100. };
  101. } else {
  102. console.log("Could not register extension: RaveAxis");
  103. }
  104. // $source: com/ibm/rave/ext/axis/tickLabelDrop/TickLabelDrop
  105. /************************************************************************
  106. ** IBM Confidential
  107. **
  108. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  109. **
  110. ** (C) Copyright IBM Corp. 2017
  111. **
  112. ** The source code for this program is not published or otherwise divested of its trade secrets,
  113. ** irrespective of what has been deposited with the U.S. Copyright Office.
  114. ************************************************************************/
  115. // GENERATED
  116. //@import com/ibm/rave/ext/position/drop/DropOverlap (runtime) // new
  117. /**
  118. * Utility for dropping overlapping tick labels.
  119. */
  120. var com_ibm_rave_ext_axis_tickLabelDrop_TickLabelDrop = rave['internal']['Declare'](rave['internal']['AbstractTickHandler'], {
  121. //drop : null,
  122. removeOverlapping : true,
  123. _$functionClassMethod : function() {
  124. var _$self = function(args) {
  125. if (args !== null || arguments.length > 1){
  126. args = Array.prototype.slice.call(arguments, 0);
  127. }
  128. {
  129. _$self.tickLabelDrop(args[0]);
  130. return null;
  131. }
  132. };
  133. return _$self;
  134. },
  135. constructor : function() {
  136. this.drop = new com_ibm_rave_ext_position_drop_DropOverlap();
  137. },
  138. /**
  139. * Set if the overlapping tick labels are to be removed from the axis, (otherwise, they will simply be hidden).
  140. * @param (boolean) remove <code>true</code> to indicate the overlapping tick labels are to be removed (the default), <code>false</code> will hide them.
  141. * @return (com.ibm.rave.ext.axis.tickLabelDrop.TickLabelDrop) this instance
  142. */
  143. remove$0 : function(remove) {
  144. this.removeOverlapping = remove;
  145. return this;
  146. },
  147. /**
  148. * @return (boolean) <code>true</code> if the overlapping tick labels are to be removed, <code>false</code> otherwise.
  149. */
  150. remove$1 : function() {
  151. return this.removeOverlapping;
  152. },
  153. /**
  154. * Resets the overlapping labels. If removing the labels, this does nothing. If not, this will make the labels visible again.
  155. * @param (rave['internal']['Selection']) ticks The selection containing the ticks to reset.
  156. */
  157. /** @expose */
  158. reset : function(ticks) {
  159. if (!this.removeOverlapping) {
  160. var labels = ticks.selectAll("text");
  161. this.drop.reset(labels);
  162. }
  163. },
  164. /**
  165. * Remove overlapping labels from the selection.
  166. * @param (rave['internal']['Selection']) axis The selection containing the axis.
  167. */
  168. /** @expose */
  169. tickLabelDrop : function(axis) {
  170. this.drop.remove(this.removeOverlapping);
  171. this.drop.dropOverlap(axis.selectAll("text"));
  172. },
  173. /** @expose */
  174. remove : function(a0) {
  175. var args = arguments;
  176. if (args.length == 0) {
  177. return this.remove$1();
  178. }
  179. return this.remove$0(a0);
  180. }
  181. });
  182. //com_ibm_rave_ext_axis_tickLabelDrop_TickLabelDrop.TEXT = "text";
  183. // $source: com/ibm/rave/ext/position/drop/DropOverlap
  184. /************************************************************************
  185. ** IBM Confidential
  186. **
  187. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  188. **
  189. ** (C) Copyright IBM Corp. 2017
  190. **
  191. ** The source code for this program is not published or otherwise divested of its trade secrets,
  192. ** irrespective of what has been deposited with the U.S. Copyright Office.
  193. ************************************************************************/
  194. // GENERATED
  195. /**
  196. * Utility for dropping overlapping elements.
  197. */
  198. var com_ibm_rave_ext_position_drop_DropOverlap = rave['internal']['Declare']({
  199. //quadTree : null,
  200. //extentPts : null,
  201. //hideCallback : null,
  202. //clampCallback : null,
  203. //showCallback : null,
  204. removeOverlapping : true,
  205. collisionFound : false,
  206. maxRadius : 0.0,
  207. labelGap : 0.0,
  208. clippingAllowed : true,
  209. _$functionClassMethod : function() {
  210. var _$self = function(args) {
  211. if (args !== null || arguments.length > 1){
  212. args = Array.prototype.slice.call(arguments, 0);
  213. }
  214. {
  215. _$self.dropOverlap(args[0]);
  216. return null;
  217. }
  218. };
  219. return _$self;
  220. },
  221. constructor : function() {
  222. this.quadTree = new rave['internal']['QuadTree']().x(com_ibm_rave_ext_position_drop_DropOverlap.fx).y(com_ibm_rave_ext_position_drop_DropOverlap.fy);
  223. {
  224. var self = this;
  225. this.hideCallback = function(args) {
  226. if (args !== null || arguments.length > 1){
  227. args = Array.prototype.slice.call(arguments, 0);
  228. }
  229. {
  230. if (self.removeOverlapping) {
  231. this.rave_getParentNode().removeChild(this);
  232. } else if (!(this.rave_hasProperty("__raveOverlapHidden__"))) {
  233. this.setAttribute("visibility", "hidden");
  234. this.rave_setProperty("__raveOverlapHidden__", "hidden");
  235. var count = ~~ (this.rave_getProperty(com_ibm_rave_ext_position_drop_DropOverlap.HIDDEN_COUNT));
  236. this.rave_setProperty(com_ibm_rave_ext_position_drop_DropOverlap.HIDDEN_COUNT, count + 1);
  237. }
  238. return null;
  239. }
  240. };
  241. this.clampCallback = function(args) {
  242. if (args !== null || arguments.length > 1){
  243. args = Array.prototype.slice.call(arguments, 0);
  244. }
  245. {
  246. var moveX = 0.0;
  247. var moveY = 0.0;
  248. var rect = this.getBBox();
  249. var extent = self.quadTree.extent();
  250. if (rect.x < extent[0][0]) {
  251. moveX = extent[0][0] - rect.x;
  252. } else if (rect.x + rect.width > extent[1][0]) {
  253. moveX = extent[1][0] - (rect.x + rect.width);
  254. }
  255. if (rect.y < extent[0][1]) {
  256. moveY = extent[0][1] - rect.y;
  257. } else if (rect.y + rect.height > extent[1][1]) {
  258. moveY = extent[1][1] - (rect.y + rect.height);
  259. }
  260. var node = rave.select(this);
  261. var nodeXcoordinate = node.attr("x");
  262. var nodeYcoordinate = node.attr("y");
  263. var x = (nodeXcoordinate == null) ? rect.x : + (nodeXcoordinate);
  264. var y = (nodeYcoordinate == null) ? rect.y : + (nodeYcoordinate);
  265. node.attr("x", x + moveX);
  266. node.attr("y", y + moveY);
  267. return null;
  268. }
  269. };
  270. this.showCallback = function(args) {
  271. if (args !== null || arguments.length > 1){
  272. args = Array.prototype.slice.call(arguments, 0);
  273. }
  274. {
  275. if (this.rave_hasProperty("__raveOverlapHidden__")) {
  276. this.rave_removeProperty("__raveOverlapHidden__");
  277. var count = ~~ (this.rave_getProperty(com_ibm_rave_ext_position_drop_DropOverlap.HIDDEN_COUNT));
  278. if (count <= 1) {
  279. this.rave_removeProperty(com_ibm_rave_ext_position_drop_DropOverlap.HIDDEN_COUNT);
  280. this.removeAttribute("visibility");
  281. } else {
  282. this.rave_setProperty(com_ibm_rave_ext_position_drop_DropOverlap.HIDDEN_COUNT, count - 1);
  283. }
  284. }
  285. return null;
  286. }
  287. };
  288. }
  289. },
  290. /**
  291. * Configure how much space to leave between nodes (default is 0)
  292. * @param (double) gap size of space
  293. */
  294. /** @expose */
  295. setOverlapGap : function(gap) {
  296. this.labelGap = gap;
  297. },
  298. /**
  299. * Node must be fully inside extent to be considered for overlap tests
  300. */
  301. /** @expose */
  302. noClipping : function() {
  303. this.clippingAllowed = false;
  304. },
  305. /**
  306. * Remove the overlapping elements in the selection. Assumes the elements return a valid bounding box. If no extent is provided, the selection's owner node will be used to calculate one.
  307. * @param (rave['internal']['Selection']) s The elements.
  308. */
  309. /** @expose */
  310. dropOverlap : function(s) {
  311. var node;
  312. if (s && (node = s.node())) {
  313. var extent = this.extentPts;
  314. if (!extent) {
  315. var bbox = node.rave_getOwner().getBBox();
  316. var ownerExtent = [[bbox.x, bbox.y], [bbox.x + bbox.width, bbox.y + bbox.height]];
  317. extent = ownerExtent;
  318. }
  319. var extentPoints = extent;
  320. var root = this.quadTree.extent(extent)([]);
  321. var self = this;
  322. s.each(function(data, index, groupIndex) {
  323. if (this) {
  324. self.collisionFound = false;
  325. var overlapNode = new com_ibm_rave_ext_position_drop_DropOverlap.OverlapNode(this, self.labelGap, self.clippingAllowed);
  326. if (self.isCollisionCandidate(this, overlapNode, extentPoints)) {
  327. root.visit(self.collide(overlapNode, self.maxRadius));
  328. if (!self.collisionFound) {
  329. self.showCallback.call(this);
  330. root.add(overlapNode);
  331. self.maxRadius = Math.max(self.maxRadius, overlapNode.radius);
  332. } else {
  333. self.hideCallback.call(this);
  334. }
  335. }
  336. }
  337. });
  338. }
  339. },
  340. isCollisionCandidate : function(sceneNode, overlapNode, extentPoints) {
  341. var isCandidate;
  342. var point0 = extentPoints[0];
  343. var extentLeft = point0[0];
  344. var extentTop = point0[1];
  345. var point1 = extentPoints[1];
  346. var extentRight = point1[0];
  347. var extentBottom = point1[1];
  348. if (this.clippingAllowed) {
  349. isCandidate = overlapNode.boundingRect.left <= extentRight && overlapNode.boundingRect.top <= extentBottom && overlapNode.boundingRect.right >= extentLeft && overlapNode.boundingRect.bottom >= extentTop;
  350. } else {
  351. var isHalfInside = false;
  352. var isFullyInside = (overlapNode.boundingRect.left + this.labelGap / 2) >= extentLeft && overlapNode.boundingRect.top >= extentTop && (overlapNode.boundingRect.right - this.labelGap / 2) <= extentRight && overlapNode.boundingRect.bottom <= extentBottom;
  353. if (!isFullyInside) {
  354. isHalfInside = (((overlapNode.boundingRect.left + overlapNode.boundingRect.width / 2 < extentRight && overlapNode.boundingRect.right > extentRight) || (overlapNode.boundingRect.left < extentLeft && overlapNode.boundingRect.right - overlapNode.boundingRect.width / 2 > extentLeft)) && (overlapNode.boundingRect.top > extentTop && overlapNode.boundingRect.bottom < extentBottom)) || (((overlapNode.boundingRect.top < extentTop && overlapNode.boundingRect.top + overlapNode.boundingRect.height / 2 > extentTop) || (overlapNode.boundingRect.top + overlapNode.boundingRect.height / 2 < extentBottom && overlapNode.boundingRect.bottom > extentBottom)) && (overlapNode.boundingRect.left > extentLeft && overlapNode.boundingRect.right < extentRight));
  355. if (isHalfInside) {
  356. this.clampCallback.call(sceneNode);
  357. } else {
  358. this.hideCallback.call(sceneNode);
  359. }
  360. }
  361. isCandidate = isFullyInside || isHalfInside;
  362. }
  363. return isCandidate;
  364. },
  365. /**
  366. * Determine if a node collides with any in the quadtree.
  367. * @param (com.ibm.rave.ext.position.drop.DropOverlap.OverlapNode) node The node to compare against.
  368. * @param (double) radius The longest radius of the visited nodes.
  369. * @return (rave['internal']['Visitor']) The visiting function.
  370. */
  371. collide : function(node, radius) {
  372. var nx1, nx2, ny1, ny2;
  373. nx1 = node.boundingRect.left - radius;
  374. nx2 = node.boundingRect.right + radius;
  375. ny1 = node.boundingRect.top - radius;
  376. ny2 = node.boundingRect.bottom + radius;
  377. var self = this;
  378. return function(qtNode, x1, y1, x2, y2) {
  379. if (self.collisionFound) {
  380. return true;
  381. }
  382. if (qtNode.point && qtNode.point.node != node.node) {
  383. self.collisionFound = com_ibm_rave_ext_position_drop_DropOverlap.intersect(node.boundingRect, qtNode.point.boundingRect);
  384. }
  385. var isOutsideQuad = x1 > nx2 || x2 < nx1 || y1 > ny2 || y2 < ny1;
  386. return self.collisionFound || isOutsideQuad;
  387. };
  388. },
  389. /**
  390. * When using the default hide/show functionality, set if the overlapping elements are to be removed (otherwise, they will be hidden).
  391. * @param (boolean) remove <code>true</code> to indicate the overlapping elements are to be removed (the default), <code>false</code> will hide them.
  392. * @return (com.ibm.rave.ext.position.drop.DropOverlap) this instance
  393. */
  394. remove$0 : function(remove) {
  395. this.removeOverlapping = remove;
  396. return this;
  397. },
  398. /**
  399. * @return (boolean) <code>true</code> if the overlapping elements are to be removed, <code>false</code> otherwise (they will be hidden).
  400. */
  401. remove$1 : function() {
  402. return this.removeOverlapping;
  403. },
  404. /**
  405. * Returns the current extent, which, if not specified, defaults to the selection's owner's bounding box.
  406. * @return (rave['internal']['Point[]']) an array of points [[x0,y0], [x1, y1]]
  407. */
  408. extent$0 : function() {
  409. return this.extentPts;
  410. },
  411. /**
  412. * Sets the current extent and returns this object. The extent must be specified as a two-dimensional array [[x0, y0], [x1, y1]], where x0 and y0 are the lower bounds of the extent, and x1 and y1 are the upper bounds of the extent.
  413. * @param (rave['internal']['Point[]']) pt A two-dimensional array [[x0, y0], [x1, y1]], where x0 and y0 are the lower bounds of the extent, and x1 and y1 are the upper bounds of the extent
  414. * @return (com.ibm.rave.ext.position.drop.DropOverlap) an instance of this object
  415. */
  416. extent$1 : function(pt) {
  417. this.extentPts = pt;
  418. return this;
  419. },
  420. /**
  421. * Resets the visibility of the overlapping nodes that were dropped. If the nodes were removed, this has no effect.
  422. * @param (rave['internal']['Selection']) s The elements.
  423. * @return (com.ibm.rave.ext.position.drop.DropOverlap) an instance of this object
  424. */
  425. /** @expose */
  426. reset : function(s) {
  427. var self = this;
  428. s.each(function(data, index, groupIndex) {
  429. self.showCallback.call(this);
  430. });
  431. return this;
  432. },
  433. /** @expose */
  434. remove : function(a0) {
  435. var args = arguments;
  436. if (args.length == 0) {
  437. return this.remove$1();
  438. }
  439. return this.remove$0(a0);
  440. },
  441. /** @expose */
  442. extent : function(a0) {
  443. var args = arguments;
  444. if (args.length == 0) {
  445. return this.extent$0();
  446. }
  447. return this.extent$1(a0);
  448. }
  449. });
  450. /**
  451. * Are the 2 rectangles intersecting?
  452. * @param (rave['internal']['NodeRect']) r1 First rectangle
  453. * @param (rave['internal']['NodeRect']) r2 Second rectangle
  454. * @return (boolean) <code>true</code> if the rectangles intersect, <code>false</code> otherwise.
  455. */
  456. com_ibm_rave_ext_position_drop_DropOverlap.intersect = function(r1, r2) {
  457. return !(r2.left > r1.right || r2.right < r1.left || r2.top > r1.bottom || r2.bottom < r1.top);
  458. };
  459. /**
  460. * Container for the quad tree element nodes. This is needed so we can cache the bounding rect, which is an expensive call in JavaScript.
  461. */
  462. com_ibm_rave_ext_position_drop_DropOverlap.OverlapNode = function(sceneNode, gap, useBoundingClientRect) {
  463. this.node = sceneNode;
  464. var bbox = sceneNode.getBBox();
  465. var bounding = new rave['internal']['RectStruct'](bbox.x, bbox.y, bbox.width, bbox.height);
  466. if (useBoundingClientRect) {
  467. bounding = rave['internal']['MatrixUtil'].transformBounds(bounding, this.node.getCTM());
  468. }
  469. this.boundingRect = new rave['internal']['NodeRect'](bounding.x - gap / 2, bounding.x + bounding.width + gap / 2, bounding.y + bounding.height, bounding.y, bounding.width + gap, bounding.height);
  470. this.radius = 0.5 * Math.max(bounding.width, bounding.height);
  471. this.x = bounding.x + 0.5 * bounding.width;
  472. this.y = bounding.y + 0.5 * bounding.height;
  473. };
  474. //com_ibm_rave_ext_position_drop_DropOverlap.VISIBILITY = "visibility";
  475. //com_ibm_rave_ext_position_drop_DropOverlap.HIDDEN = "hidden";
  476. /** @expose */
  477. com_ibm_rave_ext_position_drop_DropOverlap.HIDDEN_FLAG = "__raveOverlapHidden__";
  478. /** @expose */
  479. com_ibm_rave_ext_position_drop_DropOverlap.HIDDEN_COUNT = "__hiddenCount__";
  480. com_ibm_rave_ext_position_drop_DropOverlap.fx = function(node, index) {
  481. return node.x;
  482. };
  483. com_ibm_rave_ext_position_drop_DropOverlap.fy = function(node, index) {
  484. return node.y;
  485. };
  486. // $source: com/ibm/rave/ext/position/RavePosition
  487. /************************************************************************
  488. ** IBM Confidential
  489. **
  490. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  491. **
  492. ** (C) Copyright IBM Corp. 2017
  493. **
  494. ** The source code for this program is not published or otherwise divested of its trade secrets,
  495. ** irrespective of what has been deposited with the U.S. Copyright Office.
  496. ************************************************************************/
  497. // GENERATED
  498. //@import com/ibm/rave/ext/position/place/LabelPositioning (runtime) // new
  499. //@import com/ibm/rave/ext/position/drop/DropOverlap (runtime) // new
  500. /**
  501. * A factory of extended positioning capabilities.
  502. */
  503. var com_ibm_rave_ext_position_RavePosition = rave['internal']['Declare']({
  504. /**
  505. * @return (com.ibm.rave.ext.position.place.LabelPositioning) a new instance of {@link LabelPositioning}
  506. * @see LabelPositioning
  507. */
  508. /** @expose */
  509. place : function() {
  510. return new com_ibm_rave_ext_position_place_LabelPositioning();
  511. },
  512. /**
  513. * @return (com.ibm.rave.ext.position.drop.DropOverlap) a new instance of {@link DropOverlap}
  514. * @see DropOverlap
  515. */
  516. /** @expose */
  517. drop : function() {
  518. return new com_ibm_rave_ext_position_drop_DropOverlap();
  519. }
  520. //constructor : function() {}
  521. });
  522. com_ibm_rave_ext_position_RavePosition.getRegistrationStatus = function() {
  523. var registrationStatus = rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().getData("RAVEPOSITION_EXTENSION_REGISTRATION_STATUS_KEY");
  524. if (!registrationStatus) {
  525. registrationStatus = new com_ibm_rave_ext_position_RavePosition.RegistrationStatus();
  526. rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().putData("RAVEPOSITION_EXTENSION_REGISTRATION_STATUS_KEY", registrationStatus);
  527. }
  528. return registrationStatus;
  529. };
  530. /**
  531. * Register all extended positioning capabilities.
  532. * @return (boolean) true if registration was successful, false otherwise
  533. */
  534. /** @expose */
  535. com_ibm_rave_ext_position_RavePosition.init = function() {
  536. var registrationStatus = com_ibm_rave_ext_position_RavePosition.getRegistrationStatus();
  537. if (!registrationStatus.registered) {
  538. registrationStatus.registered = rave.capabilities.extension("position", function() {
  539. return com_ibm_rave_ext_position_RavePosition.INSTANCE;
  540. });
  541. }
  542. return registrationStatus.registered;
  543. };
  544. com_ibm_rave_ext_position_RavePosition.RegistrationStatus = rave['internal']['Declare']({
  545. registered : false
  546. });
  547. //com_ibm_rave_ext_position_RavePosition.POSITION_EXT = "position";
  548. //com_ibm_rave_ext_position_RavePosition.EXTENSION_REGISTRATION_STATUS_KEY = "RAVEPOSITION_EXTENSION_REGISTRATION_STATUS_KEY";
  549. com_ibm_rave_ext_position_RavePosition.INSTANCE = new com_ibm_rave_ext_position_RavePosition();
  550. // Auto initialization
  551. com_ibm_rave_ext_position_RavePosition.init();
  552. if (!rave.capabilities["position"]) {
  553. rave.capabilities["position"] = function() {
  554. return com_ibm_rave_ext_position_RavePosition.INSTANCE;
  555. };
  556. } else {
  557. console.log("Could not register extension: RavePosition");
  558. }
  559. // $source: com/ibm/rave/ext/position/place/LabelPositioning
  560. /************************************************************************
  561. ** IBM Confidential
  562. **
  563. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  564. **
  565. ** (C) Copyright IBM Corp. 2017
  566. **
  567. ** The source code for this program is not published or otherwise divested of its trade secrets,
  568. ** irrespective of what has been deposited with the U.S. Copyright Office.
  569. ************************************************************************/
  570. // GENERATED
  571. /**
  572. * The Label Mover utility tries to resolve label overlaps by moving them to around the chart into better positions.
  573. */
  574. var com_ibm_rave_ext_position_place_LabelPositioning = rave['internal']['Declare']({
  575. //event : null,
  576. //lab : null,
  577. //anc : null,
  578. //_energy : null,
  579. //_schedule : null,
  580. totalDistance : 1.7976931348623157E308,
  581. w : 1,
  582. h : 1,
  583. malpha : 0,
  584. max_move : 5.0,
  585. max_angle : 0.5,
  586. acc : 0,
  587. rej : 0,
  588. w_len : 0.2,
  589. w_inter : 1.0,
  590. w_lab2 : 30.0,
  591. w_lab_anc : 30.0,
  592. w_orient : 3.0,
  593. currT : 0,
  594. nsweeps : 500,
  595. constructor : function() {
  596. this.event = rave['internal']['Dispatcher'].create("start", "tick", "end");
  597. this.lab = [];
  598. this.anc = [];
  599. },
  600. /**
  601. * Sets the function for computing energy values, function that will be called by the Labeler class to get the data values
  602. * @param (rave['internal']['ValueFunction']) valueFn The function for computing data values
  603. * @return (com.ibm.rave.ext.position.place.LabelPositioning) this labelPlacement instance itself
  604. */
  605. energy$0 : function(valueFn) {
  606. this._energy = valueFn;
  607. return this;
  608. },
  609. /**
  610. * Sets the function for computing energy values, function that will be called by the Labeler class to get the data values
  611. * @param (Number) value the new energy value
  612. * @return (com.ibm.rave.ext.position.place.LabelPositioning) this labelPlacement instance itself
  613. */
  614. energy$1 : function(value) {
  615. this._energy = value;
  616. return this;
  617. },
  618. /**
  619. * Gets the energy value function
  620. * @return (Object) the value function
  621. */
  622. energy$2 : function() {
  623. return this._energy;
  624. },
  625. /**
  626. * Sets the function for computing schedule values, function that will be called by the Labeler class to get the data values
  627. * @param (rave['internal']['ValueFunction']) valueFn The function for computing data values
  628. * @return (com.ibm.rave.ext.position.place.LabelPositioning) this labelPlacement instance itself
  629. */
  630. schedule$0 : function(valueFn) {
  631. this._schedule = valueFn;
  632. return this;
  633. },
  634. /**
  635. * Gets the schedule value function
  636. * @return (Object) the value function
  637. */
  638. schedule$1 : function() {
  639. return this._schedule;
  640. },
  641. /**
  642. * In order to distinguish between the quality of different configurations in our search space, we need construct a function which takes as input a label configuration and outputs a score indicating the quality of the placements. In a labeling problem, the inputs are themselves functions of various parameters such as the amount of overlaps, distances between labels and their corresponding anchor points, and various stylistic preferences. This function, often an energy (also called cost or objective) function, is what we need to optimize. The default energy function includes penalties for:Label-label overlaps, Label-anchor overlaps, Labels far from the corresponding anchor, Leader line intersections, Poorly oriented labels
  643. * @param (int) index
  644. * @return (double) energy
  645. */
  646. calculateEnergy : function(index) {
  647. var m = this.lab.length;
  648. var ener = 0;
  649. var currentLabel = this.lab[index];
  650. var currentAnchor = this.anc[index];
  651. var dx = currentLabel["x"] - currentAnchor["x"];
  652. var dy = currentAnchor["y"] - currentLabel["y"];
  653. var dist = Math.sqrt(dx * dx + dy * dy);
  654. var overlap = true;
  655. if (dist > 0) {
  656. ener += dist * this.w_len;
  657. }
  658. dx /= dist;
  659. dy /= dist;
  660. if (dx > 0 && dy > 0) {
  661. ener += 0 * this.w_orient;
  662. } else if (dx < 0 && dy > 0) {
  663. ener += 1 * this.w_orient;
  664. } else if (dx < 0 && dy < 0) {
  665. ener += 2 * this.w_orient;
  666. } else {
  667. ener += 3 * this.w_orient;
  668. }
  669. var x21 = currentLabel["x"];
  670. var y21 = currentLabel["y"] - currentLabel["height"] + 2.0;
  671. var x22 = currentLabel["x"] + currentLabel["width"];
  672. var y22 = currentLabel["y"] + 2.0;
  673. var x11, x12, y11, y12, x_overlap, y_overlap, overlap_area;
  674. for (var i = 0; i < m; ++i) {
  675. var otherLabel = this.lab[i];
  676. var otherAnchor = this.anc[i];
  677. if (i != index) {
  678. overlap = com_ibm_rave_ext_position_place_LabelPositioning.leaderLinesIntersect(otherAnchor["x"], otherLabel["x"], otherAnchor["x"], otherLabel["x"], otherAnchor["y"], otherLabel["y"], otherAnchor["y"], otherLabel["y"]);
  679. if (overlap) {
  680. ener += this.w_inter;
  681. }
  682. x11 = otherLabel["x"];
  683. y11 = otherLabel["y"] - otherLabel["height"] + 2.0;
  684. x12 = otherLabel["x"] + otherLabel["width"];
  685. y12 = otherLabel["y"] + 2.0;
  686. x_overlap = Math.max(0, Math.min(x12, x22) - Math.max(x11, x21));
  687. y_overlap = Math.max(0, Math.min(y12, y22) - Math.max(y11, y21));
  688. overlap_area = x_overlap * y_overlap;
  689. ener += (overlap_area * this.w_lab2);
  690. }
  691. var r = otherAnchor["r"] * 2;
  692. x11 = otherAnchor["x"] - r;
  693. y11 = otherAnchor["y"] - r;
  694. x12 = otherAnchor["x"] + r;
  695. y12 = otherAnchor["y"] + r;
  696. x_overlap = Math.max(0, Math.min(x12, x22) - Math.max(x11, x21));
  697. y_overlap = Math.max(0, Math.min(y12, y22) - Math.max(y11, y21));
  698. overlap_area = x_overlap * y_overlap;
  699. ener += (overlap_area * this.w_lab_anc);
  700. }
  701. return ener;
  702. },
  703. /**
  704. * Randomly moves the label
  705. * @param (double) currTemp current temperature
  706. * @param (double) old_energy old energy
  707. * @param (int) i index
  708. */
  709. mcmove : function(currTemp, old_energy, i) {
  710. var currentLabel = this.lab[i];
  711. var currentAnchor = this.anc[i];
  712. var x_old = currentLabel["x"];
  713. var y_old = currentLabel["y"];
  714. currentLabel["x"] += (Math.random() - 0.5) * this.max_move;
  715. currentLabel["y"] += (Math.random() - 0.5) * this.max_move;
  716. this.compareOldEnergy(currTemp, old_energy, i, currentLabel, currentAnchor, x_old, y_old);
  717. },
  718. /**
  719. * Randomly rotates the label position
  720. * @param (double) currTemp current temperature
  721. * @param (double) old_energy old energy
  722. * @param (int) i index
  723. */
  724. mcrotate : function(currTemp, old_energy, i) {
  725. var currentLabel = this.lab[i];
  726. var currentAnchor = this.anc[i];
  727. var x_old = currentLabel["x"];
  728. var y_old = currentLabel["y"];
  729. var angle = (Math.random() - 0.5) * this.max_angle;
  730. var s = Math.sin(angle);
  731. var c = Math.cos(angle);
  732. currentLabel["x"] -= currentAnchor["x"];
  733. currentLabel["y"] -= currentAnchor["y"];
  734. var x_new = currentLabel["x"] * c - currentLabel["y"] * s;
  735. var y_new = currentLabel["x"] * s + currentLabel["y"] * c;
  736. currentLabel["x"] = x_new + currentAnchor["x"];
  737. currentLabel["y"] = y_new + currentAnchor["y"];
  738. this.compareOldEnergy(currTemp, old_energy, i, currentLabel, currentAnchor, x_old, y_old);
  739. },
  740. /**
  741. * Compares the energy of the Old and new position, if the energy of the new position is less the move happens
  742. * @param (double) currTemp current temperature
  743. * @param (double) old_energy old energy
  744. * @param (int) i index
  745. * @param (Object) currentLabel current label
  746. * @param (Object) currentAnchor current anchor
  747. * @param (double) x_old old x
  748. * @param (double) y_old old y
  749. */
  750. compareOldEnergy : function(currTemp, old_energy, i, currentLabel, currentAnchor, x_old, y_old) {
  751. if (currentLabel["x"] > this.w) {
  752. currentLabel["x"] = x_old;
  753. }
  754. if (currentLabel["x"] < 0) {
  755. currentLabel["x"] = x_old;
  756. }
  757. if (Math.abs(currentLabel["x"] - currentAnchor["x"]) > this.totalDistance) {
  758. currentLabel["x"] = x_old;
  759. }
  760. if (currentLabel["y"] > this.h) {
  761. currentLabel["y"] = y_old;
  762. }
  763. if (currentLabel["y"] < 0) {
  764. currentLabel["y"] = y_old;
  765. }
  766. if (Math.abs(currentLabel["y"] - currentAnchor["y"]) > this.totalDistance) {
  767. currentLabel["y"] = y_old;
  768. }
  769. var new_energy;
  770. if (this._energy != null) {
  771. new_energy = + ((typeof this._energy === "function") ? (this._energy).call(this, this.lab, i, -1) : this._energy);
  772. } else {
  773. new_energy = this.calculateEnergy(i);
  774. }
  775. var delta_energy = new_energy - old_energy;
  776. if (Math.random() < Math.exp(-delta_energy / currTemp)) {
  777. this.acc += 1;
  778. } else {
  779. currentLabel["x"] = x_old;
  780. currentLabel["y"] = y_old;
  781. this.rej += 1;
  782. }
  783. },
  784. /**
  785. * Gets the listener for the specified event type supported by labelPlacement: "start", "tick", and "end"
  786. * @param (String) type the type of event to get the listener for
  787. * @return (rave['internal']['RunFunction']) the listener for the specified event or null if none was registered
  788. */
  789. on$0 : function(type) {
  790. return this.event.on(type);
  791. },
  792. /**
  793. * Registers the specified listener to receive events of the specified type from the force layout. Currently, only "start", "tick", and "end" events are supported. The "tick" events are dispatched for each tick of the simulation. Listen to tick events to update the displayed positions of nodes and links. The "end" event is dispatched when the simulations internal cooling parameter reaches zero. The "start" is dispatched when the simulation starts
  794. * @param (String) type the type of the labelPlacement event to listen for
  795. * @param (rave['internal']['RunFunction']) listener the listener
  796. * @return (com.ibm.rave.ext.position.place.LabelPositioning) this labelPlacement instance itself
  797. */
  798. on$1 : function(type, listener) {
  799. this.event.on(type, listener);
  800. return this;
  801. },
  802. /**
  803. * Starts the simulation; this method must be called when the layout is first created, after assigning the nodes and links. On start, the layout initializes temperature and alpha.
  804. * @return (com.ibm.rave.ext.position.place.LabelPositioning) labelPlacement
  805. */
  806. /** @expose */
  807. start : function() {
  808. this.currT = 1.0;
  809. this.alpha(0.1);
  810. return this;
  811. },
  812. /**
  813. * Runs the one iteration/sweep of simulated annealing. This method can be used in conjunction with start and stop to compute a static layout. For example: <code> labelPlacement.start(); for (int i = 0; i < n; ++i) abelMover.tick(); abelMover.stop(); </code> The choice of initial positions can have a dramatic impact on how quickly the label mover finds a good position.
  814. * @return (boolean) true if the simulation has ended, false otherwise. in other words, it will return true if the layout's cooling parameter decays below some threshold and the simulation will stop. This is useful if you're calling this function in a loop and wanted to know when it is no longer necessary to call it again and break out of the loop.
  815. */
  816. /** @expose */
  817. tick : function() {
  818. var m = this.lab.length;
  819. var initialT = 1.0;
  820. if (this.currT < .005) {
  821. this.malpha = 0;
  822. var eo = new com_ibm_rave_ext_position_place_LabelPositioning.EventObject("end", 0);
  823. this.event[eo.type].call(eo, eo);
  824. return true;
  825. }
  826. for (var j = 0; j < m; ++j) {
  827. var i = Math.floor(Math.random() * this.lab.length);
  828. var old_energy;
  829. if (this._energy != null) {
  830. old_energy = + ((typeof this._energy === "function") ? (this._energy).call(this, this.lab, i, -1) : this._energy);
  831. } else {
  832. old_energy = this.calculateEnergy(i);
  833. }
  834. if (old_energy > 500) {
  835. if (Math.random() < 0.5) {
  836. this.mcmove(this.currT, old_energy, i);
  837. } else {
  838. this.mcrotate(this.currT, old_energy, i);
  839. }
  840. }
  841. }
  842. if (this._schedule) {
  843. this.currT = + (this._schedule.call(this, this.lab, -1, -1));
  844. } else {
  845. this.currT = (this.currT - (initialT / this.nsweeps));
  846. }
  847. var eo = new com_ibm_rave_ext_position_place_LabelPositioning.EventObject("tick", this.malpha);
  848. this.event[eo.type].call(eo, eo);
  849. return false;
  850. },
  851. /**
  852. * Stops the simulated anealing process, and label positioning.
  853. * @return (com.ibm.rave.ext.position.place.LabelPositioning) labelPlacement
  854. */
  855. /** @expose */
  856. stop : function() {
  857. return this.alpha(0);
  858. },
  859. /**
  860. * Controls the iterations used for sa alpha(0) stops ticks from running.
  861. */
  862. alpha : function(x) {
  863. if (this.malpha != 0) {
  864. if (x > 0) {
  865. this.malpha = x;
  866. } else {
  867. this.malpha = 0;
  868. }
  869. } else if (x > 0) {
  870. this.malpha = x;
  871. var eo = new com_ibm_rave_ext_position_place_LabelPositioning.EventObject("start", x);
  872. this.event[eo.type].call(eo, eo);
  873. var labelers = this;
  874. rave.timer(function(elapsed) {
  875. return labelers.tick();
  876. });
  877. }
  878. return this;
  879. },
  880. /**
  881. * Gets the maximum allowed distance from label and point
  882. * @return (double) maximumDistance
  883. */
  884. maxDistance$0 : function() {
  885. return this.totalDistance;
  886. },
  887. /**
  888. * Sets the maximum distance allowed between label and point
  889. * @param (double) maxDistance maximum distance allowed between label and point
  890. * @return (com.ibm.rave.ext.position.place.LabelPositioning) this labelPlacement instance itself
  891. */
  892. maxDistance$1 : function(maxDistance) {
  893. this.totalDistance = maxDistance;
  894. return this;
  895. },
  896. /**
  897. * Sets the number of iterations in which to attempt overlap resolution
  898. * @param (int) sweeps number of sweeps
  899. * @return (com.ibm.rave.ext.position.place.LabelPositioning) this labelPlacement instance itself
  900. */
  901. numberOfSweeps$0 : function(sweeps) {
  902. this.nsweeps = sweeps;
  903. return this;
  904. },
  905. /**
  906. * Gets the number of sweeps to attempt to overlap resolution
  907. * @return (int) number of sweeps
  908. */
  909. numberOfSweeps$1 : function() {
  910. return this.nsweeps;
  911. },
  912. /**
  913. * Gets the currentTemperature during the run.
  914. * @return (double) currentTemperature
  915. */
  916. /** @expose */
  917. currentTemperature : function() {
  918. return this.currT;
  919. },
  920. /**
  921. * The width is used to set the boundary conditions so that labels do not go outside the width of the figure. More specifically, Monte Carlo moves in which the labels cross the boundaries are rejected. If they are not specified, both the width defaults to 1.
  922. * @param (double) width width of the boundary
  923. * @return (com.ibm.rave.ext.position.place.LabelPositioning) this labelPlacement instance itself
  924. */
  925. width$0 : function(width) {
  926. this.w = width;
  927. return this;
  928. },
  929. /**
  930. * Gets width
  931. * @return (double) width
  932. */
  933. width$1 : function() {
  934. return this.w;
  935. },
  936. /**
  937. * The height is used to set the boundary conditions so that labels do not go outside the height of the figure. More specifically, Monte Carlo moves in which the labels cross the boundaries are rejected. If they are not specified, both the height defaults to 1.
  938. * @param (double) height height of the boundary
  939. * @return (com.ibm.rave.ext.position.place.LabelPositioning) this labelPlacement instance itself
  940. */
  941. height$0 : function(height) {
  942. this.h = height;
  943. return this;
  944. },
  945. /**
  946. * Gets height
  947. * @return (double) height
  948. */
  949. height$1 : function() {
  950. return this.h;
  951. },
  952. /**
  953. * Gets list of labels
  954. * @return (Array) get list of labels
  955. */
  956. label$0 : function() {
  957. return this.lab;
  958. },
  959. /**
  960. * Sets the list of labels that need to be moved
  961. * @param (Array) labelList list of labels
  962. * @return (com.ibm.rave.ext.position.place.LabelPositioning) this labelPlacement instance itself
  963. */
  964. label$1 : function(labelList) {
  965. this.lab = labelList;
  966. return this;
  967. },
  968. /**
  969. * Sets the anchor point list for the provided labels
  970. * @param (Array) anchorList anchor point list
  971. * @return (com.ibm.rave.ext.position.place.LabelPositioning) this labelPlacement instance itself
  972. */
  973. anchor$0 : function(anchorList) {
  974. this.anc = anchorList;
  975. return this;
  976. },
  977. /**
  978. * Gets the list of anchor points for labels
  979. * @return (Array) list of anchor points
  980. */
  981. anchor$1 : function() {
  982. return this.anc;
  983. },
  984. /** @expose */
  985. energy : function(a0) {
  986. var args = arguments;
  987. if (args.length == 0) {
  988. return this.energy$2();
  989. }
  990. if (args.length == 1 && typeof a0 === "function") {
  991. return this.energy$0(a0);
  992. }
  993. return this.energy$1(a0);
  994. },
  995. /** @expose */
  996. schedule : function(a0) {
  997. var args = arguments;
  998. if (args.length == 0) {
  999. return this.schedule$1();
  1000. }
  1001. return this.schedule$0(a0);
  1002. },
  1003. /** @expose */
  1004. on : function(a0, a1) {
  1005. var args = arguments;
  1006. if (args.length == 1) {
  1007. return this.on$0(a0);
  1008. }
  1009. return this.on$1(a0, a1);
  1010. },
  1011. /** @expose */
  1012. maxDistance : function(a0) {
  1013. var args = arguments;
  1014. if (args.length == 0) {
  1015. return this.maxDistance$0();
  1016. }
  1017. return this.maxDistance$1(a0);
  1018. },
  1019. /** @expose */
  1020. numberOfSweeps : function(a0) {
  1021. var args = arguments;
  1022. if (args.length == 0) {
  1023. return this.numberOfSweeps$1();
  1024. }
  1025. return this.numberOfSweeps$0(a0);
  1026. },
  1027. /** @expose */
  1028. width : function(a0) {
  1029. var args = arguments;
  1030. if (args.length == 0) {
  1031. return this.width$1();
  1032. }
  1033. return this.width$0(a0);
  1034. },
  1035. /** @expose */
  1036. height : function(a0) {
  1037. var args = arguments;
  1038. if (args.length == 0) {
  1039. return this.height$1();
  1040. }
  1041. return this.height$0(a0);
  1042. },
  1043. /** @expose */
  1044. label : function(a0) {
  1045. var args = arguments;
  1046. if (args.length == 0) {
  1047. return this.label$0();
  1048. }
  1049. return this.label$1(a0);
  1050. },
  1051. /** @expose */
  1052. anchor : function(a0) {
  1053. var args = arguments;
  1054. if (args.length == 0) {
  1055. return this.anchor$1();
  1056. }
  1057. return this.anchor$0(a0);
  1058. }
  1059. });
  1060. /**
  1061. * Method checks whether or not leader lines between anchors and labels intersect.
  1062. * @param (double) anc1x Anchor 1 x-coordinate
  1063. * @param (double) lab1x Label 1 x-coordinate
  1064. * @param (double) anc2x Anchor 2 x-coordinate
  1065. * @param (double) lab2x Label 2 x-coordinate
  1066. * @param (double) anc1y Anchor 1 y-coordinate
  1067. * @param (double) lab1y Label 1 y-coordinate
  1068. * @param (double) anc2y Anchor 2 y-coordinate
  1069. * @param (double) lab2y Label 2 y-coordinate
  1070. * @return (boolean) boolean.
  1071. */
  1072. com_ibm_rave_ext_position_place_LabelPositioning.leaderLinesIntersect = function(anc1x, lab1x, anc2x, lab2x, anc1y, lab1y, anc2y, lab2y) {
  1073. var mua, mub, denom, numera, numerb;
  1074. denom = (lab2y - anc2y) * (lab1x - anc1x) - (lab2x - anc2x) * (lab1y - anc1y);
  1075. numera = (lab2x - anc2x) * (anc1y - anc2y) - (lab2y - anc2y) * (anc1x - anc2x);
  1076. numerb = (lab1x - anc1x) * (anc1y - anc2y) - (lab1y - anc1y) * (anc1x - anc2x);
  1077. mua = numera / denom;
  1078. mub = numerb / denom;
  1079. return !(mua < 0 || mua > 1 || mub < 0 || mub > 1);
  1080. };
  1081. /**
  1082. * The event object fired by label movers
  1083. */
  1084. com_ibm_rave_ext_position_place_LabelPositioning.EventObject = rave['internal']['Declare']({
  1085. /**
  1086. * The type of the event being fired, could either: "start", "tick" or "end"
  1087. */
  1088. /** @expose */
  1089. type : null,
  1090. /**
  1091. * The current value of the cooling parameter alpha
  1092. */
  1093. /** @expose */
  1094. alpha : 0,
  1095. constructor : function(type, alpha) {
  1096. this.type = type;
  1097. this.alpha = alpha;
  1098. }
  1099. });
  1100. // $source: com/ibm/rave/ext/statistics/RaveStatistics
  1101. /************************************************************************
  1102. ** IBM Confidential
  1103. **
  1104. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  1105. **
  1106. ** (C) Copyright IBM Corp. 2017
  1107. **
  1108. ** The source code for this program is not published or otherwise divested of its trade secrets,
  1109. ** irrespective of what has been deposited with the U.S. Copyright Office.
  1110. ************************************************************************/
  1111. // GENERATED
  1112. //@import com/ibm/rave/ext/statistics/outliersUtility/PeirceCriterion (runtime) // new
  1113. /**
  1114. * A factory of extended statistics for rave capability.
  1115. * @see PeirceCriterion
  1116. */
  1117. var com_ibm_rave_ext_statistics_RaveStatistics = rave['internal']['Declare']({
  1118. /**
  1119. * @return (com.ibm.rave.ext.statistics.outliersUtility.PeirceCriterion) a new instance of {@link PeirceCriterion}
  1120. * @see PeirceCriterion
  1121. */
  1122. /** @expose */
  1123. peirceCriterion : function() {
  1124. return new com_ibm_rave_ext_statistics_outliersUtility_PeirceCriterion();
  1125. },
  1126. /**
  1127. * Perform the default outlier calculation on a list of data. This currently uses the Peirce Criterion calculation. This is a convenient way of calling <code>RaveStaticstics.peirceCriterion().outliers(data)</code>
  1128. * @param (Array) data The set of data to find outliers for.
  1129. * @return (Array) Indexes of statistical outliers within 'data'.
  1130. */
  1131. /** @expose */
  1132. outliers : function(data) {
  1133. return this.peirceCriterion().outliers(data);
  1134. }
  1135. //constructor : function() {}
  1136. });
  1137. com_ibm_rave_ext_statistics_RaveStatistics.getRegistrationStatus = function() {
  1138. var registrationStatus = rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().getData("RAVESTATISTICS_EXTENSION_REGISTRATION_STATUS_KEY");
  1139. if (!registrationStatus) {
  1140. registrationStatus = new com_ibm_rave_ext_statistics_RaveStatistics.RegistrationStatus();
  1141. rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().putData("RAVESTATISTICS_EXTENSION_REGISTRATION_STATUS_KEY", registrationStatus);
  1142. }
  1143. return registrationStatus;
  1144. };
  1145. /**
  1146. * Register all extended statistics functionality.
  1147. * @return (boolean) true if registration was successful, false otherwise
  1148. */
  1149. /** @expose */
  1150. com_ibm_rave_ext_statistics_RaveStatistics.init = function() {
  1151. var registrationStatus = com_ibm_rave_ext_statistics_RaveStatistics.getRegistrationStatus();
  1152. if (!registrationStatus.registered) {
  1153. registrationStatus.registered = rave.capabilities.extension("statistics", function() {
  1154. return new com_ibm_rave_ext_statistics_RaveStatistics();
  1155. });
  1156. }
  1157. return registrationStatus.registered;
  1158. };
  1159. com_ibm_rave_ext_statistics_RaveStatistics.RegistrationStatus = rave['internal']['Declare']({
  1160. registered : false
  1161. });
  1162. /** @expose */
  1163. com_ibm_rave_ext_statistics_RaveStatistics.STATISTICS = "statistics";
  1164. //com_ibm_rave_ext_statistics_RaveStatistics.EXTENSION_REGISTRATION_STATUS_KEY = "RAVESTATISTICS_EXTENSION_REGISTRATION_STATUS_KEY";
  1165. // Auto initialization
  1166. com_ibm_rave_ext_statistics_RaveStatistics.init();
  1167. if (!rave.capabilities["statistics"]) {
  1168. rave.capabilities["statistics"] = function() {
  1169. return new com_ibm_rave_ext_statistics_RaveStatistics();
  1170. };
  1171. } else {
  1172. console.log("Could not register extension: RaveStatistics");
  1173. }
  1174. // $source: com/ibm/rave/ext/statistics/outliersUtility/RaveOutlier
  1175. /************************************************************************
  1176. ** IBM Confidential
  1177. **
  1178. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  1179. **
  1180. ** (C) Copyright IBM Corp. 2017
  1181. **
  1182. ** The source code for this program is not published or otherwise divested of its trade secrets,
  1183. ** irrespective of what has been deposited with the U.S. Copyright Office.
  1184. ************************************************************************/
  1185. // GENERATED
  1186. /**
  1187. * Abstract class that describes an outlier utility. All outlier algorithms should follow this interface.
  1188. */
  1189. var com_ibm_rave_ext_statistics_outliersUtility_RaveOutlier = rave['internal']['Declare']({
  1190. //_value : null,
  1191. constructor : function() {
  1192. this._value = com_ibm_rave_ext_statistics_outliersUtility_RaveOutlier.VALUE;
  1193. },
  1194. /**
  1195. * sets the function for computing data values, function that will be called by the outlier class to get the data values
  1196. * @param (rave['internal']['ValueFunction']) valueFn The function for computing data values
  1197. * @return (com.ibm.rave.ext.statistics.outliersUtility.RaveOutlier) this outlier instance
  1198. */
  1199. value$0 : function(valueFn) {
  1200. this._value = valueFn;
  1201. return this;
  1202. },
  1203. /**
  1204. * gets the data value function
  1205. * @return (rave['internal']['ValueFunction']) the value function
  1206. */
  1207. value$1 : function() {
  1208. return this._value;
  1209. },
  1210. /**
  1211. * Returns a list containing the indices of potential outliers within the dataset according to the implemented algorithm. The data set is processed and any element that deviates greater than the allowable maximum deviation is flagged as an outlier.
  1212. * @param (Array) data of data objects. Must be either a number or an object type that can be converted into a number (Date, String).
  1213. * @return (Array) ArrayEx of outliers of this dataset. Each element is an index into the original data set. This list is simply a collection of all the outliers' indices and is not guaranteed to be in any significant order.
  1214. */
  1215. /** @expose */
  1216. outliers : function(data) {},
  1217. /** @expose */
  1218. value : function(a0) {
  1219. var args = arguments;
  1220. if (args.length == 0) {
  1221. return this.value$1();
  1222. }
  1223. return this.value$0(a0);
  1224. }
  1225. });
  1226. /**
  1227. * Default value function for value calculation.
  1228. */
  1229. com_ibm_rave_ext_statistics_outliersUtility_RaveOutlier.VALUE = function(data, index, groupIndex) {
  1230. return + (data);
  1231. };
  1232. // $source: com/ibm/rave/ext/text/TextExtensions
  1233. /************************************************************************
  1234. ** IBM Confidential
  1235. **
  1236. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  1237. **
  1238. ** (C) Copyright IBM Corp. 2017
  1239. **
  1240. ** The source code for this program is not published or otherwise divested of its trade secrets,
  1241. ** irrespective of what has been deposited with the U.S. Copyright Office.
  1242. ************************************************************************/
  1243. // GENERATED
  1244. //@import com/ibm/rave/ext/text/wrap/TextFlow (runtime) // new
  1245. //@import com/ibm/rave/ext/text/nativeImpl/FontChecker (runtime) // new
  1246. /**
  1247. * Common text extensions initializer class
  1248. */
  1249. var com_ibm_rave_ext_text_TextExtensions = rave['internal']['Declare']({
  1250. });
  1251. com_ibm_rave_ext_text_TextExtensions.getRegistrationStatus = function() {
  1252. var registrationStatus = rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().getData("TEXTEXTENSIONS_EXTENSION_REGISTRATION_STATUS_KEY");
  1253. if (!registrationStatus) {
  1254. registrationStatus = new com_ibm_rave_ext_text_TextExtensions.RegistrationStatus();
  1255. rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().putData("TEXTEXTENSIONS_EXTENSION_REGISTRATION_STATUS_KEY", registrationStatus);
  1256. }
  1257. return registrationStatus;
  1258. };
  1259. /** @expose */
  1260. com_ibm_rave_ext_text_TextExtensions.init = function() {
  1261. var registrationStatus = com_ibm_rave_ext_text_TextExtensions.getRegistrationStatus();
  1262. if (!registrationStatus.registered) {
  1263. registrationStatus.registered &= rave.capabilities.extension("textflow", function() {
  1264. return new com_ibm_rave_ext_text_wrap_TextFlow();
  1265. });
  1266. registrationStatus.registered &= rave.capabilities.extension(com_ibm_rave_ext_text_TextExtensions.FONTCHECKER_EXTENSION, function() {
  1267. return new com_ibm_rave_ext_text_nativeImpl_FontChecker();
  1268. });
  1269. }
  1270. return registrationStatus.registered;
  1271. };
  1272. com_ibm_rave_ext_text_TextExtensions.RegistrationStatus = rave['internal']['Declare']({
  1273. registered : false
  1274. });
  1275. com_ibm_rave_ext_text_TextExtensions.TEXTFLOW_EXTENSION = "textflow";
  1276. com_ibm_rave_ext_text_TextExtensions.FONTCHECKER_EXTENSION = "fontchecker";
  1277. //com_ibm_rave_ext_text_TextExtensions.EXTENSION_REGISTRATION_STATUS_KEY = "TEXTEXTENSIONS_EXTENSION_REGISTRATION_STATUS_KEY";
  1278. // Auto initialization
  1279. com_ibm_rave_ext_text_TextExtensions.init();
  1280. if (!rave.capabilities["textflow"]) {
  1281. rave.capabilities["textflow"] = function() {
  1282. return new com_ibm_rave_ext_text_wrap_TextFlow();
  1283. };
  1284. } else {
  1285. console.log("Could not register extension: TextExtensions");
  1286. }
  1287. if (!rave.capabilities[com_ibm_rave_ext_text_TextExtensions.FONTCHECKER_EXTENSION]) {
  1288. rave.capabilities[com_ibm_rave_ext_text_TextExtensions.FONTCHECKER_EXTENSION] = function() {
  1289. return new com_ibm_rave_ext_text_nativeImpl_FontChecker();
  1290. };
  1291. } else {
  1292. console.log("Could not register extension: TextExtensions");
  1293. }
  1294. // $source: com/ibm/rave/ext/text/wrap/TextFlow
  1295. /************************************************************************
  1296. ** IBM Confidential
  1297. **
  1298. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  1299. **
  1300. ** (C) Copyright IBM Corp. 2017
  1301. **
  1302. ** The source code for this program is not published or otherwise divested of its trade secrets,
  1303. ** irrespective of what has been deposited with the U.S. Copyright Office.
  1304. ************************************************************************/
  1305. // GENERATED
  1306. //@import com/ibm/rave/ext/text/nativeImpl/FontChecker (runtime) // new
  1307. //@import com/ibm/rave/ext/text/internal/wrap/TextOperation (runtime) // getOperation
  1308. //@import com/ibm/rave/ext/text/internal/wrap/FontStyleStruct (runtime) // new
  1309. /**
  1310. * A text wrapping, truncating and fitting function operating on a selection of text nodes Example usage: <code> RunFunction textfitter = Rave.capabilities.extension("textflow"); String text = "Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects. These patterns are used with the exec and test methods of RegExp, and with the match, replace, search, and split methods of String. This chapter describes JavaScript regular expressions."; Selector svg = Rave.select("body").append("svg").attr("width", 300) .attr("height", 300); svg.selectAll("text") .data(new Integer[] { 0, 150 }) .enter() .append("text") .text(text) .attr("x", new ValueFunction<SceneNode, Number>() { public Number getValue(SceneNode item, Object d, int index, int groupIndex) { return (Number) d; } }) .attr("y", 10) .attr("width", 100) .attr("height", 300) .call(textfitter, true, false); </code> TextFlow will create tspan children nodes per line of text and set their style attributes as per alignment, padding and other properties configured on the wrapper function. If a property is not configured on the wrapper (e.g. width and height of the desired text extent), the wrapper will use attributes set on the text node itself Wrapper can be accessed through <code>Rave.capabilities.extension("textflow");</code> and run on the text node selection using call invocation: <code>selection.call(textflow, wrap, fit);</code> with first argument for wrap (true|false) , and second for fit (true|false). When arguments are omitted, they assumed to be false. Truncation options are set via textOverflow property. If neither wrap, fit or truncation options are indicated, the default behavior is to do nothing Alignments works in a manner similar to align and valign in html, with the text being aligned within the bounding box, closest to the edge specified by the alignment.
  1311. */
  1312. var com_ibm_rave_ext_text_wrap_TextFlow = rave['internal']['Declare']({
  1313. //_fontChecker : null,
  1314. //_overflow_minFn : null,
  1315. //_text_overflowFn : null,
  1316. //_current_styles : null,
  1317. //_alignment : null,
  1318. //_alignmentFn : null,
  1319. //_valignment : null,
  1320. //_valignmentFn : null,
  1321. //_padding : null,
  1322. //_paddingFn : null,
  1323. //_lineSpacing : null,
  1324. //_lineSpacingFn : null,
  1325. //_extent : null,
  1326. //_extentFn : null,
  1327. //_maxFontSize : null,
  1328. //_maxFontSizeFn : null,
  1329. //_minFontSizeFn : null,
  1330. _transformMarkerAdded : false,
  1331. _wrap : false, _fit : false, _truncate : false,
  1332. _drop : true,
  1333. _overflow_min : 0,
  1334. _text_overflow : "...",
  1335. _alignement_set : false,
  1336. _minFontSize : 4.0,
  1337. _$functionClassMethod : function() {
  1338. var _$self = /**
  1339. * @see RunFunction#_$self.run(Object, Object...)
  1340. */
  1341. function(args) {
  1342. if (args !== null || arguments.length > 1){
  1343. args = Array.prototype.slice.call(arguments, 0);
  1344. }
  1345. {
  1346. _$self.flow(this);
  1347. return null;
  1348. }
  1349. };
  1350. return _$self;
  1351. },
  1352. constructor : function() {
  1353. this._alignment = "left";
  1354. this._valignment = "top";
  1355. this._padding = com_ibm_rave_ext_text_wrap_TextFlow.DEFAULT_PADDING;
  1356. this._extentFn = function(data, index, groupIndex) {
  1357. var bBox = this.getBBox();
  1358. var css_width = rave.util.parseCSSSize(this.getAttribute("width"));
  1359. var width = !css_width ? bBox.width : css_width.value;
  1360. var css_heigth = rave.util.parseCSSSize(this.getAttribute("height"));
  1361. var height = !css_heigth ? bBox.height : css_heigth.value;
  1362. return [width, height];
  1363. };
  1364. this._maxFontSize = Infinity;
  1365. },
  1366. /**
  1367. * Set fit fail behavior - when fit, wrap, truncate fails text can be dropped completely or left unchanged. This behavior can be toggled on or off. The default is to drop the text which failed to fit
  1368. * @param (boolean) drop_lines true to drop text , which failed to fit, false otherwise.
  1369. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1370. */
  1371. dropTextOnFail$0 : function(drop_lines) {
  1372. this._drop = drop_lines;
  1373. return this;
  1374. },
  1375. /**
  1376. * Returns fit fail behavior - when fit, wrap, truncate fails text can be dropped completely or left unchanged. This behavior can be toggled on or off. The default is to drop text , which failed to fit
  1377. * @return (boolean) true to drop text , which failed to fit, false otherwise.
  1378. */
  1379. dropTextOnFail$1 : function() {
  1380. return this._drop;
  1381. },
  1382. /**
  1383. * Returns wrap functionality flag set to true to wrap lines, false otherwise. Default value is false
  1384. * @return (boolean) wrap flag set to true to wrap lines, false otherwise.
  1385. */
  1386. wrap$0 : function() {
  1387. return this._wrap;
  1388. },
  1389. /**
  1390. * Toggles wrap functionality on and off. Default is set to false
  1391. * @param (boolean) wrapping true to toggle wrap functionality on, false to toggle off
  1392. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1393. */
  1394. wrap$1 : function(wrapping) {
  1395. this._wrap = wrapping;
  1396. return this;
  1397. },
  1398. /**
  1399. * Returns true if fit functionality is on, false otherwise. Default is false
  1400. * @return (boolean) true if fit functionality is on, false otherwise.
  1401. */
  1402. fit$0 : function() {
  1403. return this._fit;
  1404. },
  1405. /**
  1406. * Toggles fit functionality on and off. Default is set to false
  1407. * @param (boolean) fitting true to toggle fit functionality on, false otherwise
  1408. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1409. */
  1410. fit$1 : function(fitting) {
  1411. this._fit = fitting;
  1412. return this;
  1413. },
  1414. /**
  1415. * Returns true if truncate functionality is on, false otherwise
  1416. * @return (boolean) true if truncate functionality is on, false otherwise
  1417. */
  1418. truncate$0 : function() {
  1419. return this._truncate;
  1420. },
  1421. /**
  1422. * Toggles truncation functionality on and off.
  1423. * @param (boolean) truncation true to toggle truncation on, false otherwise
  1424. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1425. */
  1426. truncate$1 : function(truncation) {
  1427. this._truncate = truncation;
  1428. return this;
  1429. },
  1430. /**
  1431. * Sets a node selection based function, which returns minimum string length before ellipses.
  1432. * @param (rave['internal']['ValueFunction']) overflowMinFn a node selection based function, which returns minimum string length before ellipses.
  1433. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1434. */
  1435. truncationMinChars$0 : function(overflowMinFn) {
  1436. this._overflow_minFn = overflowMinFn;
  1437. this._overflow_min = null;
  1438. return this;
  1439. },
  1440. /**
  1441. * Returns an integer or a function, which returns minimum string length before ellipses.
  1442. * @return (Object) an integer or a function, which returns minimum string length before ellipses.
  1443. */
  1444. truncationMinChars$1 : function() {
  1445. return !this._overflow_minFn ? this._overflow_min : this._overflow_minFn;
  1446. },
  1447. /**
  1448. * Sets minimum string length before ellipses. If text can not be truncated with minimum characters plus ellipses string, it will be replaced by the ellipses string
  1449. * @param (int) minimum minimum string length before ellipses
  1450. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1451. */
  1452. truncationMinChars$2 : function(minimum) {
  1453. this._overflow_min = minimum;
  1454. this._overflow_minFn = null;
  1455. return this;
  1456. },
  1457. /**
  1458. * Sets ellipses string to use for text truncation.
  1459. * @param (String) ellipses ellipses string
  1460. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1461. */
  1462. textTruncateIndicator$0 : function(ellipses) {
  1463. this._text_overflow = ellipses;
  1464. this._text_overflowFn = null;
  1465. return this;
  1466. },
  1467. /**
  1468. * Sets ellipses function. The function must return a string , which will be used for text truncation.
  1469. * @param (rave['internal']['ValueFunction']) ellipses a function. The function must return a string , which will be used for text truncation
  1470. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1471. */
  1472. textTruncateIndicator$1 : function(ellipses) {
  1473. this._text_overflowFn = ellipses;
  1474. this._text_overflow = null;
  1475. return this;
  1476. },
  1477. /**
  1478. * Returns ellipses string or function. The function takes node selector and it's data as parameters and returns ellipses string, a string , which will be used for text truncation.
  1479. * @return (Object) ellipses string or a function. The function must return a string , which will be used for text truncation
  1480. */
  1481. textTruncateIndicator$2 : function() {
  1482. return this._text_overflow == null ? this._text_overflowFn : this._text_overflow;
  1483. },
  1484. /**
  1485. * Sets constant width and height extent for all nodes in the selection. If the width and height is not explicitly set, a text node's width and height attribute values will be used
  1486. * @param (int) width width of the text extent
  1487. * @param (int) height height of the text extent
  1488. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1489. */
  1490. extent$0 : function(width, height) {
  1491. this._extent = [width, height];
  1492. this._extentFn = null;
  1493. return this;
  1494. },
  1495. /**
  1496. * Sets a function to access width and height extent of the node in the selection. The function takes text node as a parameter and returns a dimension object with width and height extent for the node.
  1497. * @param (rave['internal']['ValueFunction']) extentFn a function, which returns width and height extent of the text node in the selection.
  1498. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1499. */
  1500. extent$1 : function(extentFn) {
  1501. this._extentFn = extentFn;
  1502. this._extent = null;
  1503. return this;
  1504. },
  1505. /**
  1506. * Returns width and height extent for the text or a function to access width and height of the node in the selection. The function takes text node and it's data as a parameter and returns a dimension object with width and height extent for the node.
  1507. * @return (Object) width and height extent for the text or a function, which returns width and height extent for the text node
  1508. */
  1509. extent$2 : function() {
  1510. return !this._extent ? this._extentFn : this._extent;
  1511. },
  1512. /**
  1513. * Set line spacing fraction relative to the font size same for all nodes. E.g. 1.36 will yield a line height of 1.36 of font size. If not set line-height attribute value will be used. If line-height is not set, text node dy attribute value will be used. If dy value is not set, a constant 1.36 line spacing will be applied
  1514. * @param (double) lineSpacing line spacing fraction relative to the font size.
  1515. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1516. */
  1517. spacing$0 : function(lineSpacing) {
  1518. this._lineSpacing = lineSpacing;
  1519. this._lineSpacingFn = null;
  1520. return this;
  1521. },
  1522. /**
  1523. * Set a function to access line spacing. The function takes single node selector and it's data as parameters and must return line spacing fraction relative to the font size. E.g. 1.36 will yield a line height of 1.36 of font size. If not set line-height attribute value will be used. If line-height is not set, text node dy attribute value will be used. If dy value is not set, a constant 1.36 line spacing will be applied
  1524. * @param (rave['internal']['ValueFunction']) lineSpacingFn a function, which returns line spacing fraction relative to the font size
  1525. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1526. */
  1527. spacing$1 : function(lineSpacingFn) {
  1528. this._lineSpacingFn = lineSpacingFn;
  1529. this._lineSpacing = null;
  1530. return this;
  1531. },
  1532. /**
  1533. * Returns line spacing or a function to access line spacing for individual node. The function takes a text node and it's data as parameters and must return line spacing fraction relative to the font size. E.g. 1.36 will yield a line height of 1.36 of font size. If not set line-height attribute value will be used. If line-height is not set, text node dy attribute value will be used. If dy value is not set, a constant 1.36 line spacing will be applied
  1534. * @return (Object) line spacing or a function, which returns line spacing fraction relative to the font size
  1535. */
  1536. spacing$2 : function() {
  1537. return !this._lineSpacingFn ? this._lineSpacing : this._lineSpacingFn;
  1538. },
  1539. /**
  1540. * Sets text alignment to "left" | "right" | "center" for all nodes in the selection. When alignment is not explicitly set, original alignment will not be affected
  1541. * @param (String) h_alignment horizontal alignment value ("left" | "right" | "center")
  1542. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1543. */
  1544. alignment$0 : function(h_alignment) {
  1545. if ("center" == h_alignment) {
  1546. this._alignment = "center";
  1547. } else if ("right" == h_alignment) {
  1548. this._alignment = "right";
  1549. } else {
  1550. this._alignment = "left";
  1551. }
  1552. this._alignement_set = true;
  1553. this._alignmentFn = null;
  1554. return this;
  1555. },
  1556. /**
  1557. * Sets alignment function to access horizontal alignment value. The function takes a text node and it's data as parameters and return "left" | "right" | "center" alignment value for the individual node.
  1558. * @param (rave['internal']['ValueFunction']) alignmentFn a function, which returns horizontal alignment value as "left" | "right" | "center".
  1559. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1560. */
  1561. alignment$1 : function(alignmentFn) {
  1562. this._alignmentFn = alignmentFn;
  1563. this._alignement_set = true;
  1564. return this;
  1565. },
  1566. /**
  1567. * Returns horizontal alignment string or function to access horizontal alignment value. The function takes a text node and it's data as parameters and return "left" | "right" | "center" alignment value for the individual node.
  1568. * @return (Object) horizontal alignment string or function, which returns horizontal alignment value as "left" | "right" | "center"
  1569. */
  1570. alignment$2 : function() {
  1571. return !this._alignmentFn ? this._alignment : this._alignmentFn;
  1572. },
  1573. /**
  1574. * Sets text vertical alignment for all nodes to "top" | "middle" | "bottom"
  1575. * @param (String) v_alignment vertical alignment "top" | "middle" | "bottom"
  1576. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1577. */
  1578. valignment$0 : function(v_alignment) {
  1579. if ("middle" == v_alignment) {
  1580. this._valignment = "middle";
  1581. } else if ("bottom" == v_alignment) {
  1582. this._valignment = "bottom";
  1583. } else {
  1584. this._valignment = "top";
  1585. }
  1586. this._valignmentFn = null;
  1587. return this;
  1588. },
  1589. /**
  1590. * Sets text vertical alignment function. The function takes single node selector and it's data as parameters and returns return a vertical alignment string as "top" | "middle" | "bottom" for the node.
  1591. * @param (rave['internal']['ValueFunction']) alignmentFn a function , which must return vertical alignment strings "top", "middle" or "bottom"
  1592. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1593. */
  1594. valignment$1 : function(alignmentFn) {
  1595. this._valignmentFn = alignmentFn;
  1596. this._valignment = null;
  1597. return this;
  1598. },
  1599. /**
  1600. * Returns text vertical alignment string or function. The function takes single node selector and it's data as parameters and returns return a vertical alignment string as "top" | "middle" | "bottom" for the node.
  1601. * @return (Object) vertical alignment value "top" | "middle" | "bottom" or function , which returns a vertical alignment string
  1602. */
  1603. valignment$2 : function() {
  1604. return !this._valignmentFn ? this._valignment : this._valignmentFn;
  1605. },
  1606. /**
  1607. * Run text operation on a selection of SVG text nodes. Depending on parameter values, the operation will wrap, wrap with fit, or fit a string of text on each text node and replace original text with tspan nodes per line of text as children of the original node.
  1608. * @param (rave['internal']['Selector']) text node selector, should be of type SVG 'text'
  1609. */
  1610. /** @expose */
  1611. flow : function(text) {
  1612. var wrap = this.wrap(), fit = this.fit(), truncate = this.truncate();
  1613. var operation = ((wrap ? 1 : 0) | (fit ? 2 : 0));
  1614. var self = this;
  1615. if (!this._fontChecker) {
  1616. this._fontChecker = new com_ibm_rave_ext_text_nativeImpl_FontChecker();
  1617. }
  1618. text.each(function(data, index, groupIndex) {
  1619. var fontReplaced = self._fontChecker.replaceLimitedFonts(this);
  1620. var transform = this.getAttribute("transform");
  1621. transform = transform != null ? ""+(transform) : "";
  1622. var markerPos = (transform).indexOf(com_ibm_rave_ext_text_wrap_TextFlow.TSPAN_TRANSFORM_MARKER);
  1623. if (markerPos != -1) {
  1624. if (markerPos == 0) {
  1625. this.removeAttribute("transform");
  1626. } else {
  1627. transform = (transform).substring(0, markerPos);
  1628. this.setAttribute("transform", transform);
  1629. }
  1630. }
  1631. self._transformMarkerAdded = false;
  1632. var text_operation = self._getOperation(operation, truncate ? this : null, data, index, groupIndex);
  1633. if (!text_operation) {
  1634. return;
  1635. }
  1636. text_operation.overflowMin((self._overflow_minFn ? self._overflow_minFn.call(this, data, index, groupIndex) : ~~ (self._overflow_min)));
  1637. self._current_styles = this.rave_getComputedStyles();
  1638. var insets = self._paddingFn ? self._paddingFn.call(this, data, index, groupIndex) : self._padding;
  1639. var bounds = self._getBounds(this, data, index, groupIndex, insets);
  1640. text_operation.size(bounds.width, bounds.height);
  1641. var font_size = self._calculateFontSize(this, data, index, groupIndex);
  1642. text_operation.font(com_ibm_rave_ext_text_wrap_TextFlow.createFontStruct(self._current_styles));
  1643. text_operation.fontSize(font_size);
  1644. text_operation.maxFontSize(self._maxFontSizeFn ? self._maxFontSizeFn.call(this, data, index, groupIndex) : self._maxFontSize);
  1645. text_operation.minFontSize(self._minFontSizeFn ? self._minFontSizeFn.call(this, data, index, groupIndex) : self._minFontSize);
  1646. var em = self._calculateSpacing(this, data, index, groupIndex, font_size);
  1647. text_operation.em(em);
  1648. var text = this.rave_getText();
  1649. var rtl = rave.bidi.format.determineDirection(text) == 1;
  1650. text_operation.text(text);
  1651. var result = text_operation();
  1652. var lines = result.lines;
  1653. if (lines.length == 0) {
  1654. if (self.dropTextOnFail()) {
  1655. lines.push("");
  1656. } else {
  1657. lines.push(this.rave_getText());
  1658. }
  1659. }
  1660. self._applyTextNodeAttributes(bounds.width, bounds.height, this, data, index, groupIndex, insets, rtl);
  1661. if (fit || fontReplaced) {
  1662. var fontSize = this.rave_getStyle("font-size");
  1663. if (fontSize != null && fontSize != "" && !(fontSize == result.font.fontSize)) {
  1664. this.rave_setStyle("font", null);
  1665. }
  1666. this.rave_setStyle("font", result.font.toString(), "important");
  1667. }
  1668. self._generateTspans(result, bounds, this, data, index, groupIndex, rtl);
  1669. });
  1670. /*return;*/
  1671. },
  1672. /** @expose */
  1673. _calculateSpacing : function(node, data, index, groupIndex, font_size) {
  1674. if (this.spacing() == null) {
  1675. var styled_height = rave.util.parseCSSSize(this._current_styles[com_ibm_rave_ext_text_wrap_TextFlow._LINE_HEIGHT]);
  1676. var line_height = styled_height ? styled_height.value : 0;
  1677. if (line_height > 0) {
  1678. return line_height / (font_size == 0 ? 1 : font_size);
  1679. }
  1680. var dy_attr = rave.util.parseCSSSize(this._current_styles["dy"]);
  1681. if (dy_attr) {
  1682. return dy_attr.value / font_size;
  1683. }
  1684. return 1.36;
  1685. }
  1686. return this._lineSpacingFn ? this._lineSpacingFn.call(node, data, index, groupIndex) : this._lineSpacing;
  1687. },
  1688. /** @expose */
  1689. _calculateFontSize : function(node, data, index, groupIndex) {
  1690. var size = rave.util.parseCSSSize(this._current_styles["font-size"]);
  1691. var font_size = size ? size.value : node.getBBox().height;
  1692. return font_size;
  1693. },
  1694. /**
  1695. * @return (com.ibm.rave.ext.text.internal.wrap.TextOperation) a text operation for the options
  1696. */
  1697. /** @expose */
  1698. _getOperation : function(operation, node, data, index, groupIndex) {
  1699. var overflow;
  1700. if (node) {
  1701. overflow = this._text_overflowFn ? this._text_overflowFn.call(node, data, index, groupIndex) : this._text_overflow;
  1702. }
  1703. return com_ibm_rave_ext_text_internal_wrap_TextOperation.getOperation(operation, overflow);
  1704. },
  1705. /**
  1706. * Returns padding insets object or a function to access padding insets. The function takes a single node selector and it's data parameters and returns top, left, bottom, right padding insets for the node
  1707. * @return (Object) padding insets or a function, which returns padding insets: top, left, bottom, right
  1708. */
  1709. padding$0 : function() {
  1710. return !this._padding ? this._paddingFn : this._padding;
  1711. },
  1712. /**
  1713. * Set padding for all nodes in the selection
  1714. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1715. */
  1716. padding$1 : function(top, left, bottom, right) {
  1717. this._padding = {};
  1718. this._padding["top"] = top;
  1719. this._padding["left"] = left;
  1720. this._padding["bottom"] = bottom;
  1721. this._padding["right"] = right;
  1722. this._paddingFn = null;
  1723. return this;
  1724. },
  1725. /**
  1726. * Set function to access padding insets. The function takes a single node selector and it's data as parameters and returns top, left, bottom, right padding insets for the node
  1727. * @param (rave['internal']['ValueFunction']) paddingFn top, left, bottom, right
  1728. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1729. */
  1730. padding$2 : function(paddingFn) {
  1731. this._paddingFn = paddingFn;
  1732. this._padding = null;
  1733. return this;
  1734. },
  1735. /**
  1736. * Returns minimum font size function. Function takes node selector and it's data as a parameter and returns minimum font size for that text node. Minimum font size is used by the fit functionality
  1737. * @return (Object) minimum font size function
  1738. * @see this.TextFlow#this.fit()
  1739. */
  1740. minFont$0 : function() {
  1741. return this._minFontSize == null ? this._minFontSizeFn : this._minFontSize;
  1742. },
  1743. /**
  1744. * Sets minimum font size or a function. Function takes node selector and it's data as a parameter and returns minimum font size for that text node. Minimum font size is used by the fit functionality
  1745. * @param (rave['internal']['ValueFunction']) minFontSizeFn
  1746. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1747. * @see this.TextFlow#this.fit()
  1748. */
  1749. minFont$1 : function(minFontSizeFn) {
  1750. this._minFontSizeFn = minFontSizeFn;
  1751. this._minFontSize = null;
  1752. return this;
  1753. },
  1754. /**
  1755. * Set minimum font size for all texts in a selection. Minimum font size is used by the fit functionality
  1756. * @param (Object) size minimum font size to be used by the fit functionality
  1757. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1758. * @see this.TextFlow#this.fit()
  1759. */
  1760. minFont$2 : function(size) {
  1761. this._minFontSize = + (size);
  1762. this._minFontSizeFn = null;
  1763. return this;
  1764. },
  1765. /**
  1766. * Returns maximum font size or a function. Function takes node selector and it's data as a parameter and returns maximum font size for that text node. Maximum font size is used by the fit functionality. If not set, font will be expanded (or contracted) to fit available space
  1767. * @return (Object) maximum font size function
  1768. * @see this.TextFlow#this.fit()
  1769. */
  1770. maxFont$0 : function() {
  1771. return !this._maxFontSizeFn ? this._maxFontSize : this._maxFontSizeFn;
  1772. },
  1773. /**
  1774. * Sets maximum font size function. Function takes node selector and it's data as a parameter and returns maximum font size for that text node. Maximum font size is used by the fit functionality.If not set, font will be expanded (or contracted) to fit available space
  1775. * @param (rave['internal']['ValueFunction']) fontSizeFn
  1776. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1777. * @see this.TextFlow#this.fit()
  1778. */
  1779. maxFont$1 : function(fontSizeFn) {
  1780. this._maxFontSizeFn = fontSizeFn;
  1781. this._maxFontSize = null;
  1782. return this;
  1783. },
  1784. /**
  1785. * Set maximum font size for all texts in a selection. Maximum font size is used by the fit functionality.If not set, font will be expanded (or contracted) to fit available space
  1786. * @param (Object) size minimum font size to be used by the fit functionality
  1787. * @return (com.ibm.rave.ext.text.wrap.TextFlow) this
  1788. * @see this.TextFlow#this.fit()
  1789. */
  1790. maxFont$2 : function(size) {
  1791. this._maxFontSize = + (size);
  1792. this._maxFontSizeFn = null;
  1793. return this;
  1794. },
  1795. _getBounds : function(node, data, index, groupIndex, insets) {
  1796. var ext = this._extentFn ? this._extentFn.call(node, data, index, groupIndex) : this._extent;
  1797. var size = node.getAttribute("x") != null ? rave.util.parseCSSSize(node.getAttribute("x")) : rave.util.parseCSSSize(this._current_styles["x"]);
  1798. var x = !size ? 0 : node.rave_getSizePx(size);
  1799. size = node.getAttribute("y") != null ? rave.util.parseCSSSize(node.getAttribute("y")) : rave.util.parseCSSSize(this._current_styles["y"]);
  1800. var y = !size ? 0 : node.rave_getSizePx(size);
  1801. var width = ext[0] - insets["left"] - insets["right"], height = ext[1] - insets["top"] - insets["bottom"];
  1802. return new com_ibm_rave_ext_text_wrap_TextFlow.Bounds(x, y, width, height);
  1803. },
  1804. _applyTextNodeAttributes : function(width, height, node, data, index, groupIndex, insets, rtl) {
  1805. var transform = node.getAttribute("transform");
  1806. transform = transform != null ? ""+(transform) : "";
  1807. if (insets["left"] != 0 || insets["top"] != 0) {
  1808. node.setAttribute("transform", (transform).concat(this._transformMarker() + " translate(" + insets["left"] + "," + insets["top"] + ")"));
  1809. }
  1810. node.rave_setText(null);
  1811. if (rtl) {
  1812. node.rave_setStyle(com_ibm_rave_ext_text_wrap_TextFlow._BIDI, com_ibm_rave_ext_text_wrap_TextFlow._BIDI_OVERRIDE);
  1813. node.rave_setStyle("direction", "ltr");
  1814. }
  1815. var h_align = this._alignmentFn ? this._alignmentFn.call(node, data, index, groupIndex) : this._alignment;
  1816. var align_rtl = rtl && !this._alignement_set;
  1817. if (h_align == "right" || align_rtl) {
  1818. node.rave_setStyle(com_ibm_rave_ext_text_wrap_TextFlow._H_ALIGN, "end");
  1819. node.setAttribute("transform", (transform).concat(this._transformMarker() + " translate(" + width + ",0)"));
  1820. } else if (h_align == "center") {
  1821. node.rave_setStyle(com_ibm_rave_ext_text_wrap_TextFlow._H_ALIGN, "middle");
  1822. node.setAttribute("transform", (transform).concat(this._transformMarker() + " translate(" + width / 2 + ",0)"));
  1823. }
  1824. },
  1825. /**
  1826. * Ensure that the TSPAN_TRANSFORM_MARKER is only added once for the first transform added to the attributes. On subsequent calls, a blank string is returned.
  1827. * @return (String) the TSPAN_TRANSFORM_MARKER on the first call, an empty string after
  1828. */
  1829. _transformMarker : function() {
  1830. if (!this._transformMarkerAdded) {
  1831. this._transformMarkerAdded = true;
  1832. return com_ibm_rave_ext_text_wrap_TextFlow.TSPAN_TRANSFORM_MARKER;
  1833. }
  1834. return "";
  1835. },
  1836. _generateTspans : function(result, bounds, node, data, index, groupIndex, rtl) {
  1837. var text_node = rave.select(node);
  1838. var lines = result.lines;
  1839. var _height = 0;
  1840. var dy = result.lineHeight;
  1841. for (var n = 0; n < lines.length && _height < bounds.height; ++n) {
  1842. var line = lines[n];
  1843. var tspan = text_node.append("tspan").attr("name", "line#" + n).attr("width", bounds.width).attr("x", bounds.x).text(line);
  1844. var recomputeStyles = function(data, index, groupIndex) {
  1845. this.rave_getComputedStyles();
  1846. };
  1847. tspan.each(recomputeStyles);
  1848. tspan.call(this._fontChecker);
  1849. if (n != 0) {
  1850. tspan.attr("dy", dy);
  1851. }
  1852. if (rtl) {
  1853. tspan.attr(com_ibm_rave_ext_text_wrap_TextFlow._BIDI, "embed");
  1854. text_node.append("tspan").text("\n");
  1855. }
  1856. _height += result.lineHeight;
  1857. }
  1858. var v_align = this._valignmentFn ? this._valignmentFn.call(node, data, index, groupIndex) : this._valignment;
  1859. if (v_align == "top") {
  1860. return;
  1861. }
  1862. var transform = node.getAttribute("transform");
  1863. transform = transform != null ? ""+(transform) : "";
  1864. var delta_y = bounds.height - _height;
  1865. if (v_align == "middle") {
  1866. node.setAttribute("transform", (transform).concat(this._transformMarker() + " translate(0," + delta_y / 2 + ")"));
  1867. return;
  1868. }
  1869. node.setAttribute("transform", (transform).concat(this._transformMarker() + " translate(0," + delta_y + ")"));
  1870. },
  1871. /** @expose */
  1872. dropTextOnFail : function(a0) {
  1873. var args = arguments;
  1874. if (args.length == 0) {
  1875. return this.dropTextOnFail$1();
  1876. }
  1877. return this.dropTextOnFail$0(a0);
  1878. },
  1879. /** @expose */
  1880. wrap : function(a0) {
  1881. var args = arguments;
  1882. if (args.length == 0) {
  1883. return this.wrap$0();
  1884. }
  1885. return this.wrap$1(a0);
  1886. },
  1887. /** @expose */
  1888. fit : function(a0) {
  1889. var args = arguments;
  1890. if (args.length == 0) {
  1891. return this.fit$0();
  1892. }
  1893. return this.fit$1(a0);
  1894. },
  1895. /** @expose */
  1896. truncate : function(a0) {
  1897. var args = arguments;
  1898. if (args.length == 0) {
  1899. return this.truncate$0();
  1900. }
  1901. return this.truncate$1(a0);
  1902. },
  1903. /** @expose */
  1904. truncationMinChars : function(a0) {
  1905. var args = arguments;
  1906. if (args.length == 0) {
  1907. return this.truncationMinChars$1();
  1908. }
  1909. if (args.length == 1 && typeof a0 === "function") {
  1910. return this.truncationMinChars$0(a0);
  1911. }
  1912. return this.truncationMinChars$2(a0);
  1913. },
  1914. /** @expose */
  1915. textTruncateIndicator : function(a0) {
  1916. var args = arguments;
  1917. if (args.length == 0) {
  1918. return this.textTruncateIndicator$2();
  1919. }
  1920. if (args.length == 1 && (a0 == null || typeof a0 === "string")) {
  1921. return this.textTruncateIndicator$0(a0);
  1922. }
  1923. return this.textTruncateIndicator$1(a0);
  1924. },
  1925. /** @expose */
  1926. extent : function(a0, a1) {
  1927. var args = arguments;
  1928. if (args.length == 0) {
  1929. return this.extent$2();
  1930. }
  1931. if (args.length == 1) {
  1932. return this.extent$1(a0);
  1933. }
  1934. return this.extent$0(a0, a1);
  1935. },
  1936. /** @expose */
  1937. spacing : function(a0) {
  1938. var args = arguments;
  1939. if (args.length == 0) {
  1940. return this.spacing$2();
  1941. }
  1942. if (args.length == 1 && typeof a0 === "function") {
  1943. return this.spacing$1(a0);
  1944. }
  1945. return this.spacing$0(a0);
  1946. },
  1947. /** @expose */
  1948. alignment : function(a0) {
  1949. var args = arguments;
  1950. if (args.length == 0) {
  1951. return this.alignment$2();
  1952. }
  1953. if (args.length == 1 && (a0 == null || typeof a0 === "string")) {
  1954. return this.alignment$0(a0);
  1955. }
  1956. return this.alignment$1(a0);
  1957. },
  1958. /** @expose */
  1959. valignment : function(a0) {
  1960. var args = arguments;
  1961. if (args.length == 0) {
  1962. return this.valignment$2();
  1963. }
  1964. if (args.length == 1 && (a0 == null || typeof a0 === "string")) {
  1965. return this.valignment$0(a0);
  1966. }
  1967. return this.valignment$1(a0);
  1968. },
  1969. /** @expose */
  1970. padding : function(a0, a1, a2, a3) {
  1971. var args = arguments;
  1972. if (args.length == 0) {
  1973. return this.padding$0();
  1974. }
  1975. if (args.length == 1) {
  1976. return this.padding$2(a0);
  1977. }
  1978. return this.padding$1(a0, a1, a2, a3);
  1979. },
  1980. /** @expose */
  1981. minFont : function(a0) {
  1982. var args = arguments;
  1983. if (args.length == 0) {
  1984. return this.minFont$0();
  1985. }
  1986. if (args.length == 1 && typeof a0 === "function") {
  1987. return this.minFont$1(a0);
  1988. }
  1989. return this.minFont$2(a0);
  1990. },
  1991. /** @expose */
  1992. maxFont : function(a0) {
  1993. var args = arguments;
  1994. if (args.length == 0) {
  1995. return this.maxFont$0();
  1996. }
  1997. if (args.length == 1 && typeof a0 === "function") {
  1998. return this.maxFont$1(a0);
  1999. }
  2000. return this.maxFont$2(a0);
  2001. }
  2002. });
  2003. /**
  2004. * @return (Object) 0 insets object
  2005. */
  2006. com_ibm_rave_ext_text_wrap_TextFlow._createInsets = function() {
  2007. var result = {};
  2008. result["top"] = 0;
  2009. result["left"] = 0;
  2010. result["bottom"] = 0;
  2011. result["right"] = 0;
  2012. return result;
  2013. };
  2014. com_ibm_rave_ext_text_wrap_TextFlow.createFontStruct = function(style) {
  2015. var struct = new com_ibm_rave_ext_text_internal_wrap_FontStyleStruct();
  2016. struct.fontStyle = style["font-style"];
  2017. struct.fontVariant = style[com_ibm_rave_ext_text_wrap_TextFlow.FONT_VARIANT];
  2018. struct.fontWeight = style[com_ibm_rave_ext_text_wrap_TextFlow.FONT_WEIGHT];
  2019. struct.fontSize = style["font-size"];
  2020. struct.lineHeight = style[com_ibm_rave_ext_text_wrap_TextFlow.LINE_HEIGHT];
  2021. struct.fontFamily = style[com_ibm_rave_ext_text_wrap_TextFlow.FONT_FAMILY];
  2022. return struct;
  2023. };
  2024. com_ibm_rave_ext_text_wrap_TextFlow.Bounds = rave['internal']['Declare']({
  2025. /** @expose */
  2026. x : 0,
  2027. /** @expose */
  2028. y : 0,
  2029. /** @expose */
  2030. width : 0,
  2031. /** @expose */
  2032. height : 0,
  2033. /** @expose */
  2034. constructor : function(x, y, width, height) {
  2035. this.x = x;
  2036. this.y = y;
  2037. this.width = width;
  2038. this.height = height;
  2039. }
  2040. });
  2041. /**
  2042. * Alignment center
  2043. */
  2044. /** @expose */
  2045. com_ibm_rave_ext_text_wrap_TextFlow.CENTER = "center";
  2046. /**
  2047. * Alignment right
  2048. */
  2049. /** @expose */
  2050. com_ibm_rave_ext_text_wrap_TextFlow.RIGHT = "right";
  2051. /**
  2052. * Alignment left
  2053. */
  2054. /** @expose */
  2055. com_ibm_rave_ext_text_wrap_TextFlow.LEFT = "left";
  2056. /**
  2057. * Vertical alignment text baseline
  2058. */
  2059. /** @expose */
  2060. com_ibm_rave_ext_text_wrap_TextFlow.TOP = "top";
  2061. /**
  2062. * Vertical alignment text baseline bottom
  2063. */
  2064. /** @expose */
  2065. com_ibm_rave_ext_text_wrap_TextFlow.BOTTOM = "bottom";
  2066. /**
  2067. * Vertical alignment text baseline middle
  2068. */
  2069. /** @expose */
  2070. com_ibm_rave_ext_text_wrap_TextFlow.MIDDLE = "middle";
  2071. /**
  2072. * real alignment values
  2073. */
  2074. com_ibm_rave_ext_text_wrap_TextFlow._CENTER = "middle";
  2075. com_ibm_rave_ext_text_wrap_TextFlow._RIGHT = "end";
  2076. com_ibm_rave_ext_text_wrap_TextFlow._LEFT = "start";
  2077. com_ibm_rave_ext_text_wrap_TextFlow._DY = "dy";
  2078. com_ibm_rave_ext_text_wrap_TextFlow._FONT_SIZE = "font-size";
  2079. com_ibm_rave_ext_text_wrap_TextFlow._FONT = "font";
  2080. com_ibm_rave_ext_text_wrap_TextFlow._LINE_HEIGHT = "line-height";
  2081. com_ibm_rave_ext_text_wrap_TextFlow._WIDTH = "width";
  2082. com_ibm_rave_ext_text_wrap_TextFlow._HEIGHT = "height";
  2083. com_ibm_rave_ext_text_wrap_TextFlow._X = "x";
  2084. com_ibm_rave_ext_text_wrap_TextFlow._Y = "y";
  2085. com_ibm_rave_ext_text_wrap_TextFlow._H_ALIGN = "text-anchor";
  2086. com_ibm_rave_ext_text_wrap_TextFlow._V_ALIGN = "alignment-baseline";
  2087. com_ibm_rave_ext_text_wrap_TextFlow._BIDI = "unicode-bidi";
  2088. com_ibm_rave_ext_text_wrap_TextFlow._BIDI_EMBED = "embed";
  2089. com_ibm_rave_ext_text_wrap_TextFlow._BIDI_OVERRIDE = "bidi-override";
  2090. com_ibm_rave_ext_text_wrap_TextFlow._DIRECTION = "direction";
  2091. com_ibm_rave_ext_text_wrap_TextFlow._LTR = "ltr";
  2092. com_ibm_rave_ext_text_wrap_TextFlow._NAME = "name";
  2093. com_ibm_rave_ext_text_wrap_TextFlow._TRANSFORM = "transform";
  2094. com_ibm_rave_ext_text_wrap_TextFlow._TSPAN = "tspan";
  2095. com_ibm_rave_ext_text_wrap_TextFlow.FONT_STYLE = "font-style";
  2096. com_ibm_rave_ext_text_wrap_TextFlow.FONT_VARIANT = "font-variant";
  2097. com_ibm_rave_ext_text_wrap_TextFlow.FONT_WEIGHT = "font-weight";
  2098. com_ibm_rave_ext_text_wrap_TextFlow.FONT_SIZE = "font-size";
  2099. com_ibm_rave_ext_text_wrap_TextFlow.LINE_HEIGHT = "line-height";
  2100. com_ibm_rave_ext_text_wrap_TextFlow.FONT_FAMILY = "font-family";
  2101. /** @expose */
  2102. com_ibm_rave_ext_text_wrap_TextFlow.TSPAN_TRANSFORM_MARKER = " translate(0.0000,0.0000)";
  2103. com_ibm_rave_ext_text_wrap_TextFlow.EM = 1.36;
  2104. com_ibm_rave_ext_text_wrap_TextFlow.DEFAULT_PADDING = com_ibm_rave_ext_text_wrap_TextFlow._createInsets();
  2105. // $source: com/ibm/rave/ext/text/nativeImpl/FontChecker
  2106. /************************************************************************
  2107. ** IBM Confidential
  2108. **
  2109. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  2110. **
  2111. ** (C) Copyright IBM Corp. 2016, 2017
  2112. **
  2113. ** The source code for this program is not published or otherwise divested of its trade secrets,
  2114. ** irrespective of what has been deposited with the U.S. Copyright Office.
  2115. ************************************************************************/
  2116. var com_ibm_rave_ext_text_nativeImpl_FontChecker = rave['internal']['Declare']({
  2117. _$functionClassMethod : function() {
  2118. var _$self = /**
  2119. * @see RunFunction#_$self.run(Object, Object...)
  2120. */
  2121. function(args) {
  2122. return null;
  2123. };
  2124. return _$self;
  2125. },
  2126. constructor : function() {
  2127. },
  2128. /** @expose */
  2129. replaceLimitedFonts : function(textNode) {
  2130. return false;
  2131. },
  2132. /** @expose */
  2133. nodeFontChecker : function(data, index, groupIndex) {
  2134. }
  2135. });
  2136. // $source: com/ibm/rave/ext/text/internal/wrap/TextOperation
  2137. /************************************************************************
  2138. ** IBM Confidential
  2139. **
  2140. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  2141. **
  2142. ** (C) Copyright IBM Corp. 2017
  2143. **
  2144. ** The source code for this program is not published or otherwise divested of its trade secrets,
  2145. ** irrespective of what has been deposited with the U.S. Copyright Office.
  2146. ************************************************************************/
  2147. // GENERATED
  2148. //@import com/ibm/rave/ext/text/internal/wrap/FontStyleStruct (runtime) // new
  2149. //@import com/ibm/rave/ext/text/internal/nativeImpl/WordSplitter (runtime) // spaceBasedSplit
  2150. //@import com/ibm/rave/ext/text/internal/wrap/TextData (runtime) // new
  2151. //@import com/ibm/rave/ext/text/internal/wrap/WrapOperation (runtime) // new
  2152. //@import com/ibm/rave/ext/text/internal/wrap/FitOperation (runtime) // new
  2153. //@import com/ibm/rave/ext/text/internal/wrap/FitWrapOperation (runtime) // new
  2154. //@import com/ibm/rave/ext/text/internal/wrap/TruncateOperation (runtime) // new
  2155. /**
  2156. * Text operation wraps a single text into a width and height provided. Text operations are internal utilities for text wrapping, fitting and truncation. wrapping utility can be accessed via: <code>Rave.capabilities.extension("_textwrap"); </code>
  2157. */
  2158. var com_ibm_rave_ext_text_internal_wrap_TextOperation = rave['internal']['Declare']({
  2159. //_context : null,
  2160. //_text : null,
  2161. //_font : null,
  2162. _width : 0,
  2163. _height : 0,
  2164. _ems : 1,
  2165. _maxFontSize : Infinity,
  2166. _fontSize : 10,
  2167. _minFontSize : 4,
  2168. _textOverflow : "...",
  2169. _overflowMin : 0,
  2170. _$functionClassMethod : function() {
  2171. var _$self = /**
  2172. * Runs text operation, returns TextData data structure containing the result of operation and other properties, which explain the result (e.g. truncate or clip flags toggled on, fonts being used, etc)
  2173. * @return (com.ibm.rave.ext.text.internal.wrap.TextData) returns TextData data structure containing the result of operation
  2174. */
  2175. function() {
  2176. var lines = new com_ibm_rave_ext_text_internal_wrap_TextData();
  2177. lines.font = _$self._font;
  2178. if (_$self._runPrecondition()) {
  2179. return lines;
  2180. }
  2181. _$self._doRun(lines);
  2182. if (_$self._context) {
  2183. rave.canvas.disposeContext(_$self._context);
  2184. _$self._context = null;
  2185. }
  2186. return lines;
  2187. };
  2188. return _$self;
  2189. },
  2190. constructor : function() {
  2191. this._font = new com_ibm_rave_ext_text_internal_wrap_FontStyleStruct();
  2192. },
  2193. /**
  2194. * Create new text operation to wrap the text
  2195. * @param (String) text text to wrap
  2196. */
  2197. text : function(text) {
  2198. this._text = text;
  2199. return this;
  2200. },
  2201. /**
  2202. * Set width and height of the bounding rectangle to limit the text
  2203. * @param (double) width text bounding rectangle width
  2204. * @param (double) height text bounding rectangle height
  2205. * @return (com.ibm.rave.ext.text.internal.wrap.TextOperation) this
  2206. */
  2207. size : function(width, height) {
  2208. this._width = width;
  2209. this._height = height;
  2210. return this;
  2211. },
  2212. /**
  2213. * Set font to a struct of the following 6 properties: font-style font-variant font-weight font-size/line-height font-family. see https://developer.mozilla.org/en-US/docs/Web/CSS/font
  2214. * @param (com.ibm.rave.ext.text.internal.wrap.FontStyleStruct) font struct representing a font
  2215. * @return (com.ibm.rave.ext.text.internal.wrap.TextOperation) this
  2216. */
  2217. font : function(font) {
  2218. this._font = font;
  2219. return this;
  2220. },
  2221. /**
  2222. * Set font size to line size ratio. E.g. ems of 1.5 will make line height 1.5 times of the font size
  2223. * @param (double) ems font size to line size ratio. E.g. ems of 1.5 will make line height 1.5 times of the font size
  2224. * @return (com.ibm.rave.ext.text.internal.wrap.TextOperation) this
  2225. */
  2226. em : function(ems) {
  2227. this._ems = ems;
  2228. return this;
  2229. },
  2230. /**
  2231. * Set preferred font size in pixels
  2232. * @param (double) size font size in pixels
  2233. * @return (com.ibm.rave.ext.text.internal.wrap.TextOperation) this
  2234. */
  2235. maxFontSize : function(size) {
  2236. this._maxFontSize = size;
  2237. return this;
  2238. },
  2239. /**
  2240. * Set preferred font size in pixels
  2241. * @param (double) size font size in pixels
  2242. * @return (com.ibm.rave.ext.text.internal.wrap.TextOperation) this
  2243. */
  2244. fontSize : function(size) {
  2245. this._fontSize = size;
  2246. return this;
  2247. },
  2248. /**
  2249. * Set minimum font size to be used while performing fit
  2250. * @param (double) size minimum font size to be used by fit
  2251. * @return (com.ibm.rave.ext.text.internal.wrap.TextOperation) this
  2252. */
  2253. minFontSize : function(size) {
  2254. this._minFontSize = size;
  2255. return this;
  2256. },
  2257. /**
  2258. * @return (boolean) condition that would prevent run
  2259. */
  2260. _runPrecondition : function() {
  2261. return this._text == null || this._fontSize > this._height || this._text.length === 0;
  2262. },
  2263. /**
  2264. * Create rendering context, used to measure text width
  2265. */
  2266. createContext : function() {
  2267. this._context = rave.canvas.create(2, 2).getContext("2d");
  2268. },
  2269. _measureText : function(text) {
  2270. return this._context.measureText(text)["width"];
  2271. },
  2272. _forceFontSize : function(size, font) {
  2273. font.fontSize = size + "px";
  2274. },
  2275. _truncate : function() {
  2276. return this._textOverflow != null;
  2277. },
  2278. _clip$0 : function() {
  2279. return !(this._truncate());
  2280. },
  2281. _truncateOrClip : function(testLine, lines) {
  2282. var truncate = this._truncate();
  2283. var line = truncate ? this._ellipsize(testLine, lines) : this._clip$1(testLine, lines);
  2284. if (line == null || line.length === 0) {
  2285. return line;
  2286. }
  2287. lines.add(line);
  2288. return line;
  2289. },
  2290. /**
  2291. * @param (String) text string to clip to fit the max width
  2292. * @return (String) clipped string
  2293. */
  2294. _clip$1 : function(text, lines) {
  2295. lines.truncated = false;
  2296. var index = text.length;
  2297. if (index == 0) {
  2298. lines.clipped = false;
  2299. return text;
  2300. }
  2301. var testLine = text.substring(0, index);
  2302. while (this._measureText(testLine) > this._width && --index > 0) {
  2303. testLine = testLine.substring(0, index);
  2304. lines.clipped = true;
  2305. }
  2306. return testLine;
  2307. },
  2308. _doEllipsize : function(text, lines) {
  2309. var marker = text.length;
  2310. marker = marker < this._overflowMin ? 0 : marker;
  2311. var testLine = text.substring(0, marker) + " ";
  2312. marker = marker + 1;
  2313. var exit = false;
  2314. while (this._measureText(testLine.concat(this._textOverflow)) > this._width && !exit) {
  2315. marker--;
  2316. if (marker < this._overflowMin) {
  2317. marker = 0;
  2318. exit = true;
  2319. }
  2320. testLine = testLine.substring(0, marker);
  2321. }
  2322. if (this._measureText(testLine.concat(this._textOverflow)) > this._width) {
  2323. lines.truncated = false;
  2324. return null;
  2325. }
  2326. lines.truncated = true;
  2327. return testLine.concat(this._textOverflow);
  2328. },
  2329. /**
  2330. * Returns truncated text, or null, if not enough space. Text is truncated with ellipses set by textOverflow
  2331. * @param (String) text text to truncate
  2332. * @return (String) truncated text
  2333. * @see #this.textOverflow(String)
  2334. */
  2335. _ellipsize : function(text, lines) {
  2336. lines.clipped = false;
  2337. if (this._measureText(text) <= this._width) {
  2338. lines.truncated = false;
  2339. return text;
  2340. }
  2341. return this._doEllipsize(text, lines);
  2342. },
  2343. /**
  2344. * @param (String) _overflow ellipses string to be used for text truncation
  2345. */
  2346. textOverflow : function(_overflow) {
  2347. this._textOverflow = _overflow;
  2348. },
  2349. /**
  2350. * @param (int) _min a minimum string length before ellipses
  2351. */
  2352. overflowMin : function(_min) {
  2353. this._overflowMin = Math.abs(_min);
  2354. },
  2355. /**
  2356. * Init line height based on font size and assign font to rendering context
  2357. * @param (com.ibm.rave.ext.text.internal.wrap.TextData) lines data structure to hold the result of the text operation
  2358. */
  2359. _initFont : function(lines, font, font_size) {
  2360. lines.lineHeight = Math.ceil(font_size * this._ems);
  2361. this._context.font = font.toString();
  2362. },
  2363. _splitTextIntoWords : function(_text) {
  2364. return com_ibm_rave_ext_text_internal_nativeImpl_WordSplitter.spaceBasedSplit(_text);
  2365. },
  2366. _clip : function(a0, a1) {
  2367. var args = arguments;
  2368. if (args.length == 0) {
  2369. return this._clip$0();
  2370. }
  2371. return this._clip$1(a0, a1);
  2372. }
  2373. /**
  2374. * Run text operation
  2375. */
  2376. //_doRun : function(lines) {}
  2377. });
  2378. /**
  2379. * A factory method that creates a text operation based on option passed
  2380. * @param (byte) operation WRAP, FIT, or WRAP_FIT
  2381. * @param (String) text_overflow truncation options : value of 'text-overflow' attribute
  2382. * @return (com.ibm.rave.ext.text.internal.wrap.TextOperation) an instance of text operation with truncation options to wrap, fit, or wrap-fit
  2383. */
  2384. com_ibm_rave_ext_text_internal_wrap_TextOperation.getOperation = function(operation, text_overflow) {
  2385. switch (operation) {
  2386. case 1:
  2387. {
  2388. var fitter = new com_ibm_rave_ext_text_internal_wrap_WrapOperation();
  2389. fitter.textOverflow(text_overflow);
  2390. return fitter;
  2391. } case 2:
  2392. {
  2393. var fitter = new com_ibm_rave_ext_text_internal_wrap_FitOperation();
  2394. fitter.textOverflow(text_overflow);
  2395. return fitter;
  2396. } case 3:
  2397. {
  2398. var fitter = new com_ibm_rave_ext_text_internal_wrap_FitWrapOperation();
  2399. fitter.textOverflow(text_overflow);
  2400. return fitter;
  2401. } default:
  2402. if (text_overflow != null) {
  2403. var fitter = new com_ibm_rave_ext_text_internal_wrap_TruncateOperation();
  2404. fitter.textOverflow(text_overflow);
  2405. return fitter;
  2406. }
  2407. }
  2408. return null;
  2409. };
  2410. /**
  2411. * no operation
  2412. */
  2413. com_ibm_rave_ext_text_internal_wrap_TextOperation.NONE = 0;
  2414. /**
  2415. * WRAP operation
  2416. */
  2417. com_ibm_rave_ext_text_internal_wrap_TextOperation.WRAP = 1;
  2418. /**
  2419. * FIR operation
  2420. */
  2421. com_ibm_rave_ext_text_internal_wrap_TextOperation.FIT = 1 << 1;
  2422. /**
  2423. * WRAP and FIR operation
  2424. */
  2425. com_ibm_rave_ext_text_internal_wrap_TextOperation.WRAP_FIT = 1 | 2;
  2426. // $source: com/ibm/rave/ext/text/internal/wrap/FontStyleStruct
  2427. /************************************************************************
  2428. ** IBM Confidential
  2429. **
  2430. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  2431. **
  2432. ** (C) Copyright IBM Corp. 2017
  2433. **
  2434. ** The source code for this program is not published or otherwise divested of its trade secrets,
  2435. ** irrespective of what has been deposited with the U.S. Copyright Office.
  2436. ************************************************************************/
  2437. // GENERATED
  2438. /**
  2439. * An internal struct that mimics a CSS font's properties. Has a toString() method that will return a shorthand font string in this format: font-style font-variant font-weight font-size/line-height font-family
  2440. */
  2441. var com_ibm_rave_ext_text_internal_wrap_FontStyleStruct = rave['internal']['Declare']({
  2442. fontStyle : "normal",
  2443. fontVariant : "normal",
  2444. fontWeight : "normal",
  2445. fontSize : "10px",
  2446. lineHeight : "normal",
  2447. fontFamily : "'sans serif'",
  2448. toString : function() {
  2449. return this.fontStyle + " " + this.fontVariant + " " + this.fontWeight + " " + this.fontSize + "/" + this.lineHeight + " " + this.fontFamily;
  2450. }
  2451. });
  2452. // $source: com/ibm/rave/ext/text/internal/nativeImpl/WordSplitter
  2453. /************************************************************************
  2454. ** IBM Confidential
  2455. **
  2456. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  2457. **
  2458. ** (C) Copyright IBM Corp. 2015, 2017
  2459. **
  2460. ** The source code for this program is not published or otherwise divested of its trade secrets,
  2461. ** irrespective of what has been deposited with the U.S. Copyright Office.
  2462. ************************************************************************/
  2463. var com_ibm_rave_ext_text_internal_nativeImpl_WordSplitter = rave['internal']['Declare']({
  2464. });
  2465. /** @expose */
  2466. com_ibm_rave_ext_text_internal_nativeImpl_WordSplitter.spaceBasedSplit = function(text) {
  2467. return text.split(/\s/);
  2468. };
  2469. /** @expose */
  2470. com_ibm_rave_ext_text_internal_nativeImpl_WordSplitter.isWhitespace = function(item) {
  2471. // return item == ' ' || item == '\t' || item == '\n' || item == '\r';
  2472. return item == 32 || item == 9 || item == 13 || item == 10;
  2473. };
  2474. // $source: com/ibm/rave/ext/text/internal/wrap/TextData
  2475. /************************************************************************
  2476. ** IBM Confidential
  2477. **
  2478. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  2479. **
  2480. ** (C) Copyright IBM Corp. 2017
  2481. **
  2482. ** The source code for this program is not published or otherwise divested of its trade secrets,
  2483. ** irrespective of what has been deposited with the U.S. Copyright Office.
  2484. ************************************************************************/
  2485. // GENERATED
  2486. /**
  2487. * Data structure that stores data for wrapped text lines
  2488. */
  2489. var com_ibm_rave_ext_text_internal_wrap_TextData = rave['internal']['Declare']({
  2490. /**
  2491. * Lines array
  2492. */
  2493. //lines : null,
  2494. /**
  2495. * font used for wrap-truncate-fit
  2496. */
  2497. //font : null,
  2498. /**
  2499. * true if text was truncated, false otherwise
  2500. */
  2501. truncated : false,
  2502. /**
  2503. * true if text was clipped, false otherwise
  2504. */
  2505. clipped : false,
  2506. /**
  2507. * true if text was too tall for the height. As the result it will either be clipped or truncated
  2508. */
  2509. tooTall : false,
  2510. /**
  2511. * line height (dy offset) between the lines
  2512. */
  2513. lineHeight : 0,
  2514. /**
  2515. * font size used in text operation
  2516. */
  2517. fontSize : 0,
  2518. constructor : function() {
  2519. this.lines = [];
  2520. },
  2521. /**
  2522. * @param (String) line line text string
  2523. */
  2524. add : function(line) {
  2525. this.lines.push(line);
  2526. },
  2527. /**
  2528. * @return (int) number of lines
  2529. */
  2530. length : function() {
  2531. return this.lines.length;
  2532. }
  2533. });
  2534. // $source: com/ibm/rave/ext/text/internal/nativeImpl/TextLength
  2535. /************************************************************************
  2536. ** IBM Confidential
  2537. **
  2538. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  2539. **
  2540. ** (C) Copyright IBM Corp. 2016
  2541. **
  2542. ** The source code for this program is not published or otherwise divested of its trade secrets,
  2543. ** irrespective of what has been deposited with the U.S. Copyright Office.
  2544. ************************************************************************/
  2545. var com_ibm_rave_ext_text_internal_nativeImpl_TextLength = rave['internal']['Declare']({
  2546. });
  2547. /** @expose */
  2548. com_ibm_rave_ext_text_internal_nativeImpl_TextLength.getTenPtLength = function(text, fontStr, fontStyle) {
  2549. // re-use canvas object for better performance
  2550. var canvas = this.canvas || (this.canvas = document.createElement("canvas"));
  2551. var context = canvas.getContext("2d");
  2552. context.font = fontStyle + " 10px " + fontStr;
  2553. var metrics = context.measureText(text);
  2554. return metrics.width;
  2555. };
  2556. // $source: com/ibm/rave/ext/geo/tile/TileLayout
  2557. /************************************************************************
  2558. ** IBM Confidential
  2559. **
  2560. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  2561. **
  2562. ** (C) Copyright IBM Corp. 2017
  2563. **
  2564. ** The source code for this program is not published or otherwise divested of its trade secrets,
  2565. ** irrespective of what has been deposited with the U.S. Copyright Office.
  2566. ************************************************************************/
  2567. // GENERATED
  2568. /**
  2569. * A layout for determining which 256x256 quadtree tiles to display in a rectangular viewport, based on a scale and translate. This layout can be used to create a simple slippy map, or render standard map tiles (e.g., MapBox, CloudMade) as a base layer behind a geographic projection.
  2570. */
  2571. var com_ibm_rave_ext_geo_tile_TileLayout = rave['internal']['Declare']({
  2572. //sizeVal : null,
  2573. //translateVal : null,
  2574. scaleVal : 256,
  2575. zoomDeltaVal : 0,
  2576. _$functionClassMethod : function() {
  2577. var _$self = /**
  2578. * Runs the tile algorithm
  2579. * @return (com.ibm.rave.ext.geo.tile.TileLayout.TilesData) the tiles data generated, @see {@link (com.ibm.rave.ext.geo.tile.TileLayout.TilesData) TilesData}
  2580. */
  2581. function() {
  2582. var tiles = new com_ibm_rave_ext_geo_tile_TileLayout.TilesData();
  2583. var z = Math.max(Math.log(_$self.scaleVal) / Math["LN2"] - 8, 0);
  2584. var z0 = Math.round(z + _$self.zoomDeltaVal);
  2585. var k = Math.pow(2, z - z0 + 8);
  2586. var origin = [(_$self.translateVal[0] - _$self.scaleVal / 2) / k, (_$self.translateVal[1] - _$self.scaleVal / 2) / k];
  2587. var cols = rave.range(Math.max(0, Math.floor(-origin[0])), Math.max(0, Math.ceil(_$self.sizeVal[0] / k - origin[0])));
  2588. var rows = rave.range(Math.max(0, Math.floor(-origin[1])), Math.max(0, Math.ceil(_$self.sizeVal[1] / k - origin[1])));
  2589. rows.forEach(function(y, index, array) {
  2590. cols.forEach(function(x, index, array) {
  2591. tiles.push([x, y, z0]);
  2592. return null;
  2593. });
  2594. return null;
  2595. });
  2596. tiles.translate = origin;
  2597. tiles.scale = k;
  2598. return tiles;
  2599. };
  2600. return _$self;
  2601. },
  2602. constructor : function() {
  2603. this.sizeVal = [960, 500];
  2604. this.translateVal = [this.sizeVal[0] / 2, this.sizeVal[1] / 2];
  2605. },
  2606. /**
  2607. * Gets the size of the view port used during tiling
  2608. * @return (double[]) width and height
  2609. */
  2610. size$0 : function() {
  2611. return this.sizeVal;
  2612. },
  2613. /**
  2614. * Sets the size of the ViewPort to use during running the tile layout
  2615. * @param (double[]) newSize
  2616. * @return (com.ibm.rave.ext.geo.tile.TileLayout) this TileLayout instance itself
  2617. */
  2618. size$1 : function(newSize) {
  2619. this.sizeVal = newSize;
  2620. return this;
  2621. },
  2622. /**
  2623. * Returns the current scale factor which defaults to 256
  2624. * @return (double) the current scale factor
  2625. */
  2626. scale$0 : function() {
  2627. return this.scaleVal;
  2628. },
  2629. /**
  2630. * Sets the tile scale factor to the specified value. The scale factor corresponds linearly to the distance between projected points.
  2631. * @param (double) newScaleVal the scale factor to set.
  2632. * @return (com.ibm.rave.ext.geo.tile.TileLayout) this TileLayout instance itself
  2633. */
  2634. scale$1 : function(newScaleVal) {
  2635. this.scaleVal = newScaleVal;
  2636. return this;
  2637. },
  2638. /**
  2639. * Gets the translate value (the default value is viewPortWidth/2, view portHeight/2)
  2640. * @return (double[]) translate value
  2641. */
  2642. translate$0 : function() {
  2643. return this.translateVal;
  2644. },
  2645. /**
  2646. * Sets the translate value
  2647. * @param (double[]) newTranslateVal the new translate value [width,height]
  2648. * @return (com.ibm.rave.ext.geo.tile.TileLayout) this layout
  2649. */
  2650. translate$1 : function(newTranslateVal) {
  2651. this.translateVal = newTranslateVal;
  2652. return this;
  2653. },
  2654. /**
  2655. * Gets the current Zoom delta
  2656. * @return (double) zoom delta
  2657. */
  2658. zoomDelta$0 : function() {
  2659. return this.zoomDeltaVal;
  2660. },
  2661. /**
  2662. * Sets the current Zoom Delta
  2663. * @param (double) newZoomDeltaVal the new zoom delta
  2664. * @return (com.ibm.rave.ext.geo.tile.TileLayout) this layout
  2665. */
  2666. zoomDelta$1 : function(newZoomDeltaVal) {
  2667. this.zoomDeltaVal = newZoomDeltaVal;
  2668. return this;
  2669. },
  2670. /** @expose */
  2671. size : function(a0) {
  2672. var args = arguments;
  2673. if (args.length == 0) {
  2674. return this.size$0();
  2675. }
  2676. return this.size$1(a0);
  2677. },
  2678. /** @expose */
  2679. scale : function(a0) {
  2680. var args = arguments;
  2681. if (args.length == 0) {
  2682. return this.scale$0();
  2683. }
  2684. return this.scale$1(a0);
  2685. },
  2686. /** @expose */
  2687. translate : function(a0) {
  2688. var args = arguments;
  2689. if (args.length == 0) {
  2690. return this.translate$0();
  2691. }
  2692. return this.translate$1(a0);
  2693. },
  2694. /** @expose */
  2695. zoomDelta : function(a0) {
  2696. var args = arguments;
  2697. if (args.length == 0) {
  2698. return this.zoomDelta$0();
  2699. }
  2700. return this.zoomDelta$1(a0);
  2701. }
  2702. });
  2703. /**
  2704. * Simple Array data structure representing a tiles info Each entry represent a tile the data structure contains as well the scale used during the calculations and the translate matrix
  2705. */
  2706. com_ibm_rave_ext_geo_tile_TileLayout.TilesData = rave['internal']['Declare'](Array, {
  2707. /** @expose */
  2708. translate : null,
  2709. /** @expose */
  2710. scale : 0
  2711. });
  2712. // $source: com/ibm/rave/ext/geo/tile/TiledMapGenerator
  2713. /************************************************************************
  2714. ** IBM Confidential
  2715. **
  2716. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  2717. **
  2718. ** (C) Copyright IBM Corp. 2017
  2719. **
  2720. ** The source code for this program is not published or otherwise divested of its trade secrets,
  2721. ** irrespective of what has been deposited with the U.S. Copyright Office.
  2722. ************************************************************************/
  2723. // GENERATED
  2724. //@import com/ibm/rave/ext/geo/RaveGeo (runtime) // tile
  2725. /**
  2726. * High Level component to make it easier to build a tiled map visualization The default implementation follows the WMTS (Web Map Tile Service) standard to build URLS for the different tiles, but users can provide their own url generator function if they want to use a tile provider that does not follow this standard.
  2727. */
  2728. var com_ibm_rave_ext_geo_tile_TiledMapGenerator = rave['internal']['Declare']({
  2729. //centerPointVal : null,
  2730. //tileLayout : null,
  2731. //vecData : null,
  2732. //zoomVal : null,
  2733. //projectionVal : null,
  2734. //vectorLayer : null,
  2735. //path : null,
  2736. //providerInfoVal : null,
  2737. //zoomExtentVal : null,
  2738. //urlBuilderFn : null,
  2739. widthVal : 960,
  2740. heightVal : 960,
  2741. projectionScaleVal : 1 << 21,
  2742. _$functionClassMethod : function() {
  2743. var _$self = function(args) {
  2744. if (args !== null || arguments.length > 1){
  2745. args = Array.prototype.slice.call(arguments, 0);
  2746. }
  2747. {
  2748. _$self.createTiles(args[0]);
  2749. return null;
  2750. }
  2751. };
  2752. return _$self;
  2753. },
  2754. constructor : function() {
  2755. this.centerPointVal = [-100, 40];
  2756. this.zoomExtentVal = [0, Infinity];
  2757. this.urlBuilderFn = com_ibm_rave_ext_geo_tile_TiledMapGenerator.DEFAULT_URL_GEN;
  2758. },
  2759. /** @expose */
  2760. createTiles : function(selector) {
  2761. this.tileLayout = com_ibm_rave_ext_geo_RaveGeo.tile().size([this.widthVal, this.heightVal]);
  2762. this.projectionVal = rave.geo.mercator().scale(this.projectionScaleVal / 2 / Math.PI).translate([-this.widthVal / 2, -this.heightVal / 2]);
  2763. var projectedCenetr = this.projectionVal([this.centerPointVal[0], this.centerPointVal[1]]);
  2764. this.path = rave.geo.path().projection(this.projectionVal);
  2765. if (!this.zoomVal) {
  2766. this.zoomVal = rave.behavior.zoom();
  2767. }
  2768. var invertedCenter = projectedCenetr.map(function(currentValue, index, array) {
  2769. return -1 * currentValue;
  2770. });
  2771. this.zoomVal.scale(this.projectionVal.scale() * 2 * Math.PI).scaleExtent([this.zoomExtentVal[0], this.zoomExtentVal[1]]).translate([invertedCenter[0], invertedCenter[1]]);
  2772. var outer = this;
  2773. var zoomedFn = function(args) {
  2774. if (args !== null || arguments.length > 1){
  2775. args = Array.prototype.slice.call(arguments, 0);
  2776. }
  2777. {
  2778. var translatePoint = outer.zoomVal.translate();
  2779. var arrayExVal = [translatePoint[0], translatePoint[1]];
  2780. var zoomScale = outer.zoomVal.scale();
  2781. outer.tileLayout.scale(zoomScale).translate([translatePoint[0], translatePoint[1]]);
  2782. outer.projectionVal.scale(zoomScale / 2 / Math.PI).translate(arrayExVal);
  2783. var tiles = outer.tileLayout();
  2784. if (outer.vectorLayer) {
  2785. outer.vectorLayer.attr("d", outer.path);
  2786. }
  2787. var groups = selector.selectAll("g." + com_ibm_rave_ext_geo_tile_TiledMapGenerator.CONTAINER_CLASS).data(outer.providerInfoVal);
  2788. groups.exit().remove();
  2789. groups.enter().append("g").classed(com_ibm_rave_ext_geo_tile_TiledMapGenerator.CONTAINER_CLASS, true);
  2790. groups.each(function(data, index, groupIndex) {
  2791. var g = rave.select(this);
  2792. var providerInfo = data;
  2793. if (providerInfo["type"] == "image") {
  2794. outer.handleImages(g, tiles, providerInfo);
  2795. } else if (providerInfo["type"] == "path") {
  2796. outer.handleVector(g, tiles, providerInfo);
  2797. }
  2798. });
  2799. return null;
  2800. }
  2801. };
  2802. selector.call(this.zoomVal);
  2803. zoomedFn.call(null);
  2804. this.zoomVal.on("zoom", zoomedFn);
  2805. if (this.vecData != null) {
  2806. this.vectorLayer = selector.append("path");
  2807. this.vectorLayer.datum(this.vecData);
  2808. }
  2809. },
  2810. /**
  2811. * Gets the current width
  2812. * @return (double) the width
  2813. */
  2814. width$0 : function() {
  2815. return this.widthVal;
  2816. },
  2817. /**
  2818. * Sets the current width
  2819. * @param (double) newVal the new width
  2820. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator) this tiled Map
  2821. */
  2822. width$1 : function(newVal) {
  2823. this.widthVal = newVal;
  2824. return this;
  2825. },
  2826. /**
  2827. * Gets the current height
  2828. * @return (double) the height
  2829. */
  2830. height$0 : function() {
  2831. return this.heightVal;
  2832. },
  2833. /**
  2834. * Sets the current height
  2835. * @param (double) newVal the new height
  2836. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator) this tiled Map
  2837. */
  2838. height$1 : function(newVal) {
  2839. this.heightVal = newVal;
  2840. return this;
  2841. },
  2842. /**
  2843. * Gets the current scale for the projection
  2844. * @return (double) the current projection scale
  2845. */
  2846. projectionScale$0 : function() {
  2847. return this.projectionScaleVal;
  2848. },
  2849. /**
  2850. * Sets the current scale for the projection
  2851. * @param (double) newProjectionScaleVal the new projection scale value
  2852. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator) this tiled Map
  2853. */
  2854. projectionScale$1 : function(newProjectionScaleVal) {
  2855. this.projectionScaleVal = newProjectionScaleVal;
  2856. return this;
  2857. },
  2858. /**
  2859. * Gets the current providers information {@link (Object) TileProviderInfo}
  2860. * @return (com.ibm.rave.ext.geo.tile.TileProviderInfo[]) current providers information
  2861. */
  2862. providerInfo$0 : function() {
  2863. return this.providerInfoVal;
  2864. },
  2865. /**
  2866. * Sets the current providers information {@link (Object) TileProviderInfo}
  2867. * @param (com.ibm.rave.ext.geo.tile.TileProviderInfo[]) newProviderInfoVal An array of provider info to use
  2868. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator) this tiled Map
  2869. */
  2870. providerInfo$1 : function(newProviderInfoVal) {
  2871. this.providerInfoVal = newProviderInfoVal;
  2872. return this;
  2873. },
  2874. /**
  2875. * Gets the current center for the tiled map in Long/Lat
  2876. * @return (double[]) the current center
  2877. */
  2878. center$0 : function() {
  2879. return this.centerPointVal;
  2880. },
  2881. /**
  2882. * Sets the current center for the tiled map in Long/Lat
  2883. * @param (double[]) newCenterPointVal the new center point
  2884. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator) this tiled Map
  2885. */
  2886. center$1 : function(newCenterPointVal) {
  2887. this.centerPointVal = newCenterPointVal;
  2888. return this;
  2889. },
  2890. /**
  2891. * Gets the current zoom object
  2892. * @return (rave['internal']['Zoom']) the current zoom object
  2893. */
  2894. zoom$0 : function() {
  2895. return this.zoomVal;
  2896. },
  2897. /**
  2898. * Sets the current zoom object
  2899. * @param (rave['internal']['Zoom']) newZoomVal The new zoom level
  2900. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator) this tiled Map
  2901. */
  2902. zoom$1 : function(newZoomVal) {
  2903. this.zoomVal = newZoomVal;
  2904. return this;
  2905. },
  2906. /**
  2907. * Gets the current projection object
  2908. * @return (rave['internal']['Projection']) the current projection object
  2909. */
  2910. projection$0 : function() {
  2911. return this.projectionVal;
  2912. },
  2913. /**
  2914. * Sets the projection
  2915. * @param (rave['internal']['Projection']) newProjectionVal The new projection value
  2916. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator) this tiled Map
  2917. */
  2918. projection$1 : function(newProjectionVal) {
  2919. this.projectionVal = newProjectionVal;
  2920. return this;
  2921. },
  2922. /**
  2923. * Gets the current zoom extent value
  2924. * @return (double[]) the current zoom extent
  2925. */
  2926. zoomExtent$0 : function() {
  2927. return this.zoomExtentVal;
  2928. },
  2929. /**
  2930. * Sets the current zoom extent value, use this API to control the Max and Min zoom level
  2931. * @param (double[]) newZoomExtent The new zoom extent value
  2932. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator) this tiled Map
  2933. */
  2934. zoomExtent$1 : function(newZoomExtent) {
  2935. this.zoomExtentVal = newZoomExtent;
  2936. return this;
  2937. },
  2938. /**
  2939. * Gets the current overlay data
  2940. * @return (Object) the current overlay data
  2941. */
  2942. vectorOverlayData$0 : function() {
  2943. return this.vecData;
  2944. },
  2945. /**
  2946. * Sets the current overlay data
  2947. * @param (Object) newVecData The overlay data
  2948. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator) this tiled Map
  2949. */
  2950. vectorOverlayData$1 : function(newVecData) {
  2951. this.vecData = newVecData;
  2952. return this;
  2953. },
  2954. /**
  2955. * Gets the current URL builder function
  2956. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator.URLGenerator) the current URL builder function
  2957. */
  2958. urlBuilder$0 : function() {
  2959. return this.urlBuilderFn;
  2960. },
  2961. /**
  2962. * Sets the current URL builder function
  2963. * @param (com.ibm.rave.ext.geo.tile.TiledMapGenerator.URLGenerator) newGen The URL gen function
  2964. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator) this tiled Map
  2965. */
  2966. urlBuilder$1 : function(newGen) {
  2967. this.urlBuilderFn = newGen;
  2968. return this;
  2969. },
  2970. handleImages : function(g, tiles, providerInfo) {
  2971. var imageSelector = g.attr("transform", "scale(" + tiles.scale + ")translate(" + tiles.translate + ")").selectAll("image").data(tiles, com_ibm_rave_ext_geo_tile_TiledMapGenerator.DATA_FUN);
  2972. imageSelector.exit().remove();
  2973. var outer = this;
  2974. imageSelector.enter().append("image").attr("xlink:href", function(data, index, groupIndex) {
  2975. return outer.urlBuilderFn(providerInfo, data);
  2976. }).attr("width", 1).attr("height", 1).attr("x", com_ibm_rave_ext_geo_tile_TiledMapGenerator.X_VALUEFUNCTION).attr("y", com_ibm_rave_ext_geo_tile_TiledMapGenerator.Y_VALUEFUNCTION);
  2977. },
  2978. handleVector : function(g, tiles, providerInfo) {
  2979. var tilePath = rave.geo.path().projection(this.projectionVal);
  2980. var vectorTiles = g.attr("transform", this.matrix2d(tiles.scale, tiles.translate)).selectAll("g.tile").data(tiles, com_ibm_rave_ext_geo_tile_TiledMapGenerator.DATA_FUN);
  2981. vectorTiles.exit().each(function(data, index, groupIndex) {
  2982. ((this.rave_getProperty("_xhr"))).abort();
  2983. }).remove();
  2984. var outer = this;
  2985. vectorTiles.enter().append("g").attr("class", "tile").attr("transform", com_ibm_rave_ext_geo_tile_TiledMapGenerator.TRANSLATE_FUN).each(function(data, index, groupIndex) {
  2986. var current = rave.select(this);
  2987. var tileInfo = data;
  2988. var url = outer.urlBuilderFn(providerInfo, tileInfo);
  2989. this.rave_setProperty("_xhr", rave.json(url, function(error, response) {
  2990. var k = Math.pow(2, tileInfo[2]) * 256;
  2991. ((tilePath.projection())).translate([k / 2 - tileInfo[0] * 256, k / 2 - tileInfo[1] * 256]).scale(k / 2 / Math.PI);
  2992. var jsonResponse = response;
  2993. var features = jsonResponse["features"];
  2994. features.sort(com_ibm_rave_ext_geo_tile_TiledMapGenerator.SORTKEY_COMPARATOR);
  2995. current.selectAll("path").data(features).enter().append("path").attr("class", com_ibm_rave_ext_geo_tile_TiledMapGenerator.CLASS_NAME_EXTRACTOR).attr("d", tilePath);
  2996. }));
  2997. });
  2998. },
  2999. matrix2d : function(scale, translate) {
  3000. var k = scale / 256;
  3001. var transform = [k, 0, 0, k, Math.round(translate[0] * scale), Math.round(translate[1] * scale)];
  3002. return "matrix(" + (transform) + ")";
  3003. },
  3004. /** @expose */
  3005. width : function(a0) {
  3006. var args = arguments;
  3007. if (args.length == 0) {
  3008. return this.width$0();
  3009. }
  3010. return this.width$1(a0);
  3011. },
  3012. /** @expose */
  3013. height : function(a0) {
  3014. var args = arguments;
  3015. if (args.length == 0) {
  3016. return this.height$0();
  3017. }
  3018. return this.height$1(a0);
  3019. },
  3020. /** @expose */
  3021. projectionScale : function(a0) {
  3022. var args = arguments;
  3023. if (args.length == 0) {
  3024. return this.projectionScale$0();
  3025. }
  3026. return this.projectionScale$1(a0);
  3027. },
  3028. /** @expose */
  3029. providerInfo : function(a0) {
  3030. var args = arguments;
  3031. if (args.length == 0) {
  3032. return this.providerInfo$0();
  3033. }
  3034. return this.providerInfo$1(a0);
  3035. },
  3036. /** @expose */
  3037. center : function(a0) {
  3038. var args = arguments;
  3039. if (args.length == 0) {
  3040. return this.center$0();
  3041. }
  3042. return this.center$1(a0);
  3043. },
  3044. /** @expose */
  3045. zoom : function(a0) {
  3046. var args = arguments;
  3047. if (args.length == 0) {
  3048. return this.zoom$0();
  3049. }
  3050. return this.zoom$1(a0);
  3051. },
  3052. /** @expose */
  3053. projection : function(a0) {
  3054. var args = arguments;
  3055. if (args.length == 0) {
  3056. return this.projection$0();
  3057. }
  3058. return this.projection$1(a0);
  3059. },
  3060. /** @expose */
  3061. zoomExtent : function(a0) {
  3062. var args = arguments;
  3063. if (args.length == 0) {
  3064. return this.zoomExtent$0();
  3065. }
  3066. return this.zoomExtent$1(a0);
  3067. },
  3068. /** @expose */
  3069. vectorOverlayData : function(a0) {
  3070. var args = arguments;
  3071. if (args.length == 0) {
  3072. return this.vectorOverlayData$0();
  3073. }
  3074. return this.vectorOverlayData$1(a0);
  3075. },
  3076. /** @expose */
  3077. urlBuilder : function(a0) {
  3078. var args = arguments;
  3079. if (args.length == 0) {
  3080. return this.urlBuilder$0();
  3081. }
  3082. return this.urlBuilder$1(a0);
  3083. }
  3084. });
  3085. com_ibm_rave_ext_geo_tile_TiledMapGenerator.TILE_SIZE = 256;
  3086. com_ibm_rave_ext_geo_tile_TiledMapGenerator.JSON_KIND = "kind";
  3087. com_ibm_rave_ext_geo_tile_TiledMapGenerator.JSON_SORT_KEY = "sort_key";
  3088. com_ibm_rave_ext_geo_tile_TiledMapGenerator.JSON_PROPERTIES_FEATURE = "properties";
  3089. com_ibm_rave_ext_geo_tile_TiledMapGenerator.TILE_CLASS = "tile";
  3090. com_ibm_rave_ext_geo_tile_TiledMapGenerator.TYPE_PATH = "path";
  3091. com_ibm_rave_ext_geo_tile_TiledMapGenerator.TYPE_IMAGE = "image";
  3092. com_ibm_rave_ext_geo_tile_TiledMapGenerator.CONTAINER_CLASS = "mContainers";
  3093. com_ibm_rave_ext_geo_tile_TiledMapGenerator.DEFAULT_URL_GEN = function(providerInfo, tileInfo) {
  3094. return "http://" + providerInfo["url"] + tileInfo[2] + "/" + tileInfo[0] + "/" + tileInfo[1] + "." + providerInfo["extension"] + (providerInfo["access_token"] == null ? "" : ("?access_token=" + providerInfo["access_token"]));
  3095. };
  3096. com_ibm_rave_ext_geo_tile_TiledMapGenerator.TRANSLATE_FUN = function(data, index, groupIndex) {
  3097. var currentData = data;
  3098. return "translate(" + currentData[0] * 256 + "," + currentData[1] * 256 + ")";
  3099. };
  3100. com_ibm_rave_ext_geo_tile_TiledMapGenerator.DATA_FUN = function(data, index, groupIndex) {
  3101. return data;
  3102. };
  3103. com_ibm_rave_ext_geo_tile_TiledMapGenerator.X_VALUEFUNCTION = function(data, index, groupIndex) {
  3104. return (data)[0];
  3105. };
  3106. com_ibm_rave_ext_geo_tile_TiledMapGenerator.Y_VALUEFUNCTION = function(data, index, groupIndex) {
  3107. return (data)[1];
  3108. };
  3109. com_ibm_rave_ext_geo_tile_TiledMapGenerator.SORTKEY_COMPARATOR = function(o1, o2) {
  3110. var sort_key1 = (o1["properties"])["sort_key"];
  3111. var sort_key2 = (o2["properties"])["sort_key"];
  3112. return sort_key1 - sort_key2;
  3113. };
  3114. com_ibm_rave_ext_geo_tile_TiledMapGenerator.CLASS_NAME_EXTRACTOR = function(data, index, groupIndex) {
  3115. var currentData = data;
  3116. return (currentData["properties"])["kind"];
  3117. };
  3118. // $source: com/ibm/rave/ext/symbol/RaveSymbol
  3119. /************************************************************************
  3120. ** IBM Confidential
  3121. **
  3122. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  3123. **
  3124. ** (C) Copyright IBM Corp. 2017
  3125. **
  3126. ** The source code for this program is not published or otherwise divested of its trade secrets,
  3127. ** irrespective of what has been deposited with the U.S. Copyright Office.
  3128. ************************************************************************/
  3129. // GENERATED
  3130. /**
  3131. * A class whose sole purpose is registering extra symbol creator with core's Symbol These new shapes are: <li>rectangle and horizontal-rectangle</li> <li>vertical-rectangle</li> <li>triangle-left</li> <li>triangle-right</li> <li>star</li> <li>donut</li> <li>LegendLineSymbol</li>
  3132. */
  3133. var com_ibm_rave_ext_symbol_RaveSymbol = {
  3134. };
  3135. com_ibm_rave_ext_symbol_RaveSymbol.getRegistrationStatus = function() {
  3136. var registrationStatus = rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().getData("RAVESYMBOL_EXTENSION_REGISTRATION_STATUS_KEY");
  3137. if (!registrationStatus) {
  3138. registrationStatus = new com_ibm_rave_ext_symbol_RaveSymbol.RegistrationStatus();
  3139. rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().putData("RAVESYMBOL_EXTENSION_REGISTRATION_STATUS_KEY", registrationStatus);
  3140. }
  3141. return registrationStatus;
  3142. };
  3143. /**
  3144. * Register all extended symbol creators
  3145. * @return (boolean) true if registration was successful, false otherwise
  3146. * @see SymbolCreator
  3147. */
  3148. /** @expose */
  3149. com_ibm_rave_ext_symbol_RaveSymbol.init = function() {
  3150. var registrationStatus = com_ibm_rave_ext_symbol_RaveSymbol.getRegistrationStatus();
  3151. if (!registrationStatus.registered) {
  3152. var SQRT3 = Math.sqrt(3.0);
  3153. var rect = function(size) {
  3154. var r = Math.sqrt(size / 2.0) / 2.0;
  3155. var w = 2 * r;
  3156. return "M" + -w + "," + -r + "H" + w + "V" + r + "H" + -w + "Z";
  3157. };
  3158. var status = rave.svg.symbolCreator("rectangle", rect);
  3159. status &= rave.svg.symbolCreator("horizontal-rectangle", rect);
  3160. status &= rave.svg.symbolCreator("vertical-rectangle", function(size) {
  3161. var r = Math.sqrt(size / 2.0) / 2.0;
  3162. var h = 2 * r;
  3163. return "M" + -r + "," + -h + "H" + r + "V" + h + "H" + -r + "Z";
  3164. });
  3165. status &= rave.svg.symbolCreator("triangle-left", function(size) {
  3166. var ry = Math.sqrt(size / SQRT3);
  3167. var rx = ry * SQRT3 / 2;
  3168. return "M" + -rx + ",0L" + rx + "," + -ry + " " + rx + "," + ry + "Z";
  3169. });
  3170. status &= rave.svg.symbolCreator("triangle-right", function(size) {
  3171. var ry = Math.sqrt(size / SQRT3);
  3172. var rx = ry * SQRT3 / 2;
  3173. return "M" + rx + ",0L" + -rx + "," + ry + " " + -rx + "," + -ry + "Z";
  3174. });
  3175. status &= rave.svg.symbolCreator("star", function(size) {
  3176. var outerRadius = (Math.sqrt(size / Math.PI) * 1.5);
  3177. var innerRadius = outerRadius * 0.4;
  3178. var results = "M0," + outerRadius;
  3179. var angle = Math.PI / 5;
  3180. for (var i = 0; i < 2 * 5; ++i) {
  3181. var r = (i & 1) == 0 ? outerRadius : innerRadius;
  3182. var currX = 0 + Math.cos(i * angle) * r;
  3183. var currY = 0 + Math.sin(i * angle) * r;
  3184. if (i == 0) {
  3185. results = "M " + currX + "," + currY;
  3186. }
  3187. results += " L " + currX + "," + currY;
  3188. }
  3189. results += " Z";
  3190. return results;
  3191. });
  3192. status &= rave.svg.symbolCreator("donut", function(size) {
  3193. var r1 = Math.sqrt(size / Math.PI);
  3194. var r2 = r1 * 0.4;
  3195. var outer = "M0 0m-" + r1 + ",0a" + r1 + "," + r1 + ",0 1,0 " + (r1 * 2) + ",0a " + r1 + "," + r1 + " 0 1,0 -" + (r1 * 2) + ",0z";
  3196. var inner = "M0 0m-" + r2 + ",0a" + r2 + "," + r2 + ",0 0,1 " + (r2 * 2) + ",0a " + r2 + "," + r2 + " 0 0,1 -" + (r2 * 2) + ",0z";
  3197. return outer + inner;
  3198. });
  3199. status &= rave.svg.symbolCreator("donutPlus", function(size) {
  3200. var r = Math.sqrt(size / Math.PI);
  3201. var circle = "M0," + r + "A" + r + "," + r + " 0 1,1 0," + (-r) + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
  3202. var r1 = Math.sqrt(size * 0.6 / Math.PI);
  3203. var r2 = r1 * 0.7;
  3204. var outer = "M0 0m-" + r1 + ",0a" + r1 + "," + r1 + ",0 1,0 " + (r1 * 2) + ",0a " + r1 + "," + r1 + " 0 1,0 -" + (r1 * 2) + ",0z";
  3205. var inner = "M0 0m-" + r2 + ",0a" + r2 + "," + r2 + ",0 0,1 " + (r2 * 2) + ",0a " + r2 + "," + r2 + " 0 0,1 -" + (r2 * 2) + ",0z";
  3206. return circle + outer + inner;
  3207. });
  3208. status &= rave.svg.symbolCreator("pentagon", function(size) {
  3209. var radius = Math.sqrt(size / Math.PI);
  3210. var results = "M";
  3211. for (var i = 0; i < 5; ++i) {
  3212. var angle = (i * 2) * Math.PI / 5 - (Math.PI / 2);
  3213. var currX = radius * Math.cos(angle);
  3214. var currY = radius * Math.sin(angle);
  3215. results += currX + "," + currY + " ";
  3216. }
  3217. return results;
  3218. });
  3219. status &= rave.svg.symbolCreator("compositeViewLegendLineSymbol", function(size) {
  3220. var len = Math.sqrt(size) / 2.0;
  3221. var l3 = len / 3;
  3222. return "M" + (-len) + "," + (len) + "L" + (-l3) + "," + (-l3 + 1.5) + " " + (l3) + "," + (l3 + 1.5) + " " + (len) + "," + (-len + 3) + " " + (len) + "," + (-len) + " " + (l3) + "," + (l3 - 1.5) + " " + (-l3) + "," + (-l3 - 1.15) + " " + (-len) + "," + (len - 3) + "Z";
  3223. });
  3224. }
  3225. return registrationStatus.registered;
  3226. };
  3227. com_ibm_rave_ext_symbol_RaveSymbol.RegistrationStatus = rave['internal']['Declare']({
  3228. registered : false
  3229. });
  3230. //com_ibm_rave_ext_symbol_RaveSymbol.EXTENSION_REGISTRATION_STATUS_KEY = "RAVESYMBOL_EXTENSION_REGISTRATION_STATUS_KEY";
  3231. /** @expose */
  3232. com_ibm_rave_ext_symbol_RaveSymbol.RECTANLGE = "rectangle";
  3233. /** @expose */
  3234. com_ibm_rave_ext_symbol_RaveSymbol.HORIZONTAL_RECTANGLE = "horizontal-rectangle";
  3235. /** @expose */
  3236. com_ibm_rave_ext_symbol_RaveSymbol.VERTICAL_RECTANGLE = "vertical-rectangle";
  3237. /** @expose */
  3238. com_ibm_rave_ext_symbol_RaveSymbol.TRIANGLE_LEFT = "triangle-left";
  3239. /** @expose */
  3240. com_ibm_rave_ext_symbol_RaveSymbol.TRIANGLE_RIGHT = "triangle-right";
  3241. /** @expose */
  3242. com_ibm_rave_ext_symbol_RaveSymbol.STAR = "star";
  3243. /** @expose */
  3244. com_ibm_rave_ext_symbol_RaveSymbol.DONUT = "donut";
  3245. /** @expose */
  3246. com_ibm_rave_ext_symbol_RaveSymbol.DONUTPLUS = "donutPlus";
  3247. /** @expose */
  3248. com_ibm_rave_ext_symbol_RaveSymbol.PENTAGON = "pentagon";
  3249. // Auto initialization
  3250. com_ibm_rave_ext_symbol_RaveSymbol.init();
  3251. // $source: com/ibm/rave/ext/statistics/outliersUtility/PeirceCriterion
  3252. /************************************************************************
  3253. ** IBM Confidential
  3254. **
  3255. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  3256. **
  3257. ** (C) Copyright IBM Corp. 2017
  3258. **
  3259. ** The source code for this program is not published or otherwise divested of its trade secrets,
  3260. ** irrespective of what has been deposited with the U.S. Copyright Office.
  3261. ************************************************************************/
  3262. // GENERATED
  3263. //@import com/ibm/rave/ext/statistics/outliersUtility/RaveOutlier (loadtime) // superclass
  3264. /**
  3265. * Peirce's criterion Returns the squared threshold error deviation for outlier identification using Peirce's criterion based on Gould's methodology. For a readable explanation of this method, see these links: https://www.eol.ucar.edu/system/files/piercescriterion.pdf https://en.wikipedia.org/wiki/Peirce%27s_criterion
  3266. */
  3267. var com_ibm_rave_ext_statistics_outliersUtility_PeirceCriterion = rave['internal']['Declare'](com_ibm_rave_ext_statistics_outliersUtility_RaveOutlier, {
  3268. mUnknowns : 1,
  3269. /**
  3270. * Returns the Number of model unknowns as set by the user, the default value is 1.
  3271. * @return (double) pOutliers
  3272. */
  3273. modelUnknowns$0 : function() {
  3274. return this.mUnknowns;
  3275. },
  3276. /**
  3277. * Sets the number of model unknowns. Used by the Peirce Criterion calculation.
  3278. * @param (int) unknowns Number of model unknowns.
  3279. * @return (com.ibm.rave.ext.statistics.outliersUtility.PeirceCriterion) this instance
  3280. */
  3281. modelUnknowns$1 : function(unknowns) {
  3282. this.mUnknowns = unknowns;
  3283. return this;
  3284. },
  3285. /**
  3286. * Recursively identifies outliers based on the current dataset.
  3287. * @param (Array) values
  3288. * @param outliers List of outliers
  3289. * @return (Array) List of outliers - indexes from the original data
  3290. */
  3291. identifyOutliers : function(values) {
  3292. var dataArray = values;
  3293. var mean = rave.mean(dataArray);
  3294. var variance = rave.variance(dataArray);
  3295. var std = Math.sqrt(variance);
  3296. var remainingDataIndexes = rave.range(0, values.length);
  3297. var outliers = [];
  3298. var foundOutliers = true;
  3299. var lastOutlierSize = 0;
  3300. while (foundOutliers) {
  3301. foundOutliers = this.findOutliers(values, remainingDataIndexes, outliers, mean, std, lastOutlierSize + 1);
  3302. lastOutlierSize = outliers.length - lastOutlierSize;
  3303. }
  3304. return outliers;
  3305. },
  3306. /**
  3307. * Return a list of indexes from the original data that we are to be removed based on pOutliers. Modifies remainingDataIndexes in place so on the next run we only look for values that haven't already been removed
  3308. * @param (Array) originalData The original data set.
  3309. * @param (Array) remainingDataIndexes Starts at a list of all indexes in the data set. Gets reduced on each run eliminating indexes that are outliers.
  3310. * @param (Array) outliers List of all outlier indexes found. Updated on each run.
  3311. * @param (double) originalMean The original mean of the data set
  3312. * @param (double) standardDev The original standard dev of the data set
  3313. * @param (int) outliersToRemove The number of outliers to potentially remove. This is incremented on each run and is passed into the calculateMaxDeviation calculation.
  3314. */
  3315. findOutliers : function(originalData, remainingDataIndexes, outliers, originalMean, standardDev, outliersToRemove) {
  3316. var r = Math.sqrt(com_ibm_rave_ext_statistics_outliersUtility_PeirceCriterion.calculateMaxDeviation(originalData.length, outliersToRemove, this.mUnknowns));
  3317. var maxDeviation = r * standardDev;
  3318. var foundOutliers = [];
  3319. for (var i = 0; i < remainingDataIndexes.length; ++i) {
  3320. var dataIndex = remainingDataIndexes[i];
  3321. var input = originalData[dataIndex];
  3322. if (Math.abs(input - originalMean) > maxDeviation) {
  3323. outliers.push(dataIndex);
  3324. foundOutliers.push(i);
  3325. }
  3326. }
  3327. for (var i = foundOutliers.length - 1; i >= 0; --i) {
  3328. var index = foundOutliers[i];
  3329. remainingDataIndexes.splice(index, 1);
  3330. }
  3331. return foundOutliers.length > 0;
  3332. },
  3333. /** @expose */
  3334. outliers : function(data) {
  3335. var self = this;
  3336. var values = data.map(function(currentValue, i, array) {
  3337. return self._value.call(self, currentValue, i, -1);
  3338. });
  3339. return this.identifyOutliers(values);
  3340. },
  3341. /** @expose */
  3342. modelUnknowns : function(a0) {
  3343. var args = arguments;
  3344. if (args.length == 0) {
  3345. return this.modelUnknowns$0();
  3346. }
  3347. return this.modelUnknowns$1(a0);
  3348. }
  3349. });
  3350. /**
  3351. * The pNorm method will find the area under the normal distribution curve to the left of the number x. This is used in the calculation of Peirce's Criterion.
  3352. * @param (double) x input number
  3353. * @return (double) area under normal curve
  3354. */
  3355. com_ibm_rave_ext_statistics_outliersUtility_PeirceCriterion.pNorm = function(x) {
  3356. var _x = x;
  3357. var a1 = 0.254829592;
  3358. var a2 = -0.284496736;
  3359. var a3 = 1.421413741;
  3360. var a4 = -1.453152027;
  3361. var a5 = 1.061405429;
  3362. var p = 0.3275911;
  3363. var sign = 1;
  3364. if (_x < 0) {
  3365. sign = -1;
  3366. }
  3367. _x = Math.abs(_x);
  3368. var t = 1.0 / (1.0 + p * _x);
  3369. var y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * Math.exp(-_x * _x);
  3370. return sign * y;
  3371. };
  3372. /**
  3373. * Calculates the maximum allowed deviation according to peirce's criterion
  3374. * @param (int) size The size of the data set
  3375. * @param (int) outliers Number of potential outliers
  3376. * @param (int) model_unknowns Number of model unknowns
  3377. * @return (double)
  3378. */
  3379. com_ibm_rave_ext_statistics_outliersUtility_PeirceCriterion.calculateMaxDeviation = function(size, outliers, model_unknowns) {
  3380. var _outliers = outliers;
  3381. var x2 = 0.0;
  3382. if (size > 1) {
  3383. var q = Math.pow(_outliers, (_outliers / size)) * Math.pow((size - _outliers), ((size - _outliers) / size)) / size;
  3384. var rNew = 1.0;
  3385. var rOld = 0.0;
  3386. while (Math.abs(rNew - rOld) > (size * 2.0e-16)) {
  3387. var ldiv = Math.pow(rNew, _outliers);
  3388. if (ldiv == 0) {
  3389. ldiv = 1.0e-6;
  3390. }
  3391. var lamda = Math.pow(((Math.pow(q, size)) / (ldiv)), (1.0 / (size - _outliers)));
  3392. x2 = 1.0 + (size - model_unknowns - _outliers) / _outliers * (1.0 - Math.pow(lamda, 2));
  3393. if (x2 < 0) {
  3394. x2 = 0.0;
  3395. rOld = rNew;
  3396. } else {
  3397. rOld = rNew;
  3398. rNew = Math.exp((x2 - 1) / 2.0) * (1 - com_ibm_rave_ext_statistics_outliersUtility_PeirceCriterion.pNorm(Math.sqrt(x2) / Math.sqrt(2.0)));
  3399. }
  3400. }
  3401. }
  3402. return x2;
  3403. };
  3404. // $source: com/ibm/rave/ext/text/internal/wrap/WrapOperation
  3405. /************************************************************************
  3406. ** IBM Confidential
  3407. **
  3408. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  3409. **
  3410. ** (C) Copyright IBM Corp. 2017
  3411. **
  3412. ** The source code for this program is not published or otherwise divested of its trade secrets,
  3413. ** irrespective of what has been deposited with the U.S. Copyright Office.
  3414. ************************************************************************/
  3415. // GENERATED
  3416. //@import com/ibm/rave/ext/text/internal/wrap/TextOperation (loadtime) // superclass
  3417. /**
  3418. * Text operation wraps a single text into a width and height provided
  3419. */
  3420. var com_ibm_rave_ext_text_internal_wrap_WrapOperation = rave['internal']['Declare'](com_ibm_rave_ext_text_internal_wrap_TextOperation, {
  3421. /**
  3422. * Return data structure representing wrapped text. The data contains collection lines of wrapped text, empty collection if wrapping could not succeed. Data truncation and clip flags indicate wither or not truncation or clipping had occurred
  3423. * @see (com.ibm.rave.ext.text.internal.wrap.TextData) TextData
  3424. */
  3425. _doRun : function(lines) {
  3426. var words = this._splitTextIntoWords(this._text);
  3427. if (words.length == 0) {
  3428. return;
  3429. }
  3430. this.createContext();
  3431. this._initFont(lines, this._font, this._fontSize);
  3432. this._wrap(lines, words);
  3433. lines.fontSize = this._fontSize;
  3434. /*return;*/
  3435. },
  3436. /**
  3437. * Returns truncated text, or null, if not enough space. Text is truncated with ellipses set by textOverflow
  3438. * @param (String) text text to truncate
  3439. * @return (String) truncated text
  3440. * @see #this.textOverflow(String)
  3441. */
  3442. _ellipsize : function(text, lines) {
  3443. lines.clipped = false;
  3444. var forceTruncation = lines.tooTall;
  3445. if (!forceTruncation && this._measureText(text) <= this._width) {
  3446. lines.truncated = false;
  3447. return text;
  3448. }
  3449. return this._doEllipsize(text, lines);
  3450. },
  3451. /**
  3452. * @param (String) text string to clip to fit the max width
  3453. * @return (String) clipped string
  3454. */
  3455. _clip$1 : function(text, lines) {
  3456. var result = com_ibm_rave_ext_text_internal_wrap_TextOperation.prototype._clip$1.call(this, text, lines);
  3457. if (lines.tooTall) {
  3458. lines.clipped = true;
  3459. }
  3460. return result;
  3461. },
  3462. _truncateOrClip : function(testLine, lines) {
  3463. var line = com_ibm_rave_ext_text_internal_wrap_TextOperation.prototype._truncateOrClip.call(this, testLine, lines);
  3464. if (line == null && lines.tooTall && lines.truncated == false) {
  3465. lines.clipped = true;
  3466. }
  3467. return line;
  3468. },
  3469. _wrap : function(textData, words) {
  3470. if (textData.lineHeight > this._height) {
  3471. return;
  3472. }
  3473. var line = "", space = "";
  3474. var total_height = 0;
  3475. var notClipped = true;
  3476. var n;
  3477. for (n = 0; notClipped && n < words.length && total_height < this._height; ++n) {
  3478. var testLine = line.concat(space).concat(words[n]);
  3479. space = " ";
  3480. if (this._measureText(testLine) > this._width) {
  3481. if (this._measureText(words[n]) > this._width) {
  3482. this._truncateOrClip(testLine, textData);
  3483. if (textData.length() <= 0) {
  3484. return;
  3485. }
  3486. notClipped = false;
  3487. line = "";
  3488. } else {
  3489. textData.add(line);
  3490. line = words[n];
  3491. }
  3492. total_height += textData.lineHeight;
  3493. } else {
  3494. line = testLine;
  3495. }
  3496. }
  3497. if (n == words.length) {
  3498. if (total_height + textData.lineHeight <= this._height) {
  3499. if (line.length > 0) {
  3500. this._truncateOrClip(line, textData);
  3501. }
  3502. return;
  3503. }
  3504. }
  3505. if (total_height > this._height) {
  3506. var index = textData.length() - 1;
  3507. textData.lines.splice(index, 1);
  3508. total_height -= textData.lineHeight;
  3509. }
  3510. var index = textData.length() - 1;
  3511. line = textData.lines[index];
  3512. textData.lines.splice(index, 1);
  3513. textData.tooTall = true;
  3514. this._truncateOrClip(line, textData);
  3515. }
  3516. });
  3517. // $source: com/ibm/rave/ext/text/internal/wrap/FitOperation
  3518. /************************************************************************
  3519. ** IBM Confidential
  3520. **
  3521. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  3522. **
  3523. ** (C) Copyright IBM Corp. 2017
  3524. **
  3525. ** The source code for this program is not published or otherwise divested of its trade secrets,
  3526. ** irrespective of what has been deposited with the U.S. Copyright Office.
  3527. ************************************************************************/
  3528. // GENERATED
  3529. //@import com/ibm/rave/ext/text/internal/wrap/TextOperation (loadtime) // superclass
  3530. //@import com/ibm/rave/ext/text/internal/nativeImpl/TextLength (runtime) // getTenPtLength
  3531. /**
  3532. * Fits text in a single line
  3533. */
  3534. var com_ibm_rave_ext_text_internal_wrap_FitOperation = rave['internal']['Declare'](com_ibm_rave_ext_text_internal_wrap_TextOperation, {
  3535. /**
  3536. * @return (boolean) condition that would prevent run
  3537. */
  3538. _runPrecondition : function() {
  3539. return this._text == null || Math.min(this._maxFontSize, this._minFontSize) > this._height || Math.min(this._maxFontSize, this._minFontSize) > this._width || this._text.length === 0;
  3540. },
  3541. _doRun : function(textData) {
  3542. this.createContext();
  3543. var optimalFontSize = this._approximate();
  3544. var min_font = this._minFontSize > this._maxFontSize ? this._maxFontSize : this._minFontSize;
  3545. if (optimalFontSize > this._maxFontSize) {
  3546. this._forceFontSize(~~this._maxFontSize, this._font);
  3547. this._initFont(textData, this._font, this._maxFontSize);
  3548. this._truncateOrClip(this._text, textData);
  3549. textData.font = this._font;
  3550. textData.fontSize = this._maxFontSize;
  3551. return;
  3552. }
  3553. if (optimalFontSize <= min_font) {
  3554. this._forceFontSize(~~min_font, this._font);
  3555. this._initFont(textData, this._font, min_font);
  3556. this._truncateOrClip(this._text, textData);
  3557. textData.font = this._font;
  3558. textData.fontSize = min_font;
  3559. return;
  3560. }
  3561. var size = ~~optimalFontSize;
  3562. this._forceFontSize(size, this._font);
  3563. this._initFont(textData, this._font, size);
  3564. var tooWide = false;
  3565. while ((tooWide = this._measureText(this._text) > this._width) && size > min_font) {
  3566. size--;
  3567. this._forceFontSize(size, this._font);
  3568. this._initFont(textData, this._font, size);
  3569. }
  3570. if (tooWide) {
  3571. this._truncateOrClip(this._text, textData);
  3572. } else {
  3573. textData.add(this._text);
  3574. }
  3575. textData.font = this._font;
  3576. textData.fontSize = size;
  3577. /*return;*/
  3578. },
  3579. /**
  3580. * This calls the native impl method TextLength.getTenPtLength to get the length of the string at 10 pt with the current font and style, and then scales it a new height (font size) based on the width available.
  3581. * @return (double) the new font size
  3582. */
  3583. _approximate : function() {
  3584. var tenPtWidth = com_ibm_rave_ext_text_internal_nativeImpl_TextLength.getTenPtLength(this._text, this._font.fontFamily, this._font.fontStyle);
  3585. var optimal = Math.ceil(this._width * 10.0 / tenPtWidth);
  3586. return Math.min(optimal, this._height);
  3587. }
  3588. });
  3589. // $source: com/ibm/rave/ext/text/internal/wrap/FitWrapOperation
  3590. /************************************************************************
  3591. ** IBM Confidential
  3592. **
  3593. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  3594. **
  3595. ** (C) Copyright IBM Corp. 2017
  3596. **
  3597. ** The source code for this program is not published or otherwise divested of its trade secrets,
  3598. ** irrespective of what has been deposited with the U.S. Copyright Office.
  3599. ************************************************************************/
  3600. // GENERATED
  3601. //@import com/ibm/rave/ext/text/internal/wrap/WrapOperation (loadtime) // superclass
  3602. /**
  3603. */
  3604. var com_ibm_rave_ext_text_internal_wrap_FitWrapOperation = rave['internal']['Declare'](com_ibm_rave_ext_text_internal_wrap_WrapOperation, {
  3605. /**
  3606. * @return (boolean) condition that would prevent run
  3607. */
  3608. _runPrecondition : function() {
  3609. return this._text == null || Math.min(this._maxFontSize, this._minFontSize) > this._height || Math.min(this._maxFontSize, this._minFontSize) > this._width || this._text.length === 0;
  3610. },
  3611. _doRun : function(textData) {
  3612. var words = this._splitTextIntoWords(this._text);
  3613. this.createContext();
  3614. var optimalFontSize = this._approximate();
  3615. var min_font = this._minFontSize > this._maxFontSize ? this._maxFontSize : this._minFontSize;
  3616. if (optimalFontSize >= this._maxFontSize) {
  3617. this._forceFontSize(~~this._maxFontSize, this._font);
  3618. this._initFont(textData, this._font, this._maxFontSize);
  3619. this._wrap(textData, words);
  3620. textData.font = this._font;
  3621. textData.fontSize = this._maxFontSize;
  3622. return;
  3623. }
  3624. if (optimalFontSize <= min_font) {
  3625. this._forceFontSize(~~min_font, this._font);
  3626. this._initFont(textData, this._font, min_font);
  3627. this._wrap(textData, words);
  3628. textData.font = this._font;
  3629. textData.fontSize = min_font;
  3630. return;
  3631. }
  3632. var size = optimalFontSize;
  3633. while (size - min_font > 0 && (textData.length() == 0 || textData.truncated || textData.clipped)) {
  3634. textData.tooTall = false;
  3635. this._forceFontSize(~~size, this._font);
  3636. textData.lines = [];
  3637. this._initFont(textData, this._font, size);
  3638. this._wrap(textData, words);
  3639. textData.font = this._font;
  3640. textData.fontSize = size;
  3641. size--;
  3642. }
  3643. },
  3644. _approximate : function() {
  3645. var L = this._text.length;
  3646. var sqrt = Math.sqrt(L);
  3647. var cell_width = this._width / sqrt;
  3648. var cell_height = this._height / sqrt;
  3649. cell_height = Math.min(cell_height, this._width);
  3650. cell_width = Math.min(this._height, cell_width);
  3651. return Math.ceil((cell_width + cell_height) / 2);
  3652. }
  3653. });
  3654. // $source: com/ibm/rave/ext/text/internal/wrap/TruncateOperation
  3655. /************************************************************************
  3656. ** IBM Confidential
  3657. **
  3658. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  3659. **
  3660. ** (C) Copyright IBM Corp. 2017
  3661. **
  3662. ** The source code for this program is not published or otherwise divested of its trade secrets,
  3663. ** irrespective of what has been deposited with the U.S. Copyright Office.
  3664. ************************************************************************/
  3665. // GENERATED
  3666. //@import com/ibm/rave/ext/text/internal/wrap/TextOperation (loadtime) // superclass
  3667. var com_ibm_rave_ext_text_internal_wrap_TruncateOperation = rave['internal']['Declare'](com_ibm_rave_ext_text_internal_wrap_TextOperation, {
  3668. _doRun : function(lines) {
  3669. this.createContext();
  3670. this._initFont(lines, this._font, this._fontSize);
  3671. this._truncateOrClip(this._text, lines);
  3672. }
  3673. });
  3674. // $source: com/ibm/rave/ext/geo/RaveGeo
  3675. /************************************************************************
  3676. ** IBM Confidential
  3677. **
  3678. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  3679. **
  3680. ** (C) Copyright IBM Corp. 2017
  3681. **
  3682. ** The source code for this program is not published or otherwise divested of its trade secrets,
  3683. ** irrespective of what has been deposited with the U.S. Copyright Office.
  3684. ************************************************************************/
  3685. // GENERATED
  3686. //@import com/ibm/rave/ext/geo/tile/TileLayout (static) // new
  3687. //@import com/ibm/rave/ext/geo/tile/TiledMapGenerator (static) // new
  3688. /**
  3689. * Geo extensions entry point
  3690. */
  3691. var com_ibm_rave_ext_geo_RaveGeo = {
  3692. };
  3693. /**
  3694. * Creates a new instance of a tile layout {@link (com.ibm.rave.ext.geo.tile.TileLayout) TileLayout}
  3695. * @return (com.ibm.rave.ext.geo.tile.TileLayout) new instance of Tile layout
  3696. */
  3697. /** @expose */
  3698. com_ibm_rave_ext_geo_RaveGeo.tile = function() {
  3699. return new com_ibm_rave_ext_geo_tile_TileLayout();
  3700. };
  3701. /**
  3702. * Creates a new instance of the Tiled Map generator
  3703. * @return (com.ibm.rave.ext.geo.tile.TiledMapGenerator) a new instance of Tiled Map generator
  3704. */
  3705. /** @expose */
  3706. com_ibm_rave_ext_geo_RaveGeo.tiledMapGenerator = function() {
  3707. return new com_ibm_rave_ext_geo_tile_TiledMapGenerator();
  3708. };
  3709. com_ibm_rave_ext_geo_RaveGeo.getRegistrationStatus = function() {
  3710. var registrationStatus = rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().getData("RAVEGEO_EXTENSION_REGISTRATION_STATUS_KEY");
  3711. if (!registrationStatus) {
  3712. registrationStatus = new com_ibm_rave_ext_geo_RaveGeo.RegistrationStatus();
  3713. rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().putData("RAVEGEO_EXTENSION_REGISTRATION_STATUS_KEY", registrationStatus);
  3714. }
  3715. return registrationStatus;
  3716. };
  3717. /**
  3718. * Register all extended geo functions
  3719. * @return (boolean) true if registration was successful, false otherwise
  3720. */
  3721. /** @expose */
  3722. com_ibm_rave_ext_geo_RaveGeo.init = function() {
  3723. var registrationStatus = com_ibm_rave_ext_geo_RaveGeo.getRegistrationStatus();
  3724. if (!registrationStatus.registered) {
  3725. registrationStatus.registered = rave.geo.extension("tile", function() {
  3726. return com_ibm_rave_ext_geo_RaveGeo.tile();
  3727. });
  3728. registrationStatus.registered &= rave.geo.extension(com_ibm_rave_ext_geo_RaveGeo.TILED_MAP, function() {
  3729. return com_ibm_rave_ext_geo_RaveGeo.tiledMapGenerator();
  3730. });
  3731. }
  3732. return registrationStatus.registered;
  3733. };
  3734. com_ibm_rave_ext_geo_RaveGeo.RegistrationStatus = rave['internal']['Declare']({
  3735. registered : false
  3736. });
  3737. /**
  3738. * geo tile layout ID
  3739. */
  3740. /** @expose */
  3741. com_ibm_rave_ext_geo_RaveGeo.Tile_LAYOUT = "tile";
  3742. /**
  3743. * Tiled Map generator ID
  3744. */
  3745. /** @expose */
  3746. com_ibm_rave_ext_geo_RaveGeo.TILED_MAP = "tiledMapGenerator";
  3747. //com_ibm_rave_ext_geo_RaveGeo.EXTENSION_REGISTRATION_STATUS_KEY = "RAVEGEO_EXTENSION_REGISTRATION_STATUS_KEY";
  3748. // Auto initialization
  3749. com_ibm_rave_ext_geo_RaveGeo.init();
  3750. if (!rave.geo["tile"]) {
  3751. rave.geo["tile"] = function() {
  3752. return com_ibm_rave_ext_geo_RaveGeo.tile();
  3753. };
  3754. } else {
  3755. console.log("Could not register extension: RaveGeo");
  3756. }
  3757. if (!rave.geo[com_ibm_rave_ext_geo_RaveGeo.TILED_MAP]) {
  3758. rave.geo[com_ibm_rave_ext_geo_RaveGeo.TILED_MAP] = function() {
  3759. return com_ibm_rave_ext_geo_RaveGeo.tiledMapGenerator();
  3760. };
  3761. } else {
  3762. console.log("Could not register extension: RaveGeo");
  3763. }
  3764. // $source: com/ibm/rave/ext/utilities/internal/nativeImpl/Module
  3765. /************************************************************************
  3766. ** IBM Confidential
  3767. **
  3768. ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
  3769. **
  3770. ** (C) Copyright IBM Corp. 2015
  3771. **
  3772. ** The source code for this program is not published or otherwise divested of its trade secrets,
  3773. ** irrespective of what has been deposited with the U.S. Copyright Office.
  3774. ************************************************************************/
  3775. // @OnDemandLoad("rave-utilities")
  3776. // Must be the first import
  3777. // @import ./ModuleHeader
  3778. // @import com/ibm/rave/ext/axis/RaveAxis
  3779. // @import com/ibm/rave/ext/position/RavePosition
  3780. // @import com/ibm/rave/ext/statistics/RaveStatistics
  3781. // @import com/ibm/rave/ext/text/TextExtensions
  3782. // @import com/ibm/rave/ext/geo/RaveGeo
  3783. // @import com/ibm/rave/ext/symbol/RaveSymbol
  3784. // @import com/ibm/rave/ext/text/internal/wrap/TextOperation
  3785. // @import com/ibm/rave/ext/text/internal/wrap/TextData
  3786. // @import com/ibm/rave/ext/text/internal/wrap/FontStyleStruct
  3787. rave["internal"]["com_ibm_rave_ext_text_internal_wrap_TextOperation"] = com_ibm_rave_ext_text_internal_wrap_TextOperation;
  3788. rave["internal"]["com_ibm_rave_ext_text_internal_wrap_TextData"] = com_ibm_rave_ext_text_internal_wrap_TextData;
  3789. rave["internal"]["com_ibm_rave_ext_text_internal_wrap_FontStyleStruct"] = com_ibm_rave_ext_text_internal_wrap_FontStyleStruct;
  3790. })();
  3791. // This is the end of the factory method defined in the header. Added only during a full compiled JS build.
  3792. return rave;
  3793. }));