Exemplo n.º 1
0
        protected virtual void OnCreateModifiers(SciChartInteractionToolbar toolbar, ISciChartSurface scs)
        {
            var listMod = new List <ToolbarItem>();

            var surface = scs as SciChartSurface;
            var isPolar = surface != null && (surface.IsPolarChart || surface.XAxes.Any(x => x.IsPolarAxis) || surface.YAxes.Any(x => x.IsPolarAxis));

            // RubberBandXyZoomModifier
            var rbzm = new RubberBandXyZoomModifier {
                IsXAxisOnly = IsZoomXAxisOnly
            };

            _modifiersInAllMode.ChildModifiers.Add(rbzm);
            _modifiersInDevMode.ChildModifiers.Add(rbzm);

            if (!isPolar)
            {
                // ZoomPanModifier
                var zpm = new ZoomPanModifier {
                    ClipModeX = ClipMode.None, IsEnabled = false
                };
                _modifiersInAllMode.ChildModifiers.Add(zpm);
                _modifiersInDevMode.ChildModifiers.Add(zpm);
            }

            // ZoomExtentsModifier
            var zoomExtents = new ZoomExtentsModifier {
                ExecuteOn = ExecuteOn.MouseDoubleClick
            };

            _modifiersInAllMode.ChildModifiers.Add(zoomExtents);
            _modifiersInDevMode.ChildModifiers.Add(zoomExtents);

            // SeriesSelectionModifier
            var selStyle = new Style(typeof(BaseRenderableSeries));

            selStyle.Setters.Add(new Setter(BaseRenderableSeries.StrokeProperty, Colors.Red));
            selStyle.Setters.Add(new Setter(BaseRenderableSeries.StrokeThicknessProperty, 2));
            selStyle.Seal();

            var seriesSelection = new SeriesSelectionModifier
            {
                SelectedSeriesStyle  = selStyle,
                ReceiveHandledEvents = true,
                IsEnabled            = false
            };

            _modifiersInDevMode.ChildModifiers.Add(seriesSelection);

            // AnnotationCreationModifier
            var annotationMod = new CustomAnnotationCreationModifier();

            annotationMod.AnnotationCreated += (sender, args) =>
            {
                var modifier = (CustomAnnotationCreationModifier)sender;
                if (modifier != null)
                {
                    foreach (var annotation in scs.Annotations)
                    {
                        var newAnnotation = (annotation as AnnotationBase);
                        if (newAnnotation != null)
                        {
                            newAnnotation.IsEditable  = true;
                            newAnnotation.CanEditText = true;
                        }
                    }

                    modifier.IsEnabled = false;
                }
            };
            annotationMod.IsEnabled = false;
            _modifiersInDevMode.ChildModifiers.Add(annotationMod);

            // CustomRotateChartModifier
            var rotate = new CustomRotateChartModifier();

            var propertyPath = new PropertyPath(CustomRotateChartModifier.IsRotationEnabledProperty);
            var binding      = new Binding()
            {
                Source = this, Path = propertyPath
            };

            rotate.SetBinding(ChartModifierBase.IsEnabledProperty, binding);

            _modifiersInDevMode.ChildModifiers.Add(rotate);

            // Custom Export Modifier
            var export = new CustomExportModifier();

            _modifiersInDevMode.ChildModifiers.Add(export);

            // CustomThemeChangeModifier
            var theme = new CustomThemeChangeModifier();

            _modifiersInDevMode.ChildModifiers.Add(theme);

            // LegendModifier
            var legend = new LegendModifier
            {
                UseInterpolation         = true,
                ShowLegend               = false,
                ShowVisibilityCheckboxes = true,
                ShowSeriesMarkers        = true
            };

            _modifiersInDevMode.ChildModifiers.Add(legend);

            // MouseWheelZoomModifier
            var mouseWheel = new MouseWheelZoomModifier();

            _modifiersInAllMode.ChildModifiers.Add(mouseWheel);
            _modifiersInDevMode.ChildModifiers.Add(mouseWheel);

            // CustomFlipModifier
            var flip = new CustomFlipModifier();

            _modifiersInDevMode.ChildModifiers.Add(flip);

            // RolloverModifier
            var rollover = new RolloverModifier
            {
                IsEnabled            = false,
                UseInterpolation     = true,
                DrawVerticalLine     = true,
                ReceiveHandledEvents = true,
                ShowAxisLabels       = true,
                ShowTooltipOn        = ShowTooltipOptions.Always
            };

            _modifiersInDevMode.ChildModifiers.Add(rollover);

            // CursorModifier
            var cursorMod = new CursorModifier
            {
                IsEnabled            = false,
                ShowTooltipOn        = ShowTooltipOptions.MouseOver,
                ReceiveHandledEvents = true,
                ShowAxisLabels       = false,
                ShowTooltip          = true
            };

            _modifiersInDevMode.ChildModifiers.Add(cursorMod);

            // TooltipModifier
            var toolTipMod = new TooltipModifier
            {
                ReceiveHandledEvents = true,
                IsEnabled            = false,
                UseInterpolation     = true
            };

            _modifiersInDevMode.ChildModifiers.Add(toolTipMod);

            if (!isPolar)
            {
                // YAxisDragModifier
                var yAxisDrag = new YAxisDragModifier();
                _modifiersInDevMode.ChildModifiers.Add(yAxisDrag);

                // XAxisDragModifier
                var xAxisDrag = new XAxisDragModifier();
                _modifiersInDevMode.ChildModifiers.Add(xAxisDrag);
            }

            var exampleModifiers = (scs.ChartModifier as ModifierGroup);

            if (exampleModifiers == null)
            {
                exampleModifiers = new ModifierGroup();

                if (scs.ChartModifier != null)
                {
                    exampleModifiers.ChildModifiers.Add(scs.ChartModifier);
                }
            }

            var devMods  = new ModifierGroup();
            var userMods = new ModifierGroup();

            foreach (var devMod in _modifiersInDevMode.ChildModifiers)
            {
                var devModName = devMod.ModifierName;

                if (devMod is CustomAnnotationCreationModifier)
                {
                    devModName = "AnnotationCreationModifier";
                }

                if (!(exampleModifiers.ChildModifiers.Any(x => x.ModifierName == devModName)))
                {
                    devMods.ChildModifiers.Add(devMod);
                }
                else
                {
                    if (exampleModifiers.ChildModifiers.Count(x => x.ModifierName == devModName) == 1)
                    {
                        var exampleMod = exampleModifiers.ChildModifiers.Single(x => x.ModifierName == devModName);

                        if (!GetAppearceInToolbar((ChartModifierBase)exampleMod))
                        {
                            continue;
                        }

                        devMods.ChildModifiers.Add(exampleMod);
                    }
                    else
                    {
                        foreach (var exampleMod in exampleModifiers.ChildModifiers.Where(x => x.ModifierName == devModName && GetAppearceInToolbar((ChartModifierBase)x)))
                        {
                            devMods.ChildModifiers.Add(exampleMod);
                        }
                    }
                }
            }

            foreach (var inAllMod in _modifiersInAllMode.ChildModifiers)
            {
                var modName = inAllMod.ModifierName;

                if (!(exampleModifiers.ChildModifiers.Any(x => x.ModifierName == modName)))
                {
                    userMods.ChildModifiers.Add(inAllMod);
                }
                else
                {
                    if (exampleModifiers.ChildModifiers.Count(x => x.ModifierName == modName) == 1)
                    {
                        var exampleMod = exampleModifiers.ChildModifiers.Single(x => x.ModifierName == modName);

                        if (!GetAppearceInToolbar((ChartModifierBase)exampleMod))
                        {
                            continue;
                        }

                        userMods.ChildModifiers.Add(exampleMod);
                    }
                    else
                    {
                        foreach (var exampleMod in exampleModifiers.ChildModifiers.Where(x => x.ModifierName == modName && GetAppearceInToolbar((ChartModifierBase)x)))
                        {
                            userMods.ChildModifiers.Add(exampleMod);
                        }
                    }
                }
            }

            foreach (var exampleMod in exampleModifiers.ChildModifiers.Where(x => GetAppearceInToolbar((ChartModifierBase)x)))
            {
                if (!devMods.ChildModifiers.Any(x => x.ModifierName == exampleMod.ModifierName))
                {
                    devMods.ChildModifiers.Add(exampleMod);
                }

                if (!userMods.ChildModifiers.Any(x => x.ModifierName == exampleMod.ModifierName))
                {
                    userMods.ChildModifiers.Add(exampleMod);
                }
            }

            _modifiersInDevMode  = devMods;
            _modifiersInUserMode = userMods;

            // Set modifiers to the chart
            scs.ChartModifier = IsDeveloperMode ? _modifiersInDevMode : _modifiersInUserMode;

            var wrappers = WrapModifiers(toolbar.IsDeveloperMode
                ? toolbar._modifiersInDevMode.ChildModifiers
                : toolbar._modifiersInUserMode.ChildModifiers);

            // Set modifiers to the ItemSource for ItemsControl
            listMod.AddRange(wrappers);

            if (listMod.Any(x => x.Modifier.ModifierName == "AnnotationCreationModifier" || x.Modifier is VerticalSliceModifier))
            {
                listMod.Remove(listMod.FirstOrDefault(x => x.Modifier.ModifierName == "AnnotationCreationModifier"));
                listMod.Remove(listMod.FirstOrDefault(x => x.Modifier is VerticalSliceModifier));
            }

            ModifiersSource = listMod;
        }
