//折线图定位
        private void OnCategoryChartMouseMove(object sender, MouseEventArgs e)
        {
            var series = this.CategoryChart.Series.FirstOrDefault();

            if (series == null)
            {
                return;
            }

            var position = e.GetPosition(series);

            // calculate crosshair coordinates on CategoryDateTimeXAxis
            if (((XamDataChart)series.SeriesViewer).Axes.OfType <CategoryDateTimeXAxis>().Any())
            {
                var xAxis = ((XamDataChart)series.SeriesViewer).Axes.OfType <CategoryDateTimeXAxis>().First();
                var yAxis = ((XamDataChart)series.SeriesViewer).Axes.OfType <NumericYAxis>().First();

                var viewport = new Rect(0, 0, xAxis.ActualWidth, yAxis.ActualHeight);
                var window   = series.SeriesViewer.WindowRect;

                bool         isInverted = xAxis.IsInverted;
                ScalerParams param      = new ScalerParams(window, viewport, isInverted);
                var          unscaledX  = xAxis.GetUnscaledValue(position.X, param);

                isInverted = yAxis.IsInverted;
                param      = new ScalerParams(window, viewport, isInverted);
                var unscaledY = yAxis.GetUnscaledValue(position.Y, param);

                DateTime xDate = new DateTime((long)unscaledX);


                this.CategoryXCoordinateTextBlock.Text = String.Format("{0:MM-dd}", xDate);
                this.CategoryYCoordinateTextBlock.Text = String.Format("{0:0.00}", unscaledY);

                textCornY1.Text   = String.Format("{0:0.00}", unscaledY);
                textCornDate.Text = String.Format("{0:MM-dd}", xDate);
            }
        }
        private void chaLine_MouseEnter(object sender, MouseEventArgs e)
        {
            ValueOverlay chaLine = sender as ValueOverlay;
            var          series  = dataChart.Series.FirstOrDefault();

            if (series == null)
            {
                return;
            }

            var position = e.GetPosition(series);

            if (((XamDataChart)series.SeriesViewer).Axes.OfType <NumericXAxis>().Any())
            {
                var xAxis = ((XamDataChart)series.SeriesViewer).Axes.OfType <NumericXAxis>().First();
                var yAxis = ((XamDataChart)series.SeriesViewer).Axes.OfType <NumericYAxis>().First();

                var viewport = new Rect(0, 0, xAxis.ActualWidth, yAxis.ActualHeight);
                var window   = series.SeriesViewer.WindowRect;

                bool         isInverted = xAxis.IsInverted;
                ScalerParams param      = new ScalerParams(window, viewport, isInverted);
                var          unscaledX  = xAxis.GetUnscaledValue(position.X, param);

                foreach (YuMiBaoZiModel data in predictModels)
                {
                    Int16 x = Convert.ToInt16(data.xData);
                    if (Convert.ToInt16(unscaledX) == x)
                    {
                        block.Text = data.predictChaValue.ToString();
                    }
                }


                chaLine.Value = unscaledX;
            }
        }
        private void CategoryChart_PointerMoved(object sender, PointerRoutedEventArgs e,
            Infragistics.Controls.Charts.XamDataChart targetChart)
        {
            var series = targetChart.Series.FirstOrDefault();
            if (series == null) return;

            var position = e.GetCurrentPoint(series).Position;

            // calculate crosshair coordinates on CategoryDateTimeXAxis 
            if (((XamDataChart)series.SeriesViewer).Axes.OfType<CategoryXAxis>().Any())
            {
                var xAxis = ((XamDataChart)series.SeriesViewer).Axes.OfType<CategoryXAxis>().First();
                var yAxis = ((XamDataChart)series.SeriesViewer).Axes.OfType<NumericYAxis>().First();

                var viewport = new Rect(0, 0, xAxis.ActualWidth, yAxis.ActualHeight);
                var window = series.SeriesViewer.WindowRect;

                bool isInverted = xAxis.IsInverted;
                ScalerParams param = new ScalerParams(window, viewport, isInverted);
                var unscaledX = xAxis.GetUnscaledValue(position.X, param);

                isInverted = yAxis.IsInverted;
                param = new ScalerParams(window, viewport, isInverted);
                var unscaledY = yAxis.GetUnscaledValue(position.Y, param);

                //DateTime xDate = new DateTime((long)unscaledX);

                //var x = unscaledX.ToString();//String.Format("{0:T}", xDate);
                //var y = unscaledY.ToString();// String.Format("{0:0.00}", unscaledY);
                this.SetCoordinate(unscaledX, unscaledY, targetChart.DataContext as IEnumerable<SimpleDataPoint>);
            }
        }
