Dashboard sipadu mbip
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918
  1. AUI.add('aui-drawing-base', function(A) {
  2. var Lang = A.Lang,
  3. isArray = Lang.isArray,
  4. isFunction = Lang.isFunction,
  5. isNumber = Lang.isNumber,
  6. isObject = Lang.isObject,
  7. isString = Lang.isString,
  8. isUndefined = Lang.isUndefined,
  9. DOC = A.config.doc,
  10. ColorUtil = A.ColorUtil,
  11. Util,
  12. UA = A.UA,
  13. EMPTY_FN = Lang.emptyFn,
  14. MAP_ATTRS_AVAILABLE = {
  15. blur: 0,
  16. 'clip-rect': '0 0 1e9 1e9',
  17. cursor: 'default',
  18. cx: 0,
  19. cy: 0,
  20. fill: '#fff',
  21. 'fill-opacity': 1,
  22. font: '10px "Arial"',
  23. 'font-family': '"Arial"',
  24. 'font-size': '10',
  25. 'font-style': 'normal',
  26. 'font-weight': 400,
  27. gradient: 0,
  28. height: 0,
  29. href: 'http://alloy.liferay.com/',
  30. opacity: 1,
  31. path: 'M0,0',
  32. r: 0,
  33. rotation: 0,
  34. rx: 0,
  35. ry: 0,
  36. scale: '1 1',
  37. src: '',
  38. stroke: '#000',
  39. 'stroke-dasharray': '',
  40. 'stroke-linecap': 'butt',
  41. 'stroke-linejoin': 'butt',
  42. 'stroke-miterlimit': 0,
  43. 'stroke-opacity': 1,
  44. 'stroke-width': 1,
  45. target: '_blank',
  46. 'text-anchor': 'middle',
  47. title: 'AlloyUI',
  48. translation: '0 0',
  49. width: 0,
  50. x: 0,
  51. y: 0
  52. },
  53. MAP_COMMAND_SVG_QUADRATIC = {
  54. Q: 1,
  55. T: 1
  56. },
  57. MAP_ELEMENTS = {
  58. circle: 1,
  59. ellipse: 1,
  60. image: 1,
  61. path: 1,
  62. rect: 1,
  63. text: 1
  64. },
  65. MAP_TYPES_IMAGE_TEXT = {
  66. image:1,
  67. text: 1
  68. },
  69. MAP_TYPES_CIRCLE_ELLIPSE = {
  70. circle: 1,
  71. ellipse: 1
  72. },
  73. MATH = Math,
  74. MATH_MAX = MATH.max,
  75. MATH_MIN = MATH.min,
  76. MATH_POW = MATH.pow,
  77. NAME = 'drawing',
  78. REGEX_GRADIENT_VALUES = /^([^:]*):?([\d\.]*)/,
  79. REGEX_ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
  80. REGEX_PATH_COMMAND = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?\s*,?\s*)+)/ig,
  81. REGEX_PATH_TO_STRING = /,?([achlmqrstvxz]),?/gi,
  82. REGEX_PATH_VALUES = /(-?\d*\.?\d*(?:e[-+]?\d+)?)\s*,?\s*/ig,
  83. REGEX_RADIAL_GRADIENT = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/,
  84. REGEX_SEPARATOR = /[, ]+/,
  85. REGEX_SEPARATOR_GRADIENT = /\s*\-\s*/,
  86. STR_EMPTY = '',
  87. STR_FILL = 'fill',
  88. STR_MS_PROG_ID_PREFIX = ' progid:DXImageTransform.Microsoft',
  89. STR_SPACE = ' ',
  90. TO_LOWER_CASE = String.prototype.toLowerCase,
  91. TO_UPPER_CASE = String.prototype.toUpperCase;
  92. var Drawing = A.Component.create(
  93. {
  94. ATTRS: {
  95. height: {
  96. value: 342
  97. },
  98. width: {
  99. value: 512
  100. },
  101. x: {
  102. value: null
  103. },
  104. y: {
  105. value: null
  106. }
  107. },
  108. UI_ATTRS: ['x', 'y'],
  109. create: function(config) {
  110. var args = arguments;
  111. var firstArg = args[0];
  112. if (isArray(firstArg)) {
  113. args = args[0];
  114. config = Util.getConfig(args);
  115. var paper = new Drawing(config).render();
  116. var set = paper.createSet();
  117. var element;
  118. for (var i = 0, length = args.length; i < length; i++) {
  119. element = args[i] || {};
  120. if (MAP_ELEMENTS.hasOwnProperty(element.type)) {
  121. set.push(
  122. paper[element.type]().attr(element)
  123. );
  124. }
  125. }
  126. return paper;
  127. }
  128. else if (isObject(firstArg) && !(firstArg.nodeName || firstArg instanceof A.Node)) {
  129. config = firstArg;
  130. }
  131. else {
  132. config = Util.getConfig(args);
  133. }
  134. return new Drawing(config).render();
  135. },
  136. NAME: NAME,
  137. prototype: {
  138. CONTENT_TEMPLATE: null,
  139. renderUI: function() {
  140. var instance = this;
  141. instance.customAttributes = {};
  142. Drawing.Impl.createCanvas.call(instance);
  143. },
  144. circle: function(x, y, r) {
  145. var instance = this;
  146. return Drawing.Impl.createCircle.call(instance, x || 0, y || 0, r || 0);
  147. },
  148. clear: function() {
  149. var instance = this;
  150. return Drawing.Impl.clear.call(instance);
  151. },
  152. createSet: function(itemsArray) {
  153. var instance = this;
  154. if (arguments.length > 1) {
  155. itemsArray = Array.prototype.splice.call(arguments, 0, arguments.length);
  156. }
  157. return new Set(itemsArray);
  158. },
  159. ellipse: function(x, y, rx, ry) {
  160. var instance = this;
  161. return Drawing.Impl.createEllipse.call(instance, x || 0, y || 0, rx || 0, ry || 0);
  162. },
  163. image: function(src, x, y, w, h) {
  164. var instance = this;
  165. return Drawing.Impl.createImage.call(instance, src || 'about:blank', x || 0, y || 0, w || 0, h || 0);
  166. },
  167. path: function(pathString) {
  168. var instance = this;
  169. if (isString(pathString)) {
  170. pathString = Lang.sub.apply(A, arguments);
  171. }
  172. else if (!isUndefined(pathString) && !isArray(pathString)) {
  173. pathString += STR_EMPTY;
  174. }
  175. return Drawing.Impl.createPath.call(instance, pathString);
  176. },
  177. rect: function(x, y, w, h, r) {
  178. var instance = this;
  179. return Drawing.Impl.createRectangle.call(instance, x || 0, y || 0, w || 0, h || 0, r || 0);
  180. },
  181. remove: function() {
  182. var instance = this;
  183. return Drawing.Impl.remove.call(instance);
  184. },
  185. safari: EMPTY_FN,
  186. text: function(x, y, text) {
  187. var instance = this;
  188. return Drawing.Impl.createText.call(instance, x || 0, y || 0, text || STR_EMPTY);
  189. },
  190. _uiSetX: function(value) {
  191. var instance = this;
  192. instance.get('boundingBox').setXY([value, instance.get('y')]);
  193. },
  194. _uiSetY: function(value) {
  195. var instance = this;
  196. instance.get('boundingBox').setXY([instance.get('x'), value]);
  197. }
  198. }
  199. }
  200. );
  201. Util = {
  202. getConfig: function(args) {
  203. var config = {};
  204. var firstArg = args[0];
  205. var firstConfigArg = 'boundingBox';
  206. var indexHeight = 2;
  207. var indexWidth = 1;
  208. var indexY = -1;
  209. if (isNumber(firstArg)) {
  210. firstConfigArg = 'x';
  211. indexHeight = 3;
  212. indexWidth = 2;
  213. indexY = 1;
  214. }
  215. config[firstConfigArg] = firstArg;
  216. config.height = args[indexHeight];
  217. config.width = args[indexWidth];
  218. config.y = args[indexY];
  219. return config;
  220. },
  221. translate: function(x, y) {
  222. if (x == null) {
  223. return {
  224. x: this._.tx,
  225. y: this._.ty,
  226. toString: Util.XYToString
  227. };
  228. }
  229. this._.tx += +x;
  230. this._.ty += +y;
  231. switch (this.type) {
  232. case 'circle':
  233. case 'ellipse':
  234. this.attr(
  235. {
  236. cx: +x + this.attrs.cx,
  237. cy: +y + this.attrs.cy
  238. }
  239. );
  240. break;
  241. case 'rect':
  242. case 'image':
  243. case 'text':
  244. this.attr(
  245. {
  246. x: +x + this.attrs.x,
  247. y: +y + this.attrs.y
  248. }
  249. );
  250. break;
  251. case 'path':
  252. var path = Util.pathToRelative(this.attrs.path);
  253. path[0][1] += +x;
  254. path[0][2] += +y;
  255. this.attr(
  256. {
  257. path: path
  258. }
  259. );
  260. break;
  261. }
  262. return this;
  263. }
  264. };
  265. Drawing.getColor = function(value) {
  266. var start = Drawing.getColor.start = Drawing.getColor.start || {
  267. h: 0,
  268. s: 1,
  269. b: value || 0.75
  270. };
  271. var rgb = ColorUtil.hsb2rgb(start.h, start.s, start.b);
  272. start.h += 0.075;
  273. if (start.h > 1) {
  274. start.h = 0;
  275. start.s -= 0.2;
  276. if (start.s <= 0) {
  277. Drawing.getColor.start = {
  278. h: 0,
  279. s: 1,
  280. b: start.b
  281. }
  282. }
  283. }
  284. return rgb.hex;
  285. };
  286. Drawing.getColor.reset = function() {
  287. delete Drawing.start;
  288. };
  289. Util.tear = function(el, drawing) {
  290. el == drawing.top && (drawing.top = el.prev);
  291. el == drawing.bottom && (drawing.bottom = el.next);
  292. el.next && (el.next.prev = el.prev);
  293. el.prev && (el.prev.next = el.next);
  294. };
  295. Util.toFront = function(el, drawing) {
  296. if (drawing.top === el) {
  297. return;
  298. }
  299. Util.tear(el, drawing);
  300. el.next = null;
  301. el.prev = drawing.top;
  302. drawing.top.next = el;
  303. drawing.top = el;
  304. };
  305. Util.toBack = function(el, drawing) {
  306. if (drawing.bottom === el) {
  307. return;
  308. }
  309. Util.tear(el, drawing);
  310. el.next = drawing.bottom;
  311. el.prev = null;
  312. drawing.bottom.prev = el;
  313. drawing.bottom = el;
  314. };
  315. Util.insertAfter = function(el, el2, drawing) {
  316. Util.tear(el, drawing);
  317. el2 == drawing.top && (drawing.top = el);
  318. el2.next && (el2.next.prev = el);
  319. el.next = el2.next;
  320. el.prev = el2;
  321. el2.next = el;
  322. };
  323. Util.insertBefore = function(el, el2, drawing) {
  324. Util.tear(el, drawing);
  325. el2 == drawing.bottom && (drawing.bottom = el);
  326. el2.prev && (el2.prev.next = el);
  327. el.prev = el2.prev;
  328. el2.prev = el;
  329. el.next = el2;
  330. };
  331. var Element = function(node, drawing) {
  332. var instance = this;
  333. instance.createElement.apply(instance, arguments);
  334. };
  335. Util.removed = function(methodname) {
  336. return function() {
  337. throw new Error('AlloyUI: you are calling to method "' + methodname + '" of removed object');
  338. };
  339. };
  340. Util._path2string = function() {
  341. return this.join(',').replace(REGEX_PATH_TO_STRING, '$1');
  342. };
  343. Util.parsePathString = A.cached(
  344. function(pathString) {
  345. if (!pathString) {
  346. return null;
  347. }
  348. var paramCounts = {
  349. a: 7,
  350. c: 6,
  351. h: 1,
  352. l: 2,
  353. m: 2,
  354. q: 4,
  355. s: 4,
  356. t: 2,
  357. v: 1,
  358. z: 0
  359. };
  360. var data = [];
  361. if (isArray(pathString) && isArray(pathString[0])) { // rough assumption
  362. data = pathClone(pathString);
  363. }
  364. if (!data.length) {
  365. String(pathString).replace(REGEX_PATH_COMMAND, function(a, b, c) {
  366. var params = [];
  367. var name = TO_LOWER_CASE.call(b);
  368. c.replace(
  369. REGEX_PATH_VALUES,
  370. function(a, b) {
  371. b && params.push(+b);
  372. }
  373. );
  374. if (name == 'm' && params.length > 2) {
  375. data.push([b].concat(params.splice(0, 2)));
  376. name = 'l';
  377. b = b == 'm' ? 'l' : 'L';
  378. }
  379. while (params.length >= paramCounts[name]) {
  380. data.push([b].concat(params.splice(0, paramCounts[name])));
  381. if (!paramCounts[name]) {
  382. break;
  383. }
  384. }
  385. });
  386. }
  387. data.toString = Util._path2string;
  388. return data;
  389. }
  390. );
  391. Util.findDotsAtSegment = function(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  392. var t1 = 1 - t;
  393. var x = MATH_POW(t1, 3) * p1x + MATH_POW(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + MATH_POW(t, 3) * p2x;
  394. var y = MATH_POW(t1, 3) * p1y + MATH_POW(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + MATH_POW(t, 3) * p2y;
  395. var mx = p1x + 2 * t * (c1x - p1x) + t * t * (c2x - 2 * c1x + p1x);
  396. var my = p1y + 2 * t * (c1y - p1y) + t * t * (c2y - 2 * c1y + p1y);
  397. var nx = c1x + 2 * t * (c2x - c1x) + t * t * (p2x - 2 * c2x + c1x);
  398. var ny = c1y + 2 * t * (c2y - c1y) + t * t * (p2y - 2 * c2y + c1y);
  399. var ax = (1 - t) * p1x + t * c1x;
  400. var ay = (1 - t) * p1y + t * c1y;
  401. var cx = (1 - t) * c2x + t * p2x;
  402. var cy = (1 - t) * c2y + t * p2y;
  403. var alpha = (90 - MATH.atan((mx - nx) / (my - ny)) * 180 / MATH.PI);
  404. if (mx > nx || my < ny) {
  405. alpha += 180;
  406. }
  407. return {
  408. x: x,
  409. y: y,
  410. m: {
  411. x: mx,
  412. y: my
  413. },
  414. n: {
  415. x: nx,
  416. y: ny
  417. },
  418. start: {
  419. x: ax,
  420. y: ay
  421. },
  422. end: {
  423. x: cx,
  424. y: cy
  425. },
  426. alpha: alpha
  427. };
  428. };
  429. Util.pathDimensions = A.cached(
  430. function(path) {
  431. if (!path) {
  432. return {x: 0, y: 0, width: 0, height: 0};
  433. }
  434. path = Util.path2curve(path);
  435. var x = 0;
  436. var y = 0;
  437. var X = [];
  438. var Y = [];
  439. var p;
  440. for (var i = 0, length = path.length; i < length; i++) {
  441. p = path[i];
  442. if (p[0] == "M") {
  443. x = p[1];
  444. y = p[2];
  445. X.push(x);
  446. Y.push(y);
  447. }
  448. else {
  449. var dim = Util.curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  450. X = X.concat(dim.min.x, dim.max.x);
  451. Y = Y.concat(dim.min.y, dim.max.y);
  452. x = p[5];
  453. y = p[6];
  454. }
  455. }
  456. var xmin = MATH_MIN.apply(0, X);
  457. var ymin = MATH_MIN.apply(0, Y);
  458. return {
  459. x: xmin,
  460. y: ymin,
  461. width: MATH_MAX.apply(0, X) - xmin,
  462. height: MATH_MAX.apply(0, Y) - ymin
  463. };
  464. }
  465. );
  466. Util.pathClone = function(pathArray) {
  467. var res = [];
  468. if (!isArray(pathArray) || !isArray(pathArray && pathArray[0])) { // rough assumption
  469. pathArray = Util.parsePathString(pathArray);
  470. }
  471. for (var i = 0, length = pathArray.length; i < length; i++) {
  472. res[i] = [];
  473. for (var j = 0, jLength = pathArray[i].length; j < jLength; j++) {
  474. res[i][j] = pathArray[i][j];
  475. }
  476. }
  477. res.toString = Util._path2string;
  478. return res;
  479. };
  480. Util._pathToRelative = A.cached(
  481. function(pathArray) {
  482. if (!isArray(pathArray) || !isArray(pathArray && pathArray[0])) { // rough assumption
  483. pathArray = Util.parsePathString(pathArray);
  484. }
  485. var res = [];
  486. var x = 0;
  487. var y = 0;
  488. var mx = 0;
  489. var my = 0;
  490. var start = 0;
  491. if (pathArray[0][0] == 'M') {
  492. x = pathArray[0][1];
  493. y = pathArray[0][2];
  494. mx = x;
  495. my = y;
  496. start++;
  497. res.push(['M', x, y]);
  498. }
  499. for (var i = start, length = pathArray.length; i < length; i++) {
  500. var r = res[i] = [];
  501. var pa = pathArray[i];
  502. if (pa[0] != TO_LOWER_CASE.call(pa[0])) {
  503. r[0] = TO_LOWER_CASE.call(pa[0]);
  504. switch (r[0]) {
  505. case 'a':
  506. r[1] = pa[1];
  507. r[2] = pa[2];
  508. r[3] = pa[3];
  509. r[4] = pa[4];
  510. r[5] = pa[5];
  511. r[6] = +(pa[6] - x).toFixed(3);
  512. r[7] = +(pa[7] - y).toFixed(3);
  513. break;
  514. case 'v':
  515. r[1] = +(pa[1] - y).toFixed(3);
  516. break;
  517. case 'm':
  518. mx = pa[1];
  519. my = pa[2];
  520. default:
  521. for (var j = 1, jLength = pa.length; j < jLength; j++) {
  522. r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3);
  523. }
  524. }
  525. }
  526. else {
  527. r = res[i] = [];
  528. if (pa[0] == 'm') {
  529. mx = pa[1] + x;
  530. my = pa[2] + y;
  531. }
  532. for (var k = 0, kLength = pa.length; k < kLength; k++) {
  533. res[i][k] = pa[k];
  534. }
  535. }
  536. var len = res[i].length;
  537. switch (res[i][0]) {
  538. case 'z':
  539. x = mx;
  540. y = my;
  541. break;
  542. case 'h':
  543. x += +res[i][len - 1];
  544. break;
  545. case 'v':
  546. y += +res[i][len - 1];
  547. break;
  548. default:
  549. x += +res[i][len - 2];
  550. y += +res[i][len - 1];
  551. }
  552. }
  553. res.toString = Util._path2string;
  554. return res;
  555. }
  556. );
  557. Util.pathToRelative = function(pathArray) {
  558. return Util.pathClone(Util._pathToRelative(pathArray));
  559. };
  560. Util._pathToAbsolute = A.cached(
  561. function(pathArray) {
  562. if (!isArray(pathArray) || !isArray(pathArray && pathArray[0])) { // rough assumption
  563. pathArray = Util.parsePathString(pathArray);
  564. }
  565. var res = [];
  566. var x = 0;
  567. var y = 0;
  568. var mx = 0;
  569. var my = 0;
  570. var start = 0;
  571. if (pathArray[0][0] == 'M') {
  572. x = +pathArray[0][1];
  573. y = +pathArray[0][2];
  574. mx = x;
  575. my = y;
  576. start++;
  577. res[0] = ['M', x, y];
  578. }
  579. for (var i = start, length = pathArray.length; i < length; i++) {
  580. var r = res[i] = [];
  581. var pa = pathArray[i];
  582. if (pa[0] != TO_UPPER_CASE.call(pa[0])) {
  583. r[0] = TO_UPPER_CASE.call(pa[0]);
  584. switch (r[0]) {
  585. case 'A':
  586. r[1] = pa[1];
  587. r[2] = pa[2];
  588. r[3] = pa[3];
  589. r[4] = pa[4];
  590. r[5] = pa[5];
  591. r[6] = +(pa[6] + x);
  592. r[7] = +(pa[7] + y);
  593. break;
  594. case 'V':
  595. r[1] = +pa[1] + y;
  596. break;
  597. case 'H':
  598. r[1] = +pa[1] + x;
  599. break;
  600. case 'M':
  601. mx = +pa[1] + x;
  602. my = +pa[2] + y;
  603. default:
  604. for (var j = 1, jLength = pa.length; j < jLength; j++) {
  605. r[j] = +pa[j] + ((j % 2) ? x : y);
  606. }
  607. }
  608. }
  609. else {
  610. for (var k = 0, kLength = pa.length; k < kLength; k++) {
  611. res[i][k] = pa[k];
  612. }
  613. }
  614. switch (r[0]) {
  615. case 'Z':
  616. x = mx;
  617. y = my;
  618. break;
  619. case 'H':
  620. x = r[1];
  621. break;
  622. case 'V':
  623. y = r[1];
  624. break;
  625. case 'M':
  626. mx = res[i][res[i].length - 2];
  627. my = res[i][res[i].length - 1];
  628. default:
  629. x = res[i][res[i].length - 2];
  630. y = res[i][res[i].length - 1];
  631. }
  632. }
  633. res.toString = Util._path2string;
  634. return res;
  635. }
  636. );
  637. Util.pathToAbsolute = function(pathArray) {
  638. return Util.pathClone(Util._pathToAbsolute(pathArray));
  639. };
  640. Util.lineToCubicCurve = function(x1, y1, x2, y2) {
  641. return [x1, y1, x2, y2, x2, y2];
  642. };
  643. Util.quadraticToCubicCurve = function(x1, y1, ax, ay, x2, y2) {
  644. var _13 = 1 / 3;
  645. var _23 = 2 / 3;
  646. return [
  647. _13 * x1 + _23 * ax,
  648. _13 * y1 + _23 * ay,
  649. _13 * x2 + _23 * ax,
  650. _13 * y2 + _23 * ay,
  651. x2,
  652. y2
  653. ];
  654. };
  655. Util.arcToCubicCurve = function(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
  656. // for more information of where this math came from visit:
  657. // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
  658. var PI = MATH.PI;
  659. var _120 = PI * 120 / 180;
  660. var rad = PI / 180 * (+angle || 0);
  661. var res = [];
  662. var xy;
  663. var rotate = A.cached(
  664. function(x, y, rad) {
  665. var X = x * MATH.cos(rad) - y * MATH.sin(rad),
  666. Y = x * MATH.sin(rad) + y * MATH.cos(rad);
  667. return {x: X, y: Y};
  668. }
  669. );
  670. if (!recursive) {
  671. xy = rotate(x1, y1, -rad);
  672. x1 = xy.x;
  673. y1 = xy.y;
  674. xy = rotate(x2, y2, -rad);
  675. x2 = xy.x;
  676. y2 = xy.y;
  677. var cos = MATH.cos(PI / 180 * angle);
  678. var sin = MATH.sin(PI / 180 * angle);
  679. var x = (x1 - x2) / 2;
  680. var y = (y1 - y2) / 2;
  681. var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
  682. if (h > 1) {
  683. h = MATH.sqrt(h);
  684. rx = h * rx;
  685. ry = h * ry;
  686. }
  687. var rx2 = rx * rx;
  688. var ry2 = ry * ry;
  689. var k = (large_arc_flag == sweep_flag ? -1 : 1) *
  690. MATH.sqrt(MATH.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)));
  691. var cx = k * rx * y / ry + (x1 + x2) / 2;
  692. var cy = k * -ry * x / rx + (y1 + y2) / 2;
  693. var f1 = MATH.asin(((y1 - cy) / ry).toFixed(7));
  694. var f2 = MATH.asin(((y2 - cy) / ry).toFixed(7));
  695. f1 = x1 < cx ? PI - f1 : f1;
  696. f2 = x2 < cx ? PI - f2 : f2;
  697. f1 < 0 && (f1 = PI * 2 + f1);
  698. f2 < 0 && (f2 = PI * 2 + f2);
  699. if (sweep_flag && f1 > f2) {
  700. f1 = f1 - PI * 2;
  701. }
  702. if (!sweep_flag && f2 > f1) {
  703. f2 = f2 - PI * 2;
  704. }
  705. }
  706. else {
  707. f1 = recursive[0];
  708. f2 = recursive[1];
  709. cx = recursive[2];
  710. cy = recursive[3];
  711. }
  712. var df = f2 - f1;
  713. if (MATH.abs(df) > _120) {
  714. var f2old = f2;
  715. var x2old = x2;
  716. var y2old = y2;
  717. f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
  718. x2 = cx + rx * MATH.cos(f2);
  719. y2 = cy + ry * MATH.sin(f2);
  720. res = Util.arcToCubicCurve(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
  721. }
  722. df = f2 - f1;
  723. var c1 = MATH.cos(f1);
  724. var s1 = MATH.sin(f1);
  725. var c2 = MATH.cos(f2);
  726. var s2 = MATH.sin(f2);
  727. var t = MATH.tan(df / 4);
  728. var hx = 4 / 3 * rx * t;
  729. var hy = 4 / 3 * ry * t;
  730. var m1 = [x1, y1];
  731. var m2 = [x1 + hx * s1, y1 - hy * c1];
  732. var m3 = [x2 + hx * s2, y2 - hy * c2];
  733. var m4 = [x2, y2];
  734. m2[0] = 2 * m1[0] - m2[0];
  735. m2[1] = 2 * m1[1] - m2[1];
  736. if (recursive) {
  737. return [m2, m3, m4].concat(res);
  738. }
  739. else {
  740. res = [m2, m3, m4].concat(res).join().split(',');
  741. var newres = [];
  742. for (var i = 0, length = res.length; i < length; i++) {
  743. newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
  744. }
  745. return newres;
  746. }
  747. };
  748. Util.findDotAtSegment = function(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  749. var t1 = 1 - t;
  750. return {
  751. x: MATH_POW(t1, 3) * p1x + MATH_POW(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + MATH_POW(t, 3) * p2x,
  752. y: MATH_POW(t1, 3) * p1y + MATH_POW(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + MATH_POW(t, 3) * p2y
  753. };
  754. };
  755. Util.curveDim = A.cached(
  756. function(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) {
  757. var a = (c2x - 2 * c1x + p1x) - (p2x - 2 * c2x + c1x);
  758. var b = 2 * (c1x - p1x) - 2 * (c2x - c1x);
  759. var c = p1x - c1x;
  760. var t1 = (-b + MATH.sqrt(b * b - 4 * a * c)) / 2 / a;
  761. var t2 = (-b - MATH.sqrt(b * b - 4 * a * c)) / 2 / a;
  762. var y = [p1y, p2y];
  763. var x = [p1x, p2x];
  764. var dot;
  765. MATH.abs(t1) > 1e12 && (t1 = 0.5);
  766. MATH.abs(t2) > 1e12 && (t2 = 0.5);
  767. if (t1 > 0 && t1 < 1) {
  768. dot = Util.findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  769. x.push(dot.x);
  770. y.push(dot.y);
  771. }
  772. if (t2 > 0 && t2 < 1) {
  773. dot = Util.findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  774. x.push(dot.x);
  775. y.push(dot.y);
  776. }
  777. a = (c2y - 2 * c1y + p1y) - (p2y - 2 * c2y + c1y);
  778. b = 2 * (c1y - p1y) - 2 * (c2y - c1y);
  779. c = p1y - c1y;
  780. t1 = (-b + MATH.sqrt(b * b - 4 * a * c)) / 2 / a;
  781. t2 = (-b - MATH.sqrt(b * b - 4 * a * c)) / 2 / a;
  782. MATH.abs(t1) > 1e12 && (t1 = 0.5);
  783. MATH.abs(t2) > 1e12 && (t2 = 0.5);
  784. if (t1 > 0 && t1 < 1) {
  785. dot = Util.findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t1);
  786. x.push(dot.x);
  787. y.push(dot.y);
  788. }
  789. if (t2 > 0 && t2 < 1) {
  790. dot = Util.findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t2);
  791. x.push(dot.x);
  792. y.push(dot.y);
  793. }
  794. return {
  795. min: {
  796. x: MATH_MIN.apply(0, x),
  797. y: MATH_MIN.apply(0, y)
  798. },
  799. max: {
  800. x: MATH_MAX.apply(0, x),
  801. y: MATH_MAX.apply(0, y)
  802. }
  803. };
  804. }
  805. );
  806. Util._path2curve = A.cached(
  807. function(path, path2) {
  808. var p = Util.pathToAbsolute(path);
  809. var p2 = path2 && Util.pathToAbsolute(path2);
  810. var attrs = {
  811. x: 0,
  812. y: 0,
  813. bx: 0,
  814. by: 0,
  815. X: 0,
  816. Y: 0,
  817. qx: null,
  818. qy: null
  819. };
  820. var attrs2 = {
  821. x: 0,
  822. y: 0,
  823. bx: 0,
  824. by: 0,
  825. X: 0,
  826. Y: 0,
  827. qx: null,
  828. qy: null
  829. };
  830. var processPath = function(path, d) {
  831. var nx;
  832. var ny;
  833. if (!path) {
  834. return ['C', d.x, d.y, d.x, d.y, d.x, d.y];
  835. }
  836. if (!(path[0] in MAP_COMMAND_SVG_QUADRATIC)) {
  837. d.qx = d.qy = null
  838. }
  839. switch (path[0]) {
  840. case 'M':
  841. d.X = path[1];
  842. d.Y = path[2];
  843. break;
  844. case 'A':
  845. path = ['C'].concat(Util.arcToCubicCurve.apply(0, [d.x, d.y].concat(path.slice(1))));
  846. break;
  847. case 'S':
  848. nx = d.x + (d.x - (d.bx || d.x));
  849. ny = d.y + (d.y - (d.by || d.y));
  850. path = ['C', nx, ny].concat(path.slice(1));
  851. break;
  852. case 'T':
  853. d.qx = d.x + (d.x - (d.qx || d.x));
  854. d.qy = d.y + (d.y - (d.qy || d.y));
  855. path = ['C'].concat(Util.quadraticToCubicCurve(d.x, d.y, d.qx, d.qy, path[1], path[2]));
  856. break;
  857. case 'Q':
  858. d.qx = path[1];
  859. d.qy = path[2];
  860. path = ['C'].concat(Util.quadraticToCubicCurve(d.x, d.y, path[1], path[2], path[3], path[4]));
  861. break;
  862. case 'L':
  863. path = ['C'].concat(Util.lineToCubicCurve(d.x, d.y, path[1], path[2]));
  864. break;
  865. case 'H':
  866. path = ['C'].concat(Util.lineToCubicCurve(d.x, d.y, path[1], d.y));
  867. break;
  868. case 'V':
  869. path = ['C'].concat(Util.lineToCubicCurve(d.x, d.y, d.x, path[1]));
  870. break;
  871. case 'Z':
  872. path = ['C'].concat(Util.lineToCubicCurve(d.x, d.y, d.X, d.Y));
  873. break;
  874. }
  875. return path;
  876. };
  877. var fixArc = function(pp, i) {
  878. if (pp[i].length > 7) {
  879. pp[i].shift();
  880. var pi = pp[i];
  881. while (pi.length) {
  882. pp.splice(i++, 0, ['C'].concat(pi.splice(0, 6)));
  883. }
  884. pp.splice(i, 1);
  885. length = MATH_MAX(p.length, p2 && p2.length || 0);
  886. }
  887. };
  888. var fixM = function(path1, path2, a1, a2, i) {
  889. if (path1 && path2 && path1[i][0] == 'M' && path2[i][0] != 'M') {
  890. path2.splice(i, 0, ['M', a2.x, a2.y]);
  891. a1.bx = 0;
  892. a1.by = 0;
  893. a1.x = path1[i][1];
  894. a1.y = path1[i][2];
  895. length = MATH_MAX(p.length, p2 && p2.length || 0);
  896. }
  897. };
  898. for (var i = 0, length = MATH_MAX(p.length, p2 && p2.length || 0); i < length; i++) {
  899. p[i] = processPath(p[i], attrs);
  900. fixArc(p, i);
  901. p2 && (p2[i] = processPath(p2[i], attrs2));
  902. p2 && fixArc(p2, i);
  903. fixM(p, p2, attrs, attrs2, i);
  904. fixM(p2, p, attrs2, attrs, i);
  905. var seg = p[i];
  906. var seg2 = p2 && p2[i];
  907. var seglen = seg.length;
  908. var seg2len = p2 && seg2.length;
  909. attrs.x = seg[seglen - 2];
  910. attrs.y = seg[seglen - 1];
  911. attrs.bx = parseFloat(seg[seglen - 4]) || attrs.x;
  912. attrs.by = parseFloat(seg[seglen - 3]) || attrs.y;
  913. attrs2.bx = p2 && (parseFloat(seg2[seg2len - 4]) || attrs2.x);
  914. attrs2.by = p2 && (parseFloat(seg2[seg2len - 3]) || attrs2.y);
  915. attrs2.x = p2 && seg2[seg2len - 2];
  916. attrs2.y = p2 && seg2[seg2len - 1];
  917. }
  918. return p2 ? [p, p2] : p;
  919. }
  920. );
  921. Util.path2curve = function(path1, path2) {
  922. return Util.pathClone(Util._path2curve(path1, path2));
  923. };
  924. Util.parseDots = A.cached(
  925. function(gradient) {
  926. var dots = [];
  927. for (var i = 0, length = gradient.length; i < length; i++) {
  928. var dot = {};
  929. var par = gradient[i].match(REGEX_GRADIENT_VALUES);
  930. dot.color = ColorUtil.getRGB(par[1]);
  931. if (dot.color.error) {
  932. return null;
  933. }
  934. dot.color = dot.color.hex;
  935. par[2] && (dot.offset = par[2] + '%');
  936. dots.push(dot);
  937. }
  938. for (i = 1, length = dots.length - 1; i < length; i++) {
  939. if (!dots[i].offset) {
  940. var start = parseFloat(dots[i - 1].offset || 0);
  941. var end = 0;
  942. for (var j = i + 1; j < length; j++) {
  943. if (dots[j].offset) {
  944. end = dots[j].offset;
  945. break;
  946. }
  947. }
  948. if (!end) {
  949. end = 100;
  950. j = length;
  951. }
  952. end = parseFloat(end);
  953. var d = (end - start) / (j - i + 1);
  954. for (; i < j; i++) {
  955. start += d;
  956. dots[i].offset = start + '%';
  957. }
  958. }
  959. }
  960. return dots;
  961. }
  962. );
  963. Util.XYToString = function() {
  964. return this.x + STR_SPACE + this.y;
  965. };
  966. Util.getPointAtSegmentLength = A.cached(
  967. function(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
  968. var len = 0;
  969. var old;
  970. for (var i = 0; i < 1.01; i+=.01) {
  971. var dot = Util.findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i);
  972. i && (len += MATH_POW(MATH_POW(old.x - dot.x, 2) + MATH_POW(old.y - dot.y, 2), 0.5));
  973. if (len >= length) {
  974. return dot;
  975. }
  976. old = dot;
  977. }
  978. }
  979. );
  980. var curvesLengths = {};
  981. Util.getPointAtSegmentLength = function(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) {
  982. var len = 0;
  983. var precision = 100;
  984. var name = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y].join();
  985. var cache = curvesLengths[name];
  986. var old;
  987. var dot;
  988. if (!cache) {
  989. cache = {
  990. data: []
  991. };
  992. curvesLengths[name] = cache;
  993. }
  994. if (cache.timer) {
  995. clearTimeout(cache.timer);
  996. }
  997. cache.timer = setTimeout(
  998. function() {
  999. delete curvesLengths[name];
  1000. },
  1001. 2000
  1002. );
  1003. if (length != null) {
  1004. var total = getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y);
  1005. precision = ~~total * 10;
  1006. }
  1007. for (var i = 0; i < precision + 1; i++) {
  1008. if (cache.data[length] > i) {
  1009. dot = cache.data[i * precision];
  1010. }
  1011. else {
  1012. dot = Util.findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, i / precision);
  1013. cache.data[i] = dot;
  1014. }
  1015. if (i) {
  1016. len += MATH_POW(MATH_POW(old.x - dot.x, 2) + MATH_POW(old.y - dot.y, 2), 0.5);
  1017. }
  1018. if (length != null && len >= length) {
  1019. return dot;
  1020. }
  1021. if (length == null) {
  1022. return len;
  1023. }
  1024. }
  1025. };
  1026. Util.getLengthFactory = function(istotal, subpath) {
  1027. return function(path, length, onlystart) {
  1028. path = Util.path2curve(path);
  1029. var x;
  1030. var y;
  1031. var p;
  1032. var l;
  1033. var sp = '';
  1034. var subpaths = {};
  1035. var point;
  1036. var len = 0;
  1037. for (var i = 0, length = path.length; i < length; i++) {
  1038. p = path[i];
  1039. if (p[0] == 'M') {
  1040. x = +p[1];
  1041. y = +p[2];
  1042. }
  1043. else {
  1044. l = Util.getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]);
  1045. if (len + l > length) {
  1046. if (subpath && !subpaths.start) {
  1047. point = Util.getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  1048. sp += [
  1049. 'C',
  1050. point.start.x,
  1051. point.start.y,
  1052. point.m.x,
  1053. point.m.y,
  1054. point.x,
  1055. point.y
  1056. ];
  1057. if (onlystart) {
  1058. return sp;
  1059. }
  1060. subpaths.start = sp;
  1061. sp = [
  1062. 'M',
  1063. point.x,
  1064. point.y + 'C',
  1065. point.n.x,
  1066. point.n.y,
  1067. point.end.x,
  1068. point.end.y,
  1069. p[5],
  1070. p[6]
  1071. ].join();
  1072. len += l;
  1073. x = +p[5];
  1074. y = +p[6];
  1075. continue;
  1076. }
  1077. if (!istotal && !subpath) {
  1078. point = Util.getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len);
  1079. return {
  1080. x: point.x,
  1081. y: point.y,
  1082. alpha: point.alpha
  1083. };
  1084. }
  1085. }
  1086. len += l;
  1087. x = +p[5];
  1088. y = +p[6];
  1089. }
  1090. sp += p;
  1091. }
  1092. subpaths.end = sp;
  1093. point = istotal ? len : subpath ? subpaths : Util.findDotsAtSegment(x, y, p[1], p[2], p[3], p[4], p[5], p[6], 1);
  1094. point.alpha && (point = {
  1095. x: point.x,
  1096. y: point.y,
  1097. alpha: point.alpha
  1098. });
  1099. return point;
  1100. };
  1101. };
  1102. Util.getTotalLength = Util.getLengthFactory(1);
  1103. Util.getPointAtLength = Util.getLengthFactory();
  1104. Util.getSubpathsAtLength = Util.getLengthFactory(0, 1);
  1105. Util.applyAttributes = function(element, name, value) {
  1106. var params;
  1107. if (value != null) {
  1108. params = {};
  1109. params[name] = value;
  1110. }
  1111. else if (name != null && isObject(name)) {
  1112. params = name;
  1113. }
  1114. var customAttributes = element.paper.customAttributes;
  1115. for (var key in customAttributes) {
  1116. if (
  1117. customAttributes.hasOwnProperty(key) &&
  1118. params.hasOwnProperty(key) &&
  1119. isFunction(customAttributes[key])
  1120. ) {
  1121. var subParams = customAttributes[key].apply(element, [].concat(params[key]));
  1122. element.attrs[key] = params[key];
  1123. for (var subKey in subParams) {
  1124. if (subParams.hasOwnProperty(subKey)) {
  1125. params[subKey] = subParams[subKey];
  1126. }
  1127. }
  1128. }
  1129. }
  1130. return params;
  1131. };
  1132. Element.prototype = {
  1133. attr: EMPTY_FN,
  1134. blur: EMPTY_FN,
  1135. clone: function() {
  1136. if (this.removed) {
  1137. return null;
  1138. }
  1139. var attr = this.attr();
  1140. delete attr.scale;
  1141. delete attr.translation;
  1142. return this.paper[this.type]().attr(attr);
  1143. },
  1144. createElement: EMPTY_FN,
  1145. detach: function(type, fn) {
  1146. var instance = this;
  1147. A.detach(Element._getEventType(type), fn, (instance.shape || instance.node || DOC));
  1148. return instance;
  1149. },
  1150. getRegion: EMPTY_FN,
  1151. getPointAtLength: function(length) {
  1152. if (this.type != 'path') {
  1153. return;
  1154. }
  1155. return Util.getPointAtLength(this.attrs.path, length);
  1156. },
  1157. getSubpath: function(from, to) {
  1158. if (this.type != 'path') {
  1159. return;
  1160. }
  1161. if (MATH.abs(this.getTotalLength() - to) < '1e-6') {
  1162. return Util.getSubpathsAtLength(this.attrs.path, from).end;
  1163. }
  1164. var a = Util.getSubpathsAtLength(this.attrs.path, to, 1);
  1165. return from ? Util.getSubpathsAtLength(a, from).end : a;
  1166. },
  1167. getTotalLength: function() {
  1168. if (this.type != 'path') {
  1169. return;
  1170. }
  1171. if (this.node.getTotalLength) {
  1172. return this.node.getTotalLength();
  1173. }
  1174. return Util.getTotalLength(this.attrs.path);
  1175. },
  1176. hide: EMPTY_FN,
  1177. hover: function(overFn, outFn) {
  1178. return this.on('mouseover', overFn).on('mouseout', outFn);
  1179. },
  1180. insertAfter: EMPTY_FN,
  1181. insertBefore: EMPTY_FN,
  1182. on: function(type, fn, context) {
  1183. var instance = this;
  1184. var realType = Element._getEventType(type);
  1185. A.on(realType, A.bind(fn, context || instance), instance.shape || instance.node || DOC, Element._getEventConfig(realType, type));
  1186. return instance;
  1187. },
  1188. remove: EMPTY_FN,
  1189. resetScale: function() {
  1190. if (this.removed) {
  1191. return this;
  1192. }
  1193. this._.sx = 1;
  1194. this._.sy = 1;
  1195. this.attrs.scale = '1 1';
  1196. },
  1197. rotate: EMPTY_FN,
  1198. scale: function(x, y, cx, cy) {
  1199. if (this.removed) {
  1200. return this;
  1201. }
  1202. if (x == null && y == null) {
  1203. return {
  1204. x: this._.sx,
  1205. y: this._.sy,
  1206. toString: Util.XYToString
  1207. };
  1208. }
  1209. y = y || x;
  1210. !+y && (y = x);
  1211. var dx;
  1212. var dy;
  1213. var dcx;
  1214. var dcy;
  1215. var a = this.attrs;
  1216. if (x != 0) {
  1217. var bb = this.getRegion();
  1218. var rcx = bb.x + bb.width / 2;
  1219. var rcy = bb.y + bb.height / 2;
  1220. var kx = MATH.abs(x / this._.sx);
  1221. var ky = MATH.abs(y / this._.sy);
  1222. cx = (+cx || cx == 0) ? cx : rcx;
  1223. cy = (+cy || cy == 0) ? cy : rcy;
  1224. var posx = ~~(this._.sx > 0);
  1225. var posy = ~~(this._.sy > 0);
  1226. var dirx = ~~(x / MATH.abs(x));
  1227. var diry = ~~(y / MATH.abs(y));
  1228. var dkx = kx * dirx;
  1229. var dky = ky * diry;
  1230. var s = this.node.style;
  1231. var ncx = cx + MATH.abs(rcx - cx) * dkx * (rcx > cx == posx ? 1 : -1);
  1232. var ncy = cy + MATH.abs(rcy - cy) * dky * (rcy > cy == posy ? 1 : -1);
  1233. var fr = (x * dirx > y * diry ? ky : kx);
  1234. switch (this.type) {
  1235. case 'rect':
  1236. case 'image':
  1237. var neww = a.width * kx;
  1238. var newh = a.height * ky;
  1239. this.attr({
  1240. height: newh,
  1241. r: a.r * fr,
  1242. width: neww,
  1243. x: ncx - neww / 2,
  1244. y: ncy - newh / 2
  1245. });
  1246. break;
  1247. case 'circle':
  1248. case 'ellipse':
  1249. this.attr({
  1250. rx: a.rx * dirx * kx,
  1251. ry: a.ry * diry * ky,
  1252. r: a.r * MATH_MIN(dirx * kx, diry * ky),
  1253. cx: ncx,
  1254. cy: ncy
  1255. });
  1256. break;
  1257. case 'text':
  1258. this.attr({
  1259. x: ncx,
  1260. y: ncy
  1261. });
  1262. break;
  1263. case 'path':
  1264. var path = Util.pathToRelative(a.path);
  1265. var skip = true;
  1266. var fx = posx ? dkx : kx;
  1267. var fy = posy ? dky : ky;
  1268. for (var i = 0, length = path.length; i < length; i++) {
  1269. var p = path[i];
  1270. var P0 = TO_UPPER_CASE.call(p[0]);
  1271. if (P0 == 'M' && skip) {
  1272. continue;
  1273. }
  1274. else {
  1275. skip = false;
  1276. }
  1277. if (P0 == 'A') {
  1278. p[path[i].length - 2] *= fx;
  1279. p[path[i].length - 1] *= fy;
  1280. p[1] *= kx;
  1281. p[2] *= ky;
  1282. p[5] = +(dirx + diry ? !!+p[5] : !+p[5]);
  1283. }
  1284. else if (P0 == 'H') {
  1285. for (var j = 1, jLength = p.length; j < jLength; j++) {
  1286. p[j] *= fx;
  1287. }
  1288. }
  1289. else if (P0 == 'V') {
  1290. for (j = 1, jLength = p.length; j < jLength; j++) {
  1291. p[j] *= fy;
  1292. }
  1293. }
  1294. else {
  1295. for (j = 1, jLength = p.length; j < jLength; j++) {
  1296. p[j] *= (j % 2) ? fx : fy;
  1297. }
  1298. }
  1299. }
  1300. var dim2 = Util.pathDimensions(path);
  1301. dx = ncx - dim2.x - dim2.width / 2;
  1302. dy = ncy - dim2.y - dim2.height / 2;
  1303. path[0][1] += dx;
  1304. path[0][2] += dy;
  1305. this.attr({path: path});
  1306. break;
  1307. }
  1308. if (this.type in MAP_TYPES_IMAGE_TEXT && (dirx != 1 || diry != 1)) {
  1309. if (this.transformations) {
  1310. this.transformations[2] = 'scale('.concat(dirx, ',', diry, ')');
  1311. this.node.setAttribute('transform', this.transformations.join(STR_SPACE));
  1312. dx = (dirx == -1) ? -a.x - (neww || 0) : a.x;
  1313. dy = (diry == -1) ? -a.y - (newh || 0) : a.y;
  1314. this.attr(
  1315. {
  1316. x: dx,
  1317. y: dy
  1318. }
  1319. );
  1320. a.fx = dirx - 1;
  1321. a.fy = diry - 1;
  1322. }
  1323. else {
  1324. this.node.filterMatrix = STR_MS_PROG_ID_PREFIX + '.Matrix(M11='.concat(dirx,
  1325. ', M12=0, M21=0, M22=', diry,
  1326. ', Dx=0, Dy=0, sizingmethod="auto expand", filtertype="bilinear")');
  1327. s.filter = (this.node.filterMatrix || STR_EMPTY) + (this.node.filterOpacity || STR_EMPTY);
  1328. }
  1329. }
  1330. else {
  1331. if (this.transformations) {
  1332. this.transformations[2] = STR_EMPTY;
  1333. this.node.setAttribute('transform', this.transformations.join(STR_SPACE));
  1334. a.fx = 0;
  1335. a.fy = 0;
  1336. }
  1337. else {
  1338. this.node.filterMatrix = STR_EMPTY;
  1339. s.filter = (this.node.filterMatrix || STR_EMPTY) + (this.node.filterOpacity || STR_EMPTY);
  1340. }
  1341. }
  1342. a.scale = [x, y, cx, cy].join(STR_SPACE);
  1343. this._.sx = x;
  1344. this._.sy = y;
  1345. }
  1346. return this;
  1347. },
  1348. show: EMPTY_FN,
  1349. toBack: EMPTY_FN,
  1350. toFront: EMPTY_FN,
  1351. toString: function() {
  1352. return '"' + TO_UPPER_CASE.call(this.type) + '": AlloyUI Drawing Element';
  1353. },
  1354. translate: EMPTY_FN,
  1355. unhover: function(overFn, outFn) {
  1356. return this.detach('mouseover', overFn).detach('mouseout', outFn);
  1357. }
  1358. };
  1359. Element._getEventConfig = EMPTY_FN;
  1360. Element._getEventType = function(eventType) {
  1361. return eventType;
  1362. };
  1363. Drawing.Element = Element;
  1364. var Set = A.Component.create(
  1365. {
  1366. NAME: 'set',
  1367. EXTENDS: A.ArrayList,
  1368. prototype: {
  1369. pop: function() {
  1370. var instance = this;
  1371. return instance._items.pop();
  1372. },
  1373. push: function() {
  1374. var instance = this;
  1375. var items = instance._items;
  1376. var args = arguments;
  1377. var length = args.length;
  1378. var item;
  1379. for (var i = 0; i < length; i++) {
  1380. item = args[i];
  1381. if (item && item instanceof Element || item instanceof Set) {
  1382. items[items.length] = args[i];
  1383. }
  1384. }
  1385. return instance;
  1386. },
  1387. clone: function() {
  1388. var instance = this;
  1389. var setList = new Set();
  1390. setList._items = instance._items;
  1391. return setList;
  1392. },
  1393. invoke: function(methodName) {
  1394. var instance = this;
  1395. var args = Array.prototype.slice.call(arguments, 1);
  1396. var item;
  1397. var items = instance._items;
  1398. for (var i = 0, length = items.length; i < length; i++) {
  1399. item = items[i];
  1400. if (methodName in item) {
  1401. item[methodName].apply(items[i], args);
  1402. }
  1403. }
  1404. return instance;
  1405. }
  1406. }
  1407. }
  1408. );
  1409. Drawing.Set = Set;
  1410. Set.addMethod = function(method) {
  1411. return A.ArrayList.addMethod(Drawing.Set.prototype, method);
  1412. };
  1413. var setListMethods = A.Object.keys(Element.prototype);
  1414. Set.addMethod(setListMethods);
  1415. Set.prototype.getRegion = Set.prototype.getBBox = function() {
  1416. var instance = this;
  1417. var x = [];
  1418. var y = [];
  1419. var w = [];
  1420. var h = [];
  1421. var items = instance._items;
  1422. for (var i = items.length; i--;) {
  1423. var box = items[i].getRegion();
  1424. x.push(box.x);
  1425. y.push(box.y);
  1426. w.push(box.x + box.width);
  1427. h.push(box.y + box.height);
  1428. }
  1429. x = MATH_MIN.apply(0, x);
  1430. y = MATH_MIN.apply(0, y);
  1431. return {
  1432. x: x,
  1433. y: y,
  1434. width: MATH_MAX.apply(0, w) - x,
  1435. height: MATH_MAX.apply(0, h) - y
  1436. };
  1437. };
  1438. Set.prototype.attr = function(name, value) {
  1439. var instance = this;
  1440. var items = instance._items;
  1441. if (name && isArray(name) && isObject(name[0])) {
  1442. for (var i = 0, length = name.length; i < length; i++) {
  1443. items[i].attr(name[i]);
  1444. }
  1445. }
  1446. else {
  1447. for (var i = 0, length = items.length; i < length; i++) {
  1448. items[i].attr(name, value);
  1449. }
  1450. }
  1451. return instance;
  1452. };
  1453. Set.prototype.toString = function() {
  1454. return this._items.join(',');
  1455. };
  1456. // Expose shared object/common constants
  1457. Drawing.REGEX_ISURL = REGEX_ISURL;
  1458. Drawing.REGEX_SEPARATOR = REGEX_SEPARATOR;
  1459. Drawing.REGEX_SEPARATOR_GRADIENT = REGEX_SEPARATOR_GRADIENT;
  1460. Drawing.REGEX_RADIAL_GRADIENT = REGEX_RADIAL_GRADIENT;
  1461. Drawing.MAP_ATTRS_AVAILABLE = MAP_ATTRS_AVAILABLE;
  1462. Drawing.MAP_TYPES_IMAGE_TEXT = MAP_TYPES_IMAGE_TEXT;
  1463. Drawing.MAP_TYPES_CIRCLE_ELLIPSE = MAP_TYPES_CIRCLE_ELLIPSE;
  1464. Drawing.STR_EMPTY = STR_EMPTY;
  1465. Drawing.STR_FILL = STR_FILL;
  1466. Drawing.STR_SPACE = STR_SPACE;
  1467. Drawing.STR_MS_PROG_ID_PREFIX = STR_MS_PROG_ID_PREFIX;
  1468. Drawing.Util = Util;
  1469. Drawing.Element = Element;
  1470. A.Drawing = Drawing;
  1471. }, '@VERSION@' ,{requires:['aui-base','aui-color-util','substitute']});
  1472. AUI.add('aui-drawing-svg', function(A) {
  1473. var Lang = A.Lang,
  1474. isArray = Lang.isArray,
  1475. isFunction = Lang.isFunction,
  1476. isObject = Lang.isObject,
  1477. isString = Lang.isString,
  1478. isUndefined = Lang.isUndefined,
  1479. CONFIG = A.config,
  1480. DOC = CONFIG.doc,
  1481. ColorUtil = A.ColorUtil,
  1482. Drawing = A.Drawing,
  1483. Element = Drawing.Element,
  1484. Impl,
  1485. Util = Drawing.Util,
  1486. DRAWING_PROTOTYPE = Drawing.prototype,
  1487. ELEMENT_PROTOTYPE = Element.prototype,
  1488. MATH = Math,
  1489. MATH_MAX = MATH.max,
  1490. MATH_POW = MATH.pow,
  1491. MAP_ATTRS_AVAILABLE = Drawing.MAP_ATTRS_AVAILABLE,
  1492. MAP_TYPES_IMAGE_TEXT = Drawing.MAP_TYPES_IMAGE_TEXT,
  1493. MAP_TYPES_CIRCLE_ELLIPSE = Drawing.MAP_TYPES_CIRCLE_ELLIPSE,
  1494. REGEX_ISURL = Drawing.REGEX_ISURL,
  1495. REGEX_RADIAL_GRADIENT = Drawing.REGEX_RADIAL_GRADIENT,
  1496. REGEX_SEPARATOR = Drawing.REGEX_SEPARATOR,
  1497. REGEX_SEPARATOR_GRADIENT = Drawing.REGEX_SEPARATOR_GRADIENT,
  1498. STR_CREATED_DESCRIPTION = 'Created with AlloyUI',
  1499. STR_EMPTY = Drawing.STR_EMPTY,
  1500. STR_FILL = Drawing.STR_FILL,
  1501. STR_SPACE = Drawing.STR_SPACE,
  1502. TEXT_LEADING = 1.2,
  1503. TO_LOWER_CASE = String.prototype.toLowerCase,
  1504. TO_UPPER_CASE = String.prototype.toUpperCase;
  1505. DRAWING_PROTOTYPE.svgns = 'http://www.w3.org/2000/svg';
  1506. DRAWING_PROTOTYPE.xlink = 'http://www.w3.org/1999/xlink';
  1507. Util.CREATE_ELEMENT = function(elementType) {
  1508. var el = DOC.createElementNS(DRAWING_PROTOTYPE.svgns, elementType);
  1509. el.style.webkitTapHighlightColor = 'rgba(0,0,0,0)';
  1510. return el;
  1511. };
  1512. Util.SET_ATTRS = function(el, attr) {
  1513. for (var key in attr) {
  1514. if (attr.hasOwnProperty(key)) {
  1515. el.setAttribute(key, String(attr[key]));
  1516. }
  1517. }
  1518. return el;
  1519. };
  1520. Util.TUNE_TEXT = function(el, params) {
  1521. if (el.type != 'text' || !(params.hasOwnProperty('text') || params.hasOwnProperty('font') || params.hasOwnProperty('font-size') || params.hasOwnProperty('x') || params.hasOwnProperty('y'))) {
  1522. return;
  1523. }
  1524. var texts;
  1525. var a = el.attrs;
  1526. var node = el.node;
  1527. var fontSize = 10;
  1528. if (node.firstChild) {
  1529. fontSize = parseInt(DOC.defaultView.getComputedStyle(node.firstChild, STR_EMPTY).getPropertyValue('font-size'), 10);
  1530. }
  1531. if (params.hasOwnProperty('text')) {
  1532. a.text = params.text;
  1533. while (node.firstChild) {
  1534. node.removeChild(node.firstChild);
  1535. }
  1536. texts = String(params.text).split('\n');
  1537. for (var i = 0, length = texts.length; i < length; i++) {
  1538. if (texts[i]) {
  1539. var tspan = Util.CREATE_ELEMENT('tspan');
  1540. if (i) {
  1541. Util.SET_ATTRS(
  1542. tspan,
  1543. {
  1544. dy: fontSize * TEXT_LEADING,
  1545. x: a.x
  1546. }
  1547. );
  1548. }
  1549. tspan.appendChild(DOC.createTextNode(texts[i]));
  1550. node.appendChild(tspan);
  1551. }
  1552. }
  1553. }
  1554. else {
  1555. texts = node.getElementsByTagName('tspan');
  1556. for (i = 0, length = texts.length; i < length; i++) {
  1557. if (i) {
  1558. Util.SET_ATTRS(
  1559. texts[i],
  1560. {
  1561. dy: fontSize * TEXT_LEADING,
  1562. x: a.x
  1563. }
  1564. );
  1565. }
  1566. }
  1567. }
  1568. Util.SET_ATTRS(
  1569. node,
  1570. {
  1571. y: a.y
  1572. }
  1573. );
  1574. var bb = el.getRegion();
  1575. var diff = a.y - (bb.y + bb.height / 2);
  1576. if (diff && isFinite(diff)) {
  1577. Util.SET_ATTRS(
  1578. node,
  1579. {
  1580. y: a.y + diff
  1581. }
  1582. );
  1583. }
  1584. };
  1585. Util.UPDATE_POSITION = function(obj) {
  1586. var bbox = obj.getRegion();
  1587. Util.SET_ATTRS(
  1588. obj.pattern,
  1589. {
  1590. patternTransform: Lang.sub('translate({0},{1})', [bbox.x, bbox.y])
  1591. }
  1592. );
  1593. };
  1594. Impl = Drawing.Impl = {
  1595. addGradientFill: function(obj, gradient, SVG) {
  1596. var type = 'linear';
  1597. var fx = 0.5;
  1598. var fy = 0.5;
  1599. var objStyle = obj.style;
  1600. var vector;
  1601. gradient = String(gradient).replace(REGEX_RADIAL_GRADIENT, function(all, _fx, _fy) {
  1602. type = 'radial';
  1603. if (_fx && _fy) {
  1604. fx = parseFloat(_fx);
  1605. fy = parseFloat(_fy);
  1606. var dir = ((fy > 0.5) * 2 - 1);
  1607. MATH_POW(fx - 0.5, 2) + MATH_POW(fy - 0.5, 2) > 0.25 &&
  1608. (fy = MATH.sqrt(0.25 - MATH_POW(fx - 0.5, 2)) * dir + 0.5) &&
  1609. fy != 0.5 &&
  1610. (fy = fy.toFixed(5) - 1e-5 * dir);
  1611. }
  1612. return STR_EMPTY;
  1613. });
  1614. gradient = gradient.split(REGEX_SEPARATOR_GRADIENT);
  1615. if (type == 'linear') {
  1616. var angle = gradient.shift();
  1617. angle = -parseFloat(angle);
  1618. if (isNaN(angle)) {
  1619. return null;
  1620. }
  1621. vector = [0, 0, MATH.cos(angle * MATH.PI / 180), MATH.sin(angle * MATH.PI / 180)];
  1622. var max = 1 / (MATH_MAX(MATH.abs(vector[2]), MATH.abs(vector[3])) || 1);
  1623. vector[2] *= max;
  1624. vector[3] *= max;
  1625. if (vector[2] < 0) {
  1626. vector[0] = -vector[2];
  1627. vector[2] = 0;
  1628. }
  1629. if (vector[3] < 0) {
  1630. vector[1] = -vector[3];
  1631. vector[3] = 0;
  1632. }
  1633. }
  1634. var dots = Util.parseDots(gradient);
  1635. if (!dots) {
  1636. return null;
  1637. }
  1638. var id = obj.getAttribute(STR_FILL);
  1639. id = id.match(/^url\(#(.*)\)$/);
  1640. id && SVG.defs.removeChild(DOC.getElementById(id[1]));
  1641. var el = Util.CREATE_ELEMENT(type + 'Gradient');
  1642. el.id = A.guid();
  1643. var elAttrs;
  1644. if (type == 'radial') {
  1645. elAttrs = {
  1646. fx: fx,
  1647. fy: fy
  1648. };
  1649. }
  1650. else {
  1651. elAttrs = {
  1652. x1: vector[0],
  1653. y1: vector[1],
  1654. x2: vector[2],
  1655. y2: vector[3]
  1656. };
  1657. }
  1658. Util.SET_ATTRS(el, elAttrs);
  1659. SVG.defs.appendChild(el);
  1660. for (var i = 0, length = dots.length; i < length; i++) {
  1661. var stop = Util.CREATE_ELEMENT('stop');
  1662. var offset = dots[i].offset;
  1663. if (!offset) {
  1664. if (!i) {
  1665. offset = '0%';
  1666. }
  1667. else {
  1668. offset = '100%';
  1669. }
  1670. }
  1671. Util.SET_ATTRS(
  1672. stop,
  1673. {
  1674. offset: offset,
  1675. 'stop-color': dots[i].color || '#fff'
  1676. }
  1677. );
  1678. el.appendChild(stop);
  1679. }
  1680. Util.SET_ATTRS(
  1681. obj,
  1682. {
  1683. fill: 'url(#' + el.id + ')',
  1684. opacity: 1,
  1685. 'fill-opacity': 1
  1686. }
  1687. );
  1688. objStyle.fill = STR_EMPTY;
  1689. objStyle.opacity = 1;
  1690. objStyle.fillOpacity = 1;
  1691. return 1;
  1692. },
  1693. clear: function() {
  1694. var instance = this;
  1695. var canvas = instance.canvas;
  1696. while (canvas.firstChild) {
  1697. canvas.removeChild(canvas.firstChild);
  1698. }
  1699. instance.bottom = instance.top = null;
  1700. instance.desc = Util.CREATE_ELEMENT('desc');
  1701. instance.desc.appendChild(DOC.createTextNode(STR_CREATED_DESCRIPTION));
  1702. canvas.appendChild(instance.desc);
  1703. instance.defs = Util.CREATE_ELEMENT('defs');
  1704. canvas.appendChild(instance.defs);
  1705. },
  1706. createCanvas: function() {
  1707. var instance = this;
  1708. var contentBox = instance.get('contentBox');
  1709. var x = instance.get('x');
  1710. var y = instance.get('y');
  1711. var width = instance.get('width');
  1712. var height = instance.get('height');
  1713. var canvas = Util.CREATE_ELEMENT('svg');
  1714. Util.SET_ATTRS(
  1715. canvas,
  1716. {
  1717. xmlns: 'http://www.w3.org/2000/svg',
  1718. version: 1.1,
  1719. width: width,
  1720. height: height
  1721. }
  1722. );
  1723. contentBox.prepend(canvas);
  1724. instance.canvas = canvas;
  1725. instance.clear();
  1726. },
  1727. createCircle: function(x, y, r) {
  1728. var instance = this;
  1729. var el = Util.CREATE_ELEMENT('circle');
  1730. instance.canvas.appendChild(el);
  1731. var circle = new Element(el, instance);
  1732. circle.attrs = {
  1733. cx: x,
  1734. cy: y,
  1735. r: r,
  1736. fill: 'none',
  1737. stroke: '#000'
  1738. };
  1739. circle.type = 'circle';
  1740. Util.SET_ATTRS(el, circle.attrs);
  1741. return circle;
  1742. },
  1743. createEllipse: function(x, y, rx, ry) {
  1744. var instance = this;
  1745. var el = Util.CREATE_ELEMENT('ellipse');
  1746. instance.canvas.appendChild(el);
  1747. var ellipse = new Element(el, instance);
  1748. ellipse.attrs = {
  1749. cx: x,
  1750. cy: y,
  1751. rx: rx,
  1752. ry: ry,
  1753. fill: 'none',
  1754. stroke: '#000'
  1755. };
  1756. ellipse.type = 'ellipse';
  1757. Util.SET_ATTRS(el, ellipse.attrs);
  1758. return ellipse;
  1759. },
  1760. createImage: function(src, x, y, w, h) {
  1761. var instance = this;
  1762. var el = Util.CREATE_ELEMENT('image');
  1763. Util.SET_ATTRS(
  1764. el,
  1765. {
  1766. x: x,
  1767. y: y,
  1768. width: w,
  1769. height: h,
  1770. preserveAspectRatio: 'none'
  1771. }
  1772. );
  1773. el.setAttributeNS(instance.xlink, 'href', src);
  1774. instance.canvas.appendChild(el);
  1775. var image = new Element(el, instance);
  1776. image.attrs = {
  1777. x: x,
  1778. y: y,
  1779. width: w,
  1780. height: h,
  1781. src: src
  1782. };
  1783. image.type = 'image';
  1784. return image;
  1785. },
  1786. createPath: function(pathString) {
  1787. var instance = this;
  1788. var el = Util.CREATE_ELEMENT('path');
  1789. instance.canvas.appendChild(el);
  1790. var path = new Element(el, instance);
  1791. path.type = 'path';
  1792. Impl.setFillAndStroke(
  1793. path,
  1794. {
  1795. fill: 'none',
  1796. stroke: '#000',
  1797. path: pathString
  1798. }
  1799. );
  1800. return path;
  1801. },
  1802. createRectangle: function(x, y, w, h, r) {
  1803. var instance = this;
  1804. var el = Util.CREATE_ELEMENT('rect');
  1805. instance.canvas.appendChild(el);
  1806. var rect = new Element(el, instance);
  1807. rect.attrs = {
  1808. x: x,
  1809. y: y,
  1810. width: w,
  1811. height: h,
  1812. r: r,
  1813. rx: r,
  1814. ry: r,
  1815. fill: 'none',
  1816. stroke: '#000'
  1817. };
  1818. rect.type = 'rect';
  1819. Util.SET_ATTRS(el, rect.attrs);
  1820. return rect;
  1821. },
  1822. createText: function(x, y, text) {
  1823. var instance = this;
  1824. var el = Util.CREATE_ELEMENT('text');
  1825. Util.SET_ATTRS(
  1826. el,
  1827. {
  1828. x: x,
  1829. y: y,
  1830. 'text-anchor': 'middle'
  1831. }
  1832. );
  1833. instance.canvas.appendChild(el);
  1834. var textElement = new Element(el, instance);
  1835. textElement.attrs = {
  1836. x: x,
  1837. y: y,
  1838. 'text-anchor': 'middle',
  1839. text: text,
  1840. font: MAP_ATTRS_AVAILABLE.font,
  1841. stroke: 'none',
  1842. fill: '#000'
  1843. };
  1844. textElement.type = 'text';
  1845. Impl.setFillAndStroke(textElement, textElement.attrs);
  1846. return textElement;
  1847. },
  1848. setFillAndStroke: function(obj, params) {
  1849. var dasharray = {
  1850. '': [0],
  1851. 'none': [0],
  1852. '-': [3, 1],
  1853. '.': [1, 1],
  1854. '-.': [3, 1, 1, 1],
  1855. '-..': [3, 1, 1, 1, 1, 1],
  1856. '. ': [1, 3],
  1857. '- ': [4, 3],
  1858. '--': [8, 3],
  1859. '- .': [4, 3, 1, 3],
  1860. '--.': [8, 3, 1, 3],
  1861. '--..': [8, 3, 1, 3, 1, 3]
  1862. };
  1863. var node = obj.node;
  1864. var attrs = obj.attrs;
  1865. var rot = obj.rotate();
  1866. var addDashes = function(obj, value) {
  1867. value = dasharray[TO_LOWER_CASE.call(value)];
  1868. if (value) {
  1869. var width = obj.attrs['stroke-width'] || '1';
  1870. var butt = {
  1871. round: width,
  1872. square: width,
  1873. butt: 0
  1874. }[obj.attrs['stroke-linecap'] || params['stroke-linecap']] || 0;
  1875. var dashes = [];
  1876. var i = value.length;
  1877. while (i--) {
  1878. dashes[i] = value[i] * width + ((i % 2) ? 1 : -1) * butt;
  1879. }
  1880. Util.SET_ATTRS(
  1881. node,
  1882. {
  1883. 'stroke-dasharray': dashes.join(',')
  1884. }
  1885. );
  1886. }
  1887. };
  1888. if (params.hasOwnProperty('rotation')) {
  1889. rot = params.rotation;
  1890. }
  1891. var rotxy = String(rot).split(REGEX_SEPARATOR);
  1892. if (!(rotxy.length - 1)) {
  1893. rotxy = null;
  1894. }
  1895. else {
  1896. rotxy[1] = +rotxy[1];
  1897. rotxy[2] = +rotxy[2];
  1898. }
  1899. parseFloat(rot) && obj.rotate(0, true);
  1900. for (var att in params) {
  1901. if (params.hasOwnProperty(att)) {
  1902. if (!MAP_ATTRS_AVAILABLE.hasOwnProperty(att)) {
  1903. continue;
  1904. }
  1905. var value = params[att];
  1906. attrs[att] = value;
  1907. switch (att) {
  1908. case 'blur':
  1909. obj.blur(value);
  1910. break;
  1911. case 'rotation':
  1912. obj.rotate(value, true);
  1913. break;
  1914. case 'href':
  1915. case 'title':
  1916. case 'target':
  1917. var pn = node.parentNode;
  1918. if (TO_LOWER_CASE.call(pn.tagName) != 'a') {
  1919. var hl = Util.CREATE_ELEMENT('a');
  1920. pn.insertBefore(hl, node);
  1921. hl.appendChild(node);
  1922. pn = hl;
  1923. }
  1924. pn.setAttributeNS(obj.paper.xlink, att, value);
  1925. break;
  1926. case 'cursor':
  1927. node.style.cursor = value;
  1928. break;
  1929. case 'clip-rect':
  1930. var rect = String(value).split(REGEX_SEPARATOR);
  1931. if (rect.length == 4) {
  1932. obj.clip && obj.clip.parentNode.parentNode.removeChild(obj.clip.parentNode);
  1933. var el = Util.CREATE_ELEMENT('clipPath');
  1934. var rc = Util.CREATE_ELEMENT('rect');
  1935. el.id = A.guid();
  1936. Util.SET_ATTRS(
  1937. rc,
  1938. {
  1939. x: rect[0],
  1940. y: rect[1],
  1941. width: rect[2],
  1942. height: rect[3]
  1943. }
  1944. );
  1945. el.appendChild(rc);
  1946. obj.paper.defs.appendChild(el);
  1947. Util.SET_ATTRS(
  1948. node,
  1949. {
  1950. 'clip-path': 'url(#' + el.id + ')'
  1951. }
  1952. );
  1953. obj.clip = rc;
  1954. }
  1955. if (!value) {
  1956. var clip = DOC.getElementById(node.getAttribute('clip-path').replace(/(^url\(#|\)$)/g, STR_EMPTY));
  1957. clip && clip.parentNode.removeChild(clip);
  1958. Util.SET_ATTRS(
  1959. node,
  1960. {
  1961. 'clip-path': STR_EMPTY
  1962. }
  1963. );
  1964. delete obj.clip;
  1965. }
  1966. break;
  1967. case 'path':
  1968. if (obj.type == 'path') {
  1969. var d = 'M0,0';
  1970. if (value) {
  1971. d = Util.pathToAbsolute(value);
  1972. }
  1973. Util.SET_ATTRS(
  1974. node,
  1975. {
  1976. d: d
  1977. }
  1978. );
  1979. }
  1980. break;
  1981. case 'width':
  1982. node.setAttribute(att, value);
  1983. if (attrs.fx) {
  1984. att = 'x';
  1985. value = attrs.x;
  1986. }
  1987. else {
  1988. break;
  1989. }
  1990. case 'x':
  1991. if (attrs.fx) {
  1992. value = -attrs.x - (attrs.width || 0);
  1993. }
  1994. case 'rx':
  1995. if (att == 'rx' && obj.type == 'rect') {
  1996. break;
  1997. }
  1998. case 'cx':
  1999. rotxy && (att == 'x' || att == 'cx') && (rotxy[1] += value - attrs[att]);
  2000. node.setAttribute(att, value);
  2001. obj.pattern && Util.UPDATE_POSITION(obj);
  2002. break;
  2003. case 'height':
  2004. node.setAttribute(att, value);
  2005. if (attrs.fy) {
  2006. att = 'y';
  2007. value = attrs.y;
  2008. }
  2009. else {
  2010. break;
  2011. }
  2012. case 'y':
  2013. if (attrs.fy) {
  2014. value = -attrs.y - (attrs.height || 0);
  2015. }
  2016. case 'ry':
  2017. if (att == 'ry' && obj.type == 'rect') {
  2018. break;
  2019. }
  2020. case 'cy':
  2021. rotxy && (att == 'y' || att == 'cy') && (rotxy[2] += value - attrs[att]);
  2022. node.setAttribute(att, value);
  2023. obj.pattern && Util.UPDATE_POSITION(obj);
  2024. break;
  2025. case 'r':
  2026. if (obj.type == 'rect') {
  2027. Util.SET_ATTRS(
  2028. node,
  2029. {
  2030. rx: value,
  2031. ry: value
  2032. }
  2033. );
  2034. }
  2035. else {
  2036. node.setAttribute(att, value);
  2037. }
  2038. break;
  2039. case 'src':
  2040. if (obj.type == 'image') {
  2041. node.setAttributeNS(obj.paper.xlink, 'href', value);
  2042. }
  2043. break;
  2044. case 'stroke-width':
  2045. node.style.strokeWidth = value;
  2046. // Need following line for Firefox
  2047. node.setAttribute(att, value);
  2048. if (attrs['stroke-dasharray']) {
  2049. addDashes(obj, attrs['stroke-dasharray']);
  2050. }
  2051. break;
  2052. case 'stroke-dasharray':
  2053. addDashes(obj, value);
  2054. break;
  2055. case 'translation':
  2056. var xy = String(value).split(REGEX_SEPARATOR);
  2057. xy[0] = +xy[0] || 0;
  2058. xy[1] = +xy[1] || 0;
  2059. if (rotxy) {
  2060. rotxy[1] += xy[0];
  2061. rotxy[2] += xy[1];
  2062. }
  2063. Util.translate.call(obj, xy[0], xy[1]);
  2064. break;
  2065. case 'scale':
  2066. xy = String(value).split(REGEX_SEPARATOR);
  2067. obj.scale(
  2068. +xy[0] || 1,
  2069. +xy[1] || +xy[0] || 1,
  2070. isNaN(parseFloat(xy[2])) ? null : +xy[2],
  2071. isNaN(parseFloat(xy[3])) ? null : +xy[3]
  2072. );
  2073. break;
  2074. case STR_FILL:
  2075. var isURL = String(value).match(REGEX_ISURL);
  2076. if (isURL) {
  2077. el = Util.CREATE_ELEMENT('pattern');
  2078. var ig = Util.CREATE_ELEMENT('image');
  2079. el.id = A.guid();
  2080. Util.SET_ATTRS(
  2081. el,
  2082. {
  2083. x: 0,
  2084. y: 0,
  2085. patternUnits: 'userSpaceOnUse',
  2086. height: 1,
  2087. width: 1
  2088. }
  2089. );
  2090. Util.SET_ATTRS(
  2091. ig,
  2092. {
  2093. x: 0,
  2094. y: 0
  2095. }
  2096. );
  2097. ig.setAttributeNS(obj.paper.xlink, 'href', isURL[1]);
  2098. el.appendChild(ig);
  2099. var img = DOC.createElement('img');
  2100. img.style.cssText = 'position: absolute; left: -9999em; top: -9999em';
  2101. img.onload = function() {
  2102. var attrDimensions = {
  2103. width: this.offsetWidth,
  2104. height: this.offsetHeight
  2105. };
  2106. Util.SET_ATTRS(el, attrDimensions);
  2107. Util.SET_ATTRS(ig, attrDimensions);
  2108. DOC.body.removeChild(this);
  2109. obj.paper.safari();
  2110. };
  2111. DOC.body.appendChild(img);
  2112. img.src = isURL[1];
  2113. obj.paper.defs.appendChild(el);
  2114. node.style.fill = 'url(#' + el.id + ')';
  2115. Util.SET_ATTRS(
  2116. node,
  2117. {
  2118. fill: 'url(#' + el.id + ')'
  2119. }
  2120. );
  2121. obj.pattern = el;
  2122. obj.pattern && Util.UPDATE_POSITION(obj);
  2123. break;
  2124. }
  2125. var color = ColorUtil.getRGB(value);
  2126. if (!color.error) {
  2127. delete params.gradient;
  2128. delete attrs.gradient;
  2129. if (!isUndefined(attrs.opacity) && isUndefined(params.opacity)) {
  2130. Util.SET_ATTRS(
  2131. node,
  2132. {
  2133. opacity: attrs.opacity
  2134. }
  2135. );
  2136. }
  2137. if (!isUndefined(attrs['fill-opacity']) && isUndefined(params['fill-opacity'])) {
  2138. Util.SET_ATTRS(
  2139. node,
  2140. {
  2141. 'fill-opacity': attrs['fill-opacity']
  2142. }
  2143. );
  2144. }
  2145. }
  2146. else if ((MAP_TYPES_CIRCLE_ELLIPSE.hasOwnProperty(obj.type) || String(value).charAt(0) != 'r') && Impl.addGradientFill(node, value, obj.paper)) {
  2147. attrs.gradient = value;
  2148. attrs.fill = 'none';
  2149. break;
  2150. }
  2151. if (color.hasOwnProperty('o')) {
  2152. Util.SET_ATTRS(
  2153. node,
  2154. {
  2155. 'fill-opacity': color.o > 1 ? color.o / 100 : color.o
  2156. }
  2157. );
  2158. }
  2159. case 'stroke':
  2160. color = ColorUtil.getRGB(value);
  2161. node.setAttribute(att, color.hex);
  2162. if (att == 'stroke' && color.hasOwnProperty('o')) {
  2163. Util.SET_ATTRS(
  2164. node,
  2165. {
  2166. 'stroke-opacity': color.o > 1 ? color.o / 100 : color.o
  2167. }
  2168. );
  2169. }
  2170. break;
  2171. case 'gradient':
  2172. if (MAP_TYPES_CIRCLE_ELLIPSE.hasOwnProperty(obj.type) || String(value).charAt(0) != 'r') {
  2173. Impl.addGradientFill(node, value, obj.paper);
  2174. }
  2175. break;
  2176. case 'opacity':
  2177. if (attrs.gradient && !attrs.hasOwnProperty('stroke-opacity')) {
  2178. Util.SET_ATTRS(
  2179. node,
  2180. {
  2181. 'stroke-opacity': value > 1 ? value / 100 : value
  2182. }
  2183. );
  2184. }
  2185. // fall through
  2186. case 'fill-opacity':
  2187. if (attrs.gradient) {
  2188. var gradient = DOC.getElementById(node.getAttribute(STR_FILL).replace(/^url\(#|\)$/g, STR_EMPTY));
  2189. if (gradient) {
  2190. var stops = gradient.getElementsByTagName('stop');
  2191. stops[stops.length - 1].setAttribute('stop-opacity', value);
  2192. }
  2193. break;
  2194. }
  2195. default:
  2196. if (att == 'font-size') {
  2197. value = parseInt(value, 10) + 'px';
  2198. }
  2199. var cssrule = att.replace(/(\-.)/g, function(w) {
  2200. return TO_UPPER_CASE.call(w.substring(1));
  2201. });
  2202. node.style[cssrule] = value;
  2203. // Need following line for Firefox
  2204. node.setAttribute(att, value);
  2205. break;
  2206. }
  2207. }
  2208. }
  2209. Util.TUNE_TEXT(obj, params);
  2210. if (rotxy) {
  2211. obj.rotate(rotxy.join(STR_SPACE));
  2212. }
  2213. else {
  2214. parseFloat(rot) && obj.rotate(rot, true);
  2215. }
  2216. },
  2217. remove: function() {
  2218. var instance = this;
  2219. var contentBox = instance.get('contentBox');
  2220. contentBox.removeChild(instance.canvas);
  2221. for (var i in instance) {
  2222. if (DRAWING_PROTOTYPE.hasOwnProperty(i)) {
  2223. instance[i] = Util.removed(i);
  2224. }
  2225. }
  2226. }
  2227. };
  2228. DRAWING_PROTOTYPE._uiSetWidth = function(value) {
  2229. var instance = this;
  2230. Drawing.superclass._uiSetWidth.apply(instance, arguments);
  2231. instance.canvas.setAttribute('width', value);
  2232. };
  2233. DRAWING_PROTOTYPE._uiSetHeight = function(value) {
  2234. var instance = this;
  2235. Drawing.superclass._uiSetHeight.apply(instance, arguments);
  2236. instance.canvas.setAttribute('height', value);
  2237. };
  2238. /*
  2239. ------ ELEMENT IMPL
  2240. */
  2241. ELEMENT_PROTOTYPE.createElement = function(node, drawing) {
  2242. var instance = this;
  2243. instance[0] = node;
  2244. instance.id = A.guid();
  2245. instance.node = node;
  2246. instance.paper = drawing;
  2247. instance.attrs = instance.attrs || {};
  2248. instance.transformations = []; // rotate, translate, scale
  2249. this._ = {
  2250. tx: 0,
  2251. ty: 0,
  2252. rt: {
  2253. deg: 0,
  2254. cx: 0,
  2255. cy: 0
  2256. },
  2257. sx: 1,
  2258. sy: 1
  2259. };
  2260. if (!drawing.bottom) {
  2261. drawing.bottom = instance;
  2262. }
  2263. instance.prev = drawing.top;
  2264. if (drawing.top) {
  2265. drawing.top.next = instance;
  2266. }
  2267. drawing.top = instance;
  2268. instance.next = null;
  2269. };
  2270. ELEMENT_PROTOTYPE.rotate = function(deg, cx, cy) {
  2271. var instance = this;
  2272. if (instance.removed) {
  2273. return instance;
  2274. }
  2275. if (deg == null) {
  2276. if (instance._.rt.cx) {
  2277. return [
  2278. instance._.rt.deg,
  2279. instance._.rt.cx,
  2280. instance._.rt.cy
  2281. ].join(STR_SPACE);
  2282. }
  2283. return instance._.rt.deg;
  2284. }
  2285. var bbox = instance.getRegion();
  2286. deg = String(deg).split(REGEX_SEPARATOR);
  2287. if (deg.length - 1) {
  2288. cx = parseFloat(deg[1]);
  2289. cy = parseFloat(deg[2]);
  2290. }
  2291. deg = parseFloat(deg[0]);
  2292. if (cx != null) {
  2293. instance._.rt.deg = deg;
  2294. }
  2295. else {
  2296. instance._.rt.deg += deg;
  2297. }
  2298. (cy == null) && (cx = null);
  2299. instance._.rt.cx = cx;
  2300. instance._.rt.cy = cy;
  2301. cx = cx == null ? bbox.x + bbox.width / 2 : cx;
  2302. cy = cy == null ? bbox.y + bbox.height / 2 : cy;
  2303. if (instance._.rt.deg) {
  2304. instance.transformations[0] = Lang.sub('rotate({0} {1} {2})', [instance._.rt.deg, cx, cy]);
  2305. if (instance.clip) {
  2306. Util.SET_ATTRS(
  2307. instance.clip,
  2308. {
  2309. transform: Lang.sub("rotate({0} {1} {2})", [-instance._.rt.deg, cx, cy])
  2310. }
  2311. );
  2312. }
  2313. }
  2314. else {
  2315. instance.transformations[0] = STR_EMPTY;
  2316. if (instance.clip) {
  2317. Util.SET_ATTRS(
  2318. instance.clip,
  2319. {
  2320. transform: STR_EMPTY
  2321. }
  2322. );
  2323. }
  2324. }
  2325. Util.SET_ATTRS(
  2326. instance.node,
  2327. {
  2328. transform: instance.transformations.join(STR_SPACE)
  2329. }
  2330. );
  2331. return instance;
  2332. };
  2333. ELEMENT_PROTOTYPE.hide = function() {
  2334. var instance = this;
  2335. !instance.removed && (instance.node.style.display = 'none');
  2336. return this;
  2337. };
  2338. ELEMENT_PROTOTYPE.show = function() {
  2339. var instance = this;
  2340. !instance.removed && (instance.node.style.display = '');
  2341. return instance;
  2342. };
  2343. ELEMENT_PROTOTYPE.remove = function() {
  2344. var instance = this;
  2345. if (instance.removed) {
  2346. return;
  2347. }
  2348. Util.tear(instance, instance.paper);
  2349. instance.node.parentNode.removeChild(instance.node);
  2350. for (var i in instance) {
  2351. delete instance[i];
  2352. }
  2353. instance.removed = true;
  2354. };
  2355. ELEMENT_PROTOTYPE.getRegion = function() {
  2356. var instance = this;
  2357. if (instance.removed) {
  2358. return instance;
  2359. }
  2360. if (instance.type == 'path') {
  2361. return Util.pathDimensions(instance.attrs.path);
  2362. }
  2363. var hide = false;
  2364. if (instance.node.style.display == 'none') {
  2365. instance.show();
  2366. hide = true;
  2367. }
  2368. var bbox = {};
  2369. try {
  2370. bbox = instance.node.getBBox();
  2371. } catch(e) {
  2372. // Firefox 3.0.x plays badly here
  2373. } finally {
  2374. bbox = bbox || {};
  2375. }
  2376. if (instance.type == 'text') {
  2377. bbox = {
  2378. x: bbox.x,
  2379. y: Infinity,
  2380. width: 0,
  2381. height: 0
  2382. };
  2383. for (var i = 0, length = instance.node.getNumberOfChars(); i < length; i++) {
  2384. var bb = instance.node.getExtentOfChar(i);
  2385. if (bb.y < bbox.y) {
  2386. bbox.y = bb.y;
  2387. }
  2388. if (bb.y + bb.height - bbox.y > bbox.height) {
  2389. bbox.height = bb.y + bb.height - bbox.y;
  2390. }
  2391. if (bb.x + bb.width - bbox.x > bbox.width) {
  2392. bbox.width = bb.x + bb.width - bbox.x;
  2393. }
  2394. }
  2395. }
  2396. if (hide) {
  2397. instance.hide();
  2398. }
  2399. return bbox;
  2400. };
  2401. ELEMENT_PROTOTYPE.getBBox = ELEMENT_PROTOTYPE.getRegion;
  2402. ELEMENT_PROTOTYPE.attr = function(name, value) {
  2403. var instance = this;
  2404. if (instance.removed) {
  2405. return instance;
  2406. }
  2407. if (name == null) {
  2408. var res = {};
  2409. for (var i in instance.attrs) {
  2410. if (instance.attrs.hasOwnProperty(i)) {
  2411. res[i] = instance.attrs[i];
  2412. }
  2413. }
  2414. instance._.rt.deg && (res.rotation = instance.rotate());
  2415. (instance._.sx != 1 || instance._.sy != 1) && (res.scale = instance.scale());
  2416. res.gradient && res.fill == 'none' && (res.fill = res.gradient) && delete res.gradient;
  2417. return res;
  2418. }
  2419. if (value == null && isString(name)) {
  2420. if (name == 'translation') {
  2421. return Util.translate.call(instance);
  2422. }
  2423. if (name == 'rotation') {
  2424. return instance.rotate();
  2425. }
  2426. if (name == 'scale') {
  2427. return instance.scale();
  2428. }
  2429. if (name == STR_FILL && instance.attrs.fill == 'none' && instance.attrs.gradient) {
  2430. return instance.attrs.gradient;
  2431. }
  2432. return instance.attrs[name];
  2433. }
  2434. if (value == null && isArray(name)) {
  2435. var values = {};
  2436. for (var j = 0, jLength = name.length; j < jLength; j++) {
  2437. values[name[j]] = instance.attr(name[j]);
  2438. }
  2439. return values;
  2440. }
  2441. var params = Util.applyAttributes(instance, name, value);
  2442. Impl.setFillAndStroke(instance, params);
  2443. return instance;
  2444. };
  2445. ELEMENT_PROTOTYPE.toFront = function() {
  2446. var instance = this;
  2447. if (instance.removed) {
  2448. return instance;
  2449. }
  2450. instance.node.parentNode.appendChild(instance.node);
  2451. var drawing = instance.paper;
  2452. drawing.top != instance && Util.toFront(instance, drawing);
  2453. return instance;
  2454. };
  2455. ELEMENT_PROTOTYPE.toBack = function() {
  2456. var instance = this;
  2457. if (instance.removed) {
  2458. return instance;
  2459. }
  2460. if (instance.node.parentNode.firstChild != instance.node) {
  2461. instance.node.parentNode.insertBefore(instance.node, instance.node.parentNode.firstChild);
  2462. Util.toBack(instance, instance.paper);
  2463. }
  2464. return instance;
  2465. };
  2466. ELEMENT_PROTOTYPE.insertAfter = function(element) {
  2467. var instance = this;
  2468. if (instance.removed) {
  2469. return instance;
  2470. }
  2471. var node = element.node || element instanceof Drawing.Set && element.item(element.size()).node;
  2472. if (node.nextSibling) {
  2473. node.parentNode.insertBefore(instance.node, node.nextSibling);
  2474. }
  2475. else {
  2476. node.parentNode.appendChild(instance.node);
  2477. }
  2478. Util.insertAfter(instance, element, instance.paper);
  2479. return instance;
  2480. };
  2481. ELEMENT_PROTOTYPE.insertBefore = function(element) {
  2482. var instance = this;
  2483. if (instance.removed) {
  2484. return instance;
  2485. }
  2486. var node = element.node || element instanceof Drawing.Set && element.item(0).node;
  2487. node.parentNode.insertBefore(instance.node, node);
  2488. Util.insertBefore(instance, element, instance.paper);
  2489. return instance;
  2490. };
  2491. ELEMENT_PROTOTYPE.blur = function(size) {
  2492. // Experimental. No Safari support. Use it on your own risk.
  2493. var instance = this;
  2494. if (+size !== 0) {
  2495. var fltr = CREATE_ELEMENT('filter');
  2496. var blur = CREATE_ELEMENT('feGaussianBlur');
  2497. instance.attrs.blur = size;
  2498. fltr.id = A.guid();
  2499. Util.SET_ATTRS(
  2500. blur,
  2501. {
  2502. stdDeviation: +size || 1.5
  2503. }
  2504. );
  2505. fltr.appendChild(blur);
  2506. instance.paper.defs.appendChild(fltr);
  2507. instance._blur = fltr;
  2508. Util.SET_ATTRS(
  2509. instance.node,
  2510. {
  2511. filter: 'url(#' + fltr.id + ')'
  2512. }
  2513. );
  2514. }
  2515. else {
  2516. if (instance._blur) {
  2517. instance._blur.parentNode.removeChild(instance._blur);
  2518. delete instance._blur;
  2519. delete instance.attrs.blur;
  2520. }
  2521. instance.node.removeAttribute('filter');
  2522. }
  2523. };
  2524. }, '@VERSION@' ,{requires:['aui-drawing-base'], condition: {name: 'aui-drawing-svg', trigger: 'aui-drawing-base',test: function(A){return A.UA.svg;}}});
  2525. AUI.add('aui-drawing-vml', function(A) {
  2526. var Lang = A.Lang,
  2527. isArray = Lang.isArray,
  2528. isNumber = Lang.isNumber,
  2529. isObject = Lang.isObject,
  2530. isString = Lang.isString,
  2531. isUndefined = Lang.isUndefined,
  2532. CONFIG = A.config,
  2533. DOC = CONFIG.doc,
  2534. ColorUtil = A.ColorUtil,
  2535. Drawing = A.Drawing,
  2536. Element = Drawing.Element,
  2537. Impl,
  2538. Util = Drawing.Util,
  2539. setDefaultUnit = function(value) {
  2540. return isNumber(value) ? value + 'px' : value;
  2541. },
  2542. DEFAULT_VML_COORD_SIZE = 1e3 + STR_SPACE + 1e3,
  2543. DRAWING_PROTOTYPE = Drawing.prototype,
  2544. ELEMENT_PROTOTYPE = Element.prototype,
  2545. MAP_ATTRS_AVAILABLE = Drawing.MAP_ATTRS_AVAILABLE,
  2546. MAP_PATH_LIKE = {
  2547. path: 1,
  2548. rect: 1
  2549. },
  2550. MAP_COMMAND_VML = {
  2551. M: 'm',
  2552. L: 'l',
  2553. C: 'c',
  2554. Z: 'x',
  2555. m: 't',
  2556. l: 'r',
  2557. c: 'v',
  2558. z: 'x'
  2559. },
  2560. MAP_KEYWORDS_VML_STROKE_DASH_ARRAY = {
  2561. '-': 'shortdash',
  2562. '.': 'shortdot',
  2563. '-.': 'shortdashdot',
  2564. '-..': 'shortdashdotdot',
  2565. '. ': 'dot',
  2566. '- ': 'dash',
  2567. '--': 'longdash',
  2568. '- .': 'dashdot',
  2569. '--.': 'longdashdot',
  2570. '--..': 'longdashdotdot'
  2571. },
  2572. MAP_TYPES_CIRCLE_ELLIPSE = Drawing.MAP_TYPES_CIRCLE_ELLIPSE,
  2573. MATH = Math,
  2574. MATH_POW = MATH.pow,
  2575. MATH_ROUND = MATH.round,
  2576. STR_MS_PROG_ID_PREFIX = Drawing.STR_MS_PROG_ID_PREFIX,
  2577. REGEX_ISURL = Drawing.REGEX_ISURL,
  2578. REGEX_RADIAL_GRADIENT = Drawing.REGEX_RADIAL_GRADIENT,
  2579. REGEX_SEPARATOR = Drawing.REGEX_SEPARATOR,
  2580. REGEX_SEPARATOR_GRADIENT = Drawing.REGEX_SEPARATOR_GRADIENT,
  2581. REGEX_VML_BITES = /([clmz]),?([^clmz]*)/gi,
  2582. REGEX_VML_VAL = /-?[^,\s-]+/g,
  2583. REGEX_VML_BLUR = / progid:\S+Blur\([^\)]+\)/g,
  2584. STR_EMPTY = Drawing.STR_EMPTY,
  2585. STR_FILL = Drawing.STR_FILL,
  2586. STR_SPACE = Drawing.STR_SPACE,
  2587. TEXT_LEADING = 1.2,
  2588. TPL_RECTANGLE = 'M{0},{1}l{2},0,0,{3},{4},0z',
  2589. TPL_RECTANGLE_ROUNDED_CORNER = 'M{0},{1}l{2},0a{3},{3},0,0,1,{3},{3}l0,{5}a{3},{3},0,0,1,{4},{3}l{6},0a{3},{3},0,0,1,{4},{4}l0,{7}a{3},{3},0,0,1,{3},{4}z',
  2590. TPL_CSS_TEXT_DEFAULT = 'position: absolute; left: -9999em; top: -9999em; padding: 0; margin: 0; line-height: 1; display: inline;',
  2591. TPL_CSS_TEXT_CANVAS = 'display: inline-block; position: relative; clip: rect(0 {1} {0} 0); overflow: hidden; height: {0}; width: {1};',
  2592. TPL_CSS_TEXT_ELEMENT = 'position: absolute; left: 0; top: 0; height: {0}; width: {1};',
  2593. TO_LOWER_CASE = String.prototype.toLowerCase,
  2594. TO_UPPER_CASE = String.prototype.toUpperCase,
  2595. ZOOM = 10;
  2596. DOC.createStyleSheet().addRule('.rvml', 'behavior:url(#default#VML)');
  2597. try {
  2598. if (!DOC.namespaces.rvml) {
  2599. DOC.namespaces.add('rvml', 'urn:schemas-microsoft-com:vml');
  2600. }
  2601. Util.CREATE_ELEMENT = function(tagName) {
  2602. return DOC.createElement('<rvml:' + tagName + ' class="rvml">');
  2603. };
  2604. } catch (e) {
  2605. Util.CREATE_ELEMENT = function(tagName) {
  2606. return DOC.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">');
  2607. };
  2608. }
  2609. Util.path2vml = function(path) {
  2610. var total = /[ahqstv]/ig;
  2611. var command = Util.pathToAbsolute;
  2612. var res;
  2613. if (String(path).match(total)) {
  2614. command = Util.path2curve;
  2615. }
  2616. total = /[clmz]/g;
  2617. if (command == Util.pathToAbsolute && !String(path).match(total)) {
  2618. res = String(path).replace(
  2619. REGEX_VML_BITES,
  2620. function(all, command, args) {
  2621. var vals = [];
  2622. var isMove = TO_LOWER_CASE.call(command) == 'm';
  2623. var res = MAP_COMMAND_VML[command];
  2624. args.replace(
  2625. REGEX_VML_VAL,
  2626. function(value) {
  2627. if (isMove && vals.length == 2) {
  2628. res += vals + MAP_COMMAND_VML[command == 'm' ? 'l' : 'L'];
  2629. vals = [];
  2630. }
  2631. vals.push(MATH_ROUND(value * ZOOM));
  2632. }
  2633. );
  2634. return res + vals;
  2635. }
  2636. );
  2637. return res;
  2638. }
  2639. var pa = command(path);
  2640. var p;
  2641. var r;
  2642. res = [];
  2643. for (var i = 0, length = pa.length; i < length; i++) {
  2644. p = pa[i];
  2645. r = TO_LOWER_CASE.call(pa[i][0]);
  2646. if (r == 'z') {
  2647. r = 'x';
  2648. }
  2649. for (var j = 1, pLength = p.length; j < pLength; j++) {
  2650. r += MATH_ROUND(p[j] * ZOOM) + (j != pLength - 1 ? ',' : STR_EMPTY);
  2651. }
  2652. res.push(r);
  2653. }
  2654. return res.join(STR_SPACE);
  2655. };
  2656. Util.rectPath = function(x, y, w, h, r) {
  2657. if (r) {
  2658. return Lang.sub(
  2659. TPL_RECTANGLE_ROUNDED_CORNER,
  2660. [
  2661. x + r,
  2662. y,
  2663. w - r * 2,
  2664. r,
  2665. -r,
  2666. h - r * 2,
  2667. r * 2 - w,
  2668. r * 2 - h
  2669. ]
  2670. );
  2671. }
  2672. else {
  2673. return Lang.sub(
  2674. TPL_RECTANGLE,
  2675. [
  2676. x,
  2677. y,
  2678. w,
  2679. h,
  2680. -w
  2681. ]
  2682. );
  2683. }
  2684. };
  2685. Impl = Drawing.Impl = {
  2686. addGradientFill: function(obj, gradient) {
  2687. obj.attrs = obj.attrs || {};
  2688. var attrs = obj.attrs;
  2689. var fill;
  2690. var type = 'linear';
  2691. var fxfy = '.5 .5';
  2692. var angle;
  2693. obj.attrs.gradient = gradient;
  2694. gradient = String(gradient).replace(REGEX_RADIAL_GRADIENT, function(all, fx, fy) {
  2695. type = 'radial';
  2696. if (fx && fy) {
  2697. fx = parseFloat(fx);
  2698. fy = parseFloat(fy);
  2699. if (MATH_POW(fx - 0.5, 2) + MATH_POW(fy - 0.5, 2) > 0.25) {
  2700. fy = MATH.sqrt(0.25 - MATH_POW(fx - 0.5, 2)) * ((fy > 0.5) * 2 - 1) + 0.5;
  2701. }
  2702. fxfy = fx + STR_SPACE + fy;
  2703. }
  2704. return STR_EMPTY;
  2705. });
  2706. gradient = gradient.split(REGEX_SEPARATOR_GRADIENT);
  2707. if (type == 'linear') {
  2708. angle = gradient.shift();
  2709. angle = -parseFloat(angle);
  2710. if (isNaN(angle)) {
  2711. return null;
  2712. }
  2713. }
  2714. var dots = Util.parseDots(gradient);
  2715. if (!dots) {
  2716. return null;
  2717. }
  2718. obj = obj.shape || obj.node;
  2719. fill = obj.getElementsByTagName(STR_FILL)[0] || Util.CREATE_ELEMENT(STR_FILL);
  2720. if (!fill.parentNode) {
  2721. obj.appendChild(fill);
  2722. }
  2723. if (dots.length) {
  2724. fill.on = true;
  2725. fill.method = 'none';
  2726. fill.color = dots[0].color;
  2727. fill.color2 = dots[dots.length - 1].color;
  2728. var colors = [];
  2729. for (var i = 0, length = dots.length; i < length; i++) {
  2730. if (dots[i].offset) {
  2731. colors.push(dots[i].offset + STR_SPACE + dots[i].color);
  2732. }
  2733. }
  2734. if (fill.colors) {
  2735. fill.colors.value = colors.length ? colors.join() : '0% ' + fill.color;
  2736. }
  2737. if (type == 'radial') {
  2738. fill.type = 'gradientradial';
  2739. fill.focus = '100%';
  2740. fill.focussize = fxfy;
  2741. fill.focusposition = fxfy;
  2742. }
  2743. else {
  2744. fill.type = 'gradient';
  2745. fill.angle = (270 - angle) % 360;
  2746. }
  2747. }
  2748. return 1;
  2749. },
  2750. clear: function() {
  2751. var instance = this;
  2752. instance.canvas.innerHTML = STR_EMPTY;
  2753. instance.span = DOC.createElement('span');
  2754. instance.span.style.cssText = TPL_CSS_TEXT_DEFAULT;
  2755. instance.canvas.appendChild(instance.span);
  2756. instance.bottom = instance.top = null;
  2757. },
  2758. createCanvas: function() {
  2759. var instance = this;
  2760. var contentBox = instance.get('contentBox');
  2761. var x = instance.get('x');
  2762. var y = instance.get('y');
  2763. var width = setDefaultUnit(instance.get('width'));
  2764. var height = setDefaultUnit(instance.get('height'));
  2765. var canvas = DOC.createElement('div');
  2766. instance.set('width', 1e3);
  2767. instance.set('height', 1e3);
  2768. instance.coordsize = ZOOM * 1e3 + STR_SPACE + ZOOM * 1e3;
  2769. instance.coordorigin = '0 0';
  2770. var span = DOC.createElement('span');
  2771. span.style.cssText = TPL_CSS_TEXT_DEFAULT;
  2772. canvas.appendChild(span);
  2773. instance.span = span;
  2774. instance.canvas = canvas;
  2775. var canvasStyle = canvas.style;
  2776. canvas.style.cssText = Lang.sub(TPL_CSS_TEXT_CANVAS, [height, width]);
  2777. contentBox.prepend(canvas);
  2778. },
  2779. createCircle: function(x, y, r) {
  2780. var instance = this;
  2781. var group = Util.CREATE_ELEMENT('group');
  2782. var oval = Util.CREATE_ELEMENT('oval');
  2783. var ovalStyle = oval.style;
  2784. group.style.cssText = Lang.sub(TPL_CSS_TEXT_ELEMENT, [setDefaultUnit(instance.get('height')), setDefaultUnit(instance.get('width'))]);
  2785. group.coordsize = DEFAULT_VML_COORD_SIZE;
  2786. group.coordorigin = instance.coordorigin;
  2787. group.appendChild(oval);
  2788. var circle = new Element(oval, group, instance);
  2789. circle.type = 'circle';
  2790. Impl.setFillAndStroke(
  2791. circle,
  2792. {
  2793. stroke: '#000',
  2794. fill: 'none'
  2795. }
  2796. );
  2797. circle.attrs.cx = x;
  2798. circle.attrs.cy = y;
  2799. circle.attrs.r = r;
  2800. circle.setBox(
  2801. {
  2802. x: x - r,
  2803. y: y - r,
  2804. width: r * 2,
  2805. height: r * 2
  2806. }
  2807. );
  2808. instance.canvas.appendChild(group);
  2809. return circle;
  2810. },
  2811. createEllipse: function(x, y, rx, ry) {
  2812. var instance = this;
  2813. var group = Util.CREATE_ELEMENT('group');
  2814. var oval = Util.CREATE_ELEMENT('oval');
  2815. group.style.cssText = Lang.sub(TPL_CSS_TEXT_ELEMENT, [setDefaultUnit(instance.get('height')), setDefaultUnit(instance.get('width'))]);
  2816. group.coordsize = DEFAULT_VML_COORD_SIZE;
  2817. group.coordorigin = instance.coordorigin;
  2818. group.appendChild(oval);
  2819. var ellipse = new Element(oval, group, instance);
  2820. ellipse.type = 'ellipse';
  2821. Impl.setFillAndStroke(
  2822. ellipse,
  2823. {
  2824. stroke: '#000'
  2825. }
  2826. );
  2827. ellipse.attrs.cx = x;
  2828. ellipse.attrs.cy = y;
  2829. ellipse.attrs.rx = rx;
  2830. ellipse.attrs.ry = ry;
  2831. ellipse.setBox(
  2832. {
  2833. x: x - rx,
  2834. y: y - ry,
  2835. width: rx * 2,
  2836. height: ry * 2
  2837. }
  2838. );
  2839. instance.canvas.appendChild(group);
  2840. return ellipse;
  2841. },
  2842. createImage: function(src, x, y, w, h) {
  2843. var instance = this;
  2844. var group = Util.CREATE_ELEMENT('group');
  2845. var oval = Util.CREATE_ELEMENT('image');
  2846. var ovalStyle = oval.style;
  2847. group.style.cssText = Lang.sub(TPL_CSS_TEXT_ELEMENT, [setDefaultUnit(instance.get('height')), setDefaultUnit(instance.get('width'))]);
  2848. group.coordsize = DEFAULT_VML_COORD_SIZE;
  2849. group.coordorigin = instance.coordorigin;
  2850. oval.src = src;
  2851. group.appendChild(oval);
  2852. var ellipse = new Element(oval, group, instance);
  2853. ellipse.type = 'image';
  2854. ellipse.attrs.src = src;
  2855. ellipse.attrs.x = x;
  2856. ellipse.attrs.y = y;
  2857. ellipse.attrs.w = w;
  2858. ellipse.attrs.h = h;
  2859. ellipse.setBox(
  2860. {
  2861. x: x,
  2862. y: y,
  2863. width: w,
  2864. height: h
  2865. }
  2866. );
  2867. instance.canvas.appendChild(group);
  2868. return ellipse;
  2869. },
  2870. createPath: function(pathString) {
  2871. var instance = this;
  2872. var group = Util.CREATE_ELEMENT('group');
  2873. group.style.cssText = Lang.sub(TPL_CSS_TEXT_ELEMENT, [setDefaultUnit(instance.get('height')), setDefaultUnit(instance.get('width'))]);
  2874. group.coordsize = instance.coordsize;
  2875. group.coordorigin = instance.coordorigin;
  2876. var el = Util.CREATE_ELEMENT('shape');
  2877. var shapeStyle = el.style;
  2878. shapeStyle.width = instance.get('width') + 'px';
  2879. shapeStyle.height = instance.get('height') + 'px';
  2880. el.coordsize = DEFAULT_VML_COORD_SIZE;
  2881. el.coordorigin = instance.coordorigin;
  2882. group.appendChild(el);
  2883. var path = new Element(el, group, instance);
  2884. var attr = {
  2885. fill: 'none',
  2886. stroke: '#000'
  2887. };
  2888. if (pathString) {
  2889. attr.path = pathString;
  2890. }
  2891. path.isAbsolute = true;
  2892. path.type = 'path';
  2893. path.path = [];
  2894. path.Path = STR_EMPTY;
  2895. Impl.setFillAndStroke(path, attr);
  2896. instance.canvas.appendChild(group);
  2897. return path;
  2898. },
  2899. createRectangle: function(x, y, w, h, r) {
  2900. var instance = this;
  2901. var path = Util.rectPath(x, y, w, h, r);
  2902. var rect = instance.path(path);
  2903. var attrs = rect.attrs;
  2904. rect.X = attrs.x = x;
  2905. rect.Y = attrs.y = y;
  2906. rect.W = attrs.width = w;
  2907. rect.H = attrs.height = h;
  2908. attrs.r = r;
  2909. attrs.path = path;
  2910. rect.type = 'rect';
  2911. return rect;
  2912. },
  2913. createText: function(x, y, text) {
  2914. var instance = this;
  2915. var group = Util.CREATE_ELEMENT('group');
  2916. var el = Util.CREATE_ELEMENT('shape');
  2917. var shapeStyle = el.style;
  2918. var path = Util.CREATE_ELEMENT('path');
  2919. var ps = path.style;
  2920. var textpath = Util.CREATE_ELEMENT('textpath');
  2921. var width = setDefaultUnit(instance.get('width'));
  2922. var height = setDefaultUnit(instance.get('height'));
  2923. group.style.cssText = Lang.sub(TPL_CSS_TEXT_ELEMENT, [height, width]);
  2924. group.coordsize = DEFAULT_VML_COORD_SIZE;
  2925. group.coordorigin = instance.coordorigin;
  2926. path.v = Lang.sub(
  2927. 'm{0},{1}l{2},{1}',
  2928. [
  2929. MATH_ROUND(x * 10),
  2930. MATH_ROUND(y * 10),
  2931. MATH_ROUND(x * 10) + 1
  2932. ]
  2933. );
  2934. path.textpathok = true;
  2935. shapeStyle.width = width;
  2936. shapeStyle.height = height;
  2937. textpath.string = String(text);
  2938. textpath.on = true;
  2939. el.appendChild(textpath);
  2940. el.appendChild(path);
  2941. group.appendChild(el);
  2942. var textElement = new Element(textpath, group, instance);
  2943. textElement.shape = el;
  2944. textElement.textpath = path;
  2945. textElement.type = 'text';
  2946. textElement.attrs.text = text;
  2947. textElement.attrs.x = x;
  2948. textElement.attrs.y = y;
  2949. textElement.attrs.w = 1;
  2950. textElement.attrs.h = 1;
  2951. Impl.setFillAndStroke(
  2952. textElement,
  2953. {
  2954. font: MAP_ATTRS_AVAILABLE.font,
  2955. stroke: 'none',
  2956. fill: '#000'
  2957. }
  2958. );
  2959. textElement.setBox();
  2960. instance.canvas.appendChild(group);
  2961. return textElement;
  2962. },
  2963. remove: function() {
  2964. var instance = this;
  2965. instance.canvas.parentNode.removeChild(instance.canvas);
  2966. for (var i in instance) {
  2967. if (DRAWING_PROTOTYPE.hasOwnProperty(i)) {
  2968. instance[i] = Util.removed(i);
  2969. }
  2970. }
  2971. return true;
  2972. },
  2973. setFillAndStroke: function(obj, params) {
  2974. obj.attrs = obj.attrs || {};
  2975. var node = obj.node;
  2976. var a = obj.attrs;
  2977. var nodeStyle = node.style;
  2978. var xy;
  2979. var newpath = (params.x != a.x || params.y != a.y || params.width != a.width || params.height != a.height || params.r != a.r) && obj.type == 'rect';
  2980. var res = obj;
  2981. for (var par in params) {
  2982. if (params.hasOwnProperty(par)) {
  2983. a[par] = params[par];
  2984. }
  2985. }
  2986. if (newpath) {
  2987. a.path = Util.rectPath(a.x, a.y, a.width, a.height, a.r);
  2988. obj.X = a.x;
  2989. obj.Y = a.y;
  2990. obj.W = a.width;
  2991. obj.H = a.height;
  2992. }
  2993. if (params.href) {
  2994. node.href = params.href;
  2995. }
  2996. if (params.title) {
  2997. node.title = params.title;
  2998. }
  2999. if (params.target) {
  3000. node.target = params.target;
  3001. }
  3002. if (params.cursor) {
  3003. nodeStyle.cursor = params.cursor;
  3004. }
  3005. if ('blur' in params) {
  3006. obj.blur(params.blur);
  3007. }
  3008. if (params.path && obj.type == 'path' || newpath) {
  3009. node.path = Util.path2vml(a.path);
  3010. }
  3011. if (params.rotation != null) {
  3012. obj.rotate(params.rotation, true);
  3013. }
  3014. if (params.translation) {
  3015. xy = String(params.translation).split(REGEX_SEPARATOR);
  3016. Util.translate.call(obj, xy[0], xy[1]);
  3017. if (obj._.rt.cx != null) {
  3018. obj._.rt.cx +=+ xy[0];
  3019. obj._.rt.cy +=+ xy[1];
  3020. obj.setBox(obj.attrs, xy[0], xy[1]);
  3021. }
  3022. }
  3023. if (params.scale) {
  3024. xy = String(params.scale).split(REGEX_SEPARATOR);
  3025. obj.scale(+xy[0] || 1, +xy[1] || +xy[0] || 1, +xy[2] || null, +xy[3] || null);
  3026. }
  3027. if ('clip-rect' in params) {
  3028. var rect = String(params['clip-rect']).split(REGEX_SEPARATOR);
  3029. if (rect.length == 4) {
  3030. rect[2] = +rect[2] + (+rect[0]);
  3031. rect[3] = +rect[3] + (+rect[1]);
  3032. var div = node.clipRect || DOC.createElement('div');
  3033. var dstyle = div.style;
  3034. var group = node.parentNode;
  3035. dstyle.clip = Lang.sub('rect({1}px {2}px {3}px {0}px)', rect);
  3036. if (!node.clipRect) {
  3037. dstyle.position = 'absolute';
  3038. dstyle.top = 0;
  3039. dstyle.left = 0;
  3040. dstyle.width = obj.paper.get('width') + 'px';
  3041. dstyle.height = obj.paper.get('height') + 'px';
  3042. group.parentNode.insertBefore(div, group);
  3043. div.appendChild(group);
  3044. node.clipRect = div;
  3045. }
  3046. }
  3047. if (!params['clip-rect'] && node.clipRect) {
  3048. node.clipRect.style.clip = STR_EMPTY;
  3049. }
  3050. }
  3051. if (obj.type == 'image' && params.src) {
  3052. node.src = params.src;
  3053. }
  3054. if (obj.type == 'image' && params.opacity) {
  3055. node.filterOpacity = STR_MS_PROG_ID_PREFIX + '.Alpha(opacity=' + (params.opacity * 100) + ')';
  3056. nodeStyle.filter = (node.filterMatrix || STR_EMPTY) + (node.filterOpacity || STR_EMPTY);
  3057. }
  3058. if (params.font) {
  3059. nodeStyle.font = params.font;
  3060. }
  3061. if (params['font-family']) {
  3062. nodeStyle.fontFamily = '"' + params['font-family'].split(',')[0].replace(/^['"]+|['"]+$/g, STR_EMPTY) + '"';
  3063. }
  3064. if (params['font-size']) {
  3065. nodeStyle.fontSize = params['font-size'];
  3066. }
  3067. if (params['font-weight']) {
  3068. nodeStyle.fontWeight = params['font-weight'];
  3069. }
  3070. if (params['font-style']) {
  3071. nodeStyle.fontStyle = params['font-style'];
  3072. }
  3073. if (params.opacity != null ||
  3074. params['stroke-width'] != null ||
  3075. params.fill != null ||
  3076. params.stroke != null ||
  3077. params['stroke-width'] != null ||
  3078. params['stroke-opacity'] != null ||
  3079. params['fill-opacity'] != null ||
  3080. params['stroke-dasharray'] != null ||
  3081. params['stroke-miterlimit'] != null ||
  3082. params['stroke-linejoin'] != null ||
  3083. params['stroke-linecap'] != null) {
  3084. node = obj.shape || node;
  3085. var fill = (node.getElementsByTagName(STR_FILL) && node.getElementsByTagName(STR_FILL)[0]);
  3086. var newfill = false;
  3087. var opacity;
  3088. if (!fill) {
  3089. newfill = fill = Util.CREATE_ELEMENT(STR_FILL);
  3090. }
  3091. if ('fill-opacity' in params || 'opacity' in params) {
  3092. opacity = ((+a['fill-opacity'] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+ColorUtil.getRGB(params.fill).o + 1 || 2) - 1);
  3093. if (opacity < 0) {
  3094. opacity = 0;
  3095. }
  3096. else if (opacity > 1) {
  3097. opacity = 1;
  3098. }
  3099. fill.opacity = opacity;
  3100. }
  3101. if (params.fill) {
  3102. fill.on = true;
  3103. }
  3104. if (fill.on == null || params.fill == 'none') {
  3105. fill.on = false;
  3106. }
  3107. if (fill.on && params.fill) {
  3108. var isURL = params.fill.match(REGEX_ISURL);
  3109. if (isURL) {
  3110. fill.src = isURL[1];
  3111. fill.type = 'tile';
  3112. }
  3113. else {
  3114. var fillColor = ColorUtil.getRGB(params.fill);
  3115. fill.color = fillColor.hex;
  3116. fill.src = STR_EMPTY;
  3117. fill.type = 'solid';
  3118. if (
  3119. fillColor.error &&
  3120. (res.type in MAP_TYPES_CIRCLE_ELLIPSE || String(params.fill).charAt(0) != 'r') &&
  3121. Impl.addGradientFill(res, params.fill)
  3122. ) {
  3123. a.fill = 'none';
  3124. a.gradient = params.fill;
  3125. }
  3126. }
  3127. }
  3128. if (newfill) {
  3129. node.appendChild(fill);
  3130. }
  3131. var stroke = (node.getElementsByTagName('stroke') && node.getElementsByTagName('stroke')[0]);
  3132. var newstroke = false;
  3133. if (!stroke) {
  3134. newstroke = stroke = Util.CREATE_ELEMENT('stroke');
  3135. }
  3136. if ((params.stroke && params.stroke != 'none') ||
  3137. params['stroke-width'] ||
  3138. params['stroke-opacity'] != null ||
  3139. params['stroke-dasharray'] ||
  3140. params['stroke-miterlimit'] ||
  3141. params['stroke-linejoin'] ||
  3142. params['stroke-linecap']) {
  3143. stroke.on = true;
  3144. }
  3145. if (params.stroke == 'none' || stroke.on == null || params.stroke == 0 || params['stroke-width'] == 0) {
  3146. stroke.on = false;
  3147. }
  3148. var strokeColor = ColorUtil.getRGB(params.stroke);
  3149. if (stroke.on && params.stroke) {
  3150. stroke.color = strokeColor.hex;
  3151. }
  3152. opacity = ((+a['stroke-opacity'] + 1 || 2) - 1) * ((+a.opacity + 1 || 2) - 1) * ((+strokeColor.o + 1 || 2) - 1);
  3153. var width = (parseFloat(params['stroke-width']) || 1) * 0.75;
  3154. if (opacity < 0) {
  3155. opacity = 0;
  3156. }
  3157. else if (opacity > 1) {
  3158. opacity = 1;
  3159. }
  3160. if (params['stroke-width'] == null) {
  3161. width = a['stroke-width'];
  3162. }
  3163. if (params['stroke-width']) {
  3164. stroke.weight = width;
  3165. }
  3166. if (width && width < 1 && (opacity *= width)) {
  3167. stroke.weight = 1;
  3168. }
  3169. stroke.opacity = opacity;
  3170. if (params['stroke-linejoin']) {
  3171. stroke.joinstyle = params['stroke-linejoin'] || 'miter';
  3172. }
  3173. stroke.miterlimit = params['stroke-miterlimit'] || 8;
  3174. var paramStrokeLinecap = params['stroke-linecap'];
  3175. if (paramStrokeLinecap) {
  3176. stroke.endcap = 'round';
  3177. if (paramStrokeLinecap == 'butt') {
  3178. stroke.endcap = 'flat';
  3179. }
  3180. else if (paramStrokeLinecap == 'square') {
  3181. stroke.endcap = paramStrokeLinecap;
  3182. }
  3183. }
  3184. var paramStrokeDashArray = params['stroke-dasharray'];
  3185. if (paramStrokeDashArray) {
  3186. stroke.dashstyle = STR_EMPTY;
  3187. if (MAP_KEYWORDS_VML_STROKE_DASH_ARRAY.hasOwnProperty(paramStrokeDashArray)) {
  3188. stroke.dashstyle = MAP_KEYWORDS_VML_STROKE_DASH_ARRAY[params['stroke-dasharray']];
  3189. }
  3190. }
  3191. if (newstroke) {
  3192. node.appendChild(stroke);
  3193. }
  3194. }
  3195. if (res.type == 'text') {
  3196. nodeStyle = res.paper.span.style;
  3197. if (a.font) {
  3198. nodeStyle.font = a.font;
  3199. }
  3200. if (a['font-family']) {
  3201. nodeStyle.fontFamily = a['font-family'];
  3202. }
  3203. if (a['font-size']) {
  3204. nodeStyle.fontSize = a['font-size'];
  3205. }
  3206. if (a['font-weight']) {
  3207. nodeStyle.fontWeight = a['font-weight'];
  3208. }
  3209. if (a['font-style']) {
  3210. nodeStyle.fontStyle = a['font-style'];
  3211. }
  3212. if (res.node.string) {
  3213. res.paper.span.innerHTML = String(res.node.string).replace(/</g, '&#60;').replace(/&/g, '&#38;').replace(/\n/g, '<br>');
  3214. }
  3215. res.W = a.w = res.paper.span.offsetWidth;
  3216. res.H = a.h = res.paper.span.offsetHeight;
  3217. res.X = a.x;
  3218. res.Y = a.y + MATH_ROUND(res.H / 2);
  3219. // text-anchor emulation
  3220. switch (a['text-anchor']) {
  3221. case 'start':
  3222. res.node.style['v-text-align'] = 'left';
  3223. res.bbx = MATH_ROUND(res.W / 2);
  3224. break;
  3225. case 'end':
  3226. res.node.style['v-text-align'] = 'right';
  3227. res.bbx = -MATH_ROUND(res.W / 2);
  3228. break;
  3229. default:
  3230. res.node.style['v-text-align'] = 'center';
  3231. break;
  3232. }
  3233. }
  3234. }
  3235. };
  3236. ELEMENT_PROTOTYPE.createElement = function(node, group, drawing) {
  3237. var instance = this;
  3238. instance[0] = node;
  3239. instance.id = A.guid();
  3240. instance.node = node;
  3241. instance.X = 0;
  3242. instance.Y = 0;
  3243. instance.attrs = {};
  3244. instance.Group = group;
  3245. instance.paper = drawing;
  3246. instance._ = {
  3247. tx: 0,
  3248. ty: 0,
  3249. rt: {
  3250. deg: 0
  3251. },
  3252. sx: 1,
  3253. sy: 1
  3254. };
  3255. if (!drawing.bottom) {
  3256. drawing.bottom = instance;
  3257. }
  3258. instance.prev = drawing.top;
  3259. if (drawing.top) {
  3260. drawing.top.next = instance;
  3261. }
  3262. drawing.top = instance;
  3263. instance.next = null;
  3264. };
  3265. ELEMENT_PROTOTYPE.rotate = function(deg, cx, cy) {
  3266. if (this.removed) {
  3267. return this;
  3268. }
  3269. if (deg == null) {
  3270. if (this._.rt.cx) {
  3271. return [
  3272. this._.rt.deg,
  3273. this._.rt.cx,
  3274. this._.rt.cy
  3275. ].join(STR_SPACE);
  3276. }
  3277. return this._.rt.deg;
  3278. }
  3279. deg = String(deg).split(REGEX_SEPARATOR);
  3280. if (deg.length - 1) {
  3281. cx = parseFloat(deg[1]);
  3282. cy = parseFloat(deg[2]);
  3283. }
  3284. deg = parseFloat(deg[0]);
  3285. if (cx != null) {
  3286. this._.rt.deg = deg;
  3287. }
  3288. else {
  3289. this._.rt.deg += deg;
  3290. }
  3291. if (cy == null) {
  3292. cx = null;
  3293. }
  3294. this._.rt.cx = cx;
  3295. this._.rt.cy = cy;
  3296. this.setBox(this.attrs, cx, cy);
  3297. this.Group.style.rotation = this._.rt.deg;
  3298. // gradient fix for rotation. TODO
  3299. // var fill = (this.shape || this.node).getElementsByTagName(STR_FILL);
  3300. // fill = fill[0] || {};
  3301. // var b = ((360 - this._.rt.deg) - 270) % 360;
  3302. // !R.is(fill.angle, "undefined") && (fill.angle = b);
  3303. return this;
  3304. };
  3305. ELEMENT_PROTOTYPE.setBox = function(params, cx, cy) {
  3306. if (this.removed) {
  3307. return this;
  3308. }
  3309. var gs = this.Group.style;
  3310. var os = (this.shape && this.shape.style) || this.node.style;
  3311. params = params || {};
  3312. for (var i in params) {
  3313. if (params.hasOwnProperty(i)) {
  3314. this.attrs[i] = params[i];
  3315. }
  3316. }
  3317. cx = cx || this._.rt.cx;
  3318. cy = cy || this._.rt.cy;
  3319. var attr = this.attrs;
  3320. var x;
  3321. var y;
  3322. var w;
  3323. var h;
  3324. switch (this.type) {
  3325. case 'circle':
  3326. x = attr.cx - attr.r;
  3327. y = attr.cy - attr.r;
  3328. w = h = attr.r * 2;
  3329. break;
  3330. case 'ellipse':
  3331. x = attr.cx - attr.rx;
  3332. y = attr.cy - attr.ry;
  3333. w = attr.rx * 2;
  3334. h = attr.ry * 2;
  3335. break;
  3336. case 'image':
  3337. x = +attr.x;
  3338. y = +attr.y;
  3339. w = attr.width || 0;
  3340. h = attr.height || 0;
  3341. break;
  3342. case 'text':
  3343. this.textpath.v = [
  3344. 'm', MATH_ROUND(attr.x),
  3345. ', ',
  3346. MATH_ROUND(attr.y - 2),
  3347. 'l',
  3348. MATH_ROUND(attr.x) + 1,
  3349. ', ',
  3350. MATH_ROUND(attr.y - 2)
  3351. ].join(STR_EMPTY);
  3352. x = attr.x - MATH_ROUND(this.W / 2);
  3353. y = attr.y - this.H / 2;
  3354. w = this.W;
  3355. h = this.H;
  3356. break;
  3357. case 'rect':
  3358. case 'path':
  3359. if (!this.attrs.path) {
  3360. x = 0;
  3361. y = 0;
  3362. w = this.paper.get('width');
  3363. h = this.paper.get('height');
  3364. }
  3365. else {
  3366. var dim = Util.pathDimensions(this.attrs.path);
  3367. x = dim.x;
  3368. y = dim.y;
  3369. w = dim.width;
  3370. h = dim.height;
  3371. }
  3372. break;
  3373. default:
  3374. x = 0;
  3375. y = 0;
  3376. w = this.paper.get('width');
  3377. h = this.paper.get('height');
  3378. break;
  3379. }
  3380. cx = (cx == null) ? x + w / 2 : cx;
  3381. cy = (cy == null) ? y + h / 2 : cy;
  3382. var paperWidth = this.paper.get('width');
  3383. var paperHeight = this.paper.get('height');
  3384. var left = cx - paperWidth / 2;
  3385. var top = cy - paperHeight / 2;
  3386. var t;
  3387. if (gs.left != (t = left + 'px')) {
  3388. gs.left = t;
  3389. }
  3390. if (gs.top != (t = top + 'px')) {
  3391. gs.top = t;
  3392. }
  3393. this.X = MAP_PATH_LIKE.hasOwnProperty(this.type) ? -left : x;
  3394. this.Y = MAP_PATH_LIKE.hasOwnProperty(this.type) ? -top : y;
  3395. this.W = w;
  3396. this.H = h;
  3397. if (MAP_PATH_LIKE.hasOwnProperty(this.type)) {
  3398. if (os.left != (t = -left * ZOOM + 'px')) {
  3399. os.left = t;
  3400. }
  3401. if (os.top != (t = -top * ZOOM + 'px')) {
  3402. os.top = t;
  3403. }
  3404. }
  3405. else if (this.type == 'text') {
  3406. if (os.left != (t = -left + 'px')) {
  3407. os.left = t;
  3408. }
  3409. if (os.top != (t = -top + 'px')) {
  3410. os.top = t;
  3411. }
  3412. }
  3413. else {
  3414. if (gs.width != (t = paperWidth + 'px')) {
  3415. gs.width = t;
  3416. }
  3417. if (gs.height != (t = paperHeight + 'px')) {
  3418. gs.height = t;
  3419. }
  3420. if (os.left != (t = x - left + 'px')) {
  3421. os.left = t;
  3422. }
  3423. if (os.top != (t = y - top + 'px')) {
  3424. os.top = t;
  3425. }
  3426. if (os.width != (t = w + 'px')) {
  3427. os.width = t;
  3428. }
  3429. if (os.height != (t = h + 'px')) {
  3430. os.height = t;
  3431. }
  3432. }
  3433. };
  3434. ELEMENT_PROTOTYPE.hide = function() {
  3435. if (!this.removed) {
  3436. this.Group.style.display = 'none';
  3437. }
  3438. return this;
  3439. };
  3440. ELEMENT_PROTOTYPE.show = function() {
  3441. if (!this.removed) {
  3442. this.Group.style.display = 'block';
  3443. }
  3444. return this;
  3445. };
  3446. ELEMENT_PROTOTYPE.getRegion = function() {
  3447. if (this.removed) {
  3448. return this;
  3449. }
  3450. if (MAP_PATH_LIKE.hasOwnProperty(this.type)) {
  3451. return Util.pathDimensions(this.attrs.path);
  3452. }
  3453. return {
  3454. x: this.X + (this.bbx || 0),
  3455. y: this.Y,
  3456. width: this.W,
  3457. height: this.H
  3458. };
  3459. };
  3460. ELEMENT_PROTOTYPE.remove = function() {
  3461. if (this.removed) {
  3462. return;
  3463. }
  3464. Util.tear(this, this.paper);
  3465. this.node.parentNode.removeChild(this.node);
  3466. this.Group.parentNode.removeChild(this.Group);
  3467. if (this.shape) {
  3468. this.shape.parentNode.removeChild(this.shape);
  3469. }
  3470. for (var i in this) {
  3471. delete this[i];
  3472. }
  3473. this.removed = true;
  3474. };
  3475. ELEMENT_PROTOTYPE.attr = function(name, value) {
  3476. var instance = this;
  3477. if (instance.removed) {
  3478. return instance;
  3479. }
  3480. var i;
  3481. if (name == null) {
  3482. var res = {};
  3483. for (i in instance.attrs) {
  3484. if (instance.attrs.hasOwnProperty(i)) {
  3485. res[i] = instance.attrs[i];
  3486. }
  3487. }
  3488. if (instance._.rt.deg) {
  3489. res.rotation = instance.rotate();
  3490. }
  3491. if (instance._.sx != 1 || instance._.sy != 1) {
  3492. res.scale = instance.scale();
  3493. }
  3494. if (res.gradient && res.fill == 'none') {
  3495. res.fill = res.gradient;
  3496. delete res.gradient;
  3497. }
  3498. return res;
  3499. }
  3500. if (value == null && isString(name)) {
  3501. if (name == 'translation') {
  3502. return Util.translate.call(instance);
  3503. }
  3504. if (name == 'rotation') {
  3505. return instance.rotate();
  3506. }
  3507. if (name == 'scale') {
  3508. return instance.scale();
  3509. }
  3510. if (name == STR_FILL && instance.attrs.fill == 'none' && instance.attrs.gradient) {
  3511. return instance.attrs.gradient;
  3512. }
  3513. return instance.attrs[name];
  3514. }
  3515. if (instance.attrs && value == null && isArray(name)) {
  3516. var length;
  3517. var values = {};
  3518. for (i = 0, length = name.length; i < length; i++) {
  3519. values[name[i]] = instance.attr(name[i]);
  3520. }
  3521. return values;
  3522. }
  3523. var params = Util.applyAttributes(instance, name, value);
  3524. if (params) {
  3525. if (params.text && instance.type == 'text') {
  3526. instance.node.string = params.text;
  3527. }
  3528. Impl.setFillAndStroke(instance, params);
  3529. if (
  3530. params.gradient &&
  3531. ((MAP_TYPES_CIRCLE_ELLIPSE).hasOwnProperty(instance.type) || String(params.gradient).charAt(0) != 'r')
  3532. ) {
  3533. Impl.addGradientFill(instance, params.gradient);
  3534. }
  3535. if (!MAP_PATH_LIKE.hasOwnProperty(instance.type) || instance._.rt.deg) {
  3536. instance.setBox(instance.attrs);
  3537. }
  3538. }
  3539. return instance;
  3540. };
  3541. ELEMENT_PROTOTYPE.toFront = function() {
  3542. if (!this.removed) {
  3543. this.Group.parentNode.appendChild(this.Group);
  3544. }
  3545. if (this.paper.top != this) {
  3546. Util.toFront(this, this.paper);
  3547. }
  3548. return this;
  3549. };
  3550. ELEMENT_PROTOTYPE.toBack = function() {
  3551. if (this.removed) {
  3552. return this;
  3553. }
  3554. if (this.Group.parentNode.firstChild != this.Group) {
  3555. this.Group.parentNode.insertBefore(this.Group, this.Group.parentNode.firstChild);
  3556. Util.toBack(this, this.paper);
  3557. }
  3558. return this;
  3559. };
  3560. ELEMENT_PROTOTYPE.insertAfter = function(element) {
  3561. if (this.removed) {
  3562. return this;
  3563. }
  3564. if (element instanceof Drawing.Set) {
  3565. element = element.item(element.size());
  3566. }
  3567. if (element.Group.nextSibling) {
  3568. element.Group.parentNode.insertBefore(this.Group, element.Group.nextSibling);
  3569. }
  3570. else {
  3571. element.Group.parentNode.appendChild(this.Group);
  3572. }
  3573. Util.insertAfter(this, element, this.paper);
  3574. return this;
  3575. };
  3576. ELEMENT_PROTOTYPE.insertBefore = function(element) {
  3577. if (this.removed) {
  3578. return this;
  3579. }
  3580. if (element instanceof Drawing.Set) {
  3581. element = element.item(0);
  3582. }
  3583. element.Group.parentNode.insertBefore(this.Group, element.Group);
  3584. Util.insertBefore(this, element, this.paper);
  3585. return this;
  3586. };
  3587. ELEMENT_PROTOTYPE.blur = function(size) {
  3588. var s = this.node.runtimeStyle;
  3589. var f = s.filter;
  3590. f = f.replace(REGEX_VML_BLUR, STR_EMPTY);
  3591. if (+size !== 0) {
  3592. this.attrs.blur = size;
  3593. s.filter = f + STR_SPACE + STR_MS_PROG_ID_PREFIX + '.Blur(pixelradius=' + (+size || 1.5) + ')';
  3594. s.margin = Lang.sub('-{0}px 0 0 -{0}px', [MATH_ROUND(+size || 1.5)]);
  3595. }
  3596. else {
  3597. s.filter = f;
  3598. s.margin = 0;
  3599. delete this.attrs.blur;
  3600. }
  3601. };
  3602. // We need to not sync the width and height of the boundingBox
  3603. DRAWING_PROTOTYPE._SYNC_UI_ATTRS = DRAWING_PROTOTYPE._SYNC_UI_ATTRS.join(',').replace(/,(height|width)/g, '').split(',');
  3604. DRAWING_PROTOTYPE._uiSetWidth = function(value) {
  3605. var instance = this;
  3606. Drawing.superclass._uiSetWidth.apply(instance, arguments);
  3607. var canvasStyle = instance.canvas.style;
  3608. var height = instance.get('height');
  3609. if (isNumber(value)) {
  3610. value += 'px';
  3611. }
  3612. if (isNumber(height)) {
  3613. height += 'px';
  3614. }
  3615. canvasStyle.width = value;
  3616. canvasStyle.clip = 'rect(0 ' + value + ' ' + height + ' 0)';
  3617. };
  3618. DRAWING_PROTOTYPE._uiSetHeight = function(value) {
  3619. var instance = this;
  3620. Drawing.superclass._uiSetHeight.apply(instance, arguments);
  3621. var canvasStyle = instance.canvas.style;
  3622. var width = instance.get('width');
  3623. if (isNumber(value)) {
  3624. value += 'px';
  3625. }
  3626. if (isNumber(width)) {
  3627. width += 'px';
  3628. }
  3629. canvasStyle.height = value;
  3630. canvasStyle.clip = 'rect(0 ' + width + ' ' + value + ' 0)';
  3631. };
  3632. }, '@VERSION@' ,{requires:['aui-drawing-base'], condition: {name: 'aui-drawing-vml', trigger: 'aui-drawing-base',test: function(A){return A.UA.vml;}}});
  3633. AUI.add('aui-drawing-animate', function(A) {
  3634. var Lang = A.Lang,
  3635. isFunction = Lang.isFunction,
  3636. isString = Lang.isString,
  3637. ColorUtil = A.ColorUtil,
  3638. Drawing = A.Drawing,
  3639. Element = Drawing.Element,
  3640. Set = Drawing.Set,
  3641. Util = Drawing.Util,
  3642. ELEMENT_PROTOTYPE = Element.prototype,
  3643. MAP_ATTRS_AVAILABLE = Drawing.MAP_ATTRS_AVAILABLE,
  3644. MATH = Math,
  3645. MATH_ABS = MATH.abs,
  3646. MATH_MAX = MATH.max,
  3647. MATH_MIN = MATH.min,
  3648. MATH_POW = MATH.pow,
  3649. MATH_ROUND = MATH.round,
  3650. REGEX_ANIMATE_KEYFRAMES = /^(from|to|\d+%)$/,
  3651. REGEX_BEZIER = /^cubic-bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
  3652. REGEX_SEPARATOR = Drawing.REGEX_SEPARATOR,
  3653. STR_EMPTY = Drawing.STR_EMPTY,
  3654. STR_SPACE = Drawing.STR_SPACE,
  3655. STR_NUMBER = 'number',
  3656. MAP_ATTRS_AVAILABLE_ANIM = {
  3657. along: 'along',
  3658. blur: STR_NUMBER,
  3659. 'clip-rect': 'csv',
  3660. cx: STR_NUMBER,
  3661. cy: STR_NUMBER,
  3662. fill: 'color',
  3663. 'fill-opacity': STR_NUMBER,
  3664. 'font-size': STR_NUMBER,
  3665. height: STR_NUMBER,
  3666. opacity: STR_NUMBER,
  3667. path: 'path',
  3668. r: STR_NUMBER,
  3669. rotation: 'csv',
  3670. rx: STR_NUMBER,
  3671. ry: STR_NUMBER,
  3672. scale: 'csv',
  3673. stroke: 'color',
  3674. 'stroke-opacity': STR_NUMBER,
  3675. 'stroke-width': STR_NUMBER,
  3676. translation: 'csv',
  3677. width: STR_NUMBER,
  3678. x: STR_NUMBER,
  3679. y: STR_NUMBER
  3680. };
  3681. var Animation = Drawing.Animation = {};
  3682. Animation.easing_formulas = {
  3683. linear: function(n) {
  3684. return n;
  3685. },
  3686. '<': function(n) {
  3687. return MATH_POW(n, 3);
  3688. },
  3689. '>': function(n) {
  3690. return MATH_POW(n - 1, 3) + 1;
  3691. },
  3692. '<>': function(n) {
  3693. n = n * 2;
  3694. if (n < 1) {
  3695. return MATH_POW(n, 3) / 2;
  3696. }
  3697. n -= 2;
  3698. return (MATH_POW(n, 3) + 2) / 2;
  3699. },
  3700. backIn: function(n) {
  3701. var s = 1.70158;
  3702. return n * n * ((s + 1) * n - s);
  3703. },
  3704. backOut: function(n) {
  3705. n = n - 1;
  3706. var s = 1.70158;
  3707. return n * n * ((s + 1) * n + s) + 1;
  3708. },
  3709. elastic: function(n) {
  3710. if (n == 0 || n == 1) {
  3711. return n;
  3712. }
  3713. var p = 0.3;
  3714. var s = p / 4;
  3715. return MATH_POW(2, -10 * n) * MATH.sin((n - s) * (2 * MATH.PI) / p) + 1;
  3716. },
  3717. bounce: function(n) {
  3718. var s = 7.5625;
  3719. var p = 2.75;
  3720. var l;
  3721. if (n < (1 / p)) {
  3722. l = s * n * n;
  3723. }
  3724. else {
  3725. if (n < (2 / p)) {
  3726. n -= (1.5 / p);
  3727. l = s * n * n + 0.75;
  3728. }
  3729. else {
  3730. if (n < (2.5 / p)) {
  3731. n -= (2.25 / p);
  3732. l = s * n * n + 0.9375;
  3733. }
  3734. else {
  3735. n -= (2.625 / p);
  3736. l = s * n * n + 0.984375;
  3737. }
  3738. }
  3739. }
  3740. return l;
  3741. }
  3742. };
  3743. var animationElements = [];
  3744. Animation.elements = animationElements;
  3745. Animation.animation = function() {
  3746. var Now = +new Date;
  3747. for (var l = 0; l < animationElements.length; l++) {
  3748. if (l != 'length' && animationElements.hasOwnProperty(l)) {
  3749. var e = animationElements[l];
  3750. if (e.stop || e.el.removed) {
  3751. continue;
  3752. }
  3753. var time = Now - e.start;
  3754. var ms = e.ms;
  3755. var easing = e.easing;
  3756. var from = e.from;
  3757. var diff = e.diff;
  3758. var to = e.to;
  3759. var t = e.t;
  3760. var that = e.el;
  3761. var set = {};
  3762. var now;
  3763. if (time < ms) {
  3764. var pos = easing(time / ms);
  3765. for (var attr in from) {
  3766. if (from.hasOwnProperty(attr)) {
  3767. switch (MAP_ATTRS_AVAILABLE_ANIM[attr]) {
  3768. case 'along':
  3769. now = pos * ms * diff[attr];
  3770. to.back && (now = to.len - now);
  3771. var point = getPointAtLength(to[attr], now);
  3772. that.translate(diff.sx - diff.x || 0, diff.sy - diff.y || 0);
  3773. diff.x = point.x;
  3774. diff.y = point.y;
  3775. that.translate(point.x - diff.sx, point.y - diff.sy);
  3776. to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
  3777. break;
  3778. case STR_NUMBER:
  3779. now = +from[attr] + pos * ms * diff[attr];
  3780. break;
  3781. case 'color':
  3782. now = 'rgb(' + [
  3783. upto255(MATH_ROUND(from[attr].r + pos * ms * diff[attr].r)),
  3784. upto255(MATH_ROUND(from[attr].g + pos * ms * diff[attr].g)),
  3785. upto255(MATH_ROUND(from[attr].b + pos * ms * diff[attr].b))
  3786. ].join(',') + ')';
  3787. break;
  3788. case 'path':
  3789. now = [];
  3790. for (var i = 0, length = from[attr].length; i < length; i++) {
  3791. now[i] = [from[attr][i][0]];
  3792. for (var j = 1, jLength = from[attr][i].length; j < jLength; j++) {
  3793. now[i][j] = +from[attr][i][j] + pos * ms * diff[attr][i][j];
  3794. }
  3795. now[i] = now[i].join(STR_SPACE);
  3796. }
  3797. now = now.join(STR_SPACE);
  3798. break;
  3799. case 'csv':
  3800. switch (attr) {
  3801. case 'translation':
  3802. var x = pos * ms * diff[attr][0] - t.x;
  3803. var y = pos * ms * diff[attr][1] - t.y;
  3804. t.x += x;
  3805. t.y += y;
  3806. now = x + STR_SPACE + y;
  3807. break;
  3808. case 'rotation':
  3809. now = +from[attr][0] + pos * ms * diff[attr][0];
  3810. from[attr][1] && (now += ',' + from[attr][1] + ',' + from[attr][2]);
  3811. break;
  3812. case 'scale':
  3813. now = [
  3814. +from[attr][0] + pos * ms * diff[attr][0],
  3815. +from[attr][1] + pos * ms * diff[attr][1],
  3816. (2 in to[attr] ? to[attr][2] : STR_EMPTY),
  3817. (3 in to[attr] ? to[attr][3] : STR_EMPTY)
  3818. ].join(STR_SPACE);
  3819. break;
  3820. case 'clip-rect':
  3821. now = [];
  3822. i = 4;
  3823. while (i--) {
  3824. now[i] = +from[attr][i] + pos * ms * diff[attr][i];
  3825. }
  3826. break;
  3827. }
  3828. break;
  3829. default:
  3830. var from2 = [].concat(from[attr]);
  3831. var now = [];
  3832. i = that.paper.customAttributes[attr].length;
  3833. while (i--) {
  3834. now[i] = +from[i] + pos * ms * diff[attr][i];
  3835. }
  3836. break;
  3837. }
  3838. set[attr] = now;
  3839. }
  3840. }
  3841. that.attr(set);
  3842. that._run && that._run.call(that);
  3843. }
  3844. else {
  3845. if (to.along) {
  3846. point = getPointAtLength(to.along, to.len * !to.back);
  3847. that.translate(diff.sx - (diff.x || 0) + point.x - diff.sx, diff.sy - (diff.y || 0) + point.y - diff.sy);
  3848. to.rot && that.rotate(diff.r + point.alpha, point.x, point.y);
  3849. }
  3850. if (t.x || t.y) {
  3851. that.translate(-t.x, -t.y);
  3852. }
  3853. if (to.scale) {
  3854. to.scale += STR_EMPTY;
  3855. }
  3856. that.attr(to);
  3857. animationElements.splice(l--, 1);
  3858. }
  3859. }
  3860. }
  3861. if (A.UA.svg && that && that.paper) {
  3862. that.paper.safari();
  3863. }
  3864. if (animationElements.length) {
  3865. setTimeout(Animation.animation);
  3866. }
  3867. };
  3868. var sortByKey = function (a, b) {
  3869. return a.key - b.key;
  3870. };
  3871. var keyframesRun = function(attr, element, time, prev, prevCallback) {
  3872. var diff = time - prev;
  3873. element.timeouts.push(
  3874. setTimeout(
  3875. function() {
  3876. if (isFunction(prevCallback)) {
  3877. prevCallback.call(element);
  3878. }
  3879. element.animate(attr, diff, attr.easing);
  3880. },
  3881. prev
  3882. )
  3883. );
  3884. };
  3885. var upto255 = function(color) {
  3886. return MATH_MAX(MATH_MIN(color, 255), 0);
  3887. };
  3888. function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
  3889. var cx = 3 * p1x;
  3890. var bx = 3 * (p2x - p1x) - cx;
  3891. var ax = 1 - cx - bx;
  3892. var cy = 3 * p1y;
  3893. var by = 3 * (p2y - p1y) - cy;
  3894. var ay = 1 - cy - by;
  3895. function sampleCurveX(t) {
  3896. return ((ax * t + bx) * t + cx) * t;
  3897. }
  3898. function solve(x, epsilon) {
  3899. var t = solveCurveX(x, epsilon);
  3900. return ((ay * t + by) * t + cy) * t;
  3901. }
  3902. function solveCurveX(x, epsilon) {
  3903. var t0, t1, t2, x2, d2, i;
  3904. for(t2 = x, i = 0; i < 8; i++) {
  3905. x2 = sampleCurveX(t2) - x;
  3906. if (MATH_ABS(x2) < epsilon) {
  3907. return t2;
  3908. }
  3909. d2 = (3 * ax * t2 + 2 * bx) * t2 + cx;
  3910. if (MATH_ABS(d2) < 1e-6) {
  3911. break;
  3912. }
  3913. t2 = t2 - x2 / d2;
  3914. }
  3915. t0 = 0;
  3916. t1 = 1;
  3917. t2 = x;
  3918. if (t2 < t0) {
  3919. return t0;
  3920. }
  3921. if (t2 > t1) {
  3922. return t1;
  3923. }
  3924. while (t0 < t1) {
  3925. x2 = sampleCurveX(t2);
  3926. if (MATH_ABS(x2 - x) < epsilon) {
  3927. return t2;
  3928. }
  3929. if (x > x2) {
  3930. t0 = t2;
  3931. }
  3932. else {
  3933. t1 = t2;
  3934. }
  3935. t2 = (t1 - t0) / 2 + t0;
  3936. }
  3937. return t2;
  3938. }
  3939. return solve(t, 1 / (200 * duration));
  3940. }
  3941. ELEMENT_PROTOTYPE.animateWith = function(element, params, ms, easing, callback) {
  3942. for (var i = 0, length = animationElements.length; i < length; i++) {
  3943. if (animationElements[i].el.id == element.id) {
  3944. params.start = animationElements[i].start;
  3945. }
  3946. }
  3947. return this.animate(params, ms, easing, callback);
  3948. };
  3949. Animation.along = function(isBack) {
  3950. return function(path, ms, rotate, callback) {
  3951. var params = {back: isBack};
  3952. isFunction(rotate) ? (callback = rotate) : (params.rot = rotate);
  3953. path && path.constructor == Element && (path = path.attrs.path);
  3954. path && (params.along = path);
  3955. return this.animate(params, ms, callback);
  3956. };
  3957. }
  3958. ELEMENT_PROTOTYPE.animateAlong = Animation.along();
  3959. ELEMENT_PROTOTYPE.animateAlongBack = Animation.along(1);
  3960. ELEMENT_PROTOTYPE.onAnimation = function(f) {
  3961. var instance = this;
  3962. instance._run = f || 0;
  3963. return instance;
  3964. };
  3965. ELEMENT_PROTOTYPE.animate = function(params, ms, easing, callback) {
  3966. var instance = this;
  3967. instance.timeouts = instance.timeouts || [];
  3968. if (isFunction(easing) || !easing) {
  3969. callback = easing || null;
  3970. }
  3971. if (instance.removed) {
  3972. callback && callback.call(instance);
  3973. return instance;
  3974. }
  3975. var from = {};
  3976. var to = {};
  3977. var diff = {};
  3978. var canAnimate = false;
  3979. var customAttributes = instance.paper.customAttributes;
  3980. for (var attr in params) {
  3981. if (params.hasOwnProperty(attr)) {
  3982. if (MAP_ATTRS_AVAILABLE_ANIM.hasOwnProperty(attr) || customAttributes.hasOwnProperty(attr)) {
  3983. canAnimate = true;
  3984. from[attr] = instance.attr(attr);
  3985. if (from[attr] == null) {
  3986. from[attr] = MAP_ATTRS_AVAILABLE[attr];
  3987. }
  3988. to[attr] = params[attr];
  3989. switch (MAP_ATTRS_AVAILABLE_ANIM[attr]) {
  3990. case 'along':
  3991. var len = getTotalLength(params[attr]);
  3992. var point = getPointAtLength(params[attr], len * !!params.back);
  3993. var bb = instance.getRegion();
  3994. diff[attr] = len / ms;
  3995. diff.tx = bb.x;
  3996. diff.ty = bb.y;
  3997. diff.sx = point.x;
  3998. diff.sy = point.y;
  3999. to.rot = params.rot;
  4000. to.back = params.back;
  4001. to.len = len;
  4002. if (params.rot) {
  4003. diff.r = parseFloat(instance.rotate()) || 0;
  4004. }
  4005. break;
  4006. case STR_NUMBER:
  4007. diff[attr] = (to[attr] - from[attr]) / ms;
  4008. break;
  4009. case 'color':
  4010. from[attr] = ColorUtil.getRGB(from[attr]);
  4011. var toColour = ColorUtil.getRGB(to[attr]);
  4012. diff[attr] = {
  4013. r: (toColour.r - from[attr].r) / ms,
  4014. g: (toColour.g - from[attr].g) / ms,
  4015. b: (toColour.b - from[attr].b) / ms
  4016. };
  4017. break;
  4018. case 'path':
  4019. var pathes = Util.path2curve(from[attr], to[attr]);
  4020. from[attr] = pathes[0];
  4021. var toPath = pathes[1];
  4022. diff[attr] = [];
  4023. for (var i = 0, length = from[attr].length; i < length; i++) {
  4024. diff[attr][i] = [0];
  4025. for (var j = 1, jLength = from[attr][i].length; j < jLength; j++) {
  4026. diff[attr][i][j] = (toPath[i][j] - from[attr][i][j]) / ms;
  4027. }
  4028. }
  4029. break;
  4030. case 'csv':
  4031. var values = String(params[attr]).split(REGEX_SEPARATOR);
  4032. var from2 = String(from[attr]).split(REGEX_SEPARATOR);
  4033. switch (attr) {
  4034. case 'translation':
  4035. from[attr] = [0, 0];
  4036. diff[attr] = [
  4037. values[0] / ms,
  4038. values[1] / ms
  4039. ];
  4040. break;
  4041. case 'rotation':
  4042. from[attr] = (from2[1] == values[1] && from2[2] == values[2]) ? from2 : [0, values[1], values[2]];
  4043. diff[attr] = [
  4044. (values[0] - from[attr][0]) / ms,
  4045. 0,
  4046. 0
  4047. ];
  4048. break;
  4049. case 'scale':
  4050. params[attr] = values;
  4051. from[attr] = String(from[attr]).split(REGEX_SEPARATOR);
  4052. diff[attr] = [
  4053. (values[0] - from[attr][0]) / ms,
  4054. (values[1] - from[attr][1]) / ms,
  4055. 0,
  4056. 0
  4057. ];
  4058. break;
  4059. case 'clip-rect':
  4060. from[attr] = String(from[attr]).split(REGEX_SEPARATOR);
  4061. diff[attr] = [];
  4062. i = 4;
  4063. while (i--) {
  4064. diff[attr][i] = (values[i] - from[attr][i]) / ms;
  4065. }
  4066. break;
  4067. }
  4068. to[attr] = values;
  4069. break;
  4070. default:
  4071. values = [].concat(params[attr]);
  4072. from2 = [].concat(from[attr])
  4073. diff[attr] = [];
  4074. i = customAttributes[attr].length;
  4075. while (i--) {
  4076. diff[attr][i] = ((values[i] || 0) - (from2[i] || 0)) / ms;
  4077. }
  4078. break;
  4079. }
  4080. }
  4081. }
  4082. }
  4083. if (!canAnimate) {
  4084. var attrs = [];
  4085. var lastcall;
  4086. for (var key in params) {
  4087. if (params.hasOwnProperty(key) && REGEX_ANIMATE_KEYFRAMES.test(key)) {
  4088. attr = {
  4089. value: params[key]
  4090. };
  4091. if (key == 'from') {
  4092. key = 0;
  4093. }
  4094. else if (key == 'to') {
  4095. key = 100;
  4096. }
  4097. attr.key = parseInt(key, 10);
  4098. attrs.push(attr);
  4099. }
  4100. }
  4101. attrs.sort(sortByKey);
  4102. if (attrs[0].key) {
  4103. attrs.unshift(
  4104. {
  4105. key: 0,
  4106. value: instance.attrs
  4107. }
  4108. );
  4109. }
  4110. var prevAttr;
  4111. var attrLength = attrs.length;
  4112. for (var i = 0; i < attrLength; i++) {
  4113. attr = attrs[i];
  4114. prevAttr = attrs[i - 1];
  4115. keyframesRun(
  4116. attr.value,
  4117. instance, ms / 100 * attr.key,
  4118. ms / 100 * (prevAttr && prevAttr.key || 0),
  4119. prevAttr && prevAttr.value.callback
  4120. );
  4121. }
  4122. lastcall = attrs[attrLength - 1].value.callback;
  4123. if (lastcall) {
  4124. instance.timeouts.push(
  4125. setTimeout(
  4126. function() {
  4127. lastcall.call(instance);
  4128. },
  4129. ms
  4130. )
  4131. );
  4132. }
  4133. }
  4134. else {
  4135. var easingFormula = Animation.easing_formulas[easing];
  4136. if (!easingFormula) {
  4137. easingFormula = String(easingFormula).match(REGEX_BEZIER);
  4138. if (easingFormula && easingFormula.length == 5) {
  4139. var curve = easingFormula;
  4140. easingFormula = function(t) {
  4141. return CubicBezierAtTime(t, +curve[1], +curve[2], +curve[3], +curve[4], ms);
  4142. };
  4143. }
  4144. else {
  4145. easingFormula = function(t) {
  4146. return t;
  4147. };
  4148. }
  4149. }
  4150. animationElements.push(
  4151. {
  4152. start: params.start || +new Date,
  4153. ms: ms,
  4154. easing: easingFormula,
  4155. from: from,
  4156. diff: diff,
  4157. to: to,
  4158. el: instance,
  4159. t: {
  4160. x: 0,
  4161. y: 0
  4162. }
  4163. }
  4164. );
  4165. if (isFunction(callback)) {
  4166. instance._ac = setTimeout(
  4167. function() {
  4168. callback.call(instance);
  4169. },
  4170. ms
  4171. );
  4172. }
  4173. if (animationElements.length == 1) {
  4174. setTimeout(Animation.animation);
  4175. }
  4176. }
  4177. return instance;
  4178. };
  4179. ELEMENT_PROTOTYPE.stop = function() {
  4180. var instance = this;
  4181. for (var i = 0; i < animationElements.length; i++) {
  4182. if (animationElements[i].el.id == instance.id) {
  4183. animationElements.splice(i--, 1);
  4184. }
  4185. }
  4186. instance.timeouts = [];
  4187. clearTimeout(instance._ac);
  4188. delete instance._ac;
  4189. return instance;
  4190. };
  4191. ELEMENT_PROTOTYPE.translate = function(x, y) {
  4192. return this.attr(
  4193. {
  4194. translation: x + ' ' + y
  4195. }
  4196. );
  4197. };
  4198. Set.addMethod(['animateAlong', 'animateAlongBack', 'animateWith', 'onAnimation', 'stop', 'translate']);
  4199. Set.prototype.animate = function(params, ms, easing, callback) {
  4200. var instance = this;
  4201. if (isFunction(easing) || !easing) {
  4202. callback = easing || null;
  4203. }
  4204. var items = instance._items;
  4205. var length = items.length;
  4206. var i = length;
  4207. var item;
  4208. var currentItem;
  4209. var collector;
  4210. if (callback) {
  4211. collector = function() {
  4212. if (!--length) {
  4213. callback.call(instance);
  4214. }
  4215. };
  4216. }
  4217. easing = isString(easing) ? easing : collector;
  4218. item = items[--i].animate(params, ms, easing, collector);
  4219. while(i--) {
  4220. currentItem = items[i];
  4221. if (currentItem && !currentItem.removed) {
  4222. currentItem.animateWith(item, params, ms, easing, collector);
  4223. }
  4224. }
  4225. return instance;
  4226. };
  4227. }, '@VERSION@' ,{requires:['aui-drawing-base']});
  4228. AUI.add('aui-drawing-drag', function(A) {
  4229. var Lang = A.Lang,
  4230. DOC = A.config.doc,
  4231. Drawing = A.Drawing,
  4232. Element = Drawing.Element,
  4233. ELEMENT_PROTOTYPE = Element.prototype,
  4234. MAP_EVENT_CONFIG = {
  4235. standAlone: true
  4236. },
  4237. MAP_EVENT_GESTURES = {
  4238. mousedown: 'gesturemovestart',
  4239. mousemove: 'gesturemove',
  4240. mouseup: 'gesturemoveend'
  4241. },
  4242. SUPPORTS_TOUCH = 'createTouch' in DOC;
  4243. var Drag = Drawing.Drag = {
  4244. drags: []
  4245. };
  4246. Element._getEventType = function(eventType) {
  4247. return MAP_EVENT_GESTURES[eventType] || eventType;
  4248. };
  4249. Element._getEventConfig = function(eventType, originalType) {
  4250. return MAP_EVENT_GESTURES[originalType] ? MAP_EVENT_CONFIG : null;
  4251. };
  4252. Drag.dragMove = function(e) {
  4253. var x = e.clientX;
  4254. var y = e.clientY;
  4255. var dragi;
  4256. var drags = Drag.drags;
  4257. var j = drags.length;
  4258. while (j--) {
  4259. dragi = drags[j];
  4260. if (SUPPORTS_TOUCH) {
  4261. var i = e.touches.length;
  4262. var touch;
  4263. while (i--) {
  4264. touch = e.touches[i];
  4265. if (touch.identifier == dragi.el._drag.id) {
  4266. x = touch.clientX;
  4267. y = touch.clientY;
  4268. (e.originalEvent ? e.originalEvent : e).preventDefault();
  4269. break;
  4270. }
  4271. }
  4272. }
  4273. else {
  4274. e.preventDefault();
  4275. }
  4276. if (dragi.move) {
  4277. dragi.move.call(dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y);
  4278. }
  4279. }
  4280. };
  4281. Drag.dragUp = function() {
  4282. Drag._dragMoveHandle.detach();
  4283. Drag._dragUpHandle.detach();
  4284. var drags = Drag.drags;
  4285. var i = drags.length;
  4286. var dragi;
  4287. while (i--) {
  4288. dragi = drags[i];
  4289. dragi.el._drag = {};
  4290. if (dragi.end) {
  4291. dragi.end.call(dragi.el);
  4292. }
  4293. }
  4294. Drag.drags = [];
  4295. };
  4296. ELEMENT_PROTOTYPE.drag = function(onmove, onstart, onend) {
  4297. var instance = this;
  4298. instance._drag = {};
  4299. instance.on(
  4300. 'mousedown',
  4301. function(e) {
  4302. var element = this;
  4303. (e.originalEvent || e).preventDefault();
  4304. element._drag.x = e.clientX;
  4305. element._drag.y = e.clientY;
  4306. element._drag.id = e.identifier;
  4307. if (onstart) {
  4308. onstart.call(element, e.clientX, e.clientY);
  4309. }
  4310. if (!Drag.drags.length) {
  4311. var realMoveEventName = Element._getEventType('mousemove');
  4312. var realUpEventName = Element._getEventType('mouseup');
  4313. Drag._dragMoveHandle = A.on(realMoveEventName, Drag.dragMove, DOC, Element._getEventConfig(realMoveEventName, 'mousemove'));
  4314. Drag._dragUpHandle = A.on(realUpEventName, Drag.dragUp, DOC, Element._getEventConfig(realUpEventName, 'mouseup'));
  4315. }
  4316. Drag.drags.push(
  4317. {
  4318. el: this,
  4319. move: onmove,
  4320. end: onend
  4321. }
  4322. );
  4323. }
  4324. );
  4325. return instance;
  4326. };
  4327. ELEMENT_PROTOTYPE.undrag = function(onmove, onstart, onend) {
  4328. var instance = this;
  4329. var drags = Drag.drags;
  4330. var i = drags.length;
  4331. while (i--) {
  4332. drags[i].el == instance && (drags[i].move == onmove && drags[i].end == onend) && drags.splice(i, 1);
  4333. if (!drags.length) {
  4334. Drag._dragMoveHandle.detach();
  4335. Drag._dragUpHandle.detach();
  4336. }
  4337. }
  4338. };
  4339. Drawing.Set.addMethod(['drag', 'undrag']);
  4340. }, '@VERSION@' ,{requires:['aui-drawing-base','event-gestures']});
  4341. AUI.add('aui-drawing-fonts', function(A) {
  4342. var Lang = A.Lang,
  4343. isString = Lang.isString,
  4344. Drawing = A.Drawing,
  4345. DRAWING_PROTOTYPE = Drawing.prototype,
  4346. GLYPH_FN_REPLACE = function(command) {
  4347. return GLYPH_MAP_COMMAND[command] || 'M';
  4348. },
  4349. GLYPH_MAP_COMMAND = {
  4350. l: 'L',
  4351. c: 'C',
  4352. x: 'z',
  4353. t: 'm',
  4354. r: 'l',
  4355. v: 'c'
  4356. },
  4357. MAP_FONT_WEIGHT = {
  4358. bold: 700,
  4359. bolder: 800,
  4360. lighter: 300,
  4361. normal: 400
  4362. },
  4363. MATH = Math,
  4364. MATH_MAX = MATH.max,
  4365. MATH_MIN = MATH.min,
  4366. REGEX_GLYPH_COMMANDS = /[mlcxtrv]/g,
  4367. REGEX_SEPARATOR = Drawing.REGEX_SEPARATOR,
  4368. STR_EMPTY = Drawing.STR_EMPTY;
  4369. Drawing.registerFont = function(font) {
  4370. if (!font.face) {
  4371. return font;
  4372. }
  4373. this.fonts = this.fonts || {};
  4374. var fontCollection = this.fonts;
  4375. var fontcopy = {
  4376. w: font.w,
  4377. face: {},
  4378. glyphs: {}
  4379. };
  4380. var family = font.face['font-family'];
  4381. var fontFace = font.face;
  4382. var fontCopyFace = fontcopy.face;
  4383. for (var prop in fontFace) {
  4384. if (fontFace.hasOwnProperty(prop)) {
  4385. fontCopyFace[prop] = fontFace[prop];
  4386. }
  4387. }
  4388. if (fontCollection[family]) {
  4389. fontCollection[family].push(fontcopy);
  4390. }
  4391. else {
  4392. fontCollection[family] = [fontcopy];
  4393. }
  4394. if (!font.svg) {
  4395. fontCopyFace['units-per-em'] = parseInt(fontFace['units-per-em'], 10);
  4396. for (var glyph in font.glyphs) {
  4397. if (font.glyphs.hasOwnProperty(glyph)) {
  4398. var path = font.glyphs[glyph];
  4399. var d = path.d;
  4400. if (d) {
  4401. d = d.replace(REGEX_GLYPH_COMMANDS, GLYPH_FN_REPLACE);
  4402. d = 'M' + d + 'z';
  4403. }
  4404. fontcopy.glyphs[glyph] = {
  4405. w: path.w,
  4406. k: {},
  4407. d: d
  4408. };
  4409. if (path.k) {
  4410. for (var k in path.k) {
  4411. if (path.hasOwnProperty(k)) {
  4412. fontcopy.glyphs[glyph].k[k] = path.k[k];
  4413. }
  4414. }
  4415. }
  4416. }
  4417. }
  4418. }
  4419. return font;
  4420. };
  4421. DRAWING_PROTOTYPE.getFont = function(family, weight, style, stretch) {
  4422. var instance = this;
  4423. stretch = stretch || 'normal';
  4424. style = style || 'normal';
  4425. weight = +weight || MAP_FONT_WEIGHT[weight] || 400;
  4426. if (!Drawing.fonts) {
  4427. return;
  4428. }
  4429. var fontCollection = Drawing.fonts;
  4430. var font = fontCollection[family];
  4431. if (!font) {
  4432. var name = new RegExp('(^|\\s)' + family.replace(/[^\w\d\s+!~.:_-]/g, STR_EMPTY) + '(\\s|$)', 'i');
  4433. for (var fontName in fontCollection) {
  4434. if (fontCollection.hasOwnProperty(fontName)) {
  4435. if (name.test(fontName)) {
  4436. font = fontCollection[fontName];
  4437. break;
  4438. }
  4439. }
  4440. }
  4441. }
  4442. var thefont;
  4443. if (font) {
  4444. var fontFace;
  4445. for (var i = 0, length = font.length; i < length; i++) {
  4446. thefont = font[i];
  4447. fontFace = thefont.face;
  4448. if (
  4449. fontFace['font-weight'] == weight &&
  4450. (fontFace['font-style'] == style || !fontFace['font-style']) &&
  4451. fontFace['font-stretch'] == stretch
  4452. ) {
  4453. break;
  4454. }
  4455. }
  4456. }
  4457. return thefont;
  4458. };
  4459. DRAWING_PROTOTYPE.print = function(x, y, string, font, size, origin, letterSpacing) {
  4460. var instance = this;
  4461. origin = origin || 'middle'; // baseline|middle
  4462. letterSpacing = MATH_MAX(MATH_MIN(letterSpacing || 0, 1), -1);
  4463. var out = instance.createSet();
  4464. var letters = String(string).split(STR_EMPTY);
  4465. var shift = 0;
  4466. var path = STR_EMPTY;
  4467. var scale;
  4468. isString(font) && (font = instance.getFont(font));
  4469. if (font) {
  4470. scale = (size || 16) / font.face['units-per-em'];
  4471. var bb = font.face.bbox.split(REGEX_SEPARATOR);
  4472. var top = +bb[0];
  4473. var height = +bb[1] + (origin == 'baseline' ? bb[3] - bb[1] + (+font.face.descent) : (bb[3] - bb[1]) / 2);
  4474. for (var i = 0, length = letters.length; i < length; i++) {
  4475. var prev = i && font.glyphs[letters[i - 1]] || {};
  4476. var curr = font.glyphs[letters[i]];
  4477. shift += i ? (prev.w || font.w) + (prev.k && prev.k[letters[i]] || 0) + (font.w * letterSpacing) : 0;
  4478. curr && curr.d && out.push(
  4479. instance.path(curr.d).attr(
  4480. {
  4481. fill: '#000',
  4482. stroke: 'none',
  4483. translation: [shift, 0]
  4484. }
  4485. )
  4486. );
  4487. }
  4488. out.scale(scale, scale, top, height).translate(x - top, y - height);
  4489. }
  4490. return out;
  4491. };
  4492. }, '@VERSION@' ,{requires:['aui-drawing-base']});
  4493. AUI.add('aui-drawing-safari', function(A) {
  4494. A.Drawing.prototype.safari = function() {
  4495. var instance = this;
  4496. var rect = instance.rect(-99, -99, instance.get('width') + 99, instance.get('height') + 99).attr(
  4497. {
  4498. stroke: 'none'
  4499. }
  4500. );
  4501. setTimeout(
  4502. function() {
  4503. rect.remove();
  4504. },
  4505. 0
  4506. );
  4507. };
  4508. }, '@VERSION@' ,{requires:['aui-drawing-base'], condition: {name: 'aui-drawing-safari', trigger: 'aui-drawing-base',test: function(A){var UA = A.UA; return UA.safari && (UA.version.major < 4 || (UA.iphone || UA.ipad));}}});
  4509. AUI.add('aui-drawing', function(A){}, '@VERSION@' ,{skinnable:false, use:['aui-drawing-base', 'aui-drawing-animate', 'aui-drawing-drag', 'aui-drawing-fonts']});