Axis.cs 236 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. //
  5. // Purpose: Axis related properties and methods. Axis class gives
  6. // information to Common.Chart series about
  7. // position in the Common.Chart area and keeps all necessary
  8. // information about axes.
  9. //
  10. using System;
  11. using System.Collections;
  12. using System.Collections.Specialized;
  13. using System.ComponentModel;
  14. using System.ComponentModel.Design;
  15. using System.Data;
  16. using System.Drawing;
  17. using System.Drawing.Design;
  18. using System.Drawing.Text;
  19. using System.Drawing.Drawing2D;
  20. using System.Diagnostics.CodeAnalysis;
  21. using FastReport.DataVisualization.Charting;
  22. using FastReport.DataVisualization.Charting.Data;
  23. using FastReport.DataVisualization.Charting.ChartTypes;
  24. using FastReport.DataVisualization.Charting.Utilities;
  25. using FastReport.DataVisualization.Charting.Borders3D;
  26. namespace FastReport.DataVisualization.Charting
  27. {
  28. using Point = System.Drawing.Point;
  29. #region Axis name enumeration
  30. /// <summary>
  31. /// An enumeration of auto-fitting styles of the axis labels.
  32. /// </summary>
  33. [Flags]
  34. public enum LabelAutoFitStyles
  35. {
  36. /// <summary>
  37. /// No auto-fitting.
  38. /// </summary>
  39. None = 0,
  40. /// <summary>
  41. /// Allow font size increasing.
  42. /// </summary>
  43. IncreaseFont = 1,
  44. /// <summary>
  45. /// Allow font size decreasing.
  46. /// </summary>
  47. DecreaseFont = 2,
  48. /// <summary>
  49. /// Allow using staggered labels.
  50. /// </summary>
  51. StaggeredLabels = 4,
  52. /// <summary>
  53. /// Allow changing labels angle using values of 0, 30, 60 and 90 degrees.
  54. /// </summary>
  55. LabelsAngleStep30 = 8,
  56. /// <summary>
  57. /// Allow changing labels angle using values of 0, 45, 90 degrees.
  58. /// </summary>
  59. LabelsAngleStep45 = 16,
  60. /// <summary>
  61. /// Allow changing labels angle using values of 0 and 90 degrees.
  62. /// </summary>
  63. LabelsAngleStep90 = 32,
  64. /// <summary>
  65. /// Allow replacing spaces with the new line character.
  66. /// </summary>
  67. WordWrap = 64,
  68. }
  69. /// <summary>
  70. /// An enumeration of axis names.
  71. /// </summary>
  72. public enum AxisName
  73. {
  74. /// <summary>
  75. /// Primary X Axis.
  76. /// </summary>
  77. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "X")]
  78. X = 0,
  79. /// <summary>
  80. /// Primary Y Axis.
  81. /// </summary>
  82. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Y")]
  83. Y = 1,
  84. /// <summary>
  85. /// Secondary X Axis.
  86. /// </summary>
  87. X2 = 2,
  88. /// <summary>
  89. /// Secondary Y Axis.
  90. /// </summary>
  91. Y2 = 3
  92. }
  93. #endregion
  94. /// <summary>
  95. /// The Axis class gives information to the Common.Chart series
  96. /// about positions in the Common.Chart area and keeps all of
  97. /// the data about the axis.
  98. /// </summary>
  99. [
  100. SRDescription("DescriptionAttributeAxis_Axis"),
  101. DefaultProperty("Enabled"),
  102. ]
  103. public partial class Axis : ChartNamedElement
  104. {
  105. #region Axis fields
  106. /// <summary>
  107. /// Plot area position
  108. /// </summary>
  109. internal ElementPosition PlotAreaPosition;
  110. // This field synchronies Store and Reset temporary values
  111. private bool _storeValuesEnabled = true;
  112. private FontCache _fontCache = new FontCache();
  113. private Font _titleFont;
  114. private Color _titleForeColor = Color.Black;
  115. private StringAlignment _titleAlignment = StringAlignment.Center;
  116. private string _title = "";
  117. private int _lineWidth = 1;
  118. private ChartDashStyle _lineDashStyle = ChartDashStyle.Solid;
  119. private Color _lineColor = Color.Black;
  120. private bool _isLabelAutoFit = true;
  121. private AxisArrowStyle _arrowStyle = AxisArrowStyle.None;
  122. private StripLinesCollection _stripLines = null;
  123. private bool _isMarksNextToAxis = true;
  124. // Default text orientation
  125. private TextOrientation _textOrientation = TextOrientation.Auto;
  126. // Size of the axis elements in percentage
  127. internal float titleSize = 0F;
  128. internal float labelSize = 0F;
  129. internal float labelNearOffset = 0F;
  130. internal float labelFarOffset = 0F;
  131. internal float unRotatedLabelSize = 0F;
  132. internal float markSize = 0F;
  133. internal float scrollBarSize = 0F;
  134. internal float totlaGroupingLabelsSize = 0F;
  135. internal float[] groupingLabelSizes = null;
  136. internal float totlaGroupingLabelsSizeAdjustment = 0f;
  137. private LabelAutoFitStyles _labelAutoFitStyle = LabelAutoFitStyles.DecreaseFont |
  138. LabelAutoFitStyles.IncreaseFont |
  139. LabelAutoFitStyles.LabelsAngleStep30 |
  140. LabelAutoFitStyles.StaggeredLabels |
  141. LabelAutoFitStyles.WordWrap;
  142. // Auto calculated font for labels
  143. internal Font autoLabelFont = null;
  144. internal int autoLabelAngle = -1000;
  145. internal int autoLabelOffset = -1;
  146. // Labels auto fitting constants
  147. private float _aveLabelFontSize = 10F;
  148. private float _minLabelFontSize = 5F;
  149. // Determines maximum label size of the chart area.
  150. private float _maximumAutoSize = 75f;
  151. // Chart title position rectangle
  152. private RectangleF _titlePosition = RectangleF.Empty;
  153. // Element spacing size
  154. internal const float elementSpacing = 1F;
  155. // Maximum total size of the axis's elements in percentage
  156. private const float maxAxisElementsSize = 75F;
  157. // Maximum size of the axis title in percentage
  158. private const float maxAxisTitleSize = 20F;
  159. // Maximum size of the axis second row of labels in percentage
  160. // of the total labels size
  161. private const float maxAxisLabelRow2Size = 45F;
  162. // Maximum size of the axis tick marks in percentage
  163. private const float maxAxisMarkSize = 20F;
  164. // Minimum cached value from data series.
  165. internal double minimumFromData = double.NaN;
  166. // Maximum cached value from data series.
  167. internal double maximumFromData = double.NaN;
  168. // Flag, which tells to Set Data method to take, again values from
  169. // data source and not to use cached values.
  170. internal bool refreshMinMaxFromData = true;
  171. // Flag, which tells to Set Data method to take, again values from
  172. // data source and not to use cached values.
  173. internal int numberOfPointsInAllSeries = 0;
  174. // Original axis scaleView position
  175. private double _originalViewPosition = double.NaN;
  176. /// <summary>
  177. /// Indicates that isInterlaced strip lines will be displayed for the axis.
  178. /// </summary>
  179. private bool _isInterlaced = false;
  180. /// <summary>
  181. /// Color used to draw isInterlaced strip lines for the axis.
  182. /// </summary>
  183. private Color _interlacedColor = Color.Empty;
  184. /// <summary>
  185. /// Axis interval offset.
  186. /// </summary>
  187. private double _intervalOffset = 0;
  188. /// <summary>
  189. /// Axis interval.
  190. /// </summary>
  191. internal double interval = 0;
  192. /// <summary>
  193. /// Axis interval units type.
  194. /// </summary>
  195. internal DateTimeIntervalType intervalType = DateTimeIntervalType.Auto;
  196. /// <summary>
  197. /// Axis interval offset units type.
  198. /// </summary>
  199. internal DateTimeIntervalType intervalOffsetType = DateTimeIntervalType.Auto;
  200. /// <summary>
  201. /// Minimum font size that can be used by the labels auto-fitting algorithm.
  202. /// </summary>
  203. internal int labelAutoFitMinFontSize = 6;
  204. /// <summary>
  205. /// Maximum font size that can be used by the labels auto-fitting algorithm.
  206. /// </summary>
  207. internal int labelAutoFitMaxFontSize = 10;
  208. /// <summary>
  209. /// Axis tooltip
  210. /// </summary>
  211. private string _toolTip = String.Empty;
  212. /// <summary>
  213. /// Axis HREF
  214. /// </summary>
  215. private string _url = String.Empty;
  216. #endregion
  217. #region Axis constructor and initialization
  218. /// <summary>
  219. /// Default constructor of Axis.
  220. /// </summary>
  221. public Axis()
  222. : base(null, GetName(AxisName.X))
  223. {
  224. Initialize(AxisName.X);
  225. }
  226. /// <summary>
  227. /// Axis constructor.
  228. /// </summary>
  229. /// <param name="chartArea">The chart area the axis belongs to.</param>
  230. /// <param name="axisTypeName">The type of the axis.</param>
  231. public Axis(ChartArea chartArea, AxisName axisTypeName)
  232. : base(chartArea, GetName(axisTypeName))
  233. {
  234. Initialize(axisTypeName);
  235. }
  236. /// <summary>
  237. /// Initialize axis class
  238. /// </summary>
  239. /// <param name="axisTypeName">Name of the axis type.</param>
  240. private void Initialize(AxisName axisTypeName)
  241. {
  242. // DT: Axis could be already created. Don't recreate new labelstyle and other objects.
  243. // Initialize axis labels
  244. if (labelStyle == null)
  245. {
  246. labelStyle = new LabelStyle(this);
  247. }
  248. if (_customLabels == null)
  249. {
  250. _customLabels = new CustomLabelsCollection(this);
  251. }
  252. if (_scaleView == null)
  253. {
  254. // Create axis data scaleView object
  255. _scaleView = new AxisScaleView(this);
  256. }
  257. if (scrollBar == null)
  258. {
  259. // Create axis croll bar class
  260. scrollBar = new AxisScrollBar(this);
  261. }
  262. this.axisType = axisTypeName;
  263. // Create grid & tick marks objects
  264. if (minorTickMark == null)
  265. {
  266. minorTickMark = new TickMark(this, false);
  267. }
  268. if (majorTickMark == null)
  269. {
  270. majorTickMark = new TickMark(this, true);
  271. majorTickMark.Interval = double.NaN;
  272. majorTickMark.IntervalOffset = double.NaN;
  273. majorTickMark.IntervalType = DateTimeIntervalType.NotSet;
  274. majorTickMark.IntervalOffsetType = DateTimeIntervalType.NotSet;
  275. }
  276. if (minorGrid == null)
  277. {
  278. minorGrid = new Grid(this, false);
  279. }
  280. if (majorGrid == null)
  281. {
  282. majorGrid = new Grid(this, true);
  283. majorGrid.Interval = double.NaN;
  284. majorGrid.IntervalOffset = double.NaN;
  285. majorGrid.IntervalType = DateTimeIntervalType.NotSet;
  286. majorGrid.IntervalOffsetType = DateTimeIntervalType.NotSet;
  287. }
  288. if (this._stripLines == null)
  289. {
  290. this._stripLines = new StripLinesCollection(this);
  291. }
  292. if (_titleFont == null)
  293. {
  294. _titleFont = _fontCache.DefaultFont;
  295. }
  296. #if SUBAXES
  297. if(this.subAxes == null)
  298. {
  299. this.subAxes = new SubAxisCollection(this);
  300. }
  301. #endif
  302. // Initialize axis scroll bar class
  303. this.ScrollBar.Initialize();
  304. // Create collection of scale segments
  305. if (this.scaleSegments == null)
  306. {
  307. this.scaleSegments = new AxisScaleSegmentCollection(this);
  308. }
  309. // Create scale break style
  310. if (this.axisScaleBreakStyle == null)
  311. {
  312. this.axisScaleBreakStyle = new AxisScaleBreakStyle(this);
  313. }
  314. }
  315. /// <summary>
  316. /// Initialize axis class
  317. /// </summary>
  318. /// <param name="chartArea">Chart area that the axis belongs.</param>
  319. /// <param name="axisTypeName">Axis type.</param>
  320. internal void Initialize(ChartArea chartArea, AxisName axisTypeName)
  321. {
  322. this.Initialize(axisTypeName);
  323. this.Parent = chartArea;
  324. this.Name = GetName(axisTypeName);
  325. }
  326. /// <summary>
  327. /// Set Axis Name
  328. /// </summary>
  329. internal static string GetName(AxisName axisName)
  330. {
  331. // Set axis name.
  332. // NOTE: Strings below should neber be localized. Name properties in the chart are never localized
  333. // and represent consisten object name in all locales.
  334. switch (axisName)
  335. {
  336. case (AxisName.X):
  337. return "X axis";
  338. case (AxisName.Y):
  339. return "Y (Value) axis";
  340. case (AxisName.X2):
  341. return "Secondary X axis";
  342. case (AxisName.Y2):
  343. return "Secondary Y (Value) axis";
  344. }
  345. return null;
  346. }
  347. #endregion
  348. #region Axis properies
  349. // Internal
  350. internal ChartArea ChartArea
  351. {
  352. get { return Parent as ChartArea; }
  353. }
  354. /// <summary>
  355. /// Text orientation.
  356. /// </summary>
  357. [
  358. SRCategory("CategoryAttributeTitle"),
  359. Bindable(true),
  360. DefaultValue(TextOrientation.Auto),
  361. SRDescription("DescriptionAttribute_TextOrientation"),
  362. NotifyParentPropertyAttribute(true),
  363. ]
  364. public TextOrientation TextOrientation
  365. {
  366. get
  367. {
  368. return this._textOrientation;
  369. }
  370. set
  371. {
  372. this._textOrientation = value;
  373. this.Invalidate();
  374. CallOnModifing();
  375. }
  376. }
  377. /// <summary>
  378. /// Returns sub-axis name.
  379. /// </summary>
  380. virtual internal string SubAxisName
  381. {
  382. get
  383. {
  384. return string.Empty;
  385. }
  386. }
  387. #if SUBAXES
  388. /// <summary>
  389. /// Indicates if this axis object present the main or sub axis.
  390. /// </summary>
  391. virtual internal bool IsSubAxis
  392. {
  393. get
  394. {
  395. return false;
  396. }
  397. }
  398. private SubAxisCollection subAxes = null;
  399. /// <summary>
  400. /// Sub-axes collection.
  401. /// </summary>
  402. [
  403. SRCategory("CategoryAttributeSubAxes"),
  404. Bindable(true),
  405. SRDescription("DescriptionAttributeSubAxes"),
  406. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  407. Editor(Editors.ChartCollectionEditor.Editor, Editors.ChartCollectionEditor.Base)
  408. ]
  409. virtual public SubAxisCollection SubAxes
  410. {
  411. get
  412. {
  413. return this.subAxes;
  414. }
  415. }
  416. #endif // SUBAXES
  417. /// <summary>
  418. /// Gets or sets a flag which indicates whether interlaced strip lines will be displayed for the axis.
  419. /// </summary>
  420. [
  421. SRCategory("CategoryAttributeAppearance"),
  422. Bindable(true),
  423. DefaultValue(false),
  424. SRDescription("DescriptionAttributeInterlaced"),
  425. NotifyParentPropertyAttribute(true),
  426. ]
  427. public bool IsInterlaced
  428. {
  429. get
  430. {
  431. return _isInterlaced;
  432. }
  433. set
  434. {
  435. _isInterlaced = value;
  436. this.Invalidate();
  437. CallOnModifing();
  438. }
  439. }
  440. /// <summary>
  441. /// Gets or sets the color used to draw interlaced strip lines for the axis.
  442. /// </summary>
  443. [
  444. SRCategory("CategoryAttributeAppearance"),
  445. Bindable(true),
  446. DefaultValue(typeof(Color), ""),
  447. SRDescription("DescriptionAttributeInterlacedColor"),
  448. NotifyParentPropertyAttribute(true),
  449. TypeConverter(typeof(ColorConverter)),
  450. #if DESIGNER
  451. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  452. #endif
  453. ]
  454. public Color InterlacedColor
  455. {
  456. get
  457. {
  458. return _interlacedColor;
  459. }
  460. set
  461. {
  462. _interlacedColor = value;
  463. this.Invalidate();
  464. CallOnModifing();
  465. }
  466. }
  467. /// <summary>
  468. /// Axis name. This field is reserved for internal use only.
  469. /// </summary>
  470. [
  471. SRCategory("CategoryAttributeAppearance"),
  472. Bindable(true),
  473. Browsable(false),
  474. DefaultValue(""),
  475. SRDescription("DescriptionAttributeAxis_Name"),
  476. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  477. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  478. ]
  479. public override string Name
  480. {
  481. get
  482. {
  483. return base.Name;
  484. }
  485. set
  486. {
  487. base.Name = value;
  488. CallOnModifing();
  489. }
  490. }
  491. /// <summary>
  492. /// Axis name. This field is reserved for internal use only.
  493. /// </summary>
  494. [
  495. SRCategory("CategoryAttributeAppearance"),
  496. Bindable(true),
  497. Browsable(false),
  498. DefaultValue(""),
  499. SRDescription("DescriptionAttributeType"),
  500. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  501. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  502. ]
  503. virtual public AxisName AxisName
  504. {
  505. get
  506. {
  507. return axisType;
  508. }
  509. }
  510. /// <summary>
  511. /// Gets or sets the arrow style used for the axis.
  512. /// </summary>
  513. [
  514. SRCategory("CategoryAttributeAppearance"),
  515. Bindable(true),
  516. DefaultValue(AxisArrowStyle.None),
  517. NotifyParentPropertyAttribute(true),
  518. SRDescription("DescriptionAttributeArrows"),
  519. ]
  520. public AxisArrowStyle ArrowStyle
  521. {
  522. get
  523. {
  524. return _arrowStyle;
  525. }
  526. set
  527. {
  528. _arrowStyle = value;
  529. this.Invalidate();
  530. CallOnModifing();
  531. }
  532. }
  533. /// <summary>
  534. /// Gets or sets the properties used for the major gridlines.
  535. /// </summary>
  536. [
  537. SRCategory("CategoryAttributeGridTickMarks"),
  538. Bindable(true),
  539. NotifyParentPropertyAttribute(true),
  540. SRDescription("DescriptionAttributeMajorGrid"),
  541. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  542. TypeConverter(typeof(NoNameExpandableObjectConverter))
  543. ]
  544. public Grid MajorGrid
  545. {
  546. get
  547. {
  548. return majorGrid;
  549. }
  550. set
  551. {
  552. majorGrid = value;
  553. majorGrid.Axis = this;
  554. majorGrid.majorGridTick = true;
  555. if (!majorGrid.intervalChanged)
  556. majorGrid.Interval = double.NaN;
  557. if (!majorGrid.intervalOffsetChanged)
  558. majorGrid.IntervalOffset = double.NaN;
  559. if (!majorGrid.intervalTypeChanged)
  560. majorGrid.IntervalType = DateTimeIntervalType.NotSet;
  561. if (!majorGrid.intervalOffsetTypeChanged)
  562. majorGrid.IntervalOffsetType = DateTimeIntervalType.NotSet;
  563. this.Invalidate();
  564. CallOnModifing();
  565. }
  566. }
  567. /// <summary>
  568. /// Gets or sets the properties used for the minor gridlines.
  569. /// </summary>
  570. [
  571. SRCategory("CategoryAttributeGridTickMarks"),
  572. Bindable(true),
  573. NotifyParentPropertyAttribute(true),
  574. SRDescription("DescriptionAttributeMinorGrid"),
  575. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  576. TypeConverter(typeof(NoNameExpandableObjectConverter))
  577. ]
  578. public Grid MinorGrid
  579. {
  580. get
  581. {
  582. return minorGrid;
  583. }
  584. set
  585. {
  586. minorGrid = value;
  587. minorGrid.Initialize(this, false);
  588. this.Invalidate();
  589. CallOnModifing();
  590. }
  591. }
  592. /// <summary>
  593. /// Gets or sets the properties used for the major tick marks.
  594. /// </summary>
  595. [
  596. SRCategory("CategoryAttributeGridTickMarks"),
  597. Bindable(true),
  598. NotifyParentPropertyAttribute(true),
  599. SRDescription("DescriptionAttributeMajorTickMark"),
  600. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  601. TypeConverter(typeof(NoNameExpandableObjectConverter))
  602. ]
  603. public TickMark MajorTickMark
  604. {
  605. get
  606. {
  607. return majorTickMark;
  608. }
  609. set
  610. {
  611. majorTickMark = value;
  612. majorTickMark.Axis = this;
  613. majorTickMark.majorGridTick = true;
  614. if (!majorTickMark.intervalChanged)
  615. majorTickMark.Interval = double.NaN;
  616. if (!majorTickMark.intervalOffsetChanged)
  617. majorTickMark.IntervalOffset = double.NaN;
  618. if (!majorTickMark.intervalTypeChanged)
  619. majorTickMark.IntervalType = DateTimeIntervalType.NotSet;
  620. if (!majorTickMark.intervalOffsetTypeChanged)
  621. majorTickMark.IntervalOffsetType = DateTimeIntervalType.NotSet;
  622. this.Invalidate();
  623. CallOnModifing();
  624. }
  625. }
  626. /// <summary>
  627. /// Gets or sets the properties used for the minor tick marks.
  628. /// </summary>
  629. [
  630. SRCategory("CategoryAttributeGridTickMarks"),
  631. Bindable(true),
  632. NotifyParentPropertyAttribute(true),
  633. SRDescription("DescriptionAttributeMinorTickMark"),
  634. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  635. TypeConverter(typeof(NoNameExpandableObjectConverter))
  636. ]
  637. public TickMark MinorTickMark
  638. {
  639. get
  640. {
  641. return minorTickMark;
  642. }
  643. set
  644. {
  645. minorTickMark = value;
  646. minorTickMark.Initialize(this, false);
  647. this.Invalidate();
  648. CallOnModifing();
  649. }
  650. }
  651. /// <summary>
  652. /// Gets or sets a flag which indicates whether auto-fitting of labels is enabled.
  653. /// </summary>
  654. [
  655. SRCategory("CategoryAttributeLabels"),
  656. Bindable(true),
  657. DefaultValue(true),
  658. SRDescription("DescriptionAttributeLabelsAutoFit"),
  659. NotifyParentPropertyAttribute(true),
  660. RefreshPropertiesAttribute(RefreshProperties.All)
  661. ]
  662. public bool IsLabelAutoFit
  663. {
  664. get
  665. {
  666. return _isLabelAutoFit;
  667. }
  668. set
  669. {
  670. _isLabelAutoFit = value;
  671. this.Invalidate();
  672. CallOnModifing();
  673. }
  674. }
  675. /// <summary>
  676. /// Gets or sets the minimum font size that can be used by
  677. /// the label auto-fitting algorithm.
  678. /// </summary>
  679. [
  680. SRCategory("CategoryAttributeLabels"),
  681. Bindable(true),
  682. DefaultValue(6),
  683. SRDescription("DescriptionAttributeLabelsAutoFitMinFontSize"),
  684. NotifyParentPropertyAttribute(true),
  685. RefreshPropertiesAttribute(RefreshProperties.All)
  686. ]
  687. public int LabelAutoFitMinFontSize
  688. {
  689. get
  690. {
  691. return this.labelAutoFitMinFontSize;
  692. }
  693. set
  694. {
  695. // Font size cannot be less than 5
  696. if(value < 5)
  697. {
  698. throw (new InvalidOperationException(SR.ExceptionAxisLabelsAutoFitMinFontSizeValueInvalid));
  699. }
  700. this.labelAutoFitMinFontSize = value;
  701. this.Invalidate();
  702. CallOnModifing();
  703. }
  704. }
  705. /// <summary>
  706. /// Gets or sets the maximum font size that can be used by
  707. /// the label auto-fitting algorithm.
  708. /// </summary>
  709. [
  710. SRCategory("CategoryAttributeLabels"),
  711. Bindable(true),
  712. DefaultValue(10),
  713. SRDescription("DescriptionAttributeLabelsAutoFitMaxFontSize"),
  714. NotifyParentPropertyAttribute(true),
  715. RefreshPropertiesAttribute(RefreshProperties.All)
  716. ]
  717. public int LabelAutoFitMaxFontSize
  718. {
  719. get
  720. {
  721. return this.labelAutoFitMaxFontSize;
  722. }
  723. set
  724. {
  725. // Font size cannot be less than 5
  726. if(value < 5)
  727. {
  728. throw (new InvalidOperationException(SR.ExceptionAxisLabelsAutoFitMaxFontSizeInvalid));
  729. }
  730. this.labelAutoFitMaxFontSize = value;
  731. this.Invalidate();
  732. CallOnModifing();
  733. }
  734. }
  735. /// <summary>
  736. /// Gets or sets the auto-fitting style used for the labels.
  737. /// IsLabelAutoFit must be set to true.
  738. /// </summary>
  739. [
  740. SRCategory("CategoryAttributeLabels"),
  741. Bindable(true),
  742. DefaultValue(LabelAutoFitStyles.DecreaseFont | LabelAutoFitStyles.IncreaseFont | LabelAutoFitStyles.LabelsAngleStep30 | LabelAutoFitStyles.StaggeredLabels | LabelAutoFitStyles.WordWrap),
  743. SRDescription("DescriptionAttributeLabelsAutoFitStyle"),
  744. NotifyParentPropertyAttribute(true),
  745. #if DESIGNER
  746. Editor(typeof(FlagsEnumUITypeEditor), typeof(UITypeEditor))
  747. #endif
  748. ]
  749. public LabelAutoFitStyles LabelAutoFitStyle
  750. {
  751. get
  752. {
  753. return this._labelAutoFitStyle;
  754. }
  755. set
  756. {
  757. this._labelAutoFitStyle = value;
  758. this.Invalidate();
  759. CallOnModifing();
  760. }
  761. }
  762. /// <summary>
  763. /// Gets or sets a flag which indicates whether
  764. /// tick marks and labels move with the axis when
  765. /// the crossing value changes.
  766. /// </summary>
  767. [
  768. SRCategory("CategoryAttributeAppearance"),
  769. Bindable(true),
  770. DefaultValue(true),
  771. SRDescription("DescriptionAttributeMarksNextToAxis"),
  772. NotifyParentPropertyAttribute(true),
  773. ]
  774. virtual public bool IsMarksNextToAxis
  775. {
  776. get
  777. {
  778. return _isMarksNextToAxis;
  779. }
  780. set
  781. {
  782. _isMarksNextToAxis = value;
  783. this.Invalidate();
  784. CallOnModifing();
  785. }
  786. }
  787. /// <summary>
  788. /// Gets or sets the axis title.
  789. /// </summary>
  790. [
  791. SRCategory("CategoryAttributeTitle"),
  792. Bindable(true),
  793. DefaultValue(""),
  794. SRDescription("DescriptionAttributeTitle6"),
  795. NotifyParentPropertyAttribute(true),
  796. ]
  797. public string Title
  798. {
  799. get
  800. {
  801. return _title;
  802. }
  803. set
  804. {
  805. _title = value;
  806. this.Invalidate();
  807. CallOnModifing();
  808. }
  809. }
  810. /// <summary>
  811. /// Gets or sets the color of the axis title.
  812. /// </summary>
  813. [
  814. SRCategory("CategoryAttributeTitle"),
  815. Bindable(true),
  816. DefaultValue(typeof(Color), "Black"),
  817. SRDescription("DescriptionAttributeTitleColor"),
  818. NotifyParentPropertyAttribute(true),
  819. TypeConverter(typeof(ColorConverter)),
  820. #if DESIGNER
  821. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  822. #endif
  823. ]
  824. public Color TitleForeColor
  825. {
  826. get
  827. {
  828. return _titleForeColor;
  829. }
  830. set
  831. {
  832. _titleForeColor = value;
  833. this.Invalidate();
  834. CallOnModifing();
  835. }
  836. }
  837. /// <summary>
  838. /// Gets or sets the alignment of the axis title.
  839. /// </summary>
  840. [
  841. SRCategory("CategoryAttributeTitle"),
  842. Bindable(true),
  843. DefaultValue(typeof(StringAlignment), "Center"),
  844. SRDescription("DescriptionAttributeTitleAlignment"),
  845. NotifyParentPropertyAttribute(true),
  846. ]
  847. public StringAlignment TitleAlignment
  848. {
  849. get
  850. {
  851. return _titleAlignment;
  852. }
  853. set
  854. {
  855. _titleAlignment = value;
  856. this.Invalidate();
  857. CallOnModifing();
  858. }
  859. }
  860. /// <summary>
  861. /// Gets or sets the font used for the axis title.
  862. /// </summary>
  863. [
  864. SRCategory("CategoryAttributeTitle"),
  865. Bindable(true),
  866. DefaultValue(typeof(Font), "Microsoft Sans Serif, 8pt"),
  867. SRDescription("DescriptionAttributeTitleFont"),
  868. NotifyParentPropertyAttribute(true),
  869. ]
  870. public Font TitleFont
  871. {
  872. get
  873. {
  874. return _titleFont;
  875. }
  876. set
  877. {
  878. _titleFont = value;
  879. this.Invalidate();
  880. CallOnModifing();
  881. }
  882. }
  883. /// <summary>
  884. /// Gets or sets the line color of the axis.
  885. /// </summary>
  886. [
  887. SRCategory("CategoryAttributeAppearance"),
  888. Bindable(true),
  889. DefaultValue(typeof(Color), "Black"),
  890. SRDescription("DescriptionAttributeLineColor"),
  891. NotifyParentPropertyAttribute(true),
  892. TypeConverter(typeof(ColorConverter)),
  893. #if DESIGNER
  894. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  895. #endif
  896. ]
  897. public Color LineColor
  898. {
  899. get
  900. {
  901. return _lineColor;
  902. }
  903. set
  904. {
  905. _lineColor = value;
  906. this.Invalidate();
  907. CallOnModifing();
  908. }
  909. }
  910. /// <summary>
  911. /// Gets or sets the line width of the axis.
  912. /// </summary>
  913. [
  914. SRCategory("CategoryAttributeAppearance"),
  915. Bindable(true),
  916. DefaultValue(1),
  917. SRDescription("DescriptionAttributeLineWidth"),
  918. NotifyParentPropertyAttribute(true),
  919. ]
  920. public int LineWidth
  921. {
  922. get
  923. {
  924. return _lineWidth;
  925. }
  926. set
  927. {
  928. if (value < 0)
  929. {
  930. throw (new ArgumentOutOfRangeException("value", SR.ExceptionAxisWidthIsNegative));
  931. }
  932. _lineWidth = value;
  933. this.Invalidate();
  934. CallOnModifing();
  935. }
  936. }
  937. /// <summary>
  938. /// Gets or sets the line style of the axis.
  939. /// </summary>
  940. [
  941. SRCategory("CategoryAttributeAppearance"),
  942. Bindable(true),
  943. DefaultValue(ChartDashStyle.Solid),
  944. SRDescription("DescriptionAttributeLineDashStyle"),
  945. NotifyParentPropertyAttribute(true),
  946. ]
  947. public ChartDashStyle LineDashStyle
  948. {
  949. get
  950. {
  951. return _lineDashStyle;
  952. }
  953. set
  954. {
  955. _lineDashStyle = value;
  956. this.Invalidate();
  957. CallOnModifing();
  958. }
  959. }
  960. /// <summary>
  961. /// The collection of strip lines of the axis.
  962. /// </summary>
  963. [
  964. SRCategory("CategoryAttributeAppearance"),
  965. Bindable(true),
  966. SRDescription("DescriptionAttributeStripLines"),
  967. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  968. #if DESIGNER
  969. Editor(typeof(ChartCollectionEditor), typeof(UITypeEditor))
  970. #endif
  971. ]
  972. public StripLinesCollection StripLines
  973. {
  974. get
  975. {
  976. return _stripLines;
  977. }
  978. }
  979. /// <summary>
  980. /// Gets or sets the maximum size (in percentage) of the axis used in the automatic layout algorithm.
  981. /// </summary>
  982. /// <remarks>
  983. /// This property determines the maximum size of the axis, measured as a percentage of the chart area.
  984. /// </remarks>
  985. [
  986. SRCategory("CategoryAttributeLabels"),
  987. DefaultValue(75f),
  988. SRDescription("DescriptionAttributeAxis_MaxAutoSize"),
  989. ]
  990. public float MaximumAutoSize
  991. {
  992. get
  993. {
  994. return this._maximumAutoSize;
  995. }
  996. set
  997. {
  998. if (value < 0f || value > 100f)
  999. {
  1000. throw (new ArgumentOutOfRangeException("value", SR.ExceptionValueMustBeInRange("MaximumAutoSize", "0", "100")));
  1001. }
  1002. this._maximumAutoSize = value;
  1003. this.Invalidate();
  1004. CallOnModifing();
  1005. }
  1006. }
  1007. #endregion
  1008. #region IMapAreaAttributes Properties implementation
  1009. /// <summary>
  1010. /// Tooltip of the axis.
  1011. /// </summary>
  1012. [
  1013. SRCategory("CategoryAttributeMapArea"),
  1014. Bindable(true),
  1015. SRDescription("DescriptionAttributeToolTip"),
  1016. DefaultValue(""),
  1017. ]
  1018. public string ToolTip
  1019. {
  1020. set
  1021. {
  1022. this._toolTip = value;
  1023. }
  1024. get
  1025. {
  1026. return this._toolTip;
  1027. }
  1028. }
  1029. #endregion
  1030. #region Axis Interavl properies
  1031. /// <summary>
  1032. /// Axis interval size.
  1033. /// </summary>
  1034. [
  1035. SRCategory("CategoryAttributeInterval"),
  1036. Bindable(true),
  1037. DefaultValue(0.0),
  1038. SRDescription("DescriptionAttributeInterval4"),
  1039. RefreshPropertiesAttribute(RefreshProperties.All),
  1040. TypeConverter(typeof(AxisIntervalValueConverter)),
  1041. ]
  1042. public double Interval
  1043. {
  1044. get
  1045. {
  1046. return interval;
  1047. }
  1048. set
  1049. {
  1050. // Axis interval properties must be set
  1051. if (double.IsNaN(value))
  1052. {
  1053. interval = 0;
  1054. }
  1055. else
  1056. {
  1057. interval = value;
  1058. }
  1059. // Reset initial values
  1060. majorGrid.interval = tempMajorGridInterval;
  1061. majorTickMark.interval = tempMajorTickMarkInterval;
  1062. minorGrid.interval = tempMinorGridInterval;
  1063. minorTickMark.interval = tempMinorTickMarkInterval;
  1064. labelStyle.interval = tempLabelInterval;
  1065. this.Invalidate();
  1066. CallOnModifing();
  1067. }
  1068. }
  1069. /// <summary>
  1070. /// Axis interval offset.
  1071. /// </summary>
  1072. [
  1073. SRCategory("CategoryAttributeInterval"),
  1074. Bindable(true),
  1075. DefaultValue(0.0),
  1076. SRDescription("DescriptionAttributeIntervalOffset6"),
  1077. RefreshPropertiesAttribute(RefreshProperties.All),
  1078. TypeConverter(typeof(AxisIntervalValueConverter))
  1079. ]
  1080. public double IntervalOffset
  1081. {
  1082. get
  1083. {
  1084. return _intervalOffset;
  1085. }
  1086. set
  1087. {
  1088. // Axis interval properties must be set
  1089. if (double.IsNaN(value))
  1090. {
  1091. _intervalOffset = 0;
  1092. }
  1093. else
  1094. {
  1095. _intervalOffset = value;
  1096. }
  1097. this.Invalidate();
  1098. CallOnModifing();
  1099. }
  1100. }
  1101. /// <summary>
  1102. /// Axis interval type.
  1103. /// </summary>
  1104. [
  1105. SRCategory("CategoryAttributeInterval"),
  1106. Bindable(true),
  1107. DefaultValue(DateTimeIntervalType.Auto),
  1108. SRDescription("DescriptionAttributeIntervalType4"),
  1109. RefreshPropertiesAttribute(RefreshProperties.All)
  1110. ]
  1111. public DateTimeIntervalType IntervalType
  1112. {
  1113. get
  1114. {
  1115. return intervalType;
  1116. }
  1117. set
  1118. {
  1119. // Axis interval properties must be set
  1120. if (value == DateTimeIntervalType.NotSet)
  1121. {
  1122. intervalType = DateTimeIntervalType.Auto;
  1123. }
  1124. else
  1125. {
  1126. intervalType = value;
  1127. }
  1128. // Reset initial values
  1129. majorGrid.intervalType = tempGridIntervalType;
  1130. majorTickMark.intervalType = tempTickMarkIntervalType;
  1131. labelStyle.intervalType = tempLabelIntervalType;
  1132. this.Invalidate();
  1133. CallOnModifing();
  1134. }
  1135. }
  1136. /// <summary>
  1137. /// Axis interval offset type.
  1138. /// </summary>
  1139. [
  1140. SRCategory("CategoryAttributeInterval"),
  1141. Bindable(true),
  1142. DefaultValue(DateTimeIntervalType.Auto),
  1143. SRDescription("DescriptionAttributeIntervalOffsetType4"),
  1144. RefreshPropertiesAttribute(RefreshProperties.All)
  1145. ]
  1146. public DateTimeIntervalType IntervalOffsetType
  1147. {
  1148. get
  1149. {
  1150. return intervalOffsetType;
  1151. }
  1152. set
  1153. {
  1154. // Axis interval properties must be set
  1155. if (value == DateTimeIntervalType.NotSet)
  1156. {
  1157. intervalOffsetType = DateTimeIntervalType.Auto;
  1158. }
  1159. else
  1160. {
  1161. intervalOffsetType = value;
  1162. }
  1163. this.Invalidate();
  1164. CallOnModifing();
  1165. }
  1166. }
  1167. #endregion
  1168. #region Axis painting methods
  1169. /// <summary>
  1170. /// Checks if Common.Chart axis title is drawn vertically.
  1171. /// Note: From the drawing perspective stacked text orientation is not vertical.
  1172. /// </summary>
  1173. /// <returns>True if text is vertical.</returns>
  1174. private bool IsTextVertical
  1175. {
  1176. get
  1177. {
  1178. TextOrientation currentTextOrientation = this.GetTextOrientation();
  1179. return currentTextOrientation == TextOrientation.Rotated90 || currentTextOrientation == TextOrientation.Rotated270;
  1180. }
  1181. }
  1182. /// <summary>
  1183. /// Returns axis title text orientation. If set to Auto automatically determines the
  1184. /// orientation based on the axis position.
  1185. /// </summary>
  1186. /// <returns>Current text orientation.</returns>
  1187. private TextOrientation GetTextOrientation()
  1188. {
  1189. if (this.TextOrientation == TextOrientation.Auto)
  1190. {
  1191. if (this.AxisPosition == AxisPosition.Left)
  1192. {
  1193. return TextOrientation.Rotated270;
  1194. }
  1195. else if (this.AxisPosition == AxisPosition.Right)
  1196. {
  1197. return TextOrientation.Rotated90;
  1198. }
  1199. return TextOrientation.Horizontal;
  1200. }
  1201. return this.TextOrientation;
  1202. }
  1203. /// <summary>
  1204. /// Paint Axis elements on the back of the 3D scene.
  1205. /// </summary>
  1206. /// <param name="graph">Reference to the Chart Graphics object</param>
  1207. internal void PrePaint(ChartGraphics graph)
  1208. {
  1209. if (enabled != false)
  1210. {
  1211. // draw axis hot region
  1212. DrawAxisLineHotRegion(graph, true);
  1213. // Paint Major Tick Marks
  1214. majorTickMark.Paint(graph, true);
  1215. // Paint Minor Tick Marks
  1216. minorTickMark.Paint(graph, true);
  1217. // Draw axis line
  1218. DrawAxisLine(graph, true);
  1219. // Paint Labels
  1220. labelStyle.Paint(graph, true);
  1221. }
  1222. #if SUBAXES
  1223. // Process all sub-axis
  1224. if(!ChartArea.Area3DStyle.Enable3D &&
  1225. !ChartArea.chartAreaIsCurcular)
  1226. {
  1227. foreach(SubAxis subAxis in this.SubAxes)
  1228. {
  1229. subAxis.PrePaint( graph );
  1230. }
  1231. }
  1232. #endif // SUBAXES
  1233. }
  1234. /// <summary>
  1235. /// Paint Axis
  1236. /// </summary>
  1237. /// <param name="graph">Reference to the Chart Graphics object</param>
  1238. internal void Paint(ChartGraphics graph)
  1239. {
  1240. // Only Y axis is drawn in the circular Common.Chart area
  1241. if (ChartArea != null && ChartArea.chartAreaIsCurcular)
  1242. {
  1243. // Y circular axes
  1244. if (this.axisType == AxisName.Y && enabled != false)
  1245. {
  1246. ICircularChartType chartType = ChartArea.GetCircularChartType();
  1247. if (chartType != null)
  1248. {
  1249. Matrix oldMatrix = graph.Transform;
  1250. float[] axesLocation = chartType.GetYAxisLocations(ChartArea);
  1251. bool drawLabels = true;
  1252. foreach (float curentSector in axesLocation)
  1253. {
  1254. // Set graphics rotation matrix
  1255. Matrix newMatrix = oldMatrix.Clone();
  1256. newMatrix.RotateAt(
  1257. curentSector,
  1258. graph.GetAbsolutePoint(ChartArea.circularCenter));
  1259. graph.Transform = newMatrix;
  1260. // draw axis hot region
  1261. DrawAxisLineHotRegion(graph, false);
  1262. // Paint Minor Tick Marks
  1263. minorTickMark.Paint(graph, false);
  1264. // Paint Major Tick Marks
  1265. majorTickMark.Paint(graph, false);
  1266. // Draw axis line
  1267. DrawAxisLine(graph, false);
  1268. // Only first Y axis has labels
  1269. if (drawLabels)
  1270. {
  1271. drawLabels = false;
  1272. // Save current font angle
  1273. int currentAngle = labelStyle.Angle;
  1274. // Set labels text angle
  1275. if (labelStyle.Angle == 0)
  1276. {
  1277. if (curentSector >= 45f && curentSector <= 180f)
  1278. {
  1279. labelStyle.angle = -90;
  1280. }
  1281. else if (curentSector > 180f && curentSector <= 315f)
  1282. {
  1283. labelStyle.angle = 90;
  1284. }
  1285. }
  1286. // Draw labels
  1287. labelStyle.Paint(graph, false);
  1288. // Restore font angle
  1289. labelStyle.angle = currentAngle;
  1290. }
  1291. }
  1292. graph.Transform = oldMatrix;
  1293. }
  1294. }
  1295. // X circular axes
  1296. if (this.axisType == AxisName.X && enabled != false)
  1297. {
  1298. labelStyle.PaintCircular(graph);
  1299. }
  1300. DrawAxisTitle(graph);
  1301. return;
  1302. }
  1303. // If axis is disabled draw only Title
  1304. if (enabled != false)
  1305. {
  1306. // draw axis hot region
  1307. DrawAxisLineHotRegion(graph, false);
  1308. // Paint Minor Tick Marks
  1309. minorTickMark.Paint(graph, false);
  1310. // Paint Major Tick Marks
  1311. majorTickMark.Paint(graph, false);
  1312. // Draw axis line
  1313. DrawAxisLine(graph, false);
  1314. // Paint Labels
  1315. labelStyle.Paint(graph, false);
  1316. // Scroll bar is supoorted only in 2D charts
  1317. if (ChartArea != null && ChartArea.Area3DStyle.Enable3D == false)
  1318. {
  1319. // Draw axis scroll bar
  1320. ScrollBar.Paint(graph);
  1321. }
  1322. }
  1323. // Draw axis title
  1324. this.DrawAxisTitle(graph);
  1325. #if SUBAXES
  1326. // Process all sub-axis
  1327. if(ChartArea.IsSubAxesSupported)
  1328. {
  1329. foreach(SubAxis subAxis in this.SubAxes)
  1330. {
  1331. subAxis.Paint( graph );
  1332. }
  1333. }
  1334. #endif // SUBAXES
  1335. // Reset temp axis offset for side-by-side charts like column
  1336. this.ResetTempAxisOffset();
  1337. }
  1338. /// <summary>
  1339. /// Paint Axis element when segmented axis scale feature is used.
  1340. /// </summary>
  1341. /// <param name="graph">Reference to the Chart Graphics object</param>
  1342. internal void PaintOnSegmentedScalePassOne( ChartGraphics graph )
  1343. {
  1344. // If axis is disabled draw only Title
  1345. if( enabled != false )
  1346. {
  1347. // Paint Minor Tick Marks
  1348. minorTickMark.Paint( graph, false );
  1349. // Paint Major Tick Marks
  1350. majorTickMark.Paint( graph, false );
  1351. }
  1352. #if SUBAXES
  1353. // Process all sub-axis
  1354. if(ChartArea.IsSubAxesSupported)
  1355. {
  1356. foreach(SubAxis subAxis in this.SubAxes)
  1357. {
  1358. subAxis.PaintOnSegmentedScalePassOne( graph );
  1359. }
  1360. }
  1361. #endif // SUBAXES
  1362. }
  1363. /// <summary>
  1364. /// Paint Axis element when segmented axis scale feature is used.
  1365. /// </summary>
  1366. /// <param name="graph">Reference to the Chart Graphics object</param>
  1367. internal void PaintOnSegmentedScalePassTwo( ChartGraphics graph )
  1368. {
  1369. // If axis is disabled draw only Title
  1370. if( enabled != false )
  1371. {
  1372. // Draw axis line
  1373. DrawAxisLine( graph, false );
  1374. // Paint Labels
  1375. labelStyle.Paint( graph, false);
  1376. }
  1377. // Draw axis title
  1378. this.DrawAxisTitle( graph );
  1379. // Reset temp axis offset for side-by-side charts like column
  1380. this.ResetTempAxisOffset();
  1381. #if SUBAXES
  1382. // Process all sub-axis
  1383. if(ChartArea.IsSubAxesSupported)
  1384. {
  1385. foreach(SubAxis subAxis in this.SubAxes)
  1386. {
  1387. subAxis.PaintOnSegmentedScalePassTwo( graph );
  1388. }
  1389. }
  1390. #endif // SUBAXES
  1391. }
  1392. /// <summary>
  1393. /// Draw axis title
  1394. /// </summary>
  1395. /// <param name="graph">Reference to the Chart Graphics object</param>
  1396. private void DrawAxisTitle(ChartGraphics graph)
  1397. {
  1398. if (!this.enabled)
  1399. return;
  1400. // Draw axis title
  1401. if (this.Title.Length > 0)
  1402. {
  1403. Matrix oldTransform = null;
  1404. // Draw title in 3D
  1405. if (ChartArea.Area3DStyle.Enable3D && !ChartArea.chartAreaIsCurcular)
  1406. {
  1407. DrawAxis3DTitle(graph);
  1408. return;
  1409. }
  1410. string axisTitle = this.Title;
  1411. //******************************************************
  1412. //** Check axis position
  1413. //******************************************************
  1414. float axisPosition = (float)this.GetAxisPosition();
  1415. if (this.AxisPosition == AxisPosition.Bottom)
  1416. {
  1417. if (!this.GetIsMarksNextToAxis())
  1418. {
  1419. axisPosition = ChartArea.PlotAreaPosition.Bottom;
  1420. }
  1421. axisPosition = ChartArea.PlotAreaPosition.Bottom - axisPosition;
  1422. }
  1423. else if (this.AxisPosition == AxisPosition.Top)
  1424. {
  1425. if (!this.GetIsMarksNextToAxis())
  1426. {
  1427. axisPosition = ChartArea.PlotAreaPosition.Y;
  1428. }
  1429. axisPosition = axisPosition - ChartArea.PlotAreaPosition.Y;
  1430. }
  1431. else if (this.AxisPosition == AxisPosition.Right)
  1432. {
  1433. if (!this.GetIsMarksNextToAxis())
  1434. {
  1435. axisPosition = ChartArea.PlotAreaPosition.Right;
  1436. }
  1437. axisPosition = ChartArea.PlotAreaPosition.Right - axisPosition;
  1438. }
  1439. else if (this.AxisPosition == AxisPosition.Left)
  1440. {
  1441. if (!this.GetIsMarksNextToAxis())
  1442. {
  1443. axisPosition = ChartArea.PlotAreaPosition.X;
  1444. }
  1445. axisPosition = axisPosition - ChartArea.PlotAreaPosition.X;
  1446. }
  1447. //******************************************************
  1448. //** Adjust axis elements size with axis position
  1449. //******************************************************
  1450. // Calculate total size of axis elements
  1451. float axisSize = this.markSize + this.labelSize;
  1452. axisSize -= axisPosition;
  1453. if (axisSize < 0)
  1454. {
  1455. axisSize = 0;
  1456. }
  1457. // Set title alignment
  1458. using (StringFormat format = new StringFormat())
  1459. {
  1460. format.Alignment = this.TitleAlignment;
  1461. format.Trimming = StringTrimming.EllipsisCharacter;
  1462. // VSTS #144398
  1463. // We need to have the StringFormatFlags set to FitBlackBox as othwerwise axis titles using Fonts like
  1464. // "Algerian" or "Forte" are completly clipped (= not drawn) due to the fact that MeasureString returns
  1465. // a bounding rectangle that is too small.
  1466. format.FormatFlags |= StringFormatFlags.FitBlackBox;
  1467. // Calculate title rectangle
  1468. _titlePosition = ChartArea.PlotAreaPosition.ToRectangleF();
  1469. float titleSizeWithoutSpacing = this.titleSize - elementSpacing;
  1470. if (this.AxisPosition == AxisPosition.Left)
  1471. {
  1472. _titlePosition.X = ChartArea.PlotAreaPosition.X - titleSizeWithoutSpacing - axisSize;
  1473. _titlePosition.Y = ChartArea.PlotAreaPosition.Y;
  1474. if (!this.IsTextVertical)
  1475. {
  1476. SizeF axisTitleSize = new SizeF(titleSizeWithoutSpacing, ChartArea.PlotAreaPosition.Height);
  1477. _titlePosition.Width = axisTitleSize.Width;
  1478. _titlePosition.Height = axisTitleSize.Height;
  1479. format.Alignment = StringAlignment.Center;
  1480. if (this.TitleAlignment == StringAlignment.Far)
  1481. {
  1482. format.LineAlignment = StringAlignment.Near;
  1483. }
  1484. else if (this.TitleAlignment == StringAlignment.Near)
  1485. {
  1486. format.LineAlignment = StringAlignment.Far;
  1487. }
  1488. else
  1489. {
  1490. format.LineAlignment = StringAlignment.Center;
  1491. }
  1492. }
  1493. else
  1494. {
  1495. SizeF axisTitleSize = graph.GetAbsoluteSize(new SizeF(titleSizeWithoutSpacing, ChartArea.PlotAreaPosition.Height));
  1496. axisTitleSize = graph.GetRelativeSize(new SizeF(axisTitleSize.Height, axisTitleSize.Width));
  1497. _titlePosition.Width = axisTitleSize.Width;
  1498. _titlePosition.Height = axisTitleSize.Height;
  1499. _titlePosition.Y += ChartArea.PlotAreaPosition.Height / 2f - _titlePosition.Height / 2f;
  1500. _titlePosition.X += titleSizeWithoutSpacing / 2f - _titlePosition.Width / 2f;
  1501. // Set graphics rotation transformation
  1502. oldTransform = this.SetRotationTransformation(graph, _titlePosition);
  1503. // Set alignment
  1504. format.LineAlignment = StringAlignment.Center;
  1505. }
  1506. }
  1507. else if (this.AxisPosition == AxisPosition.Right)
  1508. {
  1509. _titlePosition.X = ChartArea.PlotAreaPosition.Right + axisSize;
  1510. _titlePosition.Y = ChartArea.PlotAreaPosition.Y;
  1511. if (!this.IsTextVertical)
  1512. {
  1513. SizeF axisTitleSize = new SizeF(titleSizeWithoutSpacing, ChartArea.PlotAreaPosition.Height);
  1514. _titlePosition.Width = axisTitleSize.Width;
  1515. _titlePosition.Height = axisTitleSize.Height;
  1516. format.Alignment = StringAlignment.Center;
  1517. if (this.TitleAlignment == StringAlignment.Far)
  1518. {
  1519. format.LineAlignment = StringAlignment.Near;
  1520. }
  1521. else if (this.TitleAlignment == StringAlignment.Near)
  1522. {
  1523. format.LineAlignment = StringAlignment.Far;
  1524. }
  1525. else
  1526. {
  1527. format.LineAlignment = StringAlignment.Center;
  1528. }
  1529. }
  1530. else
  1531. {
  1532. SizeF axisTitleSize = graph.GetAbsoluteSize(new SizeF(titleSizeWithoutSpacing, ChartArea.PlotAreaPosition.Height));
  1533. axisTitleSize = graph.GetRelativeSize(new SizeF(axisTitleSize.Height, axisTitleSize.Width));
  1534. _titlePosition.Width = axisTitleSize.Width;
  1535. _titlePosition.Height = axisTitleSize.Height;
  1536. _titlePosition.Y += ChartArea.PlotAreaPosition.Height / 2f - _titlePosition.Height / 2f;
  1537. _titlePosition.X += titleSizeWithoutSpacing / 2f - _titlePosition.Width / 2f;
  1538. // Set graphics rotation transformation
  1539. oldTransform = this.SetRotationTransformation(graph, _titlePosition);
  1540. // Set alignment
  1541. format.LineAlignment = StringAlignment.Center;
  1542. }
  1543. }
  1544. else if (this.AxisPosition == AxisPosition.Top)
  1545. {
  1546. _titlePosition.Y = ChartArea.PlotAreaPosition.Y - titleSizeWithoutSpacing - axisSize;
  1547. _titlePosition.Height = titleSizeWithoutSpacing;
  1548. _titlePosition.X = ChartArea.PlotAreaPosition.X;
  1549. _titlePosition.Width = ChartArea.PlotAreaPosition.Width;
  1550. if (this.IsTextVertical)
  1551. {
  1552. // Set graphics rotation transformation
  1553. oldTransform = this.SetRotationTransformation(graph, _titlePosition);
  1554. }
  1555. // Set alignment
  1556. format.LineAlignment = StringAlignment.Center;
  1557. }
  1558. else if (this.AxisPosition == AxisPosition.Bottom)
  1559. {
  1560. _titlePosition.Y = ChartArea.PlotAreaPosition.Bottom + axisSize;
  1561. _titlePosition.Height = titleSizeWithoutSpacing;
  1562. _titlePosition.X = ChartArea.PlotAreaPosition.X;
  1563. _titlePosition.Width = ChartArea.PlotAreaPosition.Width;
  1564. if (this.IsTextVertical)
  1565. {
  1566. // Set graphics rotation transformation
  1567. oldTransform = this.SetRotationTransformation(graph, _titlePosition);
  1568. }
  1569. // Set alignment
  1570. format.LineAlignment = StringAlignment.Center;
  1571. }
  1572. #if DEBUG
  1573. // TESTING CODE: Shows labels rectangle position.
  1574. // RectangleF rr = graph.GetAbsoluteRectangle(_titlePosition);
  1575. // graph.DrawRectangle(Pens.Blue, rr.X, rr.Y, rr.Width, rr.Height);
  1576. #endif // DEBUG
  1577. // Draw title
  1578. using (Brush brush = new SolidBrush(this.TitleForeColor))
  1579. {
  1580. graph.DrawStringRel(
  1581. axisTitle.Replace("\\n", "\n"),
  1582. this.TitleFont,
  1583. brush,
  1584. _titlePosition,
  1585. format,
  1586. this.GetTextOrientation());
  1587. }
  1588. }
  1589. // Process selection regions
  1590. if (this.Common.ProcessModeRegions)
  1591. {
  1592. // NOTE: Solves Issue #4423
  1593. // Transform title position coordinates using curent Graphics matrix
  1594. RectangleF transformedTitlePosition = graph.GetAbsoluteRectangle(_titlePosition);
  1595. PointF[] rectPoints = new PointF[] {
  1596. new PointF(transformedTitlePosition.X, transformedTitlePosition.Y),
  1597. new PointF(transformedTitlePosition.Right, transformedTitlePosition.Bottom) };
  1598. graph.Transform.TransformPoints(rectPoints);
  1599. transformedTitlePosition = new RectangleF(
  1600. rectPoints[0].X,
  1601. rectPoints[0].Y,
  1602. rectPoints[1].X - rectPoints[0].X,
  1603. rectPoints[1].Y - rectPoints[0].Y);
  1604. if (transformedTitlePosition.Width < 0)
  1605. {
  1606. transformedTitlePosition.Width = Math.Abs(transformedTitlePosition.Width);
  1607. transformedTitlePosition.X -= transformedTitlePosition.Width;
  1608. }
  1609. if (transformedTitlePosition.Height < 0)
  1610. {
  1611. transformedTitlePosition.Height = Math.Abs(transformedTitlePosition.Height);
  1612. transformedTitlePosition.Y -= transformedTitlePosition.Height;
  1613. }
  1614. // Add hot region
  1615. this.Common.HotRegionsList.AddHotRegion(
  1616. transformedTitlePosition, this, ChartElementType.AxisTitle, false, false);
  1617. }
  1618. // Restore old transformation
  1619. if (oldTransform != null)
  1620. {
  1621. graph.Transform = oldTransform;
  1622. }
  1623. }
  1624. }
  1625. /// <summary>
  1626. /// Helper method which sets 90 or -90 degrees transformation in the middle of the
  1627. /// specified rectangle. It is used to draw title text rotated 90 or 270 degrees.
  1628. /// </summary>
  1629. /// <param name="graph">Chart graphics to apply transformation for.</param>
  1630. /// <param name="titlePosition">Title position.</param>
  1631. /// <returns>Old graphics transformation matrix.</returns>
  1632. private Matrix SetRotationTransformation(ChartGraphics graph, RectangleF titlePosition)
  1633. {
  1634. // Save old graphics transformation
  1635. Matrix oldTransform = graph.Transform.Clone();
  1636. // Rotate left tile 90 degrees at center
  1637. PointF center = PointF.Empty;
  1638. center.X = titlePosition.X + titlePosition.Width / 2F;
  1639. center.Y = titlePosition.Y + titlePosition.Height / 2F;
  1640. // Create and set new transformation matrix
  1641. float angle = (this.GetTextOrientation() == TextOrientation.Rotated90) ? 90f : -90f;
  1642. Matrix newMatrix = graph.Transform.Clone();
  1643. newMatrix.RotateAt(angle, graph.GetAbsolutePoint(center));
  1644. graph.Transform = newMatrix;
  1645. return oldTransform;
  1646. }
  1647. /// <summary>
  1648. /// Draws a radial line in circular Common.Chart area.
  1649. /// </summary>
  1650. /// <param name="obj">Object requesting the painting.</param>
  1651. /// <param name="graph">Graphics path.</param>
  1652. /// <param name="color">Line color.</param>
  1653. /// <param name="width">Line width.</param>
  1654. /// <param name="style">Line style.</param>
  1655. /// <param name="position">X axis circular position.</param>
  1656. internal void DrawRadialLine(
  1657. object obj,
  1658. ChartGraphics graph,
  1659. Color color,
  1660. int width,
  1661. ChartDashStyle style,
  1662. double position)
  1663. {
  1664. // Create circle position rectangle
  1665. RectangleF rect = ChartArea.PlotAreaPosition.ToRectangleF();
  1666. rect = graph.GetAbsoluteRectangle(rect);
  1667. // Make sure the rectangle width equals rectangle height for the circle
  1668. if (rect.Width != rect.Height)
  1669. {
  1670. if (rect.Width > rect.Height)
  1671. {
  1672. rect.X += (rect.Width - rect.Height) / 2f;
  1673. rect.Width = rect.Height;
  1674. }
  1675. else
  1676. {
  1677. rect.Y += (rect.Height - rect.Width) / 2f;
  1678. rect.Height = rect.Width;
  1679. }
  1680. }
  1681. // Convert axis position to angle
  1682. float angle = ChartArea.CircularPositionToAngle(position);
  1683. // Set clipping region to the polygon
  1684. Region oldRegion = null;
  1685. if (ChartArea.CircularUsePolygons)
  1686. {
  1687. oldRegion = graph.Clip;
  1688. graph.Clip = new Region(graph.GetPolygonCirclePath(rect, ChartArea.CircularSectorsNumber));
  1689. }
  1690. // Get center point
  1691. PointF centerPoint = graph.GetAbsolutePoint(ChartArea.circularCenter);
  1692. // Set graphics rotation matrix
  1693. Matrix oldMatrix = graph.Transform;
  1694. Matrix newMatrix = oldMatrix.Clone();
  1695. newMatrix.RotateAt(
  1696. angle,
  1697. centerPoint);
  1698. graph.Transform = newMatrix;
  1699. // Draw Line
  1700. PointF endPoint = new PointF(rect.X + rect.Width / 2f, rect.Y);
  1701. graph.DrawLineAbs(color, width, style, centerPoint, endPoint);
  1702. // Process selection regions
  1703. if (this.Common.ProcessModeRegions)
  1704. {
  1705. using (GraphicsPath path = new GraphicsPath())
  1706. {
  1707. path.AddLine(centerPoint, endPoint);
  1708. path.Transform(newMatrix);
  1709. try
  1710. {
  1711. using (Pen pen = new Pen(Color.Black, width + 2))
  1712. {
  1713. path.Widen(pen);
  1714. this.Common.HotRegionsList.AddHotRegion(path, false, ChartElementType.Gridlines, obj);
  1715. }
  1716. }
  1717. catch (OutOfMemoryException)
  1718. {
  1719. // GraphicsPath.Widen incorrectly throws OutOfMemoryException
  1720. // catching here and reacting by not widening
  1721. }
  1722. catch (ArgumentException)
  1723. {
  1724. }
  1725. }
  1726. }
  1727. // Restore graphics
  1728. graph.Transform = oldMatrix;
  1729. newMatrix.Dispose();
  1730. // Restore clip region
  1731. if (ChartArea.CircularUsePolygons)
  1732. {
  1733. graph.Clip = oldRegion;
  1734. }
  1735. }
  1736. /// <summary>
  1737. /// Draws a circular line in circular Common.Chart area.
  1738. /// </summary>
  1739. /// <param name="obj">Object requesting the painting.</param>
  1740. /// <param name="graph">Graphics path.</param>
  1741. /// <param name="color">Line color.</param>
  1742. /// <param name="width">Line width.</param>
  1743. /// <param name="style">Line style.</param>
  1744. /// <param name="position">Line position.</param>
  1745. internal void DrawCircularLine(
  1746. object obj,
  1747. ChartGraphics graph,
  1748. Color color,
  1749. int width,
  1750. ChartDashStyle style,
  1751. float position
  1752. )
  1753. {
  1754. // Create circle position rectangle
  1755. RectangleF rect = ChartArea.PlotAreaPosition.ToRectangleF();
  1756. rect = graph.GetAbsoluteRectangle(rect);
  1757. // Make sure the rectangle width equals rectangle height for the circle
  1758. if (rect.Width != rect.Height)
  1759. {
  1760. if (rect.Width > rect.Height)
  1761. {
  1762. rect.X += (rect.Width - rect.Height) / 2f;
  1763. rect.Width = rect.Height;
  1764. }
  1765. else
  1766. {
  1767. rect.Y += (rect.Height - rect.Width) / 2f;
  1768. rect.Height = rect.Width;
  1769. }
  1770. }
  1771. // Inflate rectangle
  1772. PointF absPoint = graph.GetAbsolutePoint(new PointF(position, position));
  1773. float rectInflate = absPoint.Y - rect.Top;
  1774. rect.Inflate(-rectInflate, -rectInflate);
  1775. // Create circle pen
  1776. Pen circlePen = new Pen(color, width);
  1777. circlePen.DashStyle = graph.GetPenStyle(style);
  1778. // Draw circle
  1779. if (ChartArea.CircularUsePolygons)
  1780. {
  1781. // Draw eaqula sides polygon
  1782. graph.DrawCircleAbs(circlePen, null, rect, ChartArea.CircularSectorsNumber, false);
  1783. }
  1784. else
  1785. {
  1786. graph.DrawEllipse(circlePen, rect);
  1787. }
  1788. // Process selection regions
  1789. if (this.Common.ProcessModeRegions)
  1790. {
  1791. // Bounding rectangle must be more than 1 pixel by 1 pixel
  1792. if (rect.Width >= 1f && rect.Height > 1)
  1793. {
  1794. GraphicsPath path = null;
  1795. try
  1796. {
  1797. if (ChartArea.CircularUsePolygons)
  1798. {
  1799. path = graph.GetPolygonCirclePath(rect, ChartArea.CircularSectorsNumber);
  1800. }
  1801. else
  1802. {
  1803. path = new GraphicsPath();
  1804. path.AddEllipse(rect);
  1805. }
  1806. circlePen.Width += 2;
  1807. path.Widen(circlePen);
  1808. this.Common.HotRegionsList.AddHotRegion(path, false, ChartElementType.Gridlines, obj);
  1809. }
  1810. catch (OutOfMemoryException)
  1811. {
  1812. // GraphicsPath.Widen incorrectly throws OutOfMemoryException
  1813. // catching here and reacting by not widening
  1814. }
  1815. catch (ArgumentException)
  1816. {
  1817. }
  1818. finally
  1819. {
  1820. path.Dispose();
  1821. }
  1822. }
  1823. }
  1824. }
  1825. /// <summary>
  1826. /// Draw axis title in 3D.
  1827. /// </summary>
  1828. /// <param name="graph">Reference to the Chart Graphics object</param>
  1829. private void DrawAxis3DTitle(ChartGraphics graph)
  1830. {
  1831. // Do not draw title if axis is not enabled
  1832. if (!this.enabled)
  1833. {
  1834. return;
  1835. }
  1836. string axisTitle = this.Title;
  1837. // Draw axis title
  1838. PointF rotationCenter = PointF.Empty;
  1839. int angle = 0;
  1840. // Set title alignment
  1841. using (StringFormat format = new StringFormat())
  1842. {
  1843. format.Alignment = this.TitleAlignment;
  1844. format.Trimming = StringTrimming.EllipsisCharacter;
  1845. format.FormatFlags |= StringFormatFlags.LineLimit;
  1846. // Measure title size for non-centered aligment
  1847. SizeF realTitleSize = graph.MeasureString(axisTitle.Replace("\\n", "\n"), this.TitleFont, new SizeF(10000f, 10000f), format, this.GetTextOrientation());
  1848. SizeF axisTitleSize = SizeF.Empty;
  1849. if (format.Alignment != StringAlignment.Center)
  1850. {
  1851. axisTitleSize = realTitleSize;
  1852. if (this.IsTextVertical)
  1853. {
  1854. // Switch height and width for vertical axis
  1855. float tempValue = axisTitleSize.Height;
  1856. axisTitleSize.Height = axisTitleSize.Width;
  1857. axisTitleSize.Width = tempValue;
  1858. }
  1859. // Get relative size
  1860. axisTitleSize = graph.GetRelativeSize(axisTitleSize);
  1861. // Change format aligment for the reversed mode
  1862. if (ChartArea.ReverseSeriesOrder)
  1863. {
  1864. if (format.Alignment == StringAlignment.Near)
  1865. {
  1866. format.Alignment = StringAlignment.Far;
  1867. }
  1868. else
  1869. {
  1870. format.Alignment = StringAlignment.Near;
  1871. }
  1872. }
  1873. }
  1874. // Set text rotation angle based on the text orientation
  1875. if (this.GetTextOrientation() == TextOrientation.Rotated90)
  1876. {
  1877. angle = 90;
  1878. }
  1879. else if (this.GetTextOrientation() == TextOrientation.Rotated270)
  1880. {
  1881. angle = -90;
  1882. }
  1883. // Calculate title center point on the axis
  1884. if (this.AxisPosition == AxisPosition.Left)
  1885. {
  1886. rotationCenter = new PointF(ChartArea.PlotAreaPosition.X, ChartArea.PlotAreaPosition.Y + ChartArea.PlotAreaPosition.Height / 2f);
  1887. if (format.Alignment == StringAlignment.Near)
  1888. {
  1889. rotationCenter.Y = ChartArea.PlotAreaPosition.Bottom - axisTitleSize.Height / 2f;
  1890. }
  1891. else if (format.Alignment == StringAlignment.Far)
  1892. {
  1893. rotationCenter.Y = ChartArea.PlotAreaPosition.Y + axisTitleSize.Height / 2f;
  1894. }
  1895. }
  1896. else if (this.AxisPosition == AxisPosition.Right)
  1897. {
  1898. rotationCenter = new PointF(ChartArea.PlotAreaPosition.Right, ChartArea.PlotAreaPosition.Y + ChartArea.PlotAreaPosition.Height / 2f);
  1899. if (format.Alignment == StringAlignment.Near)
  1900. {
  1901. rotationCenter.Y = ChartArea.PlotAreaPosition.Bottom - axisTitleSize.Height / 2f;
  1902. }
  1903. else if (format.Alignment == StringAlignment.Far)
  1904. {
  1905. rotationCenter.Y = ChartArea.PlotAreaPosition.Y + axisTitleSize.Height / 2f;
  1906. }
  1907. }
  1908. else if (this.AxisPosition == AxisPosition.Top)
  1909. {
  1910. rotationCenter = new PointF(ChartArea.PlotAreaPosition.X + ChartArea.PlotAreaPosition.Width / 2f, ChartArea.PlotAreaPosition.Y);
  1911. if (format.Alignment == StringAlignment.Near)
  1912. {
  1913. rotationCenter.X = ChartArea.PlotAreaPosition.X + axisTitleSize.Width / 2f;
  1914. }
  1915. else if (format.Alignment == StringAlignment.Far)
  1916. {
  1917. rotationCenter.X = ChartArea.PlotAreaPosition.Right - axisTitleSize.Width / 2f;
  1918. }
  1919. }
  1920. else if (this.AxisPosition == AxisPosition.Bottom)
  1921. {
  1922. rotationCenter = new PointF(ChartArea.PlotAreaPosition.X + ChartArea.PlotAreaPosition.Width / 2f, ChartArea.PlotAreaPosition.Bottom);
  1923. if (format.Alignment == StringAlignment.Near)
  1924. {
  1925. rotationCenter.X = ChartArea.PlotAreaPosition.X + axisTitleSize.Width / 2f;
  1926. }
  1927. else if (format.Alignment == StringAlignment.Far)
  1928. {
  1929. rotationCenter.X = ChartArea.PlotAreaPosition.Right - axisTitleSize.Width / 2f;
  1930. }
  1931. }
  1932. // Transform center of title coordinates and calculate axis angle
  1933. bool isOnEdge = false;
  1934. float zPosition = this.GetMarksZPosition(out isOnEdge);
  1935. Point3D[] rotationCenterPoints = null;
  1936. float angleAxis = 0;
  1937. if (this.AxisPosition == AxisPosition.Top || this.AxisPosition == AxisPosition.Bottom)
  1938. {
  1939. rotationCenterPoints = new Point3D[] {
  1940. new Point3D(rotationCenter.X, rotationCenter.Y, zPosition),
  1941. new Point3D(rotationCenter.X - 20f, rotationCenter.Y, zPosition) };
  1942. // Transform coordinates of text rotation point
  1943. ChartArea.matrix3D.TransformPoints(rotationCenterPoints);
  1944. rotationCenter = rotationCenterPoints[0].PointF;
  1945. // Get absolute coordinates
  1946. rotationCenterPoints[0].PointF = graph.GetAbsolutePoint(rotationCenterPoints[0].PointF);
  1947. rotationCenterPoints[1].PointF = graph.GetAbsolutePoint(rotationCenterPoints[1].PointF);
  1948. // Calculate X axis angle
  1949. angleAxis = (float)Math.Atan(
  1950. (rotationCenterPoints[1].Y - rotationCenterPoints[0].Y) /
  1951. (rotationCenterPoints[1].X - rotationCenterPoints[0].X));
  1952. }
  1953. else
  1954. {
  1955. rotationCenterPoints = new Point3D[] {
  1956. new Point3D(rotationCenter.X, rotationCenter.Y, zPosition),
  1957. new Point3D(rotationCenter.X, rotationCenter.Y - 20f, zPosition) };
  1958. // Transform coordinates of text rotation point
  1959. ChartArea.matrix3D.TransformPoints(rotationCenterPoints);
  1960. rotationCenter = rotationCenterPoints[0].PointF;
  1961. // Get absolute coordinates
  1962. rotationCenterPoints[0].PointF = graph.GetAbsolutePoint(rotationCenterPoints[0].PointF);
  1963. rotationCenterPoints[1].PointF = graph.GetAbsolutePoint(rotationCenterPoints[1].PointF);
  1964. // Calculate Y axis angle
  1965. if (rotationCenterPoints[1].Y != rotationCenterPoints[0].Y)
  1966. {
  1967. angleAxis = -(float)Math.Atan(
  1968. (rotationCenterPoints[1].X - rotationCenterPoints[0].X) /
  1969. (rotationCenterPoints[1].Y - rotationCenterPoints[0].Y));
  1970. }
  1971. }
  1972. angle += (int)Math.Round(angleAxis * 180f / (float)Math.PI);
  1973. // Calculate title center offset from the axis line
  1974. float offset = this.labelSize + this.markSize + this.titleSize / 2f;
  1975. float dX = 0f, dY = 0f;
  1976. // Adjust center of title with labels, marker and title size
  1977. if (this.AxisPosition == AxisPosition.Left)
  1978. {
  1979. dX = (float)(offset * Math.Cos(angleAxis));
  1980. rotationCenter.X -= dX;
  1981. }
  1982. else if (this.AxisPosition == AxisPosition.Right)
  1983. {
  1984. dX = (float)(offset * Math.Cos(angleAxis));
  1985. rotationCenter.X += dX;
  1986. }
  1987. else if (this.AxisPosition == AxisPosition.Top)
  1988. {
  1989. dY = (float)(offset * Math.Cos(angleAxis));
  1990. dX = (float)(offset * Math.Sin(angleAxis));
  1991. rotationCenter.Y -= dY;
  1992. if (dY > 0)
  1993. {
  1994. rotationCenter.X += dX;
  1995. }
  1996. else
  1997. {
  1998. rotationCenter.X -= dX;
  1999. }
  2000. }
  2001. else if (this.AxisPosition == AxisPosition.Bottom)
  2002. {
  2003. dY = (float)(offset * Math.Cos(angleAxis));
  2004. dX = (float)(offset * Math.Sin(angleAxis));
  2005. rotationCenter.Y += dY;
  2006. if (dY > 0)
  2007. {
  2008. rotationCenter.X -= dX;
  2009. }
  2010. else
  2011. {
  2012. rotationCenter.X += dX;
  2013. }
  2014. }
  2015. // Always align text in the center
  2016. format.LineAlignment = StringAlignment.Center;
  2017. format.Alignment = StringAlignment.Center;
  2018. // SQL VSTS Fix #259954, Dev10: 591135 Windows 7 crashes on empty transformation.
  2019. if (rotationCenter.IsEmpty || float.IsNaN(rotationCenter.X) || float.IsNaN(rotationCenter.Y))
  2020. {
  2021. return;
  2022. }
  2023. // Draw 3D title
  2024. using (Brush brush = new SolidBrush(this.TitleForeColor))
  2025. {
  2026. graph.DrawStringRel(
  2027. axisTitle.Replace("\\n", "\n"),
  2028. this.TitleFont,
  2029. brush,
  2030. rotationCenter,
  2031. format,
  2032. angle,
  2033. this.GetTextOrientation());
  2034. }
  2035. // Add hot region
  2036. if (Common.ProcessModeRegions)
  2037. {
  2038. using (GraphicsPath hotPath = graph.GetTranformedTextRectPath(rotationCenter, realTitleSize, angle))
  2039. {
  2040. this.Common.HotRegionsList.AddHotRegion(hotPath, false, ChartElementType.AxisTitle, this);
  2041. }
  2042. }
  2043. }
  2044. }
  2045. /// <summary>
  2046. /// Select Axis line
  2047. /// </summary>
  2048. /// <param name="graph">Reference to the Chart Graphics</param>
  2049. /// <param name="backElements">Back elements of the axis should be drawn in 3D scene.</param>
  2050. internal void DrawAxisLine(ChartGraphics graph, bool backElements)
  2051. {
  2052. Axis opositeAxis;
  2053. ArrowOrientation arrowOrientation = ArrowOrientation.Top;
  2054. PointF first = Point.Empty;
  2055. PointF second = Point.Empty;
  2056. // Set the position of axis
  2057. switch (AxisPosition)
  2058. {
  2059. case AxisPosition.Left:
  2060. first.X = (float)GetAxisPosition();
  2061. first.Y = PlotAreaPosition.Bottom;
  2062. second.X = (float)GetAxisPosition();
  2063. second.Y = PlotAreaPosition.Y;
  2064. if (isReversed)
  2065. arrowOrientation = ArrowOrientation.Bottom;
  2066. else
  2067. arrowOrientation = ArrowOrientation.Top;
  2068. break;
  2069. case AxisPosition.Right:
  2070. first.X = (float)GetAxisPosition();
  2071. first.Y = PlotAreaPosition.Bottom;
  2072. second.X = (float)GetAxisPosition();
  2073. second.Y = PlotAreaPosition.Y;
  2074. if (isReversed)
  2075. arrowOrientation = ArrowOrientation.Bottom;
  2076. else
  2077. arrowOrientation = ArrowOrientation.Top;
  2078. break;
  2079. case AxisPosition.Bottom:
  2080. first.X = PlotAreaPosition.X;
  2081. first.Y = (float)GetAxisPosition();
  2082. second.X = PlotAreaPosition.Right;
  2083. second.Y = (float)GetAxisPosition();
  2084. if (isReversed)
  2085. arrowOrientation = ArrowOrientation.Left;
  2086. else
  2087. arrowOrientation = ArrowOrientation.Right;
  2088. break;
  2089. case AxisPosition.Top:
  2090. first.X = PlotAreaPosition.X;
  2091. first.Y = (float)GetAxisPosition();
  2092. second.X = PlotAreaPosition.Right;
  2093. second.Y = (float)GetAxisPosition();
  2094. if (isReversed)
  2095. arrowOrientation = ArrowOrientation.Left;
  2096. else
  2097. arrowOrientation = ArrowOrientation.Right;
  2098. break;
  2099. }
  2100. // Update axis line position for circular area
  2101. if (ChartArea.chartAreaIsCurcular)
  2102. {
  2103. first.Y = PlotAreaPosition.Y + PlotAreaPosition.Height / 2f;
  2104. }
  2105. if (Common.ProcessModePaint)
  2106. {
  2107. if (!ChartArea.Area3DStyle.Enable3D || ChartArea.chartAreaIsCurcular)
  2108. {
  2109. // Start Svg/Flash Selection mode
  2110. graph.StartHotRegion( this._url, _toolTip );
  2111. // Draw the line
  2112. graph.DrawLineRel(_lineColor, _lineWidth, _lineDashStyle, first, second);
  2113. // End Svg/Flash Selection mode
  2114. graph.EndHotRegion( );
  2115. // Opposite axis. Arrow uses this axis to find
  2116. // a shift from Common.Chart area border. This shift
  2117. // depend on Tick mark size.
  2118. switch (arrowOrientation)
  2119. {
  2120. case ArrowOrientation.Left:
  2121. opositeAxis = ChartArea.AxisX;
  2122. break;
  2123. case ArrowOrientation.Right:
  2124. opositeAxis = ChartArea.AxisX2;
  2125. break;
  2126. case ArrowOrientation.Top:
  2127. opositeAxis = ChartArea.AxisY2;
  2128. break;
  2129. case ArrowOrientation.Bottom:
  2130. opositeAxis = ChartArea.AxisY;
  2131. break;
  2132. default:
  2133. opositeAxis = ChartArea.AxisX;
  2134. break;
  2135. }
  2136. // Draw arrow
  2137. PointF arrowPosition;
  2138. if (isReversed)
  2139. arrowPosition = first;
  2140. else
  2141. arrowPosition = second;
  2142. // Draw Arrow
  2143. graph.DrawArrowRel(arrowPosition, arrowOrientation, _arrowStyle, _lineColor, _lineWidth, _lineDashStyle, opositeAxis.majorTickMark.Size, _lineWidth);
  2144. }
  2145. else
  2146. {
  2147. Draw3DAxisLine(graph, first, second, (this.AxisPosition == AxisPosition.Top || this.AxisPosition == AxisPosition.Bottom), backElements);
  2148. }
  2149. }
  2150. }
  2151. /// <summary>
  2152. /// Draws the axis line hot region.
  2153. /// </summary>
  2154. /// <param name="graph">The graph.</param>
  2155. /// <param name="backElements">set to <c>true</c> if we draw back elements.</param>
  2156. private void DrawAxisLineHotRegion(ChartGraphics graph, bool backElements)
  2157. {
  2158. if (Common.ProcessModeRegions)
  2159. {
  2160. //VSTS #229835: During the 3D rendering the axis is drawn twice:
  2161. //1. In PrePaint() both axis and backelements (labels) are drawn.
  2162. //2. In Paint() the axis is redrawn without labels and as a result it creates a second hot region which covered the labels' hotregions.
  2163. //In order to avoid this we have to suppress the hotregion drawing in the Paint using the backElements flag (it's false during the Paint)
  2164. //The circular charts and 2D charts are drawn only once in Paint() so we draw the hot regions.
  2165. if (backElements || !ChartArea.Area3DStyle.Enable3D || ChartArea.chartAreaIsCurcular)
  2166. {
  2167. DrawAxisLineHotRegion(graph);
  2168. }
  2169. }
  2170. }
  2171. /// <summary>
  2172. /// Adds the axis hot region
  2173. /// </summary>
  2174. /// <param name="graph">The chart graphics instance.</param>
  2175. private void DrawAxisLineHotRegion(ChartGraphics graph)
  2176. {
  2177. using (GraphicsPath path = new GraphicsPath())
  2178. {
  2179. // Find the topLeft(first) and bottomRight(second) points of the hotregion rectangle
  2180. PointF first = PointF.Empty;
  2181. PointF second = PointF.Empty;
  2182. float axisPosition = (float)GetAxisPosition();
  2183. switch (this.AxisPosition)
  2184. {
  2185. case AxisPosition.Left:
  2186. first.X = axisPosition - (labelSize + markSize);
  2187. first.Y = PlotAreaPosition.Y;
  2188. second.X = axisPosition;
  2189. second.Y = PlotAreaPosition.Bottom;
  2190. break;
  2191. case AxisPosition.Right:
  2192. first.X = axisPosition;
  2193. first.Y = PlotAreaPosition.Y;
  2194. second.X = axisPosition + labelSize + markSize;
  2195. second.Y = PlotAreaPosition.Bottom;
  2196. break;
  2197. case AxisPosition.Bottom:
  2198. first.X = PlotAreaPosition.X;
  2199. first.Y = axisPosition;
  2200. second.X = PlotAreaPosition.Right;
  2201. second.Y = axisPosition + labelSize + markSize;
  2202. break;
  2203. case AxisPosition.Top:
  2204. first.X = PlotAreaPosition.X;
  2205. first.Y = axisPosition - (labelSize + markSize);
  2206. second.X = PlotAreaPosition.Right;
  2207. second.Y = axisPosition;
  2208. break;
  2209. }
  2210. // Update axis line position for circular area
  2211. if (ChartArea.chartAreaIsCurcular)
  2212. {
  2213. second.Y = PlotAreaPosition.Y + PlotAreaPosition.Height / 2f;
  2214. }
  2215. // Create rectangle and inflate it
  2216. RectangleF rect = new RectangleF(first.X, first.Y, second.X - first.X, second.Y - first.Y);
  2217. SizeF size = graph.GetRelativeSize(new SizeF(3, 3));
  2218. if (AxisPosition == AxisPosition.Top || AxisPosition == AxisPosition.Bottom)
  2219. {
  2220. rect.Inflate(2, size.Height);
  2221. }
  2222. else
  2223. {
  2224. rect.Inflate(size.Width, 2);
  2225. }
  2226. // Get the rectangle points
  2227. PointF[] points = new PointF[] {
  2228. new PointF(rect.Left, rect.Top),
  2229. new PointF(rect.Right, rect.Top),
  2230. new PointF(rect.Right, rect.Bottom),
  2231. new PointF(rect.Left, rect.Bottom)};
  2232. // If we are dealing with the 3D - transform the rectangle
  2233. if (ChartArea.Area3DStyle.Enable3D && !ChartArea.chartAreaIsCurcular)
  2234. {
  2235. Boolean axisOnEdge = false;
  2236. float zPositon = GetMarksZPosition(out axisOnEdge);
  2237. // Convert points to 3D
  2238. Point3D[] points3D = new Point3D[points.Length];
  2239. for (int i = 0; i < points.Length; i++)
  2240. {
  2241. points3D[i] = new Point3D(points[i].X, points[i].Y, zPositon);
  2242. }
  2243. // Transform
  2244. ChartArea.matrix3D.TransformPoints(points3D);
  2245. // Convert to 2D
  2246. for (int i = 0; i < points3D.Length; i++)
  2247. {
  2248. points[i] = points3D[i].PointF;
  2249. }
  2250. }
  2251. // Transform points to absolute cooordinates
  2252. for (int i = 0; i < points.Length; i++)
  2253. {
  2254. points[i] = graph.GetAbsolutePoint(points[i]);
  2255. }
  2256. // Add the points to the path
  2257. path.AddPolygon(points);
  2258. Common.HotRegionsList.AddHotRegion(
  2259. graph,
  2260. path,
  2261. false,
  2262. this._toolTip,
  2263. string.Empty,
  2264. string.Empty,
  2265. string.Empty,
  2266. this,
  2267. ChartElementType.Axis);
  2268. }
  2269. }
  2270. /// <summary>
  2271. /// Draws axis line in 3D space.
  2272. /// </summary>
  2273. /// <param name="graph">Reference to the Chart Graphics object.</param>
  2274. /// <param name="point1">First line point.</param>
  2275. /// <param name="point2">Second line point.</param>
  2276. /// <param name="horizontal">Indicates that tick mark line is horizontal</param>
  2277. /// <param name="backElements">Only back elements of axis should be drawn.</param>
  2278. private void Draw3DAxisLine(
  2279. ChartGraphics graph,
  2280. PointF point1,
  2281. PointF point2,
  2282. bool horizontal,
  2283. bool backElements
  2284. )
  2285. {
  2286. // Check if axis is positioned on the plot area adge
  2287. bool onEdge = this.IsAxisOnAreaEdge;
  2288. // Check if axis tick marks are drawn inside plotting area
  2289. bool tickMarksOnEdge = onEdge;
  2290. if (tickMarksOnEdge &&
  2291. this.MajorTickMark.TickMarkStyle == TickMarkStyle.AcrossAxis ||
  2292. this.MajorTickMark.TickMarkStyle == TickMarkStyle.InsideArea ||
  2293. this.MinorTickMark.TickMarkStyle == TickMarkStyle.AcrossAxis ||
  2294. this.MinorTickMark.TickMarkStyle == TickMarkStyle.InsideArea)
  2295. {
  2296. tickMarksOnEdge = false;
  2297. }
  2298. // Make sure first point of axis coordinates has smaller values
  2299. if ((horizontal && point1.X > point2.X) ||
  2300. (!horizontal && point1.Y > point2.Y))
  2301. {
  2302. PointF tempPoint = new PointF(point1.X, point1.Y);
  2303. point1.X = point2.X;
  2304. point1.Y = point2.Y;
  2305. point2 = tempPoint;
  2306. }
  2307. // Check if the front/back wall is on the top drawing layer
  2308. float zPositon = ChartArea.IsMainSceneWallOnFront() ? ChartArea.areaSceneDepth : 0f;
  2309. SurfaceNames surfName = ChartArea.IsMainSceneWallOnFront() ? SurfaceNames.Front : SurfaceNames.Back;
  2310. if (ChartArea.ShouldDrawOnSurface(SurfaceNames.Back, backElements, tickMarksOnEdge))
  2311. {
  2312. // Start Svg Selection mode
  2313. graph.StartHotRegion( this._url, _toolTip );
  2314. // Draw axis line on the back/front wall
  2315. graph.Draw3DLine(
  2316. ChartArea.matrix3D,
  2317. _lineColor, _lineWidth, _lineDashStyle,
  2318. new Point3D(point1.X, point1.Y, zPositon),
  2319. new Point3D(point2.X, point2.Y, zPositon),
  2320. Common,
  2321. this,
  2322. ChartElementType.Nothing
  2323. );
  2324. // End Svg Selection mode
  2325. graph.EndHotRegion();
  2326. }
  2327. // Check if the back wall is on the top drawing layer
  2328. zPositon = ChartArea.IsMainSceneWallOnFront() ? 0f : ChartArea.areaSceneDepth;
  2329. surfName = ChartArea.IsMainSceneWallOnFront() ? SurfaceNames.Back : SurfaceNames.Front;
  2330. if (ChartArea.ShouldDrawOnSurface(surfName, backElements, tickMarksOnEdge))
  2331. {
  2332. // Draw axis line on the front wall
  2333. if (!onEdge ||
  2334. (this.AxisPosition == AxisPosition.Bottom && ChartArea.IsBottomSceneWallVisible()) ||
  2335. (this.AxisPosition == AxisPosition.Left && ChartArea.IsSideSceneWallOnLeft()) ||
  2336. (this.AxisPosition == AxisPosition.Right && !ChartArea.IsSideSceneWallOnLeft()))
  2337. {
  2338. // Start Svg Selection mode
  2339. graph.StartHotRegion( this._url, _toolTip );
  2340. graph.Draw3DLine(
  2341. ChartArea.matrix3D,
  2342. _lineColor, _lineWidth, _lineDashStyle,
  2343. new Point3D(point1.X, point1.Y, zPositon),
  2344. new Point3D(point2.X, point2.Y, zPositon),
  2345. Common,
  2346. this,
  2347. ChartElementType.Nothing
  2348. );
  2349. // End Svg Selection mode
  2350. graph.EndHotRegion();
  2351. }
  2352. }
  2353. // Check if the left/top wall is on the top drawing layer
  2354. SurfaceNames surfaceName = (this.AxisPosition == AxisPosition.Left || this.AxisPosition == AxisPosition.Right) ? SurfaceNames.Top : SurfaceNames.Left;
  2355. if (ChartArea.ShouldDrawOnSurface(surfaceName, backElements, tickMarksOnEdge))
  2356. {
  2357. // Draw axis line on the left/top side walls
  2358. if (!onEdge ||
  2359. (this.AxisPosition == AxisPosition.Bottom && (ChartArea.IsBottomSceneWallVisible() || ChartArea.IsSideSceneWallOnLeft())) ||
  2360. (this.AxisPosition == AxisPosition.Left && ChartArea.IsSideSceneWallOnLeft()) ||
  2361. (this.AxisPosition == AxisPosition.Right && !ChartArea.IsSideSceneWallOnLeft()) ||
  2362. (this.AxisPosition == AxisPosition.Top && ChartArea.IsSideSceneWallOnLeft()))
  2363. {
  2364. // Start Svg Selection mode
  2365. graph.StartHotRegion( this._url, _toolTip );
  2366. graph.Draw3DLine(
  2367. ChartArea.matrix3D,
  2368. _lineColor, _lineWidth, _lineDashStyle,
  2369. new Point3D(point1.X, point1.Y, ChartArea.areaSceneDepth),
  2370. new Point3D(point1.X, point1.Y, 0f),
  2371. Common,
  2372. this,
  2373. ChartElementType.Nothing
  2374. );
  2375. // End Svg Selection mode
  2376. graph.EndHotRegion( );
  2377. }
  2378. }
  2379. // Check if the right/bottom wall is on the top drawing layer
  2380. surfaceName = (this.AxisPosition == AxisPosition.Left || this.AxisPosition == AxisPosition.Right) ? SurfaceNames.Bottom : SurfaceNames.Right;
  2381. if (ChartArea.ShouldDrawOnSurface(surfaceName, backElements, tickMarksOnEdge))
  2382. {
  2383. // Draw axis line on the bottom/right side walls
  2384. if (!onEdge ||
  2385. (this.AxisPosition == AxisPosition.Bottom && (ChartArea.IsBottomSceneWallVisible() || !ChartArea.IsSideSceneWallOnLeft())) ||
  2386. (this.AxisPosition == AxisPosition.Left && (ChartArea.IsSideSceneWallOnLeft() || ChartArea.IsBottomSceneWallVisible())) ||
  2387. (this.AxisPosition == AxisPosition.Right && (!ChartArea.IsSideSceneWallOnLeft() || ChartArea.IsBottomSceneWallVisible())) ||
  2388. (this.AxisPosition == AxisPosition.Top && !ChartArea.IsSideSceneWallOnLeft())
  2389. )
  2390. {
  2391. // Start Svg Selection mode
  2392. graph.StartHotRegion( this._url, _toolTip );
  2393. graph.Draw3DLine(
  2394. ChartArea.matrix3D,
  2395. _lineColor, _lineWidth, _lineDashStyle,
  2396. new Point3D(point2.X, point2.Y, ChartArea.areaSceneDepth),
  2397. new Point3D(point2.X, point2.Y, 0f),
  2398. Common,
  2399. this,
  2400. ChartElementType.Nothing
  2401. );
  2402. // End Svg Selection mode
  2403. graph.EndHotRegion();
  2404. }
  2405. }
  2406. }
  2407. /// <summary>
  2408. /// Gets Z position of axis tick marks and labels.
  2409. /// </summary>
  2410. /// <param name="axisOnEdge">Returns true if axis is on the edge.</param>
  2411. /// <returns>Marks Z position.</returns>
  2412. internal float GetMarksZPosition(out bool axisOnEdge)
  2413. {
  2414. axisOnEdge = this.IsAxisOnAreaEdge;
  2415. if (!this.GetIsMarksNextToAxis())
  2416. {
  2417. // Marks are forced to be on the area edge
  2418. axisOnEdge = true;
  2419. }
  2420. float wallZPosition = 0f;
  2421. if (this.AxisPosition == AxisPosition.Bottom && (ChartArea.IsBottomSceneWallVisible() || !axisOnEdge))
  2422. {
  2423. wallZPosition = ChartArea.areaSceneDepth;
  2424. }
  2425. if (this.AxisPosition == AxisPosition.Left && (ChartArea.IsSideSceneWallOnLeft() || !axisOnEdge))
  2426. {
  2427. wallZPosition = ChartArea.areaSceneDepth;
  2428. }
  2429. if (this.AxisPosition == AxisPosition.Right && (!ChartArea.IsSideSceneWallOnLeft() || !axisOnEdge))
  2430. {
  2431. wallZPosition = ChartArea.areaSceneDepth;
  2432. }
  2433. if (this.AxisPosition == AxisPosition.Top && !axisOnEdge)
  2434. {
  2435. wallZPosition = ChartArea.areaSceneDepth;
  2436. }
  2437. // Check if front wall is shown
  2438. if (ChartArea.IsMainSceneWallOnFront())
  2439. {
  2440. // Switch Z position of tick mark
  2441. wallZPosition = (wallZPosition == 0f) ? ChartArea.areaSceneDepth : 0f;
  2442. }
  2443. return wallZPosition;
  2444. }
  2445. /// <summary>
  2446. /// Paint Axis Grid lines
  2447. /// </summary>
  2448. /// <param name="graph">Reference to the Chart Graphics object</param>
  2449. internal void PaintGrids(ChartGraphics graph)
  2450. {
  2451. object obj;
  2452. PaintGrids(graph, out obj);
  2453. }
  2454. /// <summary>
  2455. /// Paint Axis Grid lines or
  2456. /// hit test function for grid lines
  2457. /// </summary>
  2458. /// <param name="graph">Reference to the Chart Graphics object</param>
  2459. /// <param name="obj">Returns selected grid object</param>
  2460. internal void PaintGrids(ChartGraphics graph, out object obj)
  2461. {
  2462. obj = null;
  2463. #if SUBAXES
  2464. // Paint grids of sub-axis
  2465. if(!ChartArea.Area3DStyle.Enable3D &&
  2466. !ChartArea.chartAreaIsCurcular)
  2467. {
  2468. foreach(SubAxis subAxis in this.SubAxes)
  2469. {
  2470. subAxis.PaintGrids( graph, out obj);
  2471. }
  2472. }
  2473. #endif // SUBAXES
  2474. // Axis is disabled
  2475. if (enabled == false)
  2476. return;
  2477. // Paint Minor grid lines
  2478. minorGrid.Paint(graph);
  2479. // Paint Major grid lines
  2480. majorGrid.Paint(graph);
  2481. }
  2482. /// <summary>
  2483. /// Paint Axis Strip lines
  2484. /// </summary>
  2485. /// <param name="graph">Reference to the Chart Graphics object</param>
  2486. /// <param name="drawLinesOnly">Indicates if Lines or Stripes should be drawn.</param>
  2487. internal void PaintStrips(ChartGraphics graph, bool drawLinesOnly)
  2488. {
  2489. object obj;
  2490. PaintStrips(graph, false, 0, 0, out obj, drawLinesOnly);
  2491. }
  2492. /// <summary>
  2493. /// Paint Axis Strip lines or
  2494. /// hit test function for Strip lines
  2495. /// </summary>
  2496. /// <param name="graph">Reference to the Chart Graphics object</param>
  2497. /// <param name="selectionMode">The selection mode is active</param>
  2498. /// <param name="x">X coordinate</param>
  2499. /// <param name="y">Y coordinate</param>
  2500. /// <param name="obj">Returns selected grid object</param>
  2501. /// <param name="drawLinesOnly">Indicates if Lines or Stripes should be drawn.</param>
  2502. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "y"),
  2503. System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "x"),
  2504. System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "selectionMode")]
  2505. internal void PaintStrips(ChartGraphics graph, bool selectionMode, int x, int y, out object obj, bool drawLinesOnly)
  2506. {
  2507. obj = null;
  2508. #if SUBAXES
  2509. // Paint strips of sub-axis
  2510. if(ChartArea.IsSubAxesSupported)
  2511. {
  2512. foreach(SubAxis subAxis in this.SubAxes)
  2513. {
  2514. subAxis.PaintStrips( graph, selectionMode, x, y, out obj, drawLinesOnly);
  2515. }
  2516. }
  2517. #endif // SUBAXES
  2518. // Axis is disabled
  2519. if (enabled == false)
  2520. return;
  2521. // Add axis isInterlaced strip lines into the collection
  2522. bool interlacedStripAdded = AddInterlacedStrip();
  2523. // Draw axis strips and lines
  2524. foreach (StripLine strip in this.StripLines)
  2525. {
  2526. strip.Paint(graph, this.Common, drawLinesOnly);
  2527. }
  2528. // Remove axis isInterlaced strip line from the collection after drawing
  2529. if (interlacedStripAdded)
  2530. {
  2531. // Remove isInterlaced strips which always is the first strip line
  2532. this.StripLines.RemoveAt(0);
  2533. }
  2534. }
  2535. /// <summary>
  2536. /// Helper function which adds temp. strip lines into the collection
  2537. /// to display isInterlaced lines in axis.
  2538. /// </summary>
  2539. private bool AddInterlacedStrip()
  2540. {
  2541. bool addStrip = false;
  2542. if (this.IsInterlaced)
  2543. {
  2544. StripLine stripLine = new StripLine();
  2545. stripLine.interlaced = true;
  2546. // VSTS fix of 164115 IsInterlaced StripLines with no border are rendered with black border, regression of VSTS 136763
  2547. stripLine.BorderColor = Color.Empty;
  2548. // Get interval from grid lines, tick marks or labels
  2549. if (this.MajorGrid.Enabled && this.MajorGrid.GetInterval() != 0.0)
  2550. {
  2551. addStrip = true;
  2552. stripLine.Interval = this.MajorGrid.GetInterval() * 2.0;
  2553. stripLine.IntervalType = this.MajorGrid.GetIntervalType();
  2554. stripLine.IntervalOffset = this.MajorGrid.GetIntervalOffset();
  2555. stripLine.IntervalOffsetType = this.MajorGrid.GetIntervalOffsetType();
  2556. stripLine.StripWidth = this.MajorGrid.GetInterval();
  2557. stripLine.StripWidthType = this.MajorGrid.GetIntervalType();
  2558. }
  2559. else if (this.MajorTickMark.Enabled && this.MajorTickMark.GetInterval() != 0.0)
  2560. {
  2561. addStrip = true;
  2562. stripLine.Interval = this.MajorTickMark.GetInterval() * 2.0;
  2563. stripLine.IntervalType = this.MajorTickMark.GetIntervalType();
  2564. stripLine.IntervalOffset = this.MajorTickMark.GetIntervalOffset();
  2565. stripLine.IntervalOffsetType = this.MajorTickMark.GetIntervalOffsetType();
  2566. stripLine.StripWidth = this.MajorTickMark.GetInterval();
  2567. stripLine.StripWidthType = this.MajorTickMark.GetIntervalType();
  2568. }
  2569. else if (this.LabelStyle.Enabled && this.LabelStyle.GetInterval() != 0.0)
  2570. {
  2571. addStrip = true;
  2572. stripLine.Interval = this.LabelStyle.GetInterval() * 2.0;
  2573. stripLine.IntervalType = this.LabelStyle.GetIntervalType();
  2574. stripLine.IntervalOffset = this.LabelStyle.GetIntervalOffset();
  2575. stripLine.IntervalOffsetType = this.LabelStyle.GetIntervalOffsetType();
  2576. stripLine.StripWidth = this.LabelStyle.GetInterval();
  2577. stripLine.StripWidthType = this.LabelStyle.GetIntervalType();
  2578. }
  2579. // Insert item into the strips collection
  2580. if (addStrip)
  2581. {
  2582. // Define stip color
  2583. if (this.InterlacedColor != Color.Empty)
  2584. {
  2585. stripLine.BackColor = this.InterlacedColor;
  2586. }
  2587. else
  2588. {
  2589. // If isInterlaced strips color is not set - use darker color of the area
  2590. if (ChartArea.BackColor == Color.Empty)
  2591. {
  2592. stripLine.BackColor = (ChartArea.Area3DStyle.Enable3D) ? Color.DarkGray : Color.LightGray;
  2593. }
  2594. else if (ChartArea.BackColor == Color.Transparent)
  2595. {
  2596. if (Common.Chart.BackColor != Color.Transparent && Common.Chart.BackColor != Color.Black)
  2597. {
  2598. stripLine.BackColor = ChartGraphics.GetGradientColor(Common.Chart.BackColor, Color.Black, 0.2);
  2599. }
  2600. else
  2601. {
  2602. stripLine.BackColor = Color.LightGray;
  2603. }
  2604. }
  2605. else
  2606. {
  2607. stripLine.BackColor = ChartGraphics.GetGradientColor(ChartArea.BackColor, Color.Black, 0.2);
  2608. }
  2609. }
  2610. // Insert strip
  2611. this.StripLines.Insert(0, stripLine);
  2612. }
  2613. }
  2614. return addStrip;
  2615. }
  2616. #endregion
  2617. #region Axis parameters recalculation and resizing methods
  2618. /// <summary>
  2619. /// This method will calculate the maximum and minimum values
  2620. /// using interval on the X axis automatically. It will make a gap between
  2621. /// data points and border of the Common.Chart area.
  2622. /// Note that this method can only be called for primary or secondary X axes.
  2623. /// </summary>
  2624. public void RoundAxisValues()
  2625. {
  2626. this.roundedXValues = true;
  2627. }
  2628. /// <summary>
  2629. /// RecalculateAxesScale axis.
  2630. /// </summary>
  2631. /// <param name="position">Plotting area position.</param>
  2632. internal void ReCalc(ElementPosition position)
  2633. {
  2634. PlotAreaPosition = position;
  2635. #if SUBAXES
  2636. // Recalculate all sub-axis
  2637. foreach(SubAxis subAxis in this.SubAxes)
  2638. {
  2639. subAxis.ReCalc( position );
  2640. }
  2641. #endif // SUBAXES
  2642. }
  2643. /// <summary>
  2644. /// This method store Axis values as minimum, maximum,
  2645. /// crossing, etc. Axis auto algorithm changes these
  2646. /// values and they have to be set to default values
  2647. /// after painting.
  2648. /// </summary>
  2649. internal void StoreAxisValues()
  2650. {
  2651. tempLabels = new CustomLabelsCollection(this);
  2652. foreach (CustomLabel label in CustomLabels)
  2653. {
  2654. tempLabels.Add(label.Clone());
  2655. }
  2656. paintMode = true;
  2657. // This field synchronies the Storing and
  2658. // resetting of temporary values
  2659. if (_storeValuesEnabled)
  2660. {
  2661. tempMaximum = maximum;
  2662. tempMinimum = minimum;
  2663. tempCrossing = crossing;
  2664. tempAutoMinimum = _autoMinimum;
  2665. tempAutoMaximum = _autoMaximum;
  2666. tempMajorGridInterval = majorGrid.interval;
  2667. tempMajorTickMarkInterval = majorTickMark.interval;
  2668. tempMinorGridInterval = minorGrid.interval;
  2669. tempMinorTickMarkInterval = minorTickMark.interval;
  2670. tempGridIntervalType = majorGrid.intervalType;
  2671. tempTickMarkIntervalType = majorTickMark.intervalType;
  2672. tempLabelInterval = labelStyle.interval;
  2673. tempLabelIntervalType = labelStyle.intervalType;
  2674. // Remember original ScaleView Position
  2675. this._originalViewPosition = this.ScaleView.Position;
  2676. // This field synchronies the Storing and
  2677. // resetting of temporary values
  2678. _storeValuesEnabled = false;
  2679. }
  2680. #if SUBAXES
  2681. // Store values of all sub-axis
  2682. if(ChartArea.IsSubAxesSupported)
  2683. {
  2684. foreach(SubAxis subAxis in this.SubAxes)
  2685. {
  2686. subAxis.StoreAxisValues( );
  2687. }
  2688. }
  2689. #endif // SUBAXES
  2690. }
  2691. /// <summary>
  2692. /// This method reset Axis values as minimum, maximum,
  2693. /// crossing, etc. Axis auto algorithm changes these
  2694. /// values and they have to be set to default values
  2695. /// after painting.
  2696. /// </summary>
  2697. internal void ResetAxisValues()
  2698. {
  2699. // Paint mode is finished
  2700. paintMode = false;
  2701. if(Common.Chart == null)
  2702. {
  2703. #if SUBAXES
  2704. else if(this is SubAxis)
  2705. {
  2706. if( ((SubAxis)this).parentAxis != null)
  2707. {
  2708. this.Common = ((SubAxis)this).parentAxis.Common;
  2709. Common.Chart = ((SubAxis)this).parentAxis.Common.Chart;
  2710. }
  2711. }
  2712. #endif // SUBAXES
  2713. }
  2714. if(Common.Chart != null && Common.Chart.Site != null && Common.Chart.Site.DesignMode)
  2715. {
  2716. ResetAutoValues();
  2717. }
  2718. // Reset back original custom labels
  2719. if (tempLabels != null)
  2720. {
  2721. CustomLabels.Clear();
  2722. foreach (CustomLabel label in tempLabels)
  2723. {
  2724. CustomLabels.Add(label.Clone());
  2725. }
  2726. tempLabels = null;
  2727. }
  2728. #if SUBAXES
  2729. // Reset values of all sub-axis
  2730. if(ChartArea.IsSubAxesSupported)
  2731. {
  2732. foreach(SubAxis subAxis in this.SubAxes)
  2733. {
  2734. subAxis.ResetAxisValues( );
  2735. }
  2736. }
  2737. #endif // SUBAXES
  2738. }
  2739. /// <summary>
  2740. /// Reset auto calculated axis values
  2741. /// </summary>
  2742. internal void ResetAutoValues()
  2743. {
  2744. refreshMinMaxFromData = true;
  2745. maximum = tempMaximum;
  2746. minimum = tempMinimum;
  2747. crossing = tempCrossing;
  2748. _autoMinimum = tempAutoMinimum;
  2749. _autoMaximum = tempAutoMaximum;
  2750. majorGrid.interval = tempMajorGridInterval;
  2751. majorTickMark.interval = tempMajorTickMarkInterval;
  2752. minorGrid.interval = tempMinorGridInterval;
  2753. minorTickMark.interval = tempMinorTickMarkInterval;
  2754. labelStyle.interval = tempLabelInterval;
  2755. majorGrid.intervalType = tempGridIntervalType;
  2756. majorTickMark.intervalType = tempTickMarkIntervalType;
  2757. labelStyle.intervalType = tempLabelIntervalType;
  2758. // Restore original ScaleView Position
  2759. if (Common.Chart != null)
  2760. {
  2761. if (!Common.Chart.serializing)
  2762. {
  2763. this.ScaleView.Position = this._originalViewPosition;
  2764. }
  2765. }
  2766. // This field synchronies the Storing and
  2767. // resetting of temporary values
  2768. _storeValuesEnabled = true;
  2769. #if SUBAXES
  2770. // Reset auto values of all sub-axis
  2771. if(ChartArea.IsSubAxesSupported)
  2772. {
  2773. foreach(SubAxis subAxis in this.SubAxes)
  2774. {
  2775. subAxis.ResetAutoValues( );
  2776. }
  2777. }
  2778. #endif // SUBAXES
  2779. }
  2780. /// <summary>
  2781. /// Calculate size of the axis elements like title, labels and marks.
  2782. /// </summary>
  2783. /// <param name="chartGraph">Chart graphics object.</param>
  2784. /// <param name="chartAreaPosition">The Chart area position.</param>
  2785. /// <param name="plotArea">Plotting area size.</param>
  2786. /// <param name="axesNumber">Number of axis of the same orientation.</param>
  2787. /// <param name="autoPlotPosition">Indicates that inner plot position is automatic.</param>
  2788. virtual internal void Resize(
  2789. ChartGraphics chartGraph,
  2790. ElementPosition chartAreaPosition,
  2791. RectangleF plotArea,
  2792. float axesNumber,
  2793. bool autoPlotPosition)
  2794. {
  2795. #if SUBAXES
  2796. // Resize all sub-axis
  2797. if(ChartArea.IsSubAxesSupported)
  2798. {
  2799. foreach(SubAxis subAxis in this.SubAxes)
  2800. {
  2801. subAxis.Resize(chartGraph, chartAreaPosition, plotArea, axesNumber, autoPlotPosition);
  2802. }
  2803. }
  2804. #endif // SUBAXES
  2805. // Disable Common.Chart invalidation
  2806. bool oldDisableInvalidates = Common.Chart.disableInvalidates;
  2807. Common.Chart.disableInvalidates = true;
  2808. // Set Common.Chart area position
  2809. PlotAreaPosition = chartAreaPosition;
  2810. // Initialize plot area size
  2811. PlotAreaPosition.FromRectangleF(plotArea);
  2812. //******************************************************
  2813. //** Calculate axis title size
  2814. //******************************************************
  2815. this.titleSize = 0F;
  2816. if (this.Title.Length > 0)
  2817. {
  2818. // Measure axis title
  2819. SizeF titleStringSize = chartGraph.MeasureStringRel(this.Title.Replace("\\n", "\n"), this.TitleFont, new SizeF(10000f, 10000f), StringFormat.GenericTypographic, this.GetTextOrientation());
  2820. // Switch Width & Heigth for vertical axes
  2821. // If axis is horizontal
  2822. float maxTitlesize = 0;
  2823. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  2824. {
  2825. maxTitlesize = (plotArea.Height / 100F) * (Axis.maxAxisTitleSize / axesNumber);
  2826. if (this.IsTextVertical)
  2827. {
  2828. this.titleSize = Math.Min(titleStringSize.Width, maxTitlesize);
  2829. }
  2830. else
  2831. {
  2832. this.titleSize = Math.Min(titleStringSize.Height, maxTitlesize);
  2833. }
  2834. }
  2835. // If axis is vertical
  2836. else
  2837. {
  2838. titleStringSize = chartGraph.GetAbsoluteSize(titleStringSize);
  2839. titleStringSize = chartGraph.GetRelativeSize(new SizeF(titleStringSize.Height, titleStringSize.Width));
  2840. maxTitlesize = (plotArea.Width / 100F) * (Axis.maxAxisTitleSize / axesNumber);
  2841. if (this.IsTextVertical)
  2842. {
  2843. this.titleSize = Math.Min(titleStringSize.Width, maxTitlesize);
  2844. }
  2845. else
  2846. {
  2847. this.titleSize = Math.Min(titleStringSize.Height, maxTitlesize);
  2848. }
  2849. }
  2850. }
  2851. if (this.titleSize > 0)
  2852. {
  2853. this.titleSize += elementSpacing;
  2854. }
  2855. //*********************************************************
  2856. //** Get arrow size of the opposite axis
  2857. //*********************************************************
  2858. float arrowSize = 0F;
  2859. SizeF arrowSizePrimary = SizeF.Empty;
  2860. SizeF arrowSizeSecondary = SizeF.Empty;
  2861. ArrowOrientation arrowOrientation = ArrowOrientation.Bottom;
  2862. if (this.axisType == AxisName.X || this.axisType == AxisName.X2)
  2863. {
  2864. if (ChartArea.AxisY.ArrowStyle != AxisArrowStyle.None)
  2865. {
  2866. arrowSizePrimary = ChartArea.AxisY.GetArrowSize(out arrowOrientation);
  2867. if (!IsArrowInAxis(arrowOrientation, this.AxisPosition))
  2868. {
  2869. arrowSizePrimary = SizeF.Empty;
  2870. }
  2871. }
  2872. if (ChartArea.AxisY2.ArrowStyle != AxisArrowStyle.None)
  2873. {
  2874. arrowSizeSecondary = ChartArea.AxisY2.GetArrowSize(out arrowOrientation);
  2875. if (!IsArrowInAxis(arrowOrientation, this.AxisPosition))
  2876. {
  2877. arrowSizeSecondary = SizeF.Empty;
  2878. }
  2879. }
  2880. }
  2881. else
  2882. {
  2883. if (ChartArea.AxisX.ArrowStyle != AxisArrowStyle.None)
  2884. {
  2885. arrowSizePrimary = ChartArea.AxisX.GetArrowSize(out arrowOrientation);
  2886. if (!IsArrowInAxis(arrowOrientation, this.AxisPosition))
  2887. {
  2888. arrowSizePrimary = SizeF.Empty;
  2889. }
  2890. }
  2891. if (ChartArea.AxisX2.ArrowStyle != AxisArrowStyle.None)
  2892. {
  2893. arrowSizeSecondary = ChartArea.AxisX2.GetArrowSize(out arrowOrientation);
  2894. if (!IsArrowInAxis(arrowOrientation, this.AxisPosition))
  2895. {
  2896. arrowSizeSecondary = SizeF.Empty;
  2897. }
  2898. }
  2899. }
  2900. // If axis is horizontal
  2901. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  2902. {
  2903. arrowSize = Math.Max(arrowSizePrimary.Height, arrowSizeSecondary.Height);
  2904. }
  2905. // If axis is vertical
  2906. else
  2907. {
  2908. arrowSize = Math.Max(arrowSizePrimary.Width, arrowSizeSecondary.Width);
  2909. }
  2910. //*********************************************************
  2911. //** Calculate axis tick marks, axis thickness, arrow size
  2912. //** and scroll bar size
  2913. //*********************************************************
  2914. this.markSize = 0F;
  2915. // Get major and minor tick marks sizes
  2916. float majorTickSize = 0;
  2917. if (this.MajorTickMark.Enabled && this.MajorTickMark.TickMarkStyle != TickMarkStyle.None)
  2918. {
  2919. if (this.MajorTickMark.TickMarkStyle == TickMarkStyle.InsideArea)
  2920. {
  2921. majorTickSize = 0F;
  2922. }
  2923. else if (this.MajorTickMark.TickMarkStyle == TickMarkStyle.AcrossAxis)
  2924. {
  2925. majorTickSize = this.MajorTickMark.Size / 2F;
  2926. }
  2927. else if (this.MajorTickMark.TickMarkStyle == TickMarkStyle.OutsideArea)
  2928. {
  2929. majorTickSize = this.MajorTickMark.Size;
  2930. }
  2931. }
  2932. float minorTickSize = 0;
  2933. if (this.MinorTickMark.Enabled && this.MinorTickMark.TickMarkStyle != TickMarkStyle.None && this.MinorTickMark.GetInterval() != 0)
  2934. {
  2935. if (this.MinorTickMark.TickMarkStyle == TickMarkStyle.InsideArea)
  2936. {
  2937. minorTickSize = 0F;
  2938. }
  2939. else if (this.MinorTickMark.TickMarkStyle == TickMarkStyle.AcrossAxis)
  2940. {
  2941. minorTickSize = this.MinorTickMark.Size / 2F;
  2942. }
  2943. else if (this.MinorTickMark.TickMarkStyle == TickMarkStyle.OutsideArea)
  2944. {
  2945. minorTickSize = this.MinorTickMark.Size;
  2946. }
  2947. }
  2948. this.markSize += (float)Math.Max(majorTickSize, minorTickSize);
  2949. // Add axis line size
  2950. SizeF borderSize = chartGraph.GetRelativeSize(new SizeF(this.LineWidth, this.LineWidth));
  2951. // If axis is horizontal
  2952. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  2953. {
  2954. this.markSize += borderSize.Height / 2f;
  2955. this.markSize = Math.Min(this.markSize, (plotArea.Height / 100F) * (Axis.maxAxisMarkSize / axesNumber));
  2956. }
  2957. // If axis is vertical
  2958. else
  2959. {
  2960. this.markSize += borderSize.Width / 2f;
  2961. this.markSize = Math.Min(this.markSize, (plotArea.Width / 100F) * (Axis.maxAxisMarkSize / axesNumber));
  2962. }
  2963. // Add axis scroll bar size (if it's visible)
  2964. this.scrollBarSize = 0f;
  2965. if (this.ScrollBar.IsVisible &&
  2966. (this.IsAxisOnAreaEdge || !this.IsMarksNextToAxis))
  2967. {
  2968. if (this.ScrollBar.IsPositionedInside)
  2969. {
  2970. this.markSize += (float)this.ScrollBar.GetScrollBarRelativeSize();
  2971. }
  2972. else
  2973. {
  2974. this.scrollBarSize = (float)this.ScrollBar.GetScrollBarRelativeSize();
  2975. }
  2976. }
  2977. //*********************************************************
  2978. //** Adjust mark size using area scene wall width
  2979. //*********************************************************
  2980. if (ChartArea.Area3DStyle.Enable3D &&
  2981. !ChartArea.chartAreaIsCurcular &&
  2982. ChartArea.BackColor != Color.Transparent &&
  2983. ChartArea.Area3DStyle.WallWidth > 0)
  2984. {
  2985. SizeF areaWallSize = chartGraph.GetRelativeSize(new SizeF(ChartArea.Area3DStyle.WallWidth, ChartArea.Area3DStyle.WallWidth));
  2986. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  2987. {
  2988. this.markSize += areaWallSize.Height;
  2989. }
  2990. else
  2991. {
  2992. this.markSize += areaWallSize.Width;
  2993. }
  2994. // Ignore Max marks size for the 3D wall size.
  2995. //this.markSize = Math.Min(this.markSize, (plotArea.Width / 100F) * (Axis.maxAxisMarkSize / axesNumber));
  2996. }
  2997. //*********************************************************
  2998. //** Adjust title size and mark size using arrow size
  2999. //*********************************************************
  3000. if (arrowSize > (this.markSize + this.scrollBarSize + this.titleSize))
  3001. {
  3002. this.markSize = Math.Max(this.markSize, arrowSize - (this.markSize + this.scrollBarSize + this.titleSize));
  3003. this.markSize = Math.Min(this.markSize, (plotArea.Width / 100F) * (Axis.maxAxisMarkSize / axesNumber));
  3004. }
  3005. //*********************************************************
  3006. //** Calculate max label size
  3007. //*********************************************************
  3008. float maxLabelSize = 0;
  3009. if (!autoPlotPosition)
  3010. {
  3011. if (this.GetIsMarksNextToAxis())
  3012. {
  3013. if (this.AxisPosition == AxisPosition.Top)
  3014. maxLabelSize = (float)GetAxisPosition() - ChartArea.Position.Y;
  3015. else if (this.AxisPosition == AxisPosition.Bottom)
  3016. maxLabelSize = ChartArea.Position.Bottom - (float)GetAxisPosition();
  3017. if (this.AxisPosition == AxisPosition.Left)
  3018. maxLabelSize = (float)GetAxisPosition() - ChartArea.Position.X;
  3019. else if (this.AxisPosition == AxisPosition.Right)
  3020. maxLabelSize = ChartArea.Position.Right - (float)GetAxisPosition();
  3021. }
  3022. else
  3023. {
  3024. if (this.AxisPosition == AxisPosition.Top)
  3025. maxLabelSize = plotArea.Y - ChartArea.Position.Y;
  3026. else if (this.AxisPosition == AxisPosition.Bottom)
  3027. maxLabelSize = ChartArea.Position.Bottom - plotArea.Bottom;
  3028. if (this.AxisPosition == AxisPosition.Left)
  3029. maxLabelSize = plotArea.X - ChartArea.Position.X;
  3030. else if (this.AxisPosition == AxisPosition.Right)
  3031. maxLabelSize = ChartArea.Position.Right - plotArea.Right;
  3032. }
  3033. maxLabelSize *= 2F;
  3034. }
  3035. else
  3036. {
  3037. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  3038. maxLabelSize = plotArea.Height * (_maximumAutoSize / 100f);
  3039. else
  3040. maxLabelSize = plotArea.Width * (_maximumAutoSize / 100f);
  3041. }
  3042. //******************************************************
  3043. //** First try to select the interval that will
  3044. //** generate best fit labels.
  3045. //******************************************************
  3046. // Make sure the variable interval mode is enabled and
  3047. // no custom label interval used.
  3048. if( this.Enabled != AxisEnabled.False &&
  3049. this.LabelStyle.Enabled &&
  3050. this.IsVariableLabelCountModeEnabled() )
  3051. {
  3052. // Increase font by several points when height of the font is the most important
  3053. // dimension. Use original size whenwidth is the most important size.
  3054. float extraSize = 3f;
  3055. if( (this.AxisPosition == AxisPosition.Left || this.AxisPosition == AxisPosition.Right) &&
  3056. (this.LabelStyle.Angle == 90 || this.LabelStyle.Angle == -90) )
  3057. {
  3058. extraSize = 0f;
  3059. }
  3060. if( (this.AxisPosition == AxisPosition.Top || this.AxisPosition == AxisPosition.Bottom) &&
  3061. (this.LabelStyle.Angle == 180 || this.LabelStyle.Angle == 0) )
  3062. {
  3063. extraSize = 0f;
  3064. }
  3065. // If 3D Common.Chart is used make the measurements with font several point larger
  3066. if(ChartArea.Area3DStyle.Enable3D)
  3067. {
  3068. extraSize += 1f;
  3069. }
  3070. this.autoLabelFont = Common.Chart.chartPicture.FontCache.GetFont(this.LabelStyle.Font.FontFamily,
  3071. this.LabelStyle.Font.Size + extraSize,
  3072. this.LabelStyle.Font.Style,
  3073. GraphicsUnit.Point);
  3074. // Reset angle and stagged flag used in the auto-fitting algorithm
  3075. this.autoLabelAngle = this.LabelStyle.Angle;
  3076. this.autoLabelOffset = (this.LabelStyle.IsStaggered) ? 1 : 0;
  3077. // Adjust interval
  3078. this.AdjustIntervalToFitLabels(chartGraph, autoPlotPosition, false);
  3079. }
  3080. //******************************************************
  3081. //** Automatically calculate the best font size, angle
  3082. //** and try to use offset labels.
  3083. //******************************************************
  3084. // Reset all automatic label properties
  3085. autoLabelFont = null;
  3086. autoLabelAngle = -1000;
  3087. autoLabelOffset = -1;
  3088. // For circular Common.Chart area process auto-fitting for Y Axis only
  3089. if (this.IsLabelAutoFit &&
  3090. this.LabelAutoFitStyle != LabelAutoFitStyles.None &&
  3091. !ChartArea.chartAreaIsCurcular)
  3092. {
  3093. bool fitDone = false;
  3094. bool noWordWrap = false;
  3095. // Set default font angle and labels offset flag
  3096. autoLabelAngle = 0;
  3097. autoLabelOffset = 0;
  3098. // Original labels collection
  3099. CustomLabelsCollection originalLabels = null;
  3100. // Pick up maximum font size
  3101. float size = 8f;
  3102. size = (float)Math.Max(this.LabelAutoFitMaxFontSize, this.LabelAutoFitMinFontSize);
  3103. _minLabelFontSize = Math.Min(this.LabelAutoFitMinFontSize, this.LabelAutoFitMaxFontSize);
  3104. _aveLabelFontSize = _minLabelFontSize + Math.Abs(size - _minLabelFontSize)/2f;
  3105. // Check if common font size should be used
  3106. if (ChartArea.IsSameFontSizeForAllAxes)
  3107. {
  3108. size = (float)Math.Min(size, ChartArea.axesAutoFontSize);
  3109. }
  3110. //Set new font
  3111. autoLabelFont = Common.Chart.chartPicture.FontCache.GetFont(this.LabelStyle.Font.FontFamily,
  3112. size,
  3113. this.LabelStyle.Font.Style,
  3114. GraphicsUnit.Point
  3115. );
  3116. // Check if we allowed to increase font size while auto-fitting
  3117. if ((this.LabelAutoFitStyle & LabelAutoFitStyles.IncreaseFont) != LabelAutoFitStyles.IncreaseFont)
  3118. {
  3119. // Use axis labels font as starting point
  3120. autoLabelFont = this.LabelStyle.Font;
  3121. }
  3122. // Loop while labels do not fit
  3123. float spacer = 0f;
  3124. while (!fitDone)
  3125. {
  3126. //******************************************************
  3127. //** Check if labels fit
  3128. //******************************************************
  3129. // Check if grouping labels fit should be checked
  3130. bool checkLabelsFirstRowOnly = true;
  3131. if ((this.LabelAutoFitStyle & LabelAutoFitStyles.DecreaseFont) == LabelAutoFitStyles.DecreaseFont)
  3132. {
  3133. // Only check grouping labels if we can reduce fonts size
  3134. checkLabelsFirstRowOnly = false;
  3135. }
  3136. // Check labels fit
  3137. fitDone = CheckLabelsFit(
  3138. chartGraph,
  3139. this.markSize + this.scrollBarSize + this.titleSize + spacer,
  3140. autoPlotPosition,
  3141. checkLabelsFirstRowOnly,
  3142. false);
  3143. //******************************************************
  3144. //** Adjust labels text properties to fit
  3145. //******************************************************
  3146. if (!fitDone)
  3147. {
  3148. // If font is bigger than average try to make it smaller
  3149. if (autoLabelFont.SizeInPoints >= _aveLabelFontSize &&
  3150. (this.LabelAutoFitStyle & LabelAutoFitStyles.DecreaseFont) == LabelAutoFitStyles.DecreaseFont)
  3151. {
  3152. //Clean up the old font
  3153. autoLabelFont = Common.Chart.chartPicture.FontCache.GetFont(
  3154. autoLabelFont.FontFamily,
  3155. autoLabelFont.SizeInPoints - 0.5f,
  3156. autoLabelFont.Style,
  3157. GraphicsUnit.Point);
  3158. }
  3159. // Try to use offset labels (2D charts and non-circular arae only!!!)
  3160. else if (!ChartArea.Area3DStyle.Enable3D &&
  3161. !ChartArea.chartAreaIsCurcular &&
  3162. originalLabels == null &&
  3163. autoLabelAngle == 0 &&
  3164. autoLabelOffset == 0 &&
  3165. (this.LabelAutoFitStyle & LabelAutoFitStyles.StaggeredLabels) == LabelAutoFitStyles.StaggeredLabels)
  3166. {
  3167. autoLabelOffset = 1;
  3168. }
  3169. // Try to insert new line characters in labels text
  3170. else if (!noWordWrap &&
  3171. (this.LabelAutoFitStyle & LabelAutoFitStyles.WordWrap) == LabelAutoFitStyles.WordWrap)
  3172. {
  3173. bool changed = false;
  3174. autoLabelOffset = 0;
  3175. // Check if backup copy of the original lables was made
  3176. if (originalLabels == null)
  3177. {
  3178. // Copy current labels collection
  3179. originalLabels = new CustomLabelsCollection(this);
  3180. foreach (CustomLabel label in this.CustomLabels)
  3181. {
  3182. originalLabels.Add(label.Clone());
  3183. }
  3184. }
  3185. // Try to insert new line character into the longest label
  3186. changed = WordWrapLongestLabel(this.CustomLabels);
  3187. // Word wrapping do not solve the labels overlapping issue
  3188. if (!changed)
  3189. {
  3190. noWordWrap = true;
  3191. // Restore original labels
  3192. if (originalLabels != null)
  3193. {
  3194. this.CustomLabels.Clear();
  3195. foreach (CustomLabel label in originalLabels)
  3196. {
  3197. this.CustomLabels.Add(label.Clone());
  3198. }
  3199. originalLabels = null;
  3200. }
  3201. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  3202. {
  3203. if ((spacer == 0 ||
  3204. spacer == 30f ||
  3205. spacer == 20f) &&
  3206. ((this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep30) == LabelAutoFitStyles.LabelsAngleStep30 ||
  3207. (this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep45) == LabelAutoFitStyles.LabelsAngleStep45 ||
  3208. (this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep90) == LabelAutoFitStyles.LabelsAngleStep90))
  3209. {
  3210. // Try to use 90 degrees angle
  3211. autoLabelAngle = 90;
  3212. noWordWrap = false;
  3213. // Usually 55% of Common.Chart area size is allowed for labels
  3214. // Reduce that space.
  3215. if (spacer == 0f)
  3216. {
  3217. // 30
  3218. spacer = 30f;
  3219. }
  3220. else if (spacer == 30f)
  3221. {
  3222. // 20
  3223. spacer = 20f;
  3224. }
  3225. else if (spacer == 20f)
  3226. {
  3227. // 5
  3228. spacer = 5f;
  3229. }
  3230. else
  3231. {
  3232. autoLabelAngle = 0;
  3233. noWordWrap = true;
  3234. }
  3235. }
  3236. else
  3237. {
  3238. spacer = 0f;
  3239. }
  3240. }
  3241. }
  3242. }
  3243. // Try to change font angle
  3244. else if (autoLabelAngle != 90 &&
  3245. ((this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep30) == LabelAutoFitStyles.LabelsAngleStep30 ||
  3246. (this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep45) == LabelAutoFitStyles.LabelsAngleStep45 ||
  3247. (this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep90) == LabelAutoFitStyles.LabelsAngleStep90))
  3248. {
  3249. spacer = 0f;
  3250. autoLabelOffset = 0;
  3251. if ((this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep30) == LabelAutoFitStyles.LabelsAngleStep30)
  3252. {
  3253. // Increase angle by 45 degrees in 2D and 45 in 3D
  3254. autoLabelAngle += (ChartArea.Area3DStyle.Enable3D) ? 45 : 30;
  3255. }
  3256. else if ((this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep45) == LabelAutoFitStyles.LabelsAngleStep45)
  3257. {
  3258. // Increase angle by 45 degrees
  3259. autoLabelAngle += 45;
  3260. }
  3261. else if ((this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep90) == LabelAutoFitStyles.LabelsAngleStep90)
  3262. {
  3263. // Increase angle by 90 degrees
  3264. autoLabelAngle += 90;
  3265. }
  3266. }
  3267. // Try to reduce font again
  3268. else if (autoLabelFont.SizeInPoints > _minLabelFontSize &&
  3269. (this.LabelAutoFitStyle & LabelAutoFitStyles.DecreaseFont) == LabelAutoFitStyles.DecreaseFont)
  3270. {
  3271. //Clean up the old font
  3272. autoLabelAngle = 0;
  3273. autoLabelFont = Common.Chart.chartPicture.FontCache.GetFont(
  3274. autoLabelFont.FontFamily,
  3275. autoLabelFont.SizeInPoints - 0.5f,
  3276. autoLabelFont.Style,
  3277. GraphicsUnit.Point);
  3278. }
  3279. // Failed to fit
  3280. else
  3281. {
  3282. // Use last font
  3283. if ((this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep30) == LabelAutoFitStyles.LabelsAngleStep30 ||
  3284. (this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep45) == LabelAutoFitStyles.LabelsAngleStep45 ||
  3285. (this.LabelAutoFitStyle & LabelAutoFitStyles.LabelsAngleStep90) == LabelAutoFitStyles.LabelsAngleStep90)
  3286. {
  3287. // Reset angle
  3288. if (this.AxisPosition == AxisPosition.Top || this.AxisPosition == AxisPosition.Bottom)
  3289. {
  3290. autoLabelAngle = 90;
  3291. }
  3292. else
  3293. {
  3294. autoLabelAngle = 0;
  3295. }
  3296. }
  3297. if ((this.LabelAutoFitStyle & LabelAutoFitStyles.StaggeredLabels) == LabelAutoFitStyles.StaggeredLabels)
  3298. {
  3299. // Reset offset labels
  3300. autoLabelOffset = 0;
  3301. }
  3302. fitDone = true;
  3303. }
  3304. }
  3305. else if (ChartArea.Area3DStyle.Enable3D &&
  3306. !ChartArea.chartAreaIsCurcular &&
  3307. autoLabelFont.SizeInPoints > _minLabelFontSize)
  3308. {
  3309. // Reduce auto-fit font by 1 for the 3D charts
  3310. autoLabelFont = Common.Chart.chartPicture.FontCache.GetFont(
  3311. autoLabelFont.FontFamily,
  3312. autoLabelFont.SizeInPoints - 0.5f,
  3313. autoLabelFont.Style,
  3314. GraphicsUnit.Point);
  3315. }
  3316. }
  3317. // Change the auto-fit angle for top and bottom axes from 90 to -90
  3318. if(this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  3319. {
  3320. if(autoLabelAngle == 90)
  3321. {
  3322. autoLabelAngle = -90;
  3323. }
  3324. }
  3325. }
  3326. //*********************************************************
  3327. //** Calculate overall labels size
  3328. //*********************************************************
  3329. this.labelSize = 0;
  3330. // if labels are not enabled their size needs to remain zero
  3331. if (this.LabelStyle.Enabled)
  3332. {
  3333. //******************************************************
  3334. //** Calculate axis second labels row size
  3335. //******************************************************
  3336. this.labelSize = (maxAxisElementsSize) - this.markSize - this.scrollBarSize - this.titleSize;
  3337. if (this.labelSize > 0)
  3338. {
  3339. this.groupingLabelSizes = GetRequiredGroupLabelSize(chartGraph, (maxLabelSize / 100F) * maxAxisLabelRow2Size);
  3340. this.totlaGroupingLabelsSize = GetGroupLablesToatalSize();
  3341. }
  3342. //******************************************************
  3343. //** Calculate axis labels size
  3344. //******************************************************
  3345. this.labelSize -= this.totlaGroupingLabelsSize;
  3346. if (this.labelSize > 0)
  3347. {
  3348. // If axis is horizontal
  3349. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  3350. {
  3351. this.labelSize = elementSpacing + GetRequiredLabelSize(chartGraph,
  3352. (maxLabelSize / 100F) * (maxAxisElementsSize - this.markSize - this.scrollBarSize - this.titleSize), out this.unRotatedLabelSize);
  3353. }
  3354. // If axis is horizontal
  3355. else
  3356. {
  3357. this.labelSize = elementSpacing + GetRequiredLabelSize(chartGraph,
  3358. (maxLabelSize / 100F) * (maxAxisElementsSize - this.markSize - this.scrollBarSize - this.titleSize), out this.unRotatedLabelSize);
  3359. }
  3360. if (!this.LabelStyle.Enabled)
  3361. {
  3362. this.labelSize -= elementSpacing;
  3363. }
  3364. }
  3365. else
  3366. {
  3367. this.labelSize = 0;
  3368. }
  3369. this.labelSize += this.totlaGroupingLabelsSize;
  3370. }
  3371. #if SUBAXES
  3372. // Calculate offsets for all sub axes
  3373. if(!ChartArea.Area3DStyle.Enable3D &&
  3374. !ChartArea.chartAreaIsCurcular)
  3375. {
  3376. float currentOffset = this.markSize + this.labelSize + this.titleSize + this.scrollBarSize;
  3377. foreach(SubAxis subAxis in this.SubAxes)
  3378. {
  3379. if(subAxis.Enabled != AxisEnabled.False)
  3380. {
  3381. currentOffset += (float)subAxis.LocationOffset;
  3382. subAxis.offsetFromParent = currentOffset;
  3383. currentOffset += subAxis.markSize + subAxis.labelSize + subAxis.titleSize;
  3384. }
  3385. }
  3386. }
  3387. #endif // SUBAXES
  3388. // Restore previous invalidation flag
  3389. Common.Chart.disableInvalidates = oldDisableInvalidates;
  3390. }
  3391. /// <summary>
  3392. /// Calculates axis interval so that labels will fit most efficiently.
  3393. /// </summary>
  3394. /// <param name="chartGraph">Chart graphics.</param>
  3395. /// <param name="autoPlotPosition">True if plot position is auto calculated.</param>
  3396. /// <param name="onlyIncreaseInterval">True if interval should only be increased.</param>
  3397. private void AdjustIntervalToFitLabels(ChartGraphics chartGraph, bool autoPlotPosition, bool onlyIncreaseInterval)
  3398. {
  3399. // Calculates axis interval so that labels will fit most efficiently.
  3400. if(this.ScaleSegments.Count == 0)
  3401. {
  3402. this.AdjustIntervalToFitLabels(chartGraph, autoPlotPosition, null, onlyIncreaseInterval);
  3403. }
  3404. else
  3405. {
  3406. // Allow values to go outside the segment boundary
  3407. this.ScaleSegments.AllowOutOfScaleValues = true;
  3408. // Adjust interval of each segment first
  3409. foreach(AxisScaleSegment axisScaleSegment in this.ScaleSegments)
  3410. {
  3411. this.AdjustIntervalToFitLabels(chartGraph, autoPlotPosition, axisScaleSegment, onlyIncreaseInterval);
  3412. }
  3413. // Fill labels using new segment intervals
  3414. bool removeLabels = true;
  3415. int segmentIndex = 0;
  3416. ArrayList removedLabels = new ArrayList();
  3417. ArrayList removedLabelsIndexes = new ArrayList();
  3418. foreach(AxisScaleSegment scaleSegment in this.ScaleSegments)
  3419. {
  3420. scaleSegment.SetTempAxisScaleAndInterval();
  3421. this.FillLabels(removeLabels);
  3422. removeLabels = false;
  3423. scaleSegment.RestoreAxisScaleAndInterval();
  3424. // Remove last label of all segmenst except of the last
  3425. if(segmentIndex < this.ScaleSegments.Count - 1 &&
  3426. this.CustomLabels.Count > 0)
  3427. {
  3428. // Remove label and save it in the list
  3429. removedLabels.Add(this.CustomLabels[this.CustomLabels.Count - 1]);
  3430. removedLabelsIndexes.Add(this.CustomLabels.Count - 1);
  3431. this.CustomLabels.RemoveAt(this.CustomLabels.Count - 1);
  3432. }
  3433. ++segmentIndex;
  3434. }
  3435. // Check all previously removed last labels of each segment if there
  3436. // is enough space to fit them
  3437. int reInsertedLabelsCount = 0;
  3438. int labelIndex = 0;
  3439. foreach(CustomLabel label in removedLabels)
  3440. {
  3441. // Re-insert the label
  3442. int labelInsertIndex = (int)removedLabelsIndexes[labelIndex] + reInsertedLabelsCount;
  3443. if(labelIndex < this.CustomLabels.Count)
  3444. {
  3445. this.CustomLabels.Insert(labelInsertIndex, label);
  3446. }
  3447. else
  3448. {
  3449. this.CustomLabels.Add(label);
  3450. }
  3451. // Check labels fit. Only horizontal or vertical fit is checked depending
  3452. // on the axis orientation.
  3453. ArrayList labelPositions = new ArrayList();
  3454. bool fitDone = CheckLabelsFit(
  3455. chartGraph,
  3456. this.markSize + this.scrollBarSize + this.titleSize,
  3457. autoPlotPosition,
  3458. true,
  3459. false,
  3460. (this.AxisPosition == AxisPosition.Left || this.AxisPosition == AxisPosition.Right) ? false : true,
  3461. (this.AxisPosition == AxisPosition.Left || this.AxisPosition == AxisPosition.Right) ? true : false,
  3462. labelPositions);
  3463. // If labels fit check if any of the label positions overlap
  3464. if(fitDone)
  3465. {
  3466. for(int index = 0; fitDone && index < labelPositions.Count; index++)
  3467. {
  3468. RectangleF rect1 = (RectangleF)labelPositions[index];
  3469. for(int index2 = index + 1; fitDone && index2 < labelPositions.Count; index2++)
  3470. {
  3471. RectangleF rect2 = (RectangleF)labelPositions[index2];
  3472. if(rect1.IntersectsWith(rect2))
  3473. {
  3474. fitDone = false;
  3475. }
  3476. }
  3477. }
  3478. }
  3479. // If labels do not fit or overlapp - remove completly
  3480. if(!fitDone)
  3481. {
  3482. this.CustomLabels.RemoveAt(labelInsertIndex);
  3483. }
  3484. else
  3485. {
  3486. ++reInsertedLabelsCount;
  3487. }
  3488. ++labelIndex;
  3489. }
  3490. // Make sure now values are rounded on segment boundary
  3491. this.ScaleSegments.AllowOutOfScaleValues = false;
  3492. }
  3493. }
  3494. /// <summary>
  3495. /// Checks if variable count labels mode is enabled.
  3496. /// </summary>
  3497. /// <returns>True if variable count labels mode is enabled.</returns>
  3498. private bool IsVariableLabelCountModeEnabled()
  3499. {
  3500. // Make sure the variable interval mode is enabled and
  3501. // no custom label interval used.
  3502. if( (this.IntervalAutoMode == IntervalAutoMode.VariableCount || this.ScaleSegments.Count > 0) &&
  3503. !this.IsLogarithmic &&
  3504. (this.tempLabelInterval <= 0.0 || (double.IsNaN(this.tempLabelInterval) && this.Interval <= 0.0)) )
  3505. {
  3506. // This feature is not supported for charts that do not
  3507. // require X and Y axes (Pie, Radar, ...)
  3508. if(!ChartArea.requireAxes)
  3509. {
  3510. return false;
  3511. }
  3512. // This feature is not supported if the axis doesn't have data range
  3513. if (Double.IsNaN(this.minimum) || Double.IsNaN(this.maximum))
  3514. {
  3515. return false;
  3516. }
  3517. // Check if custom labels are used in the first row
  3518. bool customLabels = false;
  3519. foreach(CustomLabel label in this.CustomLabels)
  3520. {
  3521. if(label.customLabel && label.RowIndex == 0)
  3522. {
  3523. customLabels = true;
  3524. break;
  3525. }
  3526. }
  3527. // Proceed only if no custom labels are used in the first row
  3528. if(!customLabels)
  3529. {
  3530. return true;
  3531. }
  3532. }
  3533. return false;
  3534. }
  3535. /// <summary>
  3536. /// Calculates axis interval so that labels will fit most efficiently.
  3537. /// </summary>
  3538. /// <param name="chartGraph">Chart graphics.</param>
  3539. /// <param name="autoPlotPosition">True if plot position is auto calculated.</param>
  3540. /// <param name="axisScaleSegment">Axis scale segment to process.</param>
  3541. /// <param name="onlyIncreaseInterval">True if interval should only be increased.</param>
  3542. private void AdjustIntervalToFitLabels(
  3543. ChartGraphics chartGraph,
  3544. bool autoPlotPosition,
  3545. AxisScaleSegment axisScaleSegment,
  3546. bool onlyIncreaseInterval)
  3547. {
  3548. // Re-fill the labels just for the scale segment provided
  3549. if(axisScaleSegment != null)
  3550. {
  3551. // Re-fill new axis labels
  3552. if(this.tempLabels != null)
  3553. {
  3554. this.CustomLabels.Clear();
  3555. foreach( CustomLabel label in this.tempLabels )
  3556. {
  3557. this.CustomLabels.Add(label.Clone());
  3558. }
  3559. }
  3560. // Fill labels just for the segment
  3561. axisScaleSegment.SetTempAxisScaleAndInterval();
  3562. this.FillLabels( true );
  3563. axisScaleSegment.RestoreAxisScaleAndInterval();
  3564. }
  3565. // Calculate minimum interval size
  3566. double minIntervalSzie = double.NaN;
  3567. ArrayList axisSeries = AxisScaleBreakStyle.GetAxisSeries(this);
  3568. foreach(Series series in axisSeries)
  3569. {
  3570. if(this.axisType == AxisName.X || this.axisType == AxisName.X2)
  3571. {
  3572. if(ChartHelper.IndexedSeries(series))
  3573. {
  3574. minIntervalSzie = 1.0;
  3575. }
  3576. else if(series.XValueType == ChartValueType.String ||
  3577. series.XValueType == ChartValueType.Int32 ||
  3578. series.XValueType == ChartValueType.UInt32 ||
  3579. series.XValueType == ChartValueType.UInt64 ||
  3580. series.XValueType == ChartValueType.Int64 )
  3581. {
  3582. minIntervalSzie = 1.0;
  3583. }
  3584. }
  3585. else
  3586. {
  3587. if(series.YValueType == ChartValueType.String ||
  3588. series.YValueType == ChartValueType.Int32 ||
  3589. series.YValueType == ChartValueType.UInt32 ||
  3590. series.YValueType == ChartValueType.UInt64 ||
  3591. series.YValueType == ChartValueType.Int64 )
  3592. {
  3593. minIntervalSzie = 1.0;
  3594. }
  3595. }
  3596. }
  3597. // Iterate while interval is not found
  3598. bool firstIteration = true;
  3599. bool increaseNumberOfLabels = true;
  3600. double currentInterval = (axisScaleSegment == null) ? this.labelStyle.GetInterval() : axisScaleSegment.Interval;
  3601. DateTimeIntervalType currentIntervalType = (axisScaleSegment == null) ? this.labelStyle.GetIntervalType() : axisScaleSegment.IntervalType;
  3602. DateTimeIntervalType lastFitIntervalType = currentIntervalType;
  3603. double lastFitInterval = currentInterval;
  3604. ArrayList lastFitLabels = new ArrayList();
  3605. bool intervalFound = false;
  3606. int iterationNumber = 0;
  3607. while(!intervalFound && iterationNumber <= 1000)
  3608. {
  3609. bool fillNewLabels = true;
  3610. #if DEBUG
  3611. if(iterationNumber >= 999)
  3612. {
  3613. throw (new InvalidOperationException(SR.ExceptionAxisDynamicIntervalCalculationFailed));
  3614. }
  3615. #endif // DEBUG
  3616. // Check labels fit. Only horizontal or vertical fit is checked depending
  3617. // on the axis orientation.
  3618. bool fitDone = CheckLabelsFit(
  3619. chartGraph,
  3620. this.markSize + this.scrollBarSize + this.titleSize,
  3621. autoPlotPosition,
  3622. true,
  3623. false,
  3624. (this.AxisPosition == AxisPosition.Left || this.AxisPosition == AxisPosition.Right) ? false : true,
  3625. (this.AxisPosition == AxisPosition.Left || this.AxisPosition == AxisPosition.Right) ? true : false,
  3626. null);
  3627. // Check if we need to increase or reduce number of labels
  3628. if(firstIteration)
  3629. {
  3630. firstIteration = false;
  3631. increaseNumberOfLabels = (fitDone) ? true : false;
  3632. // Check if we can decrease the interva;
  3633. if(onlyIncreaseInterval && increaseNumberOfLabels)
  3634. {
  3635. intervalFound = true;
  3636. continue;
  3637. }
  3638. }
  3639. // Find new interval. Value 0.0 means that interval cannot be
  3640. // reduced/increased any more and current interval should be used
  3641. double newInterval = 0.0;
  3642. DateTimeIntervalType newIntervalType = DateTimeIntervalType.Number;
  3643. if(increaseNumberOfLabels)
  3644. {
  3645. if(fitDone)
  3646. {
  3647. // Make a copy of last interval and labels collection that previously fit
  3648. lastFitInterval = currentInterval;
  3649. lastFitIntervalType = currentIntervalType;
  3650. lastFitLabels.Clear();
  3651. foreach(CustomLabel label in this.CustomLabels)
  3652. {
  3653. lastFitLabels.Add(label);
  3654. }
  3655. newIntervalType = currentIntervalType;
  3656. newInterval = this.ReduceLabelInterval(
  3657. currentInterval,
  3658. minIntervalSzie,
  3659. ref newIntervalType);
  3660. }
  3661. else
  3662. {
  3663. newInterval = lastFitInterval;
  3664. newIntervalType = lastFitIntervalType;
  3665. intervalFound = true;
  3666. // Reuse previously saved labels
  3667. fillNewLabels = false;
  3668. this.CustomLabels.Clear();
  3669. foreach(CustomLabel label in lastFitLabels)
  3670. {
  3671. this.CustomLabels.Add(label);
  3672. }
  3673. }
  3674. }
  3675. else
  3676. {
  3677. if(!fitDone && this.CustomLabels.Count > 1)
  3678. {
  3679. newIntervalType = currentIntervalType;
  3680. newInterval = this.IncreaseLabelInterval(
  3681. currentInterval,
  3682. ref newIntervalType);
  3683. }
  3684. else
  3685. {
  3686. intervalFound = true;
  3687. }
  3688. }
  3689. // Set new interval
  3690. if(newInterval != 0.0)
  3691. {
  3692. currentInterval = newInterval;
  3693. currentIntervalType = newIntervalType;
  3694. if(axisScaleSegment == null)
  3695. {
  3696. this.SetIntervalAndType(newInterval, newIntervalType);
  3697. }
  3698. else
  3699. {
  3700. axisScaleSegment.Interval = newInterval;
  3701. axisScaleSegment.IntervalType = newIntervalType;
  3702. }
  3703. // Re-fill new axis labels
  3704. if(fillNewLabels)
  3705. {
  3706. if(this.tempLabels != null)
  3707. {
  3708. this.CustomLabels.Clear();
  3709. foreach( CustomLabel label in this.tempLabels )
  3710. {
  3711. CustomLabels.Add(label.Clone());
  3712. }
  3713. }
  3714. if(axisScaleSegment == null)
  3715. {
  3716. this.FillLabels(true);
  3717. }
  3718. else
  3719. {
  3720. axisScaleSegment.SetTempAxisScaleAndInterval();
  3721. this.FillLabels( true );
  3722. axisScaleSegment.RestoreAxisScaleAndInterval();
  3723. }
  3724. }
  3725. }
  3726. else
  3727. {
  3728. intervalFound = true;
  3729. }
  3730. ++iterationNumber;
  3731. }
  3732. }
  3733. /// <summary>
  3734. /// Reduces current label interval, so that more labels can fit.
  3735. /// </summary>
  3736. /// <param name="oldInterval">An interval to reduce.</param>
  3737. /// <param name="minInterval">Minimum interval size.</param>
  3738. /// <param name="axisIntervalType">Interval type.</param>
  3739. /// <returns>New interval or 0.0 if interval cannot be reduced.</returns>
  3740. private double ReduceLabelInterval(
  3741. double oldInterval,
  3742. double minInterval,
  3743. ref DateTimeIntervalType axisIntervalType)
  3744. {
  3745. double newInterval = oldInterval;
  3746. // Calculate rounded interval value
  3747. double range = this.maximum - this.minimum;
  3748. int iterationIndex = 0;
  3749. if( axisIntervalType == DateTimeIntervalType.Auto ||
  3750. axisIntervalType == DateTimeIntervalType.NotSet ||
  3751. axisIntervalType == DateTimeIntervalType.Number)
  3752. {
  3753. // Process numeric scale
  3754. double devider = 2.0;
  3755. do
  3756. {
  3757. #if DEBUG
  3758. if(iterationIndex >= 99)
  3759. {
  3760. throw (new InvalidOperationException(SR.ExceptionAxisIntervalDecreasingFailed));
  3761. }
  3762. #endif // DEBUG
  3763. newInterval = CalcInterval( range / (range / (newInterval / devider)) );
  3764. if(newInterval == oldInterval)
  3765. {
  3766. devider *= 2.0;
  3767. }
  3768. ++iterationIndex;
  3769. } while(newInterval == oldInterval && iterationIndex <= 100);
  3770. }
  3771. else
  3772. {
  3773. // Process date scale
  3774. if(oldInterval > 1.0 || oldInterval < 1.0)
  3775. {
  3776. if( axisIntervalType == DateTimeIntervalType.Minutes ||
  3777. axisIntervalType == DateTimeIntervalType.Seconds)
  3778. {
  3779. if(oldInterval >= 60)
  3780. {
  3781. newInterval = Math.Round(oldInterval / 2.0);
  3782. }
  3783. else if(oldInterval >= 30.0)
  3784. {
  3785. newInterval = 15.0;
  3786. }
  3787. else if(oldInterval >= 15.0)
  3788. {
  3789. newInterval = 5.0;
  3790. }
  3791. else if(oldInterval >= 5.0)
  3792. {
  3793. newInterval = 1.0;
  3794. }
  3795. }
  3796. else
  3797. {
  3798. newInterval = Math.Round(oldInterval / 2.0);
  3799. }
  3800. if(newInterval < 1.0)
  3801. {
  3802. newInterval = 1.0;
  3803. }
  3804. }
  3805. if(oldInterval == 1.0)
  3806. {
  3807. if(axisIntervalType == DateTimeIntervalType.Years)
  3808. {
  3809. newInterval = 6.0;
  3810. axisIntervalType = DateTimeIntervalType.Months;
  3811. }
  3812. else if(axisIntervalType == DateTimeIntervalType.Months)
  3813. {
  3814. newInterval = 2.0;
  3815. axisIntervalType = DateTimeIntervalType.Weeks;
  3816. }
  3817. else if(axisIntervalType == DateTimeIntervalType.Weeks)
  3818. {
  3819. newInterval = 2.0;
  3820. axisIntervalType = DateTimeIntervalType.Days;
  3821. }
  3822. else if(axisIntervalType == DateTimeIntervalType.Days)
  3823. {
  3824. newInterval = 12.0;
  3825. axisIntervalType = DateTimeIntervalType.Hours;
  3826. }
  3827. else if(axisIntervalType == DateTimeIntervalType.Hours)
  3828. {
  3829. newInterval = 30.0;
  3830. axisIntervalType = DateTimeIntervalType.Minutes;
  3831. }
  3832. else if(axisIntervalType == DateTimeIntervalType.Minutes)
  3833. {
  3834. newInterval = 30.0;
  3835. axisIntervalType = DateTimeIntervalType.Seconds;
  3836. }
  3837. else if(axisIntervalType == DateTimeIntervalType.Seconds)
  3838. {
  3839. newInterval = 100.0;
  3840. axisIntervalType = DateTimeIntervalType.Milliseconds;
  3841. }
  3842. }
  3843. }
  3844. // Make sure interal is not less than min interval specified
  3845. if(!double.IsNaN(minInterval) && newInterval < minInterval)
  3846. {
  3847. newInterval = 0.0;
  3848. }
  3849. return newInterval;
  3850. }
  3851. /// <summary>
  3852. /// Increases current label interval, so that less labels fit.
  3853. /// </summary>
  3854. /// <param name="oldInterval">An interval to increase.</param>
  3855. /// <param name="axisIntervalType">Interval type.</param>
  3856. /// <returns>New interval or 0.0 if interval cannot be increased.</returns>
  3857. private double IncreaseLabelInterval(
  3858. double oldInterval,
  3859. ref DateTimeIntervalType axisIntervalType)
  3860. {
  3861. double newInterval = oldInterval;
  3862. // Calculate rounded interval value
  3863. double range = this.maximum - this.minimum;
  3864. int iterationIndex = 0;
  3865. if( axisIntervalType == DateTimeIntervalType.Auto ||
  3866. axisIntervalType == DateTimeIntervalType.NotSet ||
  3867. axisIntervalType == DateTimeIntervalType.Number)
  3868. {
  3869. // Process numeric scale
  3870. double devider = 2.0;
  3871. do
  3872. {
  3873. #if DEBUG
  3874. if(iterationIndex >= 99)
  3875. {
  3876. throw (new InvalidOperationException(SR.ExceptionAxisIntervalIncreasingFailed));
  3877. }
  3878. #endif // DEBUG
  3879. newInterval = CalcInterval( range / (range / (newInterval * devider)) );
  3880. if(newInterval == oldInterval)
  3881. {
  3882. devider *= 2.0;
  3883. }
  3884. ++iterationIndex;
  3885. } while(newInterval == oldInterval && iterationIndex <= 100);
  3886. }
  3887. else
  3888. {
  3889. // Process date scale
  3890. newInterval = oldInterval * 2.0;
  3891. if(axisIntervalType == DateTimeIntervalType.Years)
  3892. {
  3893. // Do nothing for years
  3894. }
  3895. else if(axisIntervalType == DateTimeIntervalType.Months)
  3896. {
  3897. if(newInterval >= 12.0)
  3898. {
  3899. newInterval = 1.0;
  3900. axisIntervalType = DateTimeIntervalType.Years;
  3901. }
  3902. }
  3903. else if(axisIntervalType == DateTimeIntervalType.Weeks)
  3904. {
  3905. if(newInterval >= 4.0)
  3906. {
  3907. newInterval = 1.0;
  3908. axisIntervalType = DateTimeIntervalType.Months;
  3909. }
  3910. }
  3911. else if(axisIntervalType == DateTimeIntervalType.Days)
  3912. {
  3913. if(newInterval >= 7.0)
  3914. {
  3915. newInterval = 1.0;
  3916. axisIntervalType = DateTimeIntervalType.Weeks;
  3917. }
  3918. }
  3919. else if(axisIntervalType == DateTimeIntervalType.Hours)
  3920. {
  3921. if(newInterval >= 60.0)
  3922. {
  3923. newInterval = 1.0;
  3924. axisIntervalType = DateTimeIntervalType.Days;
  3925. }
  3926. }
  3927. else if(axisIntervalType == DateTimeIntervalType.Minutes)
  3928. {
  3929. if(newInterval >= 60.0)
  3930. {
  3931. newInterval = 1.0;
  3932. axisIntervalType = DateTimeIntervalType.Hours;
  3933. }
  3934. }
  3935. else if(axisIntervalType == DateTimeIntervalType.Seconds)
  3936. {
  3937. if(newInterval >= 60.0)
  3938. {
  3939. newInterval = 1.0;
  3940. axisIntervalType = DateTimeIntervalType.Minutes;
  3941. }
  3942. }
  3943. else if(axisIntervalType == DateTimeIntervalType.Milliseconds)
  3944. {
  3945. if(newInterval >= 1000.0)
  3946. {
  3947. newInterval = 1.0;
  3948. axisIntervalType = DateTimeIntervalType.Seconds;
  3949. }
  3950. }
  3951. }
  3952. return newInterval;
  3953. }
  3954. /// <summary>
  3955. /// Finds the longest labels with the space and inserts the new line character.
  3956. /// </summary>
  3957. /// <param name="labels">Labels collection.</param>
  3958. /// <returns>True if collection was modified.</returns>
  3959. private bool WordWrapLongestLabel(CustomLabelsCollection labels)
  3960. {
  3961. bool changed = false;
  3962. // Each label may contain several lines of text.
  3963. // Create a list that contains an array of text for each label.
  3964. ArrayList labelTextRows = new ArrayList(labels.Count);
  3965. foreach (CustomLabel label in labels)
  3966. {
  3967. labelTextRows.Add(label.Text.Split('\n'));
  3968. }
  3969. // Find the longest label with a space
  3970. int longestLabelSize = 5;
  3971. int longestLabelIndex = -1;
  3972. int longestLabelRowIndex = -1;
  3973. int index = 0;
  3974. foreach (string[] textRows in labelTextRows)
  3975. {
  3976. for (int rowIndex = 0; rowIndex < textRows.Length; rowIndex++)
  3977. {
  3978. if (textRows[rowIndex].Length > longestLabelSize && textRows[rowIndex].Trim().IndexOf(' ') > 0)
  3979. {
  3980. longestLabelSize = textRows[rowIndex].Length;
  3981. longestLabelIndex = index;
  3982. longestLabelRowIndex = rowIndex;
  3983. }
  3984. }
  3985. ++index;
  3986. }
  3987. // Longest label with a space was found
  3988. if (longestLabelIndex >= 0 && longestLabelRowIndex >= 0)
  3989. {
  3990. // Try to find a space and replace it with a new line
  3991. string newText = ((string[])labelTextRows[longestLabelIndex])[longestLabelRowIndex];
  3992. for (index = 0; index < (newText.Length) / 2 - 1; index++)
  3993. {
  3994. if (newText[(newText.Length) / 2 - index] == ' ')
  3995. {
  3996. newText =
  3997. newText.Substring(0, (newText.Length) / 2 - index) +
  3998. "\n" +
  3999. newText.Substring((newText.Length) / 2 - index + 1);
  4000. changed = true;
  4001. }
  4002. else if (newText[(newText.Length) / 2 + index] == ' ')
  4003. {
  4004. newText =
  4005. newText.Substring(0, (newText.Length) / 2 + index) +
  4006. "\n" +
  4007. newText.Substring((newText.Length) / 2 + index + 1);
  4008. changed = true;
  4009. }
  4010. if (changed)
  4011. {
  4012. ((string[])labelTextRows[longestLabelIndex])[longestLabelRowIndex] = newText;
  4013. break;
  4014. }
  4015. }
  4016. // Update label text
  4017. if (changed)
  4018. {
  4019. // Construct label text from multiple rows separated by "\n"
  4020. CustomLabel label = labels[longestLabelIndex];
  4021. label.Text = string.Empty;
  4022. for (int rowIndex = 0; rowIndex < ((string[])labelTextRows[longestLabelIndex]).Length; rowIndex++)
  4023. {
  4024. if (rowIndex > 0)
  4025. {
  4026. label.Text += "\n";
  4027. }
  4028. label.Text += ((string[])labelTextRows[longestLabelIndex])[rowIndex];
  4029. }
  4030. }
  4031. }
  4032. return changed;
  4033. }
  4034. /// <summary>
  4035. /// Calculates the auto-fit font for the circular Common.Chart area axis labels.
  4036. /// </summary>
  4037. /// <param name="graph">Chart graphics object.</param>
  4038. /// <param name="axisList">List of sector labels.</param>
  4039. /// <param name="labelsStyle">Circular labels style.</param>
  4040. /// <param name="plotAreaRectAbs">Plotting area position.</param>
  4041. /// <param name="areaRectAbs">Chart area position.</param>
  4042. /// <param name="labelsSizeEstimate">Estimated size of labels.</param>
  4043. internal void GetCircularAxisLabelsAutoFitFont(
  4044. ChartGraphics graph,
  4045. ArrayList axisList,
  4046. CircularAxisLabelsStyle labelsStyle,
  4047. RectangleF plotAreaRectAbs,
  4048. RectangleF areaRectAbs,
  4049. float labelsSizeEstimate)
  4050. {
  4051. // X axis settings defines if auto-fit font should be calculated
  4052. if (!this.IsLabelAutoFit ||
  4053. this.LabelAutoFitStyle == LabelAutoFitStyles.None ||
  4054. !this.LabelStyle.Enabled)
  4055. {
  4056. return;
  4057. }
  4058. // Set minimum font size
  4059. _minLabelFontSize = Math.Min(this.LabelAutoFitMinFontSize, this.LabelAutoFitMaxFontSize);
  4060. // Create new auto-fit font
  4061. this.autoLabelFont = Common.Chart.chartPicture.FontCache.GetFont(
  4062. this.LabelStyle.Font.FontFamily,
  4063. Math.Max(this.LabelAutoFitMaxFontSize, this.LabelAutoFitMinFontSize),
  4064. this.LabelStyle.Font.Style,
  4065. GraphicsUnit.Point);
  4066. // Check if we allowed to increase font size while auto-fitting
  4067. if ((this.LabelAutoFitStyle & LabelAutoFitStyles.IncreaseFont) != LabelAutoFitStyles.IncreaseFont)
  4068. {
  4069. // Use axis labels font as starting point
  4070. this.autoLabelFont = this.LabelStyle.Font;
  4071. }
  4072. // Loop while labels do not fit
  4073. bool fitDone = false;
  4074. while (!fitDone)
  4075. {
  4076. //******************************************************
  4077. //** Check if labels fit
  4078. //******************************************************
  4079. fitDone = CheckCircularLabelsFit(
  4080. graph,
  4081. axisList,
  4082. labelsStyle,
  4083. plotAreaRectAbs,
  4084. areaRectAbs,
  4085. labelsSizeEstimate);
  4086. //******************************************************
  4087. //** Adjust labels text properties to fit
  4088. //******************************************************
  4089. if (!fitDone)
  4090. {
  4091. // Try to reduce font size
  4092. if (autoLabelFont.SizeInPoints > _minLabelFontSize &&
  4093. (this.LabelAutoFitStyle & LabelAutoFitStyles.DecreaseFont) == LabelAutoFitStyles.DecreaseFont)
  4094. {
  4095. autoLabelFont = Common.Chart.chartPicture.FontCache.GetFont(
  4096. autoLabelFont.FontFamily,
  4097. autoLabelFont.SizeInPoints - 1,
  4098. autoLabelFont.Style,
  4099. GraphicsUnit.Point);
  4100. }
  4101. // Failed to fit
  4102. else
  4103. {
  4104. // Use last font with no angles
  4105. autoLabelAngle = 0;
  4106. autoLabelOffset = 0;
  4107. fitDone = true;
  4108. }
  4109. }
  4110. }
  4111. }
  4112. /// <summary>
  4113. /// Checks id circular axis labels fits using current auto-fit font.
  4114. /// </summary>
  4115. /// <param name="graph">Chart graphics object.</param>
  4116. /// <param name="axisList">List of sector labels.</param>
  4117. /// <param name="labelsStyle">Circular labels style.</param>
  4118. /// <param name="plotAreaRectAbs">Plotting area position.</param>
  4119. /// <param name="areaRectAbs">Chart area position.</param>
  4120. /// <param name="labelsSizeEstimate">Estimated size of labels.</param>
  4121. /// <returns>True if labels fit.</returns>
  4122. internal bool CheckCircularLabelsFit(
  4123. ChartGraphics graph,
  4124. ArrayList axisList,
  4125. CircularAxisLabelsStyle labelsStyle,
  4126. RectangleF plotAreaRectAbs,
  4127. RectangleF areaRectAbs,
  4128. float labelsSizeEstimate)
  4129. {
  4130. bool labelsFit = true;
  4131. // Get absolute center of the area
  4132. PointF areaCenterAbs = graph.GetAbsolutePoint(ChartArea.circularCenter);
  4133. // Get absolute markers size and spacing
  4134. float spacing = graph.GetAbsolutePoint(new PointF(0, this.markSize + Axis.elementSpacing)).Y;
  4135. //*****************************************************************
  4136. //** Loop through all axis labels
  4137. //*****************************************************************
  4138. RectangleF prevLabelPosition = RectangleF.Empty;
  4139. float prevLabelSideAngle = float.NaN;
  4140. foreach (CircularChartAreaAxis axis in axisList)
  4141. {
  4142. //*****************************************************************
  4143. //** Measure label text
  4144. //*****************************************************************
  4145. SizeF textSize = graph.MeasureString(
  4146. axis.Title.Replace("\\n", "\n"),
  4147. this.autoLabelFont);
  4148. //*****************************************************************
  4149. //** Get circular style label position.
  4150. //*****************************************************************
  4151. if (labelsStyle == CircularAxisLabelsStyle.Circular ||
  4152. labelsStyle == CircularAxisLabelsStyle.Radial)
  4153. {
  4154. // Swith text size for the radial style
  4155. if (labelsStyle == CircularAxisLabelsStyle.Radial)
  4156. {
  4157. float tempValue = textSize.Width;
  4158. textSize.Width = textSize.Height;
  4159. textSize.Height = tempValue;
  4160. }
  4161. //*****************************************************************
  4162. //** Check overlapping with previous label
  4163. //*****************************************************************
  4164. // Get radius of plot area
  4165. float plotAreaRadius = areaCenterAbs.Y - plotAreaRectAbs.Y;
  4166. plotAreaRadius -= labelsSizeEstimate;
  4167. plotAreaRadius += spacing;
  4168. // Calculate angle on the side of the label
  4169. float leftSideAngle = (float)(Math.Atan((textSize.Width / 2f) / plotAreaRadius) * 180f / Math.PI);
  4170. float rightSideAngle = axis.AxisPosition + leftSideAngle;
  4171. leftSideAngle = axis.AxisPosition - leftSideAngle;
  4172. // Check if label overlap the previous label
  4173. if (!float.IsNaN(prevLabelSideAngle))
  4174. {
  4175. if (prevLabelSideAngle > leftSideAngle)
  4176. {
  4177. // Labels overlap
  4178. labelsFit = false;
  4179. break;
  4180. }
  4181. }
  4182. // Remember label side angle
  4183. prevLabelSideAngle = rightSideAngle - 1;
  4184. //*****************************************************************
  4185. //** Check if label is inside the Common.Chart area
  4186. //*****************************************************************
  4187. // Find the most outside point of the label
  4188. PointF outsidePoint = new PointF(areaCenterAbs.X, plotAreaRectAbs.Y);
  4189. outsidePoint.Y += labelsSizeEstimate;
  4190. outsidePoint.Y -= textSize.Height;
  4191. outsidePoint.Y -= spacing;
  4192. PointF[] rotatedPoint = new PointF[] { outsidePoint };
  4193. Matrix newMatrix = new Matrix();
  4194. newMatrix.RotateAt(axis.AxisPosition, areaCenterAbs);
  4195. newMatrix.TransformPoints(rotatedPoint);
  4196. // Check if rotated point is inside Common.Chart area
  4197. if (!areaRectAbs.Contains(rotatedPoint[0]))
  4198. {
  4199. // Label is not inside Common.Chart area
  4200. labelsFit = false;
  4201. break;
  4202. }
  4203. }
  4204. //*****************************************************************
  4205. //** Get horizontal style label position.
  4206. //*****************************************************************
  4207. else if (labelsStyle == CircularAxisLabelsStyle.Horizontal)
  4208. {
  4209. // Get text angle
  4210. float textAngle = axis.AxisPosition;
  4211. if (textAngle > 180f)
  4212. {
  4213. textAngle -= 180f;
  4214. }
  4215. // Get label rotated position
  4216. PointF[] labelPosition = new PointF[] { new PointF(areaCenterAbs.X, plotAreaRectAbs.Y) };
  4217. labelPosition[0].Y += labelsSizeEstimate;
  4218. labelPosition[0].Y -= spacing;
  4219. Matrix newMatrix = new Matrix();
  4220. newMatrix.RotateAt(textAngle, areaCenterAbs);
  4221. newMatrix.TransformPoints(labelPosition);
  4222. // Calculate label position
  4223. RectangleF curLabelPosition = new RectangleF(
  4224. labelPosition[0].X,
  4225. labelPosition[0].Y - textSize.Height / 2f,
  4226. textSize.Width,
  4227. textSize.Height);
  4228. if (textAngle < 5f)
  4229. {
  4230. curLabelPosition.X = labelPosition[0].X - textSize.Width / 2f;
  4231. curLabelPosition.Y = labelPosition[0].Y - textSize.Height;
  4232. }
  4233. if (textAngle > 175f)
  4234. {
  4235. curLabelPosition.X = labelPosition[0].X - textSize.Width / 2f;
  4236. curLabelPosition.Y = labelPosition[0].Y;
  4237. }
  4238. // Decrease label rectangle
  4239. curLabelPosition.Inflate(0f, -curLabelPosition.Height * 0.15f);
  4240. // Check if label position goes outside of the Common.Chart area.
  4241. if (!areaRectAbs.Contains(curLabelPosition))
  4242. {
  4243. // Label is not inside Common.Chart area
  4244. labelsFit = false;
  4245. break;
  4246. }
  4247. // Check if label position overlap previous label position.
  4248. if (!prevLabelPosition.IsEmpty && curLabelPosition.IntersectsWith(prevLabelPosition))
  4249. {
  4250. // Label intersects with previous label
  4251. labelsFit = false;
  4252. break;
  4253. }
  4254. // Set previous point position
  4255. prevLabelPosition = curLabelPosition;
  4256. }
  4257. }
  4258. return labelsFit;
  4259. }
  4260. #endregion
  4261. #region Axis labels auto-fitting methods
  4262. /// <summary>
  4263. /// Adjust labels font size at second pass of auto fitting.
  4264. /// </summary>
  4265. /// <param name="chartGraph">Chart graphics object.</param>
  4266. /// <param name="autoPlotPosition">Indicates that inner plot position is automatic.</param>
  4267. internal void AdjustLabelFontAtSecondPass(ChartGraphics chartGraph, bool autoPlotPosition)
  4268. {
  4269. #if SUBAXES
  4270. // Process all sub-axis
  4271. if(!ChartArea.Area3DStyle.Enable3D &&
  4272. !ChartArea.chartAreaIsCurcular)
  4273. {
  4274. foreach(SubAxis subAxis in this.SubAxes)
  4275. {
  4276. subAxis.AdjustLabelFontAtSecondPass(chartGraph, autoPlotPosition);
  4277. }
  4278. }
  4279. #endif //SUBAXES
  4280. //******************************************************
  4281. //** First try to select the interval that will
  4282. //** generate best fit labels.
  4283. //******************************************************
  4284. // Make sure the variable interval mode is enabled
  4285. if( this.Enabled != AxisEnabled.False &&
  4286. this.LabelStyle.Enabled &&
  4287. this.IsVariableLabelCountModeEnabled() )
  4288. {
  4289. // Set font for labels fitting
  4290. if(this.autoLabelFont == null)
  4291. {
  4292. this.autoLabelFont = this.LabelStyle.Font;
  4293. }
  4294. // Reset angle and stagged flag used in the auto-fitting algorithm
  4295. if(this.autoLabelAngle < 0)
  4296. {
  4297. this.autoLabelAngle = this.LabelStyle.Angle;
  4298. }
  4299. if(this.autoLabelOffset < 0)
  4300. {
  4301. this.autoLabelOffset = (this.LabelStyle.IsStaggered) ? 1 : 0;
  4302. }
  4303. // Check labels fit
  4304. bool fitDone = CheckLabelsFit(
  4305. chartGraph,
  4306. this.markSize + this.scrollBarSize + this.titleSize,
  4307. autoPlotPosition,
  4308. true,
  4309. true,
  4310. (this.AxisPosition == AxisPosition.Left || this.AxisPosition == AxisPosition.Right) ? false : true,
  4311. (this.AxisPosition == AxisPosition.Left || this.AxisPosition == AxisPosition.Right) ? true : false,
  4312. null);
  4313. // If there is a problem fitting labels try to reduce number of labels by
  4314. // increasing of the interval.
  4315. if(!fitDone)
  4316. {
  4317. // Adjust interval
  4318. this.AdjustIntervalToFitLabels(chartGraph, autoPlotPosition, true);
  4319. }
  4320. }
  4321. //******************************************************
  4322. //** If labels auto-fit is on try reducing font size.
  4323. //******************************************************
  4324. totlaGroupingLabelsSizeAdjustment = 0f;
  4325. if (this.IsLabelAutoFit &&
  4326. this.LabelAutoFitStyle != LabelAutoFitStyles.None &&
  4327. this.Enabled != AxisEnabled.False)
  4328. {
  4329. bool fitDone = false;
  4330. if (autoLabelFont == null)
  4331. {
  4332. autoLabelFont = this.LabelStyle.Font;
  4333. }
  4334. // Loop while labels do not fit
  4335. float oldLabelSecondRowSize = totlaGroupingLabelsSize;
  4336. while (!fitDone)
  4337. {
  4338. //******************************************************
  4339. //** Check if labels fit
  4340. //******************************************************
  4341. fitDone = CheckLabelsFit(
  4342. chartGraph,
  4343. this.markSize + this.scrollBarSize + this.titleSize,
  4344. autoPlotPosition,
  4345. true,
  4346. true);
  4347. //******************************************************
  4348. //** Adjust labels text properties to fit
  4349. //******************************************************
  4350. if (!fitDone)
  4351. {
  4352. // Try to reduce font
  4353. if (autoLabelFont.SizeInPoints > _minLabelFontSize)
  4354. {
  4355. // Reduce auto fit font
  4356. if (ChartArea != null && ChartArea.IsSameFontSizeForAllAxes)
  4357. {
  4358. // Same font for all axes
  4359. foreach (Axis currentAxis in ChartArea.Axes)
  4360. {
  4361. if (currentAxis.enabled && currentAxis.IsLabelAutoFit && currentAxis.autoLabelFont != null)
  4362. {
  4363. currentAxis.autoLabelFont = Common.Chart.chartPicture.FontCache.GetFont(
  4364. currentAxis.autoLabelFont.FontFamily,
  4365. autoLabelFont.SizeInPoints - 1,
  4366. currentAxis.autoLabelFont.Style,
  4367. GraphicsUnit.Point);
  4368. }
  4369. }
  4370. }
  4371. else if ((this.LabelAutoFitStyle & LabelAutoFitStyles.DecreaseFont) == LabelAutoFitStyles.DecreaseFont)
  4372. {
  4373. autoLabelFont = Common.Chart.chartPicture.FontCache.GetFont(
  4374. autoLabelFont.FontFamily,
  4375. autoLabelFont.SizeInPoints - 1,
  4376. autoLabelFont.Style,
  4377. GraphicsUnit.Point);
  4378. }
  4379. else
  4380. {
  4381. // Failed to fit
  4382. fitDone = true;
  4383. }
  4384. }
  4385. else
  4386. {
  4387. // Failed to fit
  4388. fitDone = true;
  4389. }
  4390. }
  4391. }
  4392. this.totlaGroupingLabelsSizeAdjustment = oldLabelSecondRowSize - totlaGroupingLabelsSize;
  4393. }
  4394. }
  4395. /// <summary>
  4396. /// Check if axis is logarithmic
  4397. /// </summary>
  4398. /// <param name="yValue">Y value from data</param>
  4399. /// <returns>Corected Y value if axis is logarithmic</returns>
  4400. internal double GetLogValue(double yValue)
  4401. {
  4402. // Check if axis is logarithmic
  4403. if (this.IsLogarithmic)
  4404. {
  4405. yValue = Math.Log(yValue, this.logarithmBase);
  4406. }
  4407. return yValue;
  4408. }
  4409. /// <summary>
  4410. /// Checks if labels fit using current auto fit properties
  4411. /// </summary>
  4412. /// <param name="chartGraph">Chart graphics object.</param>
  4413. /// <param name="otherElementsSize">Axis title and marks size.</param>
  4414. /// <param name="autoPlotPosition">Indicates auto calculation of plotting area.</param>
  4415. /// <param name="checkLabelsFirstRowOnly">Labels fit is checked during the second pass.</param>
  4416. /// <param name="secondPass">Indicates second pass of labels fitting.</param>
  4417. /// <returns>True if labels fit.</returns>
  4418. private bool CheckLabelsFit(
  4419. ChartGraphics chartGraph,
  4420. float otherElementsSize,
  4421. bool autoPlotPosition,
  4422. bool checkLabelsFirstRowOnly,
  4423. bool secondPass)
  4424. {
  4425. return this.CheckLabelsFit(
  4426. chartGraph,
  4427. otherElementsSize,
  4428. autoPlotPosition,
  4429. checkLabelsFirstRowOnly,
  4430. secondPass,
  4431. true,
  4432. true,
  4433. null);
  4434. }
  4435. /// <summary>
  4436. /// Checks if labels fit using current auto fit properties
  4437. /// </summary>
  4438. /// <param name="chartGraph">Chart graphics object.</param>
  4439. /// <param name="otherElementsSize">Axis title and marks size.</param>
  4440. /// <param name="autoPlotPosition">Indicates auto calculation of plotting area.</param>
  4441. /// <param name="checkLabelsFirstRowOnly">Labels fit is checked during the second pass.</param>
  4442. /// <param name="secondPass">Indicates second pass of labels fitting.</param>
  4443. /// <param name="checkWidth">True if width should be checked.</param>
  4444. /// <param name="checkHeight">True if height should be checked.</param>
  4445. /// <param name="labelPositions">Returns an array of label positions.</param>
  4446. /// <returns>True if labels fit.</returns>
  4447. private bool CheckLabelsFit(
  4448. ChartGraphics chartGraph,
  4449. float otherElementsSize,
  4450. bool autoPlotPosition,
  4451. bool checkLabelsFirstRowOnly,
  4452. bool secondPass,
  4453. bool checkWidth,
  4454. bool checkHeight,
  4455. ArrayList labelPositions)
  4456. {
  4457. // Reset list of label positions
  4458. if (labelPositions != null)
  4459. {
  4460. labelPositions.Clear();
  4461. }
  4462. // Label string drawing format
  4463. using (StringFormat format = new StringFormat())
  4464. {
  4465. format.FormatFlags |= StringFormatFlags.LineLimit;
  4466. format.Trimming = StringTrimming.EllipsisCharacter;
  4467. // Initialize all labels position rectangle
  4468. RectangleF rect = RectangleF.Empty;
  4469. // Calculate max label size
  4470. float maxLabelSize = 0;
  4471. if (!autoPlotPosition)
  4472. {
  4473. if (this.GetIsMarksNextToAxis())
  4474. {
  4475. if (this.AxisPosition == AxisPosition.Top)
  4476. maxLabelSize = (float)GetAxisPosition() - ChartArea.Position.Y;
  4477. else if (this.AxisPosition == AxisPosition.Bottom)
  4478. maxLabelSize = ChartArea.Position.Bottom - (float)GetAxisPosition();
  4479. if (this.AxisPosition == AxisPosition.Left)
  4480. maxLabelSize = (float)GetAxisPosition() - ChartArea.Position.X;
  4481. else if (this.AxisPosition == AxisPosition.Right)
  4482. maxLabelSize = ChartArea.Position.Right - (float)GetAxisPosition();
  4483. }
  4484. else
  4485. {
  4486. if (this.AxisPosition == AxisPosition.Top)
  4487. maxLabelSize = this.PlotAreaPosition.Y - ChartArea.Position.Y;
  4488. else if (this.AxisPosition == AxisPosition.Bottom)
  4489. maxLabelSize = ChartArea.Position.Bottom - this.PlotAreaPosition.Bottom;
  4490. if (this.AxisPosition == AxisPosition.Left)
  4491. maxLabelSize = this.PlotAreaPosition.X - ChartArea.Position.X;
  4492. else if (this.AxisPosition == AxisPosition.Right)
  4493. maxLabelSize = ChartArea.Position.Right - this.PlotAreaPosition.Right;
  4494. }
  4495. maxLabelSize *= 2F;
  4496. }
  4497. else
  4498. {
  4499. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  4500. maxLabelSize = ChartArea.Position.Height;
  4501. else
  4502. maxLabelSize = ChartArea.Position.Width;
  4503. }
  4504. // Loop through all grouping labels (all except first row)
  4505. this.totlaGroupingLabelsSize = 0;
  4506. // Get number of groups
  4507. int groupLabelLevelCount = GetGroupLabelLevelCount();
  4508. // Check ig grouping labels exist
  4509. if (groupLabelLevelCount > 0)
  4510. {
  4511. groupingLabelSizes = new float[groupLabelLevelCount];
  4512. // Loop through each level of grouping labels
  4513. bool fitResult = true;
  4514. for (int groupLevelIndex = 1; groupLevelIndex <= groupLabelLevelCount; groupLevelIndex++)
  4515. {
  4516. groupingLabelSizes[groupLevelIndex - 1] = 0f;
  4517. // Loop through all labels in the level
  4518. foreach (CustomLabel label in this.CustomLabels)
  4519. {
  4520. // Skip if label middle point is outside current scaleView
  4521. if (label.RowIndex == 0)
  4522. {
  4523. double middlePoint = (label.FromPosition + label.ToPosition) / 2.0;
  4524. if (middlePoint < this.ViewMinimum || middlePoint > this.ViewMaximum)
  4525. {
  4526. continue;
  4527. }
  4528. }
  4529. if (label.RowIndex == groupLevelIndex)
  4530. {
  4531. // Calculate label rect
  4532. double fromPosition = this.GetLinearPosition(label.FromPosition);
  4533. double toPosition = this.GetLinearPosition(label.ToPosition);
  4534. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  4535. {
  4536. rect.Height = (maxLabelSize / 100F) * maxAxisLabelRow2Size / groupLabelLevelCount;
  4537. rect.X = (float)Math.Min(fromPosition, toPosition);
  4538. rect.Width = (float)Math.Max(fromPosition, toPosition) - rect.X;
  4539. }
  4540. else
  4541. {
  4542. rect.Width = (maxLabelSize / 100F) * maxAxisLabelRow2Size / groupLabelLevelCount;
  4543. rect.Y = (float)Math.Min(fromPosition, toPosition);
  4544. rect.Height = (float)Math.Max(fromPosition, toPosition) - rect.Y;
  4545. }
  4546. // Measure string
  4547. SizeF axisLabelSize = chartGraph.MeasureStringRel(label.Text.Replace("\\n", "\n"), autoLabelFont);
  4548. // Add image size
  4549. if (label.Image.Length > 0)
  4550. {
  4551. SizeF imageAbsSize = new SizeF();
  4552. if (this.Common.ImageLoader.GetAdjustedImageSize(label.Image, chartGraph.Graphics, ref imageAbsSize))
  4553. {
  4554. SizeF imageRelSize = chartGraph.GetRelativeSize(imageAbsSize);
  4555. axisLabelSize.Width += imageRelSize.Width;
  4556. axisLabelSize.Height = Math.Max(axisLabelSize.Height, imageRelSize.Height);
  4557. }
  4558. }
  4559. // Add extra spacing for the box marking of the label
  4560. if (label.LabelMark == LabelMarkStyle.Box)
  4561. {
  4562. // Get relative size from pixels and add it to the label size
  4563. SizeF spacerSize = chartGraph.GetRelativeSize(new SizeF(4, 4));
  4564. axisLabelSize.Width += spacerSize.Width;
  4565. axisLabelSize.Height += spacerSize.Height;
  4566. }
  4567. // Calculate max height of the second row of labels
  4568. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  4569. {
  4570. groupingLabelSizes[groupLevelIndex - 1] = (float)Math.Max(groupingLabelSizes[groupLevelIndex - 1], axisLabelSize.Height);
  4571. }
  4572. else
  4573. {
  4574. axisLabelSize.Width = chartGraph.GetAbsoluteSize(new SizeF(axisLabelSize.Height, axisLabelSize.Height)).Height;
  4575. axisLabelSize.Width = chartGraph.GetRelativeSize(new SizeF(axisLabelSize.Width, axisLabelSize.Width)).Width;
  4576. groupingLabelSizes[groupLevelIndex - 1] = (float)Math.Max(groupingLabelSizes[groupLevelIndex - 1], axisLabelSize.Width);
  4577. }
  4578. // Check if string fits
  4579. if (Math.Round(axisLabelSize.Width) >= Math.Round(rect.Width) &&
  4580. checkWidth)
  4581. {
  4582. fitResult = false;
  4583. }
  4584. if (Math.Round(axisLabelSize.Height) >= Math.Round(rect.Height) &&
  4585. checkHeight)
  4586. {
  4587. fitResult = false;
  4588. }
  4589. }
  4590. }
  4591. }
  4592. this.totlaGroupingLabelsSize = this.GetGroupLablesToatalSize();
  4593. if (!fitResult && !checkLabelsFirstRowOnly)
  4594. {
  4595. return false;
  4596. }
  4597. }
  4598. // Loop through all labels in the first row
  4599. float angle = autoLabelAngle;
  4600. int labelIndex = 0;
  4601. foreach (CustomLabel label in this.CustomLabels)
  4602. {
  4603. // Skip if label middle point is outside current scaleView
  4604. if (label.RowIndex == 0)
  4605. {
  4606. double middlePoint = (label.FromPosition + label.ToPosition) / 2.0;
  4607. if (middlePoint < this.ViewMinimum || middlePoint > this.ViewMaximum)
  4608. {
  4609. continue;
  4610. }
  4611. }
  4612. if (label.RowIndex == 0)
  4613. {
  4614. // Force which scale segment to use when calculating label position
  4615. if (labelPositions != null)
  4616. {
  4617. this.ScaleSegments.EnforceSegment(this.ScaleSegments.FindScaleSegmentForAxisValue((label.FromPosition + label.ToPosition) / 2.0));
  4618. }
  4619. // Set label From and To coordinates
  4620. double fromPosition = this.GetLinearPosition(label.FromPosition);
  4621. double toPosition = this.GetLinearPosition(label.ToPosition);
  4622. // Reset scale segment to use when calculating label position
  4623. if (labelPositions != null)
  4624. {
  4625. this.ScaleSegments.EnforceSegment(null);
  4626. }
  4627. // Calculate single label position
  4628. rect.X = this.PlotAreaPosition.X;
  4629. rect.Y = (float)Math.Min(fromPosition, toPosition);
  4630. rect.Height = (float)Math.Max(fromPosition, toPosition) - rect.Y;
  4631. float maxElementSize = maxAxisElementsSize;
  4632. if (maxAxisElementsSize - this.totlaGroupingLabelsSize > 55)
  4633. {
  4634. maxElementSize = 55 + this.totlaGroupingLabelsSize;
  4635. }
  4636. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  4637. {
  4638. rect.Width = (maxLabelSize / 100F) *
  4639. (maxElementSize - this.totlaGroupingLabelsSize - otherElementsSize - elementSpacing);
  4640. }
  4641. else
  4642. {
  4643. rect.Width = (maxLabelSize / 100F) *
  4644. (maxElementSize - this.totlaGroupingLabelsSize - otherElementsSize - elementSpacing);
  4645. }
  4646. // Adjust label From/To position if labels are displayed with offset
  4647. if (autoLabelOffset == 1)
  4648. {
  4649. rect.Y -= rect.Height / 2F;
  4650. rect.Height *= 2F;
  4651. rect.Width /= 2F;
  4652. }
  4653. // If horizontal axis
  4654. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  4655. {
  4656. // Switch rectangle sizes
  4657. float val = rect.Height;
  4658. rect.Height = rect.Width;
  4659. rect.Width = val;
  4660. // Set vertical font for measuring
  4661. if (angle != 0)
  4662. {
  4663. format.FormatFlags |= StringFormatFlags.DirectionVertical;
  4664. }
  4665. }
  4666. else
  4667. {
  4668. // Set vertical font for measuring
  4669. if (angle == 90 || angle == -90)
  4670. {
  4671. angle = 0;
  4672. format.FormatFlags |= StringFormatFlags.DirectionVertical;
  4673. }
  4674. }
  4675. // Measure label text size. Add the 'I' character to allow a little bit of spacing between labels.
  4676. SizeF axisLabelSize = chartGraph.MeasureStringRel(
  4677. label.Text.Replace("\\n", "\n") + "W",
  4678. autoLabelFont,
  4679. (secondPass) ? rect.Size : ChartArea.Position.ToRectangleF().Size,
  4680. format);
  4681. // Width and height maybe zeros if rect is too small to fit the text and
  4682. // the LineLimit format flag is set.
  4683. if (label.Text.Length > 0 &&
  4684. (axisLabelSize.Width == 0f ||
  4685. axisLabelSize.Height == 0f))
  4686. {
  4687. // Measure string without the LineLimit flag
  4688. format.FormatFlags ^= StringFormatFlags.LineLimit;
  4689. axisLabelSize = chartGraph.MeasureStringRel(
  4690. label.Text.Replace("\\n", "\n"),
  4691. autoLabelFont,
  4692. (secondPass) ? rect.Size : ChartArea.Position.ToRectangleF().Size,
  4693. format);
  4694. format.FormatFlags |= StringFormatFlags.LineLimit;
  4695. }
  4696. // Add image size
  4697. if (label.Image.Length > 0)
  4698. {
  4699. SizeF imageAbsSize = new SizeF();
  4700. if(this.Common.ImageLoader.GetAdjustedImageSize(label.Image, chartGraph.Graphics, ref imageAbsSize))
  4701. {
  4702. SizeF imageRelSize = chartGraph.GetRelativeSize(imageAbsSize);
  4703. if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
  4704. {
  4705. axisLabelSize.Height += imageRelSize.Height;
  4706. axisLabelSize.Width = Math.Max(axisLabelSize.Width, imageRelSize.Width);
  4707. }
  4708. else
  4709. {
  4710. axisLabelSize.Width += imageRelSize.Width;
  4711. axisLabelSize.Height = Math.Max(axisLabelSize.Height, imageRelSize.Height);
  4712. }
  4713. }
  4714. }
  4715. // Add extra spacing for the box marking of the label
  4716. if (label.LabelMark == LabelMarkStyle.Box)
  4717. {
  4718. // Get relative size from pixels and add it to the label size
  4719. SizeF spacerSize = chartGraph.GetRelativeSize(new SizeF(4, 4));
  4720. axisLabelSize.Width += spacerSize.Width;
  4721. axisLabelSize.Height += spacerSize.Height;
  4722. }
  4723. // Calculate size using label angle
  4724. float width = axisLabelSize.Width;
  4725. float height = axisLabelSize.Height;
  4726. if (angle != 0)
  4727. {
  4728. // Decrease label rectangle width by 3%
  4729. rect.Width *= 0.97f;
  4730. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  4731. {
  4732. width = (float)Math.Cos((Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Height;
  4733. width += (float)Math.Sin((Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Width;
  4734. height = (float)Math.Sin((Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Height;
  4735. height += (float)Math.Cos((Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Width;
  4736. }
  4737. else
  4738. {
  4739. width = (float)Math.Cos((Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Width;
  4740. width += (float)Math.Sin((Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Height;
  4741. height = (float)Math.Sin((Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Width;
  4742. height += (float)Math.Cos((Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Height;
  4743. }
  4744. }
  4745. // Save label position
  4746. if (labelPositions != null)
  4747. {
  4748. RectangleF labelPosition = rect;
  4749. if (angle == 0F || angle == 90F || angle == -90F)
  4750. {
  4751. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  4752. {
  4753. labelPosition.X = labelPosition.X + labelPosition.Width / 2f - width / 2f;
  4754. labelPosition.Width = width;
  4755. }
  4756. else
  4757. {
  4758. labelPosition.Y = labelPosition.Y + labelPosition.Height / 2f - height / 2f;
  4759. labelPosition.Height = height;
  4760. }
  4761. }
  4762. labelPositions.Add(labelPosition);
  4763. }
  4764. // Check if string fits
  4765. if (angle == 0F)
  4766. {
  4767. if (width >= rect.Width && checkWidth)
  4768. {
  4769. return false;
  4770. }
  4771. if (height >= rect.Height && checkHeight)
  4772. {
  4773. return false;
  4774. }
  4775. }
  4776. if (angle == 90F || angle == -90F)
  4777. {
  4778. if (width >= rect.Width && checkWidth)
  4779. {
  4780. return false;
  4781. }
  4782. if (height >= rect.Height && checkHeight)
  4783. {
  4784. return false;
  4785. }
  4786. }
  4787. else
  4788. {
  4789. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  4790. {
  4791. if (width >= rect.Width * 2F && checkWidth)
  4792. {
  4793. return false;
  4794. }
  4795. if (height >= rect.Height * 2F && checkHeight)
  4796. {
  4797. return false;
  4798. }
  4799. }
  4800. else
  4801. {
  4802. if (width >= rect.Width * 2F && checkWidth)
  4803. {
  4804. return false;
  4805. }
  4806. if (height >= rect.Height * 2F && checkHeight)
  4807. {
  4808. return false;
  4809. }
  4810. }
  4811. }
  4812. ++labelIndex;
  4813. }
  4814. }
  4815. }
  4816. return true;
  4817. }
  4818. /// <summary>
  4819. /// Calculates the best size for labels area.
  4820. /// </summary>
  4821. /// <param name="chartGraph">Chart graphics object.</param>
  4822. /// <param name="maxLabelSize">Maximum labels area size.</param>
  4823. /// <param name="resultSize">Label size without angle = 0.</param>
  4824. private float GetRequiredLabelSize(ChartGraphics chartGraph, float maxLabelSize, out float resultSize)
  4825. {
  4826. float resultRotatedSize = 0F;
  4827. resultSize = 0F;
  4828. float angle = (autoLabelAngle < -90) ? this.LabelStyle.Angle : autoLabelAngle;
  4829. labelNearOffset = float.MaxValue;
  4830. labelFarOffset = float.MinValue;
  4831. // Label string drawing format
  4832. using (StringFormat format = new StringFormat())
  4833. {
  4834. format.FormatFlags |= StringFormatFlags.LineLimit;
  4835. format.Trimming = StringTrimming.EllipsisCharacter;
  4836. // Initialize all labels position rectangle
  4837. RectangleF rectLabels = ChartArea.Position.ToRectangleF();
  4838. // Loop through all labels in the first row
  4839. foreach (CustomLabel label in this.CustomLabels)
  4840. {
  4841. // Skip if label middle point is outside current scaleView
  4842. if (label.RowIndex == 0)
  4843. {
  4844. decimal middlePoint = (decimal)(label.FromPosition + label.ToPosition) / (decimal)2.0;
  4845. if (middlePoint < (decimal)this.ViewMinimum || middlePoint > (decimal)this.ViewMaximum)
  4846. {
  4847. continue;
  4848. }
  4849. }
  4850. if (label.RowIndex == 0)
  4851. {
  4852. // Calculate single label position
  4853. RectangleF rect = rectLabels;
  4854. rect.Width = maxLabelSize;
  4855. // Set label From and To coordinates
  4856. double fromPosition = this.GetLinearPosition(label.FromPosition);
  4857. double toPosition = this.GetLinearPosition(label.ToPosition);
  4858. rect.Y = (float)Math.Min(fromPosition, toPosition);
  4859. rect.Height = (float)Math.Max(fromPosition, toPosition) - rect.Y;
  4860. // Adjust label From/To position if labels are displayed with offset
  4861. if ((autoLabelOffset == -1) ? this.LabelStyle.IsStaggered : (autoLabelOffset == 1))
  4862. {
  4863. rect.Y -= rect.Height / 2F;
  4864. rect.Height *= 2F;
  4865. }
  4866. // If horizontal axis
  4867. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  4868. {
  4869. // Switch rectangle sizes
  4870. float val = rect.Height;
  4871. rect.Height = rect.Width;
  4872. rect.Width = val;
  4873. // Set vertical font for measuring
  4874. if (angle != 0)
  4875. {
  4876. format.FormatFlags |= StringFormatFlags.DirectionVertical;
  4877. }
  4878. }
  4879. else
  4880. {
  4881. // Set vertical font for measuring
  4882. if (angle == 90 || angle == -90)
  4883. {
  4884. angle = 0;
  4885. format.FormatFlags |= StringFormatFlags.DirectionVertical;
  4886. }
  4887. }
  4888. // Measure label text size
  4889. rect.Width = (float)Math.Ceiling(rect.Width);
  4890. rect.Height = (float)Math.Ceiling(rect.Height);
  4891. SizeF axisLabelSize = chartGraph.MeasureStringRel(label.Text.Replace("\\n", "\n"),
  4892. (autoLabelFont != null) ? autoLabelFont : this.LabelStyle.Font,
  4893. rect.Size,
  4894. format);
  4895. // Width and height maybe zeros if rect is too small to fit the text and
  4896. // the LineLimit format flag is set.
  4897. if (axisLabelSize.Width == 0f || axisLabelSize.Height == 0f)
  4898. {
  4899. // Measure string without the LineLimit flag
  4900. format.FormatFlags ^= StringFormatFlags.LineLimit;
  4901. axisLabelSize = chartGraph.MeasureStringRel(label.Text.Replace("\\n", "\n"),
  4902. (autoLabelFont != null) ? autoLabelFont : this.LabelStyle.Font,
  4903. rect.Size,
  4904. format);
  4905. format.FormatFlags |= StringFormatFlags.LineLimit;
  4906. }
  4907. // Add image size
  4908. if (label.Image.Length > 0)
  4909. {
  4910. SizeF imageAbsSize = new SizeF();
  4911. if (this.Common.ImageLoader.GetAdjustedImageSize(label.Image, chartGraph.Graphics, ref imageAbsSize))
  4912. {
  4913. SizeF imageRelSize = chartGraph.GetRelativeSize(imageAbsSize);
  4914. if ((format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
  4915. {
  4916. axisLabelSize.Height += imageRelSize.Height;
  4917. axisLabelSize.Width = Math.Max(axisLabelSize.Width, imageRelSize.Width);
  4918. }
  4919. else
  4920. {
  4921. axisLabelSize.Width += imageRelSize.Width;
  4922. axisLabelSize.Height = Math.Max(axisLabelSize.Height, imageRelSize.Height);
  4923. }
  4924. }
  4925. }
  4926. // Add extra spacing for the box marking of the label
  4927. if (label.LabelMark == LabelMarkStyle.Box)
  4928. {
  4929. // Get relative size from pixels and add it to the label size
  4930. SizeF spacerSize = chartGraph.GetRelativeSize(new SizeF(4, 4));
  4931. axisLabelSize.Width += spacerSize.Width;
  4932. axisLabelSize.Height += spacerSize.Height;
  4933. }
  4934. // Calculate size using label angle
  4935. float width = axisLabelSize.Width;
  4936. float height = axisLabelSize.Height;
  4937. if (angle != 0)
  4938. {
  4939. width = (float)Math.Cos((90 - Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Width;
  4940. width += (float)Math.Cos((Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Height;
  4941. height = (float)Math.Sin((Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Height;
  4942. height += (float)Math.Sin((90 - Math.Abs(angle)) / 180F * Math.PI) * axisLabelSize.Width;
  4943. }
  4944. width = (float)Math.Ceiling(width) * 1.05f;
  4945. height = (float)Math.Ceiling(height) * 1.05f;
  4946. axisLabelSize.Width = (float)Math.Ceiling(axisLabelSize.Width) * 1.05f;
  4947. axisLabelSize.Height = (float)Math.Ceiling(axisLabelSize.Height) * 1.05f;
  4948. // If axis is horizontal
  4949. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  4950. {
  4951. if (angle == 90 || angle == -90 || angle == 0)
  4952. {
  4953. resultSize = Math.Max(resultSize, axisLabelSize.Height);
  4954. resultRotatedSize = Math.Max(resultRotatedSize, axisLabelSize.Height);
  4955. // Calculate the overhang of labels on the side
  4956. labelNearOffset = (float)Math.Min(labelNearOffset, (fromPosition + toPosition) / 2f - axisLabelSize.Width / 2f);
  4957. labelFarOffset = (float)Math.Max(labelFarOffset, (fromPosition + toPosition) / 2f + axisLabelSize.Width / 2f);
  4958. }
  4959. else
  4960. {
  4961. resultSize = Math.Max(resultSize, axisLabelSize.Height);
  4962. resultRotatedSize = Math.Max(resultRotatedSize, height);
  4963. // Calculate the overhang of labels on the side
  4964. if (angle > 0)
  4965. {
  4966. labelFarOffset = (float)Math.Max(labelFarOffset, (fromPosition + toPosition) / 2f + width * 1.1f);
  4967. }
  4968. else
  4969. {
  4970. labelNearOffset = (float)Math.Min(labelNearOffset, (fromPosition + toPosition) / 2f - width * 1.1f);
  4971. }
  4972. }
  4973. }
  4974. // If axis is vertical
  4975. else
  4976. {
  4977. if (angle == 90 || angle == -90 || angle == 0)
  4978. {
  4979. resultSize = Math.Max(resultSize, axisLabelSize.Width);
  4980. resultRotatedSize = Math.Max(resultRotatedSize, axisLabelSize.Width);
  4981. // Calculate the overhang of labels on the side
  4982. labelNearOffset = (float)Math.Min(labelNearOffset, (fromPosition + toPosition) / 2f - axisLabelSize.Height / 2f);
  4983. labelFarOffset = (float)Math.Max(labelFarOffset, (fromPosition + toPosition) / 2f + axisLabelSize.Height / 2f);
  4984. }
  4985. else
  4986. {
  4987. resultSize = Math.Max(resultSize, axisLabelSize.Width);
  4988. resultRotatedSize = Math.Max(resultRotatedSize, width);
  4989. // Calculate the overhang of labels on the side
  4990. if (angle > 0)
  4991. {
  4992. labelFarOffset = (float)Math.Max(labelFarOffset, (fromPosition + toPosition) / 2f + height * 1.1f);
  4993. }
  4994. else
  4995. {
  4996. labelNearOffset = (float)Math.Min(labelNearOffset, (fromPosition + toPosition) / 2f - height * 1.1f);
  4997. }
  4998. }
  4999. }
  5000. // Check if we exceed the maximum value
  5001. if (resultSize > maxLabelSize)
  5002. {
  5003. resultSize = maxLabelSize;
  5004. }
  5005. }
  5006. }
  5007. }
  5008. // Adjust results if labels are displayed with offset
  5009. if ((autoLabelOffset == -1) ? this.LabelStyle.IsStaggered : (autoLabelOffset == 1))
  5010. {
  5011. resultSize *= 2F;
  5012. resultRotatedSize *= 2F;
  5013. // Check if we exceed the maximum value
  5014. if (resultSize > maxLabelSize)
  5015. {
  5016. resultSize = maxLabelSize;
  5017. resultRotatedSize = maxLabelSize;
  5018. }
  5019. }
  5020. // Adjust labels size for the 3D Common.Chart
  5021. if (ChartArea.Area3DStyle.Enable3D && !ChartArea.chartAreaIsCurcular)
  5022. {
  5023. // Increase labels size
  5024. resultSize *= 1.1f;
  5025. resultRotatedSize *= 1.1f;
  5026. }
  5027. return resultRotatedSize;
  5028. }
  5029. /// <summary>
  5030. /// Gets total size of all grouping labels.
  5031. /// </summary>
  5032. /// <returns>Total size of all grouping labels.</returns>
  5033. internal float GetGroupLablesToatalSize()
  5034. {
  5035. float size = 0f;
  5036. if (this.groupingLabelSizes != null && this.groupingLabelSizes.Length > 0)
  5037. {
  5038. foreach (float val in this.groupingLabelSizes)
  5039. {
  5040. size += val;
  5041. }
  5042. }
  5043. return size;
  5044. }
  5045. /// <summary>
  5046. /// Gets number of levels of the grouping labels.
  5047. /// </summary>
  5048. /// <returns>Number of levels of the grouping labels.</returns>
  5049. internal int GetGroupLabelLevelCount()
  5050. {
  5051. int groupLabelLevel = 0;
  5052. foreach (CustomLabel label in this.CustomLabels)
  5053. {
  5054. if (label.RowIndex > 0)
  5055. {
  5056. groupLabelLevel = Math.Max(groupLabelLevel, label.RowIndex);
  5057. }
  5058. }
  5059. return groupLabelLevel;
  5060. }
  5061. /// <summary>
  5062. /// Calculates the best size for axis labels for all rows except first one (grouping labels).
  5063. /// </summary>
  5064. /// <param name="chartGraph">Chart graphics object.</param>
  5065. /// <param name="maxLabelSize">Maximum labels area size.</param>
  5066. /// <returns>Array of grouping label sizes for each level.</returns>
  5067. private float[] GetRequiredGroupLabelSize(ChartGraphics chartGraph, float maxLabelSize)
  5068. {
  5069. float[] resultSize = null;
  5070. // Get number of groups
  5071. int groupLabelLevelCount = GetGroupLabelLevelCount();
  5072. // Check ig grouping labels exist
  5073. if (groupLabelLevelCount > 0)
  5074. {
  5075. // Create result array
  5076. resultSize = new float[groupLabelLevelCount];
  5077. // Loop through each level of grouping labels
  5078. for (int groupLevelIndex = 1; groupLevelIndex <= groupLabelLevelCount; groupLevelIndex++)
  5079. {
  5080. resultSize[groupLevelIndex - 1] = 0f;
  5081. // Loop through all labels in the level
  5082. foreach (CustomLabel label in this.CustomLabels)
  5083. {
  5084. // Skip if label middle point is outside current scaleView
  5085. if (label.RowIndex == 0)
  5086. {
  5087. double middlePoint = (label.FromPosition + label.ToPosition) / 2.0;
  5088. if (middlePoint < this.ViewMinimum || middlePoint > this.ViewMaximum)
  5089. {
  5090. continue;
  5091. }
  5092. }
  5093. if (label.RowIndex == groupLevelIndex)
  5094. {
  5095. // Measure label text size
  5096. SizeF axisLabelSize = chartGraph.MeasureStringRel(label.Text.Replace("\\n", "\n"), (autoLabelFont != null) ? autoLabelFont : this.LabelStyle.Font);
  5097. axisLabelSize.Width = (float)Math.Ceiling(axisLabelSize.Width);
  5098. axisLabelSize.Height = (float)Math.Ceiling(axisLabelSize.Height);
  5099. // Add image size
  5100. if(label.Image.Length > 0)
  5101. {
  5102. SizeF imageAbsSize = new SizeF();
  5103. if(this.Common.ImageLoader.GetAdjustedImageSize(label.Image, chartGraph.Graphics, ref imageAbsSize))
  5104. {
  5105. SizeF imageRelSize = chartGraph.GetRelativeSize(imageAbsSize);
  5106. axisLabelSize.Width += imageRelSize.Width;
  5107. axisLabelSize.Height = Math.Max(axisLabelSize.Height, imageRelSize.Height);
  5108. }
  5109. }
  5110. // Add extra spacing for the box marking of the label
  5111. if(label.LabelMark == LabelMarkStyle.Box)
  5112. {
  5113. // Get relative size from pixels and add it to the label size
  5114. SizeF spacerSize = chartGraph.GetRelativeSize(new SizeF(4, 4));
  5115. axisLabelSize.Width += spacerSize.Width;
  5116. axisLabelSize.Height += spacerSize.Height;
  5117. }
  5118. // If axis is horizontal
  5119. if (this.AxisPosition == AxisPosition.Bottom || this.AxisPosition == AxisPosition.Top)
  5120. {
  5121. resultSize[groupLevelIndex - 1] = Math.Max(resultSize[groupLevelIndex - 1], axisLabelSize.Height);
  5122. }
  5123. // If axis is vertical
  5124. else
  5125. {
  5126. axisLabelSize.Width = chartGraph.GetAbsoluteSize(new SizeF(axisLabelSize.Height, axisLabelSize.Height)).Height;
  5127. axisLabelSize.Width = chartGraph.GetRelativeSize(new SizeF(axisLabelSize.Width, axisLabelSize.Width)).Width;
  5128. resultSize[groupLevelIndex - 1] = Math.Max(resultSize[groupLevelIndex - 1], axisLabelSize.Width);
  5129. }
  5130. // Check if we exceed the maximum value
  5131. if (resultSize[groupLevelIndex - 1] > maxLabelSize / groupLabelLevelCount)
  5132. {
  5133. // NOTE: Group Labels size limitations are removed !!!
  5134. // resultSize[groupLevelIndex - 1] = maxLabelSize / groupLabelLevelCount;
  5135. // break;
  5136. }
  5137. }
  5138. }
  5139. }
  5140. }
  5141. return resultSize;
  5142. }
  5143. #endregion
  5144. #region Axis helper methods
  5145. /// <summary>
  5146. /// Gets main or sub axis associated with this axis.
  5147. /// </summary>
  5148. /// <param name="subAxisName">Sub axis name or empty string to get the main axis.</param>
  5149. /// <returns>Main or sub axis of the main axis.</returns>
  5150. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "subAxisName")]
  5151. internal Axis GetSubAxis(string subAxisName)
  5152. {
  5153. #if SUBAXES
  5154. if(!this.IsSubAxis && subAxisName.Length > 0)
  5155. {
  5156. SubAxis subAxis = this.SubAxes.FindByName(subAxisName);
  5157. if(subAxis == null)
  5158. {
  5159. throw(new InvalidOperationException( SR.ExceptionSubAxisNameNotFoundShort( subAxisName )));
  5160. }
  5161. return subAxis;
  5162. }
  5163. #endif // SUBAXES
  5164. return this;
  5165. }
  5166. /// <summary>
  5167. /// Checks if axis marks should be next to the axis
  5168. /// </summary>
  5169. /// <returns>true if marks are next to axis.</returns>
  5170. internal bool GetIsMarksNextToAxis()
  5171. {
  5172. if (ChartArea != null && ChartArea.chartAreaIsCurcular)
  5173. {
  5174. return true;
  5175. }
  5176. return this.IsMarksNextToAxis;
  5177. }
  5178. /// <summary>
  5179. /// Gets axis auto interval type.
  5180. /// </summary>
  5181. /// <returns>Axis interval type.</returns>
  5182. internal DateTimeIntervalType GetAxisIntervalType()
  5183. {
  5184. if(InternalIntervalType == DateTimeIntervalType.Auto)
  5185. {
  5186. if(GetAxisValuesType() == ChartValueType.DateTime ||
  5187. GetAxisValuesType() == ChartValueType.Date ||
  5188. GetAxisValuesType() == ChartValueType.Time ||
  5189. GetAxisValuesType() == ChartValueType.DateTimeOffset)
  5190. {
  5191. return DateTimeIntervalType.Years;
  5192. }
  5193. return DateTimeIntervalType.Number;
  5194. }
  5195. return InternalIntervalType;
  5196. }
  5197. /// <summary>
  5198. /// Gets axis values type depending on the series attached
  5199. /// </summary>
  5200. /// <returns>Axis values type.</returns>
  5201. internal ChartValueType GetAxisValuesType()
  5202. {
  5203. ChartValueType type = ChartValueType.Double;
  5204. // Check all series in this Common.Chart area attached to this axis
  5205. if (this.Common != null && this.Common.DataManager.Series != null && ChartArea != null)
  5206. {
  5207. foreach (Series series in this.Common.DataManager.Series)
  5208. {
  5209. bool seriesAttached = false;
  5210. // Check series name
  5211. if (series.ChartArea == ChartArea.Name && series.IsVisible())
  5212. {
  5213. // Check if axis type of series match
  5214. if (this.axisType == AxisName.X && series.XAxisType == AxisType.Primary)
  5215. {
  5216. #if SUBAXES
  5217. if(((Axis)this).SubAxisName == series.XSubAxisName)
  5218. #endif // SUBAXES
  5219. {
  5220. seriesAttached = true;
  5221. }
  5222. }
  5223. else if (this.axisType == AxisName.X2 && series.XAxisType == AxisType.Secondary)
  5224. {
  5225. #if SUBAXES
  5226. if(((Axis)this).SubAxisName == series.XSubAxisName)
  5227. #endif // SUBAXES
  5228. {
  5229. seriesAttached = true;
  5230. }
  5231. }
  5232. else if (this.axisType == AxisName.Y && series.YAxisType == AxisType.Primary)
  5233. {
  5234. #if SUBAXES
  5235. if(((Axis)this).SubAxisName == series.YSubAxisName)
  5236. #endif // SUBAXES
  5237. {
  5238. seriesAttached = true;
  5239. }
  5240. }
  5241. else if (this.axisType == AxisName.Y2 && series.YAxisType == AxisType.Secondary)
  5242. {
  5243. #if SUBAXES
  5244. if(((Axis)this).SubAxisName == series.YSubAxisName)
  5245. #endif // SUBAXES
  5246. {
  5247. seriesAttached = true;
  5248. }
  5249. }
  5250. }
  5251. // If series attached to this axes
  5252. if (seriesAttached)
  5253. {
  5254. if (this.axisType == AxisName.X || this.axisType == AxisName.X2)
  5255. {
  5256. type = series.XValueType;
  5257. }
  5258. else if (this.axisType == AxisName.Y || this.axisType == AxisName.Y2)
  5259. {
  5260. type = series.YValueType;
  5261. }
  5262. break;
  5263. }
  5264. }
  5265. }
  5266. return type;
  5267. }
  5268. /// <summary>
  5269. /// Returns Arrow size
  5270. /// </summary>
  5271. /// <param name="arrowOrientation">Return arrow orientation.</param>
  5272. /// <returns>Size of arrow</returns>
  5273. internal SizeF GetArrowSize(out ArrowOrientation arrowOrientation)
  5274. {
  5275. Axis opositeAxis;
  5276. double size;
  5277. double sizeOpposite;
  5278. arrowOrientation = ArrowOrientation.Top;
  5279. // Set the position of axis
  5280. switch (AxisPosition)
  5281. {
  5282. case AxisPosition.Left:
  5283. if (isReversed)
  5284. arrowOrientation = ArrowOrientation.Bottom;
  5285. else
  5286. arrowOrientation = ArrowOrientation.Top;
  5287. break;
  5288. case AxisPosition.Right:
  5289. if (isReversed)
  5290. arrowOrientation = ArrowOrientation.Bottom;
  5291. else
  5292. arrowOrientation = ArrowOrientation.Top;
  5293. break;
  5294. case AxisPosition.Bottom:
  5295. if (isReversed)
  5296. arrowOrientation = ArrowOrientation.Left;
  5297. else
  5298. arrowOrientation = ArrowOrientation.Right;
  5299. break;
  5300. case AxisPosition.Top:
  5301. if (isReversed)
  5302. arrowOrientation = ArrowOrientation.Left;
  5303. else
  5304. arrowOrientation = ArrowOrientation.Right;
  5305. break;
  5306. }
  5307. // Opposite axis. Arrow uses this axis to find
  5308. // a shift from Common.Chart area border. This shift
  5309. // depend on Tick mark size.
  5310. switch (arrowOrientation)
  5311. {
  5312. case ArrowOrientation.Left:
  5313. opositeAxis = ChartArea.AxisX;
  5314. break;
  5315. case ArrowOrientation.Right:
  5316. opositeAxis = ChartArea.AxisX2;
  5317. break;
  5318. case ArrowOrientation.Top:
  5319. opositeAxis = ChartArea.AxisY2;
  5320. break;
  5321. case ArrowOrientation.Bottom:
  5322. opositeAxis = ChartArea.AxisY;
  5323. break;
  5324. default:
  5325. opositeAxis = ChartArea.AxisX;
  5326. break;
  5327. }
  5328. // Arrow size has to have the same shape when width and height
  5329. // are changed. When the picture is resized, width of the Common.Chart
  5330. // picture is used only for arrow size.
  5331. if (arrowOrientation == ArrowOrientation.Top || arrowOrientation == ArrowOrientation.Bottom)
  5332. {
  5333. size = _lineWidth;
  5334. sizeOpposite = (double)(_lineWidth) * Common.Width / Common.Height;
  5335. }
  5336. else
  5337. {
  5338. size = (double)(_lineWidth) * Common.Width / Common.Height;
  5339. sizeOpposite = _lineWidth;
  5340. }
  5341. // Arrow is sharp triangle
  5342. if (_arrowStyle == AxisArrowStyle.SharpTriangle)
  5343. {
  5344. // Arrow direction is vertical
  5345. if (arrowOrientation == ArrowOrientation.Top || arrowOrientation == ArrowOrientation.Bottom)
  5346. return new SizeF((float)(size * 2), (float)(opositeAxis.MajorTickMark.Size + sizeOpposite * 4));
  5347. else
  5348. // Arrow direction is horizontal
  5349. return new SizeF((float)(opositeAxis.MajorTickMark.Size + sizeOpposite * 4), (float)(size * 2));
  5350. }
  5351. // There is no arrow
  5352. else if (_arrowStyle == AxisArrowStyle.None)
  5353. return new SizeF(0, 0);
  5354. else// Arrow is triangle or line type
  5355. {
  5356. // Arrow direction is vertical
  5357. if (arrowOrientation == ArrowOrientation.Top || arrowOrientation == ArrowOrientation.Bottom)
  5358. return new SizeF((float)(size * 2), (float)(opositeAxis.MajorTickMark.Size + sizeOpposite * 2));
  5359. else
  5360. // Arrow direction is horizontal
  5361. return new SizeF((float)(opositeAxis.MajorTickMark.Size + sizeOpposite * 2), (float)(size * 2));
  5362. }
  5363. }
  5364. /// <summary>
  5365. /// Checks if arrow with specified orientation will require space
  5366. /// in axis with specified position
  5367. /// </summary>
  5368. /// <param name="arrowOrientation">Arrow orientation.</param>
  5369. /// <param name="axisPosition">Axis position.</param>
  5370. /// <returns>True if arrow will be drawn in axis space</returns>
  5371. private bool IsArrowInAxis(ArrowOrientation arrowOrientation, AxisPosition axisPosition)
  5372. {
  5373. if (axisPosition == AxisPosition.Top && arrowOrientation == ArrowOrientation.Top)
  5374. return true;
  5375. else if (axisPosition == AxisPosition.Bottom && arrowOrientation == ArrowOrientation.Bottom)
  5376. return true;
  5377. if (axisPosition == AxisPosition.Left && arrowOrientation == ArrowOrientation.Left)
  5378. return true;
  5379. else if (axisPosition == AxisPosition.Right && arrowOrientation == ArrowOrientation.Right)
  5380. return true;
  5381. return false;
  5382. }
  5383. /// <summary>
  5384. /// This function converts real Interval to
  5385. /// absolute Interval
  5386. /// </summary>
  5387. /// <param name="realInterval">A interval represented as double value</param>
  5388. /// <returns>A interval represented in pixels</returns>
  5389. internal float GetPixelInterval(double realInterval)
  5390. {
  5391. double chartAreaSize;
  5392. // The Chart area pixel size as double
  5393. if (AxisPosition == AxisPosition.Top || AxisPosition == AxisPosition.Bottom)
  5394. {
  5395. chartAreaSize = PlotAreaPosition.Right - PlotAreaPosition.X;
  5396. }
  5397. else
  5398. {
  5399. chartAreaSize = PlotAreaPosition.Bottom - PlotAreaPosition.Y;
  5400. }
  5401. // Avoid division by zero.
  5402. if (ViewMaximum - ViewMinimum == 0)
  5403. {
  5404. return (float)(chartAreaSize / realInterval);
  5405. }
  5406. // The interval integer
  5407. return (float)(chartAreaSize / (ViewMaximum - ViewMinimum) * realInterval);
  5408. }
  5409. /// <summary>
  5410. /// Find if axis is on the edge of the Common.Chart plot area
  5411. /// </summary>
  5412. internal bool IsAxisOnAreaEdge
  5413. {
  5414. get
  5415. {
  5416. double edgePosition = 0;
  5417. if (this.AxisPosition == AxisPosition.Bottom)
  5418. {
  5419. edgePosition = PlotAreaPosition.Bottom;
  5420. }
  5421. else if (this.AxisPosition == AxisPosition.Left)
  5422. {
  5423. edgePosition = PlotAreaPosition.X;
  5424. }
  5425. else if (this.AxisPosition == AxisPosition.Right)
  5426. {
  5427. edgePosition = PlotAreaPosition.Right;
  5428. }
  5429. else if (this.AxisPosition == AxisPosition.Top)
  5430. {
  5431. edgePosition = PlotAreaPosition.Y;
  5432. }
  5433. // DT Fix : problems with values on edge ~0.0005
  5434. if (Math.Abs(GetAxisPosition() - edgePosition) < 0.0015)
  5435. {
  5436. return true;
  5437. }
  5438. return false;
  5439. }
  5440. }
  5441. /// <summary>
  5442. /// Find axis position using crossing value.
  5443. /// </summary>
  5444. /// <returns>Relative position</returns>
  5445. internal double GetAxisPosition()
  5446. {
  5447. return GetAxisPosition(false);
  5448. }
  5449. /// <summary>
  5450. /// Find axis position using crossing value.
  5451. /// </summary>
  5452. /// <param name="ignoreCrossing">Axis crossing should be ignored.</param>
  5453. /// <returns>Relative position</returns>
  5454. virtual internal double GetAxisPosition(bool ignoreCrossing)
  5455. {
  5456. Axis axisOpposite = GetOppositeAxis();
  5457. // Get axis position for circular Common.Chart area
  5458. if (ChartArea != null && ChartArea.chartAreaIsCurcular)
  5459. {
  5460. return PlotAreaPosition.X + PlotAreaPosition.Width / 2f;
  5461. }
  5462. // Axis is not connected with any series. There is no maximum and minimum
  5463. if (axisOpposite.maximum == axisOpposite.minimum ||
  5464. double.IsNaN(axisOpposite.maximum) ||
  5465. double.IsNaN(axisOpposite.minimum) ||
  5466. maximum == minimum ||
  5467. double.IsNaN(maximum) ||
  5468. double.IsNaN(minimum))
  5469. {
  5470. switch (AxisPosition)
  5471. {
  5472. case AxisPosition.Top:
  5473. return PlotAreaPosition.Y;
  5474. case AxisPosition.Bottom:
  5475. return PlotAreaPosition.Bottom;
  5476. case AxisPosition.Right:
  5477. return PlotAreaPosition.Right;
  5478. case AxisPosition.Left:
  5479. return PlotAreaPosition.X;
  5480. }
  5481. }
  5482. // Auto crossing enabled
  5483. if (Double.IsNaN(axisOpposite.crossing) || ignoreCrossing)
  5484. {
  5485. // Primary
  5486. if (axisType == AxisName.X || axisType == AxisName.Y)
  5487. return axisOpposite.GetLinearPosition(axisOpposite.ViewMinimum);
  5488. else // Secondary
  5489. return axisOpposite.GetLinearPosition(axisOpposite.ViewMaximum);
  5490. }
  5491. else // Auto crossing disabled
  5492. {
  5493. axisOpposite.crossing = axisOpposite.tempCrossing;
  5494. if (axisOpposite.crossing < axisOpposite.ViewMinimum)
  5495. {
  5496. axisOpposite.crossing = axisOpposite.ViewMinimum;
  5497. }
  5498. else if (axisOpposite.crossing > axisOpposite.ViewMaximum)
  5499. {
  5500. axisOpposite.crossing = axisOpposite.ViewMaximum;
  5501. }
  5502. }
  5503. return axisOpposite.GetLinearPosition(axisOpposite.crossing);
  5504. }
  5505. #endregion
  5506. #region Axis 3D helper methods
  5507. /// <summary>
  5508. /// Returns angle between 2D axis line and it's 3D transformed projection.
  5509. /// </summary>
  5510. /// <returns>Axis projection angle.</returns>
  5511. internal double GetAxisProjectionAngle()
  5512. {
  5513. // Get Z position
  5514. bool axisOnEdge;
  5515. float zPosition = GetMarksZPosition(out axisOnEdge);
  5516. // Get axis position
  5517. float axisPosition = (float)GetAxisPosition();
  5518. // Create two points on the sides of the axis
  5519. Point3D[] axisPoints = new Point3D[2];
  5520. if (this.AxisPosition == AxisPosition.Top || this.AxisPosition == AxisPosition.Bottom)
  5521. {
  5522. axisPoints[0] = new Point3D(0f, axisPosition, zPosition);
  5523. axisPoints[1] = new Point3D(100f, axisPosition, zPosition);
  5524. }
  5525. else
  5526. {
  5527. axisPoints[0] = new Point3D(axisPosition, 0f, zPosition);
  5528. axisPoints[1] = new Point3D(axisPosition, 100f, zPosition);
  5529. }
  5530. // Transform coordinates
  5531. ChartArea.matrix3D.TransformPoints(axisPoints);
  5532. // Round result
  5533. axisPoints[0].X = (float)Math.Round(axisPoints[0].X, 4);
  5534. axisPoints[0].Y = (float)Math.Round(axisPoints[0].Y, 4);
  5535. axisPoints[1].X = (float)Math.Round(axisPoints[1].X, 4);
  5536. axisPoints[1].Y = (float)Math.Round(axisPoints[1].Y, 4);
  5537. // Calculate angle
  5538. double angle = 0.0;
  5539. if (this.AxisPosition == AxisPosition.Top || this.AxisPosition == AxisPosition.Bottom)
  5540. {
  5541. angle = Math.Atan((axisPoints[1].Y - axisPoints[0].Y) / (axisPoints[1].X - axisPoints[0].X));
  5542. }
  5543. else
  5544. {
  5545. angle = Math.Atan((axisPoints[1].X - axisPoints[0].X) / (axisPoints[1].Y - axisPoints[0].Y));
  5546. }
  5547. // Conver to degrees
  5548. return (angle * 180.0) / Math.PI;
  5549. }
  5550. #endregion
  5551. #region IDisposable Members
  5552. /// <summary>
  5553. /// Releases unmanaged and - optionally - managed resources
  5554. /// </summary>
  5555. /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  5556. protected override void Dispose(bool disposing)
  5557. {
  5558. if (disposing)
  5559. {
  5560. if (_fontCache != null)
  5561. {
  5562. _fontCache.Dispose();
  5563. _fontCache = null;
  5564. }
  5565. if (labelStyle != null)
  5566. {
  5567. labelStyle.Dispose();
  5568. labelStyle = null;
  5569. }
  5570. if (_stripLines != null)
  5571. {
  5572. _stripLines.Dispose();
  5573. _stripLines = null;
  5574. }
  5575. if (_customLabels != null)
  5576. {
  5577. _customLabels.Dispose();
  5578. _customLabels = null;
  5579. }
  5580. if (tempLabels != null)
  5581. {
  5582. tempLabels.Dispose();
  5583. tempLabels = null;
  5584. }
  5585. if (this.scrollBar != null)
  5586. {
  5587. this.scrollBar.Dispose();
  5588. this.scrollBar = null;
  5589. }
  5590. }
  5591. base.Dispose(disposing);
  5592. }
  5593. #endregion
  5594. }
  5595. }