Exemple #4
0
        /// <summary>
        /// Zooms XamGeographicMap to a given geographic location based on source map
        /// </summary>
        /// <param name="geoMap"></param>
        /// <param name="sourceMap"></param>
        /// <param name="mouseLocation">in Cartesian coordinates</param>
        /// <param name="mapZoomMagnification">magnification of source map</param>
        public static void ZoomMapToLocation(this XamGeographicMap geoMap, XamGeographicMap sourceMap, Point mouseLocation, double mapZoomMagnification = 4.0)
        {
            if (mapZoomMagnification < 0.001)
            {
                mapZoomMagnification = 0.001;
            }
            //if (mapZoomMagnification < 1) mapZoomMagnification = 1;
            //var offset = (sourceMap.GetMapZoomScale() * (geoMap.GetMapViewportScale() / 2)) / mapZoomMagnification;
            //var pixcelNorthWest = new Point(mouseLocation.X - offset, mouseLocation.Y - offset);
            //var pixcelSouthEast = new Point(mouseLocation.X + offset, mouseLocation.Y + offset);

            var offsetX = (sourceMap.ActualWindowScale * (geoMap.ViewportRect.Width / 2)) / mapZoomMagnification;
            var offsetY = (sourceMap.ActualWindowScale * (geoMap.ViewportRect.Height / 2)) / mapZoomMagnification;

            var pixcelNorthWest = new Point(mouseLocation.X - offsetX, mouseLocation.Y - offsetY);
            var pixcelSouthEast = new Point(mouseLocation.X + offsetX, mouseLocation.Y + offsetY);

            var w = pixcelSouthEast.X - pixcelNorthWest.X;
            var h = pixcelSouthEast.Y - pixcelNorthWest.Y;

            var pixRect = new Rect(pixcelNorthWest.X, pixcelNorthWest.Y, w, h);

            // init appropriate axis scaler parameters
            var xaxis   = sourceMap.XAxis;
            var yaxis   = sourceMap.YAxis;
            var xParams = new ScalerParams(sourceMap.ActualWindowRect, sourceMap.ViewportRect, xaxis.IsInverted);

            xParams.EffectiveViewportRect = sourceMap.EffectiveViewport;
            var yParams = new ScalerParams(sourceMap.ActualWindowRect, sourceMap.ViewportRect, yaxis.IsInverted);

            yParams.EffectiveViewportRect = sourceMap.EffectiveViewport;

            var gL = xaxis.GetUnscaledValue(pixRect.Left, xParams);
            var gT = yaxis.GetUnscaledValue(pixRect.Bottom, yParams);
            var gR = xaxis.GetUnscaledValue(pixRect.Right, xParams);
            var gB = yaxis.GetUnscaledValue(pixRect.Top, yParams);

            var gH = gB - gT;
            var gW = gR - gL;

            //DebugManager.LogWarning("gT " + gT + " gB " + gB + " gL " + gL + " gR " + gR + " | gH " + gH + " gW " + gW);


            //if (gT <= GeoGlobal.MapSphericalMercator.LatitudeMin) return;
            //if (gB >= GeoGlobal.MapSphericalMercator.LatitudeMax) return;

            //if (gR >= GeoGlobal.MapSphericalMercator.LongitudeMax) return;
            //if (gL <= GeoGlobal.MapSphericalMercator.LongitudeMin) return;



            if (gT <= GeoGlobal.WorldsMercator.LatitudeMin && gR >= GeoGlobal.WorldsMercator.LongitudeMax)
            {
                return;
            }
            if (gT <= GeoGlobal.WorldsMercator.LatitudeMin && gL <= GeoGlobal.WorldsMercator.LongitudeMin)
            {
                return;
            }

            if (gB >= GeoGlobal.WorldsMercator.LatitudeMax && gR >= GeoGlobal.WorldsMercator.LongitudeMax)
            {
                return;
            }
            if (gB >= GeoGlobal.WorldsMercator.LatitudeMax && gL <= GeoGlobal.WorldsMercator.LongitudeMin)
            {
                return;
            }

            if (gT < GeoGlobal.WorldsMercator.LatitudeMin)
            {
                gT = GeoGlobal.WorldsMercator.LatitudeMin;
            }
            if (gB > GeoGlobal.WorldsMercator.LatitudeMax)
            {
                gB = GeoGlobal.WorldsMercator.LatitudeMax;
            }

            if (gR > GeoGlobal.WorldsMercator.LongitudeMax)
            {
                gR = GeoGlobal.WorldsMercator.LongitudeMax;
            }
            if (gL < GeoGlobal.WorldsMercator.LongitudeMin)
            {
                gL = GeoGlobal.WorldsMercator.LongitudeMin;
            }

            gH = System.Math.Abs(gB - gT);
            gW = System.Math.Abs(gR - gL);

            //if (gT + gH > GeoGlobal.MapSphericalMercator.LatitudeMax)
            //{
            //    gB = GeoGlobal.MapSphericalMercator.LatitudeMax;
            //    gT = gB - gH;
            //    //gT = gT - (gH);

            //}
            //if (gT < GeoGlobal.MapSphericalMercator.LatitudeMin)
            //{
            //    gT = GeoGlobal.MapSphericalMercator.LatitudeMin; // +(gH);
            //    gB = gT + gH; // +(gH);
            //    //return;
            //}


            var geoRect = new Rect(gL, gT, gW, gH);
            var winRect = geoMap.GetZoomFromGeographic(geoRect);

            //DebugManager.LogWarning("geoRect    " + geoRect.ToString());
            //DebugManager.LogWarning("winRect    " + winRect.ToString());
            //DebugManager.LogWarning("     "  );

            geoMap.WindowRect = winRect;
        }
