using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infragistics.UltraChart.Resources;
using System.Diagnostics;
using Infragistics.UltraChart.Core;
using System.Windows.Forms;
using System.Drawing;
using Infragistics.UltraChart.Core.Primitives;
using System.Reflection;


namespace _140195
{
    class MyLabelRenderer : IRenderLabel
    {
        public static List<object> values = new List<object>();
        private Infragistics.Win.UltraWinChart.UltraChart ultraChart1;

        public MyLabelRenderer(Infragistics.Win.UltraWinChart.UltraChart ultraChart1)
        {
            // TODO: Complete member initialization
            this.ultraChart1 = ultraChart1;
        }

        private void PopulateValues()
        {
            var Core = ultraChart1.GetType().GetProperty("ChartCore", BindingFlags.CreateInstance | BindingFlags.GetField | BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);
            var CoreValue = Core.GetValue(ultraChart1, null);
            SceneGraph scene = (SceneGraph)CoreValue.GetType().GetProperty("SceneGraph").GetValue(CoreValue, null);
            Point mouseLocation = Cursor.Position;
            mouseLocation = ultraChart1.PointToClient(mouseLocation);
            List<Primitive> elipses = scene.Cast<Primitive>().Where(p => p is Ellipse && ((Ellipse)p).HitTest(mouseLocation)).ToList<Primitive>();
            MyLabelRenderer.values.Clear();
            foreach(var p in elipses)
                 MyLabelRenderer.values.Add (p.Value);
        }

        public string ToString(System.Collections.Hashtable context)
        {
            PopulateValues();
            if (values.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (object o in values)
                {
                    object[] points = (object[])o;
                    sb.Append(string.Format("ColumnX:{0}, ColumnY:{1}, Radous:{2}{3}", points[0], points[1], points[2], Environment.NewLine));
                }
                return sb.ToString();
            }
            else
            {
                return null;
            }

        }
    }
}
