SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

Answered
0
0

I’ve created a custom rollover modifier, the aim being it only moves when the mouse is down. Pretty simple, here’s the code I have:

class Histogram2DSlicer : RolloverModifier
{
    public Histogram2DSlicer() : base()
    {
        ReceiveHandledEvents = true;
    }

    public override void OnModifierMouseMove(ModifierMouseArgs e)
    {
        Console.WriteLine(e.MouseButtons);
        if (e.MouseButtons == MouseButtons.Left)
        {
            base.OnModifierMouseMove(e);
        }
    }
}

However, the ModifierMouseArgs e.MouseButtons is “None” at all times, is this a bug or do the Modifiers not receive button events?

Joe

  • You must to post comments
Great Answer
0
0

Hi,

So your code is called, but e.MouseButtons is always None?

In that case I would suggest also overriding OnModifierMouseDown and storing the result of e.MouseButtons, for use later in the MouseMove event.

Does that help?

  • You must to post comments
0
0

Yeah, that workaround works, didn’t think of that. I’m also getting another problem though, the e.MousePoint.X is always 0… Y seems to function fine. Also, it woks fine in the OnModifierMouseDown.

class Histogram2DSlicer : ChartModifierBase
{
    private MouseButtons mouseButtons = MouseButtons.None;

    public override void OnModifierMouseDown(ModifierMouseArgs e)
    {
        base.OnModifierMouseDown(e);
        mouseButtons = e.MouseButtons;
    }

    public override void OnModifierMouseUp(ModifierMouseArgs e)
    {
        base.OnModifierMouseUp(e);
        mouseButtons = MouseButtons.None;
    }

    public override void OnMasterMouseLeave(ModifierMouseArgs e)
    {
        base.OnMasterMouseLeave(e);
        //in case mouse leaves with button down, releases then returns
        mouseButtons = MouseButtons.None;
    }

    public override void OnModifierMouseMove(ModifierMouseArgs e)
    {
        if (mouseButtons == MouseButtons.Left)
        {
            Console.WriteLine(e.MousePoint.X + ", " + e.MousePoint.Y);
            base.OnModifierMouseMove(e);
        }
    }
}

Tested on another surface (mountain series) and the X value was reported fine. Here’s the code for the non working graph:

            <s:SciChartSurface x:Name="sciChart"
                               Grid.Column="1"
                               GridLinesPanelStyle="{StaticResource GridLinesPanelStyle}"
                               dd:DragDrop.IsDropTarget="True"
                               dd:DragDrop.DropHandler="{Binding}">
                <s:SciChartSurface.RenderSurface>
                    <s3D:Direct3D10RenderSurface />
                </s:SciChartSurface.RenderSurface>

                <s:SciChartSurface.RenderableSeries>
                    <s:FastHeatMapRenderableSeries x:Name="heatmapSeries"
                                                   DataSeries="{Binding Histograms[0].HeatMapDataSeries}"
                                                   Maximum="{Binding Histograms[0].MaximumValue}">
                        <s:FastHeatMapRenderableSeries.ColorMap>
                            <LinearGradientBrush>
                                <GradientStop Offset="0" Color="DarkBlue" />
                                <GradientStop Offset="0.2" Color="CornflowerBlue" />
                                <GradientStop Offset="0.4" Color="DarkGreen" />
                                <GradientStop Offset="0.6" Color="Chartreuse" />
                                <GradientStop Offset="0.8" Color="Yellow" />
                                <GradientStop Offset="1" Color="Red" />
                            </LinearGradientBrush>
                        </s:FastHeatMapRenderableSeries.ColorMap>
                    </s:FastHeatMapRenderableSeries>
                </s:SciChartSurface.RenderableSeries>

                <s:SciChartSurface.XAxis>
                    <s:DateTimeAxis/>
                </s:SciChartSurface.XAxis>
                <s:SciChartSurface.YAxis>
                    <s:NumericAxis VisibleRange="{Binding VisibleRange, Mode=OneWayToSource}"/>
                </s:SciChartSurface.YAxis>

                <s:SciChartSurface.Annotations>
                    <s:HorizontalLineAnnotation HorizontalAlignment="Stretch"
                                                FontSize="13"
                                                FontWeight="Bold"
                                                Foreground="White"
                                                IsEditable="True"
                                                LabelPlacement="Axis"
                                                LabelTextFormatting="0.00"
                                                ShowLabel="True"
                                                Stroke="#FF42b649"
                                                StrokeThickness="2"
                                                Y1="{Binding YThreshold,
                                                             Mode=TwoWay,
                                                             FallbackValue=0}"/>
                    <s:VerticalLineAnnotation VerticalAlignment="Stretch"
                                                FontSize="13"
                                                FontWeight="Bold"
                                                Foreground="White"
                                                IsEditable="True"
                                                LabelPlacement="Axis"
                                                ShowLabel="True"
                                                Stroke="#FF42b649"
                                                StrokeThickness="2"
                                                X1="{Binding XThreshold,
                                                             Mode=TwoWay}"/>

                </s:SciChartSurface.Annotations>

                <s:SciChartSurface.ChartModifier>
                    <s:ModifierGroup>
                        <!--<s:RolloverModifier ShowTooltipOn="Always" UseInterpolation="True" ReceiveHandledEvents="True"/>-->
                        <helpers:RubberBandYZoomModifier ExecuteOn="MouseRightButton"/>
                        <s:ZoomExtentsModifier ExecuteOn="MouseDoubleClick"/>
                        <helpers:Histogram2DSlicer/>
                    </s:ModifierGroup>
                </s:SciChartSurface.ChartModifier>

            </s:SciChartSurface>

