12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521 |
- // During the rave-legends.js build, this file is added to the top.
- // Create an inner self-executing function that will be run with the global scope
- // On browsers, this is 'window'. Everywhere else should use 'this' if available.
- // Need to run eval('this') "indirectly" by having eval returned by (1,eval). OBVIOUSLY :)
- (function (global, factory) {
- // dynamically determine how 'rave' variable should be loaded depeneding on loader type
- var _rave;
- if (typeof module === "object" && typeof module.exports === "object" && typeof require == "function") {
- // CommonJS/node.js
- var rave = require("rave");
- require("rave-utilities");
- require("rave-layouts");
- var navigation = factory(global,rave);
- module.exports = rave;
- } else if (typeof define === "function" && define.amd) {
- // AMD
- define(['rave','rave-utilities','rave-layouts'], function(rave) {
- return factory(global,rave);
- });
- } else {
- // probably loading via script tag. run as is, setting stuff on rave
- factory(global,global['rave']);
- }
- }((1, eval)('this'), function (_global, _rave) {(function() {
- var $ = {};
- // $source: com/ibm/rave/ext/internal/legend/nativeImpl/ModuleHeader
- /************************************************************************
- ** IBM Confidential
- **
- ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
- **
- ** (C) Copyright IBM Corp. 2015
- **
- ** The source code for this program is not published or otherwise divested of its trade secrets,
- ** irrespective of what has been deposited with the U.S. Copyright Office.
- ************************************************************************/
- // setup
- var global = typeof _global !== "undefined" ? _global : (1, eval)('this');
- var rave = typeof _rave !== "undefined" ? _rave : global['rave'];
- com_ibm_rave_core_Rave = rave;
- rave["internal"]["Declare"] = rave["_"]["com_ibm_rave_core_nativeImpl_Declare"];
- // $source: com/ibm/rave/ext/legend/RaveLegend
- /************************************************************************
- ** IBM Confidential
- **
- ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
- **
- ** (C) Copyright IBM Corp. 2017
- **
- ** The source code for this program is not published or otherwise divested of its trade secrets,
- ** irrespective of what has been deposited with the U.S. Copyright Office.
- ************************************************************************/
- // GENERATED
- //@import com/ibm/rave/ext/legend/swatch/SwatchLegend (runtime) // new
- //@import com/ibm/rave/ext/legend/continuous/ContinuousLegend (runtime) // new
- //@import com/ibm/rave/ext/legend/size/NestedSizeLegend (runtime) // new
- /**
- * A factory of extended legends for rave capability.
- */
- var com_ibm_rave_ext_legend_RaveLegend = rave['internal']['Declare']({
- /**
- * Creates and return a swatch legend
- * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) a new instance of {@link SwatchLegend}
- * @see SwatchLegend
- */
- /** @expose */
- swatch : function() {
- return new com_ibm_rave_ext_legend_swatch_SwatchLegend();
- },
- /**
- * Creates and return a continuous legend
- * @return (com.ibm.rave.ext.legend.continuous.ContinuousLegend) a new instance of {@link SwatchLegend}
- * @see ContinuousLegend
- */
- /** @expose */
- continuous : function() {
- return new com_ibm_rave_ext_legend_continuous_ContinuousLegend();
- },
- /**
- * Create a new nested size legend component.
- * @see NestedSizeLegend
- */
- /** @expose */
- nestedSize : function() {
- return new com_ibm_rave_ext_legend_size_NestedSizeLegend();
- }
- //constructor : function() {}
- });
- com_ibm_rave_ext_legend_RaveLegend.getRegistrationStatus = function() {
- var registrationStatus = rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().getData("RAVELEGEND_EXTENSION_REGISTRATION_STATUS_KEY");
- if (!registrationStatus) {
- registrationStatus = new com_ibm_rave_ext_legend_RaveLegend.RegistrationStatus();
- rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().putData("RAVELEGEND_EXTENSION_REGISTRATION_STATUS_KEY", registrationStatus);
- }
- return registrationStatus;
- };
- /**
- * Register the factory for this legend provider
- * @return (boolean) true if registration was successful, false otherwise
- * @see Capabilities
- */
- /** @expose */
- com_ibm_rave_ext_legend_RaveLegend.init = function() {
- var registrationStatus = com_ibm_rave_ext_legend_RaveLegend.getRegistrationStatus();
- if (!registrationStatus.registered) {
- registrationStatus.registered = rave.capabilities.extension("legend", function() {
- return new com_ibm_rave_ext_legend_RaveLegend();
- });
- }
- return registrationStatus.registered;
- };
- com_ibm_rave_ext_legend_RaveLegend.RegistrationStatus = rave['internal']['Declare']({
- registered : false
- });
- /**
- * RaveLegend extension id
- */
- /** @expose */
- com_ibm_rave_ext_legend_RaveLegend.LEGEND = "legend";
- //com_ibm_rave_ext_legend_RaveLegend.EXTENSION_REGISTRATION_STATUS_KEY = "RAVELEGEND_EXTENSION_REGISTRATION_STATUS_KEY";
- // Auto initialization
- com_ibm_rave_ext_legend_RaveLegend.init();
- if (!rave.capabilities["legend"]) {
- rave.capabilities["legend"] = function() {
- return new com_ibm_rave_ext_legend_RaveLegend();
- };
- } else {
- console.log("Could not register extension: RaveLegend");
- }
- // $source: com/ibm/rave/ext/legend/AbstractLegend
- /************************************************************************
- ** IBM Confidential
- **
- ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
- **
- ** (C) Copyright IBM Corp. 2017
- **
- ** The source code for this program is not published or otherwise divested of its trade secrets,
- ** irrespective of what has been deposited with the U.S. Copyright Office.
- ************************************************************************/
- // GENERATED
- //@import com/ibm/rave/ext/legend/ExtraLegendEntry (runtime) // new
- /**
- * A class that would generate and draw a legend
- */
- var com_ibm_rave_ext_legend_AbstractLegend = rave['internal']['Declare']({
- //_scale : null,
- //_orient : null,
- //_labelPadding : null,
- //_scaleArguments : null,
- //_size : null,
- //_dataValues : null,
- //_labelFormat : null,
- //_title : null,
- //_labelTruncationText : null,
- //_legendTruncationIndicator : null,
- //_legendBorderColor : null,
- //_legendBackgroundColor : null,
- //_shapeBorderColor : null,
- //_titleAlignment : null,
- //_titleInsets : null,
- //_entryInsets : null,
- //_legendInsets : null,
- //_titleFontSize : null,
- //_titleFontFamily : null,
- //_titleFill : null,
- /** @expose */
- _extraLegendEntries : null,
- _reverse : false,
- _minDataLen : 0,
- /** @expose */
- _spaceUsed : 0,
- _$functionClassMethod : function() {
- var _$self = function(args) {
- if (args !== null || arguments.length > 1){
- args = Array.prototype.slice.call(arguments, 0);
- }
- {
- _$self.legend(args[0]);
- return null;
- }
- };
- return _$self;
- },
- constructor : function() {
- this._orient = "vertical";
- this._labelPadding = 3.0;
- this._scaleArguments = com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_SCALE_ARGS;
- this._size = com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_LEGEND_SIZE;
- this._labelTruncationText = "...";
- this._titleAlignment = "middle";
- this._titleInsets = com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
- this._entryInsets = com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
- this._legendInsets = com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
- {
- this._extraLegendEntries = rave.map();
- }
- },
- /** @expose */
- extraLegendEntries : function() {
- return this._extraLegendEntries;
- },
- minDataLen$0 : function() {
- return this._minDataLen;
- },
- minDataLen$1 : function(minDataLen) {
- this._minDataLen = minDataLen;
- },
- /**
- * Set the scale to be used by this legend. This scale's range must be a color object or a color string for all legends except axis legend where the range must be a numeric value If data values aren't specified on this legend, then this scale's ticksInRange, ticks or domain methods (depending on their availabilities on the scale) would be used to generate legend entries. Moreover, if label format isn't set on this legend, then this scale's tickFormat (if available) could be used to extract the legend entries labels.
- * @param (rave['internal']['AbstractScale']) scale The scale object to assign to this legend
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- * @see #this.dataValues()
- * @see #this.labelFormat()
- */
- scale$0 : function(scale) {
- this._scale = scale;
- return this;
- },
- /**
- * Get the scale assigned to this legend.
- * @return (rave['internal']['AbstractScale']) the scale assigned to this legend.
- */
- scale$1 : function() {
- return this._scale;
- },
- /**
- * Set the legend orientation. Can be one of: <ul> <li>horizontal</li> <li>vertical</li> </ul> The default orientation is vertical.
- * @param (String) orientation The orientation to assign to this legend.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- orient$0 : function(orientation) {
- if ("horizontal" == orientation || "vertical" == orientation) {
- this._orient = orientation;
- } else {
- this._orient = "vertical";
- }
- return this;
- },
- /**
- * Get the current orientation.
- * @return (String) Orientation String.
- */
- orient$1 : function() {
- return this._orient;
- },
- /**
- * Get the current legend title. Default is null
- * @return (String) Title String.
- */
- title$0 : function() {
- return this._title;
- },
- /**
- * Set the legend title. If the value passed is null or an empty string then no title would be drawn for this legend.
- * @param (String) t The title to assign to this legend.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- title$1 : function(t) {
- this._title = t;
- return this;
- },
- /**
- * Get the current legend size: width and height. The default is 100x100
- * @return (Array) the legend size.
- */
- size$0 : function() {
- return this._size;
- },
- /**
- * Set the legend size: its bounding box width and height.
- * @param (Array) t The dimension object representing the width and height to assign to this legend.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- size$1 : function(t) {
- this._size = t;
- return this;
- },
- /**
- * Set the legend's entries generation arguments. These arguments will be passed to the scale's ticks method to generate legend entries if needed.
- * @param (java.lang.Object[]) scaleArgs Argument list to control entries generation.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) This legend instance.
- * @see #this.scale(rave['internal']['AbstractScale'] this.scale)
- */
- scaleArguments$0 : function(scaleArgs) {
- if (scaleArgs !== null || arguments.length > 1){
- scaleArgs = Array.prototype.slice.call(arguments);
- }
- {
- this._scaleArguments = scaleArgs;
- return this;
- }
- },
- /**
- * Get the currently assigned legend entries arguments. Default is [5].
- * @return (java.lang.Object[]) Array of legend entries argument values.
- */
- scaleArguments$1 : function() {
- return this._scaleArguments;
- },
- /**
- * Manually specify array of legend entries values which will override the default legend entries generation behavior. A new entry will be generated for each value in the array.
- * @param (Array) values Array of legend entries values.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) This legend instance.
- */
- dataValues$0 : function(values) {
- this._dataValues = values;
- return this;
- },
- /**
- * Get the currently assigned legend entries values.
- * @return (Array) Array of legend entries values, or null if none have been assigned (see {@link #this.dataValues(Array)} ).
- */
- dataValues$1 : function() {
- return this._dataValues;
- },
- /**
- * Specify legend entries label value. This value would be used for all legend entries
- * @param (String) format the string to be used as a label for legend entries
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- labelFormat$0 : function(format) {
- this._labelFormat = format;
- return this;
- },
- /**
- * Specify legend entries label generating functor.
- * @param (rave['internal']['ValueFunction']) valueFunction "anonymous" function class, when executed, returns the formatted legend entries label value.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- labelFormat$1 : function(valueFunction) {
- this._labelFormat = valueFunction;
- return this;
- },
- /**
- * Get the currently assigned legend entries label format.
- * @return (Object) The legend entries label format object, or null if a format has not been specified.
- */
- labelFormat$2 : function() {
- return this._labelFormat;
- },
- /**
- * Specify the padding distance in pixels between a legend entry shape and its label. Default is 3 pixels
- * @param (Object) padding Padding value in pixels. It could be either a Double value, or a string that could be parsed to a double value.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- labelPadding$0 : function(padding) {
- this._labelPadding = padding;
- return this;
- },
- /**
- * Get the currently assigned padding in pixels between a legend entry shape and its label. Default is 3.
- * @return (Object) Padding value.
- */
- labelPadding$1 : function() {
- return this._labelPadding;
- },
- /**
- * Gets the value of the color assigned to the legend's border. Default is null indicating that there is no border will be drawn.
- * @return (Object) the current value assigned for the legend's border color
- */
- borderColor$0 : function() {
- return this._legendBorderColor;
- },
- /**
- * Sets the value of the color assigned to the legend's border. The value to set could either be a Color object, or a string that could be parsed into a color object. The format of this string could be any of the formats supported by CSS to represent colors. If the string passed could not be parsed successfully, then a black color will be used. If null or an empty string is passed, then no border is drawn.
- * @param (Object) borderColor The border color value to set.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- * @see Color
- */
- borderColor$1 : function(borderColor) {
- this._legendBorderColor = borderColor;
- return this;
- },
- /**
- * Gets the value of the color assigned to the legend entry shape border. Default is null indicating that there is no border will be drawn.
- * @return (Object) the current value assigned for the swatch's border color
- */
- shapeBorderColor$0 : function() {
- return this._shapeBorderColor;
- },
- /**
- * Sets the value of the color assigned to the legend entry shape border. The value to set could either be a Color object, or a string that could be parsed into a color object. The format of this string could be any of the formats supported by CSS to represent colors. If the string passed could not be parsed successfully, then a black color will be used. If null or an empty string is passed, then no border is drawn.
- * @param (Object) shapeBorderColor The border color value to set.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- * @see Color
- */
- shapeBorderColor$1 : function(shapeBorderColor) {
- this._shapeBorderColor = shapeBorderColor;
- return this;
- },
- /**
- * Gets the value of the color assigned to the legend's background. Default is null indicating that the legend's background will be transparent.
- * @return (Object) the current value assigned for the legend's background color
- */
- backgroundColor$0 : function() {
- return this._legendBackgroundColor;
- },
- /**
- * Sets the value of the color assigned to the legend's background. The value to set could either be a Color object, or a string that could be parsed into a color object. The format of this string could be any of the formats supported by CSS to represent colors. If the string passed could not be parsed successfully, then a black color will be used. If null or an empty string is passed, then no border is drawn.
- * @param (Object) backgroundColor The background color value to set.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- * @see Color
- */
- backgroundColor$1 : function(backgroundColor) {
- this._legendBackgroundColor = backgroundColor;
- return this;
- },
- /**
- * Gets the current value assigned to the legend's title alignment
- * @return (String) the current value assigned to the legend's title alignment
- */
- titleAlignment$0 : function() {
- return this._titleAlignment;
- },
- /**
- * Sets the current value assigned to the legend's title horizontal alignment. Default is middle Can be one of: <ul> <li>start</li> <li>middle</li> <li>end</li> </ul> If a non valid value is passed then the default alignment will be used.
- * @param (String) titleAlignment the alignment value to set
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- titleAlignment$1 : function(titleAlignment) {
- if ("start" == titleAlignment || "middle" == titleAlignment || "end" == titleAlignment) {
- this._titleAlignment = titleAlignment;
- } else {
- this._titleAlignment = "middle";
- }
- return this;
- },
- /**
- * Gets the current insets used for the legend's title.
- * @return (Object) the current insets used for the legend's title
- */
- titleInsets$0 : function() {
- return this._titleInsets;
- },
- /**
- * Sets the current insets to be used for the legend's title. Default insets uses padding of 3 pixels in all directions: top, bottom, left and right. If null is passed then the default insets value will be used.
- * @param (Object) titleInsets the insets to set
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- titleInsets$1 : function(titleInsets) {
- this._titleInsets = (titleInsets) ? this.sanitizeInsets(titleInsets) : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
- return this;
- },
- /**
- * Get the current legend title fill color. Default is null.
- * @return (String) Title fill string.
- */
- titleFill$0 : function() {
- return this._titleFill;
- },
- /**
- * Set the legend title fill color. If the value is null, the title will use the default fill color from the CSS.
- * @param (String) f The title fill color
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- titleFill$1 : function(f) {
- this._titleFill = f;
- return this;
- },
- /**
- * Get the current legend title font size. Default is null.
- * @return (String) Title font size string.
- */
- titleFontSize$0 : function() {
- return this._titleFontSize;
- },
- /**
- * Set the legend title font size. Sizes are CSS size strings. If the value is null, the title will use the default font size from the CSS.
- * @param (String) s The title font size
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- titleFontSize$1 : function(s) {
- this._titleFontSize = s;
- return this;
- },
- /**
- * Get the current legend title font family. Default is null.
- * @return (String) Title font family string.
- */
- titleFontFamily$0 : function() {
- return this._titleFontFamily;
- },
- /**
- * Set the legend title font family. The argument is a comma-separated list of font names; for platform independence each name should be double-quoted. If the value is null, the title will use the default font family from the CSS.
- * @param (String) f The title font family
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- titleFontFamily$1 : function(f) {
- this._titleFontFamily = f;
- return this;
- },
- /**
- * Gets the current insets used for the legend's entry.
- * @return (Object) the current insets used for the legend's entry
- */
- entryInsets$0 : function() {
- return this._entryInsets;
- },
- /**
- * Sets the current insets to be used for each legend's entry. Default insets uses padding of 3 pixels in all directions: top, bottom, left and right If null is passed then the default insets value will be used.
- * @param (Object) entryInsets the insets to set
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- entryInsets$1 : function(entryInsets) {
- this._entryInsets = (entryInsets) ? this.sanitizeInsets(entryInsets) : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
- return this;
- },
- /**
- * Gets the current insets used for the legend.
- * @return (Object) the current insets used for the legend
- */
- insets$0 : function() {
- return this._legendInsets;
- },
- /**
- * Sets the current insets to be used for each legend. Default insets uses padding of 3 pixels in all directions: top, bottom, left and right If null is passed then the default insets value will be used.
- * @param (Object) legendInsets the insets to set
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- insets$1 : function(legendInsets) {
- this._legendInsets = (legendInsets) ? this.sanitizeInsets(legendInsets) : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS;
- return this;
- },
- /**
- * Utility method used to fill any missing values from the insets
- * @param (Object) legendInsets insets to sanitize
- * @return (Object) the filled insets
- */
- sanitizeInsets : function(legendInsets) {
- legendInsets["top"] = ((typeof legendInsets["top"] === "number" || legendInsets["top"] instanceof Number)) ? legendInsets["top"] : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS["top"];
- legendInsets["bottom"] = ((typeof legendInsets["bottom"] === "number" || legendInsets["bottom"] instanceof Number)) ? legendInsets["bottom"] : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS["bottom"];
- legendInsets["left"] = ((typeof legendInsets["left"] === "number" || legendInsets["left"] instanceof Number)) ? legendInsets["left"] : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS["left"];
- legendInsets["right"] = ((typeof legendInsets["right"] === "number" || legendInsets["right"] instanceof Number)) ? legendInsets["right"] : com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS["right"];
- return legendInsets;
- },
- /**
- * Gets the value of reverse configuration
- * @return (boolean) whether the legend would reverse legend entry values or not
- */
- reverse$0 : function() {
- return this._reverse;
- },
- /**
- * Get the current text used for truncation for legend labels and title. Default is an ellipses
- * @return (String) Title String.
- */
- labelTruncationText$0 : function() {
- return this._labelTruncationText;
- },
- /**
- * Set the text used for truncation of legend labels and title. Default is an ellipses.
- * @param (String) labelTruncationText The text to use when truncating legend labels.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- */
- labelTruncationText$1 : function(labelTruncationText) {
- this._labelTruncationText = labelTruncationText;
- return this;
- },
- /**
- * Get the current truncation indicator to be used in case the size of this legend wasn't big enough to fit all entries. Default is null and a simple ellipses will be used instead;
- * @return (Object) The truncation indicator.
- * @see (Object) LegendTruncationIndicator
- */
- truncationIndicator$0 : function() {
- return this._legendTruncationIndicator;
- },
- /**
- * Set the truncation indicator of legend. Default is null and a simple ellipses will be used instead.
- * @param (Object) legendTruncationIndicator The truncation indicator object.
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance.
- * @see (Object) LegendTruncationIndicator
- */
- truncationIndicator$1 : function(legendTruncationIndicator) {
- this._legendTruncationIndicator = legendTruncationIndicator;
- return this;
- },
- /**
- * Sets the value of reverse configuration. If it is true, then the legend will reverse the order of the entries values so that the entries will be drawn in reverse order, else, the legend will render the entries in the same order it got them. Default value is false.
- * @param (boolean) reverse the value to set reverse for
- * @return (com.ibm.rave.ext.legend.AbstractLegend) this legend instance
- */
- reverse$1 : function(reverse) {
- this._reverse = reverse;
- return this;
- },
- addTruncationIndicator$0 : function(gSelection, titleVerticalShift, availableWidth, availableHeight, textFlow) {
- var midHorizontalPoint = ((this.size()[0] - (this.insets()["left"] + this.insets()["right"])) / 2.0) + this.insets()["left"];
- return this.addTruncationIndicator$1(gSelection.append("g").attr("class", "legendTruncationEntry"), midHorizontalPoint, titleVerticalShift - this.insets()["bottom"] + 3.0, availableWidth + this.entryInsets()["left"] + this.entryInsets()["right"], availableHeight + this.entryInsets()["top"] + this.entryInsets()["bottom"] - 3.0, textFlow, true);
- },
- addTruncationIndicator$1 : function(truncationSelector, midHorizontalPoint, y, availableWidth, availableHeight, textFlow, transform) {
- var truncationSymbol = this.getLegendTruncationIndicatorShapeSymbol();
- var truncationText = this.getLegendTruncationIndicatorText();
- var shapeWidth = 0;
- if (truncationSymbol) {
- var shape = truncationSelector.append("path").attr("class", "legendTruncationShape").attr("d", truncationSymbol);
- var shapeColor = this.getLegendTruncationIndicatorShapeColor();
- if ((shapeColor)) {
- shape.style("fill", shapeColor);
- } else {
- shape.style("fill-opacity", 0);
- }
- var borderColor = this.getLegendTruncationIndicatorShapeBorderColor();
- if ((borderColor)) {
- shape.attr("stroke", borderColor);
- }
- var shapeBbox = shape.node().getBBox();
- shapeWidth = shapeBbox.width;
- shape.attr("transform", "translate(" + (shapeWidth / 2.0) + ",0)");
- }
- var text = truncationSelector.append("text").attr("class", "legendTruncationLabel").text(truncationText);
- textFlow.wrap(true);
- textFlow.extent(~~(availableWidth - shapeWidth - 3.0), ~~availableHeight);
- textFlow.flow(text);
- var textX = (truncationSymbol) ? (3.0 + shapeWidth) : 0;
- text.attr("text-anchor", "start").attr("x", textX).attr("dy", this.getTextDyPlacement(text.node()));
- text.selectAll("tspan").attr("x", textX).attr("width", null);
- text.select("tspan").attr("x", null).attr("dy", null);
- var trunctationBBox = truncationSelector.node().getBBox();
- if (trunctationBBox.height > availableHeight || trunctationBBox.width > availableWidth) {
- if (truncationSymbol) {
- truncationSelector.select("path").remove();
- trunctationBBox = truncationSelector.node().getBBox();
- if (trunctationBBox.height > availableHeight || trunctationBBox.width > availableWidth) {
- truncationSelector.remove();
- return null;
- }
- text.attr("x", 0);
- text.selectAll("tspan").attr("x", 0);
- text.select("tspan").attr("x", null);
- } else {
- truncationSelector.remove();
- return null;
- }
- }
- if (transform) {
- truncationSelector.attr("transform", "translate(" + (midHorizontalPoint - (trunctationBBox.width / 2.0)) + "," + y + ")");
- }
- return truncationSelector;
- },
- /** @expose */
- getLegendTruncationIndicatorShapeSymbol : function() {
- if ((this._legendTruncationIndicator)) {
- if ((this._legendTruncationIndicator["shape"])) {
- var size = (this._legendTruncationIndicator["shapeSize"]) ? + (this._legendTruncationIndicator["shapeSize"]) : 400.0;
- var shapeSymbol;
- if (typeof this._legendTruncationIndicator["shape"] === "function") {
- shapeSymbol = (this._legendTruncationIndicator["shape"]).size(size);
- } else {
- shapeSymbol = rave.svg.symbol().size(size).type(this._legendTruncationIndicator["shape"]);
- }
- return shapeSymbol;
- }
- }
- return null;
- },
- /** @expose */
- getLegendTruncationIndicatorShapeColor : function() {
- if ((this._legendTruncationIndicator)) {
- if ((this._legendTruncationIndicator["shape"])) {
- return (this._legendTruncationIndicator["shapeColor"]) ? rave.rgb(this._legendTruncationIndicator["shapeColor"]).toString() : null;
- }
- }
- return null;
- },
- /** @expose */
- getLegendTruncationIndicatorShapeBorderColor : function() {
- if ((this._legendTruncationIndicator)) {
- if ((this._legendTruncationIndicator["shape"])) {
- return (this._legendTruncationIndicator["shapeBorderColor"]) ? rave.rgb(this._legendTruncationIndicator["shapeBorderColor"]).toString() : null;
- }
- }
- return null;
- },
- /** @expose */
- getLegendTruncationIndicatorText : function() {
- if ((this._legendTruncationIndicator)) {
- return (this._legendTruncationIndicator["text"]) ? this._legendTruncationIndicator["text"] : null;
- }
- return "...";
- },
- /** @expose */
- prepareLegendGroup : function(context) {
- var gSelection = rave.select(context);
- gSelection.selectAll(".legendGroup").remove();
- gSelection = gSelection.append("g").attr("class", "legendGroup");
- return gSelection;
- },
- /** @expose */
- getTextDyPlacement : function(node) {
- var numChildren = node.rave_getChildNodes().length;
- if (numChildren < 2) {
- return ".35em";
- }
- if (numChildren == 2) {
- return "-" + ((1.0 - 1) / 2) + "em";
- }
- var spacing = (numChildren - 1) * (1.0 - 1);
- var dy = (numChildren * 0.7) - 0.35;
- var placement = (dy + spacing) / 2;
- return "-" + (placement) + "em";
- },
- /** @expose */
- getLabelFormat : function() {
- var labelFormat = this._labelFormat;
- if (labelFormat == null) {
- labelFormat = com_ibm_rave_ext_legend_AbstractLegend._IDENTITY_FN;
- }
- return labelFormat;
- },
- /** @expose */
- prepareLegendTitle : function(gSelection, textFlow) {
- this._spaceUsed = 0;
- if ((this._title)) {
- var titleSelector = gSelection.append("text").attr("class", "legendTitle").text(this._title).style("font-size", this._titleFontSize).style("font-family", this._titleFontFamily).style("fill", this._titleFill);
- var vertical = this._legendInsets["top"] + this._titleInsets["top"] + this._legendInsets["bottom"] + this._titleInsets["bottom"];
- var availableHeight = this._size[1] - vertical;
- var left = this._titleInsets["left"] + this._legendInsets["left"];
- var right = this._titleInsets["right"] + this._legendInsets["right"];
- var availableWidth;
- if ("start" == this._titleAlignment) {
- availableWidth = this._size[0] - left - this._legendInsets["right"];
- } else if ("middle" == this._titleAlignment) {
- availableWidth = this._size[0] - (this._legendInsets["left"] + this._legendInsets["right"]);
- } else {
- availableWidth = this._size[0] - right - this._legendInsets["left"];
- }
- if (availableHeight <= 4.0 || availableWidth <= 4.0) {
- titleSelector.remove();
- return titleSelector;
- }
- textFlow.extent(~~availableWidth, ~~availableHeight);
- textFlow.flow(titleSelector);
- titleSelector.attr("dy", ".7em").attr("text-anchor", this._titleAlignment);
- var titleBbox = titleSelector.node().getBBox();
- if (titleBbox.height > availableHeight || titleBbox.width > availableWidth) {
- titleSelector.text("...");
- titleBbox = titleSelector.node().getBBox();
- if (titleBbox.height <= availableHeight && titleBbox.width <= availableWidth) {
- if (this._orient == "vertical") {
- this._spaceUsed = titleBbox.width + this._titleInsets["left"] + this._titleInsets["right"];
- } else {
- this._spaceUsed = titleBbox.height + this._titleInsets["top"] + this._titleInsets["bottom"];
- }
- titleSelector.remove();
- var titleTruncationSelector = gSelection.append("text").attr("class", "legendTruncationTitle").text("...").attr("y", this._legendInsets["top"] + this._titleInsets["top"]).attr("dy", ".7em").attr("text-anchor", "middle").attr("x", this._legendInsets["left"] + this._titleInsets["left"] + (availableWidth / 2.0));
- return titleTruncationSelector;
- }
- titleSelector.remove();
- } else {
- if (this._orient == "vertical") {
- this._spaceUsed = titleBbox.width + this._titleInsets["left"] + this._titleInsets["right"];
- } else {
- this._spaceUsed = titleBbox.height + this._titleInsets["top"] + this._titleInsets["bottom"];
- }
- }
- return titleSelector;
- }
- return null;
- },
- /** @expose */
- calculateTitleVerticalShift : function(titleSelector) {
- var titleHeight = 0;
- var top = this._legendInsets["top"];
- var bottom = this._legendInsets["bottom"];
- if (titleSelector) {
- bottom += this._titleInsets["bottom"];
- top += this._titleInsets["top"];
- titleSelector.attr("y", top);
- var node = titleSelector.node();
- var titleBBox = node.getBBox();
- titleHeight = titleBBox.height;
- }
- return top + bottom + titleHeight;
- },
- alignTitleHorizontally$0 : function(titleSelector) {
- if (titleSelector) {
- var left = this._titleInsets["left"] + this._legendInsets["left"];
- var right = this._titleInsets["right"] + this._legendInsets["right"];
- var x;
- if ("start" == this._titleAlignment) {
- x = left;
- } else if ("middle" == this._titleAlignment) {
- x = (this._size[0] / 2.0);
- } else {
- x = (this._size[0] - right);
- }
- titleSelector.attr("x", x);
- titleSelector.selectAll("tspan").attr("x", x).attr("width", null);
- titleSelector.select("tspan").attr("x", null).attr("dy", null);
- }
- },
- alignTitleHorizontally$1 : function(titleSelector, width) {
- if (titleSelector) {
- var x;
- if ("start" == this._titleAlignment) {
- x = this._titleInsets["left"] + this._legendInsets["left"];
- } else if ("end" == this._titleAlignment) {
- var diff = this.size()[0] - width;
- if (diff > (this._titleInsets["right"] + this._legendInsets["right"])) {
- x = width;
- } else {
- x = width + (diff - (this._titleInsets["right"] + this._legendInsets["right"]));
- }
- } else {
- x = (width / 2.0) + this._legendInsets["left"];
- }
- titleSelector.attr("x", x);
- titleSelector.selectAll("tspan").attr("x", x).attr("width", null);
- titleSelector.select("tspan").attr("x", null).attr("dy", null);
- }
- },
- /** @expose */
- createTextFlowComponent : function() {
- var textFlow = rave.capabilities.extension("textflow");
- textFlow.wrap(true).spacing(1.0).truncate(true).dropTextOnFail(false).textTruncateIndicator(this.labelTruncationText());
- return textFlow;
- },
- /** @expose */
- prepareLegendBounds : function(gSelection) {
- var legendBounds = gSelection.append("rect").attr("class", "legendBBox").attr("width", this._size[0]).attr("height", this._size[1]);
- if ((this._legendBorderColor)) {
- legendBounds.attr("stroke", rave.rgb(this._legendBorderColor).toString());
- }
- if ((this._legendBackgroundColor)) {
- legendBounds.style("fill", rave.rgb(this._legendBackgroundColor).toString());
- } else {
- legendBounds.style("fill-opacity", 0);
- }
- },
- /** @expose */
- getDataFromScale : function() {
- if (!this._scale) {
- return null;
- }
- var ticksData;
- if (this._scale.ticksInRange) {
- ticksData = this._scale.ticksInRange();
- }
- if (!ticksData || ticksData.length == 0) {
- if (this._scale.ticks) {
- ticksData = this._scale.ticks.apply(this._scale.ticks, this._scaleArguments);
- }
- }
- if (!ticksData || ticksData.length == 0) {
- ticksData = this._scale.domain();
- }
- return ticksData;
- },
- /** @expose */
- getData : function() {
- var ticksData = this._dataValues;
- if (!ticksData) {
- ticksData = this.getDataFromScale();
- }
- if (!ticksData || ticksData.length < this._minDataLen) {
- return null;
- }
- var ticksDataClone = [];
- for (var i = 0; i < ticksData.length; ++i) {
- ticksDataClone.push(ticksData[i]);
- }
- if (this._reverse) {
- ticksDataClone.reverse();
- }
- return ticksDataClone;
- },
- /**
- * Draws or redraws this legend into the specified selection of elements. The legend may be drawn into multiple elements simultaneously, but note that these legends would share the same backing data; typically, a legend is drawn into only one element at a time. This function will create its own subgroup and draw the legend into that, if that group exists already then all it will be removed with all its children and added anew.
- * @param (rave['internal']['Selector']) g a selection that holds the elements into which the legend is drawn. Typically a group element.
- */
- /** @expose */
- legend : function(g) {},
- /**
- * Creates an extra legend entry with the specified label. If there is an existing extra legend entry with the specified label, the old value is replaced. This is an example of how two extra entries can be added to the legend using the API: <p> legend.extraEntry("someLabel0").color("someColor").size(someSize).shape("someShape"); </p> <p> legend.extraEntry("someLabel1").color("someColor").size(someSize).shape("someShape"); </p>
- * @param (Object) label The label for the extra legend entry. Null and white spaces are not allowed.
- */
- /** @expose */
- extraEntry : function(label) {
- var ele = new com_ibm_rave_ext_legend_ExtraLegendEntry();
- if (label != null) {
- var extraEntryLabel = label.toString();
- if (extraEntryLabel.replace(new RegExp("\\s+","g"), "").length > 0) {
- this._extraLegendEntries.set(extraEntryLabel, ele);
- }
- }
- return ele;
- },
- /**
- * Clears all the extra legend entries.
- */
- /** @expose */
- clearExtraLegendEntries : function() {
- var extraEntryKeys = this._extraLegendEntries.keys();
- for (var __i_enFor0 = 0, __exp_enFor0 = extraEntryKeys, __len_enFor0 = __exp_enFor0.length;
- __i_enFor0 < __len_enFor0; ++__i_enFor0) {
- var key = __exp_enFor0[__i_enFor0];
- this._extraLegendEntries.remove(key);
- }
- },
- /**
- * When a legend component 'draws', it keeps track of how much space it used. If the legends orientation is VERTICAL_ORIENT, returned space is the width used. If the legends orientation is HORIZONTAL_ORIENT, returned space is the height used.
- * @return (double) space used (in pixels)
- */
- /** @expose */
- getUsedSize : function() {
- if (this._orient == "vertical") {
- return this._spaceUsed + this._legendInsets["left"] + this._legendInsets["right"] + 2;
- }
- return this._spaceUsed + this._legendInsets["top"] + this._legendInsets["bottom"] + 2;
- },
- /** @expose */
- minDataLen : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.minDataLen$0();
- }
- return this.minDataLen$1(a0);
- },
- /** @expose */
- scale : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.scale$1();
- }
- return this.scale$0(a0);
- },
- /** @expose */
- orient : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.orient$1();
- }
- return this.orient$0(a0);
- },
- /** @expose */
- title : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.title$0();
- }
- return this.title$1(a0);
- },
- /** @expose */
- size : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.size$0();
- }
- return this.size$1(a0);
- },
- /** @expose */
- scaleArguments : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.scaleArguments$1();
- }
- return this.scaleArguments$0.apply(this, args);
- },
- /** @expose */
- dataValues : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.dataValues$1();
- }
- return this.dataValues$0(a0);
- },
- /** @expose */
- labelFormat : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.labelFormat$2();
- }
- if (args.length == 1 && (a0 == null || typeof a0 === "string")) {
- return this.labelFormat$0(a0);
- }
- return this.labelFormat$1(a0);
- },
- /** @expose */
- labelPadding : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.labelPadding$1();
- }
- return this.labelPadding$0(a0);
- },
- /** @expose */
- borderColor : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.borderColor$0();
- }
- return this.borderColor$1(a0);
- },
- /** @expose */
- shapeBorderColor : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.shapeBorderColor$0();
- }
- return this.shapeBorderColor$1(a0);
- },
- /** @expose */
- backgroundColor : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.backgroundColor$0();
- }
- return this.backgroundColor$1(a0);
- },
- /** @expose */
- titleAlignment : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.titleAlignment$0();
- }
- return this.titleAlignment$1(a0);
- },
- /** @expose */
- titleInsets : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.titleInsets$0();
- }
- return this.titleInsets$1(a0);
- },
- /** @expose */
- titleFill : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.titleFill$0();
- }
- return this.titleFill$1(a0);
- },
- /** @expose */
- titleFontSize : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.titleFontSize$0();
- }
- return this.titleFontSize$1(a0);
- },
- /** @expose */
- titleFontFamily : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.titleFontFamily$0();
- }
- return this.titleFontFamily$1(a0);
- },
- /** @expose */
- entryInsets : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.entryInsets$0();
- }
- return this.entryInsets$1(a0);
- },
- /** @expose */
- insets : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.insets$0();
- }
- return this.insets$1(a0);
- },
- /** @expose */
- reverse : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.reverse$0();
- }
- return this.reverse$1(a0);
- },
- /** @expose */
- labelTruncationText : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.labelTruncationText$0();
- }
- return this.labelTruncationText$1(a0);
- },
- /** @expose */
- truncationIndicator : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.truncationIndicator$0();
- }
- return this.truncationIndicator$1(a0);
- },
- /** @expose */
- addTruncationIndicator : function(a0, a1, a2, a3, a4, a5, a6) {
- var args = arguments;
- if (args.length == 5) {
- return this.addTruncationIndicator$0(a0, a1, a2, a3, a4);
- }
- return this.addTruncationIndicator$1(a0, a1, a2, a3, a4, a5, a6);
- },
- /** @expose */
- alignTitleHorizontally : function(a0, a1) {
- var args = arguments;
- if (args.length == 1) {
- return this.alignTitleHorizontally$0(a0);
- }
- return this.alignTitleHorizontally$1(a0, a1);
- }
- });
- com_ibm_rave_ext_legend_AbstractLegend.createDefaultInsets = function() {
- var result = {};
- result["top"] = 3;
- result["left"] = 3;
- result["bottom"] = 3;
- result["right"] = 3;
- return result;
- };
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.EM_1 = "1em";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.EM_07 = ".7em";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.EM_035 = ".35em";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.EM_0 = "0em";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.HORIZONTAL_ORIENT = "horizontal";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.VERTICAL_ORIENT = "vertical";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.START_ALIGN = "start";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.MIDDLE_ALIGN = "middle";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.END_ALIGN = "end";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_TRUNCATION_TEXT = "...";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.FONT = "font";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_LABEL_PADDING = 3.0;
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS_VALUE = 3;
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.MIN_TEXT_DIM = 4.0;
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.LINE_SPACING_RATIO = 1.0;
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_ORIENT = "vertical";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_TITLE_ALIGN = "middle";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.LEGEND_ENTRY_CLASS_SELECTOR = "." + "legendEntry";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.LEGEND_GROUP_CLASS_SELECTOR = "." + "legendGroup";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.LEGEND_SHAPE_CLASS_SELECTOR = "." + "legendShape";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.LEGEND_TICK_LINE_CLASS_SELECTOR = "." + "legendTickLine";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.LEGEND_LABEL_CLASS_SELECTOR = "." + "legendLabel";
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_TRUNCATION_SHAPE_SIZE = 20.0 * 20.0;
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_SCALE_ARGS = [5.0];
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_LEGEND_SIZE = [100, 100];
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend.DEFAULT_INSETS = com_ibm_rave_ext_legend_AbstractLegend.createDefaultInsets();
- /** @expose */
- com_ibm_rave_ext_legend_AbstractLegend._IDENTITY_FN = function(data, index, groupIndex) {
- return ""+(data);
- };
- // $source: com/ibm/rave/ext/legend/ExtraLegendEntry
- /************************************************************************
- ** IBM Confidential
- **
- ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
- **
- ** (C) Copyright IBM Corp. 2017
- **
- ** The source code for this program is not published or otherwise divested of its trade secrets,
- ** irrespective of what has been deposited with the U.S. Copyright Office.
- ************************************************************************/
- // GENERATED
- var com_ibm_rave_ext_legend_ExtraLegendEntry = rave['internal']['Declare']({
- //_color : null,
- //_shape : null,
- _size : 0,
- _colorSet : false,
- _sizeSet : false,
- _shapeSet : false,
- /** @expose */
- constructor : function() {
- this._color = null;
- this._size = 0;
- this._shape = null;
- this._colorSet = false;
- this._sizeSet = false;
- this._shapeSet = false;
- },
- /**
- * Sets the color for the extra legend entry.
- * @param (String) color The color of the symbol for the legend entry.
- */
- color$0 : function(color) {
- if (color != null) {
- this._color = color;
- this._colorSet = true;
- }
- return this;
- },
- /**
- * Sets the size for the extra legend entry.
- * @param (double) size The size (in square pixels) of the symbol for the legend entry.
- */
- size$0 : function(size) {
- if (size >= 0) {
- this._size = size;
- this._sizeSet = true;
- }
- return this;
- },
- /**
- * Sets the shape for the extra legend entry.
- * @param (String) shape The shape of the symbol for the legend entry. Acceptable shapes are: "square", "circle", "triangle-up", "triangle-down", "triangle-left", "triangle-right", "diamond", "cross", "horizontal-rectangle", and "vertical-rectangle".
- */
- shape$0 : function(shape) {
- if ((shape != null) && (shape == "square" || shape == "circle" || shape == "triangle-up" || shape == "triangle-down" || shape == "triangle-left" || shape == "triangle-right" || shape == "diamond" || shape == "cross" || shape == "horizontal-rectangle" || shape == "vertical-rectangle")) {
- this._shape = shape;
- this._shapeSet = true;
- }
- return this;
- },
- /**
- * @return (String) The color of the symbol in the extra legend entry.
- */
- color$1 : function() {
- return this._color;
- },
- /**
- * @return (double) The size of the symbol in the extra legend entry.
- */
- size$1 : function() {
- return this._size;
- },
- /**
- * @return (String) The shape of the symbol in the extra legend entry.
- */
- shape$1 : function() {
- return this._shape;
- },
- /**
- * @return (boolean) Checks whether a color was explicitly set for the symbol of the extra legend entry.
- */
- /** @expose */
- colorSet : function() {
- return this._colorSet;
- },
- /**
- * @return (boolean) Checks whether a size was explicitly set for the symbol of the extra legend entry.
- */
- /** @expose */
- sizeSet : function() {
- return this._sizeSet;
- },
- /**
- * @return (boolean) Checks whether a shape was explicitly set for the symbol of the extra legend entry.
- */
- /** @expose */
- shapeSet : function() {
- return this._shapeSet;
- },
- /** @expose */
- color : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.color$1();
- }
- return this.color$0(a0);
- },
- /** @expose */
- size : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.size$1();
- }
- return this.size$0(a0);
- },
- /** @expose */
- shape : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.shape$1();
- }
- return this.shape$0(a0);
- }
- });
- // $source: com/ibm/rave/ext/internal/legend/nativeImpl/Module
- /************************************************************************
- ** IBM Confidential
- **
- ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
- **
- ** (C) Copyright IBM Corp. 2015
- **
- ** The source code for this program is not published or otherwise divested of its trade secrets,
- ** irrespective of what has been deposited with the U.S. Copyright Office.
- ************************************************************************/
- // @OnDemandLoad("rave-legends")
- // Must be the first import
- // @import ./ModuleHeader
- // @import com/ibm/rave/ext/legend/RaveLegend
- var com_ibm_rave_ext_text_internal_wrap_TextOperation = rave["internal"]["com_ibm_rave_ext_text_internal_wrap_TextOperation"],
- com_ibm_rave_ext_text_internal_wrap_TextData = rave["internal"]["com_ibm_rave_ext_text_internal_wrap_TextData"],
- com_ibm_rave_ext_text_internal_wrap_FontStyleStruct = rave["internal"]["com_ibm_rave_ext_text_internal_wrap_FontStyleStruct"];
- // $source: com/ibm/rave/ext/legend/swatch/SwatchLegend
- /************************************************************************
- ** IBM Confidential
- **
- ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
- **
- ** (C) Copyright IBM Corp. 2017
- **
- ** The source code for this program is not published or otherwise divested of its trade secrets,
- ** irrespective of what has been deposited with the U.S. Copyright Office.
- ************************************************************************/
- // GENERATED
- //@import com/ibm/rave/ext/legend/AbstractLegend (loadtime) // superclass
- //@import com/ibm/rave/ext/text/internal/wrap/TextOperation (runtime) // getOperation
- //@import com/ibm/rave/ext/text/internal/wrap/FontStyleStruct (runtime) // new
- /**
- * A class that would generate and draw a swatch legend based on passed parameters
- */
- var com_ibm_rave_ext_legend_swatch_SwatchLegend = rave['internal']['Declare'](com_ibm_rave_ext_legend_AbstractLegend, {
- //_shape : null,
- //_swatchSize : null,
- //_layoutMethod : null,
- _wrapLabels : true,
- _rows : 0,
- _columns : 0,
- constructor : function() {
- this._layoutMethod = "grid";
- {
- this.minDataLen(1);
- this.shape("square");
- this.swatchSize(400.0);
- }
- },
- /**
- * Get the current swatch shape type assigned to this legend
- * @return (Object) Shape string or shape generator i.e., Symbol.
- * @see Symbol
- */
- shape$0 : function() {
- return this._shape;
- },
- /**
- * Sets the shape type to be used to draw legend swatchs. Could be either Symbol functor that generates the shape path to be drawn, or one of the following strings: <li>square</li> <li>circle</li> <li>triangle-up</li> <li>triangle-down</li> <li>diamond</li> <li>cross</li> <li>rectangle and horizontal-rectangle</li> <li>vertical-rectangle</li> <li>triangle-left</li> <li>triangle-right</li> Default swatch shape is square
- * @param (Object) shape The shape to assign to this legend.
- * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance.
- */
- shape$1 : function(shape) {
- this._shape = (shape) ? shape : "square";
- return this;
- },
- /**
- * Get the value of the currently assigned area in pixels for the bounding box of legend swatchs shape. Default is 400 e.g. in case of a square shape, then it will be a box of 20x20 pixels. In case of a circle shape, the circle's diameter (bounding box side) will be equal to the squareroot of the area divided by pi.
- * @return (Object) Legend entry shape area size object.
- */
- swatchSize$0 : function() {
- return this._swatchSize;
- },
- /**
- * Specify the value of the area (in pixels) of the bounding box of swatchs shape. Could be either a value functions that will be called for each swatch or a numeric value or a string that could be parsed into a numeric value
- * @param (Object) size The value of area of swatch's bounding box.
- * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance.
- */
- swatchSize$1 : function(size) {
- this._swatchSize = size;
- return this;
- },
- /**
- * Returns whether legend's entry label is to be wrapped -if necessary- or not. Default is true
- * @return (boolean) true if the label wrapping is allowed, false otherwise
- */
- wrapLabels$0 : function() {
- return this._wrapLabels;
- },
- /**
- * Enables or disables label wrapping for legend entries. Label wrapping could occur if there isn't enough width available to display the label text as one line and there is enough height to accommodate the newly added text lines. If wrapping is disabled or if there isn't enough height, the legend would truncate the label text instead.
- * @param (boolean) wrapLabels a boolean value indicating whether to allow label wrapping or not
- * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance
- */
- wrapLabels$1 : function(wrapLabels) {
- this._wrapLabels = wrapLabels;
- return this;
- },
- /**
- * Sets the number of rows. If the legend orientation is horizontal, the layout will expand to have the given number of rows. If the legend orientation is vertical no more than this number of swatchs will be placed in any column. Passing a negative number means using the default value of zero This method takes a whole number or a string that could be parsed into a whole number The number of rows will also be impacted by the legend size as well.
- * @param (Object) rows the number of rows
- * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance
- */
- rows$0 : function(rows) {
- this._rows = ~~ (rows);
- return this;
- },
- /**
- * Returns the number of rows. Default value is zero indicating that there is no limit on the number of rows, subject to available legend size
- * @return (int) number of rows
- */
- rows$1 : function() {
- return this._rows;
- },
- /**
- * Sets the number of columns. If the legend orientation is vertical, the layout will expand to have the given number of columns. If the legend orientation is horizontal, no more than this number of swatchs will be placed in any row. Passing a negative number means using the default value of zero This method takes a whole number or a string that could be parsed into a whole number The number of columns will also be impacted by the legend size as well.
- * @param (Object) columns number of columns
- * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance
- */
- columns$0 : function(columns) {
- this._columns = ~~ (columns);
- return this;
- },
- /**
- * Returns the number of columns. Default value is zero indicating that there is no limit on the number of columns, subject to available legend size
- * @return (int) number of columns
- */
- columns$1 : function() {
- return this._columns;
- },
- /**
- * Returns layout method which controls the spacing of legend entries in the direction of legend orientation. Default is grid
- * @return (String) layout method
- */
- layoutMethod$0 : function() {
- return this._layoutMethod;
- },
- /**
- * Sets layout method used by the legend, which controls the spacing of legend entries in the direction of legend orientation. It could be either "packed" of "grid". The method "grid" (the default) makes all legend entries use the same spacing as the largest entry so that the bounding box of each entry will have the same width and height, and also, it will try to layout entries in as many columns and rows as needed. The method "packed" makes each legend entry use its own size, which usually results in the legend entries occupying lesser space if entries vary in size, also, if the legend orientation is vertical it would restrict the number of columns to one, and if the legend orientation was horizontal, it would restrict the number of rows to one . These restrictions imposed by the "packed' method will apply regardless of the size available for the legend and regardless of the values of rows and columns properties on the legend. The "packed" method is usually used for size legend where entries have varying sizes since if they don't, then no space would be saved when laying out the entries and it would only result in restricting the count of column or row used to one. Default method used is "grid"
- * @return (com.ibm.rave.ext.legend.swatch.SwatchLegend) this legend instance
- */
- layoutMethod$1 : function(layoutMethod) {
- if ("packed" == layoutMethod) {
- this._layoutMethod = "packed";
- } else {
- this._layoutMethod = "grid";
- }
- return this;
- },
- getSwatchSizeFunction : function() {
- var swatchSizeFn;
- if (typeof this._swatchSize === "function") {
- swatchSizeFn = this._swatchSize;
- } else {
- var swatchSize = + (this._swatchSize);
- swatchSizeFn = function(data, index, groupIndex) {
- return swatchSize;
- };
- }
- return swatchSizeFn;
- },
- getShapeSymbol : function(swatchSizeFn) {
- var shapeSymbol;
- if (typeof this._shape === "function") {
- shapeSymbol = (this._shape).size(swatchSizeFn);
- } else {
- shapeSymbol = rave.svg.symbol().size(swatchSizeFn).type(this._shape);
- }
- return shapeSymbol;
- },
- getLegendEntrySelectors : function(gSelection, swatchsData, shapeSymbol, labelFormat) {
- var self = this;
- var es = new com_ibm_rave_ext_legend_swatch_SwatchLegend.LegendEntrySelectors();
- if (!(self._extraLegendEntries.empty())) {
- var keys = self._extraLegendEntries.keys();
- for (var i = 0; i < keys.length; ++i) {
- if (!(swatchsData.indexOf(keys[i])> -1)) {
- swatchsData.push(keys[i]);
- }
- }
- }
- es.legendEntry = gSelection.selectAll(".legendEntry").data(swatchsData).enter().append("g").attr("class", "legendEntry");
- es.shape = es.legendEntry.append("path").attr("class", "legendShape").attr("d", function(data, index, groupIndex) {
- var ele = self._extraLegendEntries.get((data));
- if (ele) {
- var extraSymbolSize = 0.0;
- var extraSymbolShape = null;
- if (ele.sizeSet()) {
- extraSymbolSize = ele.size();
- } else {
- extraSymbolSize = (shapeSymbol.size().call(this, data, index, groupIndex));
- ele.size(extraSymbolSize);
- }
- if (ele.shapeSet()) {
- extraSymbolShape = ele.shape();
- } else {
- extraSymbolShape = shapeSymbol.type().call(this, data, index, groupIndex);
- ele.shape(extraSymbolShape);
- }
- var extraLegendEntrySymbol = rave.svg.symbol().size(extraSymbolSize).type(extraSymbolShape);
- return extraLegendEntrySymbol.call(this, data, index, groupIndex);
- }
- return shapeSymbol.call(this, data, index, groupIndex);
- }).style("fill", function(data, index, groupIndex) {
- var customColor = null;
- var ele = self._extraLegendEntries.get((data));
- customColor = self.scale().call(this, data, index, groupIndex);
- if (ele) {
- if (ele.colorSet()) {
- return self._extraLegendEntries.get((data)).color();
- }
- ele.color((customColor));
- }
- return customColor;
- });
- es.text = es.legendEntry.append("text").attr("class", "legendLabel");
- if (typeof labelFormat === "function") {
- es.text.text(labelFormat);
- } else {
- es.text.text(labelFormat);
- }
- if ((this.shapeBorderColor())) {
- es.shape.attr("stroke", rave.rgb(this.shapeBorderColor()).toString());
- }
- return es;
- },
- getLegendEntryBBoxes : function(es) {
- var eb = new com_ibm_rave_ext_legend_swatch_SwatchLegend.LegendEntryBBoxes();
- es.text.each(function(data, index, groupIndex) {
- var labelBbox = this.getBBox();
- eb.labelBboxes.push(labelBbox);
- eb.labelTexts.push(this.rave_getText());
- });
- es.shape.each(function(data, index, groupIndex) {
- eb.shapeBboxes.push(this.getBBox());
- });
- return eb;
- },
- createLayout : function(isHorizontal, availableWidth, availableHeight) {
- var layout = rave.layout.extension("fill");
- layout.cellSize(com_ibm_rave_ext_legend_swatch_SwatchLegend._NULL_SETVALUE_FN).direction(isHorizontal ? "row" : "column").size([availableWidth, availableHeight]).method(this._layoutMethod).valign("start").halign("start");
- if ("packed" == this._layoutMethod) {
- if (isHorizontal) {
- layout.rows(1);
- } else {
- layout.columns(1);
- }
- } else {
- if (this._rows > 0) {
- layout.rows(this._rows);
- }
- if (this._columns > 0) {
- layout.columns(this._columns);
- }
- }
- return layout;
- },
- buildFillNodes : function(swatchPadding, eb) {
- var entryInsets = this.entryInsets();
- var nodes = [];
- for (var i = 0; i < eb.shapeBboxes.length; ++i) {
- var fillNode = {};
- var shapeBbox = eb.shapeBboxes[i];
- var labelBbox = eb.labelBboxes[i];
- fillNode["height"] = Math.max(shapeBbox.height, labelBbox.height) + (entryInsets["top"] + entryInsets["bottom"]);
- fillNode["width"] = shapeBbox.width + labelBbox.width + entryInsets["left"] + entryInsets["right"] + swatchPadding;
- fillNode["data"] = i;
- nodes.push(fillNode);
- }
- return nodes;
- },
- buildGridDescrs : function(isHorizontal, eb, swatchPadding, availableWidth, availableHeight) {
- var entryInsets = this.entryInsets();
- var numEntries = eb.shapeBboxes.length;
- var fillNodes = [];
- for (var i = 0; i < numEntries; ++i) {
- var fillNode = {};
- var shapeBbox = eb.shapeBboxes[i];
- fillNode["height"] = entryInsets["top"] + entryInsets["bottom"];
- fillNode["width"] = shapeBbox.width + entryInsets["left"] + entryInsets["right"] + swatchPadding;
- fillNode["data"] = i;
- fillNodes.push(fillNode);
- }
- var maxRows = numEntries;
- var maxColumns = numEntries;
- var packed = "packed" == this._layoutMethod;
- if (packed) {
- if (isHorizontal) {
- maxRows = 1;
- } else {
- maxColumns = 1;
- }
- } else {
- if (this._rows > 0) {
- maxRows = this._rows;
- }
- if (this._columns > 0) {
- maxColumns = this._columns;
- }
- }
- if (isHorizontal) {
- if (maxColumns > 1) {
- var calculatedMaxCol = maxColumns;
- var totWidth = 0;
- var firstLabelBboxHeight = eb.labelBboxes[0].height;
- for (var i = 0; i < numEntries; ++i) {
- var fillNode = fillNodes[i];
- totWidth += fillNode["width"] + firstLabelBboxHeight;
- if (availableWidth < totWidth) {
- calculatedMaxCol = i;
- break;
- }
- }
- maxColumns = Math.min(maxColumns, calculatedMaxCol);
- }
- } else {
- if (maxRows > 1) {
- var calculatedMaxRow = maxRows;
- var totHeight = 0;
- for (var i = 0; i < numEntries; ++i) {
- var fillNode = fillNodes[i];
- var shapeBbox = eb.shapeBboxes[i];
- var labelBbox = eb.labelBboxes[i];
- totHeight += fillNode["height"] + Math.max(labelBbox.height, shapeBbox.height);
- if (availableHeight < totHeight) {
- calculatedMaxRow = i;
- break;
- }
- }
- maxRows = Math.min(maxRows, calculatedMaxRow);
- }
- }
- var maxNumNodes = Math.min(numEntries, (maxRows * maxColumns));
- var maxIteration = (isHorizontal) ? maxColumns : maxRows;
- var crl;
- var gridDescrs = [];
- var lastSeenNumColumns = -1;
- var lastSeenNumRows = -1;
- var largestSeenFailureIndex = 0;
- var numColumns;
- var numRows;
- for (var i = maxIteration; i > 0; --i) {
- if (isHorizontal) {
- numColumns = i;
- numRows = Math.ceil(maxNumNodes / numColumns);
- } else {
- numRows = i;
- numColumns = Math.ceil(maxNumNodes / numRows);
- }
- if (numColumns <= maxColumns && numRows <= maxRows) {
- numColumns = this.getMaxColumn(isHorizontal, maxNumNodes, numColumns, numRows);
- numRows = this.getMaxRow(isHorizontal, maxNumNodes, numColumns, numRows);
- if (numColumns != lastSeenNumColumns || numRows != lastSeenNumRows) {
- crl = this.buildColumnRowLists(isHorizontal, numColumns, numRows, fillNodes, maxNumNodes, eb);
- lastSeenNumColumns = numColumns;
- lastSeenNumRows = numRows;
- var cellHeight = availableHeight / numRows;
- var cellWidth = availableWidth / numColumns;
- var gridDescr = this.createGridDescr(numColumns, numRows, cellHeight, cellWidth, eb, fillNodes, maxNumNodes, crl.columnListShapes, crl.rowListShapes);
- if (packed) {
- gridDescrs.push(gridDescr);
- } else if (maxNumNodes > largestSeenFailureIndex) {
- if (gridDescr.firstFailureIndex > largestSeenFailureIndex) {
- largestSeenFailureIndex = gridDescr.firstFailureIndex;
- }
- if (gridDescr.firstFailureIndex < maxNumNodes) {
- var rowIndex = this.determineRow(isHorizontal, gridDescr.firstFailureIndex, gridDescr.numColumns, gridDescr.numRows);
- var colIndex = this.determineColumn(isHorizontal, gridDescr.firstFailureIndex, gridDescr.numColumns, gridDescr.numRows);
- var columnListIndex = crl.columnListShapes[colIndex];
- var labelBbox = eb.labelBboxes[columnListIndex];
- var colFillNode = fillNodes[columnListIndex];
- var minCellWidth = colFillNode["width"] + labelBbox.height;
- var rowListIndex = crl.rowListShapes[rowIndex];
- labelBbox = eb.labelBboxes[rowListIndex];
- var shapeBbox = eb.shapeBboxes[rowListIndex];
- var rowFillNode = fillNodes[rowListIndex];
- var minCellHeight = rowFillNode["height"] + Math.max(labelBbox.height, shapeBbox.height);
- var gridDescr2 = this.adjustFailedGridDescr(gridDescr, fillNodes, maxNumNodes, isHorizontal, eb, availableWidth, availableHeight, minCellWidth, minCellHeight, largestSeenFailureIndex);
- if (gridDescr2) {
- gridDescr = gridDescr2;
- if (gridDescr.firstFailureIndex > largestSeenFailureIndex) {
- largestSeenFailureIndex = gridDescr.firstFailureIndex;
- }
- }
- }
- if (gridDescr.firstFailureIndex > 0 && gridDescr.firstFailureIndex >= largestSeenFailureIndex) {
- gridDescrs.push(gridDescr);
- }
- } else if (maxNumNodes == gridDescr.firstFailureIndex) {
- gridDescrs.push(gridDescr);
- }
- }
- }
- }
- return gridDescrs;
- },
- getMaxColumn : function(isHorizontal, numNodes, numCols, numRows) {
- if (isHorizontal) {
- if (numNodes >= numCols) {
- return numCols;
- } else {
- return numNodes;
- }
- }
- return Math.ceil(numNodes / numRows);
- },
- getMaxRow : function(isHorizontal, numNodes, numCols, numRows) {
- if (isHorizontal) {
- return Math.ceil(numNodes / numCols);
- }
- if (numNodes >= numRows) {
- return numRows;
- } else {
- return numNodes;
- }
- },
- adjustFailedGridDescr : function(gridDescr, fillNodes, numNodes, isHorizontal, eb, availableWidth, availableHeight, minCellWidth, minCellHeight, largestSeenFailureIndex) {
- var _fillNodes = fillNodes;
- var bestGridDescr;
- var lastSeenCellWidth = gridDescr.cellWidth;
- var lastSeenCellHeight = gridDescr.cellHeight;
- var increaseWidth = lastSeenCellWidth < minCellWidth;
- var increaseHeight = lastSeenCellHeight < minCellHeight;
- if (increaseWidth && increaseHeight) {
- return null;
- }
- var minNodeCount = Math.max(2, largestSeenFailureIndex);
- var _numNodes = numNodes;
- var numRowCol;
- var availableLength;
- var lastSeenlength;
- var minIncrease;
- if (isHorizontal) {
- if (increaseHeight) {
- numRowCol = gridDescr.numColumns;
- availableLength = availableHeight;
- lastSeenlength = lastSeenCellHeight;
- minIncrease = Math.max(1, minCellHeight - lastSeenCellHeight);
- } else {
- numRowCol = 1;
- availableLength = availableWidth;
- lastSeenlength = lastSeenCellWidth;
- minIncrease = Math.max(1, minCellWidth - lastSeenCellWidth);
- }
- } else {
- if (increaseWidth) {
- numRowCol = gridDescr.numRows;
- availableLength = availableWidth;
- lastSeenlength = lastSeenCellWidth;
- minIncrease = Math.max(1, minCellWidth - lastSeenCellWidth);
- } else {
- numRowCol = 1;
- availableLength = availableHeight;
- lastSeenlength = lastSeenCellHeight;
- minIncrease = Math.max(1, minCellHeight - lastSeenCellHeight);
- }
- }
- _numNodes = Math.floor(availableLength / (lastSeenlength + minIncrease)) * numRowCol;
- minIncrease = 1;
- while (_numNodes >= minNodeCount) {
- var numColumns = this.getMaxColumn(isHorizontal, _numNodes, gridDescr.numColumns, gridDescr.numRows);
- var numRows = this.getMaxRow(isHorizontal, _numNodes, gridDescr.numColumns, gridDescr.numRows);
- if (numRows != gridDescr.numRows || numColumns != gridDescr.numColumns) {
- if ((!bestGridDescr) || (numRows != bestGridDescr.numRows || numColumns != bestGridDescr.numColumns)) {
- var cellHeight = availableHeight / numRows;
- var cellWidth = availableWidth / numColumns;
- if ((cellHeight - lastSeenCellHeight) >= minIncrease || (cellWidth - lastSeenCellWidth) >= minIncrease) {
- lastSeenCellHeight = cellHeight;
- lastSeenCellWidth = cellWidth;
- lastSeenlength = (increaseHeight) ? lastSeenCellHeight : lastSeenCellWidth;
- if (cellHeight >= minCellHeight && cellWidth >= minCellWidth) {
- var crl = this.buildColumnRowLists(isHorizontal, gridDescr.numColumns, gridDescr.numRows, _fillNodes, _numNodes, eb);
- var gridDescr2 = this.createGridDescr(gridDescr.numColumns, gridDescr.numRows, cellHeight, cellWidth, eb, _fillNodes, _numNodes, crl.columnListShapes, crl.rowListShapes);
- if (gridDescr2.firstFailureIndex >= largestSeenFailureIndex) {
- if (!bestGridDescr || bestGridDescr.firstFailureIndex < gridDescr2.firstFailureIndex) {
- bestGridDescr = gridDescr2;
- for (var j = crl.rowListShapes.length; j < gridDescr.numRows; ++j) {
- bestGridDescr.heightAvailableForTextPerRow.push(4.0);
- }
- for (var j = crl.columnListShapes.length; j < gridDescr.numColumns; ++j) {
- bestGridDescr.widthAvailableForTextPerColumn.push(4.0);
- }
- if (bestGridDescr.firstFailureIndex == _numNodes) {
- return bestGridDescr;
- } else if (bestGridDescr.firstFailureIndex > minNodeCount) {
- minNodeCount = bestGridDescr.firstFailureIndex;
- }
- }
- }
- }
- }
- }
- }
- _numNodes = Math.floor(availableLength / (lastSeenlength + minIncrease)) * numRowCol;
- }
- return bestGridDescr;
- },
- createGridDescr : function(numColumns, numRows, cellHeight, cellWidth, eb, fillNodes, nodeCount, columnListShapes, rowListShapes) {
- var widthAvailableForTextPerColumn = [];
- var heightAvailableForTextPerRow = [];
- var firstFailureIndex = nodeCount;
- for (var j = 0; j < columnListShapes.length; ++j) {
- var columnListIndex = columnListShapes[j];
- var labelBbox = eb.labelBboxes[columnListIndex];
- var colFillNode = fillNodes[columnListIndex];
- var widthAvailableForText = cellWidth - colFillNode["width"];
- if (widthAvailableForText < labelBbox.height) {
- if (columnListIndex < firstFailureIndex) {
- firstFailureIndex = columnListIndex;
- }
- }
- widthAvailableForTextPerColumn.push((widthAvailableForText > 4.0) ? widthAvailableForText : 4.0);
- }
- for (var k = 0; k < rowListShapes.length; ++k) {
- var rowListIndex = rowListShapes[k];
- var shapeBbox = eb.shapeBboxes[rowListIndex];
- var labelBbox = eb.labelBboxes[rowListIndex];
- var rowFillNode = fillNodes[rowListIndex];
- var heightAvailableForText = cellHeight - rowFillNode["height"];
- if (heightAvailableForText < Math.max(labelBbox.height, shapeBbox.height)) {
- if (rowListIndex < firstFailureIndex) {
- firstFailureIndex = rowListIndex;
- }
- }
- heightAvailableForTextPerRow.push((heightAvailableForText > 4.0) ? heightAvailableForText : 4.0);
- }
- return new com_ibm_rave_ext_legend_swatch_SwatchLegend.GridDescr(numColumns, numRows, columnListShapes.length, rowListShapes.length, firstFailureIndex, cellWidth, cellHeight, widthAvailableForTextPerColumn, heightAvailableForTextPerRow);
- },
- applyTextWrapping : function(isHorizontal, textFlow, eb, es, swatchPadding, availableWidth, availableHeight) {
- var gridDescrs = this.buildGridDescrs(isHorizontal, eb, swatchPadding, availableWidth, availableHeight);
- if (gridDescrs.length > 0) {
- if (gridDescrs.length > 1) {
- gridDescrs.sort(function(obj1, obj2) {
- var result = obj2.firstFailureIndex - obj1.firstFailureIndex;
- if (result == 0) {
- if (isHorizontal) {
- return obj2.numColumnsUsed - obj1.numColumnsUsed;
- } else {
- return obj2.numRowsUsed - obj1.numRowsUsed;
- }
- }
- return result;
- });
- }
- var text_operation = com_ibm_rave_ext_text_internal_wrap_TextOperation.getOperation((this._wrapLabels) ? 1 : 0, this.labelTruncationText());
- text_operation.font(com_ibm_rave_ext_legend_swatch_SwatchLegend.createFontStruct(es.text.node().rave_getComputedStyles()));
- text_operation.em(1.0);
- var bestFailedResult = null;
- var bestSuccessResult = null;
- var numEntries = eb.shapeBboxes.length;
- var success;
- var noTruncation;
- for (var i = 0; i < gridDescrs.length; ++i) {
- success = true;
- noTruncation = 0;
- var gridDescr = gridDescrs[i];
- if (bestFailedResult) {
- if (gridDescr.firstFailureIndex < bestFailedResult.gridDescr.firstFailureIndex) {
- continue;
- }
- if (gridDescr.cellHeight == bestFailedResult.gridDescr.cellHeight && gridDescr.cellWidth == bestFailedResult.gridDescr.cellWidth) {
- continue;
- }
- }
- var j;
- for (j = 0; j < gridDescr.firstFailureIndex; ++j) {
- var labelBbox = eb.labelBboxes[j];
- var rowIndex = this.determineRow(isHorizontal, j, gridDescr.numColumns, gridDescr.numRows);
- var colIndex = this.determineColumn(isHorizontal, j, gridDescr.numColumns, gridDescr.numRows);
- var width = (colIndex < gridDescr.widthAvailableForTextPerColumn.length) ? gridDescr.widthAvailableForTextPerColumn[colIndex] : 4.0;
- var height = (rowIndex < gridDescr.heightAvailableForTextPerRow.length) ? gridDescr.heightAvailableForTextPerRow[rowIndex] : 4.0;
- if (width < labelBbox.height || height < labelBbox.height) {
- success = false;
- break;
- }
- text_operation.size(width, height);
- text_operation.fontSize(labelBbox.height);
- var text = eb.labelTexts[j];
- if (text.length === 0) {
- noTruncation++;
- break;
- }
- text_operation.text(text);
- var result = text_operation();
- if (result.lines.length == 0 || result.clipped || result.tooTall || result.truncated) {
- success = false;
- if (result.lines.length == 0) {
- break;
- }
- } else {
- noTruncation++;
- }
- }
- if (success && gridDescr.firstFailureIndex == numEntries) {
- bestSuccessResult = new com_ibm_rave_ext_legend_swatch_SwatchLegend.TextResult(numEntries, noTruncation, gridDescr);
- break;
- } else {
- if (!bestFailedResult || (gridDescr.firstFailureIndex > bestFailedResult.gridDescr.firstFailureIndex) || (gridDescr.firstFailureIndex == bestFailedResult.gridDescr.firstFailureIndex && j > bestFailedResult.entriesCount) || (gridDescr.firstFailureIndex == bestFailedResult.gridDescr.firstFailureIndex && j == bestFailedResult.entriesCount && noTruncation > bestFailedResult.noTruncation)) {
- bestFailedResult = new com_ibm_rave_ext_legend_swatch_SwatchLegend.TextResult(j, noTruncation, gridDescr);
- }
- }
- }
- var textResult = (bestSuccessResult) ? bestSuccessResult : bestFailedResult;
- if (textResult) {
- textFlow.wrap(this._wrapLabels);
- if (textResult.entriesCount > 0) {
- var self = this;
- es.text.each(function(data, index, groupIndex) {
- if (index < textResult.entriesCount) {
- var rowIndex = self.determineRow(isHorizontal, index, textResult.gridDescr.numColumns, textResult.gridDescr.numRows);
- var colIndex = self.determineColumn(isHorizontal, index, textResult.gridDescr.numColumns, textResult.gridDescr.numRows);
- var width = (colIndex < textResult.gridDescr.widthAvailableForTextPerColumn.length) ? textResult.gridDescr.widthAvailableForTextPerColumn[colIndex] : 4.0;
- var height = (rowIndex < textResult.gridDescr.heightAvailableForTextPerRow.length) ? textResult.gridDescr.heightAvailableForTextPerRow[rowIndex] : 4.0;
- textFlow.extent(~~width, ~~height);
- textFlow.flow(rave.select(this));
- var text = this.rave_getText();
- var labelBbox = this.getBBox();
- eb.labelBboxes[index] = labelBbox;
- eb.labelTexts[index] = text;
- }
- });
- }
- }
- return textResult;
- }
- return null;
- },
- layoutLegendEntries : function(isHorizontal, textFlow, eb, es, swatchPadding, availableWidth, availableHeight) {
- var textResult = this.applyTextWrapping(isHorizontal, textFlow, eb, es, swatchPadding, availableWidth, availableHeight);
- var lr = new com_ibm_rave_ext_legend_swatch_SwatchLegend.LayoutResults();
- lr.textResult = textResult;
- lr.layout = this.createLayout(isHorizontal, availableWidth, availableHeight);
- lr.nodes = this.buildFillNodes(swatchPadding, eb);
- var firstFailureIndex = lr.nodes.length;
- var entrySpaceUsed = 0;
- if (textResult && !("packed" == this._layoutMethod)) {
- var entryInsets = this.entryInsets();
- var isVertical = this.orient() == "vertical";
- var entriesCount = textResult.entriesCount;
- firstFailureIndex = textResult.gridDescr.firstFailureIndex;
- var largestWidth = -1;
- var largestHeight = -1;
- for (var i = 0; i < entriesCount; ++i) {
- var node = lr.nodes[i];
- if (node["width"] > largestWidth) {
- largestWidth = node["width"];
- if (isVertical) {
- entrySpaceUsed = largestWidth;
- }
- }
- if (node["height"] > largestHeight) {
- largestHeight = node["height"];
- if (!isVertical) {
- entrySpaceUsed = largestHeight;
- }
- }
- }
- if (isVertical) {
- entrySpaceUsed *= lr.textResult.gridDescr.numColumnsUsed;
- entrySpaceUsed += (entryInsets["left"] + entryInsets["right"]);
- if (entrySpaceUsed > this._spaceUsed) {
- this._spaceUsed = entrySpaceUsed;
- }
- } else {
- entrySpaceUsed *= lr.textResult.gridDescr.numRowsUsed;
- entrySpaceUsed += (entryInsets["top"] + entryInsets["bottom"]);
- this._spaceUsed += entrySpaceUsed;
- }
- if (textResult.entriesCount == lr.nodes.length && firstFailureIndex == lr.nodes.length) {
- if (textResult.gridDescr.cellHeight >= largestHeight && textResult.gridDescr.cellWidth >= largestWidth) {
- lr.layout.rows(lr.textResult.gridDescr.numRowsUsed);
- lr.layout.columns(lr.textResult.gridDescr.numColumnsUsed);
- }
- }
- }
- lr.elements = lr.layout(lr.nodes);
- lr.numCols = lr.layout.numberOfHorizontalCells();
- lr.numRows = lr.layout.numberOfVerticalCells();
- if (firstFailureIndex != lr.nodes.length) {
- if (lr.elements.length < firstFailureIndex && !("packed" == this._layoutMethod)) {
- var elements = lr.layout(lr.nodes.slice(0, firstFailureIndex));
- if (elements.length > lr.elements.length) {
- lr.elements = elements;
- lr.numCols = lr.layout.numberOfHorizontalCells();
- lr.numRows = lr.layout.numberOfVerticalCells();
- }
- }
- }
- lr.crl = this.buildColumnRowLists(isHorizontal, lr.numCols, lr.numRows, lr.elements, lr.elements.length, eb);
- return lr;
- },
- buildColumnRowLists : function(isHorizontal, numCols, numRows, fillNodes, nodeCount, eb) {
- var crl = new com_ibm_rave_ext_legend_swatch_SwatchLegend.ColumnRowLists();
- for (var i = 0; i < nodeCount; ++i) {
- var node = fillNodes[i];
- var currentNodeIndex = node["data"];
- var currentColumnNumber = this.determineColumn(isHorizontal, currentNodeIndex, numCols, numRows);
- if (currentColumnNumber < crl.columnListShapes.length) {
- var curColIndex = crl.columnListShapes[currentColumnNumber];
- var currentShape = eb.shapeBboxes[currentNodeIndex];
- var curColShape = eb.shapeBboxes[curColIndex];
- if ((currentShape.width > curColShape.width)) {
- crl.columnListShapes[currentColumnNumber] = currentNodeIndex;
- }
- } else {
- crl.columnListShapes[currentColumnNumber] = currentNodeIndex;
- }
- var currentRowNumber = this.determineRow(isHorizontal, currentNodeIndex, numCols, numRows);
- if (currentRowNumber < crl.rowListShapes.length) {
- var curRowIndex = crl.rowListShapes[currentRowNumber];
- var currentShape = eb.shapeBboxes[currentNodeIndex];
- var curRowShape = eb.shapeBboxes[curRowIndex];
- if ((currentShape.height > curRowShape.height)) {
- crl.rowListShapes[currentRowNumber] = currentNodeIndex;
- }
- } else {
- crl.rowListShapes[currentRowNumber] = currentNodeIndex;
- }
- }
- return crl;
- },
- handleFailedLayout : function(isHorizontal, gSelection, lr, es, eb, swatchsData, availableWidth, availableHeight, titleVerticalShift, textFlow) {
- var removedFillNode;
- if (lr.elements.length > 0) {
- removedFillNode = lr.elements.pop();
- }
- if (lr.elements.length == 0 || !removedFillNode) {
- gSelection.selectAll(".legendEntry").remove();
- this.addTruncationIndicator(gSelection, titleVerticalShift, availableWidth, availableHeight, textFlow);
- return false;
- }
- var newSwatchsData = [];
- for (var i = 0; i < lr.elements.length; ++i) {
- newSwatchsData[i] = swatchsData[i];
- }
- es.legendEntry = gSelection.selectAll(".legendEntry").data(newSwatchsData);
- es.legendEntry.exit().remove();
- es.shape = es.legendEntry.select("path");
- es.text = es.legendEntry.select("text");
- lr.crl = this.buildColumnRowLists(isHorizontal, lr.numCols, lr.numRows, lr.elements, lr.elements.length, eb);
- lr.numCols = lr.crl.columnListShapes.length;
- lr.numRows = lr.crl.rowListShapes.length;
- var truncationSelector = gSelection.append("g").attr("class", "legendTruncationEntry");
- var removedFillNodeIndex = lr.elements.length;
- var rowVal = this.determineRow(isHorizontal, removedFillNodeIndex, lr.numCols, lr.numRows);
- var width = availableWidth - removedFillNode["x"];
- var height = availableHeight - removedFillNode["y"];
- var midHorizontalPoint = (removedFillNode["x"] + this.entryInsets()["left"] + this.insets()["left"]) + (width / 2.0);
- var yShift;
- if (rowVal == 0 || rowVal == lr.numRows - 1) {
- yShift = removedFillNode["height"] - this.entryInsets()["bottom"];
- } else {
- yShift = removedFillNode["height"] - this.entryInsets()["bottom"] - this.entryInsets()["top"];
- }
- this.addTruncationIndicator(truncationSelector, midHorizontalPoint, (removedFillNode["y"] + titleVerticalShift - this.insets()["bottom"] + (yShift / 2.0)), width, height, textFlow, true);
- return true;
- },
- alignLabelsShapes : function(isHorizontal, eb, es, lr, swatchPadding) {
- var self = this;
- es.shape.attr("transform", function(data, index, groupIndex) {
- var val = self.determineColumn(isHorizontal, index, lr.numCols, lr.numRows);
- var shapeBbox = eb.shapeBboxes[lr.crl.columnListShapes[val]];
- return "translate(" + (shapeBbox.width / 2.0) + ",0)";
- });
- es.text.each(function(data, index, groupIndex) {
- var textSelection = rave.select(this);
- var val = self.determineColumn(isHorizontal, index, lr.numCols, lr.numRows);
- var shapeBbox = eb.shapeBboxes[lr.crl.columnListShapes[val]];
- var x = swatchPadding + shapeBbox.width;
- textSelection.attr("x", x).attr("text-anchor", "start").attr("dy", self.getTextDyPlacement(this));
- textSelection.selectAll("tspan").attr("x", x).attr("width", null);
- textSelection.select("tspan").attr("x", null).attr("dy", null);
- });
- },
- buildRowListFillNodes : function(isHorizontal, numCols, numRows, fillNodes) {
- var rowListFillNodes = [];
- for (var i = 0; i < fillNodes.length; ++i) {
- var node = fillNodes[i];
- var currentNodeIndex = node["data"];
- var currentRowNumber = this.determineRow(isHorizontal, currentNodeIndex, numCols, numRows);
- if (currentRowNumber < rowListFillNodes.length) {
- var curRowIndex = rowListFillNodes[currentRowNumber];
- var curRowNode = fillNodes[curRowIndex];
- if (node["height"] > curRowNode["height"]) {
- rowListFillNodes[currentRowNumber] = currentNodeIndex;
- }
- } else {
- rowListFillNodes[currentRowNumber] = currentNodeIndex;
- }
- }
- return rowListFillNodes;
- },
- transformShapes : function(isHorizontal, es, lr, titleVerticalShift) {
- var self = this;
- var entryInsets = this.entryInsets();
- var legendInsets = this.insets();
- var rowListFillNodes = this.buildRowListFillNodes(isHorizontal, lr.numCols, lr.numRows, lr.elements);
- es.legendEntry.attr("transform", function(data, index, groupIndex) {
- var fillNode = lr.elements[index];
- var val = self.determineRow(isHorizontal, index, lr.numCols, lr.numRows);
- var nodeHeight = lr.elements[rowListFillNodes[val]]["height"];
- var height = (nodeHeight - entryInsets["bottom"] - entryInsets["top"]);
- var x = (fillNode["x"] + entryInsets["left"] + legendInsets["left"]);
- var y = (fillNode["y"] + entryInsets["top"] + titleVerticalShift - legendInsets["bottom"] + (height / 2.0));
- return "translate(" + x + "," + y + ")";
- });
- },
- verifyResults : function(isHorizontal, eb, lr, availableWidth, availableHeight) {
- var columnNodesHorizontalExtent = [];
- for (var row = 0; row < lr.numRows; ++row) {
- var column = [];
- columnNodesHorizontalExtent.push(column);
- }
- var firstFailure = -1;
- for (var i = 0; i < lr.elements.length; ++i) {
- var fillNode = lr.elements[i];
- if ((fillNode["data"]) != i) {
- firstFailure = i;
- break;
- }
- if (((fillNode["x"] + fillNode["width"]) - availableWidth) > 1) {
- firstFailure = i;
- break;
- }
- if (((fillNode["y"] + fillNode["height"]) - availableHeight) > 1) {
- firstFailure = i;
- break;
- }
- var colIndex = this.determineColumn(isHorizontal, i, lr.numCols, lr.numRows);
- var columnListIndex = lr.crl.columnListShapes[colIndex];
- var currentShapeBbox = eb.shapeBboxes[i];
- var shapeBbox = eb.shapeBboxes[columnListIndex];
- var width = (fillNode["width"] - currentShapeBbox.width) + shapeBbox.width;
- var horizontalExtent = fillNode["x"] + width;
- if ((horizontalExtent - availableWidth) > 1) {
- firstFailure = i;
- break;
- }
- var rowIndex = this.determineRow(isHorizontal, i, lr.numCols, lr.numRows);
- var columnsPerRow = columnNodesHorizontalExtent[rowIndex];
- columnsPerRow.push(horizontalExtent);
- if (colIndex > 0) {
- var precedingNodeExtent = columnsPerRow[colIndex - 1];
- if ((precedingNodeExtent - fillNode["x"]) > 1) {
- firstFailure = i;
- break;
- }
- }
- }
- if (firstFailure != -1) {
- lr.elements = lr.elements.slice(0, firstFailure);
- lr.crl = this.buildColumnRowLists(isHorizontal, lr.numCols, lr.numRows, lr.elements, lr.elements.length, eb);
- lr.numCols = lr.crl.columnListShapes.length;
- lr.numRows = lr.crl.rowListShapes.length;
- }
- },
- alignSwatchLegendTitleHorizontally : function(isHorizontal, titleSelector, eb, lr) {
- if (titleSelector) {
- var legendProperWidth = 0;
- var lastColIndex = lr.numCols - 1;
- var columnListIndex = lr.crl.columnListShapes[lastColIndex];
- var shapeBbox = eb.shapeBboxes[columnListIndex];
- for (var i = 0; i < lr.elements.length; ++i) {
- var colIndex = this.determineColumn(isHorizontal, i, lr.numCols, lr.numRows);
- if (colIndex == lastColIndex) {
- var fillNode = lr.elements[i];
- var currentShapeBbox = eb.shapeBboxes[i];
- var fillNodeWidth = (fillNode["width"] - currentShapeBbox.width) + shapeBbox.width;
- var horizontalExtent = fillNode["x"] + fillNodeWidth;
- if (horizontalExtent > legendProperWidth) {
- legendProperWidth = horizontalExtent;
- }
- }
- }
- if (legendProperWidth > 0) {
- var titleBbox = titleSelector.node().getBBox();
- var w = Math.max(titleBbox.width, legendProperWidth);
- this.alignTitleHorizontally(titleSelector, w);
- } else {
- this.alignTitleHorizontally(titleSelector);
- }
- }
- },
- determineColumn : function(isHorizontal, index, numCols, numRows) {
- if (isHorizontal) {
- return index % numCols;
- }
- return ~~ (index / numRows);
- },
- determineRow : function(isHorizontal, index, numCols, numRows) {
- if (isHorizontal) {
- return ~~ (index / numCols);
- }
- return index % numRows;
- },
- /**
- * Draws or redraws this legend into the specified selection of elements. The legend may be drawn into multiple elements simultaneously, but note that these legends would share the same backing data; typically, a legend is drawn into only one element at a time. This function will create its own subgroup and draw the legend into that, if that group exists already then all it will be removed with all its children and added anew.
- * @param (rave['internal']['Selector']) g a selection that holds the elements into which the legend is drawn. Typically a group element.
- */
- /** @expose */
- legend : function(g) {
- var self = this;
- g.each(function(data, index, groupIndex) {
- self._spaceUsed = 0;
- var gSelection = self.prepareLegendGroup(this);
- self.prepareLegendBounds(gSelection);
- var labelFormat = self.getLabelFormat();
- var swatchSizeFn = self.getSwatchSizeFunction();
- var shapeSymbol = self.getShapeSymbol(swatchSizeFn);
- var textFlow = self.createTextFlowComponent();
- var titleSelector = self.prepareLegendTitle(gSelection, textFlow);
- if (titleSelector && !titleSelector.node().rave_getParentNode()) {
- return;
- }
- var titleVerticalShift = self.calculateTitleVerticalShift(titleSelector);
- var availableWidth = self.size()[0] - self.insets()["left"] - self.insets()["right"];
- var availableHeight = self.size()[1] - titleVerticalShift;
- if (availableHeight <= 0 || availableWidth <= 0) {
- self.alignTitleHorizontally(titleSelector);
- return;
- }
- if (!((self.scale()))) {
- self.alignTitleHorizontally(titleSelector);
- return;
- }
- var swatchsData = self.getData();
- if (!swatchsData) {
- self.alignTitleHorizontally(titleSelector);
- return;
- }
- var es = self.getLegendEntrySelectors(gSelection, swatchsData, shapeSymbol, labelFormat);
- var eb = self.getLegendEntryBBoxes(es);
- if (eb.shapeBboxes.length == 0) {
- self.alignTitleHorizontally(titleSelector);
- return;
- }
- var swatchPadding = + (self.labelPadding());
- for (var i = 0; i < Math.min(eb.labelBboxes.length, 2); ++i) {
- var labelBBox = eb.labelBboxes[i];
- var shapeBBox = eb.shapeBboxes[i];
- var test1 = availableHeight < Math.max(labelBBox.height, shapeBBox.height);
- var test2 = availableWidth < ((labelBBox.height / 2.0) + shapeBBox.width + self.entryInsets()["left"] + self.entryInsets()["right"] + swatchPadding);
- if (test1 || test2) {
- es.legendEntry.remove();
- self.addTruncationIndicator(gSelection, titleVerticalShift, availableWidth, availableHeight, textFlow);
- self.alignTitleHorizontally(titleSelector);
- return;
- }
- }
- var isHorizontal = "horizontal" == self.orient();
- var lr = self.layoutLegendEntries(isHorizontal, textFlow, eb, es, swatchPadding, availableWidth, availableHeight);
- self.verifyResults(isHorizontal, eb, lr, availableWidth, availableHeight);
- if (lr.nodes.length != lr.elements.length) {
- if (!(self.handleFailedLayout(isHorizontal, gSelection, lr, es, eb, swatchsData, availableWidth, availableHeight, titleVerticalShift, textFlow))) {
- self.alignTitleHorizontally(titleSelector);
- return;
- }
- }
- self.alignLabelsShapes(isHorizontal, eb, es, lr, swatchPadding);
- self.transformShapes(isHorizontal, es, lr, titleVerticalShift);
- self.alignSwatchLegendTitleHorizontally(isHorizontal, titleSelector, eb, lr);
- });
- },
- /** @expose */
- shape : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.shape$0();
- }
- return this.shape$1(a0);
- },
- /** @expose */
- swatchSize : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.swatchSize$0();
- }
- return this.swatchSize$1(a0);
- },
- /** @expose */
- wrapLabels : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.wrapLabels$0();
- }
- return this.wrapLabels$1(a0);
- },
- /** @expose */
- rows : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.rows$1();
- }
- return this.rows$0(a0);
- },
- /** @expose */
- columns : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.columns$1();
- }
- return this.columns$0(a0);
- },
- /** @expose */
- layoutMethod : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.layoutMethod$0();
- }
- return this.layoutMethod$1(a0);
- }
- });
- com_ibm_rave_ext_legend_swatch_SwatchLegend.createFontStruct = function(style) {
- var struct = new com_ibm_rave_ext_text_internal_wrap_FontStyleStruct();
- struct.fontStyle = style["font-style"];
- struct.fontVariant = style["font-variant"];
- struct.fontWeight = style["font-weight"];
- struct.fontSize = style["font-size"];
- struct.lineHeight = style["line-height"];
- struct.fontFamily = style["font-family"];
- return struct;
- };
- com_ibm_rave_ext_legend_swatch_SwatchLegend.LegendEntrySelectors = function(){};
- com_ibm_rave_ext_legend_swatch_SwatchLegend.LegendEntryBBoxes = function() {
- this.shapeBboxes = [];
- this.labelBboxes = [];
- this.labelTexts = [];
- };
- com_ibm_rave_ext_legend_swatch_SwatchLegend.ColumnRowLists = function() {
- this.columnListShapes = [];
- this.rowListShapes = [];
- };
- com_ibm_rave_ext_legend_swatch_SwatchLegend.LayoutResults = function(){};
- com_ibm_rave_ext_legend_swatch_SwatchLegend.GridDescr = function(numColumns, numRows, numColumnsUsed, numRowsUsed, firstFailureIndex, cellWidth, cellHeight, widthAvailableForTextPerColumn, heightAvailableForTextPerRow) {
- this.numColumns = numColumns;
- this.numRows = numRows;
- this.numColumnsUsed = numColumnsUsed;
- this.numRowsUsed = numRowsUsed;
- this.firstFailureIndex = firstFailureIndex;
- this.cellWidth = cellWidth;
- this.cellHeight = cellHeight;
- this.widthAvailableForTextPerColumn = widthAvailableForTextPerColumn;
- this.heightAvailableForTextPerRow = heightAvailableForTextPerRow;
- };
- com_ibm_rave_ext_legend_swatch_SwatchLegend.TextResult = function(entriesCount, noTruncation, gridDescr) {
- this.entriesCount = entriesCount;
- this.noTruncation = noTruncation;
- this.gridDescr = gridDescr;
- };
- com_ibm_rave_ext_legend_swatch_SwatchLegend.MIN_DATA_COUNT = 1;
- com_ibm_rave_ext_legend_swatch_SwatchLegend.TOLERANCE_PIXELS = 1;
- com_ibm_rave_ext_legend_swatch_SwatchLegend.MIN_ADJUSTED_NODE_COUNT = 2;
- //com_ibm_rave_ext_legend_swatch_SwatchLegend.DEFAULT_SHAPE = "square";
- //com_ibm_rave_ext_legend_swatch_SwatchLegend.PACKED = "packed";
- //com_ibm_rave_ext_legend_swatch_SwatchLegend.GRID = "grid";
- //com_ibm_rave_ext_legend_swatch_SwatchLegend.FONT_STYLE = "font-style";
- //com_ibm_rave_ext_legend_swatch_SwatchLegend.FONT_VARIANT = "font-variant";
- //com_ibm_rave_ext_legend_swatch_SwatchLegend.FONT_WEIGHT = "font-weight";
- //com_ibm_rave_ext_legend_swatch_SwatchLegend.FONT_SIZE = "font-size";
- //com_ibm_rave_ext_legend_swatch_SwatchLegend.LINE_HEIGHT = "line-height";
- //com_ibm_rave_ext_legend_swatch_SwatchLegend.FONT_FAMILY = "font-family";
- com_ibm_rave_ext_legend_swatch_SwatchLegend.DEFAULT_SWATCH_SIZE = 20.0 * 20.0;
- //com_ibm_rave_ext_legend_swatch_SwatchLegend.DEFAULT_LABEL_VALIGN = "middle";
- //com_ibm_rave_ext_legend_swatch_SwatchLegend.DEFAULT_LABEL_HALIGN = "start";
- com_ibm_rave_ext_legend_swatch_SwatchLegend._NULL_SETVALUE_FN = function(node) {};
- // $source: com/ibm/rave/ext/legend/continuous/ContinuousLegend
- /************************************************************************
- ** IBM Confidential
- **
- ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
- **
- ** (C) Copyright IBM Corp. 2017
- **
- ** The source code for this program is not published or otherwise divested of its trade secrets,
- ** irrespective of what has been deposited with the U.S. Copyright Office.
- ************************************************************************/
- // GENERATED
- //@import com/ibm/rave/ext/legend/AbstractLegend (loadtime) // superclass
- /**
- * A class that would generate and draw an axis-based legend
- */
- var com_ibm_rave_ext_legend_continuous_ContinuousLegend = rave['internal']['Declare'](com_ibm_rave_ext_legend_AbstractLegend, {
- //_method : null,
- //_shapeRectSize : null,
- _tickLen : 6.00,
- _startAt : 0.0,
- constructor : function() {
- this._method = "continuous";
- {
- this.minDataLen(2);
- }
- },
- /**
- * Sets which method to use to render this legend. Default value is continuous Possible values are: <ul> <li>axis</li> <li>stagger</li> <li>continuous</li> </ul>
- * @param (String) method the method used to draw this legend
- * @return (com.ibm.rave.ext.legend.continuous.ContinuousLegend) this legend instance.
- */
- method$0 : function(method) {
- if ("axis" == method || "stagger" == method || "continuous" == method) {
- this._method = method;
- } else {
- this._method = "continuous";
- }
- return this;
- },
- /**
- * Get the current method used to render this legend.
- * @return (String) method String.
- */
- method$1 : function() {
- return this._method;
- },
- /**
- * Specify the size (length) of the tick marks.
- * @param (Object) length The size of ticks
- * @return (com.ibm.rave.ext.legend.continuous.ContinuousLegend) this legend instance.
- */
- ticklength$0 : function(length) {
- this._tickLen = + (length);
- return this;
- },
- /**
- * Get the currently assigned tick length (in pixels). Default is 6.
- * @return (double) Tick length in pixels.
- */
- ticklength$1 : function() {
- return this._tickLen;
- },
- /**
- * Specify the starting point (in pixels) for the first tick of axis legend. This value is ignored for other legend methods (e.g., continuous and stagger)
- * @param (Object) startAt The starting point for the first tick for axis legend
- * @return (com.ibm.rave.ext.legend.continuous.ContinuousLegend) this legend instance.
- */
- startAt$0 : function(startAt) {
- this._startAt = + (startAt);
- return this;
- },
- /**
- * Get starting point (in pixels) for the first tick of axis legend. Default is 0.
- * @return (double) Tick length in pixels.
- */
- startAt$1 : function() {
- return this._startAt;
- },
- /**
- * Get the value of the width and height in pixels for the bounding box of legend rectangular shape. Applicable only to stagger and continuous legends since the axis legend sets its length to the last value of the scale's range
- * @return (Array) legend shape bounding box.
- */
- shapeRectSize$0 : function() {
- return this._shapeRectSize;
- },
- /**
- * Set the value of the width and height in pixels for the bounding box of legend rectangular shape. Applicable only to stagger and continuous legends. For stagger and continuous methods the values passed will be used for the bounding box of the colored rectangle regardless of the orientation. If the either of width or height value passed is a non-positive number (i.e., zero or a negative number) then the default calculation for the value of that dimension will be used. This allows client to set one dimension to a fixed value while leaving the other to be calculated dynamically. Default value for major dimension (width in case of horizontal orientation, height for vertical orientation), is the remaining length of the legends' relevant extent (as per its size/bounding box) after accounting for padding and the size occupied by the legend's title the size occupied by the legend's tick's length and label -if applicable. As for minor dimension (width in case of vertical orientation, height for horizontal orientation) it would be the lesser of 40 pixels or the remaining length of legends' relevant extent (as per its size/bounding box) after accounting for padding and the size occupied by the legend's title, the legend's tick's length and label -if applicable.
- * @param (Array) size The dimensions of legend's shape bounding box.
- * @return (com.ibm.rave.ext.legend.continuous.ContinuousLegend) this legend instance.
- */
- shapeRectSize$1 : function(size) {
- this._shapeRectSize = size;
- return this;
- },
- getOrientationValues : function(isHorizontal, digitBbox, tickPadding, availableWidth, availableHeight) {
- var shapeAvailableHeight;
- var shapeAvailableWidth;
- if (isHorizontal) {
- shapeAvailableHeight = availableHeight - (this._tickLen + tickPadding + digitBbox.height);
- shapeAvailableWidth = availableWidth - (digitBbox.width * 6);
- } else {
- shapeAvailableWidth = availableWidth - (this._tickLen + tickPadding + digitBbox.width * 6);
- shapeAvailableHeight = availableHeight - digitBbox.height;
- }
- var vals = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.OrientationValues();
- if (isHorizontal) {
- vals.shape_changing_coord2 = "x2";
- vals.shape_const_coord2 = "y2";
- vals.tick_len_coord1 = "y1";
- vals.tick_len_coord2 = "y2";
- vals.tick_place_coord1 = "x1";
- vals.tick_place_coord2 = "x2";
- vals.label_place_coord = "x";
- vals.label_shift_coord = "y";
- vals.label_anchor = "middle";
- vals.label_adjust_dy_value = ".7em";
- vals.shape_major_dimension = "width";
- vals.shape_minor_dimension = "height";
- if ((this._shapeRectSize)) {
- vals.shapeRectSize = [this._shapeRectSize[0], this._shapeRectSize[1]];
- if (vals.shapeRectSize[1] <= 0) {
- vals.shapeRectSize[1] = Math.min(shapeAvailableHeight, 40);
- }
- if (vals.shapeRectSize[0] <= 0) {
- vals.shapeRectSize[0] = shapeAvailableWidth;
- }
- } else {
- vals.shapeRectSize = [shapeAvailableWidth, Math.min(shapeAvailableHeight, 40)];
- }
- if ("axis" == this._method) {
- vals.shape_major_dimension_len = (this.scale().range()[this.scale().range().length - 1]);
- vals.shape_major_dimension_len += this._startAt;
- } else {
- vals.shape_major_dimension_len = vals.shapeRectSize[0];
- }
- vals.shape_minor_dimension_len = vals.shapeRectSize[1];
- vals.tickPlacementScaleRange = [0, vals.shape_major_dimension_len];
- } else {
- vals.shape_changing_coord2 = "y2";
- vals.shape_const_coord2 = "x2";
- vals.tick_len_coord1 = "x1";
- vals.tick_len_coord2 = "x2";
- vals.tick_place_coord1 = "y1";
- vals.tick_place_coord2 = "y2";
- vals.label_place_coord = "y";
- vals.label_shift_coord = "x";
- vals.label_anchor = "start";
- vals.label_adjust_dy_value = ".35em";
- vals.shape_major_dimension = "height";
- vals.shape_minor_dimension = "width";
- if ((this._shapeRectSize)) {
- vals.shapeRectSize = [this._shapeRectSize[0], this._shapeRectSize[1]];
- if (vals.shapeRectSize[1] <= 0) {
- vals.shapeRectSize[1] = shapeAvailableHeight;
- }
- if (vals.shapeRectSize[0] <= 0) {
- vals.shapeRectSize[0] = Math.min(shapeAvailableWidth, 40);
- }
- } else {
- vals.shapeRectSize = [Math.min(shapeAvailableWidth, 40), shapeAvailableHeight];
- }
- if ("axis" == this._method) {
- vals.shape_major_dimension_len = (this.scale().range()[this.scale().range().length - 1]);
- vals.shape_major_dimension_len += this._startAt;
- } else {
- vals.shape_major_dimension_len = vals.shapeRectSize[1];
- }
- vals.shape_minor_dimension_len = vals.shapeRectSize[0];
- vals.tickPlacementScaleRange = [vals.shape_major_dimension_len, 0];
- }
- vals.tickShift = ("axis" == this._method) ? 1 : vals.shape_minor_dimension_len;
- return vals;
- },
- getTickPlacementValues : function(isHorizontal, ticksData, ov) {
- var vals = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickPlacementValues();
- vals.extent = rave.extent(ticksData);
- if (this.reverse()) {
- vals.extent = [vals.extent[1], vals.extent[0]];
- }
- var horizontal = (this.reverse()) ? !isHorizontal : isHorizontal;
- var placementScale = rave.scale.linear().domain(vals.extent).range(ov.tickPlacementScaleRange);
- if ("axis" == this._method) {
- vals.ticksPlacementData = placementScale.ticks();
- var self = this;
- if (horizontal) {
- vals.tickPlacementValueFunction = function(data, index, groupIndex) {
- var val = self.scale().call(this, data, index, groupIndex);
- return val + self._startAt;
- };
- } else {
- vals.tickPlacementValueFunction = function(data, index, groupIndex) {
- var val = self.scale().call(this, data, index, groupIndex);
- return ov.shape_major_dimension_len - val - self._startAt;
- };
- }
- } else if ("stagger" == this._method) {
- var stagger_rect_major_dim_len;
- var numRects = ~~(ov.shape_major_dimension_len / 20.0);
- if (numRects < 2) {
- numRects = 1;
- stagger_rect_major_dim_len = ov.shape_major_dimension_len;
- vals.ticksPlacementData = vals.extent;
- } else {
- if (numRects > 15) {
- numRects = 15;
- }
- var extentStart = + (vals.extent[0]);
- var extentEnd = + (vals.extent[1]);
- var diff = extentEnd - extentStart;
- if (diff == 0) {
- stagger_rect_major_dim_len = ov.shape_major_dimension_len;
- vals.ticksPlacementData = [];
- } else {
- var step = diff / (numRects + 1);
- var ticks = rave.range(extentStart, extentEnd, step);
- this.fixTicksDecimalPlaces(ticks, 4);
- if (ticks[ticks.length - 1] != extentEnd) {
- ticks[ticks.length - 1] = extentEnd;
- }
- vals.ticksPlacementData = ticks;
- stagger_rect_major_dim_len = ov.shape_major_dimension_len / (ticks.length - 1);
- }
- }
- if (horizontal) {
- vals.tickPlacementValueFunction = function(data, index, groupIndex) {
- return stagger_rect_major_dim_len * index;
- };
- } else {
- vals.tickPlacementValueFunction = function(data, index, groupIndex) {
- return ov.shape_major_dimension_len - (stagger_rect_major_dim_len * index);
- };
- }
- } else {
- vals.tickPlacementValueFunction = placementScale;
- vals.ticksPlacementData = placementScale.ticks();
- }
- return vals;
- },
- fixTicksDecimalPlaces : function(ticks, numPlaces) {
- for (var i = 0; i < ticks.length; ++i) {
- var tickValue = ticks[i];
- tickValue = this.fixDecimalPlaces(tickValue, numPlaces);
- ticks[i] = tickValue;
- }
- },
- fixDecimalPlaces : function(val, numPlaces) {
- if (val == 0) {
- return 0;
- }
- var f = Math.pow(10, numPlaces);
- while ((~~(val * f)) == 0) {
- f *= 10;
- }
- return (~~(val * f)) / f;
- },
- getTickEntrySelectors : function(gSelection, labelFormat, tickColor, tickPadding, ov, tv) {
- var ts = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickEntrySelectors();
- ts.tickEntry = gSelection.selectAll(".legendEntry").data(tv.ticksPlacementData).enter().append("g").attr("class", "legendEntry");
- ts.tick = ts.tickEntry.append("line").attr("class", "legendTickLine").attr(ov.tick_len_coord1, ov.tickShift).attr(ov.tick_len_coord2, ov.tickShift + this._tickLen).attr(ov.tick_place_coord1, tv.tickPlacementValueFunction).attr(ov.tick_place_coord2, tv.tickPlacementValueFunction).style("stroke", tickColor);
- ts.text = ts.tickEntry.append("text").attr("class", "legendLabel").attr(ov.label_place_coord, tv.tickPlacementValueFunction).attr(ov.label_shift_coord, ov.tickShift + this._tickLen + tickPadding).attr("dy", ov.label_adjust_dy_value).attr("text-anchor", ov.label_anchor);
- if (typeof labelFormat === "function") {
- ts.text.text(labelFormat);
- } else {
- ts.text.text(labelFormat);
- }
- return ts;
- },
- updateTickEntrySelectors : function(gSelection) {
- var ts = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickEntrySelectors();
- ts.tickEntry = gSelection.selectAll(".legendEntry");
- ts.tick = gSelection.selectAll("." + "legendTickLine");
- ts.text = gSelection.selectAll("." + "legendLabel");
- return ts;
- },
- getTickEntryBBoxes : function(ts) {
- var tb = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickEntryBBoxes();
- ts.text.each(function(data, index, groupIndex) {
- var labelBbox = this.getBBox();
- if (labelBbox.width > tb.largestLabelWidth) {
- tb.largestLabelWidth = labelBbox.width;
- }
- if (labelBbox.height > tb.largestLabelHeight) {
- tb.largestLabelHeight = labelBbox.height;
- }
- tb.labelBboxes.push(labelBbox);
- tb.labelTexts.push(this.rave_getText());
- tb.labelBboxesPoints.push([+ (this.getAttribute("x")), + (this.getAttribute("y"))]);
- });
- ts.tick.each(function(data, index, groupIndex) {
- tb.tickBboxes.push(this.getBBox());
- });
- return tb;
- },
- getShapeSelectors : function(isHorizontal, gSelection, ov, tv, ticksData, axisColor, borderColor) {
- var ss = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.ShapeSelectors();
- if ("axis" == this._method) {
- ss.shapeSelector = gSelection.append("line").attr("class", "legendShape").attr("x1", 0).attr("y1", 0).attr(ov.shape_changing_coord2, ov.shape_major_dimension_len).attr(ov.shape_const_coord2, 0).style("stroke", axisColor);
- } else if ("stagger" == this._method) {
- var staggerRectData;
- if (tv.ticksPlacementData.length > 1) {
- staggerRectData = [];
- var tickValue = + (tv.ticksPlacementData[0]);
- for (var i = 1; i < tv.ticksPlacementData.length; ++i) {
- var nextTickValue = + (tv.ticksPlacementData[i]);
- staggerRectData[i - 1] = (tickValue + nextTickValue) / 2.0;
- tickValue = nextTickValue;
- }
- } else {
- staggerRectData = [+ (tv.ticksPlacementData[0])];
- }
- var colors = [];
- for (var i = 0; i < ticksData.length; ++i) {
- var color = this.scale().call(null, ticksData[i], -1, -1);
- colors.push(color);
- }
- var colorScale = this.scale().copy();
- colorScale.domain(ticksData);
- colorScale.range(colors);
- var staggerRectColor = [];
- if (isHorizontal) {
- for (var i = 0; i < staggerRectData.length; ++i) {
- staggerRectColor.push(colorScale.call(null, staggerRectData[i], -1, -1).toString());
- }
- } else {
- for (var i = staggerRectData.length - 1; i >= 0; --i) {
- staggerRectColor.push(colorScale.call(null, staggerRectData[i], -1, -1).toString());
- }
- }
- if (this.reverse()) {
- staggerRectColor.reverse();
- }
- var stagger_rect_major_dim_len = ov.shape_major_dimension_len / (staggerRectData.length);
- ss.shapeSelector = gSelection.selectAll(".legendShape").data(staggerRectData).enter().append("rect").attr("class", "legendShape").attr(ov.shape_major_dimension, stagger_rect_major_dim_len).attr(ov.shape_minor_dimension, ov.shape_minor_dimension_len).style("fill", function(data, index, groupIndex) {
- return staggerRectColor[index];
- }).attr(ov.label_place_coord, function(data, index, groupIndex) {
- return stagger_rect_major_dim_len * index;
- });
- if (borderColor != null) {
- ss.boundsSelector = gSelection.append("rect").attr("class", "legendStaggerBorder").attr(ov.shape_minor_dimension, ov.shape_minor_dimension_len).attr(ov.shape_major_dimension, ov.shape_major_dimension_len).style("fill-opacity", 0).attr("stroke", borderColor);
- }
- } else {
- var gradientIdCount = com_ibm_rave_ext_legend_continuous_ContinuousLegend.getGradientIdCount();
- var gradientID = "legendGradient" + gradientIdCount.idCount++;
- var gradient = gSelection.append("defs").append("linearGradient").attr("id", gradientID).attr("x1", "0%").attr("y1", "0%").attr(ov.shape_const_coord2, "0%").attr(ov.shape_changing_coord2, "100%").attr("spreadMethod", "pad");
- if (isHorizontal) {
- var stopsScale = rave.scale.linear().domain(tv.extent).range([0, 100]);
- for (var i = 0; i < ticksData.length; ++i) {
- var stop = stopsScale.call(null, ticksData[i], -1, -1);
- gradient.append("stop").attr("offset", stop + "%").attr("stop-color", this.scale().call(null, ticksData[i], -1, -1)).attr("stop-opacity", 1);
- }
- } else {
- var stopsScale = rave.scale.linear().domain(tv.extent).range([100, 0]);
- for (var i = ticksData.length - 1; i >= 0; --i) {
- var stop = stopsScale.call(null, ticksData[i], -1, -1);
- gradient.append("stop").attr("offset", stop + "%").attr("stop-color", this.scale().call(null, ticksData[i], -1, -1)).attr("stop-opacity", 1);
- }
- }
- ss.shapeSelector = gSelection.append("rect").attr("class", "legendShape").attr(ov.shape_minor_dimension, ov.shape_minor_dimension_len).attr(ov.shape_major_dimension, ov.shape_major_dimension_len);
- if (borderColor != null) {
- ss.shapeSelector.attr("stroke", borderColor);
- }
- ss.shapeSelector.style("fill", "url(#" + gradientID + ")");
- }
- return ss;
- },
- transformShapes : function(isHorizontal, tb, ov, ts, ss, titleSelector, titleVerticalShift) {
- var label_vertical_shift = 0;
- var label_horizontal_shift = 0;
- if (isHorizontal) {
- if ((tb.labelBboxes[0].width / 2.0) - tb.labelBboxesPoints[0][0] > 0) {
- label_horizontal_shift = tb.labelBboxes[0].width / 2.0;
- }
- } else {
- if ((tb.labelBboxes[tb.labelBboxes.length - 1].height / 2.0) - tb.labelBboxesPoints[tb.labelBboxesPoints.length - 1][1] > 0) {
- label_vertical_shift = tb.labelBboxes[tb.labelBboxes.length - 1].height / 2.0;
- }
- }
- var horizontal_shift = (this.entryInsets()["left"] + this.insets()["left"] + label_horizontal_shift);
- var vertical_shift = (titleVerticalShift - this.insets()["bottom"] + label_vertical_shift + this.entryInsets()["top"]);
- var transformStr = "translate(" + (horizontal_shift) + "," + (vertical_shift) + ")";
- if ((ss.boundsSelector)) {
- ss.boundsSelector.attr("transform", transformStr);
- }
- ss.shapeSelector.attr("transform", transformStr);
- ts.tickEntry.attr("transform", transformStr);
- this.alignContinuousLegendTitleHorizontally(isHorizontal, horizontal_shift, ov, titleSelector);
- },
- alignContinuousLegendTitleHorizontally : function(isHorizontal, horizontal_shift, ov, titleSelector) {
- if (titleSelector) {
- var titleBbox = titleSelector.node().getBBox();
- var legendProperWidth = (isHorizontal) ? ov.shape_major_dimension_len : ov.shape_minor_dimension_len;
- var title_horizontal_shift = horizontal_shift;
- if ("start" == this.titleAlignment()) {
- title_horizontal_shift = 0;
- } else if ("end" == this.titleAlignment()) {
- title_horizontal_shift += (titleBbox.width > legendProperWidth) ? (this.titleInsets()["right"] + this.insets()["right"]) : 0;
- } else {
- title_horizontal_shift *= 2;
- title_horizontal_shift -= this.insets()["left"];
- }
- legendProperWidth += title_horizontal_shift;
- var w = Math.max(titleBbox.width, legendProperWidth);
- this.alignTitleHorizontally(titleSelector, w);
- }
- },
- cleanUpTextFlowSettings : function(text, ov) {
- text.selectAll("tspan").attr("x", null).attr("dy", null).attr("width", null);
- text.attr("dy", ov.label_adjust_dy_value).attr("text-anchor", ov.label_anchor);
- },
- getLegendProperDim : function(isHorizontal, ov, tb, tickPadding) {
- var legend_shape_width;
- var legend_shape_height;
- if (isHorizontal) {
- legend_shape_width = ov.shape_major_dimension_len;
- if ((tb.labelBboxes[0].width / 2.0) + tb.labelBboxesPoints[0][0] >= ov.shape_major_dimension_len) {
- legend_shape_width += tb.labelBboxes[0].width / 2.0;
- }
- if ((tb.labelBboxes[tb.labelBboxes.length - 1].width / 2.0) + tb.labelBboxesPoints[tb.labelBboxesPoints.length - 1][0] >= ov.shape_major_dimension_len) {
- legend_shape_width += tb.labelBboxes[tb.labelBboxes.length - 1].width / 2.0;
- }
- legend_shape_height = ov.tickShift + tb.largestLabelHeight + +this._tickLen + tickPadding;
- } else {
- legend_shape_height = ov.shape_major_dimension_len;
- if ((tb.labelBboxes[0].height / 2.0) + tb.labelBboxesPoints[0][1] >= ov.shape_major_dimension_len) {
- legend_shape_height += tb.labelBboxes[0].height / 2.0;
- }
- if ((tb.labelBboxes[tb.labelBboxes.length - 1].height / 2.0) + tb.labelBboxesPoints[tb.labelBboxesPoints.length - 1][1] >= ov.shape_major_dimension_len) {
- legend_shape_height += tb.labelBboxes[tb.labelBboxes.length - 1].height / 2.0;
- }
- legend_shape_width = ov.tickShift + tb.largestLabelWidth + this._tickLen + tickPadding;
- }
- return [legend_shape_width, legend_shape_height];
- },
- verifyResults : function(gSelection, titleSelector, titleVerticalShift, isHorizontal, tickPadding, ov, tb, ts, ss, availableWidth, availableHeight, textFlow) {
- var _tb = tb;
- var _ts = ts;
- var legendDim = this.getLegendProperDim(isHorizontal, ov, _tb, tickPadding);
- var entryInsets = this.entryInsets();
- if (isHorizontal) {
- this._spaceUsed += legendDim[1] + (entryInsets["top"] + entryInsets["bottom"]);
- } else {
- if (legendDim[0] > this._spaceUsed) {
- this._spaceUsed = legendDim[0] + (entryInsets["left"] + entryInsets["right"]);
- }
- }
- if (legendDim[0] > availableWidth || legendDim[1] > availableHeight) {
- if (legendDim[0] > availableWidth) {
- textFlow.wrap(false);
- if (isHorizontal) {
- var extraWidth = Math.ceil(legendDim[0] - availableWidth) * 2;
- if ((_tb.labelBboxes[0].width / 2.0) + _tb.labelBboxesPoints[0][0] >= ov.shape_major_dimension_len) {
- var halfFirstlabel = _tb.labelBboxes[0].width / 2.0;
- var halfLastLabel = 0;
- if ((_tb.labelBboxes[_tb.labelBboxes.length - 1].width / 2.0) + _tb.labelBboxesPoints[_tb.labelBboxesPoints.length - 1][0] > ov.shape_major_dimension_len) {
- halfLastLabel = _tb.labelBboxes[_tb.labelBboxes.length - 1].width / 2.0;
- }
- var firstLabelRatio = halfFirstlabel / (halfFirstlabel + halfLastLabel);
- var firstLabelReduction = Math.ceil(firstLabelRatio * extraWidth);
- var firstLabelSelection = rave.select(_ts.text.node());
- textFlow.extent(~~(_tb.labelBboxes[0].width - firstLabelReduction), ~~_tb.largestLabelHeight);
- textFlow.flow(firstLabelSelection);
- this.cleanUpTextFlowSettings(firstLabelSelection, ov);
- if (extraWidth - firstLabelReduction > 0) {
- var lastLabelReduction = Math.ceil(extraWidth - firstLabelReduction);
- var lastLabelSelection = rave.select(_ts.text[0][_ts.text.size() - 1]);
- textFlow.extent(~~(_tb.labelBboxes[_tb.labelBboxes.length - 1].width - lastLabelReduction), ~~_tb.largestLabelHeight);
- textFlow.flow(lastLabelSelection);
- this.cleanUpTextFlowSettings(lastLabelSelection, ov);
- }
- }
- } else {
- var truncationWidth = _tb.largestLabelWidth - (legendDim[0] - availableWidth);
- textFlow.extent(~~truncationWidth, ~~_tb.largestLabelHeight);
- textFlow.flow(_ts.text);
- this.cleanUpTextFlowSettings(_ts.text, ov);
- }
- this.transformShapes(isHorizontal, _tb, ov, _ts, ss, titleSelector, titleVerticalShift);
- _tb = this.getTickEntryBBoxes(_ts);
- legendDim = this.getLegendProperDim(isHorizontal, ov, _tb, tickPadding);
- }
- if (legendDim[0] > availableWidth || legendDim[1] > availableHeight) {
- this.alignTitleHorizontally(titleSelector);
- _ts.tickEntry.remove();
- ss.shapeSelector.remove();
- if (ss.boundsSelector) {
- ss.boundsSelector.remove();
- }
- this.addTruncationIndicator(gSelection, titleVerticalShift, availableWidth, availableHeight, textFlow);
- return false;
- } else {
- _ts = this.updateTickEntrySelectors(gSelection);
- _tb = this.getTickEntryBBoxes(_ts);
- this.transformShapes(isHorizontal, _tb, ov, _ts, ss, titleSelector, titleVerticalShift);
- }
- }
- return true;
- },
- /** @expose */
- getDataFromScale : function() {
- if (!this.scale()) {
- return null;
- }
- return this.scale().domain();
- },
- /**
- * Draws or redraws this legend into the specified selection of elements. The legend may be drawn into multiple elements simultaneously, but note that these legends would share the same backing data; typically, a legend is drawn into only one element at a time. This function will create its own subgroup and draw the legend into that, if that group exists already then all it will be removed with all its children and added anew.
- * @param (rave['internal']['Selector']) g a selection that holds the elements into which the legend is drawn. Typically a group element.
- */
- /** @expose */
- legend : function(g) {
- var self = this;
- g.each(function(data, index, groupIndex) {
- self._spaceUsed = 0;
- var gSelection = self.prepareLegendGroup(this);
- self.prepareLegendBounds(gSelection);
- var labelFormat = self.getLabelFormat();
- var textFlow = self.createTextFlowComponent();
- var titleSelector = self.prepareLegendTitle(gSelection, textFlow);
- if (titleSelector && !titleSelector.node().rave_getParentNode()) {
- return;
- }
- var titleVerticalShift = self.calculateTitleVerticalShift(titleSelector);
- var tickPadding = + (self.labelPadding());
- var isHorizontal = "horizontal" == self.orient();
- var availableWidth = self.size()[0] - self.insets()["left"] - self.insets()["right"] - self.entryInsets()["left"] - self.entryInsets()["right"];
- var availableHeight = self.size()[1] - titleVerticalShift - self.entryInsets()["top"] - self.entryInsets()["bottom"];
- if (availableHeight <= 0 || availableWidth <= 0) {
- self.alignTitleHorizontally(titleSelector);
- return;
- }
- if (!((self.scale()))) {
- self.alignTitleHorizontally(titleSelector);
- return;
- }
- var ticksData = self.getData();
- if (!ticksData) {
- self.alignTitleHorizontally(titleSelector);
- return;
- }
- ticksData = self.sanitizeData(ticksData);
- var digitBbox = self.getSingleDigitBbox(gSelection);
- var ov = self.getOrientationValues(isHorizontal, digitBbox, tickPadding, availableWidth, availableHeight);
- var tickColor = "black";
- var axisColor = "black";
- var borderColor = null;
- if ((self.shapeBorderColor())) {
- borderColor = rave.rgb(self.shapeBorderColor()).toString();
- tickColor = borderColor;
- axisColor = borderColor;
- }
- var tv = self.getTickPlacementValues(isHorizontal, ticksData, ov);
- if (!tv.ticksPlacementData || tv.ticksPlacementData.length == 0) {
- self.alignTitleHorizontally(titleSelector);
- return;
- }
- var ts = self.getTickEntrySelectors(gSelection, labelFormat, tickColor, tickPadding, ov, tv);
- var tb = self.getTickEntryBBoxes(ts);
- if (tb.labelBboxes.length == 0) {
- self.alignTitleHorizontally(titleSelector);
- return;
- }
- var ss = self.getShapeSelectors(isHorizontal, gSelection, ov, tv, ticksData, axisColor, borderColor);
- self.transformShapes(isHorizontal, tb, ov, ts, ss, titleSelector, titleVerticalShift);
- self.handleCollidingLabels(ts);
- ts = self.updateTickEntrySelectors(gSelection);
- tb = self.getTickEntryBBoxes(ts);
- self.verifyResults(gSelection, titleSelector, titleVerticalShift, isHorizontal, tickPadding, ov, tb, ts, ss, availableWidth, availableHeight, textFlow);
- self.createSwatchExtraEntries(gSelection, self.size()[0], self.size()[1], self.getLegendProperDim(isHorizontal, ov, tb, tickPadding)[0], self.getLegendProperDim(isHorizontal, ov, tb, tickPadding)[1], availableWidth, availableHeight, self.insets(), titleVerticalShift);
- });
- },
- getSingleDigitBbox : function(gSelection) {
- var selector = gSelection.append("text").text("0");
- var digitBbox = selector.node().getBBox();
- selector.remove();
- return digitBbox;
- },
- sanitizeData : function(ticksData) {
- if (this.dataValues()) {
- var hasInvalidValues = false;
- var domainExtent = rave.extent(this.scale().domain());
- var minVal = + (domainExtent[0]);
- var maxVal = + (domainExtent[1]);
- var newData = [];
- for (var i = 0; i < ticksData.length; ++i) {
- var val = + (ticksData[i]);
- if (val > maxVal || val < minVal) {
- hasInvalidValues = true;
- continue;
- }
- newData.push(val);
- }
- if (newData.length > 0) {
- return newData;
- } else if (hasInvalidValues) {
- return this.scale().domain();
- }
- }
- return ticksData;
- },
- handleCollidingLabels : function(ts) {
- var ravePosition = rave.capabilities.extension("position");
- var dropOverlap = ravePosition.drop();
- dropOverlap.remove(true).dropOverlap(ts.text);
- },
- createSwatchExtraEntries : function(gSelection, overallWidth, overallHeight, legendWidth, legendHeight, availableWidth, availableHeight, insets, verticalTitleShift) {
- var self = this;
- var extraLegendRect;
- if (self.orient() == "vertical") {
- extraLegendRect = new rave['internal']['RectStruct'](((insets["left"] * 2) + legendWidth), (overallHeight - availableHeight), (availableWidth - legendWidth), (legendHeight));
- } else {
- extraLegendRect = new rave['internal']['RectStruct']((overallWidth - availableWidth), ((insets["top"] * 2) + legendHeight + verticalTitleShift), legendWidth, (availableHeight - legendHeight));
- }
- if (!(self._extraLegendEntries.empty())) {
- var swatchData = [];
- for (var __i_enFor0 = 0, __exp_enFor0 = self._extraLegendEntries.keys(), __len_enFor0 = __exp_enFor0.length;
- __i_enFor0 < __len_enFor0; ++__i_enFor0) {
- var key = __exp_enFor0[__i_enFor0];
- swatchData.push(key);
- }
- var rl = rave.capabilities.extension("legend");
- var swatchLegend = rl.swatch().size([extraLegendRect.width, extraLegendRect.height]).orient(self.orient()).scale(rave.scale.category20b().domain((swatchData)));
- for (var i = 0; i < self._extraLegendEntries.size(); ++i) {
- var ele = swatchLegend.extraEntry(self._extraLegendEntries.keys()[i]);
- if ((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).colorSet()) {
- ele.color((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).color());
- }
- if ((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).sizeSet()) {
- ele.size((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).size());
- }
- if ((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).shapeSet()) {
- ele.shape((self._extraLegendEntries.get(self._extraLegendEntries.keys()[i])).shape());
- }
- }
- var swatchLegendSelector = gSelection.append("g").attr("class", "extraLegend").attr("transform", "translate(" + extraLegendRect.x + "," + extraLegendRect.y + ")").attr("width", extraLegendRect.width).attr("height", extraLegendRect.height).call(swatchLegend);
- if (swatchLegendSelector.selectAll(".legendEntry").size() == 0) {
- gSelection.selectAll(".extraLegend").remove();
- }
- }
- },
- /** @expose */
- method : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.method$1();
- }
- return this.method$0(a0);
- },
- /** @expose */
- ticklength : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.ticklength$1();
- }
- return this.ticklength$0(a0);
- },
- /** @expose */
- startAt : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.startAt$1();
- }
- return this.startAt$0(a0);
- },
- /** @expose */
- shapeRectSize : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.shapeRectSize$0();
- }
- return this.shapeRectSize$1(a0);
- }
- });
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.getGradientIdCount = function() {
- var gradientIdCount = rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().getData("GRADIENT_ID_COUNT_KEY");
- if (!gradientIdCount) {
- gradientIdCount = new com_ibm_rave_ext_legend_continuous_ContinuousLegend.GradientIdCount();
- rave['internal']['RaveContextManager'].INSTANCE.getRaveContext().putData("GRADIENT_ID_COUNT_KEY", gradientIdCount);
- }
- return gradientIdCount;
- };
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.OrientationValues = function(){};
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickPlacementValues = function(){};
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickEntrySelectors = function(){};
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.TickEntryBBoxes = function() {
- this.largestLabelWidth = 0;
- this.largestLabelHeight = 0;
- this.tickBboxes = [];
- this.labelBboxes = [];
- this.labelTexts = [];
- this.labelBboxesPoints = [];
- };
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.ShapeSelectors = function(){};
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.GradientIdCount = rave['internal']['Declare']({
- idCount : 0
- });
- //com_ibm_rave_ext_legend_continuous_ContinuousLegend.AXIS_METHOD = "axis";
- //com_ibm_rave_ext_legend_continuous_ContinuousLegend.STAGGER_METHOD = "stagger";
- //com_ibm_rave_ext_legend_continuous_ContinuousLegend.CONTINUOUS_METHOD = "continuous";
- //com_ibm_rave_ext_legend_continuous_ContinuousLegend.AXIS_DEFAULT_COLOR = "black";
- //com_ibm_rave_ext_legend_continuous_ContinuousLegend.GRADIENT_ID = "legendGradient";
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.AXIS_DEFAULT_MINOR_DIMENSION_LEN = 1;
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.MAX_TICK_LABEL_DIGITS = 6;
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.MINOR_SHAPE_MAX_LENGTH = 40;
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.MIN_DATA_COUNT = 2;
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.DEFAULT_STAGGER_RECT_SIDE_LEN = 20.0;
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.MAX_STAGGER_SQUARE_COUNT = 15;
- com_ibm_rave_ext_legend_continuous_ContinuousLegend.PREFERRED_DECIMAL_PLACES_COUNT = 4;
- //com_ibm_rave_ext_legend_continuous_ContinuousLegend.GRADIENT_ID_COUNT_KEY = "GRADIENT_ID_COUNT_KEY";
- //com_ibm_rave_ext_legend_continuous_ContinuousLegend.DEFAULT_METHOD = "continuous";
- // $source: com/ibm/rave/ext/legend/size/NestedSizeLegend
- /************************************************************************
- ** IBM Confidential
- **
- ** IBM Business Analytics: Rapidly Adaptive Visualization Engine
- **
- ** (C) Copyright IBM Corp. 2017
- **
- ** The source code for this program is not published or otherwise divested of its trade secrets,
- ** irrespective of what has been deposited with the U.S. Copyright Office.
- ************************************************************************/
- // GENERATED
- //@import com/ibm/rave/ext/legend/AbstractLegend (loadtime) // superclass
- /**
- * A nested size legend displays a set of shapes representing a range of sizes. Each shape is displayed with a corresponding value label, representing the size which would appear for in a visualization for that particular value. Note that this size legend assumes size values are given as <em>area</em> (in pixels), not diameter, width/height, etc. This is consistent with the Rave.svg.symbol generator, which accepts area values when generating shapes.
- */
- var com_ibm_rave_ext_legend_size_NestedSizeLegend = rave['internal']['Declare'](com_ibm_rave_ext_legend_AbstractLegend, {
- //_shapeDisplay : null,
- //_defs : null,
- //_clipId : null,
- _tickPadding : 20.0,
- constructor : function() {
- this._shapeDisplay = "full";
- {
- this.scaleArguments(3);
- }
- },
- /** @expose */
- legend : function(g) {
- var self = this;
- g.each(function(data, index, groupIndex) {
- var gSelection = self.prepareLegendGroup(this);
- self.prepareLegendBounds(gSelection);
- var labelFormat = self.getLabelFormat();
- var textFlow = self.createTextFlowComponent();
- var titleSelector = self.prepareLegendTitle(gSelection, textFlow);
- if (titleSelector && !titleSelector.node().rave_getParentNode()) {
- return;
- }
- var titleVerticalShift = self.calculateTitleVerticalShift(titleSelector);
- var availableWidth = self.size()[0] - self.insets()["left"] - self.insets()["right"];
- var availableHeight = self.size()[1] - self.insets()["top"] - self.insets()["bottom"] - titleVerticalShift;
- self.alignTitleHorizontally(titleSelector);
- if (availableHeight <= 0 || availableWidth <= 0 || !((self.scale()))) {
- return;
- }
- var scaleData = self.getData();
- if (!scaleData) {
- return;
- }
- var ticks = (scaleData).reverse();
- var maxArea = + (self.scale().call(null, ticks[0], 0, 0));
- var minArea = + (self.scale().call(null, ticks[ticks.length - 1], 0, 0));
- var maxSymbolHeight = 2 * com_ibm_rave_ext_legend_size_NestedSizeLegend.areaToCircleRadius(Math.max(maxArea, minArea));
- var symbol = rave.svg.symbol().type("circle").size(function(data, index, groupIndex) {
- return + (self.scale().call(null, data, 0, 0));
- });
- var container = new rave['internal']['RectStruct'](self.insets()["left"], self.insets()["top"] + titleVerticalShift, availableWidth, availableHeight);
- var entryBounds = new rave['internal']['RectStruct'](container.x + self.entryInsets()["left"], container.y + self.entryInsets()["top"], container.width - self.entryInsets()["left"] - self.entryInsets()["right"], container.height - self.entryInsets()["top"] - self.entryInsets()["bottom"]);
- var entryShiftX = 0;
- if ("full" == self._shapeDisplay) {
- entryShiftX = entryShiftX + (maxSymbolHeight / 2.0);
- }
- var legendContainer = gSelection.append("g").classed("legendContainer", true).attr("clip-path", self._clipId != null ? "url(#" + self._clipId + ")" : null);
- if (self._defs && self._clipId != null) {
- var clipPath = self._defs.selectAll("#" + self._clipId).data([0]);
- clipPath.enter().append("clipPath").attr("id", self._clipId).append("rect");
- clipPath.select("rect").attr("x", entryBounds.x).attr("width", entryBounds.width).attr("y", titleVerticalShift).attr("height", availableHeight);
- }
- var transformEntry = function(data, index, groupIndex) {
- var x = com_ibm_rave_ext_legend_size_NestedSizeLegend.areaToCircleRadius(+ (self.scale().call(null, data, 0, 0)));
- return "translate(0, " + (maxSymbolHeight - x) + ")";
- };
- var transformCenterEntry = function(data, index, groupIndex) {
- var x = 2 * com_ibm_rave_ext_legend_size_NestedSizeLegend.areaToCircleRadius(+ (self.scale().call(null, data, 0, 0)));
- return "translate(0, " + (maxSymbolHeight - x) + ")";
- };
- var legendEntries = legendContainer.selectAll(".legendEntry").data(ticks);
- var legendEntriesEnter = legendEntries.enter().append("g").classed("legendEntry", true);
- legendEntriesEnter.append("path").classed("legendShape", true);
- legendEntriesEnter.append("line").classed("legendTickLine", true);
- legendEntriesEnter.append("text").classed("legendLabel", true);
- legendEntries.attr("transform", "translate(" + (entryBounds.x + entryShiftX) + "," + entryBounds.y + ")");
- legendEntries.select(".legendShape").attr("d", symbol).attr("transform", transformEntry).style("stroke", (self.shapeBorderColor()) ? rave.rgb(self.shapeBorderColor()).toString() : null);
- legendEntries.select(".legendTickLine").attr("x1", 0).attr("x2", maxSymbolHeight / 2 + self._tickPadding).attr("transform", transformCenterEntry);
- var labelX = maxSymbolHeight / 2 + + (self.labelPadding()) + self._tickPadding;
- var label = legendEntries.select(".legendLabel");
- label.attr("x", labelX).attr("transform", transformCenterEntry).attr("dy", function(data, index, groupIndex) {
- return self.getTextDyPlacement(this);
- }).text(labelFormat);
- textFlow.extent(~~ (Math.max(0, entryBounds.width - labelX - entryShiftX)), ~~ (label.node().getBBox().height)).flow(label);
- });
- },
- /**
- * Tick padding controls the distance between the largest legend symbol (i.e. circle) and the symbol labels. This has the effect of controlling the length of the line connecting each legend symbol to it's label.
- * @param (double) padding Distance (in pixels) between the largest symbol's perimeter and labels.
- * @return (com.ibm.rave.ext.legend.size.NestedSizeLegend) This legend component.
- */
- tickPadding$0 : function(padding) {
- this._tickPadding = Math.max(0.0, padding);
- return this;
- },
- /**
- * Retrieve current tick padding value. Default is 20.
- */
- tickPadding$1 : function() {
- return this._tickPadding;
- },
- /**
- * Shapes can be displayed in "full" or "half". <em>Full</em> (the default) will center the shapes such that its left-most extent appears inside the left-most bounds of the legend. <em>Half</em> will center the shapes at the left-most boundary of the legend; such that a clipping rectangle can be used to visually cut the shapes in half. When using the "half" method, it is recommended to add a clip path, to prevent the legend elements from overflowing outside the bounds of the legend. See {@link #this.clip(rave['internal']['Selector'], String)} .
- * @param (String) display Can be "full" or "half". Defaults to "full" when an invalid value is entered.
- * @return (com.ibm.rave.ext.legend.size.NestedSizeLegend) This NestedSizeLegend component.
- */
- shapeDisplay$0 : function(display) {
- this._shapeDisplay = "half" == display ? display : "full";
- return this;
- },
- /**
- * Retrieve current shape display method. Default is "full".
- */
- shapeDisplay$1 : function() {
- return this._shapeDisplay;
- },
- /**
- * A clip path can be applied automatically to hide any legend elements from overlapping the legend bounds. Both a <defs> element and a unique ID must be supplied in order for the clip path to be generated.
- * @param (rave['internal']['Selector']) defs A selector into which a <clippath> element will be added.
- * @param (String) id An id unique to the entire document containing the legend.
- * @return (com.ibm.rave.ext.legend.size.NestedSizeLegend) This NestedSizeLegend component.
- */
- /** @expose */
- clip : function(defs, id) {
- this._defs = defs;
- this._clipId = id;
- return this;
- },
- /** @expose */
- tickPadding : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.tickPadding$1();
- }
- return this.tickPadding$0(a0);
- },
- /** @expose */
- shapeDisplay : function(a0) {
- var args = arguments;
- if (args.length == 0) {
- return this.shapeDisplay$1();
- }
- return this.shapeDisplay$0(a0);
- }
- });
- com_ibm_rave_ext_legend_size_NestedSizeLegend.areaToCircleRadius = function(area) {
- return Math.sqrt(area / Math.PI);
- };
- com_ibm_rave_ext_legend_size_NestedSizeLegend.SHAPE_SYMBOL_TYPE = "circle";
- com_ibm_rave_ext_legend_size_NestedSizeLegend.SHAPE_DISPLAY_FULL = "full";
- com_ibm_rave_ext_legend_size_NestedSizeLegend.SHAPE_DISPLAY_HALF = "half";
- com_ibm_rave_ext_legend_size_NestedSizeLegend.TICK_PADDING_DEFAULT = 20.0;
- })();
- // This is the end of the factory method defined in the header. Added only during a full compiled JS build.
- return rave;
- }));
|