LegendDesigner.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 support classes for Legend.
  6. //
  7. #if DESIGNER
  8. using System.ComponentModel;
  9. using FastReport.DataVisualization.Charting;
  10. namespace FastReport.Design.DataVisualization.Charting
  11. {
  12. /// <summary>
  13. /// Designer editor for the custom legend items collection.
  14. /// </summary>
  15. internal class LegendItemCollectionEditor : ChartCollectionEditor
  16. {
  17. #region Editor methods
  18. /// <summary>
  19. /// Object constructor.
  20. /// </summary>
  21. public LegendItemCollectionEditor() : base(typeof(LegendItemsCollection))
  22. {
  23. }
  24. /// <summary>
  25. /// Edit object's value.
  26. /// </summary>
  27. /// <param name="context">Descriptor context.</param>
  28. /// <param name="provider">Service provider.</param>
  29. /// <param name="value">Calue.</param>
  30. /// <returns>Object.</returns>
  31. public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
  32. {
  33. return base.EditValue(context, provider, value);
  34. }
  35. #endregion
  36. }
  37. /// <summary>
  38. /// Designer editor for the legend collection.
  39. /// </summary>
  40. internal class LegendCollectionEditor : ChartCollectionEditor
  41. {
  42. #region Editor methods
  43. /// <summary>
  44. /// Object constructor.
  45. /// </summary>
  46. public LegendCollectionEditor() : base(typeof(LegendCollection))
  47. {
  48. }
  49. /// <summary>
  50. /// Create series instance in the editor
  51. /// </summary>
  52. /// <param name="itemType">Item type.</param>
  53. /// <returns>Newly created item.</returns>
  54. protected override object CreateInstance(Type itemType)
  55. {
  56. if (Context != null && Context.Instance != null)
  57. {
  58. Chart control = (Chart)Context.Instance;
  59. // Create legend with unique name
  60. int countLegend = control.Legends.Count + 1;
  61. string legendName = "Legend" + countLegend.ToString(System.Globalization.CultureInfo.InvariantCulture);
  62. // Check if this name already in use
  63. bool legendFound = true;
  64. while(legendFound)
  65. {
  66. legendFound = false;
  67. foreach(Legend legend in control.Legends)
  68. {
  69. if(legend.Name == legendName)
  70. {
  71. legendFound = true;
  72. }
  73. }
  74. if(legendFound)
  75. {
  76. ++countLegend;
  77. legendName = "Legend" + countLegend.ToString(System.Globalization.CultureInfo.InvariantCulture);
  78. }
  79. }
  80. // Create new legend
  81. Legend newLegend = new Legend(legendName);
  82. return newLegend;
  83. }
  84. return base.CreateInstance(itemType);
  85. }
  86. #endregion
  87. }
  88. /// <summary>
  89. /// Designer editor for the legend column collection.
  90. /// </summary>
  91. internal class LegendCellColumnCollectionEditor : ChartCollectionEditor
  92. {
  93. #region Editor methods
  94. /// <summary>
  95. /// Object constructor.
  96. /// </summary>
  97. public LegendCellColumnCollectionEditor() : base(typeof(LegendCellColumnCollection))
  98. {
  99. }
  100. /// <summary>
  101. /// Create series instance in the editor
  102. /// </summary>
  103. /// <param name="itemType">Item type.</param>
  104. /// <returns>Newly created item.</returns>
  105. protected override object CreateInstance(Type itemType)
  106. {
  107. if (Context != null && Context.Instance != null)
  108. {
  109. Legend legend = Context.Instance as Legend;
  110. if(legend != null)
  111. {
  112. int itemCount = legend.CellColumns.Count + 1;
  113. string itemName = "Column" + itemCount.ToString(System.Globalization.CultureInfo.InvariantCulture);
  114. // Check if this name already in use
  115. bool itemFound = true;
  116. while (itemFound)
  117. {
  118. itemFound = false;
  119. foreach (LegendCellColumn column in legend.CellColumns)
  120. {
  121. if (column.Name == itemName)
  122. {
  123. itemFound = true;
  124. }
  125. }
  126. if (itemFound)
  127. {
  128. ++itemCount;
  129. itemName = "Column" + itemCount.ToString(System.Globalization.CultureInfo.InvariantCulture);
  130. }
  131. }
  132. // Create new legend column
  133. LegendCellColumn legendColumn = new LegendCellColumn();
  134. legendColumn.Name = itemName;
  135. return legendColumn;
  136. }
  137. }
  138. return base.CreateInstance(itemType);
  139. }
  140. #endregion
  141. }
  142. /// <summary>
  143. /// Designer editor for the legend cell collection.
  144. /// </summary>
  145. internal class LegendCellCollectionEditor : ChartCollectionEditor
  146. {
  147. #region Editor methods
  148. /// <summary>
  149. /// Object constructor.
  150. /// </summary>
  151. public LegendCellCollectionEditor() : base(typeof(LegendCellCollection))
  152. {
  153. }
  154. /// <summary>
  155. /// Create series instance in the editor
  156. /// </summary>
  157. /// <param name="itemType">Item type.</param>
  158. /// <returns>Newly created item.</returns>
  159. protected override object CreateInstance(Type itemType)
  160. {
  161. if (Context != null && Context.Instance != null)
  162. {
  163. LegendItem legendItem = Context.Instance as LegendItem;
  164. if(legendItem != null)
  165. {
  166. int itemCount = legendItem.Cells.Count + 1;
  167. string itemName = "Cell" + itemCount.ToString(System.Globalization.CultureInfo.InvariantCulture);
  168. // Check if this name already in use
  169. bool itemFound = true;
  170. while (itemFound)
  171. {
  172. itemFound = false;
  173. foreach (LegendCell cell in legendItem.Cells)
  174. {
  175. if (cell.Name == itemName)
  176. {
  177. itemFound = true;
  178. }
  179. }
  180. if (itemFound)
  181. {
  182. ++itemCount;
  183. itemName = "Cell" + itemCount.ToString(System.Globalization.CultureInfo.InvariantCulture);
  184. }
  185. }
  186. // Create new legend cell
  187. LegendCell legendCell = new LegendCell();
  188. legendCell.Name = itemName;
  189. return legendCell;
  190. }
  191. }
  192. return base.CreateInstance(itemType);
  193. }
  194. #endregion
  195. }
  196. }
  197. #endif