DataManagerEditors.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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: Design-time editors and converter classes for the
  6. // Series and DataPoint properties.
  7. //
  8. #if DESIGNER
  9. using System.Collections;
  10. using System.ComponentModel;
  11. using System.ComponentModel.Design;
  12. using System.Diagnostics.CodeAnalysis;
  13. using System.Drawing.Design;
  14. using FastReport.DataVisualization.Charting;
  15. using FastReport.DataVisualization.Charting.ChartTypes;
  16. namespace FastReport.Design.DataVisualization.Charting
  17. {
  18. /// <summary>
  19. /// UI type editor for the Y data source members of the series.
  20. /// </summary>
  21. internal class SeriesDataSourceMemberValueAxisUITypeEditor : System.Drawing.Design.UITypeEditor
  22. {
  23. #region Editor methods and properties
  24. internal virtual SeriesDataSourceMemberYCheckedListBox GetDropDownControl(Chart chart, ITypeDescriptorContext context, object value, bool flag)
  25. {
  26. return new SeriesDataSourceMemberYCheckedListBox(chart, value, flag);
  27. }
  28. /// <summary>
  29. /// Display a drop down list with check boxes.
  30. /// </summary>
  31. /// <param name="context">Editing context.</param>
  32. /// <param name="provider">Provider.</param>
  33. /// <param name="value">Value to edit.</param>
  34. /// <returns>Result</returns>
  35. public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
  36. {
  37. if (context != null && context.Instance != null && provider != null)
  38. {
  39. IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
  40. if(edSvc != null)
  41. {
  42. Chart chart = ConverterHelper.GetChartFromContext(context);
  43. if(chart != null)
  44. {
  45. // Create control for editing
  46. SeriesDataSourceMemberYCheckedListBox control = this.GetDropDownControl(chart, context, value, true);
  47. // Show drop down control
  48. edSvc.DropDownControl(control);
  49. // Get new enumeration value
  50. value = control.GetNewValue();
  51. }
  52. }
  53. }
  54. return value;
  55. }
  56. /// <summary>
  57. /// Gets editing style.
  58. /// </summary>
  59. /// <param name="context">Editing context.</param>
  60. /// <returns>Editor style.</returns>
  61. public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
  62. {
  63. if (context != null && context.Instance != null)
  64. {
  65. // Check how many Y values in the series.
  66. int yValuesNumber = 1;
  67. if(context.Instance is Series)
  68. {
  69. yValuesNumber = ((Series)context.Instance).YValuesPerPoint;
  70. }
  71. else if(context.Instance is Array)
  72. {
  73. Array array = (Array)context.Instance;
  74. if(array.Length > 0 && array.GetValue(0) is Series)
  75. {
  76. yValuesNumber = Math.Max(yValuesNumber, ((Series)array.GetValue(0)).YValuesPerPoint);
  77. }
  78. }
  79. return (yValuesNumber == 1) ? UITypeEditorEditStyle.None : UITypeEditorEditStyle.DropDown;
  80. }
  81. return base.GetEditStyle(context);
  82. }
  83. #endregion
  84. }
  85. /// <summary>
  86. /// Checked list box, which is used for the series Y dats source member UI type editing.
  87. /// </summary>
  88. internal class SeriesDataSourceMemberYCheckedListBox : CheckedListBox
  89. {
  90. // Chart object
  91. private Chart _chart = null;
  92. // Object to edit
  93. protected object editValue = null;
  94. // Indicates that editor was used for the Y values members
  95. protected bool usedForYValue = false;
  96. #region Control constructor
  97. /// <summary>
  98. /// Public constructor.
  99. /// </summary>
  100. /// <param name="chart">Chart control.</param>
  101. ///
  102. /// <param name="editValue">Value to edit.</param>
  103. /// <param name="usedForYValue">Indicates that editor was used for the Y values members.</param>
  104. public SeriesDataSourceMemberYCheckedListBox(Chart chart, object editValue, bool usedForYValue)
  105. {
  106. // Set editable value
  107. this.editValue = editValue;
  108. this.usedForYValue = usedForYValue;
  109. // Set control border style
  110. this.BorderStyle = System.Windows.Forms.BorderStyle.None;
  111. this.IntegralHeight = false;
  112. // Fill member items list
  113. //this.FillList();
  114. // Set Chart
  115. _chart = chart;
  116. }
  117. #endregion
  118. #region Control methods
  119. protected override void OnCreateControl()
  120. {
  121. this.FillList();
  122. }
  123. internal virtual ArrayList GetMemberNames()
  124. {
  125. object dataSource = null;
  126. if (ChartWinDesigner.controlDesigner != null)
  127. {
  128. dataSource = ChartWinDesigner.controlDesigner.GetControlDataSource(_chart);
  129. }
  130. // Get list of members
  131. if (dataSource != null)
  132. {
  133. return ChartImage.GetDataSourceMemberNames(dataSource, this.usedForYValue);
  134. }
  135. return new ArrayList();
  136. }
  137. /// <summary>
  138. /// Fills checked list items
  139. /// </summary>
  140. private void FillList()
  141. {
  142. // Create arry of current names
  143. string[] currentNames = null;
  144. if (editValue != null && editValue is string)
  145. {
  146. string editedString = (string)editValue;
  147. currentNames = editedString.Split(',');
  148. }
  149. ArrayList memberNames = this.GetMemberNames();
  150. // Fill list with all possible values in the enumeration
  151. foreach (string name in memberNames)
  152. {
  153. // Test if item should be checked by default
  154. bool isChecked = false;
  155. if (currentNames != null)
  156. {
  157. foreach (string curName in currentNames)
  158. {
  159. if (name == curName.Trim())
  160. {
  161. isChecked = true;
  162. }
  163. }
  164. }
  165. // Add items into the list
  166. this.Items.Add(name, isChecked);
  167. }
  168. }
  169. /// <summary>
  170. /// Gets new enumeration value.
  171. /// </summary>
  172. /// <returns>New enum value.</returns>
  173. public string GetNewValue()
  174. {
  175. // Update enumeration flags
  176. string result = String.Empty;
  177. foreach (object checkedItem in this.CheckedItems)
  178. {
  179. if (result.Length > 0)
  180. {
  181. result += ", ";
  182. }
  183. result += (string)checkedItem;
  184. }
  185. // Return value
  186. return result;
  187. }
  188. #endregion
  189. }
  190. /// <summary>
  191. /// Chart type editor. Paint chart type image in the property grid.
  192. /// </summary>
  193. internal class ChartTypeEditor : UITypeEditor
  194. {
  195. #region Converter methods
  196. // Reference to the chart type registry
  197. private ChartTypeRegistry _chartTypeRegistry = null;
  198. /// <summary>
  199. /// Override this function to support chart type drawing
  200. /// </summary>
  201. /// <param name="context">Descriptor context.</param>
  202. /// <returns>Can paint values.</returns>
  203. public override bool GetPaintValueSupported(ITypeDescriptorContext context)
  204. {
  205. // Initialize the chartTypeRegistry using context
  206. if (context != null && context.Instance != null)
  207. {
  208. IChartElement chartElement = context.Instance as IChartElement;
  209. if (chartElement != null)
  210. {
  211. this._chartTypeRegistry = chartElement.Common.ChartTypeRegistry;
  212. }
  213. }
  214. // Always return true
  215. return true;
  216. }
  217. /// <summary>
  218. /// Override this function to support chart type drawing
  219. /// </summary>
  220. /// <param name="e">Paint value event arguments.</param>
  221. public override void PaintValue(PaintValueEventArgs e)
  222. {
  223. string chartTypeName = String.Empty;
  224. if(_chartTypeRegistry != null && e != null)
  225. {
  226. if(e.Value is string)
  227. {
  228. chartTypeName = (string)e.Value;
  229. }
  230. else if(e.Value is SeriesChartType)
  231. {
  232. chartTypeName = Series.GetChartTypeName((SeriesChartType)e.Value);
  233. }
  234. if(!string.IsNullOrEmpty(chartTypeName))
  235. {
  236. IChartType chartType = _chartTypeRegistry.GetChartType(chartTypeName);
  237. // Get imahe from the chart type
  238. System.Drawing.Image chartImage = null;
  239. if(chartType != null)
  240. {
  241. chartImage = chartType.GetImage(_chartTypeRegistry);
  242. }
  243. // Draw image
  244. if(chartImage != null)
  245. {
  246. e.Graphics.DrawImage(chartImage, e.Bounds);
  247. }
  248. }
  249. }
  250. }
  251. #endregion
  252. }
  253. /// <summary>
  254. /// Designer editor for the data points collection.
  255. /// </summary>
  256. internal class DataPointCollectionEditor : ChartCollectionEditor
  257. {
  258. #region Editor methods
  259. /// <summary>
  260. /// Default constructor
  261. /// </summary>
  262. public DataPointCollectionEditor() : base(typeof(DataPointCollection))
  263. {
  264. }
  265. /// <summary>
  266. /// Do not allow to edit if multiple series selected.
  267. /// </summary>
  268. /// <param name="context">Descriptor context.</param>
  269. /// <param name="provider">Service provider.</param>
  270. /// <param name="value">Value to edit.</param>
  271. /// <returns>The new value of the object.</returns>
  272. public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
  273. {
  274. if (context != null && context.Instance != null)
  275. {
  276. // Save current control type descriptor context
  277. if(!(context.Instance is Series))
  278. {
  279. throw (new InvalidOperationException(SR.ExceptionEditorMultipleSeriesEditiingUnsupported));
  280. }
  281. }
  282. return base.EditValue(context, provider, value);
  283. }
  284. /// <summary>
  285. /// Create instance of data point object
  286. /// </summary>
  287. /// <param name="itemType">Item type.</param>
  288. /// <returns>New item instance.</returns>
  289. protected override object CreateInstance(Type itemType)
  290. {
  291. if (Context != null && Context.Instance != null)
  292. {
  293. if (Context.Instance is Series)
  294. {
  295. Series series = (Series)Context.Instance;
  296. DataPoint newDataPoint = new DataPoint(series);
  297. return newDataPoint;
  298. }
  299. else if(Context.Instance is Array)
  300. {
  301. throw (new InvalidOperationException(SR.ExceptionEditorMultipleSeriesEditiingUnsupported));
  302. }
  303. }
  304. return base.CreateInstance(itemType);
  305. }
  306. #endregion
  307. }
  308. /// <summary>
  309. /// Collection editor that supports property help in the property grid
  310. /// </summary>
  311. internal class ChartCollectionEditor : CollectionEditor
  312. {
  313. #region Editor methods and properties
  314. // Collection editor form
  315. CollectionForm _form = null;
  316. Chart _chart = null;
  317. ITypeDescriptorContext _context = null;
  318. // Help topic string
  319. string _helpTopic = "";
  320. /// <summary>
  321. /// Object constructor.
  322. /// </summary>
  323. /// <param name="type">AxisName.</param>
  324. public ChartCollectionEditor(Type type) : base(type)
  325. {
  326. }
  327. /// <summary>
  328. /// Edit object's value.
  329. /// </summary>
  330. /// <param name="context">Descriptor context.</param>
  331. /// <param name="provider">Service provider.</param>
  332. /// <param name="value">Value to edit.</param>
  333. /// <returns>The new value of the object.</returns>
  334. public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
  335. {
  336. _context = context;
  337. if (context != null && context.Instance != null)
  338. {
  339. // Save current control type descriptor context
  340. _chart = context.Instance as Chart;
  341. }
  342. INameController controller = value as INameController;
  343. bool isReferenceCollection = controller != null && (value is ChartAreaCollection || value is LegendCollection);
  344. try
  345. {
  346. if (isReferenceCollection)
  347. {
  348. controller.DoSnapshot(true,
  349. new EventHandler<NameReferenceChangedEventArgs>(OnNameReferenceChanging),
  350. new EventHandler<NameReferenceChangedEventArgs>(OnNameReferenceChanged)
  351. );
  352. controller.IsColectionEditing = true;
  353. }
  354. return base.EditValue(context, provider, value);;
  355. }
  356. finally
  357. {
  358. if (isReferenceCollection)
  359. {
  360. controller.IsColectionEditing = false;
  361. controller.DoSnapshot(false,
  362. new EventHandler<NameReferenceChangedEventArgs>(OnNameReferenceChanging),
  363. new EventHandler<NameReferenceChangedEventArgs>(OnNameReferenceChanged)
  364. );
  365. }
  366. }
  367. }
  368. /// <summary>
  369. /// Called when [name reference changing].
  370. /// </summary>
  371. /// <param name="sender">The sender.</param>
  372. /// <param name="e">The <see cref="NameReferenceChangedEventArgs"/> instance containing the event data.</param>
  373. private void OnNameReferenceChanging(object sender, NameReferenceChangedEventArgs e)
  374. {
  375. IComponentChangeService svc = _context.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
  376. if (svc != null)
  377. {
  378. svc.OnComponentChanging(this._chart, null);
  379. }
  380. }
  381. /// <summary>
  382. /// Called when [name reference changed].
  383. /// </summary>
  384. /// <param name="sender">The sender.</param>
  385. /// <param name="e">The <see cref="NameReferenceChangedEventArgs"/> instance containing the event data.</param>
  386. private void OnNameReferenceChanged(object sender, NameReferenceChangedEventArgs e)
  387. {
  388. IComponentChangeService svc = _context.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
  389. if (svc != null)
  390. {
  391. svc.OnComponentChanged(this._chart, null, null, null);
  392. }
  393. }
  394. /// <summary>
  395. /// Sets the specified array as the items of the collection.
  396. /// </summary>
  397. /// <param name="editValue">The collection to edit.</param>
  398. /// <param name="value">An array of objects to set as the collection items.</param>
  399. /// <returns>
  400. /// The newly created collection object or, otherwise, the collection indicated by the <paramref name="editValue"/> parameter.
  401. /// </returns>
  402. protected override object SetItems(object editValue, object[] value)
  403. {
  404. object result = base.SetItems(editValue, value);
  405. IComponentChangeService svc = _context.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
  406. INameController controller = editValue as INameController;
  407. if (controller != null && svc != null && (editValue is ChartAreaCollection || editValue is LegendCollection))
  408. {
  409. IList newList = (IList)result;
  410. bool elementsRemoved = false;
  411. foreach (ChartNamedElement element in controller.Snapshot)
  412. {
  413. if (newList.IndexOf(element) < 0)
  414. {
  415. elementsRemoved = true;
  416. }
  417. }
  418. if (elementsRemoved)
  419. {
  420. svc.OnComponentChanging(this._chart, null);
  421. ChartNamedElement defaultElement = (ChartNamedElement)(newList.Count > 0 ? newList[0] : null);
  422. foreach (ChartNamedElement element in controller.Snapshot)
  423. {
  424. if (newList.IndexOf(element) < 0)
  425. {
  426. controller.OnNameReferenceChanged(new NameReferenceChangedEventArgs(element, defaultElement));
  427. }
  428. }
  429. svc.OnComponentChanged(this._chart, null, null, null);
  430. }
  431. }
  432. return result;
  433. }
  434. /// <summary>
  435. /// Ovveride the HelpTopic property to provide different topics,
  436. /// depending on selected property.
  437. /// </summary>
  438. protected override string HelpTopic
  439. {
  440. get
  441. {
  442. return (_helpTopic.Length == 0) ? base.HelpTopic : _helpTopic;
  443. }
  444. }
  445. /// <summary>
  446. /// Displaying help for the curently selected item in the property grid
  447. /// </summary>
  448. protected override void ShowHelp()
  449. {
  450. // Init topic name
  451. _helpTopic = "";
  452. PropertyGrid grid = this.GetPropertyGrid(_form.Controls);
  453. // Check currently selected grid item
  454. if(grid != null)
  455. {
  456. GridItem item = grid.SelectedGridItem;
  457. if(item != null && (item.GridItemType == GridItemType.Property || item.GridItemType == GridItemType.ArrayValue))
  458. {
  459. _helpTopic = item.PropertyDescriptor.ComponentType.ToString() + "." + item.PropertyDescriptor.Name;
  460. }
  461. }
  462. // Call base class
  463. base.ShowHelp();
  464. // Re-Init topic name
  465. _helpTopic = "";
  466. }
  467. /// <summary>
  468. /// Returns the collection form property grid. Added for VS2005 compatibility.
  469. /// </summary>
  470. /// <param name="controls"></param>
  471. /// <returns></returns>
  472. private PropertyGrid GetPropertyGrid(System.Windows.Forms.Control.ControlCollection controls)
  473. {
  474. foreach (System.Windows.Forms.Control control in controls)
  475. {
  476. PropertyGrid grid = control as PropertyGrid;
  477. if (grid != null)
  478. {
  479. return grid;
  480. }
  481. if (control.Controls.Count > 0)
  482. {
  483. grid = GetPropertyGrid(control.Controls);
  484. if (grid != null)
  485. {
  486. return grid;
  487. }
  488. }
  489. }
  490. return null;
  491. }
  492. /// <summary>
  493. /// Collect the collection editor form buttons into array. Added for VS2005 compatibility.
  494. /// </summary>
  495. /// <param name="buttons"></param>
  496. /// <param name="controls"></param>
  497. private void CollectButtons(ArrayList buttons, System.Windows.Forms.Control.ControlCollection controls)
  498. {
  499. foreach (System.Windows.Forms.Control control in controls)
  500. {
  501. if (control is System.Windows.Forms.Button)
  502. {
  503. buttons.Add(control);
  504. }
  505. if (control.Controls.Count > 0)
  506. {
  507. CollectButtons(buttons, control.Controls);
  508. }
  509. }
  510. }
  511. /// <summary>
  512. /// Cretaes form for collection editing.
  513. /// </summary>
  514. /// <returns>Form object.</returns>
  515. protected override CollectionForm CreateCollectionForm()
  516. {
  517. _form = base.CreateCollectionForm();
  518. // Changed Apr 29, DT, for VS2005 compatibility
  519. PropertyGrid grid = GetPropertyGrid(_form.Controls);
  520. if (grid != null)
  521. {
  522. // Show properties help
  523. grid.HelpVisible = true;
  524. grid.CommandsVisibleIfAvailable = true;
  525. // Hookup to the update events
  526. grid.PropertyValueChanged += new PropertyValueChangedEventHandler(this.OnPropertyChanged);
  527. grid.ControlAdded += new ControlEventHandler(this.OnControlAddedRemoved);
  528. grid.ControlRemoved += new ControlEventHandler(this.OnControlAddedRemoved);
  529. }
  530. // Changed Apr 29, DT, for VS2005 compatibility
  531. ArrayList buttons = new ArrayList();
  532. this.CollectButtons(buttons, _form.Controls);
  533. foreach (System.Windows.Forms.Button button in buttons)
  534. {
  535. if (button.DialogResult == DialogResult.OK ||
  536. button.DialogResult == DialogResult.Cancel)
  537. {
  538. button.Click += new EventHandler(this.OnOkClicked);
  539. }
  540. }
  541. return _form;
  542. }
  543. /// <summary>
  544. /// Update design-time HTML when OK button is clicked in the collection editor
  545. /// </summary>
  546. private void OnOkClicked(object sender, EventArgs e)
  547. {
  548. // Clear the help topic
  549. _helpTopic = "";
  550. }
  551. /// <summary>
  552. /// Update design-time HTML when propery is added or removed
  553. /// </summary>
  554. private void OnControlAddedRemoved(object sender, ControlEventArgs e)
  555. {
  556. }
  557. /// <summary>
  558. /// Update design-time HTML when propery is changed
  559. /// </summary>
  560. private void OnPropertyChanged(object sender, PropertyValueChangedEventArgs e)
  561. {
  562. }
  563. /// <summary>
  564. /// Checks if the instance belongs to Chart type or contains the field of chart type.
  565. /// NOTE: Required for the Diagram product.
  566. /// </summary>
  567. /// <param name="instance">
  568. /// Instance to check.
  569. /// </param>
  570. /// <returns>
  571. /// Object of chart type.
  572. /// </returns>
  573. public static object GetChartReference(object instance)
  574. {
  575. // Check instance type.
  576. if(instance is Chart)
  577. {
  578. return instance;
  579. }
  580. // Read chart reference from the "chart" field.
  581. IChartElement element = instance as IChartElement;
  582. if (element != null)
  583. return element.Common.Chart;
  584. else
  585. throw (new InvalidOperationException(SR.ExceptionEditorContectInstantsIsNotChartObject));
  586. }
  587. protected override void DestroyInstance(object instance)
  588. {
  589. // don't destroy instance because remove is clicked.
  590. }
  591. #endregion
  592. }
  593. /// <summary>
  594. /// Designer editor for the data series collection.
  595. /// </summary>
  596. internal class SeriesCollectionEditor : ChartCollectionEditor
  597. {
  598. #region Editor methods
  599. /// <summary>
  600. /// Object constructor.
  601. /// </summary>
  602. public SeriesCollectionEditor() : base(typeof(SeriesCollection))
  603. {
  604. }
  605. internal static Series CreateNewSeries(Chart control, string suggestedChartArea)
  606. {
  607. int countSeries = control.Series.Count + 1;
  608. string seriesName = "Series" + countSeries.ToString(System.Globalization.CultureInfo.InvariantCulture);
  609. // Check if this name already in use
  610. bool seriesFound = true;
  611. while (seriesFound)
  612. {
  613. seriesFound = false;
  614. foreach (Series series in control.Series)
  615. {
  616. if (series.Name == seriesName)
  617. {
  618. seriesFound = true;
  619. }
  620. }
  621. if (seriesFound)
  622. {
  623. ++countSeries;
  624. seriesName = "Series" + countSeries.ToString(System.Globalization.CultureInfo.InvariantCulture);
  625. }
  626. }
  627. // Create new series
  628. Series newSeries = new Series(seriesName);
  629. // Check if default chart area name exists
  630. if (control.ChartAreas.Count > 0)
  631. {
  632. bool defaultFound = false;
  633. if (!string.IsNullOrEmpty(suggestedChartArea) &&
  634. control.ChartAreas.IndexOf(suggestedChartArea) != -1)
  635. {
  636. newSeries.ChartArea = suggestedChartArea;
  637. defaultFound = true;
  638. }
  639. else
  640. {
  641. foreach (ChartArea area in control.ChartAreas)
  642. {
  643. if (area.Name == newSeries.ChartArea)
  644. {
  645. defaultFound = true;
  646. break;
  647. }
  648. }
  649. }
  650. // If default chart area was not found - use name of the first area
  651. if (!defaultFound)
  652. {
  653. newSeries.ChartArea = control.ChartAreas[0].Name;
  654. }
  655. // Check if series area is circular
  656. if (control.ChartAreas[newSeries.ChartArea].chartAreaIsCurcular)
  657. {
  658. // Change default chart type
  659. newSeries.ChartTypeName = ChartTypeNames.Radar;
  660. // Check if it's a Polar chart type
  661. IChartType chartType = control.ChartAreas[newSeries.ChartArea].GetCircularChartType() as IChartType;
  662. if (chartType != null && String.Compare(chartType.Name, ChartTypeNames.Polar, StringComparison.OrdinalIgnoreCase) == 0)
  663. {
  664. newSeries.ChartTypeName = ChartTypeNames.Polar;
  665. }
  666. }
  667. }
  668. return newSeries;
  669. }
  670. /// <summary>
  671. /// Create series instance in the editor
  672. /// </summary>
  673. /// <param name="itemType">Item type.</param>
  674. /// <returns>Newly created item.</returns>
  675. protected override object CreateInstance(Type itemType)
  676. {
  677. if (Context != null && Context.Instance != null)
  678. {
  679. Chart control = (Chart)GetChartReference(Context.Instance);
  680. return SeriesCollectionEditor.CreateNewSeries(control, String.Empty);
  681. }
  682. return base.CreateInstance(itemType);
  683. }
  684. #endregion
  685. }
  686. }
  687. #endif