Edit notes: Replaced custom annothation with s:VerticalLineAnnotation. Didn’t fix.

  • Andrew
    I’m very surprised to hear e.MousePoint.X is always zero, because all our modifiers depend on this! Maybe share some more code?
  • Ken Hobbs
    I tested it on another surface and it works fine. I wonder if its because I’m using a FastHeatMapRenderableSeries?
  • Ken Hobbs
    I added the xaml code for the problem chart
  • Ken Hobbs
    Aha! It was my other custom monitor (RubberBandYZoomModifier), I removed that and everything works.
  • You must to post comments
0
0

I was thinking about what you said, that all the modifiers use this so they must all be broken. So how does the zoom modifying work then? I knew that used x and y position.

The problem was the code I’d copied from here:

https://www.scichart.com/questions/question/rubberbandxyzoommodifier-zoom-in-y-axis-only

That’ll teach me not to actually read through and figure out how it works. Because at a glance the problem is obvious! I’m assuming everything will work fine provided this is the last modifier added:

class RubberBandYZoomModifier : RubberBandXyZoomModifier
{
    // Create a class which inherits RubberBandXyZoomModifier and override ... 

    public override void OnModifierMouseDown(ModifierMouseArgs e)
    {
        Rect cb = this.ModifierSurface.GetBoundsRelativeTo(this.ModifierSurface);

        ModifierMouseArgs mm = e;
        mm.MousePoint = new Point(cb.Right, e.MousePoint.Y);

        base.OnModifierMouseDown(mm);
    }

    public override void OnModifierMouseUp(ModifierMouseArgs e)
    {
        ModifierMouseArgs mm = e;
        mm.MousePoint = new Point(0, e.MousePoint.Y);

        base.OnModifierMouseUp(mm);
    }

    public override void OnModifierMouseMove(ModifierMouseArgs e)
    {
        Rect cb = this.ModifierSurface.GetBoundsRelativeTo(this.ModifierSurface);

        ModifierMouseArgs mm = e;
        mm.MousePoint = new Point(cb.Left, e.MousePoint.Y);

        base.OnModifierMouseMove(mm);
    }
}
  • Andrew
    Good point. The ModifierMouseArgs is shared across all the modifiers (passed to each in turn until handled). It might be better practice here to create new ModifierMouseArgs passing in all arguments to the constructor and passing that to the base. Well done for figuring it out!
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.