Exemplo n.º 2
0
        public TrackToShow()
        {
            XAxisCollection = new AxisCollection();
            YAxis = new NumericAxis
            {
                DrawMajorTicks = false,
                AxisAlignment = AxisAlignment.Left,
                FlipCoordinates = true,
                MinimalZoomConstrain = 1,
                Name = "yAxisDesign",
            };

            HasCurves = false;
            ChartModifier = new ModifierGroup();

            SeriesModifier = new SeriesSelectionModifier
            {
                ReceiveHandledEvents = true
            };
            ScaleModifier = new ScaleFactorModifier
            {
                ReceiveHandledEvents = true
            };
            ZoomPanModifier = new ZoomPanModifierExtension
            {
                ReceiveHandledEvents = true,
                ClipModeX = ClipMode.None,
                ExecuteOn = ExecuteOn.MouseLeftButton,
                IsEnabled = true,
                XyDirection = XyDirection.YDirection,
                ZoomExtentsY = true
            };

            LegendModifier = new LegendModifier
            {
                GetLegendDataFor = SourceMode.AllSeries
            };
            MouseWheelModifier = new MouseWheelZoomModifier
            {
                ReceiveHandledEvents = true,
                XyDirection = XyDirection.YDirection
            };
            ZoomModifier = new ZoomExtentsModifier
            {
                ReceiveHandledEvents = true,
                XyDirection = XyDirection.YDirection
            };
            TooltipModifierObject = new TooltipModifier
            {
                UseInterpolation = true
            };

            TooltipModifierObject.TooltipLabelTemplate = GetTooltipLabelTemplate();

            ChartModifier.ChildModifiers.Add(SeriesModifier);
            ChartModifier.ChildModifiers.Add(ScaleModifier);
            ChartModifier.ChildModifiers.Add(ZoomPanModifier);
            ChartModifier.ChildModifiers.Add(LegendModifier);
            ChartModifier.ChildModifiers.Add(MouseWheelModifier);
            ChartModifier.ChildModifiers.Add(ZoomModifier);
            ChartModifier.ChildModifiers.Add(TooltipModifierObject);
            ChartModifier.ChildModifiers.Add(ExtendedTooltipModifier);
        }