DataManipulator.cs 113 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451
  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: DataManipulator class exposes to the user methods
  6. // to perform data filtering, grouping, inserting
  7. // empty points, sorting and exporting data.
  8. // It also expose financial and statistical formulas
  9. // through the DataFormula base class.
  10. //
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.Data;
  15. namespace FastReport.DataVisualization.Charting
  16. {
  17. #region Data manipulation enumerations
  18. /// <summary>
  19. /// Grouping functions types
  20. /// </summary>
  21. internal enum GroupingFunction
  22. {
  23. /// <summary>
  24. /// Not defined
  25. /// </summary>
  26. None,
  27. /// <summary>
  28. /// Minimum value of the group
  29. /// </summary>
  30. Min,
  31. /// <summary>
  32. /// Maximum value of the group
  33. /// </summary>
  34. Max,
  35. /// <summary>
  36. /// Average value of the group
  37. /// </summary>
  38. Ave,
  39. /// <summary>
  40. /// Total of all values of the group
  41. /// </summary>
  42. Sum,
  43. /// <summary>
  44. /// Value of the first point in the group
  45. /// </summary>
  46. First,
  47. /// <summary>
  48. /// Value of the last point in the group
  49. /// </summary>
  50. Last,
  51. /// <summary>
  52. /// Value of the center point in the group
  53. /// </summary>
  54. Center,
  55. /// <summary>
  56. /// High, Low, Open, Close values in the group
  57. /// </summary>
  58. HiLoOpCl,
  59. /// <summary>
  60. /// High, Low values in the group
  61. /// </summary>
  62. HiLo,
  63. /// <summary>
  64. /// Number of points in the group
  65. /// </summary>
  66. Count,
  67. /// <summary>
  68. /// Number of unique points in the group
  69. /// </summary>
  70. DistinctCount,
  71. /// <summary>
  72. /// Variance of points in the group
  73. /// </summary>
  74. Variance,
  75. /// <summary>
  76. /// Deviation of points in the group
  77. /// </summary>
  78. Deviation
  79. }
  80. /// <summary>
  81. /// An enumeration of units of measurement for intervals.
  82. /// </summary>
  83. public enum IntervalType
  84. {
  85. /// <summary>
  86. /// Interval in numbers.
  87. /// </summary>
  88. Number,
  89. /// <summary>
  90. /// Interval in years.
  91. /// </summary>
  92. Years,
  93. /// <summary>
  94. /// Interval in months.
  95. /// </summary>
  96. Months,
  97. /// <summary>
  98. /// Interval in weeks.
  99. /// </summary>
  100. Weeks,
  101. /// <summary>
  102. /// Interval in days.
  103. /// </summary>
  104. Days,
  105. /// <summary>
  106. /// Interval in hours.
  107. /// </summary>
  108. Hours,
  109. /// <summary>
  110. /// Interval in minutes.
  111. /// </summary>
  112. Minutes,
  113. /// <summary>
  114. /// Interval in seconds.
  115. /// </summary>
  116. Seconds,
  117. /// <summary>
  118. /// Interval in milliseconds.
  119. /// </summary>
  120. Milliseconds
  121. }
  122. /// <summary>
  123. /// An enumeration of units of measurement for date ranges.
  124. /// </summary>
  125. public enum DateRangeType
  126. {
  127. /// <summary>
  128. /// Range defined in years.
  129. /// </summary>
  130. Year,
  131. /// <summary>
  132. /// Range defined in months.
  133. /// </summary>
  134. Month,
  135. /// <summary>
  136. /// Range defined in days of week.
  137. /// </summary>
  138. DayOfWeek,
  139. /// <summary>
  140. /// Range defined in days of month.
  141. /// </summary>
  142. DayOfMonth,
  143. /// <summary>
  144. /// Range defined in hours.
  145. /// </summary>
  146. Hour,
  147. /// <summary>
  148. /// Range defined in minutes.
  149. /// </summary>
  150. Minute
  151. }
  152. /// <summary>
  153. /// An enumeration of methods of comparison.
  154. /// </summary>
  155. public enum CompareMethod
  156. {
  157. /// <summary>
  158. /// One value is more than the other value.
  159. /// </summary>
  160. MoreThan,
  161. /// <summary>
  162. /// One value is less than the other value.
  163. /// </summary>
  164. LessThan,
  165. /// <summary>
  166. /// One value is equal the other value.
  167. /// </summary>
  168. EqualTo,
  169. /// <summary>
  170. /// One value is more or equal to the other value.
  171. /// </summary>
  172. MoreThanOrEqualTo,
  173. /// <summary>
  174. /// One value is less or equal to the other value.
  175. /// </summary>
  176. LessThanOrEqualTo,
  177. /// <summary>
  178. /// One value is not equal to the other value.
  179. /// </summary>
  180. NotEqualTo
  181. }
  182. #endregion
  183. #region Data points filtering inteface
  184. /// <summary>
  185. /// The IDataPointFilter interface is used for filtering series data points.
  186. /// </summary>
  187. public interface IDataPointFilter
  188. {
  189. /// <summary>
  190. /// Checks if the specified data point must be filtered.
  191. /// </summary>
  192. /// <param name="point">Data point object.</param>
  193. /// <param name="series">Series of the point.</param>
  194. /// <param name="pointIndex">Index of the point in the series.</param>
  195. /// <returns>True if point must be removed</returns>
  196. bool FilterDataPoint(DataPoint point, Series series, int pointIndex);
  197. }
  198. #endregion
  199. /// <summary>
  200. /// The DataManipulator class is used at runtime to perform data manipulation
  201. /// operations, and is exposed via the DataManipulator property of the
  202. /// root Chart object.
  203. /// </summary>
  204. public class DataManipulator : DataFormula
  205. {
  206. #region Fields
  207. // Indicates that filtering do not remove points, just mark them as empty
  208. private bool _filterSetEmptyPoints = false;
  209. // Indicates that points that match the criteria must be filtered out
  210. private bool _filterMatchedPoints = true;
  211. #endregion // Fields
  212. #region Data manipulator helper functions
  213. /// <summary>
  214. /// Helper function that converts one series or a comma separated
  215. /// list of series names into the Series array.
  216. /// </summary>
  217. /// <param name="obj">Series or string of series names.</param>
  218. /// <param name="createNew">If series with this name do not exist - create new.</param>
  219. /// <returns>Array of series.</returns>
  220. internal Series[] ConvertToSeriesArray(object obj, bool createNew)
  221. {
  222. Series[] array = null;
  223. if(obj == null)
  224. {
  225. return null;
  226. }
  227. // Parameter is one series
  228. if(obj.GetType() == typeof(Series))
  229. {
  230. array = new Series[1];
  231. array[0] = (Series)obj;
  232. }
  233. // Parameter is a string (comma separated series names)
  234. else if(obj.GetType() == typeof(string))
  235. {
  236. string series = (string)obj;
  237. int index = 0;
  238. // "*" means process all series from the collection
  239. if(series == "*")
  240. {
  241. // Create array of series
  242. array = new Series[Common.DataManager.Series.Count];
  243. // Add all series from the collection
  244. foreach(Series s in Common.DataManager.Series)
  245. {
  246. array[index] = s;
  247. ++index;
  248. }
  249. }
  250. // Comma separated list
  251. else if(series.Length > 0)
  252. {
  253. // Replace commas in value string
  254. series = series.Replace("\\,", "\\x45");
  255. series = series.Replace("\\=", "\\x46");
  256. // Split string by comma
  257. string[] seriesNames = series.Split(',');
  258. // Create array of series
  259. array = new Series[seriesNames.Length];
  260. // Find series by name
  261. foreach(string s in seriesNames)
  262. {
  263. // Put pack a comma character
  264. string seriesName = s.Replace("\\x45", ",");
  265. seriesName = seriesName.Replace("\\x46", "=");
  266. try
  267. {
  268. array[index] = Common.DataManager.Series[seriesName.Trim()];
  269. }
  270. catch(System.Exception)
  271. {
  272. if(createNew)
  273. {
  274. Series newSeries = new Series(seriesName.Trim());
  275. Common.DataManager.Series.Add(newSeries);
  276. array[index] = newSeries;
  277. }
  278. else
  279. {
  280. throw;
  281. }
  282. }
  283. ++index;
  284. }
  285. }
  286. }
  287. return array;
  288. }
  289. /// <summary>
  290. /// Public constructor
  291. /// </summary>
  292. public DataManipulator()
  293. {
  294. }
  295. #endregion
  296. #region Series points sorting methods
  297. /// <summary>
  298. /// Sort series data points in specified order.
  299. /// </summary>
  300. /// <param name="pointSortOrder">Sorting order.</param>
  301. /// <param name="sortBy">Value to sort by.</param>
  302. /// <param name="series">Series array to sort.</param>
  303. private void Sort(PointSortOrder pointSortOrder, string sortBy, Series[] series)
  304. {
  305. // Check arguments
  306. if (sortBy == null)
  307. throw new ArgumentNullException("sortBy");
  308. if (series == null)
  309. throw new ArgumentNullException("series");
  310. // Check array of series
  311. if(series.Length == 0)
  312. {
  313. return;
  314. }
  315. // Sort series
  316. DataPointComparer comparer = new DataPointComparer(series[0], pointSortOrder, sortBy);
  317. this.Sort(comparer, series);
  318. }
  319. /// <summary>
  320. /// Sort series data points in specified order.
  321. /// </summary>
  322. /// <param name="comparer">Comparing interface.</param>
  323. /// <param name="series">Series array to sort.</param>
  324. private void Sort(IComparer<DataPoint> comparer, Series[] series)
  325. {
  326. // Check arguments
  327. if (comparer == null)
  328. throw new ArgumentNullException("comparer");
  329. if (series == null)
  330. throw new ArgumentNullException("series");
  331. //**************************************************
  332. //** Check array of series
  333. //**************************************************
  334. if(series.Length == 0)
  335. {
  336. return;
  337. }
  338. //**************************************************
  339. //** If we sorting more than one series
  340. //**************************************************
  341. if(series.Length > 1)
  342. {
  343. // Check if series X values are aligned
  344. this.CheckXValuesAlignment(series);
  345. // Apply points indexes to the first series
  346. int pointIndex = 0;
  347. foreach(DataPoint point in series[0].Points)
  348. {
  349. point["_Index"] = pointIndex.ToString(System.Globalization.CultureInfo.InvariantCulture);
  350. ++pointIndex;
  351. }
  352. }
  353. //**************************************************
  354. //** Sort first series
  355. //**************************************************
  356. series[0].Sort(comparer);
  357. //**************************************************
  358. //** If we sorting more than one series
  359. //**************************************************
  360. if(series.Length > 1)
  361. {
  362. // Sort other series (depending on the first)
  363. int toIndex = 0;
  364. int fromIndex = 0;
  365. foreach(DataPoint point in series[0].Points)
  366. {
  367. // Move point from index is stored in point attribute (as index before sorting)
  368. fromIndex = int.Parse(point["_Index"], System.Globalization.CultureInfo.InvariantCulture);
  369. // Move points in series
  370. for(int seriesIndex = 1; seriesIndex < series.Length; seriesIndex++)
  371. {
  372. series[seriesIndex].Points.Insert(toIndex, series[seriesIndex].Points[toIndex + fromIndex]);
  373. }
  374. // Increase move point to index
  375. ++toIndex;
  376. }
  377. // Remove extra points from series
  378. for(int seriesIndex = 1; seriesIndex < series.Length; seriesIndex++)
  379. {
  380. while(series[seriesIndex].Points.Count > series[0].Points.Count)
  381. {
  382. series[seriesIndex].Points.RemoveAt(series[seriesIndex].Points.Count - 1);
  383. }
  384. }
  385. //**************************************************
  386. //** Remove points index attribute
  387. //**************************************************
  388. foreach(DataPoint point in series[0].Points)
  389. {
  390. point.DeleteCustomProperty("_Index");
  391. }
  392. }
  393. }
  394. #endregion
  395. #region Series points sorting overloaded methods
  396. /// <summary>
  397. /// Sort the series' data points in specified order.
  398. /// </summary>
  399. /// <param name="pointSortOrder">Sorting order.</param>
  400. /// <param name="sortBy">Value to sort by.</param>
  401. /// <param name="seriesName">Comma separated series names to sort.</param>
  402. public void Sort(PointSortOrder pointSortOrder, string sortBy, string seriesName)
  403. {
  404. // Check arguments
  405. if (seriesName == null)
  406. throw new ArgumentNullException("seriesName");
  407. Sort(pointSortOrder, sortBy, ConvertToSeriesArray(seriesName, false));
  408. }
  409. /// <summary>
  410. /// Sort the series' data points in specified order.
  411. /// </summary>
  412. /// <param name="pointSortOrder">Sorting order.</param>
  413. /// <param name="series">Series to sort.</param>
  414. public void Sort(PointSortOrder pointSortOrder, Series series)
  415. {
  416. // Check arguments
  417. if (series == null)
  418. throw new ArgumentNullException("series");
  419. Sort(pointSortOrder, "Y", ConvertToSeriesArray(series, false));
  420. }
  421. /// <summary>
  422. /// Sort the series' data points in specified order.
  423. /// </summary>
  424. /// <param name="pointSortOrder">Sorting order.</param>
  425. /// <param name="seriesName">Comma separated series names to sort.</param>
  426. public void Sort(PointSortOrder pointSortOrder, string seriesName)
  427. {
  428. // Check arguments
  429. if (seriesName == null)
  430. throw new ArgumentNullException("seriesName");
  431. Sort(pointSortOrder, "Y", ConvertToSeriesArray(seriesName, false));
  432. }
  433. /// <summary>
  434. /// Sort the series' data points in specified order.
  435. /// </summary>
  436. /// <param name="pointSortOrder">Sorting order.</param>
  437. /// <param name="sortBy">Value to sort by.</param>
  438. /// <param name="series">Series to sort.</param>
  439. public void Sort(PointSortOrder pointSortOrder, string sortBy, Series series)
  440. {
  441. // Check arguments
  442. if (series == null)
  443. throw new ArgumentNullException("series");
  444. Sort(pointSortOrder, sortBy, ConvertToSeriesArray(series, false));
  445. }
  446. /// <summary>
  447. /// Sort the series' data points in specified order.
  448. /// </summary>
  449. /// <param name="comparer">IComparer interface.</param>
  450. /// <param name="series">Series to sort.</param>
  451. public void Sort(IComparer<DataPoint> comparer, Series series)
  452. {
  453. // Check arguments - comparer is checked in the private override of Sort
  454. if (series == null)
  455. throw new ArgumentNullException("series");
  456. Sort(comparer, ConvertToSeriesArray(series, false));
  457. }
  458. /// <summary>
  459. /// Sort the series' data points in specified order.
  460. /// </summary>
  461. /// <param name="comparer">Comparing interface.</param>
  462. /// <param name="seriesName">Comma separated series names to sort.</param>
  463. public void Sort(IComparer<DataPoint> comparer, string seriesName)
  464. {
  465. // Check arguments - comparer is checked in the private override of Sort
  466. if (seriesName == null)
  467. throw new ArgumentNullException("seriesName");
  468. Sort(comparer, ConvertToSeriesArray(seriesName, false));
  469. }
  470. #endregion
  471. #region Insert empty data points method
  472. /// <summary>
  473. /// Insert empty data points using specified interval.
  474. /// </summary>
  475. /// <param name="interval">Interval size.</param>
  476. /// <param name="intervalType">Interval type.</param>
  477. /// <param name="intervalOffset">Interval offset size.</param>
  478. /// <param name="intervalOffsetType">Interval offset type.</param>
  479. /// <param name="fromXValue">Check intervals from this X value.</param>
  480. /// <param name="toXValue">Check intervals until this X value.</param>
  481. /// <param name="series">Series array.</param>
  482. private void InsertEmptyPoints(
  483. double interval,
  484. IntervalType intervalType,
  485. double intervalOffset,
  486. IntervalType intervalOffsetType,
  487. double fromXValue,
  488. double toXValue,
  489. Series[] series)
  490. {
  491. // Check the arguments
  492. if (interval <= 0)
  493. throw new ArgumentOutOfRangeException("interval");
  494. //**************************************************
  495. //** Automaticly detect minimum and maximum values
  496. //**************************************************
  497. double fromX = Math.Min(fromXValue, toXValue);
  498. double toX = Math.Max(fromXValue, toXValue);
  499. bool fromIsNaN = double.IsNaN(fromX);
  500. bool toIsNaN = double.IsNaN(toX);
  501. foreach(Series ser in series)
  502. {
  503. if(ser.Points.Count >= 1)
  504. {
  505. if(toIsNaN)
  506. {
  507. if(double.IsNaN(toX))
  508. {
  509. toX = ser.Points[ser.Points.Count - 1].XValue;
  510. }
  511. else
  512. {
  513. toX = Math.Max(toX, ser.Points[ser.Points.Count - 1].XValue);
  514. }
  515. }
  516. if(fromIsNaN)
  517. {
  518. if(double.IsNaN(fromX))
  519. {
  520. fromX = ser.Points[0].XValue;
  521. }
  522. else
  523. {
  524. fromX = Math.Min(fromX, ser.Points[0].XValue);
  525. }
  526. }
  527. if(fromX > toX)
  528. {
  529. double tempValue = fromX;
  530. fromX = toX;
  531. toX = tempValue;
  532. }
  533. }
  534. }
  535. //**************************************************
  536. //** Automaticly adjust the beginning interval and
  537. //** offset
  538. //**************************************************
  539. double nonAdjustedFromX = fromX;
  540. fromX = ChartHelper.AlignIntervalStart(fromX, interval, ConvertIntervalType(intervalType));
  541. // Add offset to the start position
  542. if( intervalOffset != 0 )
  543. {
  544. fromX = fromX + ChartHelper.GetIntervalSize(fromX, intervalOffset, ConvertIntervalType(intervalOffsetType), null, 0, DateTimeIntervalType.Number, true, false);
  545. }
  546. //**************************************************
  547. //** Loop through all series
  548. //**************************************************
  549. foreach(Series ser in series)
  550. {
  551. //**************************************************
  552. //** Loop through all data points
  553. //**************************************************
  554. int numberOfPoints = 0;
  555. int lastInsertPoint = 0;
  556. double currentPointValue = fromX;
  557. while(currentPointValue <= toX)
  558. {
  559. //**************************************************
  560. //** Check that X value is in range
  561. //**************************************************
  562. bool outOfRange = false;
  563. if(double.IsNaN(fromXValue) && currentPointValue < nonAdjustedFromX ||
  564. !double.IsNaN(fromXValue) && currentPointValue < fromXValue)
  565. {
  566. outOfRange = true;
  567. }
  568. else if(currentPointValue > toXValue)
  569. {
  570. outOfRange = true;
  571. }
  572. // Current X value is in range of points values
  573. if(!outOfRange)
  574. {
  575. //**************************************************
  576. //** Find required X value
  577. //**************************************************
  578. int insertPosition = lastInsertPoint;
  579. for(int pointIndex = lastInsertPoint; pointIndex < ser.Points.Count; pointIndex++)
  580. {
  581. // Value was found
  582. if(ser.Points[pointIndex].XValue == currentPointValue)
  583. {
  584. insertPosition = -1;
  585. break;
  586. }
  587. // Save point index where we should insert new empty point
  588. if(ser.Points[pointIndex].XValue > currentPointValue)
  589. {
  590. insertPosition = pointIndex;
  591. break;
  592. }
  593. // Insert as last point
  594. if(pointIndex == (ser.Points.Count - 1))
  595. {
  596. insertPosition = ser.Points.Count;
  597. }
  598. }
  599. //**************************************************
  600. //** Required value was not found - insert empty data point
  601. //**************************************************
  602. if(insertPosition != -1)
  603. {
  604. lastInsertPoint = insertPosition;
  605. ++numberOfPoints;
  606. DataPoint dataPoint = new DataPoint(ser);
  607. dataPoint.XValue = currentPointValue;
  608. dataPoint.IsEmpty = true;
  609. ser.Points.Insert(insertPosition, dataPoint);
  610. }
  611. }
  612. //**************************************************
  613. //** Determine next required data point
  614. //**************************************************
  615. currentPointValue += ChartHelper.GetIntervalSize(currentPointValue,
  616. interval,
  617. ConvertIntervalType(intervalType));
  618. //**************************************************
  619. //** Check if we exceed number of empty points
  620. //** we can add.
  621. //**************************************************
  622. if(numberOfPoints > 1000)
  623. {
  624. currentPointValue = toX + 1;
  625. continue;
  626. }
  627. }
  628. }
  629. }
  630. /// <summary>
  631. /// Helper function which converts IntervalType enumeration
  632. /// into DateTimeIntervalType enumeration.
  633. /// </summary>
  634. /// <param name="type">Interval type value.</param>
  635. /// <returns>Date time interval type value.</returns>
  636. private DateTimeIntervalType ConvertIntervalType(IntervalType type)
  637. {
  638. switch(type)
  639. {
  640. case(IntervalType.Milliseconds):
  641. return DateTimeIntervalType.Milliseconds;
  642. case(IntervalType.Seconds):
  643. return DateTimeIntervalType.Seconds;
  644. case(IntervalType.Days):
  645. return DateTimeIntervalType.Days;
  646. case(IntervalType.Hours):
  647. return DateTimeIntervalType.Hours;
  648. case(IntervalType.Minutes):
  649. return DateTimeIntervalType.Minutes;
  650. case(IntervalType.Months):
  651. return DateTimeIntervalType.Months;
  652. case(IntervalType.Number):
  653. return DateTimeIntervalType.Number;
  654. case(IntervalType.Weeks):
  655. return DateTimeIntervalType.Weeks;
  656. case(IntervalType.Years):
  657. return DateTimeIntervalType.Years;
  658. }
  659. return DateTimeIntervalType.Auto;
  660. }
  661. #endregion
  662. #region Insert empty data points overloaded methods
  663. /// <summary>
  664. /// Insert empty data points using the specified interval.
  665. /// </summary>
  666. /// <param name="interval">Interval size.</param>
  667. /// <param name="intervalType">Interval type.</param>
  668. /// <param name="series">Series to insert the empty points.</param>
  669. public void InsertEmptyPoints(
  670. double interval,
  671. IntervalType intervalType,
  672. Series series)
  673. {
  674. InsertEmptyPoints(interval, intervalType, 0, IntervalType.Number, series);
  675. }
  676. /// <summary>
  677. /// Insert empty data points using the specified interval.
  678. /// </summary>
  679. /// <param name="interval">Interval size.</param>
  680. /// <param name="intervalType">Interval type.</param>
  681. /// <param name="seriesName">Name of series to insert the empty points.</param>
  682. public void InsertEmptyPoints(
  683. double interval,
  684. IntervalType intervalType,
  685. string seriesName)
  686. {
  687. InsertEmptyPoints(interval, intervalType, 0, IntervalType.Number, seriesName);
  688. }
  689. /// <summary>
  690. /// Insert empty data points using the specified interval.
  691. /// </summary>
  692. /// <param name="interval">Interval size.</param>
  693. /// <param name="intervalType">Interval type.</param>
  694. /// <param name="intervalOffset">Interval offset size.</param>
  695. /// <param name="intervalOffsetType">Interval offset type.</param>
  696. /// <param name="seriesName">Name of series to insert the empty points.</param>
  697. public void InsertEmptyPoints(
  698. double interval,
  699. IntervalType intervalType,
  700. double intervalOffset,
  701. IntervalType intervalOffsetType,
  702. string seriesName)
  703. {
  704. InsertEmptyPoints(interval, intervalType, intervalOffset, intervalOffsetType, double.NaN, double.NaN, seriesName);
  705. }
  706. /// <summary>
  707. /// Insert empty data points using the specified interval.
  708. /// </summary>
  709. /// <param name="interval">Interval size.</param>
  710. /// <param name="intervalType">Interval type.</param>
  711. /// <param name="intervalOffset">Interval offset size.</param>
  712. /// <param name="intervalOffsetType">Interval offset type.</param>
  713. /// <param name="series">Series to insert the empty points.</param>
  714. public void InsertEmptyPoints(
  715. double interval,
  716. IntervalType intervalType,
  717. double intervalOffset,
  718. IntervalType intervalOffsetType,
  719. Series series)
  720. {
  721. InsertEmptyPoints(interval, intervalType, intervalOffset, intervalOffsetType, double.NaN, double.NaN, series);
  722. }
  723. /// <summary>
  724. /// Insert empty data points using the specified interval.
  725. /// </summary>
  726. /// <param name="interval">Interval size.</param>
  727. /// <param name="intervalType">Interval type.</param>
  728. /// <param name="intervalOffset">Interval offset size.</param>
  729. /// <param name="intervalOffsetType">Interval offset type.</param>
  730. /// <param name="fromXValue">Check intervals from this X value.</param>
  731. /// <param name="toXValue">Check intervals until this X value.</param>
  732. /// <param name="seriesName">Name of series to insert the empty points.</param>
  733. public void InsertEmptyPoints(
  734. double interval,
  735. IntervalType intervalType,
  736. double intervalOffset,
  737. IntervalType intervalOffsetType,
  738. double fromXValue,
  739. double toXValue,
  740. string seriesName)
  741. {
  742. // Check arguments
  743. if (seriesName == null)
  744. throw new ArgumentNullException("seriesName");
  745. InsertEmptyPoints(
  746. interval,
  747. intervalType,
  748. intervalOffset,
  749. intervalOffsetType,
  750. fromXValue,
  751. toXValue,
  752. ConvertToSeriesArray(seriesName, false));
  753. }
  754. /// <summary>
  755. /// Insert empty data points using the specified interval.
  756. /// </summary>
  757. /// <param name="interval">Interval size.</param>
  758. /// <param name="intervalType">Interval type.</param>
  759. /// <param name="intervalOffset">Interval offset size.</param>
  760. /// <param name="intervalOffsetType">Interval offset type.</param>
  761. /// <param name="fromXValue">Check intervals from this X value.</param>
  762. /// <param name="toXValue">Check intervals until this X value.</param>
  763. /// <param name="series">Series to insert the empty points.</param>
  764. public void InsertEmptyPoints(
  765. double interval,
  766. IntervalType intervalType,
  767. double intervalOffset,
  768. IntervalType intervalOffsetType,
  769. double fromXValue,
  770. double toXValue,
  771. Series series)
  772. {
  773. // Check arguments
  774. if (series == null)
  775. throw new ArgumentNullException("series");
  776. InsertEmptyPoints(
  777. interval,
  778. intervalType,
  779. intervalOffset,
  780. intervalOffsetType,
  781. fromXValue,
  782. toXValue,
  783. ConvertToSeriesArray(series, false));
  784. }
  785. #endregion
  786. #region Series data exporting methods
  787. /// <summary>
  788. /// Export series data into the DataSet object.
  789. /// </summary>
  790. /// <param name="series">Array of series which should be exported.</param>
  791. /// <returns>Data set object with series data.</returns>
  792. internal DataSet ExportSeriesValues(Series[] series)
  793. {
  794. //*****************************************************
  795. //** Create DataSet object
  796. //*****************************************************
  797. DataSet dataSet = new DataSet();
  798. dataSet.Locale = System.Globalization.CultureInfo.CurrentCulture;
  799. // If input series are specified
  800. if(series != null)
  801. {
  802. // Export each series in the loop
  803. foreach(Series ser in series)
  804. {
  805. //*****************************************************
  806. //** Check if all X values are zeros
  807. //*****************************************************
  808. bool zeroXValues = true;
  809. foreach( DataPoint point in ser.Points )
  810. {
  811. if( point.XValue != 0.0 )
  812. {
  813. zeroXValues = false;
  814. break;
  815. }
  816. }
  817. // Added 10 May 2005, DT - dataset after databinding
  818. // to string x value returns X as indexes
  819. if (zeroXValues && ser.XValueType == ChartValueType.String)
  820. {
  821. zeroXValues = false;
  822. }
  823. //*****************************************************
  824. //** Create new table for the series
  825. //*****************************************************
  826. DataTable seriesTable = new DataTable(ser.Name);
  827. seriesTable.Locale = System.Globalization.CultureInfo.CurrentCulture;
  828. //*****************************************************
  829. //** Add X column into data table schema
  830. //*****************************************************
  831. Type columnType = typeof(double);
  832. if(ser.IsXValueDateTime())
  833. {
  834. columnType = typeof(DateTime);
  835. }
  836. else if(ser.XValueType == ChartValueType.String)
  837. {
  838. columnType = typeof(string);
  839. }
  840. seriesTable.Columns.Add("X", columnType);
  841. //*****************************************************
  842. //** Add Y column(s) into data table schema
  843. //*****************************************************
  844. columnType = typeof(double);
  845. if(ser.IsYValueDateTime())
  846. {
  847. columnType = typeof(DateTime);
  848. }
  849. else if(ser.YValueType == ChartValueType.String)
  850. {
  851. columnType = typeof(string);
  852. }
  853. for(int yIndex = 0; yIndex < ser.YValuesPerPoint; yIndex++)
  854. {
  855. if(yIndex == 0)
  856. {
  857. seriesTable.Columns.Add("Y", columnType);
  858. }
  859. else
  860. {
  861. seriesTable.Columns.Add("Y" + (yIndex + 1).ToString(System.Globalization.CultureInfo.InvariantCulture), columnType);
  862. }
  863. }
  864. //*****************************************************
  865. //** Fill data table's rows
  866. //*****************************************************
  867. double pointIndex = 1.0;
  868. foreach(DataPoint point in ser.Points)
  869. {
  870. if(!point.IsEmpty || !this.IsEmptyPointIgnored)
  871. {
  872. DataRow dataRow = seriesTable.NewRow();
  873. // Set row X value
  874. object xValue = point.XValue;
  875. if(ser.IsXValueDateTime())
  876. {
  877. if (Double.IsNaN(point.XValue))
  878. xValue = DBNull.Value;
  879. else
  880. xValue = DateTime.FromOADate(point.XValue);
  881. }
  882. else if(ser.XValueType == ChartValueType.String)
  883. {
  884. xValue = point.AxisLabel;
  885. }
  886. dataRow["X"] = (zeroXValues) ? pointIndex : xValue;
  887. // Set row Y value(s)
  888. for(int yIndex = 0; yIndex < ser.YValuesPerPoint; yIndex++)
  889. {
  890. object yValue = point.YValues[yIndex];
  891. if(!point.IsEmpty)
  892. {
  893. if(ser.IsYValueDateTime())
  894. {
  895. if (Double.IsNaN(point.YValues[yIndex]))
  896. xValue = DBNull.Value;
  897. else
  898. yValue = DateTime.FromOADate(point.YValues[yIndex]);
  899. }
  900. else if(ser.YValueType == ChartValueType.String)
  901. {
  902. yValue = point.AxisLabel;
  903. }
  904. }
  905. else if(!this.IsEmptyPointIgnored)
  906. {
  907. // Special handling of empty points
  908. yValue = DBNull.Value;
  909. }
  910. if(yIndex == 0)
  911. {
  912. dataRow["Y"] = yValue;
  913. }
  914. else
  915. {
  916. dataRow["Y" + (yIndex + 1).ToString(System.Globalization.CultureInfo.InvariantCulture)] = yValue;
  917. }
  918. }
  919. // Add row to the table
  920. seriesTable.Rows.Add(dataRow);
  921. ++pointIndex;
  922. }
  923. }
  924. // Accept changes
  925. seriesTable.AcceptChanges();
  926. //*****************************************************
  927. //** Add data table into the data set
  928. //*****************************************************
  929. dataSet.Tables.Add(seriesTable);
  930. }
  931. }
  932. return dataSet;
  933. }
  934. #endregion
  935. #region Series data exporting overloaded methods
  936. /// <summary>
  937. /// Export all series from the collection into the DataSet object.
  938. /// </summary>
  939. /// <returns>Dataset object with series data.</returns>
  940. public DataSet ExportSeriesValues()
  941. {
  942. return ExportSeriesValues("*");
  943. }
  944. /// <summary>
  945. /// Export series data into the DataSet object.
  946. /// </summary>
  947. /// <param name="seriesNames">Comma separated list of series names to be exported.</param>
  948. /// <returns>Dataset object with series data.</returns>
  949. public DataSet ExportSeriesValues(string seriesNames)
  950. {
  951. // Check arguments
  952. if (seriesNames == null)
  953. throw new ArgumentNullException(seriesNames);
  954. return ExportSeriesValues(ConvertToSeriesArray(seriesNames, false));
  955. }
  956. /// <summary>
  957. /// Export series data into the DataSet object.
  958. /// </summary>
  959. /// <param name="series">Series to be exported.</param>
  960. /// <returns>Dataset object with series data.</returns>
  961. public DataSet ExportSeriesValues(Series series)
  962. {
  963. // Check arguments
  964. if (series == null)
  965. throw new ArgumentNullException("series");
  966. return ExportSeriesValues(ConvertToSeriesArray(series, false));
  967. }
  968. #endregion
  969. #region Filtering properties
  970. /// <summary>
  971. /// Gets or sets a flag which indicates whether points filtered by
  972. /// the Filter or FilterTopN methods are removed or marked as empty.
  973. /// If set to true, filtered points are marked as empty; otherwise they are removed.
  974. /// This property defaults to be false.
  975. /// </summary>
  976. public bool FilterSetEmptyPoints
  977. {
  978. get
  979. {
  980. return _filterSetEmptyPoints;
  981. }
  982. set
  983. {
  984. _filterSetEmptyPoints = value;
  985. }
  986. }
  987. /// <summary>
  988. /// Gets or sets a value that determines if points are filtered
  989. /// if they match criteria that is specified in Filter method calls.
  990. /// If set to true, points that match specified criteria are filtered.
  991. /// If set to false, points that do not match the criteria are filtered.
  992. /// This property defaults to be true.
  993. /// </summary>
  994. public bool FilterMatchedPoints
  995. {
  996. get
  997. {
  998. return _filterMatchedPoints;
  999. }
  1000. set
  1001. {
  1002. _filterMatchedPoints = value;
  1003. }
  1004. }
  1005. #endregion
  1006. #region Filtering methods
  1007. /// <summary>
  1008. /// Keeps only N top/bottom points of the series
  1009. /// </summary>
  1010. /// <param name="pointCount">Number of top/bottom points to return.</param>
  1011. /// <param name="inputSeries">Input series array.</param>
  1012. /// <param name="outputSeries">Output series array.</param>
  1013. /// <param name="usingValue">Defines which value of the point use in comparison (X, Y, Y2, ...).</param>
  1014. /// <param name="getTopValues">Indicate that N top values must be retrieved, otherwise N bottom values.</param>
  1015. private void FilterTopN(int pointCount,
  1016. Series[] inputSeries,
  1017. Series[] outputSeries,
  1018. string usingValue,
  1019. bool getTopValues)
  1020. {
  1021. // Check input/output series arrays
  1022. CheckSeriesArrays(inputSeries, outputSeries);
  1023. // Check input series alignment
  1024. CheckXValuesAlignment(inputSeries);
  1025. if(pointCount <= 0)
  1026. {
  1027. throw (new ArgumentOutOfRangeException("pointCount", SR.ExceptionDataManipulatorPointCountIsZero));
  1028. }
  1029. //**************************************************
  1030. //** Filter points in the first series and remove
  1031. //** in all
  1032. //**************************************************
  1033. // Define an output series array
  1034. Series[] output = new Series[inputSeries.Length];
  1035. for(int seriesIndex = 0; seriesIndex < inputSeries.Length; seriesIndex++)
  1036. {
  1037. output[seriesIndex] = inputSeries[seriesIndex];
  1038. if(outputSeries != null && outputSeries.Length > seriesIndex)
  1039. {
  1040. output[seriesIndex] = outputSeries[seriesIndex];
  1041. }
  1042. // Remove all points from the output series
  1043. if(output[seriesIndex] != inputSeries[seriesIndex])
  1044. {
  1045. output[seriesIndex].Points.Clear();
  1046. // Make sure there is enough Y values per point
  1047. output[seriesIndex].YValuesPerPoint = inputSeries[seriesIndex].YValuesPerPoint;
  1048. // Copy X values type
  1049. if(output[seriesIndex].XValueType == ChartValueType.Auto || output[seriesIndex].autoXValueType)
  1050. {
  1051. output[seriesIndex].XValueType = inputSeries[seriesIndex].XValueType;
  1052. output[seriesIndex].autoXValueType = true;
  1053. }
  1054. // Copy Y values type
  1055. if(output[seriesIndex].YValueType == ChartValueType.Auto || output[seriesIndex].autoYValueType)
  1056. {
  1057. output[seriesIndex].YValueType = inputSeries[seriesIndex].YValueType;
  1058. output[seriesIndex].autoYValueType = true;
  1059. }
  1060. // Copy input points into output
  1061. foreach(DataPoint point in inputSeries[seriesIndex].Points)
  1062. {
  1063. output[seriesIndex].Points.Add(point.Clone());
  1064. }
  1065. }
  1066. }
  1067. // No points to filter
  1068. if(inputSeries[0].Points.Count == 0)
  1069. {
  1070. return;
  1071. }
  1072. //**************************************************
  1073. //** Sort input data
  1074. //**************************************************
  1075. this.Sort((getTopValues) ? PointSortOrder.Descending : PointSortOrder.Ascending,
  1076. usingValue,
  1077. output);
  1078. //**************************************************
  1079. //** Get top/bottom points
  1080. //**************************************************
  1081. // Process all series
  1082. for(int seriesIndex = 0; seriesIndex < inputSeries.Length; seriesIndex++)
  1083. {
  1084. // Only keep N first points
  1085. while(output[seriesIndex].Points.Count > pointCount)
  1086. {
  1087. if(this.FilterSetEmptyPoints)
  1088. {
  1089. output[seriesIndex].Points[pointCount].IsEmpty = true;
  1090. ++pointCount;
  1091. }
  1092. else
  1093. {
  1094. output[seriesIndex].Points.RemoveAt(pointCount);
  1095. }
  1096. }
  1097. }
  1098. }
  1099. /// <summary>
  1100. /// Filter data points using IDataPointFilter interface
  1101. /// </summary>
  1102. /// <param name="filterInterface">Data points filtering interface.</param>
  1103. /// <param name="inputSeries">Input series array.</param>
  1104. /// <param name="outputSeries">Output series array.</param>
  1105. private void Filter(IDataPointFilter filterInterface,
  1106. Series[] inputSeries,
  1107. Series[] outputSeries)
  1108. {
  1109. //**************************************************
  1110. //** Check input/output series arrays
  1111. //**************************************************
  1112. CheckSeriesArrays(inputSeries, outputSeries);
  1113. CheckXValuesAlignment(inputSeries);
  1114. if(filterInterface == null)
  1115. {
  1116. throw(new ArgumentNullException("filterInterface"));
  1117. }
  1118. //**************************************************
  1119. //** Filter points in the first series and remove
  1120. //** in all
  1121. //**************************************************
  1122. // Define an output series array
  1123. Series[] output = new Series[inputSeries.Length];
  1124. for(int seriesIndex = 0; seriesIndex < inputSeries.Length; seriesIndex++)
  1125. {
  1126. output[seriesIndex] = inputSeries[seriesIndex];
  1127. if(outputSeries != null && outputSeries.Length > seriesIndex)
  1128. {
  1129. output[seriesIndex] = outputSeries[seriesIndex];
  1130. }
  1131. // Remove all points from the output series
  1132. if(output[seriesIndex] != inputSeries[seriesIndex])
  1133. {
  1134. output[seriesIndex].Points.Clear();
  1135. // Make sure there is enough Y values per point
  1136. output[seriesIndex].YValuesPerPoint = inputSeries[seriesIndex].YValuesPerPoint;
  1137. // Copy X values type
  1138. if(output[seriesIndex].XValueType == ChartValueType.Auto || output[seriesIndex].autoXValueType)
  1139. {
  1140. output[seriesIndex].XValueType = inputSeries[seriesIndex].XValueType;
  1141. output[seriesIndex].autoXValueType = true;
  1142. }
  1143. // Copy Y values type
  1144. if(output[seriesIndex].YValueType == ChartValueType.Auto || output[seriesIndex].autoYValueType)
  1145. {
  1146. output[seriesIndex].YValueType = inputSeries[seriesIndex].YValueType;
  1147. output[seriesIndex].autoYValueType = true;
  1148. }
  1149. }
  1150. }
  1151. // No points to filter
  1152. if(inputSeries[0].Points.Count == 0)
  1153. {
  1154. return;
  1155. }
  1156. //**************************************************
  1157. //** Loop through all points of the first input series
  1158. //**************************************************
  1159. int originalPointIndex = 0;
  1160. for(int pointIndex = 0; pointIndex < inputSeries[0].Points.Count; pointIndex++, originalPointIndex++)
  1161. {
  1162. bool pointRemoved = false;
  1163. // Check if point match the criteria
  1164. bool matchCriteria = filterInterface.FilterDataPoint(
  1165. inputSeries[0].Points[pointIndex],
  1166. inputSeries[0],
  1167. originalPointIndex) == this.FilterMatchedPoints;
  1168. // Process all series
  1169. for(int seriesIndex = 0; seriesIndex < inputSeries.Length; seriesIndex++)
  1170. {
  1171. bool seriesMatchCriteria = matchCriteria;
  1172. if(output[seriesIndex] != inputSeries[seriesIndex])
  1173. {
  1174. if(seriesMatchCriteria && !this.FilterSetEmptyPoints)
  1175. {
  1176. // Don't do anything...
  1177. seriesMatchCriteria = false;
  1178. }
  1179. else
  1180. {
  1181. // Copy point into the output series for all series
  1182. output[seriesIndex].Points.Add(inputSeries[seriesIndex].Points[pointIndex].Clone());
  1183. }
  1184. }
  1185. // If point match the criteria
  1186. if(seriesMatchCriteria)
  1187. {
  1188. // Set point's empty flag
  1189. if(this.FilterSetEmptyPoints)
  1190. {
  1191. output[seriesIndex].Points[pointIndex].IsEmpty = true;
  1192. for(int valueIndex = 0; valueIndex < output[seriesIndex].Points[pointIndex].YValues.Length; valueIndex++)
  1193. {
  1194. output[seriesIndex].Points[pointIndex].YValues[valueIndex] = 0.0;
  1195. }
  1196. }
  1197. // Remove point
  1198. else
  1199. {
  1200. output[seriesIndex].Points.RemoveAt(pointIndex);
  1201. pointRemoved = true;
  1202. }
  1203. }
  1204. }
  1205. // Adjust index because of the removed point
  1206. if(pointRemoved)
  1207. {
  1208. --pointIndex;
  1209. }
  1210. }
  1211. }
  1212. /// <summary>
  1213. /// Data point filter.
  1214. /// Filters points using element type and index
  1215. /// </summary>
  1216. private class PointElementFilter : IDataPointFilter
  1217. {
  1218. // Private fields
  1219. private DataManipulator _dataManipulator = null;
  1220. private DateRangeType _dateRange;
  1221. private int[] _rangeElements = null;
  1222. // Default constructor is not accesiable
  1223. private PointElementFilter()
  1224. {
  1225. }
  1226. /// <summary>
  1227. /// Public constructor.
  1228. /// </summary>
  1229. /// <param name="dataManipulator">Data manipulator object.</param>
  1230. /// <param name="dateRange">Range type.</param>
  1231. /// <param name="rangeElements">Range elements to filter.</param>
  1232. public PointElementFilter(DataManipulator dataManipulator, DateRangeType dateRange, string rangeElements)
  1233. {
  1234. this._dataManipulator = dataManipulator;
  1235. this._dateRange = dateRange;
  1236. this._rangeElements = dataManipulator.ConvertElementIndexesToArray(rangeElements);
  1237. }
  1238. /// <summary>
  1239. /// Data points filtering method.
  1240. /// </summary>
  1241. /// <param name="point">Data point.</param>
  1242. /// <param name="series">Data point series.</param>
  1243. /// <param name="pointIndex">Data point index.</param>
  1244. /// <returns>Indicates that point should be filtered.</returns>
  1245. public bool FilterDataPoint(DataPoint point, Series series, int pointIndex)
  1246. {
  1247. return _dataManipulator.CheckFilterElementCriteria(
  1248. this._dateRange,
  1249. this._rangeElements,
  1250. point);
  1251. }
  1252. }
  1253. /// <summary>
  1254. /// Data point filter.
  1255. /// Filters points using point values
  1256. /// </summary>
  1257. private class PointValueFilter : IDataPointFilter
  1258. {
  1259. // Private fields
  1260. private CompareMethod _compareMethod;
  1261. private string _usingValue;
  1262. private double _compareValue;
  1263. /// <summary>
  1264. /// Default constructor is not accessible
  1265. /// </summary>
  1266. private PointValueFilter()
  1267. {
  1268. }
  1269. /// <summary>
  1270. /// Public constructor.
  1271. /// </summary>
  1272. /// <param name="compareMethod">Comparing method.</param>
  1273. /// <param name="compareValue">Comparing constant.</param>
  1274. /// <param name="usingValue">Value used in comparison.</param>
  1275. public PointValueFilter(CompareMethod compareMethod,
  1276. double compareValue,
  1277. string usingValue)
  1278. {
  1279. this._compareMethod = compareMethod;
  1280. this._usingValue = usingValue;
  1281. this._compareValue = compareValue;
  1282. }
  1283. /// <summary>
  1284. /// IDataPointFilter interface method implementation
  1285. /// </summary>
  1286. /// <param name="point">Data point.</param>
  1287. /// <param name="series">Data point series.</param>
  1288. /// <param name="pointIndex">Data point index.</param>
  1289. /// <returns>Indicates that point should be filtered.</returns>
  1290. public bool FilterDataPoint(DataPoint point, Series series, int pointIndex)
  1291. {
  1292. // Check if point match the criteria
  1293. bool matchCriteria = false;
  1294. switch(_compareMethod)
  1295. {
  1296. case(CompareMethod.EqualTo):
  1297. matchCriteria = point.GetValueByName(_usingValue)
  1298. == _compareValue;
  1299. break;
  1300. case(CompareMethod.LessThan):
  1301. matchCriteria = point.GetValueByName(_usingValue)
  1302. < _compareValue;
  1303. break;
  1304. case(CompareMethod.LessThanOrEqualTo):
  1305. matchCriteria = point.GetValueByName(_usingValue)
  1306. <= _compareValue;
  1307. break;
  1308. case(CompareMethod.MoreThan):
  1309. matchCriteria = point.GetValueByName(_usingValue)
  1310. > _compareValue;
  1311. break;
  1312. case(CompareMethod.MoreThanOrEqualTo):
  1313. matchCriteria = point.GetValueByName(_usingValue)
  1314. >= _compareValue;
  1315. break;
  1316. case(CompareMethod.NotEqualTo):
  1317. matchCriteria = point.GetValueByName(_usingValue)
  1318. != _compareValue;
  1319. break;
  1320. }
  1321. return matchCriteria;
  1322. }
  1323. }
  1324. /// <summary>
  1325. /// Helper function to convert elements indexes from a string
  1326. /// into an array of integers
  1327. /// </summary>
  1328. /// <param name="rangeElements">Element indexes string. Ex:"3,5,6-9,15"</param>
  1329. /// <returns>Array of integer indexes.</returns>
  1330. private int[] ConvertElementIndexesToArray(string rangeElements)
  1331. {
  1332. // Split input string by comma
  1333. string[] indexes = rangeElements.Split(',');
  1334. // Check if there are items in the array
  1335. if(indexes.Length == 0)
  1336. {
  1337. throw (new ArgumentException(SR.ExceptionDataManipulatorIndexUndefined, "rangeElements"));
  1338. }
  1339. // Allocate memory for the result array
  1340. int[] result = new int[indexes.Length * 2];
  1341. // Process each element index
  1342. int index = 0;
  1343. foreach(string str in indexes)
  1344. {
  1345. // Check if it's a simple index or a range
  1346. if(str.IndexOf('-') != -1)
  1347. {
  1348. string[] rangeIndex = str.Split('-');
  1349. if(rangeIndex.Length == 2)
  1350. {
  1351. // Convert to integer
  1352. try
  1353. {
  1354. result[index] = Int32.Parse(rangeIndex[0], System.Globalization.CultureInfo.InvariantCulture);
  1355. result[index + 1] = Int32.Parse(rangeIndex[1], System.Globalization.CultureInfo.InvariantCulture);
  1356. if(result[index + 1] < result[index])
  1357. {
  1358. int temp = result[index];
  1359. result[index] = result[index + 1];
  1360. result[index + 1] = temp;
  1361. }
  1362. }
  1363. catch(System.Exception)
  1364. {
  1365. throw (new ArgumentException(SR.ExceptionDataManipulatorIndexFormatInvalid, "rangeElements"));
  1366. }
  1367. }
  1368. else
  1369. {
  1370. throw (new ArgumentException(SR.ExceptionDataManipulatorIndexFormatInvalid, "rangeElements"));
  1371. }
  1372. }
  1373. else
  1374. {
  1375. // Convert to integer
  1376. try
  1377. {
  1378. result[index] = Int32.Parse(str, System.Globalization.CultureInfo.InvariantCulture);
  1379. result[index + 1] = result[index];
  1380. }
  1381. catch(System.Exception)
  1382. {
  1383. throw (new ArgumentException(SR.ExceptionDataManipulatorIndexFormatInvalid, "rangeElements"));
  1384. }
  1385. }
  1386. index += 2;
  1387. }
  1388. return result;
  1389. }
  1390. /// <summary>
  1391. /// Helper function, which checks if specified point matches the criteria
  1392. /// </summary>
  1393. /// <param name="dateRange">Element type.</param>
  1394. /// <param name="rangeElements">Array of element indexes ranges (pairs).</param>
  1395. /// <param name="point">Data point to check.</param>
  1396. /// <returns>True if point matches the criteria.</returns>
  1397. private bool CheckFilterElementCriteria(
  1398. DateRangeType dateRange,
  1399. int[] rangeElements,
  1400. DataPoint point)
  1401. {
  1402. // Conver X value to DateTime
  1403. DateTime dateTimeValue = DateTime.FromOADate(point.XValue);
  1404. for(int index = 0; index < rangeElements.Length; index += 2)
  1405. {
  1406. switch(dateRange)
  1407. {
  1408. case(DateRangeType.Year):
  1409. if(dateTimeValue.Year >= rangeElements[index] &&
  1410. dateTimeValue.Year <= rangeElements[index+1])
  1411. return true;
  1412. break;
  1413. case(DateRangeType.Month):
  1414. if(dateTimeValue.Month >= rangeElements[index] &&
  1415. dateTimeValue.Month <= rangeElements[index+1])
  1416. return true;
  1417. break;
  1418. case(DateRangeType.DayOfWeek):
  1419. if((int)dateTimeValue.DayOfWeek >= rangeElements[index] &&
  1420. (int)dateTimeValue.DayOfWeek <= rangeElements[index+1])
  1421. return true;
  1422. break;
  1423. case(DateRangeType.DayOfMonth):
  1424. if(dateTimeValue.Day >= rangeElements[index] &&
  1425. dateTimeValue.Day <= rangeElements[index+1])
  1426. return true;
  1427. break;
  1428. case(DateRangeType.Hour):
  1429. if(dateTimeValue.Hour >= rangeElements[index] &&
  1430. dateTimeValue.Hour <= rangeElements[index+1])
  1431. return true;
  1432. break;
  1433. case(DateRangeType.Minute):
  1434. if(dateTimeValue.Minute >= rangeElements[index] &&
  1435. dateTimeValue.Minute <= rangeElements[index+1])
  1436. return true;
  1437. break;
  1438. }
  1439. }
  1440. return false;
  1441. }
  1442. #endregion
  1443. #region Filtering overloaded methods
  1444. /// <summary>
  1445. /// Filters a series' data points, either removing the specified points
  1446. /// or marking them as empty for the given date/time ranges.
  1447. /// </summary>
  1448. /// <param name="dateRange">Element type.</param>
  1449. /// <param name="rangeElements">Specifies the elements within the date/time range
  1450. /// (specified by the dateRange parameter) that will be filtered. Can be a single value (e.g. "7"),
  1451. /// comma-separated values (e.g. "5,6"), a range of values (e.g. 9-11),
  1452. /// or any variation thereof (e.g. "5,6,9-11").</param>
  1453. /// <param name="inputSeriesNames">Comma separated list of input series names.</param>
  1454. /// <param name="outputSeriesNames">Comma separated list of output series names, to store the output.</param>
  1455. public void Filter(DateRangeType dateRange,
  1456. string rangeElements,
  1457. string inputSeriesNames,
  1458. string outputSeriesNames)
  1459. {
  1460. // Check arguments
  1461. if (rangeElements == null)
  1462. throw new ArgumentNullException("rangeElements");
  1463. if (inputSeriesNames == null)
  1464. throw new ArgumentNullException("inputSeriesNames");
  1465. // Filter points using filtering interface
  1466. Filter(new PointElementFilter(this, dateRange, rangeElements),
  1467. ConvertToSeriesArray(inputSeriesNames, false),
  1468. ConvertToSeriesArray(outputSeriesNames, true));
  1469. }
  1470. /// <summary>
  1471. /// Filters a series' data points, either removing the specified points
  1472. /// or marking them as empty for the given date/time ranges.
  1473. /// The Series object that is filtered is used to store the modified data.
  1474. /// </summary>
  1475. /// <param name="dateRange">Element type.</param>
  1476. /// <param name="rangeElements">Specifies the elements within the date/time range
  1477. /// (specified by the dateRange parameter) that will be filtered. Can be a single value (e.g. "7"),
  1478. /// comma-separated values (e.g. "5,6"), a range of values (e.g. 9-11),
  1479. /// or any variation thereof (e.g. "5,6,9-11").</param>
  1480. /// <param name="inputSeries">Input series.</param>
  1481. public void Filter(DateRangeType dateRange,
  1482. string rangeElements,
  1483. Series inputSeries)
  1484. {
  1485. // Check arguments
  1486. if (rangeElements == null)
  1487. throw new ArgumentNullException("rangeElements");
  1488. if (inputSeries == null)
  1489. throw new ArgumentNullException("inputSeries");
  1490. Filter(dateRange, rangeElements, inputSeries, null);
  1491. }
  1492. /// <summary>
  1493. /// Filters a series' data points, either removing the specified points
  1494. /// or marking them as empty for the given date/time ranges.
  1495. /// </summary>
  1496. /// <param name="dateRange">Element type.</param>
  1497. /// <param name="rangeElements">Specifies the elements within the date/time range
  1498. /// (specified by the dateRange parameter) that will be filtered. Can be a single value (e.g. "7"),
  1499. /// comma-separated values (e.g. "5,6"), a range of values (e.g. 9-11),
  1500. /// or any variation thereof (e.g. "5,6,9-11").</param>
  1501. /// <param name="inputSeries">Input series.</param>
  1502. /// <param name="outputSeries">Output series.</param>
  1503. public void Filter(DateRangeType dateRange,
  1504. string rangeElements,
  1505. Series inputSeries,
  1506. Series outputSeries)
  1507. {
  1508. // Check arguments
  1509. if (rangeElements == null)
  1510. throw new ArgumentNullException("rangeElements");
  1511. if (inputSeries == null)
  1512. throw new ArgumentNullException("inputSeries");
  1513. // Filter points using filtering interface
  1514. Filter(new PointElementFilter(this, dateRange, rangeElements),
  1515. ConvertToSeriesArray(inputSeries, false),
  1516. ConvertToSeriesArray(outputSeries, false));
  1517. }
  1518. /// <summary>
  1519. /// Filters a series' data points, either removing the specified points
  1520. /// or marking them as empty for the given date/time ranges.
  1521. /// The filtered Series objects are used to store the modified data.
  1522. /// </summary>
  1523. /// <param name="dateRange">Element type.</param>
  1524. /// <param name="rangeElements">Specifies the elements within the date/time range
  1525. /// (specified by the dateRange parameter) that will be filtered. Can be a single value (e.g. "7"),
  1526. /// comma-separated values (e.g. "5,6"), a range of values (e.g. 9-11),
  1527. /// or any variation thereof (e.g. "5,6,9-11").</param>
  1528. /// <param name="inputSeriesNames">Comma separated list of input series names.</param>
  1529. public void Filter(DateRangeType dateRange,
  1530. string rangeElements,
  1531. string inputSeriesNames)
  1532. {
  1533. // Check arguments
  1534. if (rangeElements == null)
  1535. throw new ArgumentNullException("rangeElements");
  1536. if (inputSeriesNames == null)
  1537. throw new ArgumentNullException("inputSeriesNames");
  1538. Filter(dateRange,
  1539. rangeElements,
  1540. inputSeriesNames,
  1541. "");
  1542. }
  1543. /// <summary>
  1544. /// Filters a series' data points by applying a filtering rule to the first Y-value of data points.
  1545. /// The Series object that is filtered is used to store the modified data.
  1546. /// </summary>
  1547. /// <param name="compareMethod">Value comparing method.</param>
  1548. /// <param name="compareValue">Value to compare with.</param>
  1549. /// <param name="inputSeries">Input series.</param>
  1550. public void Filter(CompareMethod compareMethod,
  1551. double compareValue,
  1552. Series inputSeries)
  1553. {
  1554. // Check arguments
  1555. if (inputSeries == null)
  1556. throw new ArgumentNullException("inputSeries");
  1557. Filter(compareMethod,
  1558. compareValue,
  1559. inputSeries,
  1560. null,
  1561. "Y");
  1562. }
  1563. /// <summary>
  1564. /// Filters a series' data points by applying a filtering rule to the first Y-value of data points.
  1565. /// </summary>
  1566. /// <param name="compareMethod">Value comparing method.</param>
  1567. /// <param name="compareValue">Value to compare with.</param>
  1568. /// <param name="inputSeries">Input series.</param>
  1569. /// <param name="outputSeries">Output series.</param>
  1570. public void Filter(CompareMethod compareMethod,
  1571. double compareValue,
  1572. Series inputSeries,
  1573. Series outputSeries)
  1574. {
  1575. // Check arguments
  1576. if (inputSeries == null)
  1577. throw new ArgumentNullException("inputSeries");
  1578. // Filter points using filtering interface
  1579. Filter(new PointValueFilter(compareMethod, compareValue, "Y"),
  1580. ConvertToSeriesArray(inputSeries, false),
  1581. ConvertToSeriesArray(outputSeries, false));
  1582. }
  1583. /// <summary>
  1584. /// Filters a series' data points by applying a filtering rule to the specified value for comparison.
  1585. /// </summary>
  1586. /// <param name="compareMethod">Value comparing method.</param>
  1587. /// <param name="compareValue">Value to compare with.</param>
  1588. /// <param name="inputSeries">Input series.</param>
  1589. /// <param name="outputSeries">Output series.</param>
  1590. /// <param name="usingValue">The data point value that the filtering rule is applied to. Can be X, Y, Y2, Y3, etc.</param>
  1591. public void Filter(CompareMethod compareMethod,
  1592. double compareValue,
  1593. Series inputSeries,
  1594. Series outputSeries,
  1595. string usingValue)
  1596. {
  1597. // Check arguments
  1598. if (inputSeries == null)
  1599. throw new ArgumentNullException("inputSeries");
  1600. if (usingValue == null)
  1601. throw new ArgumentNullException("usingValue");
  1602. // Filter points using filtering interface
  1603. Filter(new PointValueFilter(compareMethod, compareValue, usingValue),
  1604. ConvertToSeriesArray(inputSeries, false),
  1605. ConvertToSeriesArray(outputSeries, false));
  1606. }
  1607. /// <summary>
  1608. /// Filters one or more series by applying a filtering rule to the first Y-value of the first series' data points.
  1609. /// The filtered Series objects are used to store the modified data.
  1610. /// </summary>
  1611. /// <param name="compareMethod">Value comparing method.</param>
  1612. /// <param name="compareValue">Value to compare with.</param>
  1613. /// <param name="inputSeriesNames">Comma separated list of input series names.</param>
  1614. public void Filter(CompareMethod compareMethod,
  1615. double compareValue,
  1616. string inputSeriesNames)
  1617. {
  1618. // Check arguments
  1619. if (inputSeriesNames == null)
  1620. throw new ArgumentNullException("inputSeriesNames");
  1621. Filter(compareMethod,
  1622. compareValue,
  1623. inputSeriesNames,
  1624. "",
  1625. "Y");
  1626. }
  1627. /// <summary>
  1628. /// Filters one or more series by applying a filtering rule to the first Y-value of the first series' data points.
  1629. /// </summary>
  1630. /// <param name="compareMethod">Value comparing method.</param>
  1631. /// <param name="compareValue">Value to compare with.</param>
  1632. /// <param name="inputSeriesNames">Comma separated list of input series names.</param>
  1633. /// <param name="outputSeriesNames">Comma separated list of output series names.</param>
  1634. public void Filter(CompareMethod compareMethod,
  1635. double compareValue,
  1636. string inputSeriesNames,
  1637. string outputSeriesNames)
  1638. {
  1639. // Check arguments
  1640. if (inputSeriesNames == null)
  1641. throw new ArgumentNullException("inputSeriesNames");
  1642. // Filter points using filtering interface
  1643. Filter(new PointValueFilter(compareMethod, compareValue, "Y"),
  1644. ConvertToSeriesArray(inputSeriesNames, false),
  1645. ConvertToSeriesArray(outputSeriesNames, true));
  1646. }
  1647. /// <summary>
  1648. /// Filters one or more series by applying a filtering rule to the specified value of the first series' data points.
  1649. /// </summary>
  1650. /// <param name="compareMethod">Value comparing method.</param>
  1651. /// <param name="compareValue">Value to compare with.</param>
  1652. /// <param name="inputSeriesNames">Comma separated input series names.</param>
  1653. /// <param name="outputSeriesNames">Comma separated output series names.</param>
  1654. /// <param name="usingValue">The data point value that the filtering rule is applied to. Can be X, Y, Y2, Y3, etc.</param>
  1655. public void Filter(CompareMethod compareMethod,
  1656. double compareValue,
  1657. string inputSeriesNames,
  1658. string outputSeriesNames,
  1659. string usingValue)
  1660. {
  1661. // Check arguments
  1662. if (inputSeriesNames == null)
  1663. throw new ArgumentNullException("inputSeriesNames");
  1664. if (usingValue == null)
  1665. throw new ArgumentNullException("usingValue");
  1666. // Filter points using filtering interface
  1667. Filter(new PointValueFilter(compareMethod, compareValue, usingValue),
  1668. ConvertToSeriesArray(inputSeriesNames, false),
  1669. ConvertToSeriesArray(outputSeriesNames, true));
  1670. }
  1671. /// <summary>
  1672. /// Filters all data points in one or more series except for a specified number of points.
  1673. /// The points that are not filtered correspond to points in the first input series that have the largest or smallest values.
  1674. /// </summary>
  1675. /// <param name="pointCount">The number of data points that the filtering operation will not remove.</param>
  1676. /// <param name="inputSeriesNames">Comma separated list of input series names.</param>
  1677. /// <param name="outputSeriesNames">Comma separated list of output series names.</param>
  1678. /// <param name="usingValue">The data point value that the filtering rule is applied to. Can be X, Y, Y2, Y3, etc.</param>
  1679. /// <param name="getTopValues">The largest values are kept if set to true; otherwise the smallest values are kept.</param>
  1680. public void FilterTopN(int pointCount,
  1681. string inputSeriesNames,
  1682. string outputSeriesNames,
  1683. string usingValue,
  1684. bool getTopValues)
  1685. {
  1686. // Check arguments
  1687. if (inputSeriesNames == null)
  1688. throw new ArgumentNullException("inputSeriesNames");
  1689. if (usingValue == null)
  1690. throw new ArgumentNullException("usingValue");
  1691. FilterTopN(pointCount,
  1692. ConvertToSeriesArray(inputSeriesNames, false),
  1693. ConvertToSeriesArray(outputSeriesNames, true),
  1694. usingValue,
  1695. getTopValues);
  1696. }
  1697. /// <summary>
  1698. /// Filters out all data points in a series except for a specified number of points with the largest (first) Y-values.
  1699. /// The Series object that is filtered is used to store the modified data.
  1700. /// </summary>
  1701. /// <param name="pointCount">The number of data points that the filtering operation will not remove.</param>
  1702. /// <param name="inputSeries">Input series.</param>
  1703. public void FilterTopN(int pointCount,
  1704. Series inputSeries)
  1705. {
  1706. // Check arguments
  1707. if (inputSeries == null)
  1708. throw new ArgumentNullException("inputSeries");
  1709. FilterTopN(pointCount,
  1710. ConvertToSeriesArray(inputSeries, false),
  1711. null,
  1712. "Y",
  1713. true);
  1714. }
  1715. /// <summary>
  1716. /// Filters all data points in a series except for a specified number of points with the largest first Y-values.
  1717. /// </summary>
  1718. /// <param name="pointCount">The number of data points that the filtering operation will not remove.</param>
  1719. /// <param name="inputSeries">Input series.</param>
  1720. /// <param name="outputSeries">Output series.</param>
  1721. public void FilterTopN(int pointCount,
  1722. Series inputSeries,
  1723. Series outputSeries)
  1724. {
  1725. // Check arguments
  1726. if (inputSeries == null)
  1727. throw new ArgumentNullException("inputSeries");
  1728. FilterTopN(pointCount,
  1729. ConvertToSeriesArray(inputSeries, false),
  1730. ConvertToSeriesArray(outputSeries, false),
  1731. "Y",
  1732. true);
  1733. }
  1734. /// <summary>
  1735. /// Filters all data points in a series except for a specified number of points with the largest values.
  1736. /// </summary>
  1737. /// <param name="pointCount">The number of data points that the filtering operation will not remove.</param>
  1738. /// <param name="inputSeries">Input series.</param>
  1739. /// <param name="outputSeries">Output series.</param>
  1740. /// <param name="usingValue">The data point value that the filtering rule is applied to. Can be X, Y, Y2, Y3, etc.</param>
  1741. public void FilterTopN(int pointCount,
  1742. Series inputSeries,
  1743. Series outputSeries,
  1744. string usingValue)
  1745. {
  1746. // Check arguments
  1747. if (inputSeries == null)
  1748. throw new ArgumentNullException("inputSeries");
  1749. if (usingValue == null)
  1750. throw new ArgumentNullException("usingValue");
  1751. FilterTopN(pointCount,
  1752. ConvertToSeriesArray(inputSeries, false),
  1753. ConvertToSeriesArray(outputSeries, false),
  1754. usingValue,
  1755. true);
  1756. }
  1757. /// <summary>
  1758. /// Filters all data points in a series except for a specified number of points with the smallest or largest values.
  1759. /// </summary>
  1760. /// <param name="pointCount">The number of data points that the filtering operation will not remove.</param>
  1761. /// <param name="inputSeries">Input series.</param>
  1762. /// <param name="outputSeries">Output series.</param>
  1763. /// <param name="usingValue">The data point value that the filtering rule is applied to. Can be X, Y, Y2, Y3, etc.</param>
  1764. /// <param name="getTopValues">The largest values are kept if set to true; otherwise the smallest values are kept.</param>
  1765. public void FilterTopN(int pointCount,
  1766. Series inputSeries,
  1767. Series outputSeries,
  1768. string usingValue,
  1769. bool getTopValues)
  1770. {
  1771. // Check arguments
  1772. if (inputSeries == null)
  1773. throw new ArgumentNullException("inputSeries");
  1774. if (usingValue == null)
  1775. throw new ArgumentNullException("usingValue");
  1776. FilterTopN(pointCount,
  1777. ConvertToSeriesArray(inputSeries, false),
  1778. ConvertToSeriesArray(outputSeries, false),
  1779. usingValue,
  1780. getTopValues);
  1781. }
  1782. /// <summary>
  1783. /// Filters all data points in one or more series except for a specified number of points.
  1784. /// The points that are not filtered correspond to points in the first series that have the largest first Y-values.
  1785. /// The Series objects that are filtered are used to store the modified data.
  1786. /// </summary>
  1787. /// <param name="pointCount">The number of data points that the filtering operation will not remove.</param>
  1788. /// <param name="inputSeriesNames">Comma separated list of input series names.</param>
  1789. public void FilterTopN(int pointCount,
  1790. string inputSeriesNames)
  1791. {
  1792. // Check arguments
  1793. if (inputSeriesNames == null)
  1794. throw new ArgumentNullException("inputSeriesNames");
  1795. FilterTopN(pointCount,
  1796. ConvertToSeriesArray(inputSeriesNames, false),
  1797. null,
  1798. "Y",
  1799. true);
  1800. }
  1801. /// <summary>
  1802. /// Filters out data points in one or more series except for a specified number of points.
  1803. /// The points that aren't filtered correspond to points in the first series that have the largest first Y-values.
  1804. /// </summary>
  1805. /// <param name="pointCount">The number of data points that the filtering operation will not remove.</param>
  1806. /// <param name="inputSeriesNames">Comma separated list of input series names.</param>
  1807. /// <param name="outputSeriesNames">Comma separated list of output series names.</param>
  1808. public void FilterTopN(int pointCount,
  1809. string inputSeriesNames,
  1810. string outputSeriesNames)
  1811. {
  1812. // Check arguments
  1813. if (inputSeriesNames == null)
  1814. throw new ArgumentNullException("inputSeriesNames");
  1815. FilterTopN(pointCount,
  1816. ConvertToSeriesArray(inputSeriesNames, false),
  1817. ConvertToSeriesArray(outputSeriesNames, true),
  1818. "Y",
  1819. true);
  1820. }
  1821. /// <summary>
  1822. /// Filters all data points in one or more series except for a specified number of points.
  1823. /// The points that are not filtered correspond to points in the first series that have the largest values.
  1824. /// </summary>
  1825. /// <param name="pointCount">The number of data points that the filtering operation will not remove.</param>
  1826. /// <param name="inputSeriesNames">Comma separated list of input series names.</param>
  1827. /// <param name="outputSeriesNames">Comma separated list of output series names.</param>
  1828. /// <param name="usingValue">The data point value that the filtering rule is applied to. Can be X, Y, Y2, Y3, etc.</param>
  1829. public void FilterTopN(int pointCount,
  1830. string inputSeriesNames,
  1831. string outputSeriesNames,
  1832. string usingValue)
  1833. {
  1834. // Check arguments
  1835. if (inputSeriesNames == null)
  1836. throw new ArgumentNullException("inputSeriesNames");
  1837. if (usingValue == null)
  1838. throw new ArgumentNullException("usingValue");
  1839. FilterTopN(pointCount,
  1840. ConvertToSeriesArray(inputSeriesNames, false),
  1841. ConvertToSeriesArray(outputSeriesNames, true),
  1842. usingValue,
  1843. true);
  1844. }
  1845. /// <summary>
  1846. /// Performs custom filtering on a series' data points.
  1847. /// The Series object that is filtered is used to store the modified data.
  1848. /// </summary>
  1849. /// <param name="filterInterface">Filtering interface.</param>
  1850. /// <param name="inputSeries">Input series.</param>
  1851. public void Filter(IDataPointFilter filterInterface,
  1852. Series inputSeries)
  1853. {
  1854. // Check arguments
  1855. if (filterInterface == null)
  1856. throw new ArgumentNullException("filterInterface");
  1857. if (inputSeries == null)
  1858. throw new ArgumentNullException("inputSeries");
  1859. Filter(filterInterface,
  1860. ConvertToSeriesArray(inputSeries, false),
  1861. null);
  1862. }
  1863. /// <summary>
  1864. /// Performs custom filtering on a series' data points.
  1865. /// </summary>
  1866. /// <param name="filterInterface">Filtering interface.</param>
  1867. /// <param name="inputSeries">Input series.</param>
  1868. /// <param name="outputSeries">Output series.</param>
  1869. public void Filter(IDataPointFilter filterInterface,
  1870. Series inputSeries,
  1871. Series outputSeries)
  1872. {
  1873. // Check arguments
  1874. if (filterInterface == null)
  1875. throw new ArgumentNullException("filterInterface");
  1876. if (inputSeries == null)
  1877. throw new ArgumentNullException("inputSeries");
  1878. Filter(filterInterface,
  1879. ConvertToSeriesArray(inputSeries, false),
  1880. ConvertToSeriesArray(outputSeries, false));
  1881. }
  1882. /// <summary>
  1883. /// Performs custom filtering on one or more series' data points, based on the first series' points.
  1884. /// The filtered series are also used to store the modified data.
  1885. /// </summary>
  1886. /// <param name="filterInterface">Filtering interface.</param>
  1887. /// <param name="inputSeriesNames">Comma separated list of input series names.</param>
  1888. public void Filter(IDataPointFilter filterInterface,
  1889. string inputSeriesNames)
  1890. {
  1891. // Check arguments
  1892. if (filterInterface == null)
  1893. throw new ArgumentNullException("filterInterface");
  1894. if (inputSeriesNames == null)
  1895. throw new ArgumentNullException("inputSeriesNames");
  1896. Filter(filterInterface,
  1897. ConvertToSeriesArray(inputSeriesNames, false),
  1898. null);
  1899. }
  1900. /// <summary>
  1901. /// Performs custom filtering on one or more series' data points, based on the first series' points.
  1902. /// </summary>
  1903. /// <param name="filterInterface">Filtering interface.</param>
  1904. /// <param name="inputSeriesNames">Comma separated list of input series names.</param>
  1905. /// <param name="outputSeriesNames">Comma separated list of output series names.</param>
  1906. public void Filter(IDataPointFilter filterInterface,
  1907. string inputSeriesNames,
  1908. string outputSeriesNames)
  1909. {
  1910. // Check arguments
  1911. if (filterInterface == null)
  1912. throw new ArgumentNullException("filterInterface");
  1913. if (inputSeriesNames == null)
  1914. throw new ArgumentNullException("inputSeriesNames");
  1915. Filter(filterInterface,
  1916. ConvertToSeriesArray(inputSeriesNames, false),
  1917. ConvertToSeriesArray(outputSeriesNames, true));
  1918. }
  1919. #endregion
  1920. #region Grouping methods
  1921. /// <summary>
  1922. /// Class stores information about the grouping function type and
  1923. /// index of output value.
  1924. /// </summary>
  1925. private class GroupingFunctionInfo
  1926. {
  1927. // AxisName of the grouping function
  1928. internal GroupingFunction function = GroupingFunction.None;
  1929. // Index of the Y value for storing results
  1930. internal int outputIndex = 0;
  1931. /// <summary>
  1932. /// Constructor.
  1933. /// </summary>
  1934. internal GroupingFunctionInfo()
  1935. {
  1936. }
  1937. }
  1938. /// <summary>
  1939. /// Grouping by X value, when it’s a string (stored in AxisLabel property).
  1940. /// </summary>
  1941. /// <param name="formula">Grouping formula.</param>
  1942. /// <param name="inputSeries">Array of input series.</param>
  1943. /// <param name="outputSeries">Array of output series.</param>
  1944. private void GroupByAxisLabel(string formula, Series[] inputSeries, Series[] outputSeries)
  1945. {
  1946. // Check arguments
  1947. if (formula == null)
  1948. throw new ArgumentNullException("formula");
  1949. //**************************************************
  1950. //** Check input/output series arrays
  1951. //**************************************************
  1952. CheckSeriesArrays(inputSeries, outputSeries);
  1953. //**************************************************
  1954. //** Check and parse formula
  1955. //**************************************************
  1956. int outputValuesNumber = 1;
  1957. GroupingFunctionInfo[] functions = GetGroupingFunctions(inputSeries, formula, out outputValuesNumber);
  1958. //**************************************************
  1959. //** Loop through all input series
  1960. //**************************************************
  1961. for(int seriesIndex = 0; seriesIndex < inputSeries.Length; seriesIndex++)
  1962. {
  1963. // Define an input and output series
  1964. Series input = inputSeries[seriesIndex];
  1965. Series output = input;
  1966. if(outputSeries != null && seriesIndex < outputSeries.Length)
  1967. {
  1968. output = outputSeries[seriesIndex];
  1969. // Remove all points from the output series
  1970. if(output.Name != input.Name)
  1971. {
  1972. output.Points.Clear();
  1973. // Copy X values type
  1974. if(output.XValueType == ChartValueType.Auto || output.autoXValueType)
  1975. {
  1976. output.XValueType = input.XValueType;
  1977. output.autoXValueType = true;
  1978. }
  1979. // Copy Y values type
  1980. if(output.YValueType == ChartValueType.Auto || output.autoYValueType)
  1981. {
  1982. output.YValueType = input.YValueType;
  1983. output.autoYValueType = true;
  1984. }
  1985. }
  1986. }
  1987. // Copy input data into temp storage
  1988. if(input != output)
  1989. {
  1990. Series inputTemp = new Series("Temp", input.YValuesPerPoint);
  1991. foreach(DataPoint point in input.Points)
  1992. {
  1993. DataPoint dp = new DataPoint(inputTemp);
  1994. dp.AxisLabel = point.AxisLabel;
  1995. dp.XValue = point.XValue;
  1996. point.YValues.CopyTo(dp.YValues, 0);
  1997. dp.IsEmpty = point.IsEmpty;
  1998. inputTemp.Points.Add(dp);
  1999. }
  2000. input = inputTemp;
  2001. }
  2002. // No points to group
  2003. if(input.Points.Count == 0)
  2004. {
  2005. continue;
  2006. }
  2007. // Make sure there is enough Y values per point
  2008. output.YValuesPerPoint = outputValuesNumber - 1;
  2009. //**************************************************
  2010. //** Sort input data by axis label
  2011. //**************************************************
  2012. input.Sort(PointSortOrder.Ascending, "AxisLabel");
  2013. //**************************************************
  2014. //** Initialize interval & value tracking variables
  2015. //**************************************************
  2016. int intervalFirstIndex = 0;
  2017. int intervalLastIndex = 0;
  2018. //**************************************************
  2019. //** Allocate array for storing temp.
  2020. //** values of the point
  2021. //**************************************************
  2022. double[] pointTempValues = new double[outputValuesNumber];
  2023. //**************************************************
  2024. //** Loop through the series points
  2025. //**************************************************
  2026. string currentLabel = null;
  2027. bool lastPoint = false;
  2028. int emptyPointsSkipped = 0;
  2029. for(int pointIndex = 0; pointIndex <= input.Points.Count && !lastPoint; pointIndex++)
  2030. {
  2031. bool endOfInterval = false;
  2032. //**************************************************
  2033. //** Check if it's the last point
  2034. //**************************************************
  2035. if(pointIndex == input.Points.Count)
  2036. {
  2037. // End of the group interval detected
  2038. lastPoint = true;
  2039. intervalLastIndex = pointIndex - 1;
  2040. pointIndex = intervalLastIndex;
  2041. endOfInterval = true;
  2042. }
  2043. // Set current axis label
  2044. if(!endOfInterval && currentLabel == null)
  2045. {
  2046. currentLabel = input.Points[pointIndex].AxisLabel;
  2047. }
  2048. //**************************************************
  2049. //** Check if current point X value is inside current group
  2050. //**************************************************
  2051. if(!endOfInterval && input.Points[pointIndex].AxisLabel != currentLabel)
  2052. {
  2053. // End of the group interval detected
  2054. intervalLastIndex = pointIndex - 1;
  2055. endOfInterval = true;
  2056. }
  2057. //**************************************************
  2058. //** Process data at end of the interval
  2059. //**************************************************
  2060. if(endOfInterval)
  2061. {
  2062. // Finalize the calculation
  2063. ProcessPointValues(
  2064. functions,
  2065. pointTempValues,
  2066. inputSeries[seriesIndex],
  2067. input.Points[pointIndex],
  2068. pointIndex,
  2069. intervalFirstIndex,
  2070. intervalLastIndex,
  2071. true,
  2072. ref emptyPointsSkipped);
  2073. //**************************************************
  2074. //** Calculate the X values
  2075. //**************************************************
  2076. if(functions[0].function == GroupingFunction.Center)
  2077. {
  2078. pointTempValues[0] =
  2079. (inputSeries[seriesIndex].Points[intervalFirstIndex].XValue +
  2080. inputSeries[seriesIndex].Points[intervalLastIndex].XValue) / 2.0;
  2081. }
  2082. else if(functions[0].function == GroupingFunction.First)
  2083. {
  2084. pointTempValues[0] =
  2085. inputSeries[seriesIndex].Points[intervalFirstIndex].XValue;
  2086. }
  2087. if(functions[0].function == GroupingFunction.Last)
  2088. {
  2089. pointTempValues[0] =
  2090. inputSeries[seriesIndex].Points[intervalLastIndex].XValue;
  2091. }
  2092. //**************************************************
  2093. //** Create new point object
  2094. //**************************************************
  2095. DataPoint newPoint = new DataPoint();
  2096. newPoint.ResizeYValueArray(outputValuesNumber - 1);
  2097. newPoint.XValue = pointTempValues[0];
  2098. newPoint.AxisLabel = currentLabel;
  2099. for(int i = 1; i < pointTempValues.Length; i++)
  2100. {
  2101. newPoint.YValues[i - 1] = pointTempValues[i];
  2102. }
  2103. //**************************************************
  2104. //** Remove grouped points if output and input
  2105. //** series are the same
  2106. //**************************************************
  2107. int newPointIndex = output.Points.Count;
  2108. if(output == input)
  2109. {
  2110. newPointIndex = intervalFirstIndex;
  2111. pointIndex = newPointIndex + 1;
  2112. // Remove grouped points
  2113. for(int removedPoint = intervalFirstIndex; removedPoint <= intervalLastIndex; removedPoint++)
  2114. {
  2115. output.Points.RemoveAt(intervalFirstIndex);
  2116. }
  2117. }
  2118. //**************************************************
  2119. //** Add point to the output series
  2120. //**************************************************
  2121. output.Points.Insert(newPointIndex, newPoint);
  2122. // Set new group interval indexes
  2123. intervalFirstIndex = pointIndex;
  2124. intervalLastIndex = pointIndex;
  2125. // Reset number of skipped points
  2126. emptyPointsSkipped = 0;
  2127. currentLabel = null;
  2128. // Process point once again
  2129. --pointIndex;
  2130. continue;
  2131. }
  2132. //**************************************************
  2133. //** Use current point values in the formula
  2134. //**************************************************
  2135. ProcessPointValues(
  2136. functions,
  2137. pointTempValues,
  2138. inputSeries[seriesIndex],
  2139. input.Points[pointIndex],
  2140. pointIndex,
  2141. intervalFirstIndex,
  2142. intervalLastIndex,
  2143. false,
  2144. ref emptyPointsSkipped);
  2145. }
  2146. }
  2147. }
  2148. /// <summary>
  2149. /// Groups series points in the interval with offset
  2150. /// </summary>
  2151. /// <param name="formula">Grouping formula.</param>
  2152. /// <param name="interval">Interval size.</param>
  2153. /// <param name="intervalType">Interval type.</param>
  2154. /// <param name="intervalOffset">Interval offset size.</param>
  2155. /// <param name="intervalOffsetType">Interval offset type.</param>
  2156. /// <param name="inputSeries">Array of input series.</param>
  2157. /// <param name="outputSeries">Array of output series.</param>
  2158. private void Group(string formula,
  2159. double interval,
  2160. IntervalType intervalType,
  2161. double intervalOffset,
  2162. IntervalType intervalOffsetType,
  2163. Series[] inputSeries,
  2164. Series[] outputSeries)
  2165. {
  2166. // Check arguments
  2167. if (formula == null)
  2168. throw new ArgumentNullException("formula");
  2169. //**************************************************
  2170. //** Check input/output series arrays
  2171. //**************************************************
  2172. CheckSeriesArrays(inputSeries, outputSeries);
  2173. //**************************************************
  2174. //** Check and parse formula
  2175. //**************************************************
  2176. int outputValuesNumber = 1;
  2177. GroupingFunctionInfo[] functions = GetGroupingFunctions(inputSeries, formula, out outputValuesNumber);
  2178. //**************************************************
  2179. //** Loop through all input series
  2180. //**************************************************
  2181. for(int seriesIndex = 0; seriesIndex < inputSeries.Length; seriesIndex++)
  2182. {
  2183. // Define an input and output series
  2184. Series input = inputSeries[seriesIndex];
  2185. Series output = input;
  2186. if(outputSeries != null && seriesIndex < outputSeries.Length)
  2187. {
  2188. output = outputSeries[seriesIndex];
  2189. // Remove all points from the output series
  2190. if(output.Name != input.Name)
  2191. {
  2192. output.Points.Clear();
  2193. // Copy X values type
  2194. if(output.XValueType == ChartValueType.Auto || output.autoXValueType)
  2195. {
  2196. output.XValueType = input.XValueType;
  2197. output.autoXValueType = true;
  2198. }
  2199. // Copy Y values type
  2200. if(output.YValueType == ChartValueType.Auto || output.autoYValueType)
  2201. {
  2202. output.YValueType = input.YValueType;
  2203. output.autoYValueType = true;
  2204. }
  2205. }
  2206. }
  2207. // No points to group
  2208. if(input.Points.Count == 0)
  2209. {
  2210. continue;
  2211. }
  2212. // Make sure there is enough Y values per point
  2213. output.YValuesPerPoint = outputValuesNumber - 1;
  2214. //**************************************************
  2215. //** Initialize interval & value tracking variables
  2216. //**************************************************
  2217. int intervalFirstIndex = 0;
  2218. int intervalLastIndex = 0;
  2219. double intervalFrom = 0;
  2220. double intervalTo = 0;
  2221. // Set interval start point
  2222. intervalFrom = input.Points[0].XValue;
  2223. // Adjust start point depending on the interval type
  2224. intervalFrom = ChartHelper.AlignIntervalStart(intervalFrom, interval, ConvertIntervalType(intervalType));
  2225. // Add offset to the start position
  2226. double offsetFrom = 0;
  2227. if( intervalOffset != 0 )
  2228. {
  2229. offsetFrom = intervalFrom + ChartHelper.GetIntervalSize(intervalFrom,
  2230. intervalOffset,
  2231. ConvertIntervalType(intervalOffsetType));
  2232. // Check if there are points left outside first group
  2233. if(input.Points[0].XValue < offsetFrom)
  2234. {
  2235. if(intervalType == IntervalType.Number)
  2236. {
  2237. intervalFrom = offsetFrom + ChartHelper.GetIntervalSize(offsetFrom,
  2238. -interval,
  2239. ConvertIntervalType(intervalType));
  2240. }
  2241. else
  2242. {
  2243. intervalFrom = offsetFrom - ChartHelper.GetIntervalSize(offsetFrom,
  2244. interval,
  2245. ConvertIntervalType(intervalType));
  2246. }
  2247. intervalTo = offsetFrom;
  2248. }
  2249. else
  2250. {
  2251. intervalFrom = offsetFrom;
  2252. intervalTo = intervalFrom + ChartHelper.GetIntervalSize(intervalFrom, interval, ConvertIntervalType(intervalType));
  2253. }
  2254. }
  2255. else
  2256. {
  2257. intervalTo = intervalFrom + ChartHelper.GetIntervalSize(intervalFrom, interval, ConvertIntervalType(intervalType));
  2258. }
  2259. //**************************************************
  2260. //** Allocate array for storing temp.
  2261. //** values of the point
  2262. //**************************************************
  2263. double[] pointTempValues = new double[outputValuesNumber];
  2264. //**************************************************
  2265. //** Loop through the series points
  2266. //**************************************************
  2267. bool lastPoint = false;
  2268. int emptyPointsSkipped = 0;
  2269. int pointsNumberInInterval = 0;
  2270. for(int pointIndex = 0; pointIndex <= input.Points.Count && !lastPoint; pointIndex++)
  2271. {
  2272. bool endOfInterval = false;
  2273. //**************************************************
  2274. //** Check if series is sorted by X value
  2275. //**************************************************
  2276. if(pointIndex > 0 && pointIndex < input.Points.Count)
  2277. {
  2278. if(input.Points[pointIndex].XValue < input.Points[pointIndex - 1].XValue)
  2279. {
  2280. throw (new InvalidOperationException(SR.ExceptionDataManipulatorGroupedSeriesNotSorted));
  2281. }
  2282. }
  2283. //**************************************************
  2284. //** Check if it's the last point
  2285. //**************************************************
  2286. if(pointIndex == input.Points.Count)
  2287. {
  2288. // End of the group interval detected
  2289. lastPoint = true;
  2290. intervalLastIndex = pointIndex - 1;
  2291. pointIndex = intervalLastIndex;
  2292. endOfInterval = true;
  2293. }
  2294. //**************************************************
  2295. //** Check if current point X value is inside current group
  2296. //**************************************************
  2297. if(!endOfInterval && input.Points[pointIndex].XValue >= intervalTo)
  2298. {
  2299. // End of the group interval detected
  2300. if(pointIndex == 0)
  2301. {
  2302. continue;
  2303. }
  2304. intervalLastIndex = pointIndex - 1;
  2305. endOfInterval = true;
  2306. }
  2307. //**************************************************
  2308. //** Process data at end of the interval
  2309. //**************************************************
  2310. if(endOfInterval)
  2311. {
  2312. // Add grouped point only if there are non empty points in the interval
  2313. if(pointsNumberInInterval > emptyPointsSkipped)
  2314. {
  2315. // Finalize the calculation
  2316. ProcessPointValues(
  2317. functions,
  2318. pointTempValues,
  2319. inputSeries[seriesIndex],
  2320. input.Points[pointIndex],
  2321. pointIndex,
  2322. intervalFirstIndex,
  2323. intervalLastIndex,
  2324. true,
  2325. ref emptyPointsSkipped);
  2326. //**************************************************
  2327. //** Calculate the X values
  2328. //**************************************************
  2329. if(functions[0].function == GroupingFunction.Center)
  2330. {
  2331. pointTempValues[0] = (intervalFrom + intervalTo) / 2.0;
  2332. }
  2333. else if(functions[0].function == GroupingFunction.First)
  2334. {
  2335. pointTempValues[0] = intervalFrom;
  2336. }
  2337. if(functions[0].function == GroupingFunction.Last)
  2338. {
  2339. pointTempValues[0] = intervalTo;
  2340. }
  2341. //**************************************************
  2342. //** Create new point object
  2343. //**************************************************
  2344. DataPoint newPoint = new DataPoint();
  2345. newPoint.ResizeYValueArray(outputValuesNumber - 1);
  2346. newPoint.XValue = pointTempValues[0];
  2347. for(int i = 1; i < pointTempValues.Length; i++)
  2348. {
  2349. newPoint.YValues[i - 1] = pointTempValues[i];
  2350. }
  2351. //**************************************************
  2352. //** Remove grouped points if output and input
  2353. //** series are the same
  2354. //**************************************************
  2355. int newPointIndex = output.Points.Count;
  2356. if(output == input)
  2357. {
  2358. newPointIndex = intervalFirstIndex;
  2359. pointIndex = newPointIndex + 1;
  2360. // Remove grouped points
  2361. for(int removedPoint = intervalFirstIndex; removedPoint <= intervalLastIndex; removedPoint++)
  2362. {
  2363. output.Points.RemoveAt(intervalFirstIndex);
  2364. }
  2365. }
  2366. //**************************************************
  2367. //** Add point to the output series
  2368. //**************************************************
  2369. output.Points.Insert(newPointIndex, newPoint);
  2370. }
  2371. // Set new From To values of the group interval
  2372. intervalFrom = intervalTo;
  2373. intervalTo = intervalFrom + ChartHelper.GetIntervalSize(intervalFrom, interval, ConvertIntervalType(intervalType));
  2374. // Set new group interval indexes
  2375. intervalFirstIndex = pointIndex;
  2376. intervalLastIndex = pointIndex;
  2377. // Reset number of points in the interval
  2378. pointsNumberInInterval = 0;
  2379. // Reset number of skipped points
  2380. emptyPointsSkipped = 0;
  2381. // Process point once again
  2382. --pointIndex;
  2383. continue;
  2384. }
  2385. //**************************************************
  2386. //** Use current point values in the formula
  2387. //**************************************************
  2388. ProcessPointValues(
  2389. functions,
  2390. pointTempValues,
  2391. inputSeries[seriesIndex],
  2392. input.Points[pointIndex],
  2393. pointIndex,
  2394. intervalFirstIndex,
  2395. intervalLastIndex,
  2396. false,
  2397. ref emptyPointsSkipped);
  2398. // Increase number of points in the group
  2399. ++pointsNumberInInterval;
  2400. }
  2401. }
  2402. }
  2403. /// <summary>
  2404. /// Adds current point values to the temp. formula results.
  2405. /// </summary>
  2406. /// <param name="functions">Array of functions type.</param>
  2407. /// <param name="pointTempValues">Temp. point values.</param>
  2408. /// <param name="series">Point series.</param>
  2409. /// <param name="point">Current point.</param>
  2410. /// <param name="pointIndex">Current point index.</param>
  2411. /// <param name="intervalFirstIndex">Index of the first point in the interval.</param>
  2412. /// <param name="intervalLastIndex">Index of the last point in the interval.</param>
  2413. /// <param name="finalPass">Indicates that interval processing is finished.</param>
  2414. /// <param name="numberOfEmptyPoints">Number of skipped points in the interval.</param>
  2415. private void ProcessPointValues(
  2416. GroupingFunctionInfo[] functions,
  2417. double[] pointTempValues,
  2418. Series series,
  2419. DataPoint point,
  2420. int pointIndex,
  2421. int intervalFirstIndex,
  2422. int intervalLastIndex,
  2423. bool finalPass,
  2424. ref int numberOfEmptyPoints)
  2425. {
  2426. //*******************************************************************
  2427. //** Initialize temp data if it's the first point in the interval
  2428. //*******************************************************************
  2429. if(pointIndex == intervalFirstIndex && !finalPass)
  2430. {
  2431. // Initialize values depending on the function type
  2432. int funcIndex = 0;
  2433. foreach(GroupingFunctionInfo functionInfo in functions)
  2434. {
  2435. // Check that we do not exced number of input values
  2436. if(funcIndex > point.YValues.Length)
  2437. {
  2438. break;
  2439. }
  2440. // Initialize with zero
  2441. pointTempValues[functionInfo.outputIndex] = 0;
  2442. // Initialize with custom value depending on the formula
  2443. if(functionInfo.function == GroupingFunction.Min)
  2444. {
  2445. pointTempValues[functionInfo.outputIndex] = double.MaxValue;
  2446. }
  2447. else if(functionInfo.function == GroupingFunction.Max)
  2448. {
  2449. pointTempValues[functionInfo.outputIndex] = double.MinValue;
  2450. }
  2451. else if(functionInfo.function == GroupingFunction.First)
  2452. {
  2453. if(funcIndex == 0)
  2454. {
  2455. pointTempValues[0] = point.XValue;
  2456. }
  2457. else
  2458. {
  2459. pointTempValues[functionInfo.outputIndex] = point.YValues[funcIndex-1];
  2460. }
  2461. }
  2462. else if(functionInfo.function == GroupingFunction.HiLo ||
  2463. functionInfo.function == GroupingFunction.HiLoOpCl)
  2464. {
  2465. // Hi
  2466. pointTempValues[functionInfo.outputIndex] = double.MinValue;
  2467. //Lo
  2468. pointTempValues[functionInfo.outputIndex + 1] = double.MaxValue;
  2469. if(functionInfo.function == GroupingFunction.HiLoOpCl)
  2470. {
  2471. //Open
  2472. pointTempValues[functionInfo.outputIndex + 2] = point.YValues[funcIndex-1];
  2473. //Close
  2474. pointTempValues[functionInfo.outputIndex + 3] = 0;
  2475. }
  2476. }
  2477. // Increase current function index
  2478. ++funcIndex;
  2479. }
  2480. }
  2481. //*******************************************************************
  2482. //** Add points values using formula
  2483. //*******************************************************************
  2484. if(!finalPass)
  2485. {
  2486. //*******************************************************************
  2487. //** Ignore empty points
  2488. //*******************************************************************
  2489. if(point.IsEmpty && this.IsEmptyPointIgnored)
  2490. {
  2491. ++numberOfEmptyPoints;
  2492. return;
  2493. }
  2494. //*******************************************************************
  2495. //** Loop through each grouping function
  2496. //*******************************************************************
  2497. int funcIndex = 0;
  2498. foreach(GroupingFunctionInfo functionInfo in functions)
  2499. {
  2500. // Check that we do not exced number of input values
  2501. if(funcIndex > point.YValues.Length)
  2502. {
  2503. break;
  2504. }
  2505. // Process point values depending on the formula
  2506. if(functionInfo.function == GroupingFunction.Min &&
  2507. (!point.IsEmpty && this.IsEmptyPointIgnored))
  2508. {
  2509. pointTempValues[functionInfo.outputIndex] =
  2510. Math.Min(pointTempValues[functionInfo.outputIndex], point.YValues[funcIndex-1]);
  2511. }
  2512. else if(functionInfo.function == GroupingFunction.Max)
  2513. {
  2514. pointTempValues[functionInfo.outputIndex] =
  2515. Math.Max(pointTempValues[functionInfo.outputIndex], point.YValues[funcIndex-1]);
  2516. }
  2517. else if(functionInfo.function == GroupingFunction.Ave ||
  2518. functionInfo.function == GroupingFunction.Sum)
  2519. {
  2520. if(funcIndex == 0)
  2521. {
  2522. pointTempValues[0] += point.XValue;
  2523. }
  2524. else
  2525. {
  2526. pointTempValues[functionInfo.outputIndex] += point.YValues[funcIndex-1];
  2527. }
  2528. }
  2529. else if(functionInfo.function == GroupingFunction.Variance ||
  2530. functionInfo.function == GroupingFunction.Deviation)
  2531. {
  2532. pointTempValues[functionInfo.outputIndex] += point.YValues[funcIndex-1];
  2533. }
  2534. else if(functionInfo.function == GroupingFunction.Last)
  2535. {
  2536. if(funcIndex == 0)
  2537. {
  2538. pointTempValues[0] = point.XValue;
  2539. }
  2540. else
  2541. {
  2542. pointTempValues[functionInfo.outputIndex] = point.YValues[funcIndex-1];
  2543. }
  2544. }
  2545. else if(functionInfo.function == GroupingFunction.Count)
  2546. {
  2547. pointTempValues[functionInfo.outputIndex] += 1;
  2548. }
  2549. else if(functionInfo.function == GroupingFunction.HiLo ||
  2550. functionInfo.function == GroupingFunction.HiLoOpCl)
  2551. {
  2552. // Hi
  2553. pointTempValues[functionInfo.outputIndex] =
  2554. Math.Max(pointTempValues[functionInfo.outputIndex], point.YValues[funcIndex-1]);
  2555. // Lo
  2556. pointTempValues[functionInfo.outputIndex + 1] =
  2557. Math.Min(pointTempValues[functionInfo.outputIndex + 1], point.YValues[funcIndex-1]);
  2558. if(functionInfo.function == GroupingFunction.HiLoOpCl)
  2559. {
  2560. // Close
  2561. pointTempValues[functionInfo.outputIndex + 3] = point.YValues[funcIndex-1];
  2562. }
  2563. }
  2564. // Increase current function index
  2565. ++funcIndex;
  2566. }
  2567. }
  2568. //*******************************************************************
  2569. //** Adjust formula results at final pass
  2570. //*******************************************************************
  2571. if(finalPass)
  2572. {
  2573. int funcIndex = 0;
  2574. foreach(GroupingFunctionInfo functionInfo in functions)
  2575. {
  2576. // Check that we do not exceed number of input values
  2577. if(funcIndex > point.YValues.Length)
  2578. {
  2579. break;
  2580. }
  2581. if(functionInfo.function == GroupingFunction.Ave)
  2582. {
  2583. pointTempValues[functionInfo.outputIndex] /= intervalLastIndex - intervalFirstIndex - numberOfEmptyPoints + 1;
  2584. }
  2585. if(functionInfo.function == GroupingFunction.DistinctCount)
  2586. {
  2587. // Initialize value with zero
  2588. pointTempValues[functionInfo.outputIndex] = 0;
  2589. // Create a list of uniques values
  2590. ArrayList uniqueValues = new ArrayList(intervalLastIndex - intervalFirstIndex + 1);
  2591. // Second pass through inteval points required for calculations
  2592. for(int secondPassIndex = intervalFirstIndex; secondPassIndex <= intervalLastIndex; secondPassIndex++)
  2593. {
  2594. // Ignore empty points
  2595. if(series.Points[secondPassIndex].IsEmpty && this.IsEmptyPointIgnored)
  2596. {
  2597. continue;
  2598. }
  2599. // Check if current value is in the unique list
  2600. if(!uniqueValues.Contains(series.Points[secondPassIndex].YValues[funcIndex-1]))
  2601. {
  2602. uniqueValues.Add(series.Points[secondPassIndex].YValues[funcIndex-1]);
  2603. }
  2604. }
  2605. // Get count of unique values
  2606. pointTempValues[functionInfo.outputIndex] = uniqueValues.Count;
  2607. }
  2608. else if(functionInfo.function == GroupingFunction.Variance ||
  2609. functionInfo.function == GroupingFunction.Deviation)
  2610. {
  2611. // Calculate average first
  2612. double average = pointTempValues[functionInfo.outputIndex] / (intervalLastIndex - intervalFirstIndex - numberOfEmptyPoints + 1);
  2613. // Second pass through inteval points required for calculations
  2614. pointTempValues[functionInfo.outputIndex] = 0;
  2615. for(int secondPassIndex = intervalFirstIndex; secondPassIndex <= intervalLastIndex; secondPassIndex++)
  2616. {
  2617. // Ignore empty points
  2618. if(series.Points[secondPassIndex].IsEmpty && this.IsEmptyPointIgnored)
  2619. {
  2620. continue;
  2621. }
  2622. pointTempValues[functionInfo.outputIndex] +=
  2623. Math.Pow(series.Points[secondPassIndex].YValues[funcIndex-1] - average, 2);
  2624. }
  2625. // Divide by points number
  2626. pointTempValues[functionInfo.outputIndex] /=
  2627. intervalLastIndex - intervalFirstIndex - numberOfEmptyPoints + 1;
  2628. // If calculating the deviation - take a square root of variance
  2629. if(functionInfo.function == GroupingFunction.Deviation)
  2630. {
  2631. pointTempValues[functionInfo.outputIndex] =
  2632. Math.Sqrt(pointTempValues[functionInfo.outputIndex]);
  2633. }
  2634. }
  2635. // Increase current function index
  2636. ++funcIndex;
  2637. }
  2638. }
  2639. }
  2640. /// <summary>
  2641. /// Checks the formula format and returns an array of formula types
  2642. /// for each X and each Y value of the input series.
  2643. /// </summary>
  2644. /// <param name="inputSeries">Array of input series.</param>
  2645. /// <param name="formula">Formula string.</param>
  2646. /// <param name="outputValuesNumber">Number of values in output series.</param>
  2647. /// <returns>Array of functions for each Y value.</returns>
  2648. private GroupingFunctionInfo[] GetGroupingFunctions(Series[] inputSeries, string formula, out int outputValuesNumber)
  2649. {
  2650. // Get maximum number of Y values in all series
  2651. int numberOfYValues = 0;
  2652. foreach(Series series in inputSeries)
  2653. {
  2654. numberOfYValues = (int)Math.Max(numberOfYValues, series.YValuesPerPoint);
  2655. }
  2656. // Allocate memory for the result array for X and each Y values
  2657. GroupingFunctionInfo[] result = new GroupingFunctionInfo[numberOfYValues + 1];
  2658. for(int index = 0 ; index < result.Length; index++)
  2659. {
  2660. result[index] = new GroupingFunctionInfo();
  2661. }
  2662. // Split formula by comma
  2663. string[] valueFormulas = formula.Split(',');
  2664. // At least one formula must be specified
  2665. if(valueFormulas.Length == 0)
  2666. {
  2667. throw (new ArgumentException(SR.ExceptionDataManipulatorGroupingFormulaUndefined));
  2668. }
  2669. // Check each formula in the array
  2670. GroupingFunctionInfo defaultFormula = new GroupingFunctionInfo();
  2671. foreach(string s in valueFormulas)
  2672. {
  2673. // Trim white space and make upper case
  2674. string formulaString = s.Trim();
  2675. formulaString = formulaString.ToUpper(System.Globalization.CultureInfo.InvariantCulture);
  2676. // Get value index and formula type from the string
  2677. int valueIndex = 1;
  2678. GroupingFunction formulaType = ParseFormulaAndValueType(formulaString, out valueIndex);
  2679. // Save the default (first) formula
  2680. if(defaultFormula.function == GroupingFunction.None)
  2681. {
  2682. defaultFormula.function = formulaType;
  2683. }
  2684. // Check that value index do not exceed the max values number
  2685. if(valueIndex >= result.Length)
  2686. {
  2687. throw(new ArgumentException(SR.ExceptionDataManipulatorYValuesIndexExceeded( formulaString )));
  2688. }
  2689. // Check if formula for this value type was already set
  2690. if(result[valueIndex].function != GroupingFunction.None)
  2691. {
  2692. throw (new ArgumentException(SR.ExceptionDataManipulatorGroupingFormulaAlreadyDefined(formulaString)));
  2693. }
  2694. // Set formula type
  2695. result[valueIndex].function = formulaType;
  2696. }
  2697. // Apply default formula for non set X value
  2698. if(result[0].function == GroupingFunction.None)
  2699. {
  2700. result[0].function = GroupingFunction.First;
  2701. }
  2702. // Apply default formula for all non set Y values
  2703. for(int funcIndex = 1; funcIndex < result.Length; funcIndex++)
  2704. {
  2705. if(result[funcIndex].function == GroupingFunction.None)
  2706. {
  2707. result[funcIndex].function = defaultFormula.function;
  2708. }
  2709. }
  2710. // Specify output value index
  2711. outputValuesNumber = 0;
  2712. for(int funcIndex = 0; funcIndex < result.Length; funcIndex++)
  2713. {
  2714. result[funcIndex].outputIndex = outputValuesNumber;
  2715. if(result[funcIndex].function == GroupingFunction.HiLoOpCl)
  2716. {
  2717. outputValuesNumber += 3;
  2718. }
  2719. else if(result[funcIndex].function == GroupingFunction.HiLo)
  2720. {
  2721. outputValuesNumber += 1;
  2722. }
  2723. ++outputValuesNumber;
  2724. }
  2725. // X value formula can be FIRST, LAST and AVE
  2726. if(result[0].function != GroupingFunction.First &&
  2727. result[0].function != GroupingFunction.Last &&
  2728. result[0].function != GroupingFunction.Center)
  2729. {
  2730. throw (new ArgumentException(SR.ExceptionDataManipulatorGroupingFormulaUnsupported));
  2731. }
  2732. return result;
  2733. }
  2734. /// <summary>
  2735. /// Parse one formula with optional value prefix.
  2736. /// Example: "Y2:MAX"
  2737. /// </summary>
  2738. /// <param name="formulaString">One formula name with optional value prefix.</param>
  2739. /// <param name="valueIndex">Return value index.</param>
  2740. /// <returns>Formula type.</returns>
  2741. private GroupingFunction ParseFormulaAndValueType(string formulaString, out int valueIndex)
  2742. {
  2743. // Initialize value index as first Y value (default)
  2744. valueIndex = 1;
  2745. // Split formula by optional ':' character
  2746. string[] formulaParts = formulaString.Split(':');
  2747. // There must be at least one and no more than two result strings
  2748. if(formulaParts.Length < 1 && formulaParts.Length > 2)
  2749. {
  2750. throw(new ArgumentException(SR.ExceptionDataManipulatorGroupingFormulaFormatInvalid( formulaString )));
  2751. }
  2752. // Check specified value type
  2753. if(formulaParts.Length == 2)
  2754. {
  2755. if(formulaParts[0] == "X")
  2756. {
  2757. valueIndex = 0;
  2758. }
  2759. else if(formulaParts[0].StartsWith("Y", StringComparison.Ordinal))
  2760. {
  2761. formulaParts[0] = formulaParts[0].TrimStart('Y');
  2762. if(formulaParts[0].Length == 0)
  2763. {
  2764. valueIndex = 1;
  2765. }
  2766. else
  2767. {
  2768. // Try to convert the rest of the string to integer
  2769. try
  2770. {
  2771. valueIndex = Int32.Parse(formulaParts[0], System.Globalization.CultureInfo.InvariantCulture);
  2772. }
  2773. catch(System.Exception)
  2774. {
  2775. throw (new ArgumentException(SR.ExceptionDataManipulatorGroupingFormulaFormatInvalid( formulaString )));
  2776. }
  2777. }
  2778. }
  2779. else
  2780. {
  2781. throw (new ArgumentException(SR.ExceptionDataManipulatorGroupingFormulaFormatInvalid( formulaString )));
  2782. }
  2783. }
  2784. // Check formula name
  2785. if(formulaParts[formulaParts.Length - 1] == "MIN")
  2786. return GroupingFunction.Min;
  2787. else if(formulaParts[formulaParts.Length - 1] == "MAX")
  2788. return GroupingFunction.Max;
  2789. else if(formulaParts[formulaParts.Length - 1] == "AVE")
  2790. return GroupingFunction.Ave;
  2791. else if(formulaParts[formulaParts.Length - 1] == "SUM")
  2792. return GroupingFunction.Sum;
  2793. else if(formulaParts[formulaParts.Length - 1] == "FIRST")
  2794. return GroupingFunction.First;
  2795. else if(formulaParts[formulaParts.Length - 1] == "LAST")
  2796. return GroupingFunction.Last;
  2797. else if(formulaParts[formulaParts.Length - 1] == "HILOOPCL")
  2798. return GroupingFunction.HiLoOpCl;
  2799. else if(formulaParts[formulaParts.Length - 1] == "HILO")
  2800. return GroupingFunction.HiLo;
  2801. else if(formulaParts[formulaParts.Length - 1] == "COUNT")
  2802. return GroupingFunction.Count;
  2803. else if(formulaParts[formulaParts.Length - 1] == "DISTINCTCOUNT")
  2804. return GroupingFunction.DistinctCount;
  2805. else if(formulaParts[formulaParts.Length - 1] == "VARIANCE")
  2806. return GroupingFunction.Variance;
  2807. else if(formulaParts[formulaParts.Length - 1] == "DEVIATION")
  2808. return GroupingFunction.Deviation;
  2809. else if(formulaParts[formulaParts.Length - 1] == "CENTER")
  2810. return GroupingFunction.Center;
  2811. // Invalid formula name
  2812. throw (new ArgumentException(SR.ExceptionDataManipulatorGroupingFormulaNameInvalid(formulaString)));
  2813. }
  2814. /// <summary>
  2815. /// Checks if input/output series parameters are correct.
  2816. /// If not - fires an exception
  2817. /// </summary>
  2818. /// <param name="inputSeries">Input series array.</param>
  2819. /// <param name="outputSeries">Output series array.</param>
  2820. private void CheckSeriesArrays(Series[] inputSeries, Series[] outputSeries)
  2821. {
  2822. // At least one series must be in the input series
  2823. if(inputSeries == null || inputSeries.Length == 0)
  2824. {
  2825. throw (new ArgumentException(SR.ExceptionDataManipulatorGroupingInputSeriesUndefined));
  2826. }
  2827. // Output series must be empty or have the same number of items
  2828. if(outputSeries != null && outputSeries.Length != inputSeries.Length)
  2829. {
  2830. throw (new ArgumentException(SR.ExceptionDataManipulatorGroupingInputOutputSeriesNumberMismatch));
  2831. }
  2832. }
  2833. #endregion
  2834. #region Grouping overloaded methods
  2835. /// <summary>
  2836. /// Groups data using one or more formulas.
  2837. /// The series that is grouped is cleared of its original data, and used to store the new data points.
  2838. /// </summary>
  2839. /// <param name="formula">Grouping formula.</param>
  2840. /// <param name="interval">Interval size.</param>
  2841. /// <param name="intervalType">Interval type.</param>
  2842. /// <param name="inputSeries">Input series.</param>
  2843. public void Group(string formula,
  2844. double interval,
  2845. IntervalType intervalType,
  2846. Series inputSeries)
  2847. {
  2848. // Check arguments
  2849. if (inputSeries == null)
  2850. throw new ArgumentNullException("inputSeries");
  2851. Group(formula, interval, intervalType, inputSeries, null);
  2852. }
  2853. /// <summary>
  2854. /// Groups data using one or more formulas.
  2855. /// Series are cleared of their original data and used to store the new data points.
  2856. /// </summary>
  2857. /// <param name="formula">Grouping formula.</param>
  2858. /// <param name="interval">Interval size.</param>
  2859. /// <param name="intervalType">Interval type.</param>
  2860. /// <param name="inputSeriesName">Comma separated list of input series names.</param>
  2861. public void Group(string formula,
  2862. double interval,
  2863. IntervalType intervalType,
  2864. string inputSeriesName)
  2865. {
  2866. // Check arguments
  2867. if (inputSeriesName == null)
  2868. throw new ArgumentNullException("inputSeriesName");
  2869. Group(formula, interval, intervalType, inputSeriesName, "");
  2870. }
  2871. /// <summary>
  2872. /// Groups data using one or more formulas.
  2873. /// The series that is grouped is cleared of its original data, and used to store the new data points.
  2874. /// </summary>
  2875. /// <param name="formula">Grouping formula.</param>
  2876. /// <param name="interval">Interval size.</param>
  2877. /// <param name="intervalType">Interval type.</param>
  2878. /// <param name="intervalOffset">Interval offset size.</param>
  2879. /// <param name="intervalOffsetType">Interval offset type.</param>
  2880. /// <param name="inputSeries">Input series.</param>
  2881. public void Group(string formula,
  2882. double interval,
  2883. IntervalType intervalType,
  2884. double intervalOffset,
  2885. IntervalType intervalOffsetType,
  2886. Series inputSeries)
  2887. {
  2888. // Check arguments
  2889. if (inputSeries == null)
  2890. throw new ArgumentNullException("inputSeries");
  2891. Group(formula, interval, intervalType, intervalOffset, intervalOffsetType, inputSeries, null);
  2892. }
  2893. /// <summary>
  2894. /// Groups data using one or more formulas.
  2895. /// Series are cleared of their original data and used to store the new data points.
  2896. /// </summary>
  2897. /// <param name="formula">Grouping formula.</param>
  2898. /// <param name="interval">Interval size.</param>
  2899. /// <param name="intervalType">Interval type.</param>
  2900. /// <param name="intervalOffset">Interval offset size.</param>
  2901. /// <param name="intervalOffsetType">Interval offset type.</param>
  2902. /// <param name="inputSeriesName">Comma separated list of input series names.</param>
  2903. public void Group(string formula,
  2904. double interval,
  2905. IntervalType intervalType,
  2906. double intervalOffset,
  2907. IntervalType intervalOffsetType,
  2908. string inputSeriesName)
  2909. {
  2910. // Check arguments
  2911. if (inputSeriesName == null)
  2912. throw new ArgumentNullException("inputSeriesName");
  2913. Group(formula, interval, intervalType, intervalOffset, intervalOffsetType, inputSeriesName, "");
  2914. }
  2915. /// <summary>
  2916. /// Groups series data by axis labels using one or more formulas.
  2917. /// Output series are used to store the grouped data points.
  2918. /// </summary>
  2919. /// <param name="formula">Grouping formula.</param>
  2920. /// <param name="inputSeriesName">Comma separated list of input series names.</param>
  2921. /// <param name="outputSeriesName">Comma separated list of output series names.</param>
  2922. public void GroupByAxisLabel(string formula, string inputSeriesName, string outputSeriesName)
  2923. {
  2924. // Check arguments
  2925. if (inputSeriesName == null)
  2926. throw new ArgumentNullException("inputSeriesName");
  2927. GroupByAxisLabel(formula,
  2928. ConvertToSeriesArray(inputSeriesName, false),
  2929. ConvertToSeriesArray(outputSeriesName, true));
  2930. }
  2931. /// <summary>
  2932. /// Groups a series' data by axis labels using one or more formulas.
  2933. /// The series is cleared of its original data, and then used to store the new data points.
  2934. /// </summary>
  2935. /// <param name="formula">Grouping formula.</param>
  2936. /// <param name="inputSeries">Input data series.</param>
  2937. public void GroupByAxisLabel(string formula, Series inputSeries)
  2938. {
  2939. // Check arguments
  2940. if (inputSeries == null)
  2941. throw new ArgumentNullException("inputSeries");
  2942. GroupByAxisLabel(formula, inputSeries, null);
  2943. }
  2944. /// <summary>
  2945. /// Groups series data by axis labels using one or more formulas.
  2946. /// Each series that is grouped is cleared of its original data, and used to store the new data points.
  2947. /// </summary>
  2948. /// <param name="formula">Grouping formula.</param>
  2949. /// <param name="inputSeriesName">Comma separated list of input series names.</param>
  2950. public void GroupByAxisLabel(string formula, string inputSeriesName)
  2951. {
  2952. // Check arguments
  2953. if (inputSeriesName == null)
  2954. throw new ArgumentNullException("inputSeriesName");
  2955. GroupByAxisLabel(formula, inputSeriesName, null);
  2956. }
  2957. /// <summary>
  2958. /// Groups series using one or more formulas.
  2959. /// Output series are used to store the grouped data points, and an offset can be used for intervals.
  2960. /// </summary>
  2961. /// <param name="formula">Grouping formula.</param>
  2962. /// <param name="interval">Interval size.</param>
  2963. /// <param name="intervalType">Interval type.</param>
  2964. /// <param name="intervalOffset">Interval offset size.</param>
  2965. /// <param name="intervalOffsetType">Interval offset type.</param>
  2966. /// <param name="inputSeriesName">Comma separated list of input series names.</param>
  2967. /// <param name="outputSeriesName">Comma separated list of output series names.</param>
  2968. public void Group(string formula,
  2969. double interval,
  2970. IntervalType intervalType,
  2971. double intervalOffset,
  2972. IntervalType intervalOffsetType,
  2973. string inputSeriesName,
  2974. string outputSeriesName)
  2975. {
  2976. // Check arguments
  2977. if (inputSeriesName == null)
  2978. throw new ArgumentNullException("inputSeriesName");
  2979. Group(formula,
  2980. interval,
  2981. intervalType,
  2982. intervalOffset,
  2983. intervalOffsetType,
  2984. ConvertToSeriesArray(inputSeriesName, false),
  2985. ConvertToSeriesArray(outputSeriesName, true));
  2986. }
  2987. /// <summary>
  2988. /// Groups a series' data using one or more formulas.
  2989. /// An output series is used to store the grouped data points.
  2990. /// </summary>
  2991. /// <param name="formula">Grouping formula.</param>
  2992. /// <param name="interval">Interval size.</param>
  2993. /// <param name="intervalType">Interval type.</param>
  2994. /// <param name="inputSeries">Input data series.</param>
  2995. /// <param name="outputSeries">Output data series.</param>
  2996. public void Group(string formula,
  2997. double interval,
  2998. IntervalType intervalType,
  2999. Series inputSeries,
  3000. Series outputSeries)
  3001. {
  3002. // Check arguments
  3003. if (inputSeries == null)
  3004. throw new ArgumentNullException("inputSeries");
  3005. Group(formula, interval, intervalType, 0, IntervalType.Number, inputSeries, outputSeries);
  3006. }
  3007. /// <summary>
  3008. /// Groups data for series using one or more formulas.
  3009. /// Output series are used to store the grouped data points.
  3010. /// </summary>
  3011. /// <param name="formula">Grouping formula.</param>
  3012. /// <param name="interval">Interval size.</param>
  3013. /// <param name="intervalType">Interval type.</param>
  3014. /// <param name="inputSeriesName">Comma separated list of input series names.</param>
  3015. /// <param name="outputSeriesName">Comma separated list of output series names.</param>
  3016. public void Group(string formula,
  3017. double interval,
  3018. IntervalType intervalType,
  3019. string inputSeriesName,
  3020. string outputSeriesName)
  3021. {
  3022. // Check arguments
  3023. if (inputSeriesName == null)
  3024. throw new ArgumentNullException("inputSeriesName");
  3025. Group(formula, interval, intervalType, 0, IntervalType.Number, inputSeriesName, outputSeriesName);
  3026. }
  3027. /// <summary>
  3028. /// Groups a series using one or more formulas.
  3029. /// An output series is used to store the grouped data points, and an offset can be used for intervals.
  3030. /// </summary>
  3031. /// <param name="formula">Grouping formula.</param>
  3032. /// <param name="interval">Interval size.</param>
  3033. /// <param name="intervalType">Interval type.</param>
  3034. /// <param name="intervalOffset">Interval offset size.</param>
  3035. /// <param name="intervalOffsetType">Interval offset type.</param>
  3036. /// <param name="inputSeries">Input data series.</param>
  3037. /// <param name="outputSeries">Output data series.</param>
  3038. public void Group(string formula,
  3039. double interval,
  3040. IntervalType intervalType,
  3041. double intervalOffset,
  3042. IntervalType intervalOffsetType,
  3043. Series inputSeries,
  3044. Series outputSeries)
  3045. {
  3046. // Check arguments
  3047. if (inputSeries == null)
  3048. throw new ArgumentNullException("inputSeries");
  3049. Group(formula,
  3050. interval,
  3051. intervalType,
  3052. intervalOffset,
  3053. intervalOffsetType,
  3054. ConvertToSeriesArray(inputSeries, false),
  3055. ConvertToSeriesArray(outputSeries, false));
  3056. }
  3057. /// <summary>
  3058. /// Groups a series' data by axis labels using one or more formulas.
  3059. /// An output series is used to store the grouped data points.
  3060. /// </summary>
  3061. /// <param name="formula">Grouping formula.</param>
  3062. /// <param name="inputSeries">Input data series.</param>
  3063. /// <param name="outputSeries">Output data series.</param>
  3064. public void GroupByAxisLabel(string formula, Series inputSeries, Series outputSeries)
  3065. {
  3066. // Check arguments
  3067. if (inputSeries == null)
  3068. throw new ArgumentNullException("inputSeries");
  3069. GroupByAxisLabel(formula,
  3070. ConvertToSeriesArray(inputSeries, false),
  3071. ConvertToSeriesArray(outputSeries, false));
  3072. }
  3073. #endregion
  3074. }
  3075. }