Exemple #5
0
        private void OnCategoryChartMouseMove(object sender, MouseEventArgs e)
        {
            DataSource data    = new DataSource();
            var        series1 = this.CategoryChart.Series.FirstOrDefault();

            if (series1 == null)
            {
                return;
            }

            var position = e.GetPosition(series1);

            // calculate crosshair coordinates on CategoryDateTimeXAxis
            if (((XamDataChart)series1.SeriesViewer).Axes.OfType <CategoryDateTimeXAxis>().Any())
            {
                var xAxis = ((XamDataChart)series1.SeriesViewer).Axes.OfType <CategoryDateTimeXAxis>().First();
                var yAxis = ((XamDataChart)series1.SeriesViewer).Axes.OfType <NumericYAxis>().First();

                var viewport = new Rect(0, 0, xAxis.ActualWidth, yAxis.ActualHeight);
                var window   = series1.SeriesViewer.WindowRect;

                bool         isInverted = xAxis.IsInverted;
                ScalerParams param      = new ScalerParams(window, viewport, isInverted);
                var          unscaledX  = xAxis.GetUnscaledValue(position.X, param);

                isInverted = yAxis.IsInverted;
                param      = new ScalerParams(window, viewport, isInverted);
                var unscaledY = yAxis.GetUnscaledValue(position.Y, param);

                if ((long)unscaledX > DateTime.MaxValue.Ticks || (long)unscaledX < DateTime.MinValue.Ticks)
                {
                    return;
                }

                DateTime xDate = new DateTime((long)unscaledX);

                this.CategoryXCoordinateTextBlock.Text = String.Format("{0:MM-dd}", xDate);
                this.CategoryYCoordinateTextBlock.Text = String.Format("{0:0.00}", unscaledY);

                string dateStr = String.Format("{0:MM-dd}", xDate);
                if (colCorn != null && colCorn.Visibility == Visibility.Visible)
                {
                    foreach (DataValue data1 in predictY1Data)
                    {
                        string dateStr1 = String.Format("{0:MM-dd}", data1.date);
                        if (dateStr1.Equals(dateStr))
                        {
                            textDate.Text = dateStr;
                            textCha.Text  = String.Format("{0:0.00}", data1.ChaValue);
                            break;
                        }
                    }
                }
                else if (colGrain != null && colGrain.Visibility == Visibility.Visible)
                {
                    foreach (DataValue data1 in predictYData)
                    {
                        string dateStr1 = String.Format("{0:MM-dd}", data1.date);
                        if (dateStr1.Equals(dateStr))
                        {
                            textDate.Text = dateStr;
                            textCha.Text  = String.Format("{0:0.00}", data1.ChaValue);
                            break;
                        }
                    }
                }
                else if (colTCC != null && colTCC.Visibility == Visibility.Visible)
                {
                    foreach (DataValue data1 in predictY3Data)
                    {
                        string dateStr1 = String.Format("{0:MM-dd}", data1.date);
                        if (dateStr1.Equals(dateStr))
                        {
                            textCha.Text = String.Format("{0:0.00}", data1.ChaValue);
                            break;
                        }
                    }
                }
                else if (colRice != null && colRice.Visibility == Visibility.Visible)
                {
                    foreach (DataValue data1 in predictY2Data)
                    {
                        string dateStr1 = String.Format("{0:MM-dd}", data1.date);
                        if (dateStr1.Equals(dateStr))
                        {
                            textDate.Text = dateStr;
                            textCha.Text  = String.Format("{0:0.00}", data1.ChaValue);
                            break;
                        }
                    }
                }

                textGrainY.Text    = String.Format("{0:0.00}", unscaledY);
                textGrainDate.Text = String.Format("{0:MM-dd}", xDate);

                textCornY1.Text   = String.Format("{0:0.00}", unscaledY);
                textCornDate.Text = String.Format("{0:MM-dd}", xDate);

                textRiceY2.Text   = String.Format("{0:0.00}", unscaledY);
                textRiceDate.Text = String.Format("{0:MM-dd}", xDate);

                textTCCY3.Text   = String.Format("{0:0.00}", unscaledY);
                textTCCDate.Text = String.Format("{0:MM-dd}", xDate);
            }
        }
