コード例 #1
0
        /// <summary>
        /// Create graph showing how accounts are related via Transfer transactions.
        /// </summary>
        /// <param name="myMoney">The money data to analyze</param>
        /// <param name="fileName">The file name for the DGML graph output</param>
        public void ExportDgmlAccountMap(MyMoney myMoney, string fileName)
        {
            SimpleGraph sg = new SimpleGraph();

            foreach (Transaction t in myMoney.Transactions)
            {
                SimpleGraphNode n = sg.AddOrGetNode(t.AccountName);
                n.Category = t.Account.Type.ToString();


                // Look for Transfer FROM transactions
                if (t.TransferTo != null && t.Amount < 0)
                {
                    // Create a Link that shows a IncomingAccount To This Account
                    SimpleGraphLink link = sg.GetOrAddLink(t.AccountName, t.TransferTo);

                    SimpleGraphProperty sgp = link.GetProperty("Label");

                    if (sgp == null)
                    {
                        sgp = link.AddProperty("Label", 0);
                    }

                    sgp.Value = Convert.ToDecimal(sgp.Value) + Math.Abs(t.Amount);
                }
            }

            //
            // Convert all Label that looks like numeric values into a "Currency" look
            //
            foreach (SimpleGraphLink l in sg.Links)
            {
                try
                {
                    SimpleGraphProperty sgp = l.GetProperty("Label");
                    sgp.Value = Convert.ToDecimal(sgp.Value).ToString("C2");
                }
                catch
                {
                }
            }

            sg.Save(fileName, styleForGraph_Accounts);
        }