DataPoint.cs 174 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244
  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: Classes related to the Data Points:
  6. // DataPointCollection - data points collection class
  7. // DataPoint - data point properties and methods
  8. // DataPointCustomProperties - data point & series properties
  9. // DataPointComparer - used for sorting data points in series
  10. //
  11. using System;
  12. using System.Windows.Forms;
  13. using System.Collections;
  14. using System.Collections.Generic;
  15. using System.ComponentModel;
  16. using System.Data;
  17. using System.Data.Common;
  18. using System.Diagnostics.CodeAnalysis;
  19. using System.Drawing;
  20. using System.Drawing.Design;
  21. using System.Globalization;
  22. using System.Text;
  23. using FastReport.DataVisualization.Charting.Utilities;
  24. using FastReport.Design.DataVisualization.Charting;
  25. namespace FastReport.DataVisualization.Charting
  26. {
  27. #region CustomProperties enumeration
  28. /// <summary>
  29. /// Enumeration of common properties names.
  30. /// </summary>
  31. internal enum CommonCustomProperties
  32. {
  33. PointName,
  34. Label,
  35. AxisLabel,
  36. LabelFormat,
  37. IsValueShownAsLabel,
  38. Color,
  39. BorderColor,
  40. BorderDashStyle,
  41. BorderWidth,
  42. BackImage,
  43. BackImageWrapMode,
  44. BackImageAlignment,
  45. BackImageTransparentColor,
  46. BackGradientStyle,
  47. BackSecondaryColor,
  48. BackHatchStyle,
  49. Font,
  50. LabelForeColor,
  51. LabelAngle,
  52. MarkerStyle,
  53. MarkerSize,
  54. MarkerImage,
  55. MarkerImageTransparentColor,
  56. MarkerColor,
  57. MarkerBorderColor,
  58. MarkerBorderWidth,
  59. MapAreaAttributes,
  60. PostBackValue,
  61. MapAreaType,
  62. LegendMapAreaType,
  63. LabelMapAreaType,
  64. Url,
  65. ToolTip,
  66. Tag,
  67. LegendUrl,
  68. LegendToolTip,
  69. LegendText,
  70. LegendMapAreaAttributes,
  71. LegendPostBackValue,
  72. IsVisibleInLegend,
  73. LabelUrl,
  74. LabelToolTip,
  75. LabelMapAreaAttributes,
  76. LabelPostBackValue,
  77. LabelBorderColor,
  78. LabelBorderDashStyle,
  79. LabelBorderWidth,
  80. LabelBackColor,
  81. };
  82. #endregion
  83. /// <summary>
  84. /// Data points comparer class
  85. /// </summary>
  86. [
  87. SRDescription("DescriptionAttributeDataPointComparer_DataPointComparer")
  88. ]
  89. public class DataPointComparer : IComparer<DataPoint>
  90. {
  91. #region Fields
  92. // Sorting order
  93. private PointSortOrder _sortingOrder = PointSortOrder.Ascending;
  94. // Sorting value index
  95. private int _sortingValueIndex = 1;
  96. #endregion
  97. #region Constructors
  98. /// <summary>
  99. /// Private default constructor.
  100. /// </summary>
  101. private DataPointComparer()
  102. {
  103. }
  104. /// <summary>
  105. /// Data points comparer class constructor.
  106. /// </summary>
  107. /// <param name="series">Data series.</param>
  108. /// <param name="sortOrder">Sorting order.</param>
  109. /// <param name="sortBy">Value used for sorting ("X", "Y or Y1", "Y2", ...).</param>
  110. public DataPointComparer(Series series, PointSortOrder sortOrder, string sortBy)
  111. {
  112. // Check if sorting value is valid
  113. sortBy = sortBy.ToUpper(System.Globalization.CultureInfo.InvariantCulture);
  114. if(String.Compare(sortBy, "X", StringComparison.Ordinal) == 0)
  115. {
  116. _sortingValueIndex = -1;
  117. }
  118. else if (String.Compare(sortBy, "Y", StringComparison.Ordinal) == 0)
  119. {
  120. _sortingValueIndex = 0;
  121. }
  122. else if (String.Compare(sortBy, "AXISLABEL", StringComparison.Ordinal) == 0)
  123. {
  124. _sortingValueIndex = -2;
  125. }
  126. else if(sortBy.Length == 2 &&
  127. sortBy.StartsWith("Y", StringComparison.Ordinal) &&
  128. Char.IsDigit(sortBy[1]))
  129. {
  130. _sortingValueIndex = Int32.Parse(sortBy.Substring(1), System.Globalization.CultureInfo.InvariantCulture) - 1;
  131. }
  132. else
  133. {
  134. throw(new ArgumentException( SR.ExceptionDataPointConverterInvalidSorting, "sortBy"));
  135. }
  136. // Check if data series support as many Y values as required
  137. if(_sortingValueIndex > 0 && _sortingValueIndex >= series.YValuesPerPoint)
  138. {
  139. throw(new ArgumentException( SR.ExceptionDataPointConverterUnavailableSorting(sortBy, series.YValuesPerPoint.ToString(System.Globalization.CultureInfo.InvariantCulture) ), "sortBy"));
  140. }
  141. this._sortingOrder = sortOrder;
  142. }
  143. #endregion
  144. #region Comparing method
  145. /// <summary>
  146. /// Compares two data points.
  147. /// </summary>
  148. /// <param name="x">First data point.</param>
  149. /// <param name="y">Second data point.</param>
  150. /// <returns>If the two values are equal, it returns zero. If point 1 is greater than point 2,
  151. /// it returns a positive integer; otherwise, it returns a negative integer.
  152. /// </returns>
  153. public int Compare(DataPoint x, DataPoint y)
  154. {
  155. int result = -1;
  156. // Compare X value
  157. if(_sortingValueIndex == -1)
  158. {
  159. result = x.XValue.CompareTo(y.XValue);
  160. }
  161. // Compare Axis Label value
  162. else if(_sortingValueIndex == -2)
  163. {
  164. result = string.Compare(x.AxisLabel, y.AxisLabel, StringComparison.CurrentCulture);
  165. }
  166. // Compare one of the Y value(s)
  167. else
  168. {
  169. result = x.YValues[_sortingValueIndex].CompareTo(y.YValues[_sortingValueIndex]);
  170. }
  171. // Invert result depending on the sorting order
  172. if(this._sortingOrder == PointSortOrder.Descending)
  173. {
  174. result = -result;
  175. }
  176. return result;
  177. }
  178. #endregion
  179. }
  180. /// <summary>
  181. /// A collection of data points.
  182. /// </summary>
  183. [
  184. SRDescription("DescriptionAttributeDataPointCollection_DataPointCollection"),
  185. ]
  186. public class DataPointCollection : ChartElementCollection<DataPoint>
  187. {
  188. #region Fields
  189. // Reference to the sereies of data points
  190. internal Series series = null;
  191. #endregion
  192. #region Constructors and Initialization
  193. /// <summary>
  194. /// Data Point Collection object constructor.
  195. /// </summary>
  196. /// <param name="series">Series object, which the Data Point Collection belongs to.</param>
  197. internal DataPointCollection(Series series) : base(series)
  198. {
  199. this.series = series;
  200. }
  201. /// <summary>
  202. /// Initialize data point series and name.
  203. /// </summary>
  204. /// <param name="dataPoint">Reference to the data point object to initialize.</param>
  205. internal void DataPointInit(ref DataPoint dataPoint)
  206. {
  207. DataPointInit(this.series, ref dataPoint);
  208. }
  209. /// <summary>
  210. /// Initialize data point series and name.
  211. /// </summary>
  212. /// <param name="series">Series the data point belongs to.</param>
  213. /// <param name="dataPoint">Reference to the data point object to initialize.</param>
  214. internal static void DataPointInit(Series series, ref DataPoint dataPoint)
  215. {
  216. dataPoint.series = series;
  217. if(dataPoint.AxisLabel.Length > 0 && series != null)
  218. {
  219. series.noLabelsInPoints = false;
  220. }
  221. // Set flag that tooltips flags should be recalculated
  222. if(dataPoint.ToolTip.Length > 0 &&
  223. dataPoint.LegendToolTip.Length > 0 &&
  224. dataPoint.LabelToolTip.Length > 0 &&
  225. series != null && series.Chart != null && series.Chart.selection != null)
  226. {
  227. series.Chart.selection.enabledChecked = false;
  228. }
  229. }
  230. #endregion
  231. #region Data point binding, adding and inserting methods
  232. /// <summary>
  233. /// Adds the new DataPoint to a collection and sets its Y values.
  234. /// </summary>
  235. /// <param name="y">The y.</param>
  236. /// <returns></returns>
  237. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  238. Justification = "X and Y are cartesian coordinates and well understood")]
  239. public DataPoint Add(params double[] y)
  240. {
  241. DataPoint point = new DataPoint(0, y);
  242. this.Add(point);
  243. return point;
  244. }
  245. /// <summary>
  246. /// Parse the input parameter with other point attribute binding rule
  247. /// in format: PointProperty=Field[{Format}] [,PointProperty=Field[{Format}]].
  248. /// For example: "Tooltip=Price{C1},Url=WebSiteName".
  249. /// </summary>
  250. /// <param name="otherFields">Other fields parameter.</param>
  251. /// <param name="otherAttributeNames">Returns array of attribute names.</param>
  252. /// <param name="otherFieldNames">Returns array of field names.</param>
  253. /// <param name="otherValueFormat">Returns array of format strings.</param>
  254. internal static void ParsePointFieldsParameter(
  255. string otherFields,
  256. ref string[] otherAttributeNames,
  257. ref string[] otherFieldNames,
  258. ref string[] otherValueFormat)
  259. {
  260. if(otherFields != null && otherFields.Length > 0)
  261. {
  262. // Split string by comma
  263. otherAttributeNames = otherFields.Replace(",,", "\n").Split(',');
  264. otherFieldNames = new string[otherAttributeNames.Length];
  265. otherValueFormat = new string[otherAttributeNames.Length];
  266. // Loop through all strings
  267. for(int index = 0; index < otherAttributeNames.Length; index++)
  268. {
  269. // Split string by equal sign
  270. int equalSignIndex = otherAttributeNames[index].IndexOf('=');
  271. if(equalSignIndex > 0)
  272. {
  273. otherFieldNames[index] = otherAttributeNames[index].Substring(equalSignIndex + 1);
  274. otherAttributeNames[index] = otherAttributeNames[index].Substring(0, equalSignIndex);
  275. }
  276. else
  277. {
  278. throw (new ArgumentException(SR.ExceptionParameterFormatInvalid, "otherFields"));
  279. }
  280. // Check if format string was specified
  281. int bracketIndex = otherFieldNames[index].IndexOf('{');
  282. if(bracketIndex > 0 && otherFieldNames[index][otherFieldNames[index].Length - 1] == '}')
  283. {
  284. otherValueFormat[index] = otherFieldNames[index].Substring(bracketIndex + 1);
  285. otherValueFormat[index] = otherValueFormat[index].Trim('{', '}');
  286. otherFieldNames[index] = otherFieldNames[index].Substring(0, bracketIndex);
  287. }
  288. // Trim and replace new line character
  289. otherAttributeNames[index] = otherAttributeNames[index].Trim().Replace("\n", ",");
  290. otherFieldNames[index] = otherFieldNames[index].Trim().Replace("\n", ",");
  291. if ( otherValueFormat[index] != null )
  292. otherValueFormat[index] = otherValueFormat[index].Trim().Replace("\n", ",");
  293. }
  294. }
  295. }
  296. /// <summary>
  297. /// Data bind X, Y and other values (like Tooltip, LabelStyle,...) of the data points to the data source.
  298. /// Data source can be the Ole(SQL)DataReader, DataView, DataSet, DataTable or DataRow.
  299. /// </summary>
  300. /// <param name="dataSource">Data source.</param>
  301. /// <param name="xField">Name of the field for X values.</param>
  302. /// <param name="yFields">Comma separated names of the fields for Y values.</param>
  303. /// <param name="otherFields">Other point properties binding rule in format: PointProperty=Field[{Format}] [,PointProperty=Field[{Format}]]. For example: "Tooltip=Price{C1},Url=WebSiteName".</param>
  304. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  305. Justification = "X and Y are cartesian coordinates and well understood")]
  306. public void DataBind(IEnumerable dataSource, string xField, string yFields, string otherFields)
  307. {
  308. // Check arguments
  309. if (dataSource == null)
  310. throw new ArgumentNullException("dataSource", SR.ExceptionDataPointInsertionNoDataSource);
  311. if (dataSource is string)
  312. throw (new ArgumentException(SR.ExceptionDataBindSeriesToString, "dataSource"));
  313. if (yFields == null)
  314. throw new ArgumentNullException("yFields");
  315. // Convert comma separated Y values field names string to array of names
  316. string[] yFieldNames = yFields.Replace(",,", "\n").Split(',');
  317. for(int index = 0; index < yFieldNames.Length; index++)
  318. {
  319. yFieldNames[index] = yFieldNames[index].Replace("\n", ",");
  320. }
  321. if (yFieldNames.GetLength(0) > series.YValuesPerPoint)
  322. throw (new ArgumentOutOfRangeException("yFields", SR.ExceptionDataPointYValuesCountMismatch(series.YValuesPerPoint.ToString(System.Globalization.CultureInfo.InvariantCulture))));
  323. // Convert other fields/properties names to two arrays of names
  324. string[] otherAttributeNames = null;
  325. string[] otherFieldNames = null;
  326. string[] otherValueFormat = null;
  327. ParsePointFieldsParameter(
  328. otherFields,
  329. ref otherAttributeNames,
  330. ref otherFieldNames,
  331. ref otherValueFormat);
  332. // Remove all existing data points
  333. this.Clear();
  334. // Get and reset enumerator
  335. IEnumerator enumerator = GetDataSourceEnumerator(dataSource);
  336. if (enumerator.GetType() != typeof(System.Data.Common.DbEnumerator))
  337. {
  338. try
  339. {
  340. enumerator.Reset();
  341. }
  342. // Some enumerators may not support Resetting
  343. catch (InvalidOperationException)
  344. {
  345. }
  346. catch (NotImplementedException)
  347. {
  348. }
  349. catch (NotSupportedException)
  350. {
  351. }
  352. }
  353. // Add data points
  354. bool valueExsist = true;
  355. object[] yValuesObj = new object[yFieldNames.Length];
  356. object xValueObj = null;
  357. bool autoDetectType = true;
  358. this.SuspendUpdates();
  359. try
  360. {
  361. do
  362. {
  363. // Move to the next objects in the enumerations
  364. if (valueExsist)
  365. {
  366. valueExsist = enumerator.MoveNext();
  367. }
  368. // Auto detect valu(s) type
  369. if (autoDetectType)
  370. {
  371. autoDetectType = false;
  372. AutoDetectValuesType(this.series, enumerator, xField, enumerator, yFieldNames[0]);
  373. }
  374. // Create and initialize data point
  375. if (valueExsist)
  376. {
  377. DataPoint newDataPoint = new DataPoint(series);
  378. bool emptyValues = false;
  379. // Set X to the value provided
  380. if (xField.Length > 0)
  381. {
  382. xValueObj = ConvertEnumerationItem(enumerator.Current, xField);
  383. if (IsEmptyValue(xValueObj))
  384. {
  385. emptyValues = true;
  386. xValueObj = 0.0;
  387. }
  388. }
  389. // Set Y values
  390. if (yFieldNames.Length == 0)
  391. {
  392. yValuesObj[0] = ConvertEnumerationItem(enumerator.Current, null);
  393. if (IsEmptyValue(yValuesObj[0]))
  394. {
  395. emptyValues = true;
  396. yValuesObj[0] = 0.0;
  397. }
  398. }
  399. else
  400. {
  401. for (int i = 0; i < yFieldNames.Length; i++)
  402. {
  403. yValuesObj[i] = ConvertEnumerationItem(enumerator.Current, yFieldNames[i]);
  404. if (IsEmptyValue(yValuesObj[i]))
  405. {
  406. emptyValues = true;
  407. yValuesObj[i] = 0.0;
  408. }
  409. }
  410. }
  411. // Set other values
  412. if (otherAttributeNames != null &&
  413. otherAttributeNames.Length > 0)
  414. {
  415. for (int i = 0; i < otherFieldNames.Length; i++)
  416. {
  417. // Get object by field name
  418. object obj = ConvertEnumerationItem(enumerator.Current, otherFieldNames[i]);
  419. if (!IsEmptyValue(obj))
  420. {
  421. newDataPoint.SetPointCustomProperty(
  422. obj,
  423. otherAttributeNames[i],
  424. otherValueFormat[i]);
  425. }
  426. }
  427. }
  428. // IsEmpty value was detected
  429. if (emptyValues)
  430. {
  431. if (xValueObj != null)
  432. {
  433. newDataPoint.SetValueXY(xValueObj, yValuesObj);
  434. }
  435. else
  436. {
  437. newDataPoint.SetValueXY(0, yValuesObj);
  438. }
  439. DataPointInit(ref newDataPoint);
  440. newDataPoint.IsEmpty = true;
  441. this.Add(newDataPoint);
  442. }
  443. else
  444. {
  445. if (xValueObj != null)
  446. {
  447. newDataPoint.SetValueXY(xValueObj, yValuesObj);
  448. }
  449. else
  450. {
  451. newDataPoint.SetValueXY(0, yValuesObj);
  452. }
  453. DataPointInit(ref newDataPoint);
  454. this.Add(newDataPoint);
  455. }
  456. }
  457. } while (valueExsist);
  458. }
  459. finally
  460. {
  461. this.ResumeUpdates();
  462. }
  463. }
  464. /// <summary>
  465. /// Data bind Y values of the data points to the data source.
  466. /// Data source can be the Array, Collection, Ole(SQL)DataReader, DataView, DataSet, DataTable or DataRow.
  467. /// </summary>
  468. /// <param name="yValue">One or more enumerable objects with Y values.</param>
  469. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  470. Justification = "Y is a cartesian coordinate and well understood")]
  471. public void DataBindY(params IEnumerable[] yValue)
  472. {
  473. DataBindXY(null, yValue);
  474. }
  475. /// <summary>
  476. /// Data bind X and Y values of the data points to the data source.
  477. /// Data source can be the Array, Collection, Ole(SQL)DataReader, DataView, DataSet, DataTable or DataRow.
  478. /// </summary>
  479. /// <param name="xValue">Enumerable objects with X values.</param>
  480. /// <param name="yValues">One or more enumerable objects with Y values.</param>
  481. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  482. Justification = "X and Y are cartesian coordinates and well understood")]
  483. public void DataBindXY(IEnumerable xValue, params IEnumerable[] yValues)
  484. {
  485. // Y value must be provided
  486. if (yValues == null ||
  487. yValues.Length==1 && yValues[0]==null)
  488. throw new ArgumentNullException("yValues");
  489. if (yValues.GetLength(0) == 0)
  490. throw new ArgumentException(SR.ExceptionDataPointBindingYValueNotSpecified, "yValues");
  491. // Double check that a string object is not provided for data binding
  492. for(int i = 0; i < yValues.Length; i++)
  493. {
  494. if(yValues[i] is string)
  495. {
  496. throw (new ArgumentException(SR.ExceptionDataBindYValuesToString, "yValues"));
  497. }
  498. }
  499. // Check if number of Y values do not out of range
  500. if(yValues.GetLength(0) > series.YValuesPerPoint)
  501. {
  502. throw(new ArgumentOutOfRangeException("yValues", SR.ExceptionDataPointYValuesBindingCountMismatch( series.YValuesPerPoint.ToString(System.Globalization.CultureInfo.InvariantCulture) ) ) );
  503. }
  504. // Remove all existing data points
  505. this.Clear();
  506. // Reset X, Y enumerators
  507. IEnumerator xEnumerator = null;
  508. IEnumerator[] yEnumerator = new IEnumerator[yValues.GetLength(0)];
  509. if(xValue != null)
  510. {
  511. // Double check that a string object is not provided for data binding
  512. if(xValue is string)
  513. {
  514. throw (new ArgumentException(SR.ExceptionDataBindXValuesToString, "xValue"));
  515. }
  516. // Get and reset Y values enumerators
  517. xEnumerator = GetDataSourceEnumerator(xValue);
  518. if(xEnumerator.GetType() != typeof(System.Data.Common.DbEnumerator))
  519. {
  520. xEnumerator.Reset();
  521. }
  522. }
  523. for(int i = 0; i < yValues.Length; i++)
  524. {
  525. // Get and reset Y values enumerators
  526. yEnumerator[i] = GetDataSourceEnumerator(yValues[i]);
  527. if(yEnumerator[i].GetType() != typeof(System.Data.Common.DbEnumerator))
  528. {
  529. yEnumerator[i].Reset();
  530. }
  531. }
  532. // Add data points
  533. bool xValueExsist = false;
  534. bool yValueExsist = true;
  535. object[] yValuesObj = new object[series.YValuesPerPoint];
  536. object xValueObj = null;
  537. bool autoDetectType = true;
  538. SuspendUpdates();
  539. try
  540. {
  541. do
  542. {
  543. // Move to the next objects in the enumerations
  544. yValueExsist = true;
  545. for (int i = 0; i < yValues.Length; i++)
  546. {
  547. if (yValueExsist)
  548. {
  549. yValueExsist = yEnumerator[i].MoveNext();
  550. }
  551. }
  552. if (xValue != null)
  553. {
  554. xValueExsist = xEnumerator.MoveNext();
  555. if (yValueExsist && !xValueExsist)
  556. {
  557. throw (new ArgumentOutOfRangeException("xValue", SR.ExceptionDataPointInsertionXValuesQtyIsLessYValues));
  558. }
  559. }
  560. // Auto detect value(s) type
  561. if (autoDetectType)
  562. {
  563. autoDetectType = false;
  564. AutoDetectValuesType(this.series, xEnumerator, null, yEnumerator[0], null);
  565. }
  566. // Create and initialize data point
  567. if (xValueExsist || yValueExsist)
  568. {
  569. DataPoint newDataPoint = new DataPoint(series);
  570. bool emptyValues = false;
  571. // Set X to the value provided
  572. if (xValueExsist)
  573. {
  574. xValueObj = ConvertEnumerationItem(xEnumerator.Current, null);
  575. if (xValueObj is System.DBNull || xValueObj == null)
  576. {
  577. emptyValues = true;
  578. xValueObj = 0.0;
  579. }
  580. }
  581. // Set Y values
  582. for (int i = 0; i < yValues.Length; i++)
  583. {
  584. yValuesObj[i] = ConvertEnumerationItem(yEnumerator[i].Current, null);
  585. if (yValuesObj[i] is System.DBNull || yValuesObj[i] == null)
  586. {
  587. emptyValues = true;
  588. yValuesObj[i] = 0.0;
  589. }
  590. }
  591. // IsEmpty value was detected
  592. if (emptyValues)
  593. {
  594. if (xValueObj != null)
  595. {
  596. newDataPoint.SetValueXY(xValueObj, yValuesObj);
  597. }
  598. else
  599. {
  600. newDataPoint.SetValueXY(0, yValuesObj);
  601. }
  602. DataPointInit(ref newDataPoint);
  603. newDataPoint.IsEmpty = true;
  604. this.Add(newDataPoint);
  605. }
  606. else
  607. {
  608. if (xValueObj != null)
  609. {
  610. newDataPoint.SetValueXY(xValueObj, yValuesObj);
  611. }
  612. else
  613. {
  614. newDataPoint.SetValueXY(0, yValuesObj);
  615. }
  616. DataPointInit(ref newDataPoint);
  617. this.Add(newDataPoint);
  618. }
  619. }
  620. } while (xValueExsist || yValueExsist);
  621. }
  622. finally
  623. {
  624. this.ResumeUpdates();
  625. }
  626. }
  627. /// <summary>
  628. /// Data bind Y values of the data points to the data source.
  629. /// Data source can be the Array, Collection, Ole(SQL)DataReader, DataView, DataSet, DataTable or DataRow.
  630. /// </summary>
  631. /// <param name="yValue">Enumerable objects with Y values.</param>
  632. /// <param name="yFields">Name of the fields for Y values.</param>
  633. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  634. Justification = "X and Y are cartesian coordinates and well understood")]
  635. public void DataBindY(IEnumerable yValue, string yFields)
  636. {
  637. DataBindXY(null, null, yValue, yFields);
  638. }
  639. /// <summary>
  640. /// Data bind X and Y values of the data points to the data source.
  641. /// Data source can be the Array, Collection, Ole(SQL)DataReader, DataView, DataSet, DataTable or DataRow.
  642. /// </summary>
  643. /// <param name="xValue">Enumerable object with X values.</param>
  644. /// <param name="xField">Name of the field for X values.</param>
  645. /// <param name="yValue">Enumerable objects with Y values.</param>
  646. /// <param name="yFields">Comma separated names of the fields for Y values.</param>
  647. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  648. Justification = "X and Y are cartesian coordinates and well understood")]
  649. public void DataBindXY(IEnumerable xValue, string xField, IEnumerable yValue, string yFields)
  650. {
  651. // Check arguments
  652. if (xValue is string)
  653. throw new ArgumentException(SR.ExceptionDataBindXValuesToString, "xValue");
  654. if (yValue == null)
  655. throw new ArgumentNullException("yValue", SR.ExceptionDataPointInsertionYValueNotSpecified);
  656. if (yValue is string)
  657. throw new ArgumentException(SR.ExceptionDataBindYValuesToString, "yValue");
  658. if (yFields == null)
  659. throw new ArgumentOutOfRangeException("yFields", SR.ExceptionDataPointYValuesCountMismatch(series.YValuesPerPoint.ToString(System.Globalization.CultureInfo.InvariantCulture)));
  660. // Convert comma separated field names string to array of names
  661. string[] yFieldNames = yFields.Replace(",,", "\n").Split(',');;
  662. for(int index = 0; index < yFieldNames.Length; index++)
  663. {
  664. yFieldNames[index] = yFieldNames[index].Replace("\n", ",");
  665. }
  666. if (yFieldNames.GetLength(0) > series.YValuesPerPoint)
  667. throw new ArgumentOutOfRangeException("yFields", SR.ExceptionDataPointYValuesCountMismatch(series.YValuesPerPoint.ToString(System.Globalization.CultureInfo.InvariantCulture)));
  668. // Remove all existing data points
  669. this.Clear();
  670. // Reset X, Y enumerators
  671. IEnumerator xEnumerator = null;
  672. IEnumerator yEnumerator = GetDataSourceEnumerator(yValue);
  673. if(yEnumerator.GetType() != typeof(System.Data.Common.DbEnumerator))
  674. {
  675. yEnumerator.Reset();
  676. }
  677. if(xValue != null)
  678. {
  679. if(xValue != yValue)
  680. {
  681. xEnumerator = GetDataSourceEnumerator(xValue);
  682. if(xEnumerator.GetType() != typeof(System.Data.Common.DbEnumerator))
  683. {
  684. xEnumerator.Reset();
  685. }
  686. }
  687. else
  688. {
  689. xEnumerator = yEnumerator;
  690. }
  691. }
  692. // Add data points
  693. bool xValueExsist = false;
  694. bool yValueExsist = true;
  695. object[] yValuesObj = new object[yFieldNames.Length];
  696. object xValueObj = null;
  697. bool autoDetectType = true;
  698. this.SuspendUpdates();
  699. try
  700. {
  701. do
  702. {
  703. // Move to the next objects in the enumerations
  704. if (yValueExsist)
  705. {
  706. yValueExsist = yEnumerator.MoveNext();
  707. }
  708. if (xValue != null)
  709. {
  710. if (xValue != yValue)
  711. {
  712. xValueExsist = xEnumerator.MoveNext();
  713. if (yValueExsist && !xValueExsist)
  714. {
  715. throw (new ArgumentOutOfRangeException("xValue", SR.ExceptionDataPointInsertionXValuesQtyIsLessYValues));
  716. }
  717. }
  718. else
  719. {
  720. xValueExsist = yValueExsist;
  721. }
  722. }
  723. // Auto detect valu(s) type
  724. if (autoDetectType)
  725. {
  726. autoDetectType = false;
  727. AutoDetectValuesType(this.series, xEnumerator, xField, yEnumerator, yFieldNames[0]);
  728. }
  729. // Create and initialize data point
  730. if (xValueExsist || yValueExsist)
  731. {
  732. DataPoint newDataPoint = new DataPoint(series);
  733. bool emptyValues = false;
  734. // Set X to the value provided or use sequence numbers starting with 1
  735. if (xValueExsist)
  736. {
  737. xValueObj = ConvertEnumerationItem(xEnumerator.Current, xField);
  738. if (IsEmptyValue(xValueObj))
  739. {
  740. emptyValues = true;
  741. xValueObj = 0.0;
  742. }
  743. }
  744. if (yFieldNames.Length == 0)
  745. {
  746. yValuesObj[0] = ConvertEnumerationItem(yEnumerator.Current, null);
  747. if (IsEmptyValue(yValuesObj[0]))
  748. {
  749. emptyValues = true;
  750. yValuesObj[0] = 0.0;
  751. }
  752. }
  753. else
  754. {
  755. for (int i = 0; i < yFieldNames.Length; i++)
  756. {
  757. yValuesObj[i] = ConvertEnumerationItem(yEnumerator.Current, yFieldNames[i]);
  758. if (IsEmptyValue(yValuesObj[i]))
  759. {
  760. emptyValues = true;
  761. yValuesObj[i] = 0.0;
  762. }
  763. }
  764. }
  765. // IsEmpty value was detected
  766. if (emptyValues)
  767. {
  768. if (xValueObj != null)
  769. {
  770. newDataPoint.SetValueXY(xValueObj, yValuesObj);
  771. }
  772. else
  773. {
  774. newDataPoint.SetValueXY(0, yValuesObj);
  775. }
  776. DataPointInit(ref newDataPoint);
  777. newDataPoint.IsEmpty = true;
  778. this.Add(newDataPoint);
  779. }
  780. else
  781. {
  782. if (xValueObj != null)
  783. {
  784. newDataPoint.SetValueXY(xValueObj, yValuesObj);
  785. }
  786. else
  787. {
  788. newDataPoint.SetValueXY(0, yValuesObj);
  789. }
  790. DataPointInit(ref newDataPoint);
  791. this.Add(newDataPoint);
  792. }
  793. }
  794. } while (xValueExsist || yValueExsist);
  795. }
  796. finally
  797. {
  798. this.ResumeUpdates();
  799. }
  800. }
  801. /// <summary>
  802. /// Returns true if objet represents an empty value.
  803. /// </summary>
  804. /// <param name="val">Value to test.</param>
  805. /// <returns>True if empty.</returns>
  806. internal static bool IsEmptyValue(object val)
  807. {
  808. if(val is System.DBNull || val == null)
  809. {
  810. return true;
  811. }
  812. if(val is double && double.IsNaN((double)val))
  813. {
  814. return true;
  815. }
  816. if(val is Single && Single.IsNaN((Single)val))
  817. {
  818. return true;
  819. }
  820. return false;
  821. }
  822. /// <summary>
  823. /// Adds one data point with one Y value.
  824. /// </summary>
  825. /// <param name="yValue">Y value of the data point.</param>
  826. /// <returns>Index of newly added data point.</returns>
  827. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  828. Justification = "Y is a cartesian coordinate and well understood")]
  829. public int AddY(double yValue)
  830. {
  831. // Create new point object
  832. DataPoint newDataPoint = new DataPoint(series);
  833. newDataPoint.SetValueY(yValue);
  834. DataPointInit(ref newDataPoint);
  835. Add(newDataPoint);
  836. return Count - 1;
  837. }
  838. /// <summary>
  839. /// Adds one data point with one or more Y values.
  840. /// </summary>
  841. /// <param name="yValue">List of Y values of the data point.</param>
  842. /// <returns>Index of newly added data point.</returns>
  843. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  844. Justification = "Y is a cartesian coordinate and well understood")]
  845. public int AddY(params object[] yValue)
  846. {
  847. //Check arguments
  848. if (yValue == null ||
  849. yValue.Length==1 && yValue[0]==null)
  850. throw new ArgumentNullException("yValue");
  851. // Auto detect DateTime values type
  852. if(this.series.YValueType == ChartValueType.Auto &&
  853. yValue.Length > 0 &&
  854. yValue[0] != null)
  855. {
  856. if (yValue[0] is DateTime)
  857. {
  858. this.series.YValueType = ChartValueType.DateTime;
  859. this.series.autoYValueType = true;
  860. }
  861. else if (yValue[0] is DateTimeOffset)
  862. {
  863. this.series.YValueType = ChartValueType.DateTimeOffset;
  864. this.series.autoYValueType = true;
  865. }
  866. }
  867. // Create new point object
  868. DataPoint newDataPoint = new DataPoint(series);
  869. newDataPoint.SetValueY(yValue);
  870. DataPointInit(ref newDataPoint);
  871. Add(newDataPoint);
  872. return Count - 1;
  873. }
  874. /// <summary>
  875. /// Adds one data point with X value and one Y value.
  876. /// </summary>
  877. /// <param name="yValue">Y value of the data point.</param>
  878. /// <param name="xValue">X value of the data point.</param>
  879. /// <returns>Index of newly added data poit.</returns>
  880. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  881. Justification = "X and Y are cartesian coordinates and well understood")]
  882. public int AddXY(double xValue, double yValue)
  883. {
  884. // Create new point object
  885. DataPoint newDataPoint = new DataPoint(series);
  886. newDataPoint.SetValueXY(xValue, yValue);
  887. DataPointInit(ref newDataPoint);
  888. Add(newDataPoint);
  889. return Count - 1;
  890. }
  891. /// <summary>
  892. /// Adds one data point with X value and one or more Y values.
  893. /// </summary>
  894. /// <param name="yValue">List of Y values of the data point.</param>
  895. /// <param name="xValue">X value of the data point.</param>
  896. /// <returns>Index of newly added data poit.</returns>
  897. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  898. Justification = "X and Y are cartesian coordinates and well understood")]
  899. public int AddXY(object xValue, params object[] yValue)
  900. {
  901. // Auto detect DateTime and String values type
  902. if(this.series.XValueType == ChartValueType.Auto)
  903. {
  904. if(xValue is DateTime)
  905. {
  906. this.series.XValueType = ChartValueType.DateTime;
  907. }
  908. if(xValue is DateTimeOffset)
  909. {
  910. this.series.XValueType = ChartValueType.DateTimeOffset;
  911. }
  912. if(xValue is string)
  913. {
  914. this.series.XValueType = ChartValueType.String;
  915. }
  916. this.series.autoXValueType = true;
  917. }
  918. if(this.series.YValueType == ChartValueType.Auto &&
  919. yValue.Length > 0 &&
  920. yValue[0] != null)
  921. {
  922. if (yValue[0] is DateTime)
  923. {
  924. this.series.YValueType = ChartValueType.DateTime;
  925. this.series.autoYValueType = true;
  926. }
  927. else if (yValue[0] is DateTimeOffset)
  928. {
  929. this.series.YValueType = ChartValueType.DateTimeOffset;
  930. this.series.autoYValueType = true;
  931. }
  932. }
  933. // Create new point object
  934. DataPoint newDataPoint = new DataPoint(series);
  935. newDataPoint.SetValueXY(xValue, yValue);
  936. DataPointInit(ref newDataPoint);
  937. Add(newDataPoint);
  938. return Count - 1;
  939. }
  940. /// <summary>
  941. /// Insert one data point with X value and one or more Y values.
  942. /// </summary>
  943. /// <param name="index">Index after which to insert the data point.</param>
  944. /// <param name="xValue">X value of the data point.</param>
  945. /// <param name="yValue">List of Y values of the data point.</param>
  946. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  947. Justification = "X and Y are cartesian coordinates and well understood")]
  948. public void InsertXY(int index, object xValue, params object[] yValue)
  949. {
  950. DataPoint newDataPoint = new DataPoint(series);
  951. newDataPoint.SetValueXY(xValue, yValue);
  952. DataPointInit(ref newDataPoint);
  953. this.Insert(index, newDataPoint);
  954. }
  955. /// <summary>
  956. /// Insert one data point with one or more Y values.
  957. /// </summary>
  958. /// <param name="index">Index after which to insert the data point.</param>
  959. /// <param name="yValue">List of Y values of the data point.</param>
  960. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  961. Justification = "Y is a cartesian coordinate and well understood")]
  962. public void InsertY(int index, params object[] yValue)
  963. {
  964. DataPoint newDataPoint = new DataPoint(series);
  965. newDataPoint.SetValueY(yValue);
  966. DataPointInit(ref newDataPoint);
  967. this.Insert(index, newDataPoint);
  968. }
  969. /// <summary>
  970. /// Get data source enumerator object helper function.
  971. /// </summary>
  972. /// <param name="dataSource">Data source.</param>
  973. /// <returns>Returns data source enumerator.</returns>
  974. internal static IEnumerator GetDataSourceEnumerator(IEnumerable dataSource)
  975. {
  976. DataView dataView = dataSource as DataView;
  977. if(dataView != null)
  978. {
  979. return dataView.GetEnumerator();
  980. }
  981. DataSet dataSet = dataSource as DataSet;
  982. if(dataSet != null)
  983. {
  984. if(dataSet.Tables.Count > 0)
  985. {
  986. return dataSet.Tables[0].Rows.GetEnumerator();
  987. }
  988. }
  989. return dataSource.GetEnumerator();
  990. }
  991. /// <summary>
  992. /// Convert enumeration item object from DataRow and DataRowView
  993. /// to the actual value of specified column in row
  994. /// </summary>
  995. /// <param name="item">Enumeration item.</param>
  996. /// <param name="fieldName">Converted item.</param>
  997. /// <returns></returns>
  998. internal static object ConvertEnumerationItem(object item, string fieldName)
  999. {
  1000. object result = item;
  1001. // If original object is DataRow
  1002. DataRow dataRow = item as DataRow;
  1003. if(dataRow != null)
  1004. {
  1005. if(fieldName != null && fieldName.Length > 0)
  1006. {
  1007. // Check if specified column exist
  1008. bool failed = true;
  1009. if (dataRow.Table.Columns.Contains(fieldName))
  1010. {
  1011. result = dataRow[fieldName];
  1012. failed = false;
  1013. }
  1014. else
  1015. {
  1016. // Try to treat field name as column index number
  1017. int columnIndex;
  1018. failed = !int.TryParse(fieldName, NumberStyles.Any, CultureInfo.InvariantCulture, out columnIndex);
  1019. if (!failed && columnIndex < dataRow.Table.Columns.Count && columnIndex >= 0)
  1020. {
  1021. result = dataRow[columnIndex];
  1022. }
  1023. }
  1024. if(failed)
  1025. {
  1026. throw(new ArgumentException( SR.ExceptionColumnNameNotFound( fieldName) ) );
  1027. }
  1028. }
  1029. else
  1030. {
  1031. // Get first column value if name not specified
  1032. result = dataRow[0];
  1033. }
  1034. }
  1035. // If original object is DataRowView
  1036. DataRowView dataRowView = item as DataRowView;
  1037. if(dataRowView != null)
  1038. {
  1039. if(fieldName != null && fieldName.Length > 0)
  1040. {
  1041. // Check if specified column exist
  1042. bool failed = true;
  1043. if (dataRowView.DataView.Table.Columns.Contains(fieldName))
  1044. {
  1045. result = dataRowView[fieldName];
  1046. failed = false;
  1047. }
  1048. else
  1049. {
  1050. // Try to treat field name as column index number
  1051. int columnIndex;
  1052. failed = !int.TryParse(fieldName, NumberStyles.Any, CultureInfo.InvariantCulture, out columnIndex);
  1053. if (!failed && columnIndex < dataRowView.DataView.Table.Columns.Count && columnIndex >= 0)
  1054. {
  1055. result = dataRowView[columnIndex];
  1056. }
  1057. }
  1058. if(failed)
  1059. {
  1060. throw(new ArgumentException( SR.ExceptionColumnNameNotFound(fieldName)));
  1061. }
  1062. }
  1063. else
  1064. {
  1065. // Get first column value if name not specified
  1066. result = dataRowView[0];
  1067. }
  1068. }
  1069. // If original object is DbDataRecord
  1070. DbDataRecord dbDataRecord = item as DbDataRecord;
  1071. if(dbDataRecord != null)
  1072. {
  1073. if(fieldName != null && fieldName.Length > 0)
  1074. {
  1075. // Check if specified column exist
  1076. bool failed = true;
  1077. if(!Char.IsNumber(fieldName, 0))
  1078. {
  1079. try
  1080. {
  1081. result = dbDataRecord[fieldName];
  1082. failed = false;
  1083. }
  1084. catch (IndexOutOfRangeException)
  1085. {
  1086. failed = true;
  1087. }
  1088. }
  1089. if(failed)
  1090. {
  1091. // Try to treat field name as column index number
  1092. try
  1093. {
  1094. int columnIndex;
  1095. bool parseSucceed = int.TryParse(fieldName, NumberStyles.Any, CultureInfo.InvariantCulture, out columnIndex);
  1096. if (parseSucceed)
  1097. {
  1098. result = dbDataRecord[columnIndex];
  1099. failed = false;
  1100. }
  1101. else
  1102. {
  1103. failed = true;
  1104. }
  1105. }
  1106. catch (IndexOutOfRangeException)
  1107. {
  1108. failed = true;
  1109. }
  1110. }
  1111. if(failed)
  1112. {
  1113. throw(new ArgumentException( SR.ExceptionColumnNameNotFound(fieldName)));
  1114. }
  1115. }
  1116. else
  1117. {
  1118. // Get first column value if name not specified
  1119. result = dbDataRecord[0];
  1120. }
  1121. }
  1122. else
  1123. {
  1124. if (fieldName != null && fieldName.Length > 0)
  1125. {
  1126. PropertyDescriptor descriptor = TypeDescriptor.GetProperties(item).Find(fieldName, true);
  1127. if (descriptor != null)
  1128. {
  1129. result = descriptor.GetValue(item);
  1130. return result ?? null;
  1131. }
  1132. }
  1133. }
  1134. return result;
  1135. }
  1136. /// <summary>
  1137. /// Auto detects the X and Y(s) values type
  1138. /// </summary>
  1139. /// <param name="series">Series the values type is detected for.</param>
  1140. /// <param name="xEnumerator">X values enumerator.</param>
  1141. /// <param name="xField">X value field.</param>
  1142. /// <param name="yEnumerator">Y values enumerator.</param>
  1143. /// <param name="yField">Y value field.</param>
  1144. internal static void AutoDetectValuesType(
  1145. Series series,
  1146. IEnumerator xEnumerator,
  1147. string xField,
  1148. IEnumerator yEnumerator,
  1149. string yField)
  1150. {
  1151. if(series.XValueType == ChartValueType.Auto)
  1152. {
  1153. series.XValueType = GetValueType(xEnumerator, xField);
  1154. if(series.XValueType != ChartValueType.Auto)
  1155. {
  1156. series.autoXValueType = true;
  1157. }
  1158. }
  1159. if(series.YValueType == ChartValueType.Auto)
  1160. {
  1161. series.YValueType = GetValueType(yEnumerator, yField);
  1162. if(series.YValueType != ChartValueType.Auto)
  1163. {
  1164. series.autoYValueType = true;
  1165. }
  1166. }
  1167. }
  1168. /// <summary>
  1169. /// Return value type.
  1170. /// </summary>
  1171. /// <param name="enumerator">Values enumerator.</param>
  1172. /// <param name="field">Value field.</param>
  1173. private static ChartValueType GetValueType(IEnumerator enumerator, string field)
  1174. {
  1175. ChartValueType type = ChartValueType.Auto;
  1176. Type columnDataType = null;
  1177. // Check parameters
  1178. if(enumerator == null)
  1179. {
  1180. return type;
  1181. }
  1182. // Check if current enumeration element is available
  1183. try
  1184. {
  1185. if(enumerator.Current == null)
  1186. {
  1187. return type;
  1188. }
  1189. }
  1190. catch(InvalidOperationException)
  1191. {
  1192. return type;
  1193. }
  1194. // If original object is DataRow
  1195. if(enumerator.Current is DataRow)
  1196. {
  1197. if(field != null && field.Length > 0)
  1198. {
  1199. // Check if specified column exist
  1200. bool failed = true;
  1201. if(((DataRow)enumerator.Current).Table.Columns.Contains(field))
  1202. {
  1203. columnDataType = ((DataRow)enumerator.Current).Table.Columns[field].DataType;
  1204. failed = false;
  1205. }
  1206. // Try to treat field as column number
  1207. if (failed)
  1208. {
  1209. int columnIndex;
  1210. bool parseSucceed = int.TryParse(field, NumberStyles.Any, CultureInfo.InvariantCulture, out columnIndex);
  1211. if (parseSucceed)
  1212. {
  1213. columnDataType = ((DataRow)enumerator.Current).Table.Columns[columnIndex].DataType;
  1214. failed = false;
  1215. }
  1216. else
  1217. {
  1218. failed = true;
  1219. }
  1220. }
  1221. if(failed)
  1222. {
  1223. throw(new ArgumentException( SR.ExceptionColumnNameNotFound(field)));
  1224. }
  1225. }
  1226. else if(((DataRow)enumerator.Current).Table.Columns.Count > 0)
  1227. {
  1228. columnDataType = ((DataRow)enumerator.Current).Table.Columns[0].DataType;
  1229. }
  1230. }
  1231. // If original object is DataRowView
  1232. else if(enumerator.Current is DataRowView)
  1233. {
  1234. if(field != null && field.Length > 0)
  1235. {
  1236. // Check if specified column exist
  1237. bool failed = true;
  1238. if(((DataRowView)enumerator.Current).DataView.Table.Columns.Contains(field))
  1239. {
  1240. columnDataType = ((DataRowView)enumerator.Current).DataView.Table.Columns[field].DataType;
  1241. failed = false;
  1242. }
  1243. // Try to treat field as column number
  1244. if (failed)
  1245. {
  1246. int columnIndex;
  1247. bool parseSucceed = int.TryParse(field, NumberStyles.Any, CultureInfo.InvariantCulture, out columnIndex);
  1248. if (parseSucceed)
  1249. {
  1250. columnDataType = ((DataRowView)enumerator.Current).DataView.Table.Columns[columnIndex].DataType;
  1251. failed = false;
  1252. }
  1253. else
  1254. {
  1255. failed = true;
  1256. }
  1257. }
  1258. if(failed)
  1259. {
  1260. throw(new ArgumentException(SR.ExceptionColumnNameNotFound(field)));
  1261. }
  1262. }
  1263. else if(((DataRowView)enumerator.Current).DataView.Table.Columns.Count > 0)
  1264. {
  1265. columnDataType = ((DataRowView)enumerator.Current).DataView.Table.Columns[0].DataType;
  1266. }
  1267. }
  1268. // If original object is DbDataRecord
  1269. else if(enumerator.Current is DbDataRecord)
  1270. {
  1271. if(field != null && field.Length > 0)
  1272. {
  1273. bool failed = true;
  1274. int columnIndex = 0;
  1275. if(!Char.IsNumber(field, 0))
  1276. {
  1277. columnIndex = ((DbDataRecord)enumerator.Current).GetOrdinal(field);
  1278. columnDataType = ((DbDataRecord)enumerator.Current).GetFieldType(columnIndex);
  1279. failed = false;
  1280. }
  1281. // Try to treat field as column number
  1282. if (failed)
  1283. {
  1284. failed = !int.TryParse(field, NumberStyles.Any, CultureInfo.InvariantCulture, out columnIndex);
  1285. if (!failed)
  1286. {
  1287. columnDataType = ((DbDataRecord)enumerator.Current).GetFieldType(columnIndex);
  1288. }
  1289. }
  1290. if(failed)
  1291. {
  1292. throw(new ArgumentException(SR.ExceptionColumnNameNotFound(field)));
  1293. }
  1294. }
  1295. else if(((DbDataRecord)enumerator.Current).FieldCount > 0)
  1296. {
  1297. columnDataType = ((DbDataRecord)enumerator.Current).GetFieldType(0);
  1298. }
  1299. }
  1300. // Try detecting simple data types
  1301. else
  1302. {
  1303. if (field != null && field.Length > 0)
  1304. {
  1305. PropertyDescriptor descriptor = TypeDescriptor.GetProperties(enumerator.Current).Find(field, true);
  1306. if (descriptor != null)
  1307. {
  1308. columnDataType = descriptor.PropertyType;
  1309. }
  1310. }
  1311. if ( columnDataType == null )
  1312. {
  1313. columnDataType = enumerator.Current.GetType();
  1314. }
  1315. }
  1316. // Use data type
  1317. if(columnDataType != null)
  1318. {
  1319. if(columnDataType == typeof(DateTime))
  1320. type = ChartValueType.DateTime;
  1321. else if (columnDataType == typeof(DateTimeOffset))
  1322. type = ChartValueType.DateTimeOffset;
  1323. else if (columnDataType == typeof(TimeSpan))
  1324. type = ChartValueType.Time;
  1325. else if (columnDataType == typeof(Double))
  1326. type = ChartValueType.Double;
  1327. else if (columnDataType == typeof(Int32))
  1328. type = ChartValueType.Int32;
  1329. else if(columnDataType == typeof(Int64))
  1330. type = ChartValueType.Int64;
  1331. else if(columnDataType == typeof(Single))
  1332. type = ChartValueType.Single;
  1333. else if(columnDataType == typeof(String))
  1334. type = ChartValueType.String;
  1335. else if(columnDataType == typeof(UInt32))
  1336. type = ChartValueType.UInt32;
  1337. else if(columnDataType == typeof(UInt64))
  1338. type = ChartValueType.UInt64;
  1339. }
  1340. return type;
  1341. }
  1342. #endregion
  1343. #region DataPoint finding functions
  1344. /// <summary>
  1345. /// Find all the points that equal to the specified value starting from the specified index.
  1346. /// </summary>
  1347. /// <param name="valueToFind">Point value to find.</param>
  1348. /// <param name="useValue">Which point value to use (X, Y1, Y2,...).</param>
  1349. /// <param name="startIndex">Index of the point to start looking from.</param>
  1350. /// <returns>Enumerator of datapoints.</returns>
  1351. public IEnumerable<DataPoint> FindAllByValue(double valueToFind, string useValue, int startIndex)
  1352. {
  1353. // Loop through all points from specified index
  1354. for (int i = startIndex; i < this.Count; i++)
  1355. {
  1356. DataPoint point = this[i];
  1357. if (point.GetValueByName(useValue) == valueToFind)
  1358. {
  1359. yield return point;
  1360. }
  1361. }
  1362. }
  1363. /// <summary>
  1364. /// Find all the points that equal to the specified value.
  1365. /// </summary>
  1366. /// <param name="valueToFind">Point value to find.</param>
  1367. /// <param name="useValue">Which point value to use (X, Y1, Y2,...).</param>
  1368. /// <returns>Enumerator of datapoints.</returns>
  1369. public IEnumerable<DataPoint> FindAllByValue(double valueToFind, string useValue)
  1370. {
  1371. // Loop through all points from specified index
  1372. for (int i = 0; i < this.Count; i++)
  1373. {
  1374. DataPoint point = this[i];
  1375. if (point.GetValueByName(useValue) == valueToFind)
  1376. {
  1377. yield return point;
  1378. }
  1379. }
  1380. }
  1381. /// <summary>
  1382. /// Find all the points that equal to the specified value.
  1383. /// </summary>
  1384. /// <param name="valueToFind">Point value to find.</param>
  1385. /// <returns>Enumerator of datapoints.</returns>
  1386. public IEnumerable<DataPoint> FindAllByValue(double valueToFind)
  1387. {
  1388. return FindAllByValue(valueToFind, "Y");
  1389. }
  1390. /// <summary>
  1391. /// Find the first point that equals to the specified value starting from the specified index.
  1392. /// </summary>
  1393. /// <param name="valueToFind">Point value to find.</param>
  1394. /// <param name="useValue">Which point value to use (X, Y1, Y2,...).</param>
  1395. /// <param name="startIndex">Index of the point to start looking from.</param>
  1396. /// <returns>Datapoint which matches the value. Null if there is no match.</returns>
  1397. public DataPoint FindByValue(double valueToFind, string useValue, int startIndex)
  1398. {
  1399. //Check arguments
  1400. if (useValue == null)
  1401. throw new ArgumentNullException("useValue");
  1402. if (startIndex < 0 || startIndex >= this.Count)
  1403. throw new ArgumentOutOfRangeException("startIndex");
  1404. // Loop through all points from specified index
  1405. for (int i = startIndex; i < this.Count; i++)
  1406. {
  1407. DataPoint point = this[i];
  1408. if (point.GetValueByName(useValue) == valueToFind)
  1409. {
  1410. return point;
  1411. }
  1412. }
  1413. // Nothing was found
  1414. return null;
  1415. }
  1416. /// <summary>
  1417. /// Find the first point that equals to the specified value.
  1418. /// </summary>
  1419. /// <param name="valueToFind">Point value to find.</param>
  1420. /// <param name="useValue">Which point value to use (X, Y1, Y2,...).</param>
  1421. /// <returns>Datapoint which matches the value. Null if there is no match.</returns>
  1422. public DataPoint FindByValue(double valueToFind, string useValue)
  1423. {
  1424. return FindByValue(valueToFind, useValue, 0);
  1425. }
  1426. /// <summary>
  1427. /// Find the first point that equals to the specified value.
  1428. /// </summary>
  1429. /// <param name="valueToFind">Point value to find.</param>
  1430. /// <returns>Datapoint which matches the value. Null if there is no match.</returns>
  1431. public DataPoint FindByValue(double valueToFind)
  1432. {
  1433. return FindByValue(valueToFind, "Y");
  1434. }
  1435. /// <summary>
  1436. /// Find point with the maximum value starting from specified index.
  1437. /// </summary>
  1438. /// <param name="useValue">Which point value to use (X, Y1, Y2,...).</param>
  1439. /// <param name="startIndex">Index of the point to start looking from.</param>
  1440. /// <returns>Datapoint with the maximum value.</returns>
  1441. public DataPoint FindMaxByValue(string useValue, int startIndex)
  1442. {
  1443. //Check arguments
  1444. if (useValue == null)
  1445. throw new ArgumentNullException("useValue");
  1446. if (startIndex < 0 || startIndex >= this.Count)
  1447. throw new ArgumentOutOfRangeException("startIndex");
  1448. bool isYValue = useValue.StartsWith("Y", StringComparison.OrdinalIgnoreCase);
  1449. double maxValue = double.MinValue;
  1450. DataPoint maxPoint = null;
  1451. for (int i = startIndex; i < this.Count; i++)
  1452. {
  1453. DataPoint point = this[i];
  1454. // Skip empty points when searching for the Y values
  1455. if (point.IsEmpty && isYValue)
  1456. continue;
  1457. double pointValue = point.GetValueByName(useValue);
  1458. if (maxValue < pointValue)
  1459. {
  1460. maxValue = pointValue;
  1461. maxPoint = point;
  1462. }
  1463. }
  1464. return maxPoint;
  1465. }
  1466. /// <summary>
  1467. /// Find point with the maximum value.
  1468. /// </summary>
  1469. /// <param name="useValue">Which point value to use (X, Y1, Y2,...).</param>
  1470. /// <returns>Datapoint with the maximum value.</returns>
  1471. public DataPoint FindMaxByValue(string useValue)
  1472. {
  1473. return FindMaxByValue(useValue, 0);
  1474. }
  1475. /// <summary>
  1476. /// Find data point with the maximum value.
  1477. /// </summary>
  1478. /// <returns>Datapoint with the maximum value.</returns>
  1479. public DataPoint FindMaxByValue()
  1480. {
  1481. return FindMaxByValue("Y");
  1482. }
  1483. /// <summary>
  1484. /// Find point with the Min value starting from specified index.
  1485. /// </summary>
  1486. /// <param name="useValue">Which point value to use (X, Y1, Y2,...).</param>
  1487. /// <param name="startIndex">Index of the point to start looking from.</param>
  1488. /// <returns>Datapoint with the Min value.</returns>
  1489. public DataPoint FindMinByValue(string useValue, int startIndex)
  1490. {
  1491. if (useValue == null)
  1492. throw new ArgumentNullException("useValue");
  1493. if (startIndex < 0 || startIndex >= this.Count)
  1494. throw new ArgumentOutOfRangeException("startIndex");
  1495. bool isYValue = useValue.StartsWith("Y", StringComparison.OrdinalIgnoreCase);
  1496. double minValue = double.MaxValue;
  1497. DataPoint minPoint = null;
  1498. for (int i = startIndex; i < this.Count; i++)
  1499. {
  1500. DataPoint point = this[i];
  1501. // Skip empty points when searching for the Y values
  1502. if (point.IsEmpty && isYValue)
  1503. continue;
  1504. double pointValue = point.GetValueByName(useValue);
  1505. if (minValue > pointValue)
  1506. {
  1507. minValue = pointValue;
  1508. minPoint = point;
  1509. }
  1510. }
  1511. return minPoint;
  1512. }
  1513. /// <summary>
  1514. /// Find point with the Min value.
  1515. /// </summary>
  1516. /// <param name="useValue">Which point value to use (X, Y1, Y2,...).</param>
  1517. /// <returns>Datapoint with the Min value.</returns>
  1518. public DataPoint FindMinByValue(string useValue)
  1519. {
  1520. return FindMinByValue(useValue, 0);
  1521. }
  1522. /// <summary>
  1523. /// Find point with the Min value
  1524. /// </summary>
  1525. /// <returns>Datapoint with the Min value.</returns>
  1526. public DataPoint FindMinByValue()
  1527. {
  1528. return FindMinByValue("Y");
  1529. }
  1530. #endregion
  1531. #region Collection<T> overrides
  1532. /// <summary>
  1533. /// Initializes the specified item.
  1534. /// </summary>
  1535. /// <param name="item">The item.</param>
  1536. internal override void Initialize(DataPoint item)
  1537. {
  1538. DataPointInit(ref item);
  1539. base.Initialize(item);
  1540. }
  1541. /// <summary>
  1542. /// Removes all elements from the <see cref="T:System.Collections.ObjectModel.Collection`1"/>.
  1543. /// </summary>
  1544. protected override void ClearItems()
  1545. {
  1546. // Refresh Minimum and Maximum from data
  1547. // after recalc and set data
  1548. if (Common != null && Common.ChartPicture != null)
  1549. {
  1550. Common.ChartPicture.ResetMinMaxFromData();
  1551. }
  1552. base.ClearItems();
  1553. }
  1554. #endregion
  1555. }
  1556. /// <summary>
  1557. /// Stores values and properties of a DataPoint of a Series.
  1558. /// </summary>
  1559. [
  1560. SRDescription("DescriptionAttributeDataPoint_DataPoint"),
  1561. DefaultProperty("YValues"),
  1562. TypeConverter(typeof(DataPointConverter))
  1563. ]
  1564. public class DataPoint : DataPointCustomProperties
  1565. {
  1566. #region Fields
  1567. // Point X value
  1568. private double _xValue;
  1569. // Point Y values
  1570. private double[] _yValue = new double[1];
  1571. // Pre calculated (during painting) relative position of data point
  1572. internal PointF positionRel = PointF.Empty;
  1573. // VSTS:199794 - Accessibility needs the last rendered label content to be exposed.
  1574. // The current label content evaluation is scattered over different chart types and cannot be isolated without risk of regression.
  1575. // This variable will cache the label content taken just before drawing.
  1576. internal string _lastLabelText = String.Empty;
  1577. #endregion
  1578. #region Constructors
  1579. /// <summary>
  1580. /// DataPoint object constructor.
  1581. /// </summary>
  1582. public DataPoint() : base(null, true)
  1583. {
  1584. _yValue = new double[1];
  1585. }
  1586. /// <summary>
  1587. /// DataPoint object constructor.
  1588. /// </summary>
  1589. /// <param name="series">series object, which the DataPoint belongs to.</param>
  1590. public DataPoint(Series series) : base(series, true)
  1591. {
  1592. // Create Y value(s) array
  1593. _yValue = new double[series.YValuesPerPoint];
  1594. _xValue = 0;
  1595. }
  1596. /// <summary>
  1597. /// DataPoint object constructor.
  1598. /// </summary>
  1599. /// <param name="xValue">X value.</param>
  1600. /// <param name="yValue">Y value.</param>
  1601. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  1602. Justification = "X and Y are cartesian coordinates and well understood")]
  1603. public DataPoint(double xValue, double yValue)
  1604. : base(null, true)
  1605. {
  1606. // Set Y value
  1607. this._yValue = new double[1];
  1608. this._yValue[0] = yValue;
  1609. // Set X value
  1610. this._xValue = xValue;
  1611. }
  1612. /// <summary>
  1613. /// DataPoint object constructor.
  1614. /// </summary>
  1615. /// <param name="xValue">X value.</param>
  1616. /// <param name="yValues">Array of Y values.</param>
  1617. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  1618. Justification = "X and Y are cartesian coordinates and well understood")]
  1619. public DataPoint(double xValue, double[] yValues)
  1620. : base(null, true)
  1621. {
  1622. // Set Y value
  1623. this._yValue = yValues;
  1624. // Set X value
  1625. this._xValue = xValue;
  1626. }
  1627. /// <summary>
  1628. /// DataPoint object constructor.
  1629. /// </summary>
  1630. /// <remarks>
  1631. /// This method is only used during the Windows Forms serialization of the chart.
  1632. /// </remarks>
  1633. /// <param name="xValue">X value.</param>
  1634. /// <param name="yValues">String of comma separated Y values.</param>
  1635. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  1636. Justification = "X and Y are cartesian coordinates and well understood")]
  1637. [EditorBrowsable(EditorBrowsableState.Never)]
  1638. public DataPoint(double xValue, string yValues)
  1639. : base(null, true)
  1640. {
  1641. string[] values = yValues.Split(',');
  1642. // Create Y value(s) array
  1643. _yValue = new double[values.Length];
  1644. for (int index = 0; index < values.Length; index++)
  1645. {
  1646. _yValue[index] = CommonElements.ParseDouble(values[index], true);
  1647. }
  1648. // Set X value
  1649. this._xValue = xValue;
  1650. }
  1651. #endregion
  1652. #region Data point methods
  1653. /// <summary>
  1654. /// Sets the specified data point attribute to the specified value.
  1655. /// </summary>
  1656. /// <param name="obj">Attribute value.</param>
  1657. /// <param name="propertyName">Attribute name.</param>
  1658. /// <param name="format">Value format.</param>
  1659. internal void SetPointCustomProperty(
  1660. object obj,
  1661. string propertyName,
  1662. string format)
  1663. {
  1664. // Convert value to string
  1665. string stringValue = obj as string;
  1666. if(stringValue == null)
  1667. {
  1668. double doubleObj = double.NaN;
  1669. ChartValueType valueType = ChartValueType.Auto;
  1670. if(obj is DateTime)
  1671. {
  1672. doubleObj = ((DateTime)obj).ToOADate();
  1673. valueType = ChartValueType.Date;
  1674. }
  1675. else
  1676. {
  1677. doubleObj = this.ConvertValue(obj);
  1678. }
  1679. // Try converting to string
  1680. if( !double.IsNaN(doubleObj) )
  1681. {
  1682. try
  1683. {
  1684. stringValue = ValueConverter.FormatValue(
  1685. this.Chart,
  1686. this,
  1687. this.Tag,
  1688. doubleObj,
  1689. format,
  1690. valueType,
  1691. ChartElementType.DataPoint);
  1692. }
  1693. catch(FormatException)
  1694. {
  1695. // Use basic string converter
  1696. stringValue = obj.ToString();
  1697. }
  1698. }
  1699. else
  1700. {
  1701. // Use basic string converter
  1702. stringValue = obj.ToString();
  1703. }
  1704. }
  1705. // Assign data point attribute by name
  1706. if(stringValue.Length > 0)
  1707. {
  1708. if(String.Compare(propertyName, "AxisLabel", StringComparison.OrdinalIgnoreCase) == 0)
  1709. {
  1710. this.AxisLabel = stringValue;
  1711. }
  1712. else if (String.Compare(propertyName, "Tooltip", StringComparison.OrdinalIgnoreCase) == 0)
  1713. {
  1714. this.ToolTip = stringValue;
  1715. }
  1716. else if (String.Compare(propertyName, "Label", StringComparison.OrdinalIgnoreCase) == 0)
  1717. {
  1718. this.Label = stringValue;
  1719. }
  1720. else if (String.Compare(propertyName, "LegendTooltip", StringComparison.OrdinalIgnoreCase) == 0)
  1721. {
  1722. this.LegendToolTip = stringValue;
  1723. }
  1724. else if (String.Compare(propertyName, "LegendText", StringComparison.OrdinalIgnoreCase) == 0)
  1725. {
  1726. this.LegendText = stringValue;
  1727. }
  1728. else if (String.Compare(propertyName, "LabelToolTip", StringComparison.OrdinalIgnoreCase) == 0)
  1729. {
  1730. this.LabelToolTip = stringValue;
  1731. }
  1732. else
  1733. {
  1734. this[propertyName] = stringValue;
  1735. }
  1736. }
  1737. }
  1738. /// <summary>
  1739. /// Converts object to double.
  1740. /// </summary>
  1741. /// <param name="value">Object to convert.</param>
  1742. /// <returns>Double value.</returns>
  1743. private double ConvertValue(object value)
  1744. {
  1745. if(value == null)
  1746. {
  1747. return 0;
  1748. }
  1749. if(value is Double)
  1750. {
  1751. return (double)value;
  1752. }
  1753. else if(value is Single)
  1754. {
  1755. return (double)((float)value);
  1756. }
  1757. else if(value is Decimal)
  1758. {
  1759. return (double)((Decimal)value);
  1760. }
  1761. else if(value is Int32)
  1762. {
  1763. return (double)((Int32)value);
  1764. }
  1765. else if(value is UInt32)
  1766. {
  1767. return (double)((UInt32)value);
  1768. }
  1769. else if(value is Int64)
  1770. {
  1771. return (double)((Int64)value);
  1772. }
  1773. else if(value is UInt64)
  1774. {
  1775. return (double)((UInt64)value);
  1776. }
  1777. else if(value is Byte)
  1778. {
  1779. return (double)((Byte)value);
  1780. }
  1781. else if(value is SByte)
  1782. {
  1783. return (double)((SByte)value);
  1784. }
  1785. else if(value is Boolean)
  1786. {
  1787. return ((Boolean)value) ? 1.0 : 0.0;
  1788. }
  1789. else
  1790. {
  1791. string stringValue = "";
  1792. stringValue = value.ToString();
  1793. return CommonElements.ParseDouble(stringValue);
  1794. }
  1795. }
  1796. /// <summary>
  1797. /// Set X value and one or more Y values of the data point.
  1798. /// </summary>
  1799. /// <param name="xValue">X value of the data point.</param>
  1800. /// <param name="yValue">List of Y values of the data point.</param>
  1801. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  1802. Justification = "X and Y are cartesian coordinates and well understood")]
  1803. public void SetValueXY(object xValue, params object[] yValue)
  1804. {
  1805. // Check arguments
  1806. if (xValue == null)
  1807. throw new ArgumentNullException("xValue");
  1808. // Set Y value first
  1809. SetValueY(yValue);
  1810. // Check if parameters type matches with series type
  1811. Type paramType = xValue.GetType();
  1812. if(base.series != null)
  1813. {
  1814. base.series.CheckSupportedTypes(paramType);
  1815. }
  1816. // Save value in the array
  1817. if(paramType == typeof(String))
  1818. {
  1819. AxisLabel = (string)xValue;
  1820. }
  1821. else if(paramType == typeof(DateTime))
  1822. {
  1823. this._xValue = ((DateTime)xValue).ToOADate();
  1824. }
  1825. else
  1826. {
  1827. this._xValue = ConvertValue(xValue);
  1828. }
  1829. // Get Date or Time if required
  1830. if(base.series != null && xValue is DateTime)
  1831. {
  1832. if(base.series.XValueType == ChartValueType.Date)
  1833. {
  1834. DateTime time = new DateTime(
  1835. ((DateTime)xValue).Year,
  1836. ((DateTime)xValue).Month,
  1837. ((DateTime)xValue).Day,
  1838. 0,
  1839. 0,
  1840. 0,
  1841. 0);
  1842. this._xValue = time.ToOADate();
  1843. }
  1844. else if(base.series.XValueType == ChartValueType.Time)
  1845. {
  1846. DateTime time = new DateTime(
  1847. 1899,
  1848. 12,
  1849. 30,
  1850. ((DateTime)xValue).Hour,
  1851. ((DateTime)xValue).Minute,
  1852. ((DateTime)xValue).Second,
  1853. ((DateTime)xValue).Millisecond);
  1854. this._xValue = time.ToOADate();
  1855. }
  1856. }
  1857. // Check if one of Y values are not avilable
  1858. bool empty = false;
  1859. foreach(double d in this._yValue)
  1860. {
  1861. if(double.IsNaN(d))
  1862. {
  1863. empty = true;
  1864. break;
  1865. }
  1866. }
  1867. // Set point empty flag and values to zero
  1868. if(empty)
  1869. {
  1870. this.IsEmpty = true;
  1871. for(int valueIndex = 0; valueIndex < this._yValue.Length; valueIndex++)
  1872. {
  1873. this._yValue[valueIndex] = 0.0;
  1874. }
  1875. }
  1876. }
  1877. /// <summary>
  1878. /// Set one or more Y values of the data point.
  1879. /// </summary>
  1880. /// <param name="yValue">List of Y values of the data point.</param>
  1881. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
  1882. Justification = "Y is a cartesian coordinate and well understood")]
  1883. public void SetValueY(params object[] yValue)
  1884. {
  1885. // Check arguments
  1886. if (yValue == null)
  1887. throw new ArgumentNullException("yValue");
  1888. // Check number of parameters. Should be more than 0 and
  1889. if(yValue.Length == 0 || (base.series != null && yValue.Length > base.series.YValuesPerPoint))
  1890. throw(new ArgumentOutOfRangeException("yValue", SR.ExceptionDataPointYValuesSettingCountMismatch(base.series.YValuesPerPoint.ToString(System.Globalization.CultureInfo.InvariantCulture))));
  1891. // Check if there is a Null Y value
  1892. for( int i = 0 ; i < yValue.Length ; i++ )
  1893. {
  1894. if(yValue[i] == null || yValue[i] is System.DBNull)
  1895. {
  1896. yValue[i] = 0.0;
  1897. if(i == 0)
  1898. {
  1899. this.IsEmpty = true;
  1900. }
  1901. }
  1902. }
  1903. // Check if parameters type matches with series type
  1904. Type paramType = yValue[0].GetType();
  1905. if(base.series != null)
  1906. {
  1907. base.series.CheckSupportedTypes(paramType);
  1908. }
  1909. // Make sure the Y values array is big enough
  1910. if (this._yValue.Length < yValue.Length)
  1911. {
  1912. this._yValue = new double[yValue.Length];
  1913. }
  1914. // Save value in the array
  1915. if(paramType == typeof(String))
  1916. {
  1917. try
  1918. {
  1919. for (int i = 0; i < yValue.Length; i++)
  1920. {
  1921. this._yValue[i] = CommonElements.ParseDouble((string)yValue[i]);
  1922. }
  1923. }
  1924. catch
  1925. {
  1926. // Get reference to the chart object
  1927. if (Common!=null && Common.ChartPicture!=null && Common.ChartPicture.SuppressExceptions)
  1928. {
  1929. this.IsEmpty = true;
  1930. for (int i = 0; i < yValue.Length; i++)
  1931. {
  1932. yValue[i] = 0.0;
  1933. }
  1934. }
  1935. else
  1936. {
  1937. throw (new ArgumentException( SR.ExceptionDataPointYValueStringFormat));
  1938. }
  1939. }
  1940. }
  1941. else if(paramType == typeof(DateTime))
  1942. {
  1943. for( int i = 0 ; i < yValue.Length ; i++ )
  1944. {
  1945. if(yValue[i] == null ||
  1946. (yValue[i] is double && ((double)yValue[i]) == 0.0) )
  1947. {
  1948. this._yValue[i] = DateTime.Now.ToOADate();
  1949. }
  1950. else
  1951. {
  1952. this._yValue[i] = ((DateTime)yValue[i]).ToOADate();
  1953. }
  1954. }
  1955. }
  1956. else
  1957. {
  1958. for( int i = 0 ; i < yValue.Length ; i++ )
  1959. {
  1960. this._yValue[i] = ConvertValue(yValue[i]);
  1961. }
  1962. }
  1963. // Get Date or Time if required
  1964. if(base.series != null)
  1965. {
  1966. for( int i = 0 ; i < yValue.Length ; i++ )
  1967. {
  1968. if(yValue[i] == null ||
  1969. (yValue[i] is double && ((double)yValue[i]) == 0.0) )
  1970. {
  1971. if(base.series.YValueType == ChartValueType.Date)
  1972. {
  1973. this._yValue[i] = Math.Floor(this._yValue[i]);
  1974. }
  1975. else if(base.series.YValueType == ChartValueType.Time)
  1976. {
  1977. this._yValue[i] = this._xValue - Math.Floor(this._yValue[i]);
  1978. }
  1979. }
  1980. else
  1981. {
  1982. if(base.series.YValueType == ChartValueType.Date)
  1983. {
  1984. DateTime yDate;
  1985. if (yValue[i] is DateTime)
  1986. yDate = (DateTime)yValue[i];
  1987. else if (yValue[i] is Double)
  1988. yDate = DateTime.FromOADate((Double)yValue[i]);
  1989. else
  1990. yDate = Convert.ToDateTime(yValue[i], CultureInfo.InvariantCulture); //This will throw an exception in case when the yValue type is not compatible with the DateTime
  1991. DateTime date = new DateTime(
  1992. yDate.Year,
  1993. yDate.Month,
  1994. yDate.Day,
  1995. 0,
  1996. 0,
  1997. 0,
  1998. 0);
  1999. this._yValue[i] = date.ToOADate();
  2000. }
  2001. else if (base.series.YValueType == ChartValueType.Time)
  2002. {
  2003. DateTime yTime;
  2004. if (yValue[i] is DateTime)
  2005. yTime = (DateTime)yValue[i];
  2006. if (yValue[i] is Double)
  2007. yTime = DateTime.FromOADate((Double)yValue[i]);
  2008. else
  2009. yTime = Convert.ToDateTime(yValue[i], CultureInfo.InvariantCulture); //This will throw an exception in case when the yValue type is not compatible with the DateTime
  2010. DateTime time = new DateTime(
  2011. 1899,
  2012. 12,
  2013. 30,
  2014. yTime.Hour,
  2015. yTime.Minute,
  2016. yTime.Second,
  2017. yTime.Millisecond);
  2018. this._yValue[i] = time.ToOADate();
  2019. }
  2020. }
  2021. }
  2022. }
  2023. }
  2024. /// <summary>
  2025. /// Creates an exact copy of this DataPoint object.
  2026. /// </summary>
  2027. /// <returns>An exact copy of this DataPoint object.</returns>
  2028. public DataPoint Clone()
  2029. {
  2030. // Create new data point
  2031. DataPoint clonePoint = new DataPoint();
  2032. // Reset series pointer
  2033. clonePoint.series = null;
  2034. clonePoint.pointCustomProperties = this.pointCustomProperties;
  2035. // Copy values
  2036. clonePoint._xValue = this.XValue;
  2037. clonePoint._yValue = new double[this._yValue.Length];
  2038. this._yValue.CopyTo(clonePoint._yValue, 0);
  2039. clonePoint.tempColorIsSet = this.tempColorIsSet;
  2040. clonePoint.isEmptyPoint = this.isEmptyPoint;
  2041. // Copy properties
  2042. foreach(object key in this.properties.Keys)
  2043. {
  2044. clonePoint.properties.Add(key, this.properties[key]);
  2045. }
  2046. return clonePoint;
  2047. }
  2048. /// <summary>
  2049. /// Resize Y values array.
  2050. /// </summary>
  2051. /// <param name="newSize">New number of Y values in array.</param>
  2052. internal void ResizeYValueArray(int newSize)
  2053. {
  2054. // Create new array
  2055. double[] newArray = new Double[newSize];
  2056. // Copy elements
  2057. if(_yValue != null)
  2058. {
  2059. for(int i = 0; i < ((_yValue.Length < newSize) ? _yValue.Length : newSize); i++)
  2060. {
  2061. newArray[i] = _yValue[i];
  2062. }
  2063. }
  2064. _yValue = newArray;
  2065. }
  2066. /// <summary>
  2067. /// Helper function, which returns point value by it's name.
  2068. /// </summary>
  2069. /// <param name="valueName">Point value names. X, Y, Y2,...</param>
  2070. /// <returns>Point value.</returns>
  2071. public double GetValueByName(string valueName)
  2072. {
  2073. // Check arguments
  2074. if (valueName == null)
  2075. throw new ArgumentNullException("valueName");
  2076. valueName = valueName.ToUpper(System.Globalization.CultureInfo.InvariantCulture);
  2077. if(String.Compare(valueName, "X", StringComparison.Ordinal) == 0)
  2078. {
  2079. return this.XValue;
  2080. }
  2081. else if (valueName.StartsWith("Y", StringComparison.Ordinal))
  2082. {
  2083. if(valueName.Length == 1)
  2084. {
  2085. return this.YValues[0];
  2086. }
  2087. else
  2088. {
  2089. int yIndex = 0;
  2090. try
  2091. {
  2092. yIndex = Int32.Parse(valueName.Substring(1), System.Globalization.CultureInfo.InvariantCulture) - 1;
  2093. }
  2094. catch(System.Exception)
  2095. {
  2096. throw(new ArgumentException( SR.ExceptionDataPointValueNameInvalid, "valueName"));
  2097. }
  2098. if(yIndex < 0)
  2099. {
  2100. throw(new ArgumentException( SR.ExceptionDataPointValueNameYIndexIsNotPositive, "valueName"));
  2101. }
  2102. if(yIndex >= this.YValues.Length)
  2103. {
  2104. throw(new ArgumentException( SR.ExceptionDataPointValueNameYIndexOutOfRange, "valueName"));
  2105. }
  2106. return this.YValues[yIndex];
  2107. }
  2108. }
  2109. else
  2110. {
  2111. throw(new ArgumentException( SR.ExceptionDataPointValueNameInvalid, "valueName"));
  2112. }
  2113. }
  2114. /// <summary>
  2115. /// Replaces predefined keyword inside the string with their values.
  2116. /// </summary>
  2117. /// <param name="strOriginal">Original string with keywords.</param>
  2118. /// <returns>Modified string.</returns>
  2119. internal override string ReplaceKeywords(string strOriginal)
  2120. {
  2121. // Nothing to process
  2122. if(strOriginal == null || strOriginal.Length == 0)
  2123. return strOriginal;
  2124. // Replace all "\n" strings with '\n' character
  2125. string result = strOriginal;
  2126. result = result.Replace("\\n", "\n");
  2127. // #LABEL - point label
  2128. result = result.Replace(KeywordName.Label, this.Label);
  2129. // #LEGENDTEXT - series name
  2130. result = result.Replace(KeywordName.LegendText, this.LegendText);
  2131. // #AXISLABEL - series name
  2132. result = result.Replace(KeywordName.AxisLabel, this.AxisLabel);
  2133. // #CUSTOMPROPERTY - one of the custom properties by name
  2134. result = DataPoint.ReplaceCustomPropertyKeyword(result, this);
  2135. if(this.series != null)
  2136. {
  2137. // #INDEX - point index
  2138. result = result.Replace(KeywordName.Index, this.series.Points.IndexOf(this).ToString(System.Globalization.CultureInfo.InvariantCulture));
  2139. // Replace series keywords
  2140. result = this.series.ReplaceKeywords(result);
  2141. // #PERCENT - percentage of Y value from total
  2142. result = this.series.ReplaceOneKeyword(
  2143. this.Chart,
  2144. this,
  2145. this.Tag,
  2146. ChartElementType.DataPoint,
  2147. result,
  2148. KeywordName.Percent,
  2149. (this.YValues[0]/(this.series.GetTotalYValue())),
  2150. ChartValueType.Double,
  2151. "P");
  2152. // #VAL[X] - point value X, Y, Y2, ...
  2153. if(this.series.XValueType == ChartValueType.String)
  2154. {
  2155. result = result.Replace(KeywordName.ValX, this.AxisLabel);
  2156. }
  2157. else
  2158. {
  2159. result = this.series.ReplaceOneKeyword(
  2160. this.Chart,
  2161. this,
  2162. this.Tag,
  2163. ChartElementType.DataPoint,
  2164. result,
  2165. KeywordName.ValX,
  2166. this.XValue,
  2167. this.series.XValueType,
  2168. "");
  2169. }
  2170. // remove keywords #VAL? for unexisted Y value indices
  2171. for (int index = this.YValues.Length; index <= 7; index++)
  2172. {
  2173. result = this.RemoveOneKeyword(result, KeywordName.ValY + index + 1, SR.FormatErrorString);
  2174. }
  2175. for(int index = 1; index <= this.YValues.Length; index++)
  2176. {
  2177. result = this.series.ReplaceOneKeyword(
  2178. this.Chart,
  2179. this,
  2180. this.Tag,
  2181. ChartElementType.DataPoint,
  2182. result,
  2183. KeywordName.ValY + index,
  2184. this.YValues[index - 1],
  2185. this.series.YValueType,
  2186. "");
  2187. }
  2188. result = this.series.ReplaceOneKeyword(
  2189. Chart,
  2190. this,
  2191. this.Tag,
  2192. ChartElementType.DataPoint,
  2193. result,
  2194. KeywordName.ValY,
  2195. this.YValues[0],
  2196. this.series.YValueType,
  2197. "");
  2198. result = this.series.ReplaceOneKeyword(
  2199. Chart,
  2200. this,
  2201. this.Tag,
  2202. ChartElementType.DataPoint,
  2203. result,
  2204. KeywordName.Val,
  2205. this.YValues[0],
  2206. this.series.YValueType,
  2207. "");
  2208. }
  2209. return result;
  2210. }
  2211. /// <summary>
  2212. /// Removes one keyword from format string.
  2213. /// </summary>
  2214. /// <param name="strOriginal">Original format string</param>
  2215. /// <param name="keyword">The keyword</param>
  2216. /// <param name="strToReplace">String to replace the keyword.</param>
  2217. /// <returns>Modified format string</returns>
  2218. private string RemoveOneKeyword(string strOriginal, string keyword, string strToReplace)
  2219. {
  2220. string result = strOriginal;
  2221. int keyIndex = -1;
  2222. while ((keyIndex = result.IndexOf(keyword, StringComparison.Ordinal)) != -1)
  2223. {
  2224. // Get optional format
  2225. int keyEndIndex = keyIndex + keyword.Length;
  2226. if (result.Length > keyEndIndex && result[keyEndIndex] == '{')
  2227. {
  2228. int formatEnd = result.IndexOf('}', keyEndIndex);
  2229. if (formatEnd == -1)
  2230. {
  2231. throw (new InvalidOperationException(SR.ExceptionDataSeriesKeywordFormatInvalid(result)));
  2232. }
  2233. keyEndIndex = formatEnd + 1;
  2234. }
  2235. // Remove keyword string (with optional format)
  2236. result = result.Remove(keyIndex, keyEndIndex - keyIndex);
  2237. if (!String.IsNullOrEmpty(strToReplace))
  2238. {
  2239. result = result.Insert(keyIndex, strToReplace);
  2240. }
  2241. }
  2242. return result;
  2243. }
  2244. /// <summary>
  2245. /// Replaces all "#CUSTOMPROPERTY(XXX)" (where XXX is the custom attribute name)
  2246. /// keywords in the string provided.
  2247. /// </summary>
  2248. /// <param name="originalString">String where the keyword need to be replaced.</param>
  2249. /// <param name="properties">DataPoint or Series properties class.</param>
  2250. /// <returns>Converted string.</returns>
  2251. internal static string ReplaceCustomPropertyKeyword(string originalString, DataPointCustomProperties properties)
  2252. {
  2253. string result = originalString;
  2254. int keyStartIndex = -1;
  2255. while ((keyStartIndex = result.IndexOf(KeywordName.CustomProperty, StringComparison.Ordinal)) >= 0)
  2256. {
  2257. string attributeValue = string.Empty;
  2258. string attributeName = string.Empty;
  2259. // Forward to the end of the keyword
  2260. int keyEndIndex = keyStartIndex + KeywordName.CustomProperty.Length;
  2261. // An opening bracket '(' must follow
  2262. if (result.Length > keyEndIndex && result[keyEndIndex] == '(')
  2263. {
  2264. ++keyEndIndex;
  2265. int attributeNameStartIndex = keyEndIndex;
  2266. // Search for the closing bracket
  2267. int closingBracketIndex = result.IndexOf(')', keyEndIndex);
  2268. if (closingBracketIndex >= keyEndIndex)
  2269. {
  2270. keyEndIndex = closingBracketIndex + 1;
  2271. attributeName = result.Substring(attributeNameStartIndex, keyEndIndex - attributeNameStartIndex - 1);
  2272. // Get attribute value
  2273. if (properties.IsCustomPropertySet(attributeName))
  2274. {
  2275. attributeValue = properties.GetCustomProperty(attributeName);
  2276. }
  2277. else
  2278. {
  2279. // In case of the DataPoint check if the attribute is set in the parent series
  2280. DataPoint dataPoint = properties as DataPoint;
  2281. if (dataPoint != null && dataPoint.series != null)
  2282. {
  2283. if (dataPoint.series.IsCustomPropertySet(attributeName))
  2284. {
  2285. attributeValue = dataPoint.series.GetCustomProperty(attributeName);
  2286. }
  2287. }
  2288. }
  2289. }
  2290. }
  2291. // Remove keyword string with attribute name
  2292. result = result.Remove(keyStartIndex, keyEndIndex - keyStartIndex);
  2293. // Insert value of the custom attribute
  2294. result = result.Insert(keyStartIndex, attributeValue);
  2295. }
  2296. return result;
  2297. }
  2298. /// <summary>
  2299. /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
  2300. /// </summary>
  2301. /// <returns>
  2302. /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
  2303. /// </returns>
  2304. internal override string ToStringInternal()
  2305. {
  2306. StringBuilder sb = new StringBuilder();
  2307. sb.AppendFormat(CultureInfo.CurrentCulture, "{{X={0}, ", XValue);
  2308. if (YValues.Length == 1)
  2309. {
  2310. sb.AppendFormat(CultureInfo.CurrentCulture, "Y={0}", YValues[0]);
  2311. }
  2312. else
  2313. {
  2314. sb.Append("Y={");
  2315. for (int i = 0; i < YValues.Length; i++)
  2316. if (i == 0)
  2317. sb.AppendFormat(CultureInfo.CurrentCulture, "{0}", YValues[i]);
  2318. else
  2319. sb.AppendFormat(CultureInfo.CurrentCulture, ", {0}", YValues[i]);
  2320. sb.Append("}");
  2321. }
  2322. sb.Append("}");
  2323. return sb.ToString();
  2324. }
  2325. #endregion
  2326. #region DataPoint Properties
  2327. /// <summary>
  2328. /// X value of the data point.
  2329. /// </summary>
  2330. [
  2331. SRCategory("CategoryAttributeData"),
  2332. Bindable(true),
  2333. SRDescription("DescriptionAttributeDataPoint_XValue"),
  2334. TypeConverter(typeof(DataPointValueConverter)),
  2335. DefaultValue(typeof(double), "0.0"),
  2336. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  2337. ]
  2338. public double XValue
  2339. {
  2340. get
  2341. {
  2342. return _xValue;
  2343. }
  2344. set
  2345. {
  2346. _xValue = value;
  2347. this.Invalidate(false);
  2348. CallOnModifing();
  2349. }
  2350. }
  2351. /// <summary>
  2352. /// List of Y values of the data point.
  2353. /// </summary>
  2354. [
  2355. SRCategory("CategoryAttributeData"),
  2356. SRDescription("DescriptionAttributeDataPoint_YValues"),
  2357. Bindable(true),
  2358. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  2359. TypeConverter(typeof(DoubleArrayConverter)),
  2360. #if DESIGNER
  2361. Editor(typeof(UITypeEditor), typeof(UITypeEditor)),
  2362. #endif
  2363. RefreshProperties(RefreshProperties.All),
  2364. SerializationVisibilityAttribute(SerializationVisibility.Attribute)
  2365. ]
  2366. [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
  2367. public double[] YValues
  2368. {
  2369. get
  2370. {
  2371. return _yValue;
  2372. }
  2373. set
  2374. {
  2375. if(value == null)
  2376. {
  2377. // Clear array data
  2378. for(int i=0; i < _yValue.Length; i++)
  2379. {
  2380. _yValue[i] = 0;
  2381. }
  2382. }
  2383. else
  2384. {
  2385. _yValue = value;
  2386. }
  2387. this.Invalidate(false);
  2388. CallOnModifing();
  2389. }
  2390. }
  2391. /// <summary>
  2392. /// A flag which indicates whether the data point is empty.
  2393. /// </summary>
  2394. [
  2395. SRCategory("CategoryAttributeData"),
  2396. Bindable(true),
  2397. SRDescription("DescriptionAttributeDataPoint_Empty"),
  2398. DefaultValue(false)
  2399. ]
  2400. public bool IsEmpty
  2401. {
  2402. get
  2403. {
  2404. return base.isEmptyPoint;
  2405. }
  2406. set
  2407. {
  2408. base.isEmptyPoint = value;
  2409. this.Invalidate(true);
  2410. CallOnModifing();
  2411. }
  2412. }
  2413. /// <summary>
  2414. /// Name of the data point. This field is reserved for internal use only.
  2415. /// </summary>
  2416. [
  2417. SRCategory("CategoryAttributeData"),
  2418. Bindable(true),
  2419. Browsable(false),
  2420. SRDescription("DescriptionAttributeDataPoint_Name"),
  2421. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  2422. SerializationVisibilityAttribute(SerializationVisibility.Hidden)
  2423. ]
  2424. public override string Name
  2425. {
  2426. get
  2427. {
  2428. return "DataPoint";
  2429. }
  2430. set
  2431. {
  2432. //Dont call the base method - the names don't need to be unique
  2433. }
  2434. }
  2435. #endregion
  2436. }
  2437. /// <summary>
  2438. /// Stores properties of one Data Point and Data series.
  2439. /// </summary>
  2440. [
  2441. SRDescription("DescriptionAttributeDataPointCustomProperties_DataPointCustomProperties"),
  2442. DefaultProperty("LabelStyle"),
  2443. TypeConverter(typeof(DataPointCustomPropertiesConverter))
  2444. ]
  2445. public class DataPointCustomProperties : ChartNamedElement
  2446. {
  2447. #region Fields and enumerations
  2448. // True indicates data point properties. Otherwise - series.
  2449. internal bool pointCustomProperties = true;
  2450. // Reference to the data point series
  2451. internal Series series = null;
  2452. // Storage for the custom properties names/values
  2453. internal Hashtable properties = new Hashtable();
  2454. // Flag indicating that temp. color was set
  2455. internal bool tempColorIsSet = false;
  2456. // Design time custom properties data
  2457. internal CustomProperties customProperties = null;
  2458. // IsEmpty point indicator
  2459. internal bool isEmptyPoint = false;
  2460. #endregion
  2461. #region Constructors
  2462. /// <summary>
  2463. /// DataPointCustomProperties constructor.
  2464. /// </summary>
  2465. public DataPointCustomProperties()
  2466. {
  2467. // Initialize the data series
  2468. this.series = null;
  2469. this.customProperties = new CustomProperties(this);
  2470. }
  2471. /// <summary>
  2472. /// DataPointCustomProperties constructor.
  2473. /// </summary>
  2474. /// <param name="series">The series which the data point belongs to.</param>
  2475. /// <param name="pointProperties">Indicates whether this is a data point custom properties.</param>
  2476. public DataPointCustomProperties(Series series, bool pointProperties): base( series, String.Empty)
  2477. {
  2478. // Initialize the data series
  2479. this.series = series;
  2480. this.pointCustomProperties = pointProperties;
  2481. this.customProperties = new CustomProperties(this);
  2482. }
  2483. #endregion
  2484. #region Custom Properties methods
  2485. /// <summary>
  2486. /// Checks if custom property with specified name was set.
  2487. /// </summary>
  2488. /// <param name="name">Name of the custom property to check.</param>
  2489. /// <returns>True if custom property was set.</returns>
  2490. virtual public bool IsCustomPropertySet(string name)
  2491. {
  2492. return properties.ContainsKey(name);
  2493. }
  2494. /// <summary>
  2495. /// Checks if the custom property with specified name was set.
  2496. /// </summary>
  2497. /// <param name="property">The CommonCustomProperties object to check for.</param>
  2498. /// <returns>True if attribute was set.</returns>
  2499. internal bool IsCustomPropertySet(CommonCustomProperties property)
  2500. {
  2501. return properties.ContainsKey((int)property);
  2502. }
  2503. /// <summary>
  2504. /// Delete the data point custom property with the specified name.
  2505. /// </summary>
  2506. /// <param name="name">Name of the property to delete.</param>
  2507. virtual public void DeleteCustomProperty(string name)
  2508. {
  2509. if(name == null)
  2510. {
  2511. throw (new ArgumentNullException(SR.ExceptionAttributeNameIsEmpty));
  2512. }
  2513. // Check if trying to delete the common attribute
  2514. string[] AttributesNames = CommonCustomProperties.GetNames(typeof(CommonCustomProperties));
  2515. foreach(string commonName in AttributesNames)
  2516. {
  2517. if(name == commonName)
  2518. {
  2519. DeleteCustomProperty((CommonCustomProperties)Enum.Parse(typeof(CommonCustomProperties), commonName));
  2520. }
  2521. }
  2522. // Remove attribute
  2523. properties.Remove(name);
  2524. }
  2525. /// <summary>
  2526. /// Delete Data Point attribute with specified name.
  2527. /// </summary>
  2528. /// <param name="property">ID of the attribute to delete.</param>
  2529. internal void DeleteCustomProperty(CommonCustomProperties property)
  2530. {
  2531. // Check if trying to delete the common attribute from the series
  2532. if(!this.pointCustomProperties)
  2533. {
  2534. throw(new ArgumentException( SR.ExceptionAttributeUnableToDelete));
  2535. }
  2536. // Remove attribute
  2537. properties.Remove((int)property);
  2538. }
  2539. /// <summary>
  2540. /// Gets the data point custom property with the specified name.
  2541. /// </summary>
  2542. /// <param name="name">Name of the property to get.</param>
  2543. /// <returns>Returns the data point custom property with the specified name. If the requested one is not set,
  2544. /// the default custom property of the data series will be returned.</returns>
  2545. virtual public string GetCustomProperty(string name)
  2546. {
  2547. if(!IsCustomPropertySet(name) && this.pointCustomProperties)
  2548. {
  2549. // Check if we are in serialization mode
  2550. bool serializing = false;
  2551. if(Chart != null && Chart.serializing)
  2552. {
  2553. serializing = true;
  2554. }
  2555. if(!serializing)
  2556. {
  2557. if(this.isEmptyPoint)
  2558. {
  2559. // Return empty point properties from series
  2560. return (string)series.EmptyPointStyle.properties[name];
  2561. }
  2562. // Return properties from series
  2563. return (string)series.properties[name];
  2564. }
  2565. else
  2566. {
  2567. // Return default properties
  2568. return (string)Series.defaultCustomProperties[name];
  2569. }
  2570. }
  2571. return (string)properties[name];
  2572. }
  2573. /// <summary>
  2574. /// Checks if data is currently serialized.
  2575. /// </summary>
  2576. /// <returns>True if serialized.</returns>
  2577. internal bool IsSerializing()
  2578. {
  2579. // Check if series object is provided
  2580. if(series == null)
  2581. {
  2582. return true;
  2583. }
  2584. // Check if we are in serialization mode
  2585. if(Chart != null)
  2586. {
  2587. return Chart.serializing;
  2588. }
  2589. else
  2590. {
  2591. return false;
  2592. }
  2593. }
  2594. /// <summary>
  2595. /// Returns an attribute object of the Data Point. If required attribute is not set
  2596. /// in the Data Point the default attribute of the Data series is returned.
  2597. /// </summary>
  2598. /// <param name="attrib">Attribute name ID.</param>
  2599. /// <returns>Attribute value.</returns>
  2600. internal object GetAttributeObject(CommonCustomProperties attrib)
  2601. {
  2602. // Get series properties
  2603. if(!this.pointCustomProperties || series == null)
  2604. {
  2605. return properties[(int)attrib];
  2606. }
  2607. // Get data point properties
  2608. if(properties.Count == 0 || !IsCustomPropertySet(attrib))
  2609. {
  2610. // Check if we are in serialization mode
  2611. bool serializing = false;
  2612. if(Chart != null)
  2613. {
  2614. serializing = Chart.serializing;
  2615. }
  2616. if(!serializing)
  2617. {
  2618. if(this.isEmptyPoint)
  2619. {
  2620. // Return empty point properties from series
  2621. return series.EmptyPointStyle.properties[(int)attrib];
  2622. }
  2623. // Return properties from series
  2624. return series.properties[(int)attrib];
  2625. }
  2626. else
  2627. {
  2628. // Return default properties
  2629. return Series.defaultCustomProperties.properties[(int)attrib];
  2630. }
  2631. }
  2632. return properties[(int)attrib];
  2633. }
  2634. /// <summary>
  2635. /// Sets a custom property of the data point.
  2636. /// </summary>
  2637. /// <param name="name">Property name.</param>
  2638. /// <param name="propertyValue">Property value.</param>
  2639. virtual public void SetCustomProperty(string name, string propertyValue)
  2640. {
  2641. properties[name] = propertyValue;
  2642. }
  2643. /// <summary>
  2644. /// Sets an attribute of the Data Point as an object.
  2645. /// </summary>
  2646. /// <param name="attrib">Attribute name ID.</param>
  2647. /// <param name="attributeValue">Attribute new value.</param>
  2648. internal void SetAttributeObject(CommonCustomProperties attrib, object attributeValue)
  2649. {
  2650. properties[(int)attrib] = attributeValue;
  2651. }
  2652. /// <summary>
  2653. /// Set the default properties of the data point.
  2654. /// <param name="clearAll">Indicates that previous properties must be cleared.</param>
  2655. /// </summary>
  2656. virtual public void SetDefault(bool clearAll)
  2657. {
  2658. // If setting defaults for the data series - clear all properties and initialize common one
  2659. if(!this.pointCustomProperties)
  2660. {
  2661. if(clearAll)
  2662. {
  2663. properties.Clear();
  2664. }
  2665. // !!! IMPORTANT !!!
  2666. // After changing the default value of the common attribute you must also
  2667. // change the DefaultAttribute of the property representing this attribute.
  2668. if(!IsCustomPropertySet(CommonCustomProperties.ToolTip))
  2669. SetAttributeObject(CommonCustomProperties.ToolTip, "");
  2670. if(!IsCustomPropertySet(CommonCustomProperties.LegendToolTip))
  2671. SetAttributeObject(CommonCustomProperties.LegendToolTip, "");
  2672. if(!IsCustomPropertySet(CommonCustomProperties.Color))
  2673. SetAttributeObject(CommonCustomProperties.Color, Color.Empty);
  2674. if(!IsCustomPropertySet(CommonCustomProperties.IsValueShownAsLabel))
  2675. SetAttributeObject(CommonCustomProperties.IsValueShownAsLabel, false);
  2676. if(!IsCustomPropertySet(CommonCustomProperties.MarkerStyle))
  2677. SetAttributeObject(CommonCustomProperties.MarkerStyle, MarkerStyle.None);
  2678. if(!IsCustomPropertySet(CommonCustomProperties.MarkerSize))
  2679. SetAttributeObject(CommonCustomProperties.MarkerSize, 5);
  2680. if(!IsCustomPropertySet(CommonCustomProperties.MarkerImage))
  2681. SetAttributeObject(CommonCustomProperties.MarkerImage, "");
  2682. if(!IsCustomPropertySet(CommonCustomProperties.Label))
  2683. SetAttributeObject(CommonCustomProperties.Label, "");
  2684. if(!IsCustomPropertySet(CommonCustomProperties.BorderWidth))
  2685. SetAttributeObject(CommonCustomProperties.BorderWidth, 1);
  2686. if(!IsCustomPropertySet(CommonCustomProperties.BorderDashStyle))
  2687. SetAttributeObject(CommonCustomProperties.BorderDashStyle, ChartDashStyle.Solid);
  2688. if(!IsCustomPropertySet(CommonCustomProperties.AxisLabel))
  2689. SetAttributeObject(CommonCustomProperties.AxisLabel, "");
  2690. if(!IsCustomPropertySet(CommonCustomProperties.LabelFormat))
  2691. SetAttributeObject(CommonCustomProperties.LabelFormat, "");
  2692. if(!IsCustomPropertySet(CommonCustomProperties.BorderColor))
  2693. SetAttributeObject(CommonCustomProperties.BorderColor, Color.Empty);
  2694. if(!IsCustomPropertySet(CommonCustomProperties.BackImage))
  2695. SetAttributeObject(CommonCustomProperties.BackImage, "");
  2696. if(!IsCustomPropertySet(CommonCustomProperties.BackImageWrapMode))
  2697. SetAttributeObject(CommonCustomProperties.BackImageWrapMode, ChartImageWrapMode.Tile);
  2698. if(!IsCustomPropertySet(CommonCustomProperties.BackImageAlignment))
  2699. SetAttributeObject(CommonCustomProperties.BackImageAlignment, ChartImageAlignmentStyle.TopLeft);
  2700. if(!IsCustomPropertySet(CommonCustomProperties.BackImageTransparentColor))
  2701. SetAttributeObject(CommonCustomProperties.BackImageTransparentColor, Color.Empty);
  2702. if(!IsCustomPropertySet(CommonCustomProperties.BackGradientStyle))
  2703. SetAttributeObject(CommonCustomProperties.BackGradientStyle, GradientStyle.None);
  2704. if(!IsCustomPropertySet(CommonCustomProperties.BackSecondaryColor))
  2705. SetAttributeObject(CommonCustomProperties.BackSecondaryColor, Color.Empty);
  2706. if(!IsCustomPropertySet(CommonCustomProperties.BackHatchStyle))
  2707. SetAttributeObject(CommonCustomProperties.BackHatchStyle, ChartHatchStyle.None);
  2708. if(!IsCustomPropertySet(CommonCustomProperties.Font))
  2709. SetAttributeObject(CommonCustomProperties.Font, null);
  2710. if(!IsCustomPropertySet(CommonCustomProperties.MarkerImageTransparentColor))
  2711. SetAttributeObject(CommonCustomProperties.MarkerImageTransparentColor, Color.Empty);
  2712. if(!IsCustomPropertySet(CommonCustomProperties.MarkerColor))
  2713. SetAttributeObject(CommonCustomProperties.MarkerColor, Color.Empty);
  2714. if(!IsCustomPropertySet(CommonCustomProperties.MarkerBorderColor))
  2715. SetAttributeObject(CommonCustomProperties.MarkerBorderColor, Color.Empty);
  2716. if(!IsCustomPropertySet(CommonCustomProperties.MarkerBorderWidth))
  2717. SetAttributeObject(CommonCustomProperties.MarkerBorderWidth, 1);
  2718. if(!IsCustomPropertySet(CommonCustomProperties.MapAreaAttributes))
  2719. SetAttributeObject(CommonCustomProperties.MapAreaAttributes, "");
  2720. if (!IsCustomPropertySet(CommonCustomProperties.PostBackValue))
  2721. SetAttributeObject(CommonCustomProperties.PostBackValue, "");
  2722. if (!IsCustomPropertySet(CommonCustomProperties.LabelForeColor))
  2723. SetAttributeObject(CommonCustomProperties.LabelForeColor, Color.Black);
  2724. if (!IsCustomPropertySet(CommonCustomProperties.LabelAngle))
  2725. SetAttributeObject(CommonCustomProperties.LabelAngle, 0);
  2726. if (!IsCustomPropertySet(CommonCustomProperties.LabelToolTip))
  2727. SetAttributeObject(CommonCustomProperties.LabelToolTip, "");
  2728. if(!IsCustomPropertySet(CommonCustomProperties.LabelUrl))
  2729. SetAttributeObject(CommonCustomProperties.LabelUrl, "");
  2730. if (!IsCustomPropertySet(CommonCustomProperties.LabelPostBackValue))
  2731. SetAttributeObject(CommonCustomProperties.LabelPostBackValue, "");
  2732. if (!IsCustomPropertySet(CommonCustomProperties.LabelMapAreaAttributes))
  2733. SetAttributeObject(CommonCustomProperties.LabelMapAreaAttributes, "");
  2734. if(!IsCustomPropertySet(CommonCustomProperties.LabelBackColor))
  2735. SetAttributeObject(CommonCustomProperties.LabelBackColor, Color.Empty);
  2736. if(!IsCustomPropertySet(CommonCustomProperties.LabelBorderWidth))
  2737. SetAttributeObject(CommonCustomProperties.LabelBorderWidth, 1);
  2738. if(!IsCustomPropertySet(CommonCustomProperties.LabelBorderDashStyle))
  2739. SetAttributeObject(CommonCustomProperties.LabelBorderDashStyle, ChartDashStyle.Solid);
  2740. if(!IsCustomPropertySet(CommonCustomProperties.LabelBorderColor))
  2741. SetAttributeObject(CommonCustomProperties.LabelBorderColor, Color.Empty);
  2742. if(!IsCustomPropertySet(CommonCustomProperties.Url))
  2743. SetAttributeObject(CommonCustomProperties.Url, "");
  2744. if(!IsCustomPropertySet(CommonCustomProperties.LegendUrl))
  2745. SetAttributeObject(CommonCustomProperties.LegendUrl, "");
  2746. if (!IsCustomPropertySet(CommonCustomProperties.LegendPostBackValue))
  2747. SetAttributeObject(CommonCustomProperties.LegendPostBackValue, "");
  2748. if (!IsCustomPropertySet(CommonCustomProperties.LegendText))
  2749. SetAttributeObject(CommonCustomProperties.LegendText, "");
  2750. if(!IsCustomPropertySet(CommonCustomProperties.LegendMapAreaAttributes))
  2751. SetAttributeObject(CommonCustomProperties.LegendMapAreaAttributes, "");
  2752. if(!IsCustomPropertySet(CommonCustomProperties.IsVisibleInLegend))
  2753. SetAttributeObject(CommonCustomProperties.IsVisibleInLegend, true);
  2754. }
  2755. // If setting defaults for the data point - clear all properties
  2756. else
  2757. {
  2758. properties.Clear();
  2759. }
  2760. }
  2761. #endregion
  2762. #region DataPointCustomProperties Properties
  2763. /// <summary>
  2764. /// Indexer of the custom properties. Returns the DataPointCustomProperties object by index.
  2765. /// </summary>
  2766. /// <param name="index">Index of the custom property.</param>
  2767. public string this[int index]
  2768. {
  2769. get
  2770. {
  2771. int currentIndex = 0;
  2772. foreach(object key in properties.Keys)
  2773. {
  2774. if(currentIndex == index)
  2775. {
  2776. string keyStr = key as string;
  2777. if (keyStr != null)
  2778. {
  2779. return keyStr;
  2780. }
  2781. else if (key is int)
  2782. {
  2783. return Enum.GetName(typeof(CommonCustomProperties), key);
  2784. }
  2785. return key.ToString();
  2786. }
  2787. ++currentIndex;
  2788. }
  2789. // we can't throw IndexOutOfRangeException here, it is reserved
  2790. // by the CLR.
  2791. throw (new InvalidOperationException());
  2792. }
  2793. }
  2794. /// <summary>
  2795. /// Indexer of the custom properties. Returns the DataPointCustomProperties object by name.
  2796. /// </summary>
  2797. /// <param name="name">Name of the custom property.</param>
  2798. public string this[string name]
  2799. {
  2800. get
  2801. {
  2802. // If attribute is not set in data point - try getting it from the series
  2803. if(!IsCustomPropertySet(name) && this.pointCustomProperties)
  2804. {
  2805. if(this.isEmptyPoint)
  2806. {
  2807. return (string)series.EmptyPointStyle.properties[name];
  2808. }
  2809. return (string)series.properties[name];
  2810. }
  2811. return (string)properties[name];
  2812. }
  2813. set
  2814. {
  2815. properties[name] = value;
  2816. this.Invalidate(true);
  2817. CallOnModifing();
  2818. }
  2819. }
  2820. /// <summary>
  2821. /// The text of the data point label.
  2822. /// </summary>
  2823. [
  2824. #if DESIGNER
  2825. Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)),
  2826. #endif
  2827. SRCategory("CategoryAttributeLabel"),
  2828. Bindable(true),
  2829. SRDescription("DescriptionAttributeLabel"),
  2830. ]
  2831. virtual public string Label
  2832. {
  2833. get
  2834. {
  2835. if(this.pointCustomProperties)
  2836. {
  2837. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.Label))
  2838. {
  2839. return (string)GetAttributeObject(CommonCustomProperties.Label);
  2840. }
  2841. else
  2842. {
  2843. if(IsSerializing())
  2844. {
  2845. return "";
  2846. }
  2847. if(this.isEmptyPoint)
  2848. {
  2849. return (string)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.Label);
  2850. }
  2851. return series.label;
  2852. }
  2853. }
  2854. else
  2855. {
  2856. return series.label;
  2857. }
  2858. }
  2859. set
  2860. {
  2861. // Replace NULL with empty string
  2862. if(value == null)
  2863. {
  2864. value = string.Empty;
  2865. }
  2866. if (this.pointCustomProperties)
  2867. SetAttributeObject(CommonCustomProperties.Label, value);
  2868. else
  2869. series.label = value;
  2870. this.Invalidate(true);
  2871. CallOnModifing();
  2872. }
  2873. }
  2874. /// <summary>
  2875. /// The text of X axis label for the data point.
  2876. /// </summary>
  2877. [
  2878. SRCategory("CategoryAttributeMisc"),
  2879. Bindable(true),
  2880. SRDescription("DescriptionAttributeAxisLabel"),
  2881. #if DESIGNER
  2882. Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)),
  2883. #endif
  2884. ]
  2885. virtual public string AxisLabel
  2886. {
  2887. get
  2888. {
  2889. if(this.pointCustomProperties)
  2890. {
  2891. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.AxisLabel))
  2892. {
  2893. return (string)GetAttributeObject(CommonCustomProperties.AxisLabel);
  2894. }
  2895. else
  2896. {
  2897. if(IsSerializing())
  2898. {
  2899. return "";
  2900. }
  2901. if(this.isEmptyPoint)
  2902. {
  2903. return (string)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.AxisLabel);
  2904. }
  2905. return series.axisLabel;
  2906. }
  2907. }
  2908. else
  2909. {
  2910. return series.axisLabel;
  2911. }
  2912. }
  2913. set
  2914. {
  2915. // Replace NULL with empty string
  2916. if(value == null)
  2917. {
  2918. value = string.Empty;
  2919. }
  2920. if(this.pointCustomProperties)
  2921. SetAttributeObject(CommonCustomProperties.AxisLabel, value);
  2922. else
  2923. series.axisLabel = value;
  2924. // Set flag that there are non-empy axis labels in series or points
  2925. if(value.Length > 0 && series != null)
  2926. {
  2927. series.noLabelsInPoints = false;
  2928. }
  2929. this.Invalidate(false);
  2930. CallOnModifing();
  2931. }
  2932. }
  2933. /// <summary>
  2934. /// Format string of the data point label.
  2935. /// </summary>
  2936. [
  2937. SRCategory("CategoryAttributeLabel"),
  2938. Bindable(true),
  2939. SRDescription("DescriptionAttributeLabelFormat")
  2940. ]
  2941. public string LabelFormat
  2942. {
  2943. get
  2944. {
  2945. if(this.pointCustomProperties)
  2946. {
  2947. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.LabelFormat))
  2948. {
  2949. return (string)GetAttributeObject(CommonCustomProperties.LabelFormat);
  2950. }
  2951. else
  2952. {
  2953. if(IsSerializing())
  2954. {
  2955. return "";
  2956. }
  2957. if(this.isEmptyPoint)
  2958. {
  2959. return (string)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.LabelFormat);
  2960. }
  2961. return series.labelFormat;
  2962. }
  2963. }
  2964. else
  2965. {
  2966. return series.labelFormat;
  2967. }
  2968. }
  2969. set
  2970. {
  2971. // Replace NULL with empty string
  2972. if(value == null)
  2973. {
  2974. value = string.Empty;
  2975. }
  2976. if(this.pointCustomProperties)
  2977. SetAttributeObject(CommonCustomProperties.LabelFormat, value);
  2978. else
  2979. series.labelFormat = value;
  2980. this.Invalidate(false);
  2981. CallOnModifing();
  2982. }
  2983. }
  2984. /// <summary>
  2985. /// A flag which indicates whether to show the data point's value on the label.
  2986. /// </summary>
  2987. [
  2988. SRCategory("CategoryAttributeLabel"),
  2989. Bindable(true),
  2990. SRDescription("DescriptionAttributeShowLabelAsValue")
  2991. ]
  2992. public bool IsValueShownAsLabel
  2993. {
  2994. get
  2995. {
  2996. if(this.pointCustomProperties)
  2997. {
  2998. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.IsValueShownAsLabel))
  2999. {
  3000. return (bool)GetAttributeObject(CommonCustomProperties.IsValueShownAsLabel);
  3001. }
  3002. else
  3003. {
  3004. if(IsSerializing())
  3005. {
  3006. return false;
  3007. }
  3008. if(this.isEmptyPoint)
  3009. {
  3010. return (bool)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.IsValueShownAsLabel);
  3011. }
  3012. return series.showLabelAsValue;
  3013. }
  3014. }
  3015. else
  3016. {
  3017. return series.showLabelAsValue;
  3018. }
  3019. }
  3020. set
  3021. {
  3022. if(this.pointCustomProperties)
  3023. SetAttributeObject(CommonCustomProperties.IsValueShownAsLabel, value);
  3024. else
  3025. series.showLabelAsValue = value;
  3026. this.Invalidate(false);
  3027. CallOnModifing();
  3028. }
  3029. }
  3030. /// <summary>
  3031. /// Color of the data point.
  3032. /// </summary>
  3033. [
  3034. SRCategory("CategoryAttributeAppearance"),
  3035. Bindable(true),
  3036. SRDescription("DescriptionAttributeColor4"),
  3037. TypeConverter(typeof(ColorConverter)),
  3038. #if DESIGNER
  3039. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  3040. #endif
  3041. ]
  3042. public Color Color
  3043. {
  3044. get
  3045. {
  3046. if(this.pointCustomProperties)
  3047. {
  3048. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.Color))
  3049. {
  3050. return (Color)GetAttributeObject(CommonCustomProperties.Color);
  3051. }
  3052. else
  3053. {
  3054. if(IsSerializing())
  3055. {
  3056. return Color.Empty;
  3057. }
  3058. if(this.isEmptyPoint)
  3059. {
  3060. return (Color)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.Color);
  3061. }
  3062. return series.color;
  3063. }
  3064. }
  3065. else
  3066. {
  3067. return series.color;
  3068. }
  3069. }
  3070. set
  3071. {
  3072. // Remove the temp color flag
  3073. this.tempColorIsSet = false;
  3074. if(value == Color.Empty && this.pointCustomProperties)
  3075. {
  3076. DeleteCustomProperty(CommonCustomProperties.Color);
  3077. }
  3078. else
  3079. {
  3080. if(this.pointCustomProperties)
  3081. SetAttributeObject(CommonCustomProperties.Color, value);
  3082. else
  3083. series.color = value;
  3084. this.Invalidate(true);
  3085. }
  3086. }
  3087. }
  3088. /// <summary>
  3089. /// Border color of the data point.
  3090. /// </summary>
  3091. [
  3092. SRCategory("CategoryAttributeAppearance"),
  3093. Bindable(true),
  3094. SRDescription("DescriptionAttributeBorderColor"),
  3095. TypeConverter(typeof(ColorConverter)),
  3096. #if DESIGNER
  3097. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  3098. #endif
  3099. ]
  3100. public Color BorderColor
  3101. {
  3102. get
  3103. {
  3104. if(this.pointCustomProperties)
  3105. {
  3106. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.BorderColor))
  3107. {
  3108. return (Color)GetAttributeObject(CommonCustomProperties.BorderColor);
  3109. }
  3110. else
  3111. {
  3112. if(IsSerializing())
  3113. {
  3114. return Color.Empty;
  3115. }
  3116. if(this.isEmptyPoint)
  3117. {
  3118. return (Color)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.BorderColor);
  3119. }
  3120. return series.borderColor;
  3121. }
  3122. }
  3123. else
  3124. {
  3125. return series.borderColor;
  3126. }
  3127. }
  3128. set
  3129. {
  3130. if(this.pointCustomProperties)
  3131. SetAttributeObject(CommonCustomProperties.BorderColor, value);
  3132. else
  3133. series.borderColor = value;
  3134. this.Invalidate(true);
  3135. CallOnModifing();
  3136. }
  3137. }
  3138. /// <summary>
  3139. /// Border style of the data point.
  3140. /// </summary>
  3141. [
  3142. SRCategory("CategoryAttributeAppearance"),
  3143. Bindable(true),
  3144. SRDescription("DescriptionAttributeBorderDashStyle")
  3145. ]
  3146. public ChartDashStyle BorderDashStyle
  3147. {
  3148. get
  3149. {
  3150. if(this.pointCustomProperties)
  3151. {
  3152. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.BorderDashStyle))
  3153. {
  3154. return (ChartDashStyle)GetAttributeObject(CommonCustomProperties.BorderDashStyle);
  3155. }
  3156. else
  3157. {
  3158. if(IsSerializing())
  3159. {
  3160. return ChartDashStyle.Solid;
  3161. }
  3162. if(this.isEmptyPoint)
  3163. {
  3164. return (ChartDashStyle)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.BorderDashStyle);
  3165. }
  3166. return series.borderDashStyle;
  3167. }
  3168. }
  3169. else
  3170. {
  3171. return series.borderDashStyle;
  3172. }
  3173. }
  3174. set
  3175. {
  3176. if(this.pointCustomProperties)
  3177. SetAttributeObject(CommonCustomProperties.BorderDashStyle, value);
  3178. else
  3179. series.borderDashStyle = value;
  3180. this.Invalidate(true);
  3181. CallOnModifing();
  3182. }
  3183. }
  3184. /// <summary>
  3185. /// Border width of the data point.
  3186. /// </summary>
  3187. [
  3188. SRCategory("CategoryAttributeAppearance"),
  3189. Bindable(true),
  3190. SRDescription("DescriptionAttributeBorderWidth"),
  3191. ]
  3192. public int BorderWidth
  3193. {
  3194. get
  3195. {
  3196. if(this.pointCustomProperties)
  3197. {
  3198. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.BorderWidth))
  3199. {
  3200. return (int)GetAttributeObject(CommonCustomProperties.BorderWidth);
  3201. }
  3202. else
  3203. {
  3204. if(IsSerializing())
  3205. {
  3206. return 1;
  3207. }
  3208. if(this.isEmptyPoint)
  3209. {
  3210. return (int)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.BorderWidth);
  3211. }
  3212. return series.borderWidth;
  3213. }
  3214. }
  3215. else
  3216. {
  3217. return series.borderWidth;
  3218. }
  3219. }
  3220. set
  3221. {
  3222. if(value < 0)
  3223. {
  3224. throw (new ArgumentOutOfRangeException("value", SR.ExceptionBorderWidthIsNotPositive));
  3225. }
  3226. if(this.pointCustomProperties)
  3227. SetAttributeObject(CommonCustomProperties.BorderWidth, value);
  3228. else
  3229. series.borderWidth = value;
  3230. this.Invalidate(true);
  3231. CallOnModifing();
  3232. }
  3233. }
  3234. /// <summary>
  3235. /// Background image of the data point.
  3236. /// </summary>
  3237. [
  3238. SRCategory("CategoryAttributeAppearance"),
  3239. Bindable(true),
  3240. SRDescription("DescriptionAttributeBackImage"),
  3241. #if DESIGNER
  3242. Editor(typeof(ImageValueEditor), typeof(UITypeEditor)),
  3243. #endif
  3244. ]
  3245. public string BackImage
  3246. {
  3247. get
  3248. {
  3249. if(this.pointCustomProperties)
  3250. {
  3251. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.BackImage))
  3252. {
  3253. return (string)GetAttributeObject(CommonCustomProperties.BackImage);
  3254. }
  3255. else
  3256. {
  3257. if(IsSerializing())
  3258. {
  3259. return "";
  3260. }
  3261. if(this.isEmptyPoint)
  3262. {
  3263. return (string)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.BackImage);
  3264. }
  3265. return series.backImage;
  3266. }
  3267. }
  3268. else
  3269. {
  3270. return series.backImage;
  3271. }
  3272. }
  3273. set
  3274. {
  3275. // Replace NULL with empty string
  3276. if(value == null)
  3277. {
  3278. value = string.Empty;
  3279. }
  3280. if(this.pointCustomProperties)
  3281. SetAttributeObject(CommonCustomProperties.BackImage, value);
  3282. else
  3283. series.backImage = value;
  3284. this.Invalidate(true);
  3285. CallOnModifing();
  3286. }
  3287. }
  3288. /// <summary>
  3289. /// Gets or sets the drawing mode of the background image.
  3290. /// </summary>
  3291. /// <value>
  3292. /// A <see cref="ChartImageWrapMode"/> value that defines the drawing mode of the image.
  3293. /// </value>
  3294. [
  3295. SRCategory("CategoryAttributeAppearance"),
  3296. Bindable(true),
  3297. SRDescription("DescriptionAttributeImageWrapMode")
  3298. ]
  3299. public ChartImageWrapMode BackImageWrapMode
  3300. {
  3301. get
  3302. {
  3303. if(this.pointCustomProperties)
  3304. {
  3305. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.BackImageWrapMode))
  3306. {
  3307. return (ChartImageWrapMode)GetAttributeObject(CommonCustomProperties.BackImageWrapMode);
  3308. }
  3309. else
  3310. {
  3311. if(IsSerializing())
  3312. {
  3313. return ChartImageWrapMode.Tile;
  3314. }
  3315. if(this.isEmptyPoint)
  3316. {
  3317. return (ChartImageWrapMode)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.BackImageWrapMode);
  3318. }
  3319. return series.backImageWrapMode;
  3320. }
  3321. }
  3322. else
  3323. {
  3324. return series.backImageWrapMode;
  3325. }
  3326. }
  3327. set
  3328. {
  3329. if(this.pointCustomProperties)
  3330. SetAttributeObject(CommonCustomProperties.BackImageWrapMode, value);
  3331. else
  3332. series.backImageWrapMode = value;
  3333. this.Invalidate(true);
  3334. CallOnModifing();
  3335. }
  3336. }
  3337. /// <summary>
  3338. /// Gets or sets a color which will be replaced with a transparent color while drawing the background image.
  3339. /// </summary>
  3340. /// <value>
  3341. /// A <see cref="Color"/> value which will be replaced with a transparent color while drawing the image.
  3342. /// </value>
  3343. [
  3344. SRCategory("CategoryAttributeAppearance"),
  3345. Bindable(true),
  3346. NotifyParentPropertyAttribute(true),
  3347. SRDescription("DescriptionAttributeImageTransparentColor"),
  3348. TypeConverter(typeof(ColorConverter)),
  3349. #if DESIGNER
  3350. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  3351. #endif
  3352. ]
  3353. public Color BackImageTransparentColor
  3354. {
  3355. get
  3356. {
  3357. if(this.pointCustomProperties)
  3358. {
  3359. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.BackImageTransparentColor))
  3360. {
  3361. return (Color)GetAttributeObject(CommonCustomProperties.BackImageTransparentColor);
  3362. }
  3363. else
  3364. {
  3365. if(IsSerializing())
  3366. {
  3367. return Color.Empty;
  3368. }
  3369. if(this.isEmptyPoint)
  3370. {
  3371. return (Color)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.BackImageTransparentColor);
  3372. }
  3373. return series.backImageTransparentColor;
  3374. }
  3375. }
  3376. else
  3377. {
  3378. return series.backImageTransparentColor;
  3379. }
  3380. }
  3381. set
  3382. {
  3383. if(this.pointCustomProperties)
  3384. SetAttributeObject(CommonCustomProperties.BackImageTransparentColor, value);
  3385. else
  3386. series.backImageTransparentColor = value;
  3387. this.Invalidate(true);
  3388. CallOnModifing();
  3389. }
  3390. }
  3391. /// <summary>
  3392. /// Gets or sets the alignment of the background image which is used by ClampUnscale drawing mode.
  3393. /// </summary>
  3394. [
  3395. SRCategory("CategoryAttributeAppearance"),
  3396. Bindable(true),
  3397. NotifyParentPropertyAttribute(true),
  3398. SRDescription("DescriptionAttributeBackImageAlign")
  3399. ]
  3400. public ChartImageAlignmentStyle BackImageAlignment
  3401. {
  3402. get
  3403. {
  3404. if(this.pointCustomProperties)
  3405. {
  3406. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.BackImageAlignment))
  3407. {
  3408. return (ChartImageAlignmentStyle)GetAttributeObject(CommonCustomProperties.BackImageAlignment);
  3409. }
  3410. else
  3411. {
  3412. if(IsSerializing())
  3413. {
  3414. return ChartImageAlignmentStyle.TopLeft;
  3415. }
  3416. if(this.isEmptyPoint)
  3417. {
  3418. return (ChartImageAlignmentStyle)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.BackImageAlignment);
  3419. }
  3420. return series.backImageAlignment;
  3421. }
  3422. }
  3423. else
  3424. {
  3425. return series.backImageAlignment;
  3426. }
  3427. }
  3428. set
  3429. {
  3430. if(this.pointCustomProperties)
  3431. SetAttributeObject(CommonCustomProperties.BackImageAlignment, value);
  3432. else
  3433. series.backImageAlignment = value;
  3434. this.Invalidate(true);
  3435. CallOnModifing();
  3436. }
  3437. }
  3438. /// <summary>
  3439. /// Gets or sets the background gradient style.
  3440. /// </summary>
  3441. [
  3442. SRCategory("CategoryAttributeAppearance"),
  3443. Bindable(true),
  3444. SRDescription("DescriptionAttributeBackGradientStyle"),
  3445. #if DESIGNER
  3446. Editor(typeof(GradientEditor), typeof(UITypeEditor))
  3447. #endif
  3448. ]
  3449. public GradientStyle BackGradientStyle
  3450. {
  3451. get
  3452. {
  3453. if(this.pointCustomProperties)
  3454. {
  3455. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.BackGradientStyle))
  3456. {
  3457. return (GradientStyle)GetAttributeObject(CommonCustomProperties.BackGradientStyle);
  3458. }
  3459. else
  3460. {
  3461. if(IsSerializing())
  3462. {
  3463. return GradientStyle.None;
  3464. }
  3465. if(this.isEmptyPoint)
  3466. {
  3467. return (GradientStyle)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.BackGradientStyle);
  3468. }
  3469. return series.backGradientStyle;
  3470. }
  3471. }
  3472. else
  3473. {
  3474. return series.backGradientStyle;
  3475. }
  3476. }
  3477. set
  3478. {
  3479. if(this.pointCustomProperties)
  3480. SetAttributeObject(CommonCustomProperties.BackGradientStyle, value);
  3481. else
  3482. series.backGradientStyle = value;
  3483. this.Invalidate(true);
  3484. CallOnModifing();
  3485. }
  3486. }
  3487. /// <summary>
  3488. /// Gets or sets the secondary background color.
  3489. /// </summary>
  3490. [
  3491. SRCategory("CategoryAttributeAppearance"),
  3492. Bindable(true),
  3493. SRDescription("DescriptionAttributeBackSecondaryColor"),
  3494. TypeConverter(typeof(ColorConverter)),
  3495. #if DESIGNER
  3496. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  3497. #endif
  3498. ]
  3499. public Color BackSecondaryColor
  3500. {
  3501. get
  3502. {
  3503. if(this.pointCustomProperties)
  3504. {
  3505. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.BackSecondaryColor))
  3506. {
  3507. return (Color)GetAttributeObject(CommonCustomProperties.BackSecondaryColor);
  3508. }
  3509. else
  3510. {
  3511. if(IsSerializing())
  3512. {
  3513. return Color.Empty;
  3514. }
  3515. if(this.isEmptyPoint)
  3516. {
  3517. return (Color)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.BackSecondaryColor);
  3518. }
  3519. return series.backSecondaryColor;
  3520. }
  3521. }
  3522. else
  3523. {
  3524. return series.backSecondaryColor;
  3525. }
  3526. }
  3527. set
  3528. {
  3529. if(this.pointCustomProperties)
  3530. SetAttributeObject(CommonCustomProperties.BackSecondaryColor, value);
  3531. else
  3532. series.backSecondaryColor = value;
  3533. this.Invalidate(true);
  3534. CallOnModifing();
  3535. }
  3536. }
  3537. /// <summary>
  3538. /// Gets or sets the background hatch style.
  3539. /// </summary>
  3540. [
  3541. SRCategory("CategoryAttributeAppearance"),
  3542. Bindable(true),
  3543. SRDescription("DescriptionAttributeBackHatchStyle"),
  3544. #if DESIGNER
  3545. Editor(typeof(HatchStyleEditor), typeof(UITypeEditor))
  3546. #endif
  3547. ]
  3548. public ChartHatchStyle BackHatchStyle
  3549. {
  3550. get
  3551. {
  3552. if(this.pointCustomProperties)
  3553. {
  3554. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.BackHatchStyle))
  3555. {
  3556. return (ChartHatchStyle)GetAttributeObject(CommonCustomProperties.BackHatchStyle);
  3557. }
  3558. else
  3559. {
  3560. if(IsSerializing())
  3561. {
  3562. return ChartHatchStyle.None;
  3563. }
  3564. if(this.isEmptyPoint)
  3565. {
  3566. return (ChartHatchStyle)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.BackHatchStyle);
  3567. }
  3568. return series.backHatchStyle;
  3569. }
  3570. }
  3571. else
  3572. {
  3573. return series.backHatchStyle;
  3574. }
  3575. }
  3576. set
  3577. {
  3578. if(this.pointCustomProperties)
  3579. SetAttributeObject(CommonCustomProperties.BackHatchStyle, value);
  3580. else
  3581. series.backHatchStyle = value;
  3582. this.Invalidate(true);
  3583. CallOnModifing();
  3584. }
  3585. }
  3586. /// <summary>
  3587. /// Gets or sets the font of the data point.
  3588. /// </summary>
  3589. [
  3590. SRCategory("CategoryAttributeLabelAppearance"),
  3591. Bindable(true),
  3592. SRDescription("DescriptionAttributeFont")
  3593. ]
  3594. public Font Font
  3595. {
  3596. get
  3597. {
  3598. if(this.pointCustomProperties)
  3599. {
  3600. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.Font))
  3601. {
  3602. Font font = GetAttributeObject(CommonCustomProperties.Font) as Font;
  3603. if (font != null)
  3604. return font;
  3605. }
  3606. if(IsSerializing())
  3607. {
  3608. return series.FontCache.DefaultFont;
  3609. }
  3610. if(this.isEmptyPoint)
  3611. {
  3612. return series.EmptyPointStyle.Font;
  3613. }
  3614. return series.font;
  3615. }
  3616. else
  3617. {
  3618. return series.font;
  3619. }
  3620. }
  3621. set
  3622. {
  3623. if(this.pointCustomProperties)
  3624. SetAttributeObject(CommonCustomProperties.Font, value);
  3625. else
  3626. series.font = value;
  3627. this.Invalidate(false);
  3628. CallOnModifing();
  3629. }
  3630. }
  3631. /// <summary>
  3632. /// Gets or sets the label color.
  3633. /// </summary>
  3634. [
  3635. SRCategory("CategoryAttributeLabelAppearance"),
  3636. Bindable(true),
  3637. SRDescription("DescriptionAttributeFontColor"),
  3638. TypeConverter(typeof(ColorConverter)),
  3639. #if DESIGNER
  3640. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  3641. #endif
  3642. ]
  3643. public Color LabelForeColor
  3644. {
  3645. get
  3646. {
  3647. if(this.pointCustomProperties)
  3648. {
  3649. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.LabelForeColor))
  3650. {
  3651. Color color = (Color)GetAttributeObject(CommonCustomProperties.LabelForeColor);
  3652. return color;
  3653. }
  3654. else
  3655. {
  3656. if(IsSerializing())
  3657. {
  3658. return Color.Black;
  3659. }
  3660. if(this.isEmptyPoint)
  3661. {
  3662. return (Color)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.LabelForeColor);
  3663. }
  3664. if(SystemInformation.HighContrast)
  3665. {
  3666. return SystemColors.WindowText;
  3667. }
  3668. return series.fontColor;
  3669. }
  3670. }
  3671. else
  3672. {
  3673. return series.fontColor;
  3674. }
  3675. }
  3676. set
  3677. {
  3678. if(this.pointCustomProperties)
  3679. SetAttributeObject(CommonCustomProperties.LabelForeColor, value);
  3680. else
  3681. series.fontColor = value;
  3682. this.Invalidate(false);
  3683. CallOnModifing();
  3684. }
  3685. }
  3686. /// <summary>
  3687. /// Gets or sets the angle of the label.
  3688. /// </summary>
  3689. [
  3690. SRCategory("CategoryAttributeLabelAppearance"),
  3691. Bindable(true),
  3692. SRDescription(SR.Keys.DescriptionAttributeLabel_FontAngle)
  3693. ]
  3694. public int LabelAngle
  3695. {
  3696. get
  3697. {
  3698. if(this.pointCustomProperties)
  3699. {
  3700. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.LabelAngle))
  3701. {
  3702. return (int)GetAttributeObject(CommonCustomProperties.LabelAngle);
  3703. }
  3704. else
  3705. {
  3706. if(IsSerializing())
  3707. {
  3708. return 0;
  3709. }
  3710. if(this.isEmptyPoint)
  3711. {
  3712. return (int)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.LabelAngle);
  3713. }
  3714. return series.fontAngle;
  3715. }
  3716. }
  3717. else
  3718. {
  3719. return series.fontAngle;
  3720. }
  3721. }
  3722. set
  3723. {
  3724. if(value < -90 || value > 90)
  3725. {
  3726. throw (new ArgumentOutOfRangeException("value", SR.ExceptionAngleRangeInvalid));
  3727. }
  3728. if(this.pointCustomProperties)
  3729. SetAttributeObject(CommonCustomProperties.LabelAngle, value);
  3730. else
  3731. series.fontAngle = value;
  3732. this.Invalidate(false);
  3733. CallOnModifing();
  3734. }
  3735. }
  3736. /// <summary>
  3737. /// Gets or sets the marker style.
  3738. /// </summary>
  3739. [
  3740. SRCategory("CategoryAttributeMarker"),
  3741. Bindable(true),
  3742. SRDescription("DescriptionAttributeMarkerStyle4"),
  3743. #if DESIGNER
  3744. Editor(typeof(MarkerStyleEditor), typeof(UITypeEditor)),
  3745. #endif
  3746. RefreshProperties(RefreshProperties.All)
  3747. ]
  3748. public MarkerStyle MarkerStyle
  3749. {
  3750. get
  3751. {
  3752. if(this.pointCustomProperties)
  3753. {
  3754. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.MarkerStyle))
  3755. {
  3756. return (MarkerStyle)GetAttributeObject(CommonCustomProperties.MarkerStyle);
  3757. }
  3758. else
  3759. {
  3760. if(IsSerializing())
  3761. {
  3762. return MarkerStyle.None;
  3763. }
  3764. if(this.isEmptyPoint)
  3765. {
  3766. return (MarkerStyle)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.MarkerStyle);
  3767. }
  3768. return series.markerStyle;
  3769. }
  3770. }
  3771. else
  3772. {
  3773. return series.markerStyle;
  3774. }
  3775. }
  3776. set
  3777. {
  3778. if(this.pointCustomProperties)
  3779. SetAttributeObject(CommonCustomProperties.MarkerStyle, value);
  3780. else
  3781. series.markerStyle = value;
  3782. Series thisSeries = this as Series;
  3783. if(thisSeries != null)
  3784. {
  3785. thisSeries.tempMarkerStyleIsSet = false;
  3786. }
  3787. this.Invalidate(true);
  3788. CallOnModifing();
  3789. }
  3790. }
  3791. /// <summary>
  3792. /// Gets or sets the size of the marker.
  3793. /// </summary>
  3794. [
  3795. SRCategory("CategoryAttributeMarker"),
  3796. Bindable(true),
  3797. SRDescription("DescriptionAttributeMarkerSize"),
  3798. RefreshProperties(RefreshProperties.All)
  3799. ]
  3800. public int MarkerSize
  3801. {
  3802. get
  3803. {
  3804. if(this.pointCustomProperties)
  3805. {
  3806. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.MarkerSize))
  3807. {
  3808. return (int)GetAttributeObject(CommonCustomProperties.MarkerSize);
  3809. }
  3810. else
  3811. {
  3812. if(IsSerializing())
  3813. {
  3814. return 5;
  3815. }
  3816. if(this.isEmptyPoint)
  3817. {
  3818. return (int)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.MarkerSize);
  3819. }
  3820. return series.markerSize;
  3821. }
  3822. }
  3823. else
  3824. {
  3825. return series.markerSize;
  3826. }
  3827. }
  3828. set
  3829. {
  3830. if(this.pointCustomProperties)
  3831. SetAttributeObject(CommonCustomProperties.MarkerSize, value);
  3832. else
  3833. series.markerSize = value;
  3834. this.Invalidate(true);
  3835. CallOnModifing();
  3836. }
  3837. }
  3838. /// <summary>
  3839. /// Gets or sets the marker image.
  3840. /// </summary>
  3841. [
  3842. SRCategory("CategoryAttributeMarker"),
  3843. Bindable(true),
  3844. SRDescription("DescriptionAttributeMarkerImage"),
  3845. #if DESIGNER
  3846. Editor(typeof(ImageValueEditor), typeof(UITypeEditor)),
  3847. #endif
  3848. RefreshProperties(RefreshProperties.All)
  3849. ]
  3850. public string MarkerImage
  3851. {
  3852. get
  3853. {
  3854. if(this.pointCustomProperties)
  3855. {
  3856. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.MarkerImage))
  3857. {
  3858. return (string)GetAttributeObject(CommonCustomProperties.MarkerImage);
  3859. }
  3860. else
  3861. {
  3862. if(IsSerializing())
  3863. {
  3864. return "";
  3865. }
  3866. if(this.isEmptyPoint)
  3867. {
  3868. return (string)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.MarkerImage);
  3869. }
  3870. return series.markerImage;
  3871. }
  3872. }
  3873. else
  3874. {
  3875. return series.markerImage;
  3876. }
  3877. }
  3878. set
  3879. {
  3880. // Replace NULL with empty string
  3881. if(value == null)
  3882. {
  3883. value = string.Empty;
  3884. }
  3885. if(this.pointCustomProperties)
  3886. SetAttributeObject(CommonCustomProperties.MarkerImage, value);
  3887. else
  3888. series.markerImage = value;
  3889. this.Invalidate(true);
  3890. CallOnModifing();
  3891. }
  3892. }
  3893. /// <summary>
  3894. /// Gets or sets the color which will be replaced with a transparent color while drawing the marker image.
  3895. /// </summary>
  3896. [
  3897. SRCategory("CategoryAttributeMarker"),
  3898. Bindable(true),
  3899. SRDescription("DescriptionAttributeImageTransparentColor"),
  3900. TypeConverter(typeof(ColorConverter)),
  3901. #if DESIGNER
  3902. Editor(typeof(ChartColorEditor), typeof(UITypeEditor)),
  3903. #endif
  3904. RefreshProperties(RefreshProperties.All)
  3905. ]
  3906. public Color MarkerImageTransparentColor
  3907. {
  3908. get
  3909. {
  3910. if(this.pointCustomProperties)
  3911. {
  3912. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.MarkerImageTransparentColor))
  3913. {
  3914. return (Color)GetAttributeObject(CommonCustomProperties.MarkerImageTransparentColor);
  3915. }
  3916. else
  3917. {
  3918. if(IsSerializing())
  3919. {
  3920. return Color.Empty;
  3921. }
  3922. if(this.isEmptyPoint)
  3923. {
  3924. return (Color)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.MarkerImageTransparentColor);
  3925. }
  3926. return series.markerImageTransparentColor;
  3927. }
  3928. }
  3929. else
  3930. {
  3931. return series.markerImageTransparentColor;
  3932. }
  3933. }
  3934. set
  3935. {
  3936. if(this.pointCustomProperties)
  3937. SetAttributeObject(CommonCustomProperties.MarkerImageTransparentColor, value);
  3938. else
  3939. series.markerImageTransparentColor = value;
  3940. this.Invalidate(true);
  3941. CallOnModifing();
  3942. }
  3943. }
  3944. /// <summary>
  3945. /// Gets or sets the marker color.
  3946. /// </summary>
  3947. [
  3948. SRCategory("CategoryAttributeMarker"),
  3949. Bindable(true),
  3950. SRDescription("DescriptionAttributeMarkerColor3"),
  3951. TypeConverter(typeof(ColorConverter)),
  3952. #if DESIGNER
  3953. Editor(typeof(ChartColorEditor), typeof(UITypeEditor)),
  3954. #endif
  3955. RefreshProperties(RefreshProperties.All)
  3956. ]
  3957. public Color MarkerColor
  3958. {
  3959. get
  3960. {
  3961. if(this.pointCustomProperties)
  3962. {
  3963. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.MarkerColor))
  3964. {
  3965. return (Color)GetAttributeObject(CommonCustomProperties.MarkerColor);
  3966. }
  3967. else
  3968. {
  3969. if(IsSerializing())
  3970. {
  3971. return Color.Empty;
  3972. }
  3973. if(this.isEmptyPoint)
  3974. {
  3975. return (Color)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.MarkerColor);
  3976. }
  3977. return series.markerColor;
  3978. }
  3979. }
  3980. else
  3981. {
  3982. return series.markerColor;
  3983. }
  3984. }
  3985. set
  3986. {
  3987. if(this.pointCustomProperties)
  3988. SetAttributeObject(CommonCustomProperties.MarkerColor, value);
  3989. else
  3990. series.markerColor = value;
  3991. this.Invalidate(true);
  3992. CallOnModifing();
  3993. }
  3994. }
  3995. /// <summary>
  3996. /// Gets or sets the border color of the marker.
  3997. /// </summary>
  3998. [
  3999. SRCategory("CategoryAttributeMarker"),
  4000. Bindable(true),
  4001. SRDescription("DescriptionAttributeMarkerBorderColor"),
  4002. TypeConverter(typeof(ColorConverter)),
  4003. #if DESIGNER
  4004. Editor(typeof(ChartColorEditor), typeof(UITypeEditor)),
  4005. #endif
  4006. RefreshProperties(RefreshProperties.All)
  4007. ]
  4008. public Color MarkerBorderColor
  4009. {
  4010. get
  4011. {
  4012. if(this.pointCustomProperties)
  4013. {
  4014. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.MarkerBorderColor))
  4015. {
  4016. return (Color)GetAttributeObject(CommonCustomProperties.MarkerBorderColor);
  4017. }
  4018. else
  4019. {
  4020. if(IsSerializing())
  4021. {
  4022. return Color.Empty;
  4023. }
  4024. if(this.isEmptyPoint)
  4025. {
  4026. return (Color)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.MarkerBorderColor);
  4027. }
  4028. return series.markerBorderColor;
  4029. }
  4030. }
  4031. else
  4032. {
  4033. return series.markerBorderColor;
  4034. }
  4035. }
  4036. set
  4037. {
  4038. if(this.pointCustomProperties)
  4039. SetAttributeObject(CommonCustomProperties.MarkerBorderColor, value);
  4040. else
  4041. series.markerBorderColor = value;
  4042. this.Invalidate(true);
  4043. CallOnModifing();
  4044. }
  4045. }
  4046. /// <summary>
  4047. /// Gets or sets the border width of the marker.
  4048. /// </summary>
  4049. [
  4050. SRCategory("CategoryAttributeMarker"),
  4051. Bindable(true),
  4052. SRDescription("DescriptionAttributeMarkerBorderWidth")
  4053. ]
  4054. public int MarkerBorderWidth
  4055. {
  4056. get
  4057. {
  4058. if(this.pointCustomProperties)
  4059. {
  4060. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.MarkerBorderWidth))
  4061. {
  4062. return (int)GetAttributeObject(CommonCustomProperties.MarkerBorderWidth);
  4063. }
  4064. else
  4065. {
  4066. if(IsSerializing())
  4067. {
  4068. return 1;
  4069. }
  4070. if(this.isEmptyPoint)
  4071. {
  4072. return (int)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.MarkerBorderWidth);
  4073. }
  4074. return series.markerBorderWidth;
  4075. }
  4076. }
  4077. else
  4078. {
  4079. return series.markerBorderWidth;
  4080. }
  4081. }
  4082. set
  4083. {
  4084. if(value < 0)
  4085. {
  4086. throw (new ArgumentOutOfRangeException("value", SR.ExceptionBorderWidthIsNotPositive));
  4087. }
  4088. if(this.pointCustomProperties)
  4089. SetAttributeObject(CommonCustomProperties.MarkerBorderWidth, value);
  4090. else
  4091. series.markerBorderWidth = value;
  4092. this.Invalidate(true);
  4093. CallOnModifing();
  4094. }
  4095. }
  4096. /// <summary>
  4097. /// Gets or sets the extended custom properties of the data point.
  4098. /// Extended custom properties can be specified in the following format:
  4099. /// AttrName1=Value1, AttrName2=Value2, ...
  4100. /// </summary>
  4101. [
  4102. SRCategory("CategoryAttributeMisc"),
  4103. Bindable(false),
  4104. SRDescription("DescriptionAttributeCustomAttributesExtended"),
  4105. DefaultValue(null),
  4106. RefreshProperties(RefreshProperties.All),
  4107. NotifyParentPropertyAttribute(true),
  4108. DesignOnlyAttribute(true),
  4109. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
  4110. SerializationVisibilityAttribute(SerializationVisibility.Hidden),
  4111. EditorBrowsableAttribute(EditorBrowsableState.Never),
  4112. DisplayName("CustomProperties")
  4113. ]
  4114. public CustomProperties CustomPropertiesExtended
  4115. {
  4116. set
  4117. {
  4118. customProperties = value;
  4119. CallOnModifing();
  4120. }
  4121. get
  4122. {
  4123. return customProperties;
  4124. }
  4125. }
  4126. /// <summary>
  4127. /// Gets or sets the custom properties of the data point.
  4128. /// Custom properties can be specified in the following format:
  4129. /// AttrName1=Value1, AttrName2=Value2, ...
  4130. /// </summary>
  4131. [
  4132. SRCategory("CategoryAttributeMisc"),
  4133. Bindable(true),
  4134. Browsable(false),
  4135. SRDescription("DescriptionAttributeCustomAttributesExtended"),
  4136. DefaultValue("")
  4137. ]
  4138. public string CustomProperties
  4139. {
  4140. get
  4141. {
  4142. // Save all custom properties in a string
  4143. string result = "";
  4144. string[] attributesNames = CommonCustomProperties.GetNames(typeof(CommonCustomProperties));
  4145. for(int i = properties.Count - 1; i >= 0; i--)
  4146. {
  4147. if(this[i] != null)
  4148. {
  4149. string attributeName = this[i];
  4150. // Check if attribute is custom
  4151. bool customAttribute = true;
  4152. foreach(string name in attributesNames)
  4153. {
  4154. if(String.Compare(attributeName, name, StringComparison.OrdinalIgnoreCase) == 0)
  4155. {
  4156. customAttribute = false;
  4157. break;
  4158. }
  4159. }
  4160. // Add custom attribute to the string
  4161. if(customAttribute && properties[attributeName] != null)
  4162. {
  4163. if(result.Length > 0)
  4164. {
  4165. result += ", ";
  4166. }
  4167. string attributeValue = properties[attributeName].ToString().Replace(",", "\\,");
  4168. attributeValue = attributeValue.Replace("=", "\\=");
  4169. result += attributeName + "=" + attributeValue;
  4170. }
  4171. }
  4172. }
  4173. return result;
  4174. }
  4175. set
  4176. {
  4177. // Replace NULL with empty string
  4178. if(value == null)
  4179. {
  4180. value = string.Empty;
  4181. }
  4182. // Copy all common properties to the new collection
  4183. Hashtable newAttributes = new Hashtable();
  4184. Array enumValues = Enum.GetValues(typeof(CommonCustomProperties));
  4185. foreach(object val in enumValues)
  4186. {
  4187. if(IsCustomPropertySet((CommonCustomProperties)val))
  4188. {
  4189. newAttributes[(int)val] = properties[(int)val];
  4190. }
  4191. }
  4192. if(value.Length > 0)
  4193. {
  4194. // Replace commas in value string
  4195. value = value.Replace("\\,", "\\x45");
  4196. value = value.Replace("\\=", "\\x46");
  4197. // Add new custom properties
  4198. string[] nameValueStrings = value.Split(',');
  4199. foreach(string nameValue in nameValueStrings)
  4200. {
  4201. string[] values = nameValue.Split('=');
  4202. // Check format
  4203. if(values.Length != 2)
  4204. {
  4205. throw(new FormatException( SR.ExceptionAttributeInvalidFormat));
  4206. }
  4207. // Check for empty name or value
  4208. values[0] = values[0].Trim();
  4209. values[1] = values[1].Trim();
  4210. if(values[0].Length == 0)
  4211. {
  4212. throw(new FormatException( SR.ExceptionAttributeInvalidFormat));
  4213. }
  4214. // Check if value already defined
  4215. foreach(object existingAttributeName in newAttributes.Keys)
  4216. {
  4217. string existingAttributeNameStr = existingAttributeName as string;
  4218. if (existingAttributeNameStr != null)
  4219. {
  4220. if (String.Compare(existingAttributeNameStr, values[0], StringComparison.OrdinalIgnoreCase) == 0)
  4221. {
  4222. throw(new FormatException( SR.ExceptionAttributeNameIsNotUnique(values[0] ) ) );
  4223. }
  4224. }
  4225. }
  4226. string newValue = values[1].Replace("\\x45", ",");
  4227. newAttributes[values[0]] = newValue.Replace("\\x46", "=");
  4228. }
  4229. }
  4230. properties = newAttributes;
  4231. this.Invalidate(true);
  4232. }
  4233. }
  4234. #endregion
  4235. #region IMapAreaAttributesutes Properties implementation
  4236. /// <summary>
  4237. /// Tooltip.
  4238. /// </summary>
  4239. [
  4240. SRCategory("CategoryAttributeMapArea"),
  4241. Bindable(true),
  4242. SRDescription("DescriptionAttributeToolTip"),
  4243. #if DESIGNER
  4244. Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)),
  4245. #endif
  4246. ]
  4247. public string ToolTip
  4248. {
  4249. set
  4250. {
  4251. if(this.pointCustomProperties)
  4252. SetAttributeObject(CommonCustomProperties.ToolTip, value);
  4253. else
  4254. series.toolTip = value;
  4255. if(Chart != null && Chart.selection != null)
  4256. {
  4257. Chart.selection.enabledChecked = false;
  4258. }
  4259. }
  4260. get
  4261. {
  4262. if(this.pointCustomProperties)
  4263. {
  4264. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.ToolTip))
  4265. {
  4266. return (String)GetAttributeObject(CommonCustomProperties.ToolTip);
  4267. }
  4268. else
  4269. {
  4270. if(IsSerializing())
  4271. {
  4272. return "";
  4273. }
  4274. if(this.isEmptyPoint)
  4275. {
  4276. return (string)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.ToolTip);
  4277. }
  4278. return series.toolTip;
  4279. }
  4280. }
  4281. else
  4282. {
  4283. return series.toolTip;
  4284. }
  4285. }
  4286. }
  4287. /// <summary>
  4288. /// Replaces predefined keyword inside the string with their values.
  4289. /// </summary>
  4290. /// <param name="strOriginal">Original string with keywords.</param>
  4291. /// <returns>Modified string.</returns>
  4292. internal virtual string ReplaceKeywords(string strOriginal)
  4293. {
  4294. return strOriginal;
  4295. }
  4296. #endregion
  4297. #region Legend properties
  4298. /// <summary>
  4299. /// Indicates whether the item is shown in the legend.
  4300. /// </summary>
  4301. [
  4302. SRCategory("CategoryAttributeLegend"),
  4303. Bindable(true),
  4304. SRDescription("DescriptionAttributeShowInLegend")
  4305. ]
  4306. public bool IsVisibleInLegend
  4307. {
  4308. get
  4309. {
  4310. if(this.pointCustomProperties)
  4311. {
  4312. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.IsVisibleInLegend))
  4313. {
  4314. return (bool)GetAttributeObject(CommonCustomProperties.IsVisibleInLegend);
  4315. }
  4316. else
  4317. {
  4318. if(IsSerializing())
  4319. {
  4320. return true;
  4321. }
  4322. if(this.isEmptyPoint)
  4323. {
  4324. return (bool)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.IsVisibleInLegend);
  4325. }
  4326. return series.showInLegend;
  4327. }
  4328. }
  4329. else
  4330. {
  4331. return series.showInLegend;
  4332. }
  4333. }
  4334. set
  4335. {
  4336. if(this.pointCustomProperties)
  4337. SetAttributeObject(CommonCustomProperties.IsVisibleInLegend, value);
  4338. else
  4339. series.showInLegend = value;
  4340. this.Invalidate(true);
  4341. CallOnModifing();
  4342. }
  4343. }
  4344. /// <summary>
  4345. /// Text of the item in the legend
  4346. /// </summary>
  4347. [
  4348. SRCategory("CategoryAttributeLegend"),
  4349. Bindable(true),
  4350. SRDescription("DescriptionAttributeLegendText"),
  4351. #if DESIGNER
  4352. Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)),
  4353. #endif
  4354. ]
  4355. public string LegendText
  4356. {
  4357. set
  4358. {
  4359. if(this.pointCustomProperties)
  4360. SetAttributeObject(CommonCustomProperties.LegendText, value);
  4361. else
  4362. series.legendText = value;
  4363. this.Invalidate(true);
  4364. CallOnModifing();
  4365. }
  4366. get
  4367. {
  4368. if(this.pointCustomProperties)
  4369. {
  4370. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.LegendText))
  4371. {
  4372. return (String)GetAttributeObject(CommonCustomProperties.LegendText);
  4373. }
  4374. else
  4375. {
  4376. if(IsSerializing())
  4377. {
  4378. return "";
  4379. }
  4380. if(this.isEmptyPoint)
  4381. {
  4382. return (string)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.LegendText);
  4383. }
  4384. return series.legendText;
  4385. }
  4386. }
  4387. else
  4388. {
  4389. return series.legendText;
  4390. }
  4391. }
  4392. }
  4393. /// <summary>
  4394. /// Tooltip of the item in the legend
  4395. /// </summary>
  4396. [
  4397. SRCategory("CategoryAttributeLegend"),
  4398. Bindable(true),
  4399. SRDescription("DescriptionAttributeLegendToolTip"),
  4400. #if DESIGNER
  4401. Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)),
  4402. #endif
  4403. ]
  4404. public string LegendToolTip
  4405. {
  4406. set
  4407. {
  4408. if(this.pointCustomProperties)
  4409. SetAttributeObject(CommonCustomProperties.LegendToolTip, value);
  4410. else
  4411. series.legendToolTip = value;
  4412. if(Chart != null && Chart.selection != null)
  4413. {
  4414. Chart.selection.enabledChecked = false;
  4415. }
  4416. CallOnModifing();
  4417. }
  4418. get
  4419. {
  4420. if(this.pointCustomProperties)
  4421. {
  4422. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.LegendToolTip))
  4423. {
  4424. return (String)GetAttributeObject(CommonCustomProperties.LegendToolTip);
  4425. }
  4426. else
  4427. {
  4428. if(IsSerializing())
  4429. {
  4430. return "";
  4431. }
  4432. if(this.isEmptyPoint)
  4433. {
  4434. return (string)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.LegendToolTip);
  4435. }
  4436. return series.legendToolTip;
  4437. }
  4438. }
  4439. else
  4440. {
  4441. return series.legendToolTip;
  4442. }
  4443. }
  4444. }
  4445. /// <summary>
  4446. /// Background color of the data point label.
  4447. /// </summary>
  4448. [
  4449. SRCategory("CategoryAttributeLabelAppearance"),
  4450. Bindable(true),
  4451. SRDescription("DescriptionAttributeLabelBackColor"),
  4452. TypeConverter(typeof(ColorConverter)),
  4453. #if DESIGNER
  4454. Editor(typeof(ChartColorEditor), typeof(UITypeEditor)),
  4455. #endif
  4456. DefaultValue(typeof(Color), ""),
  4457. ]
  4458. public Color LabelBackColor
  4459. {
  4460. get
  4461. {
  4462. if(this.pointCustomProperties)
  4463. {
  4464. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.LabelBackColor))
  4465. {
  4466. return (Color)GetAttributeObject(CommonCustomProperties.LabelBackColor);
  4467. }
  4468. else
  4469. {
  4470. if(IsSerializing())
  4471. {
  4472. return Color.Empty;
  4473. }
  4474. if(this.isEmptyPoint)
  4475. {
  4476. return (Color)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.LabelBackColor);
  4477. }
  4478. if(SystemInformation.HighContrast)
  4479. {
  4480. return SystemColors.Window;
  4481. }
  4482. return series.labelBackColor;
  4483. }
  4484. }
  4485. else
  4486. {
  4487. return series.labelBackColor;
  4488. }
  4489. }
  4490. set
  4491. {
  4492. if(this.pointCustomProperties)
  4493. SetAttributeObject(CommonCustomProperties.LabelBackColor, value);
  4494. else
  4495. series.labelBackColor = value;
  4496. this.Invalidate(true);
  4497. CallOnModifing();
  4498. }
  4499. }
  4500. /// <summary>
  4501. /// Border color of the data point label.
  4502. /// </summary>
  4503. [
  4504. SRCategory("CategoryAttributeLabelAppearance"),
  4505. Bindable(true),
  4506. SRDescription("DescriptionAttributeBorderColor"),
  4507. TypeConverter(typeof(ColorConverter)),
  4508. #if DESIGNER
  4509. Editor(typeof(ChartColorEditor), typeof(UITypeEditor)),
  4510. #endif
  4511. DefaultValue(typeof(Color), ""),
  4512. ]
  4513. public Color LabelBorderColor
  4514. {
  4515. get
  4516. {
  4517. if(this.pointCustomProperties)
  4518. {
  4519. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.LabelBorderColor))
  4520. {
  4521. return (Color)GetAttributeObject(CommonCustomProperties.LabelBorderColor);
  4522. }
  4523. else
  4524. {
  4525. if(IsSerializing())
  4526. {
  4527. return Color.Empty;
  4528. }
  4529. if(this.isEmptyPoint)
  4530. {
  4531. return (Color)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.LabelBorderColor);
  4532. }
  4533. if(SystemInformation.HighContrast)
  4534. {
  4535. return SystemColors.ActiveBorder;
  4536. }
  4537. return series.labelBorderColor;
  4538. }
  4539. }
  4540. else
  4541. {
  4542. return series.labelBorderColor;
  4543. }
  4544. }
  4545. set
  4546. {
  4547. if(this.pointCustomProperties)
  4548. SetAttributeObject(CommonCustomProperties.LabelBorderColor, value);
  4549. else
  4550. series.labelBorderColor = value;
  4551. this.Invalidate(true);
  4552. CallOnModifing();
  4553. }
  4554. }
  4555. /// <summary>
  4556. /// Border style of the label.
  4557. /// </summary>
  4558. [
  4559. SRCategory("CategoryAttributeLabelAppearance"),
  4560. Bindable(true),
  4561. SRDescription("DescriptionAttributeLabelBorderDashStyle")
  4562. ]
  4563. public ChartDashStyle LabelBorderDashStyle
  4564. {
  4565. get
  4566. {
  4567. if(this.pointCustomProperties)
  4568. {
  4569. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.LabelBorderDashStyle))
  4570. {
  4571. return (ChartDashStyle)GetAttributeObject(CommonCustomProperties.LabelBorderDashStyle);
  4572. }
  4573. else
  4574. {
  4575. if(IsSerializing())
  4576. {
  4577. return ChartDashStyle.Solid;
  4578. }
  4579. if(this.isEmptyPoint)
  4580. {
  4581. return (ChartDashStyle)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.LabelBorderDashStyle);
  4582. }
  4583. return series.labelBorderDashStyle;
  4584. }
  4585. }
  4586. else
  4587. {
  4588. return series.labelBorderDashStyle;
  4589. }
  4590. }
  4591. set
  4592. {
  4593. if(this.pointCustomProperties)
  4594. SetAttributeObject(CommonCustomProperties.LabelBorderDashStyle, value);
  4595. else
  4596. series.labelBorderDashStyle = value;
  4597. this.Invalidate(true);
  4598. CallOnModifing();
  4599. }
  4600. }
  4601. /// <summary>
  4602. /// Border width of the label.
  4603. /// </summary>
  4604. [
  4605. SRCategory("CategoryAttributeLabelAppearance"),
  4606. Bindable(true),
  4607. SRDescription("DescriptionAttributeBorderWidth")
  4608. ]
  4609. public int LabelBorderWidth
  4610. {
  4611. get
  4612. {
  4613. if(this.pointCustomProperties)
  4614. {
  4615. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.LabelBorderWidth))
  4616. {
  4617. return (int)GetAttributeObject(CommonCustomProperties.LabelBorderWidth);
  4618. }
  4619. else
  4620. {
  4621. if(IsSerializing())
  4622. {
  4623. return 1;
  4624. }
  4625. if(this.isEmptyPoint)
  4626. {
  4627. return (int)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.LabelBorderWidth);
  4628. }
  4629. return series.labelBorderWidth;
  4630. }
  4631. }
  4632. else
  4633. {
  4634. return series.labelBorderWidth;
  4635. }
  4636. }
  4637. set
  4638. {
  4639. if(value < 0)
  4640. {
  4641. throw(new ArgumentOutOfRangeException("value", SR.ExceptionLabelBorderIsNotPositive));
  4642. }
  4643. if(this.pointCustomProperties)
  4644. SetAttributeObject(CommonCustomProperties.LabelBorderWidth, value);
  4645. else
  4646. series.labelBorderWidth = value;
  4647. this.Invalidate(true);
  4648. CallOnModifing();
  4649. }
  4650. }
  4651. /// <summary>
  4652. /// Tooltip of the data point label.
  4653. /// </summary>
  4654. [
  4655. SRCategory("CategoryAttributeLabel"),
  4656. Bindable(true),
  4657. SRDescription("DescriptionAttributeLabelToolTip"),
  4658. #if DESIGNER
  4659. Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)),
  4660. #endif
  4661. ]
  4662. public string LabelToolTip
  4663. {
  4664. set
  4665. {
  4666. if(this.pointCustomProperties)
  4667. SetAttributeObject(CommonCustomProperties.LabelToolTip, value);
  4668. else
  4669. series.labelToolTip = value;
  4670. if(Chart != null && Chart.selection != null)
  4671. {
  4672. Chart.selection.enabledChecked = false;
  4673. }
  4674. CallOnModifing();
  4675. }
  4676. get
  4677. {
  4678. if(this.pointCustomProperties)
  4679. {
  4680. if(properties.Count != 0 && IsCustomPropertySet(CommonCustomProperties.LabelToolTip))
  4681. {
  4682. return (String)GetAttributeObject(CommonCustomProperties.LabelToolTip);
  4683. }
  4684. else
  4685. {
  4686. if(IsSerializing())
  4687. {
  4688. return "";
  4689. }
  4690. if(this.isEmptyPoint)
  4691. {
  4692. return (string)series.EmptyPointStyle.GetAttributeObject(CommonCustomProperties.LabelToolTip);
  4693. }
  4694. return series.labelToolTip;
  4695. }
  4696. }
  4697. else
  4698. {
  4699. return series.labelToolTip;
  4700. }
  4701. }
  4702. }
  4703. #endregion
  4704. #region Serialization control
  4705. private bool CheckIfSerializationRequired(CommonCustomProperties attribute)
  4706. {
  4707. if(this is DataPoint)
  4708. {
  4709. return IsCustomPropertySet(attribute);
  4710. }
  4711. else
  4712. {
  4713. object attr1 = this.GetAttributeObject(attribute);
  4714. object attr2 = Series.defaultCustomProperties.GetAttributeObject(attribute);
  4715. if(attr1 == null || attr2 == null)
  4716. {
  4717. return false;
  4718. }
  4719. return ! attr1.Equals(attr2);
  4720. }
  4721. }
  4722. private void ResetProperty(CommonCustomProperties attribute)
  4723. {
  4724. if(this is DataPoint)
  4725. {
  4726. DeleteCustomProperty(attribute);
  4727. }
  4728. else
  4729. {
  4730. this.SetAttributeObject(attribute, Series.defaultCustomProperties.GetAttributeObject(attribute));
  4731. }
  4732. }
  4733. /// <summary>
  4734. /// Returns true if property should be serialized.
  4735. /// </summary>
  4736. internal bool ShouldSerializeLabel()
  4737. {
  4738. if(this.pointCustomProperties)
  4739. return CheckIfSerializationRequired(CommonCustomProperties.Label);
  4740. else
  4741. return !String.IsNullOrEmpty(series.label);
  4742. }
  4743. /// <summary>
  4744. /// Returns true if property should be serialized.
  4745. /// </summary>
  4746. internal bool ShouldSerializeAxisLabel()
  4747. {
  4748. if(this.pointCustomProperties)
  4749. return CheckIfSerializationRequired(CommonCustomProperties.AxisLabel);
  4750. else
  4751. return !String.IsNullOrEmpty(series.axisLabel);
  4752. }
  4753. /// <summary>
  4754. /// Returns true if property should be serialized.
  4755. /// </summary>
  4756. internal bool ShouldSerializeLabelFormat()
  4757. {
  4758. if(this.pointCustomProperties)
  4759. return CheckIfSerializationRequired(CommonCustomProperties.LabelFormat);
  4760. else
  4761. return !String.IsNullOrEmpty(series.labelFormat);
  4762. }
  4763. /// <summary>
  4764. /// Returns true if property should be serialized.
  4765. /// </summary>
  4766. internal bool ShouldSerializeIsValueShownAsLabel()
  4767. {
  4768. if(this.pointCustomProperties)
  4769. return CheckIfSerializationRequired(CommonCustomProperties.IsValueShownAsLabel);
  4770. else
  4771. return series.showLabelAsValue != false;
  4772. }
  4773. /// <summary>
  4774. /// Returns true if property should be serialized.
  4775. /// </summary>
  4776. internal bool ShouldSerializeColor()
  4777. {
  4778. if(this.pointCustomProperties)
  4779. return CheckIfSerializationRequired(CommonCustomProperties.Color);
  4780. else
  4781. return series.color != Color.Empty;
  4782. }
  4783. /// <summary>
  4784. /// Returns true if property should be serialized.
  4785. /// </summary>
  4786. internal bool ShouldSerializeBorderColor()
  4787. {
  4788. if(this.pointCustomProperties)
  4789. return CheckIfSerializationRequired(CommonCustomProperties.BorderColor);
  4790. else
  4791. return series.borderColor != Color.Empty;
  4792. }
  4793. /// <summary>
  4794. /// Returns true if property should be serialized.
  4795. /// </summary>
  4796. internal bool ShouldSerializeBorderDashStyle()
  4797. {
  4798. if(this.pointCustomProperties)
  4799. return CheckIfSerializationRequired(CommonCustomProperties.BorderDashStyle);
  4800. else
  4801. return series.borderDashStyle != ChartDashStyle.Solid;
  4802. }
  4803. /// <summary>
  4804. /// Returns true if property should be serialized.
  4805. /// </summary>
  4806. internal bool ShouldSerializeBorderWidth()
  4807. {
  4808. if(this.pointCustomProperties)
  4809. return CheckIfSerializationRequired(CommonCustomProperties.BorderWidth);
  4810. else
  4811. return series.borderWidth != 1;
  4812. }
  4813. /// <summary>
  4814. /// Returns true if property should be serialized.
  4815. /// </summary>
  4816. internal bool ShouldSerializeMarkerBorderWidth()
  4817. {
  4818. if(this.pointCustomProperties)
  4819. return CheckIfSerializationRequired(CommonCustomProperties.MarkerBorderWidth);
  4820. else
  4821. return series.markerBorderWidth != 1;
  4822. }
  4823. /// <summary>
  4824. /// Returns true if property should be serialized.
  4825. /// </summary>
  4826. internal bool ShouldSerializeBackImage()
  4827. {
  4828. if(this.pointCustomProperties)
  4829. return CheckIfSerializationRequired(CommonCustomProperties.BackImage);
  4830. else
  4831. return !String.IsNullOrEmpty(series.backImage);
  4832. }
  4833. /// <summary>
  4834. /// Returns true if property should be serialized.
  4835. /// </summary>
  4836. internal bool ShouldSerializeBackImageWrapMode()
  4837. {
  4838. if(this.pointCustomProperties)
  4839. return CheckIfSerializationRequired(CommonCustomProperties.BackImageWrapMode);
  4840. else
  4841. return series.backImageWrapMode != ChartImageWrapMode.Tile;
  4842. }
  4843. /// <summary>
  4844. /// Returns true if property should be serialized.
  4845. /// </summary>
  4846. internal bool ShouldSerializeBackImageTransparentColor()
  4847. {
  4848. if(this.pointCustomProperties)
  4849. return CheckIfSerializationRequired(CommonCustomProperties.BackImageTransparentColor);
  4850. else
  4851. return series.backImageTransparentColor != Color.Empty;
  4852. }
  4853. /// <summary>
  4854. /// Returns true if property should be serialized.
  4855. /// </summary>
  4856. internal bool ShouldSerializeBackImageAlignment()
  4857. {
  4858. if(this.pointCustomProperties)
  4859. return CheckIfSerializationRequired(CommonCustomProperties.BackImageAlignment);
  4860. else
  4861. return series.backImageAlignment != ChartImageAlignmentStyle.TopLeft;
  4862. }
  4863. /// <summary>
  4864. /// Returns true if property should be serialized.
  4865. /// </summary>
  4866. internal bool ShouldSerializeBackGradientStyle()
  4867. {
  4868. if(this.pointCustomProperties)
  4869. return CheckIfSerializationRequired(CommonCustomProperties.BackGradientStyle);
  4870. else
  4871. return series.backGradientStyle != GradientStyle.None;
  4872. }
  4873. /// <summary>
  4874. /// Returns true if property should be serialized.
  4875. /// </summary>
  4876. internal bool ShouldSerializeBackSecondaryColor()
  4877. {
  4878. if(this.pointCustomProperties)
  4879. return CheckIfSerializationRequired(CommonCustomProperties.BackSecondaryColor);
  4880. else
  4881. return series.backSecondaryColor != Color.Empty;
  4882. }
  4883. /// <summary>
  4884. /// Returns true if property should be serialized.
  4885. /// </summary>
  4886. internal bool ShouldSerializeBackHatchStyle()
  4887. {
  4888. if(this.pointCustomProperties)
  4889. return CheckIfSerializationRequired(CommonCustomProperties.BackHatchStyle);
  4890. else
  4891. return series.backHatchStyle != ChartHatchStyle.None;
  4892. }
  4893. /// <summary>
  4894. /// Returns true if property should be serialized.
  4895. /// </summary>
  4896. internal bool ShouldSerializeFont()
  4897. {
  4898. if(this.pointCustomProperties)
  4899. return CheckIfSerializationRequired(CommonCustomProperties.Font);
  4900. else
  4901. {
  4902. return series.font != series.FontCache.DefaultFont;
  4903. }
  4904. }
  4905. /// <summary>
  4906. /// Returns true if property should be serialized.
  4907. /// </summary>
  4908. internal bool ShouldSerializeLabelForeColor()
  4909. {
  4910. if(this.pointCustomProperties)
  4911. return CheckIfSerializationRequired(CommonCustomProperties.LabelForeColor);
  4912. else
  4913. return series.fontColor != Color.Black;
  4914. }
  4915. /// <summary>
  4916. /// Returns true if property should be serialized.
  4917. /// </summary>
  4918. internal bool ShouldSerializeLabelAngle()
  4919. {
  4920. if(this.pointCustomProperties)
  4921. return CheckIfSerializationRequired(CommonCustomProperties.LabelAngle);
  4922. else
  4923. return series.fontAngle != 0f;
  4924. }
  4925. /// <summary>
  4926. /// Returns true if property should be serialized.
  4927. /// </summary>
  4928. internal bool ShouldSerializeMarkerStyle()
  4929. {
  4930. if(this.pointCustomProperties)
  4931. return CheckIfSerializationRequired(CommonCustomProperties.MarkerStyle);
  4932. else
  4933. return series.markerStyle != MarkerStyle.None;
  4934. }
  4935. /// <summary>
  4936. /// Returns true if property should be serialized.
  4937. /// </summary>
  4938. internal bool ShouldSerializeMarkerSize()
  4939. {
  4940. if(this.pointCustomProperties)
  4941. return CheckIfSerializationRequired(CommonCustomProperties.MarkerSize);
  4942. else
  4943. return series.markerSize != 5;
  4944. }
  4945. /// <summary>
  4946. /// Returns true if property should be serialized.
  4947. /// </summary>
  4948. internal bool ShouldSerializeMarkerImage()
  4949. {
  4950. if(this.pointCustomProperties)
  4951. return CheckIfSerializationRequired(CommonCustomProperties.MarkerImage);
  4952. else
  4953. return !String.IsNullOrEmpty(series.markerImage);
  4954. }
  4955. /// <summary>
  4956. /// Returns true if property should be serialized.
  4957. /// </summary>
  4958. internal bool ShouldSerializeMarkerImageTransparentColor()
  4959. {
  4960. if(this.pointCustomProperties)
  4961. return CheckIfSerializationRequired(CommonCustomProperties.MarkerImageTransparentColor);
  4962. else
  4963. return series.markerImageTransparentColor != Color.Empty;
  4964. }
  4965. /// <summary>
  4966. /// Returns true if property should be serialized.
  4967. /// </summary>
  4968. internal bool ShouldSerializeMarkerColor()
  4969. {
  4970. if(this.pointCustomProperties)
  4971. return CheckIfSerializationRequired(CommonCustomProperties.MarkerColor);
  4972. else
  4973. return series.markerColor != Color.Empty;
  4974. }
  4975. /// <summary>
  4976. /// Returns true if property should be serialized.
  4977. /// </summary>
  4978. internal bool ShouldSerializeMarkerBorderColor()
  4979. {
  4980. if(this.pointCustomProperties)
  4981. return CheckIfSerializationRequired(CommonCustomProperties.MarkerBorderColor);
  4982. else
  4983. return series.markerBorderColor != Color.Empty;
  4984. }
  4985. /// <summary>
  4986. /// Returns true if property should be serialized.
  4987. /// </summary>
  4988. internal bool ShouldSerializeToolTip()
  4989. {
  4990. if(this.pointCustomProperties)
  4991. return CheckIfSerializationRequired(CommonCustomProperties.ToolTip);
  4992. else
  4993. return !String.IsNullOrEmpty(series.toolTip);
  4994. }
  4995. /// <summary>
  4996. /// Returns true if property should be serialized.
  4997. /// </summary>
  4998. internal bool ShouldSerializeIsVisibleInLegend()
  4999. {
  5000. if(this.pointCustomProperties)
  5001. return CheckIfSerializationRequired(CommonCustomProperties.IsVisibleInLegend);
  5002. else
  5003. return series.showInLegend != true;
  5004. }
  5005. /// <summary>
  5006. /// Returns true if property should be serialized.
  5007. /// </summary>
  5008. internal bool ShouldSerializeLegendText()
  5009. {
  5010. if(this.pointCustomProperties)
  5011. return CheckIfSerializationRequired(CommonCustomProperties.LegendText);
  5012. else
  5013. return !String.IsNullOrEmpty(series.legendText);
  5014. }
  5015. /// <summary>
  5016. /// Returns true if property should be serialized.
  5017. /// </summary>
  5018. internal bool ShouldSerializeLegendToolTip()
  5019. {
  5020. if(this.pointCustomProperties)
  5021. return CheckIfSerializationRequired(CommonCustomProperties.LegendToolTip);
  5022. else
  5023. return !String.IsNullOrEmpty(series.legendToolTip);
  5024. }
  5025. /// <summary>
  5026. /// Returns true if property should be serialized.
  5027. /// </summary>
  5028. internal bool ShouldSerializeLabelToolTip()
  5029. {
  5030. if(this.pointCustomProperties)
  5031. return CheckIfSerializationRequired(CommonCustomProperties.LabelToolTip);
  5032. else
  5033. return !String.IsNullOrEmpty(series.labelToolTip);
  5034. }
  5035. /// <summary>
  5036. /// Returns true if property should be serialized.
  5037. /// </summary>
  5038. internal bool ShouldSerializeLabelBackColor()
  5039. {
  5040. if(this.pointCustomProperties)
  5041. return CheckIfSerializationRequired(CommonCustomProperties.LabelBackColor);
  5042. else
  5043. return series.labelBackColor != Color.Empty;
  5044. }
  5045. /// <summary>
  5046. /// Returns true if property should be serialized.
  5047. /// </summary>
  5048. internal bool ShouldSerializeLabelBorderColor()
  5049. {
  5050. if(this.pointCustomProperties)
  5051. return CheckIfSerializationRequired(CommonCustomProperties.LabelBorderColor);
  5052. else
  5053. return series.labelBorderColor != Color.Empty;
  5054. }
  5055. /// <summary>
  5056. /// Returns true if property should be serialized.
  5057. /// </summary>
  5058. internal bool ShouldSerializeLabelBorderDashStyle()
  5059. {
  5060. if(this.pointCustomProperties)
  5061. return CheckIfSerializationRequired(CommonCustomProperties.LabelBorderDashStyle);
  5062. else
  5063. return series.labelBorderDashStyle != ChartDashStyle.Solid;
  5064. }
  5065. /// <summary>
  5066. /// Returns true if property should be serialized.
  5067. /// </summary>
  5068. internal bool ShouldSerializeLabelBorderWidth()
  5069. {
  5070. if(this.pointCustomProperties)
  5071. return CheckIfSerializationRequired(CommonCustomProperties.LabelBorderWidth);
  5072. else
  5073. return series.labelBorderWidth != 1;
  5074. }
  5075. /// <summary>
  5076. /// Resets property to its default value.
  5077. /// </summary>
  5078. internal void ResetLabel()
  5079. {
  5080. if(this.pointCustomProperties)
  5081. ResetProperty(CommonCustomProperties.Label);
  5082. else
  5083. series.label = "";
  5084. }
  5085. /// <summary>
  5086. /// Resets property to its default value.
  5087. /// </summary>
  5088. internal void ResetAxisLabel()
  5089. {
  5090. if(this.pointCustomProperties)
  5091. ResetProperty(CommonCustomProperties.AxisLabel);
  5092. else
  5093. series.axisLabel = "";
  5094. }
  5095. /// <summary>
  5096. /// Resets property to its default value.
  5097. /// </summary>
  5098. internal void ResetLabelFormat()
  5099. {
  5100. if(this.pointCustomProperties)
  5101. ResetProperty(CommonCustomProperties.LabelFormat);
  5102. else
  5103. series.labelFormat = "";
  5104. }
  5105. /// <summary>
  5106. /// Resets property to its default value.
  5107. /// </summary>
  5108. public void ResetIsValueShownAsLabel()
  5109. {
  5110. if(this.pointCustomProperties)
  5111. ResetProperty(CommonCustomProperties.IsValueShownAsLabel);
  5112. else
  5113. series.IsValueShownAsLabel = false;
  5114. }
  5115. /// <summary>
  5116. /// Resets property to its default value.
  5117. /// </summary>
  5118. internal void ResetColor()
  5119. {
  5120. if(this.pointCustomProperties)
  5121. ResetProperty(CommonCustomProperties.Color);
  5122. else
  5123. series.color = Color.Empty;
  5124. }
  5125. /// <summary>
  5126. /// Resets property to its default value.
  5127. /// </summary>
  5128. internal void ResetBorderColor()
  5129. {
  5130. if(this.pointCustomProperties)
  5131. ResetProperty(CommonCustomProperties.BorderColor);
  5132. else
  5133. series.borderColor = Color.Empty;
  5134. }
  5135. /// <summary>
  5136. /// Resets property to its default value.
  5137. /// </summary>
  5138. internal void ResetBorderDashStyle()
  5139. {
  5140. if(this.pointCustomProperties)
  5141. ResetProperty(CommonCustomProperties.BorderDashStyle);
  5142. else
  5143. series.borderDashStyle = ChartDashStyle.Solid;
  5144. }
  5145. /// <summary>
  5146. /// Resets property to its default value.
  5147. /// </summary>
  5148. internal void ResetBorderWidth()
  5149. {
  5150. if(this.pointCustomProperties)
  5151. ResetProperty(CommonCustomProperties.BorderWidth);
  5152. else
  5153. series.borderWidth = 1;
  5154. }
  5155. /// <summary>
  5156. /// Resets property to its default value.
  5157. /// </summary>
  5158. internal void ResetMarkerBorderWidth()
  5159. {
  5160. if(this.pointCustomProperties)
  5161. ResetProperty(CommonCustomProperties.MarkerBorderWidth);
  5162. else
  5163. series.markerBorderWidth = 1;
  5164. }
  5165. /// <summary>
  5166. /// Resets property to its default value.
  5167. /// </summary>
  5168. internal void ResetBackImage()
  5169. {
  5170. if(this.pointCustomProperties)
  5171. ResetProperty(CommonCustomProperties.BackImage);
  5172. else
  5173. series.backImage = "";
  5174. }
  5175. /// <summary>
  5176. /// Resets property to its default value.
  5177. /// </summary>
  5178. internal void ResetBackImageWrapMode()
  5179. {
  5180. if(this.pointCustomProperties)
  5181. ResetProperty(CommonCustomProperties.BackImageWrapMode);
  5182. else
  5183. series.backImageWrapMode = ChartImageWrapMode.Tile;
  5184. }
  5185. /// <summary>
  5186. /// Resets property to its default value.
  5187. /// </summary>
  5188. internal void ResetBackImageTransparentColor()
  5189. {
  5190. if(this.pointCustomProperties)
  5191. ResetProperty(CommonCustomProperties.BackImageTransparentColor);
  5192. else
  5193. series.backImageTransparentColor = Color.Empty;
  5194. }
  5195. /// <summary>
  5196. /// Resets property to its default value.
  5197. /// </summary>
  5198. internal void ResetBackSecondaryColor()
  5199. {
  5200. if(this.pointCustomProperties)
  5201. ResetProperty(CommonCustomProperties.BackSecondaryColor);
  5202. else
  5203. series.backSecondaryColor = Color.Empty;
  5204. }
  5205. /// <summary>
  5206. /// Resets property to its default value.
  5207. /// </summary>
  5208. internal void ResetBackHatchStyle()
  5209. {
  5210. if(this.pointCustomProperties)
  5211. ResetProperty(CommonCustomProperties.BackHatchStyle);
  5212. else
  5213. series.backHatchStyle = ChartHatchStyle.None;
  5214. }
  5215. /// <summary>
  5216. /// Resets property to its default value.
  5217. /// </summary>
  5218. internal void ResetFont()
  5219. {
  5220. if (this.pointCustomProperties)
  5221. ResetProperty(CommonCustomProperties.Font);
  5222. else
  5223. {
  5224. series.font = series.FontCache.DefaultFont;
  5225. }
  5226. }
  5227. /// <summary>
  5228. /// Resets property to its default value.
  5229. /// </summary>
  5230. internal void ResetLabelAngle()
  5231. {
  5232. if(this.pointCustomProperties)
  5233. ResetProperty(CommonCustomProperties.LabelAngle);
  5234. else
  5235. series.fontAngle = 0;
  5236. }
  5237. /// <summary>
  5238. /// Resets property to its default value.
  5239. /// </summary>
  5240. internal void ResetMarkerStyle()
  5241. {
  5242. if(this.pointCustomProperties)
  5243. ResetProperty(CommonCustomProperties.MarkerStyle);
  5244. else
  5245. series.markerStyle = MarkerStyle.None;
  5246. }
  5247. /// <summary>
  5248. /// Resets property to its default value.
  5249. /// </summary>
  5250. internal void ResetMarkerSize()
  5251. {
  5252. if(this.pointCustomProperties)
  5253. ResetProperty(CommonCustomProperties.MarkerSize);
  5254. else
  5255. series.markerSize = 5;
  5256. }
  5257. /// <summary>
  5258. /// Resets property to its default value.
  5259. /// </summary>
  5260. internal void ResetMarkerImage()
  5261. {
  5262. if(this.pointCustomProperties)
  5263. ResetProperty(CommonCustomProperties.MarkerImage);
  5264. else
  5265. series.markerImage = "";
  5266. }
  5267. /// <summary>
  5268. /// Resets property to its default value.
  5269. /// </summary>
  5270. internal void ResetMarkerImageTransparentColor()
  5271. {
  5272. if(this.pointCustomProperties)
  5273. ResetProperty(CommonCustomProperties.MarkerImageTransparentColor);
  5274. else
  5275. series.markerImageTransparentColor = Color.Empty;
  5276. }
  5277. /// <summary>
  5278. /// Resets property to its default value.
  5279. /// </summary>
  5280. internal void ResetMarkerColor()
  5281. {
  5282. if(this.pointCustomProperties)
  5283. ResetProperty(CommonCustomProperties.MarkerColor);
  5284. else
  5285. series.markerColor = Color.Empty;
  5286. }
  5287. /// <summary>
  5288. /// Resets property to its default value.
  5289. /// </summary>
  5290. internal void ResetMarkerBorderColor()
  5291. {
  5292. if(this.pointCustomProperties)
  5293. ResetProperty(CommonCustomProperties.MarkerBorderColor);
  5294. else
  5295. series.markerBorderColor = Color.Empty;
  5296. }
  5297. /// <summary>
  5298. /// Resets property to its default value.
  5299. /// </summary>
  5300. internal void ResetToolTip()
  5301. {
  5302. if(this.pointCustomProperties)
  5303. ResetProperty(CommonCustomProperties.ToolTip);
  5304. else
  5305. series.toolTip = "";
  5306. if(Chart != null && Chart.selection != null)
  5307. {
  5308. Chart.selection.enabledChecked = false;
  5309. }
  5310. }
  5311. /// <summary>
  5312. /// Resets property to its default value.
  5313. /// </summary>
  5314. public void ResetIsVisibleInLegend()
  5315. {
  5316. if(this.pointCustomProperties)
  5317. ResetProperty(CommonCustomProperties.IsVisibleInLegend);
  5318. else
  5319. series.showInLegend = true;
  5320. }
  5321. /// <summary>
  5322. /// Resets property to its default value.
  5323. /// </summary>
  5324. internal void ResetLegendText()
  5325. {
  5326. if(this.pointCustomProperties)
  5327. ResetProperty(CommonCustomProperties.LegendText);
  5328. else
  5329. series.legendText = "";
  5330. }
  5331. /// <summary>
  5332. /// Resets property to its default value.
  5333. /// </summary>
  5334. internal void ResetLegendToolTip()
  5335. {
  5336. if(this.pointCustomProperties)
  5337. ResetProperty(CommonCustomProperties.LegendToolTip);
  5338. else
  5339. series.legendToolTip = "";
  5340. if(Chart != null && Chart.selection != null)
  5341. {
  5342. Chart.selection.enabledChecked = false;
  5343. }
  5344. }
  5345. /// <summary>
  5346. /// Resets property to its default value.
  5347. /// </summary>
  5348. internal void ResetLabelBackColor()
  5349. {
  5350. if(this.pointCustomProperties)
  5351. ResetProperty(CommonCustomProperties.LabelBackColor);
  5352. else
  5353. series.labelBackColor = Color.Empty;
  5354. }
  5355. /// <summary>
  5356. /// Resets property to its default value.
  5357. /// </summary>
  5358. internal void ResetLabelBorderColor()
  5359. {
  5360. if(this.pointCustomProperties)
  5361. ResetProperty(CommonCustomProperties.LabelBorderColor);
  5362. else
  5363. series.labelBorderColor = Color.Empty;
  5364. }
  5365. /// <summary>
  5366. /// Resets property to its default value.
  5367. /// </summary>
  5368. internal void ResetLabelBorderDashStyle()
  5369. {
  5370. if(this.pointCustomProperties)
  5371. ResetProperty(CommonCustomProperties.LabelBorderDashStyle);
  5372. else
  5373. series.labelBorderDashStyle = ChartDashStyle.Solid;
  5374. }
  5375. /// <summary>
  5376. /// Resets property to its default value.
  5377. /// </summary>
  5378. internal void ResetLabelBorderWidth()
  5379. {
  5380. if(this.pointCustomProperties)
  5381. ResetProperty(CommonCustomProperties.LabelBorderWidth);
  5382. else
  5383. series.labelBorderWidth = 1;
  5384. }
  5385. /// <summary>
  5386. /// Resets property to its default value.
  5387. /// </summary>
  5388. internal void ResetLabelToolTip()
  5389. {
  5390. if(this.pointCustomProperties)
  5391. ResetProperty(CommonCustomProperties.LabelToolTip);
  5392. else
  5393. series.labelToolTip = "";
  5394. if(Chart != null && Chart.selection != null)
  5395. {
  5396. Chart.selection.enabledChecked = false;
  5397. }
  5398. }
  5399. #endregion
  5400. #region Invalidating method
  5401. /// <summary>
  5402. /// Invalidate chart area.
  5403. /// </summary>
  5404. /// <param name="invalidateLegend">Invalidate legend area only.</param>
  5405. [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", Justification = "This parameter is used when compiling for the WinForms version of Chart")]
  5406. internal void Invalidate(bool invalidateLegend)
  5407. {
  5408. if(this.series != null)
  5409. {
  5410. series.Invalidate(true, invalidateLegend);
  5411. }
  5412. else
  5413. {
  5414. Series thisSeries = this as Series;
  5415. if (thisSeries != null)
  5416. {
  5417. thisSeries.Invalidate(true, invalidateLegend);
  5418. }
  5419. }
  5420. }
  5421. #endregion
  5422. }
  5423. /// <summary>
  5424. /// Class stores additional information about the data point in 3D space.
  5425. /// </summary>
  5426. internal class DataPoint3D
  5427. {
  5428. #region Fields
  5429. /// <summary>
  5430. /// Reference to the 2D data point object
  5431. /// </summary>
  5432. internal DataPoint dataPoint = null;
  5433. /// <summary>
  5434. /// Data point index.
  5435. /// </summary>
  5436. internal int index = 0;
  5437. /// <summary>
  5438. /// Point X position in relative coordinates.
  5439. /// </summary>
  5440. internal double xPosition = 0.0;
  5441. /// <summary>
  5442. /// Point Y position in relative coordinates.
  5443. /// </summary>
  5444. internal double yPosition = 0.0;
  5445. /// <summary>
  5446. /// Point X center position in relative coordinates. Used for side-by-side charts.
  5447. /// </summary>
  5448. internal double xCenterVal = 0.0;
  5449. /// <summary>
  5450. /// Point Z position in relative coordinates.
  5451. /// </summary>
  5452. internal float zPosition = 0f;
  5453. /// <summary>
  5454. /// Point width.
  5455. /// </summary>
  5456. internal double width = 0.0;
  5457. /// <summary>
  5458. /// Point height.
  5459. /// </summary>
  5460. internal double height = 0.0;
  5461. /// <summary>
  5462. /// Point depth.
  5463. /// </summary>
  5464. internal float depth = 0f;
  5465. /// <summary>
  5466. /// Indicates that point belongs to indexed series.
  5467. /// </summary>
  5468. internal bool indexedSeries = false;
  5469. #endregion
  5470. }
  5471. /// <summary>
  5472. /// Design-time representation of the CustomProperties.
  5473. /// This class is used instead of the string "CustomProperties"
  5474. /// property at design time and supports expandable list
  5475. /// of custom properties.
  5476. /// </summary>
  5477. [ TypeConverter(typeof(CustomPropertiesTypeConverter)) ]
  5478. [EditorBrowsable(EditorBrowsableState.Never)]
  5479. public class CustomProperties
  5480. {
  5481. #region Fields
  5482. // Reference to the properties class
  5483. internal DataPointCustomProperties m_DataPointCustomProperties = null;
  5484. #endregion // Fields
  5485. #region Constructor
  5486. /// <summary>
  5487. /// Constructor
  5488. /// </summary>
  5489. /// <param name="properties">Attributes object.</param>
  5490. internal CustomProperties(DataPointCustomProperties properties)
  5491. {
  5492. this.m_DataPointCustomProperties = properties;
  5493. }
  5494. #endregion // Constructor
  5495. #region Properties
  5496. internal virtual DataPointCustomProperties DataPointCustomProperties
  5497. {
  5498. get
  5499. {
  5500. return this.m_DataPointCustomProperties;
  5501. }
  5502. set
  5503. {
  5504. this.m_DataPointCustomProperties = value;
  5505. }
  5506. }
  5507. #endregion //Properties
  5508. #region Methods
  5509. /// <summary>
  5510. /// Gets a comma separated string of user defined custom properties.
  5511. /// </summary>
  5512. /// <returns>Comma separated string of user defined custom properties.</returns>
  5513. internal virtual string GetUserDefinedCustomProperties()
  5514. {
  5515. return GetUserDefinedCustomProperties(true);
  5516. }
  5517. /// <summary>
  5518. /// Gets a comma separated string of user defined or non-user defined custom properties.
  5519. /// </summary>
  5520. /// <param name="userDefined">True if user defined properties must be returned.</param>
  5521. /// <returns>Comma separated string of user defined custom properties.</returns>
  5522. internal virtual string GetUserDefinedCustomProperties(bool userDefined)
  5523. {
  5524. // Get comma separated string of custom properties
  5525. string customAttribute = this.DataPointCustomProperties.CustomProperties;
  5526. string userDefinedCustomAttribute = string.Empty;
  5527. // Get custom attribute registry
  5528. CustomPropertyRegistry registry = (CustomPropertyRegistry)this.DataPointCustomProperties.Common.container.GetService(typeof(CustomPropertyRegistry));
  5529. // Replace commas in value string
  5530. customAttribute = customAttribute.Replace("\\,", "\\x45");
  5531. customAttribute = customAttribute.Replace("\\=", "\\x46");
  5532. // Split custom properties by commas into individual properties
  5533. if(customAttribute.Length > 0)
  5534. {
  5535. string[] nameValueStrings = customAttribute.Split(',');
  5536. foreach(string nameValue in nameValueStrings)
  5537. {
  5538. string[] values = nameValue.Split('=');
  5539. // Check format
  5540. if(values.Length != 2)
  5541. {
  5542. throw(new FormatException(SR.ExceptionAttributeInvalidFormat));
  5543. }
  5544. // Check for empty name or value
  5545. values[0] = values[0].Trim();
  5546. values[1] = values[1].Trim();
  5547. if(values[0].Length == 0)
  5548. {
  5549. throw(new FormatException(SR.ExceptionAttributeInvalidFormat));
  5550. }
  5551. // Check if attribute is registered or user defined
  5552. bool userDefinedAttribute = true;
  5553. foreach(CustomPropertyInfo info in registry.registeredCustomProperties)
  5554. {
  5555. if(string.Compare(info.Name, values[0], StringComparison.OrdinalIgnoreCase) == 0)
  5556. {
  5557. userDefinedAttribute = false;
  5558. }
  5559. }
  5560. // Copy attribute into the output string
  5561. if(userDefinedAttribute == userDefined)
  5562. {
  5563. if(userDefinedCustomAttribute.Length > 0)
  5564. {
  5565. userDefinedCustomAttribute += ", ";
  5566. }
  5567. string val = values[1].Replace("\\x45", ",");
  5568. val = val.Replace("\\x46", "=");
  5569. userDefinedCustomAttribute += values[0] + "=" + val;
  5570. }
  5571. }
  5572. }
  5573. return userDefinedCustomAttribute;
  5574. }
  5575. /// <summary>
  5576. /// Sets user defined custom properties without cleaning registered properties.
  5577. /// </summary>
  5578. /// <param name="val">New user defined properties.</param>
  5579. internal virtual void SetUserDefinedAttributes(string val)
  5580. {
  5581. // Get non-user defined custom properties
  5582. string properties = GetUserDefinedCustomProperties(false);
  5583. // Check if new string is empty
  5584. if(val.Length > 0)
  5585. {
  5586. // Add comma at the end
  5587. if(properties.Length > 0)
  5588. {
  5589. properties += ", ";
  5590. }
  5591. // Add new user defined properties
  5592. properties += val;
  5593. }
  5594. // Set new custom attribute string
  5595. this.DataPointCustomProperties.CustomProperties = properties;
  5596. }
  5597. #endregion // Methods
  5598. }
  5599. }