Exemple #6
0
        private void RefreshStrips()
        {
            Axis xAxis;
            Axis yAxis;

            GetAxes(out xAxis, out yAxis);

            if (xAxis == null || yAxis == null || xAxis.RootCanvas == null)
            {
                return;
            }

            ClearExisting(xAxis);

            Rect viewport = GetViewportRect(xAxis);
            Rect window   = _owner.WindowRect;

            foreach (InfoStrip strip in this.InfoStrips)
            {
                InfoStrip toAdd = strip.Clone();

                bool         isInverted = xAxis.IsInverted;
                ScalerParams param      = new ScalerParams(window, viewport, isInverted);

                if (!toAdd.UseDates)
                {
                    if (double.IsNaN(toAdd.StartX))
                    {
                        toAdd.StartX = viewport.Left;
                    }
                    else
                    {
                        toAdd.StartX = xAxis.GetScaledValue(toAdd.StartX, param);
                        //NOTE: prior to 12.1 release:
                        //toAdd.StartX = xAxis.GetScaledValue(toAdd.StartX, window, viewport);
                    }
                    if (double.IsNaN(toAdd.EndX))
                    {
                        toAdd.EndX = viewport.Right;
                    }
                    else
                    {
                        toAdd.EndX = xAxis.GetScaledValue(toAdd.EndX, param);
                        //NOTE: prior to 12.1 release:
                        //toAdd.EndX = xAxis.GetScaledValue(toAdd.EndX, window, viewport);
                    }
                }
                else
                {
                    toAdd.StartX = xAxis.GetScaledValue(toAdd.StartDate.Ticks, param);
                    toAdd.EndX   = xAxis.GetScaledValue(toAdd.EndDate.Ticks, param);
                    //NOTE: prior to 12.1 release:
                    //toAdd.StartX = xAxis.GetScaledValue(toAdd.StartDate.Ticks, window, viewport);
                    //toAdd.EndX = xAxis.GetScaledValue(toAdd.EndDate.Ticks, window, viewport);
                }
                // check if y-axis is inverted
                isInverted = yAxis.IsInverted;
                param      = new ScalerParams(window, viewport, isInverted);

                if (double.IsNaN(toAdd.StartY))
                {
                    toAdd.StartY = viewport.Top;
                }
                else
                {
                    toAdd.StartY = yAxis.GetScaledValue(toAdd.StartY, param);
                    //NOTE: prior to 12.1 release:
                    //toAdd.StartY = yAxis.GetScaledValue(toAdd.StartY, window, viewport);
                }
                if (double.IsNaN(toAdd.EndY))
                {
                    toAdd.EndY = viewport.Bottom;
                }
                else
                {
                    toAdd.EndY = yAxis.GetScaledValue(toAdd.EndY, param);
                    //NOTE: prior to 12.1 release:
                    //toAdd.EndY = yAxis.GetScaledValue(toAdd.EndY, window, viewport);
                }
                if (toAdd.StripTemplate == null)
                {
                    toAdd.StripTemplate = this.InfoStripTemplate;
                }

                if (toAdd.StripTemplate != null &&
                    !double.IsNaN(toAdd.StartY) &&
                    !double.IsInfinity(toAdd.StartY) &&
                    !double.IsNaN(toAdd.StartX) &&
                    !double.IsInfinity(toAdd.StartX))
                {
                    ContentControl stripControl = new ContentControl();
                    stripControl.ContentTemplate = toAdd.StripTemplate;
                    stripControl.Content         = toAdd;
                    Canvas.SetLeft(stripControl, toAdd.StartX);
                    Canvas.SetTop(stripControl, toAdd.StartY);

                    xAxis.RootCanvas.Children.Add(stripControl);
                }
            }
        }