Exemple #1
0
        // Constructor for bar graph.
        // To insert graph, call the constructor then use barGraph.Root to get the container to parent.
        public BarGraph(Compositor compositor, IntPtr hwnd, string title, string xAxisLabel,                  // required parameters
                        string yAxisLabel, float width, float height, double dpiX, double dpiY, float[] data, // required parameters
                        bool AnimationsOn = true, GraphBarStyle graphBarStyle = GraphBarStyle.Single,         // optional parameters
                        List <Windows.UI.Color> barColors = null)
        {
            this.compositor  = compositor;
            this.hwnd        = hwnd;
            this.graphWidth  = (float)(width * dpiX / 96.0);
            this.graphHeight = (float)(height * dpiY / 96.0);

            this.graphData = data;

            Title      = title;
            XAxisLabel = xAxisLabel;
            YAxisLabel = yAxisLabel;

            this.graphBarStyle = graphBarStyle;

            if (barColors != null)
            {
                graphBarColors = barColors;
            }
            else
            {
                graphBarColors = new List <Windows.UI.Color>()
                {
                    Colors.Blue
                };
            }

            // Configure options for text.
            var Factory2D = new SharpDX.Direct2D1.Factory();

            var properties = new HwndRenderTargetProperties();

            properties.Hwnd           = this.hwnd;
            properties.PixelSize      = new SharpDX.Size2((int)(width * dpiX / 96.0), (int)(width * dpiY / 96.0));
            properties.PresentOptions = PresentOptions.None;

            textRenderTarget             = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)), properties);
            textRenderTarget.DotsPerInch = new Size2F((float)dpiX, (float)dpiY);
            textRenderTarget.Resize(new Size2((int)(width * dpiX / 96.0), (int)(width * dpiY / 96.0)));

            // Generate graph structure.
            var graphRoot = GenerateGraphStructure();

            GraphRoot = graphRoot;

            BarRoot = this.compositor.CreateContainerVisual();
            GraphRoot.Children.InsertAtBottom(BarRoot);

            // If data has been provided, initialize bars and animations; otherwise, leave graph empty.
            if (graphData.Length > 0)
            {
                barValueMap = new Hashtable();
                var bars = CreateBars(graphData);
                AddBarsToTree(bars);
            }
        }
Exemple #2
0
        // Constructor for bar graph.
        // To insert graph, call the constructor then use barGraph.Root to get the container to parent.
        public BarGraph(Compositor compositor,
                        string title,
                        string xAxisLabel,
                        string yAxisLabel,
                        float width,
                        float height,
                        double dpiX,
                        double dpiY,
                        WindowRenderTarget renderTarget,
                        double[] data                = null,
                        bool AnimationsOn            = true,
                        GraphBarStyle graphBarStyle  = GraphBarStyle.Single,
                        Windows.UI.Color[] barColors = null)
        {
            _compositor  = compositor;
            _graphWidth  = (float)(width * dpiX / 96.0);
            _graphHeight = (float)(height * dpiY / 96.0);

            _graphData = data;

            _graphTitle = title;
            _xAxisLabel = xAxisLabel;
            _yAxisLabel = yAxisLabel;

            _graphBarStyle  = graphBarStyle;
            _graphBarColors = barColors ?? new Windows.UI.Color[] { Colors.Blue };

            _textRenderTarget    = renderTarget;
            _textSceneColorBrush = new SolidColorBrush(renderTarget, _black);

            // Generate graph structure.
            GraphRoot = GenerateGraphStructure();

            _barRoot = _compositor.CreateContainerVisual();
            GraphRoot.Children.InsertAtBottom(_barRoot);

            // Ambient light
            _ambientLight       = _compositor.CreateAmbientLight();
            _ambientLight.Color = Colors.White;
            _ambientLight.Targets.Add(_mainContainer);

            // Spot light
            var innerConeColor = Colors.White;
            var outerConeColor = Colors.AntiqueWhite;

            _barOutlineLight = _compositor.CreateSpotLight();
            _barOutlineLight.InnerConeColor          = innerConeColor;
            _barOutlineLight.OuterConeColor          = outerConeColor;
            _barOutlineLight.CoordinateSpace         = _mainContainer;
            _barOutlineLight.InnerConeAngleInDegrees = 45;
            _barOutlineLight.OuterConeAngleInDegrees = 80;
            _barOutlineLight.Offset = new SnVector3(0, 0, 80);

            // Point light
            _barLight                 = _compositor.CreatePointLight();
            _barLight.Color           = outerConeColor;
            _barLight.CoordinateSpace = _mainContainer;
            _barLight.Intensity       = 0.5f;
            _barLight.Offset          = new SnVector3(0, 0, 120);

            // If data has been provided, initialize bars and animations; otherwise, leave graph empty.
            if (_graphData != null && _graphData.Length > 0)
            {
                _bars = new Bar[_graphData.Length];
                var bars = CreateBars(_graphData);
                AddBarsToTree(bars);
            }
        }
Exemple #3
0
        /*
         * Constructor for bar graph.
         * For now only does single bars, no grouping
         * As of 12/6 to insert graph, call the constructor then use barGraph.Root to get the container to parent
         */
        public BarGraph(Compositor compositor, IntPtr hwnd, string title, string xAxisLabel, string yAxisLabel, float width, float height, float[] data, //required parameters
                        bool AnimationsOn = true, GraphOrientation orientation = GraphOrientation.Vertical, GraphBarStyle graphBarStyle = GraphBarStyle.Single,
                        List <Windows.UI.Color> barColors = null)                                                                                        //optional parameters
        {
            _compositor       = compositor;
            _hwnd             = hwnd;
            this._graphWidth  = width;
            this._graphHeight = height;
            this._graphData   = data;

            Title      = title;
            XAxisLabel = xAxisLabel;
            YAxisLabel = yAxisLabel;

            Orientation    = orientation;
            _graphBarStyle = graphBarStyle;

            if (barColors != null)
            {
                _graphBarColors = barColors;
            }
            else
            {
                _graphBarColors = new List <Windows.UI.Color>()
                {
                    Colors.Blue
                };
            }


            // Configure options for text
            var Factory2D = new SharpDX.Direct2D1.Factory();

            HwndRenderTargetProperties properties = new HwndRenderTargetProperties();

            properties.Hwnd           = _hwnd;
            properties.PixelSize      = new SharpDX.Size2((int)_graphWidth, (int)_graphHeight);
            properties.PresentOptions = PresentOptions.None;

            _titleRenderTarget = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)), properties);
            _yAxisRenderTarget = new WindowRenderTarget(Factory2D, new RenderTargetProperties(new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)), properties);


            //TODO legend
            //TODO trend line on top of bars
            //TODO surface or value on top of bars?
            //TODO meaningful orientation options
            //TODO option for data sets (more than one bar in a set, multiple sets per graph)

            // Generate graph structure
            var graphRoot = GenerateGraphStructure();

            GraphRoot = graphRoot;

            BarRoot = _compositor.CreateContainerVisual();
            GraphRoot.Children.InsertAtTop(BarRoot);

            //If data has been provided init bars and animations, else leave graph empty
            //TODO add ability to add data later on (move out of constructor)
            //TODO add ability to either create individual bars or barsets for the graph
            if (_graphData.Length > 0)
            {
                barValueMap = new Hashtable();
                var bars = CreateBars(_graphData);
                AddBarsToTree(bars);
            }
        }