Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code LNG204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

ChartControl.cs

Description du code

ChartControl.cs est un fichier du projet BrolDev.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/broldev/src/.

Projet BrolDev : Librairie de composants réutilisables pour les applications BrolDev en CSharp.

Code source ou contenu du fichier

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using be.gaudry.events;
  8. using be.gaudry.model;
  9. using be.gaudry.model.comparators;
  10. using be.gaudry.model.drawing.chart;
  11. using be.gaudry.view.utils;
  12.  
  13. namespace be.gaudry.view.controls
  14. {
  15. public partial class ChartControl : UserControl
  16. {
  17.  
  18. #region constructor and declarations
  19. private List<Color> colors;
  20. private int alpha, minPercent, topCount;
  21. private float inactivePosition, selectedPosition;
  22. private PieChartControl chartCtl;
  23. private bool useLegend, useBgColorForValues;
  24.  
  25. public ChartControl()
  26. {
  27. alpha = 100;
  28. minPercent = 2;
  29. inactivePosition = 0F;
  30. selectedPosition = 1F;
  31. topCount = 0;
  32. colors = new List<Color>();
  33. useLegend = true;
  34. InitializeComponent();
  35. this.SetStyle(ControlStyles.ResizeRedraw, false);
  36. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  37. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  38. /*this.SetStyle(ControlStyles.UserPaint, true);
  39.   this.SetStyle(ControlStyles.DoubleBuffer, true);
  40.   this.SetStyle(ControlStyles.ResizeRedraw, true);*/
  41.  
  42. }
  43. #endregion
  44.  
  45. #region properties
  46. [
  47. Category("Display"),
  48. Browsable(true),
  49. Description("Event called to format a double value to get string to display on value column")
  50. ]
  51. public event FormatStringFromDoubleEventHandler FormatValue;
  52. [
  53. Category("Display"),
  54. Browsable(true),
  55. Description("Event called to format a string to display on the pie chart parts")
  56. ]
  57. public event FormatStringEventHandler FormatString;
  58. /// <summary>
  59. /// Title of the group box
  60. /// </summary>
  61. [
  62. Category("Chart options"),
  63. Browsable(true),
  64. Description("Title displayed on the GroupBox")
  65. ]
  66. public String Title
  67. {
  68. get { return this.mainGB.Text; }
  69. set { this.mainGB.Text = value; }
  70. }
  71. /// <summary>
  72. /// Minimum percentage required to display text on pie chart
  73. /// </summary>
  74. [
  75. Category("Chart options"),
  76. Browsable(true),
  77. Description("Minimum percentage required to display text on pie chart")
  78. ]
  79. public int MinPercentToDisplay
  80. {
  81. get { return this.minPercent; }
  82. set { this.minPercent = value; }
  83. }
  84. /// <summary>
  85. /// Count of most significative items to display on the pie chart
  86. /// </summary>
  87. [
  88. Category("Chart options"),
  89. Browsable(true),
  90. Description("Count of most significative items to display on the pie chart")
  91. ]
  92. public int TopCountToDisplay
  93. {
  94. get { return this.topCount; }
  95. set { this.topCount = value; }
  96. }
  97. /// <summary>
  98. /// Alpha value of the colors
  99. /// </summary>
  100. /*public int AlphaColor
  101.   {
  102.   get { return this.alpha; }
  103.   set { this.alpha = (value > 255) ? 255 : (value < 0) ? 0 : value; }
  104.   }*/
  105. /// <summary>
  106. /// Display a legend for each value in the pie chart on a scrollable legend panel
  107. /// </summary>
  108. [
  109. Category("Chart options"),
  110. Browsable(true),
  111. Description("Display or hide the scrollable legend panel")
  112. ]
  113. public bool DisplayLegend
  114. {
  115. get { return this.useLegend; }
  116. set { this.useLegend = value; }
  117. }
  118. /// <summary>
  119. /// Display or hide the toolStrip containing the options buttons
  120. /// </summary>
  121. [
  122. Category("Chart options"),
  123. Browsable(true),
  124. Description("Display or hide the toolStrip containing the options buttons"),
  125. DefaultValue(true)
  126. ]
  127. public bool DisplayToolStrip
  128. {
  129. get { return this.toolStrip.Visible; }
  130. set { this.toolStrip.Visible = value; }
  131. }
  132. /// <summary>
  133. /// Display background color for values
  134. /// </summary>
  135. [
  136. Category("Chart options"),
  137. Browsable(true),
  138. Description("Display background color for values")
  139. ]
  140. public bool DisplayBgColorForValues
  141. {
  142. get { return this.useBgColorForValues; }
  143. set { this.useBgColorForValues = value; }
  144. }
  145. #endregion
  146.  
  147. #region events
  148. private void ChartControl_Load(object sender, EventArgs e)
  149. {
  150. //create a chart object and fill it with default values
  151. initializeChart();
  152. }
  153. private void chartVSB_Scroll(object sender, ScrollEventArgs e)
  154. {
  155. try
  156. {
  157. chartCtl.SliceRelativeHeight = (float)chartVSB.Value / 100 * -1;
  158.  
  159. }
  160. catch (Exception) { }
  161. }
  162.  
  163. private void chartHSB_Scroll(object sender, ScrollEventArgs e)
  164. {
  165. try
  166. {
  167. chartCtl.InitialAngle = (float)chartHSB.Value * -1;
  168. }
  169. catch (Exception) { }
  170. }
  171.  
  172. private void legendDGV_SelectionChanged(object sender, EventArgs e)
  173. {
  174. float[] displacements = new float[legendDGV.RowCount];
  175. foreach (DataGridViewRow row in legendDGV.Rows)
  176. {
  177. displacements[(int)row.Cells["id"].Value] = (row.Selected) ? selectedPosition : inactivePosition;
  178. }
  179. chartCtl.SliceRelativeDisplacements = displacements;
  180. }
  181.  
  182.  
  183. #endregion
  184.  
  185. #region private methods
  186. /// <summary>
  187. /// create a chart object and fill it with default values
  188. /// </summary>
  189. private void initializeChart()
  190. {
  191. if (chartCtl == null)
  192. {
  193. this.SuspendLayout();
  194.  
  195. chartCtl = new PieChartControl();
  196. //chartCtl.DisplaceOnMouseOn = true;
  197. this.chartPanel.Controls.Add(chartCtl);
  198. //chartCtl.Name = "chartCtl";
  199. chartCtl.Dock = DockStyle.Fill;
  200.  
  201. chartCtl.ToolTips = null;
  202. chartCtl.LeftMargin = 10F;
  203. chartCtl.RightMargin = 10F;
  204. chartCtl.TopMargin = 10F;
  205. chartCtl.BottomMargin = 10F;
  206. chartCtl.FitChart = true;
  207. chartCtl.SliceRelativeHeight = 0.10F;
  208. chartCtl.InitialAngle = 0F;
  209. chartCtl.EdgeLineWidth = 1F;
  210. chartCtl.EdgeColorType = EdgeColorType.DarkerDarkerThanSurface;
  211.  
  212. this.ResumeLayout(false);
  213. }
  214. }
  215. private Color getColor(int i)
  216. {
  217. if (colors.Count < 1)
  218. {
  219. colors.Add(Color.FromArgb(alpha, 175,175,255));
  220. colors.Add(Color.FromArgb(alpha, Color.Magenta));
  221. colors.Add(Color.FromArgb(alpha, 255,75,75));
  222. colors.Add(Color.FromArgb(alpha, Color.Orange));
  223. colors.Add(Color.FromArgb(alpha, Color.Yellow));
  224. colors.Add(Color.FromArgb(alpha, 200, 255, 75));
  225. colors.Add(Color.FromArgb(alpha, 40,200,10));
  226. }
  227. //if we are out of bounds,
  228. // the first color after the last of the array is the first (circular)
  229. if(i >= colors.Count) i = i % colors.Count;
  230. return colors[i];
  231. }
  232. #endregion
  233.  
  234. #region public methods
  235. /// <summary>
  236. /// Open a custom print dialog to print the results
  237. /// </summary>
  238. public void print()
  239. {
  240. //be.gaudry.view.utils.PrintDGV.Print_DataGridView(legendDGV, mainGB.Text);
  241. DgvFactory.print(legendDGV, mainGB.Text, this.ParentForm);
  242. }
  243.  
  244. /// <summary>
  245. /// Set colors used for the parts of chart
  246. /// </summary>
  247. /// <param name="colors">List of colors</param>
  248. /// <param name="replaceExisting">(bool) false to add colors at existings, true to replace existing colors by the new list</param>
  249. public void setColors(List<Color> colors, bool replaceExisting)
  250. {
  251. if (replaceExisting)
  252. this.colors.Clear();
  253. foreach (Color c in colors)
  254. {
  255. this.colors.Add(Color.FromArgb(alpha, c));
  256. }
  257. }
  258. public void setColumnTitle(int columnIndex, string columnTitle)
  259. {
  260. if (columnIndex >= 0 && columnIndex < legendDGV.ColumnCount)
  261. {
  262. legendDGV.Columns[columnIndex].HeaderCell.Value = columnTitle;
  263. }
  264. }
  265. public void setBrolChart(Stat stat, String title, String columnTitle)
  266. {
  267. setBrolChart(stat, title);
  268. legendDGV.Columns[1].HeaderCell.Value = columnTitle;
  269. }
  270. public void setBrolChart(Stat stat, String title)
  271. {
  272. setBrolChart(stat);
  273. Title = title;
  274. }
  275. public void setBrolChart(Stat stat)
  276. {
  277. mainGB.Visible = false;
  278. if (stat.Total <= 0)
  279. {
  280. return;
  281. }
  282. initializeChart();
  283. Color color;
  284. legendDGV.Rows.Clear();
  285.  
  286. #region Top X
  287. //If we don't want displaying all results
  288. if (topCount > 0)
  289. {
  290. List<KeyValuePair<string, double>> pairs = new List<KeyValuePair<string, double>>();
  291. double others = 0;
  292. int topCounter = 0;
  293. IComparer<KeyValuePair<string, double>> comparer = new KeyValueByDoubleComparer();
  294. foreach (KeyValuePair<string, double> kvp in stat.Dictionary)
  295. {
  296. if (topCounter < topCount)
  297. {
  298. pairs.Add(kvp);
  299. topCounter++;
  300. }
  301. //We must replace the smallest value by the current
  302. else
  303. {
  304. pairs.Sort(comparer);
  305. if (pairs[0].Value > kvp.Value)
  306. {
  307. others += kvp.Value;
  308. }
  309. else
  310. {
  311. others += pairs[0].Value;
  312. pairs[0] = kvp;
  313. }
  314. }
  315. }
  316. int nbToDisplay = (topCounter >= topCount) ? pairs.Count + 1 : topCounter + 1;
  317. chartCtl.Values = new double[nbToDisplay];
  318. chartCtl.Texts = new string[nbToDisplay];
  319. chartCtl.ToolTips = new string[nbToDisplay];
  320.  
  321.  
  322. if (topCounter >= topCount)
  323. {
  324. chartCtl.Values[topCounter] = others;
  325. chartCtl.Texts[topCounter] = "Autres";
  326. chartCtl.ToolTips[topCounter++] = "Somme des éléments restants";
  327. }
  328. int i = 0;
  329. foreach (KeyValuePair<string, double> kvp in pairs)
  330. {
  331. chartCtl.Values[i] = kvp.Value;
  332. chartCtl.Texts[i] = kvp.Key;
  333. chartCtl.ToolTips[i++] = kvp.Key;
  334. }
  335. //if (topCounter >= topCount)
  336. //{
  337. chartCtl.Values[i] = others;
  338. chartCtl.Texts[i] = "Autres";
  339. chartCtl.ToolTips[i] = "Somme des éléments restants";
  340. //}
  341. }
  342. #endregion
  343. else
  344. {
  345. chartCtl.Values = stat.Values;
  346. chartCtl.Texts = stat.Texts;
  347. chartCtl.ToolTips = stat.Labels;
  348. }
  349. Color[] colors = new Color[chartCtl.Values.Length];
  350. float[] displacements = new float[chartCtl.Values.Length];
  351. for (int i = 0; i < chartCtl.Values.Length; i++)
  352. {
  353. color = getColor(i);
  354. colors[i] = color;
  355. displacements[i] = inactivePosition;
  356. double tempPercent = (chartCtl.Values[i] / stat.Total) * 100;
  357. if (FormatValue != null)
  358. {
  359. legendDGV.Rows.Add(i, chartCtl.Texts[i], tempPercent, FormatValue(chartCtl.Values[i]));
  360. }
  361. else
  362. {
  363. legendDGV.Rows.Add(i, chartCtl.Texts[i], tempPercent, chartCtl.Values[i]);
  364. }
  365.  
  366. legendDGV.Rows[legendDGV.RowCount - 1].Cells[1].Style.BackColor = Color.FromArgb(255, color);
  367. legendDGV.Rows[legendDGV.RowCount - 1].DefaultCellStyle.SelectionBackColor = Color.FromArgb(color.R, color.G, color.B);
  368. legendDGV.Rows[legendDGV.RowCount - 1].DefaultCellStyle.SelectionForeColor = Color.Black;
  369.  
  370. if (tempPercent < minPercent)
  371. {
  372. chartCtl.Texts[i] = "";
  373. }
  374. else if(FormatString!=null)
  375. {
  376. chartCtl.Texts[i] = FormatString(chartCtl.Texts[i]);
  377. }
  378. }
  379. chartCtl.Colors = colors;
  380. chartCtl.SliceRelativeDisplacements = displacements;
  381. legendDGV.Sort(percentCol, ListSortDirection.Descending);
  382. legendDGV.CurrentCell = null;
  383. mainGB.Visible = true;
  384. }
  385. #endregion
  386.  
  387. #region DGV actions
  388. private void printTSB_Click(object sender, EventArgs e)
  389. {
  390. print();
  391. }
  392.  
  393. private void saveDGVTsB_Click(object sender, EventArgs e)
  394. {
  395. DgvFactory.save(legendDGV, mainGB.Text, this.ParentForm);
  396. }
  397. #endregion
  398.  
  399. #region DGV sort
  400. private void sortAscTitleTsMi_Click(object sender, EventArgs e)
  401. {
  402. legendDGV.Sort(valCol, ListSortDirection.Ascending);
  403. }
  404.  
  405. private void sortAscNbTsMi_Click(object sender, EventArgs e)
  406. {
  407. legendDGV.Sort(nbCol, ListSortDirection.Ascending);
  408. }
  409.  
  410. private void sortAscPercentTsMi_Click(object sender, EventArgs e)
  411. {
  412. legendDGV.Sort(percentCol, ListSortDirection.Ascending);
  413. }
  414.  
  415. private void sortDescTitleTsMi_Click(object sender, EventArgs e)
  416. {
  417. legendDGV.Sort(valCol, ListSortDirection.Descending);
  418. }
  419.  
  420. private void sortDescNbTsMi_Click(object sender, EventArgs e)
  421. {
  422. legendDGV.Sort(nbCol, ListSortDirection.Descending);
  423. }
  424.  
  425. private void sortDescPercentTsMi_Click(object sender, EventArgs e)
  426. {
  427. legendDGV.Sort(percentCol, ListSortDirection.Descending);
  428. }
  429. #endregion
  430. }
  431. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/controls/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1714370264 29/04/2024 07:57:44
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/controls/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csToolBarHomeControl.Designer.cs7.41 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csWizardUserControl.Designer.cs6.79 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csHeaderPanel.Designer.cs1.19 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csDGVLayoutOptionsControl.cs7.55 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csXPGroupBox.cs15.83 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csWizardXpUserControl.Designer.cs7.85 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csToolBarHomeControl.cs2.32 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csVersionControl.Designer.cs4.09 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csWizardUserControl.cs2.01 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .resx|.resxWizardXpUserControl.resx5.68 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csBrolBoxUserControl.Designer.cs5.92 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxChartControl.resx6.58 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csHeaderPanel.cs35.93 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csIWizardUC.cs2.35 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxAboutUserControl.resx5.68 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csTextBoxDragDrop.cs8.59 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csSystemInfoControl.cs5.46 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxXPGroupBox.resx17.7 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csHeaderPanelNativeMethods.cs21.09 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csToolBarManagerControl.cs6.99 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csTextBoxDragDrop.Designer.cs1.11 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxSystemInfoControl.resx6.22 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csSystemInfoControl.Designer.cs4.79 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxHeaderPanel.resx5.85 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csScrollablePictureBoxUserControl.cs5.55 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csBrolBoxUserControl.cs4.7 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxDGVLayoutOptionsControl.resx5.68 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxWizardUserControl.resx5.68 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csUpdateControl.cs7.55 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csIconList.cs2.68 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csVersionControl.cs463 octets31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxBrolBoxUserControl.resx5.68 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csAboutUserControl.cs6.75 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxToolBarManagerControl.resx5.88 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csToolBarManagerControl.Designer.cs10.66 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csIToolBarControl.cs1.07 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csWizardXpUserControl.cs8.11 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csImageCombo.cs15.49 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csAboutUserControl.Designer.cs12.31 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .resx|.resxScrollablePictureBoxUserControl.resx5.68 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csScrollablePictureBoxUserControl.Designer.cs5.64 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxVersionControl.resx5.68 Ko31/10/2018 18:33:13-refusé-
Afficher le fichier .cs|.csChartControl.Designer.cs18.45 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csUpdateControl.Designer.cs3.92 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .resx|.resxUpdateControl.resx5.68 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csChartControl.cs15.11 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csDGVLayoutOptionsControl.Designer.cs17.39 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .cs|.csToolStrip.cs1.06 Ko31/10/2018 18:33:12-refusé-
Afficher le fichier .cs|.csIconList.Designer.cs1.1 Ko31/10/2018 18:33:11-refusé-
Afficher le fichier .resx|.resxToolBarHomeControl.resx48.51 Ko31/10/2018 18:33:12-refusé-

Utilisation de l'explorateur de code

  • Navigation :
    • Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
    • Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
    • La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
    • Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
  • Affichage :
    • Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
  • Actions :
    • Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 16/10/2009, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/cs-broldev-source-rf-view/controls/ChartControl.cs.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.