CustomLinePointColoringAndShaping not working correctly

Found a possible bug in LightningChart? Report it here.

Moderator: Queue Moderators

Post Reply
frank
Posts: 51
Joined: Tue Mar 25, 2014 9:04 am

CustomLinePointColoringAndShaping not working correctly

Post by frank » Wed Aug 27, 2014 11:32 am

Hi,

I have some PointLineSeries with CustomLinePointColoringAndShaping-Event. The PointLineSeries are only drawn if the LineStyle.Width = 1.0f.
I need to be able to change the LineWidth e.g. with a slider or anything else (please see attached Sample).

If in CustomLinePointColoringAndShaping I set series.LineStyle.Width = 1.0f; the lines are sometimes(!) drawn. If not, canModifyCoords is always false.

Could you please help me with this?

Best regards,
Frank
Attachments
WpfApplication2.zip
(38.84 KiB) Downloaded 927 times

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: CustomLinePointColoringAndShaping not working correctly

Post by ArctionPasi » Thu Aug 28, 2014 4:35 pm

Hi Frank,

The event fires just before the rendering instructions are about to be transferred to GPU. In general, rendering instructions can be line vertices, point vertices and triangle corner vertices.

When line width = 1, it uses line vertices. It's just quite simple to modify them.

And so would be point vertices (1 px dots).

But when line width > 0, the line is triangulated, transferred to GPU with list of triangle corners. Modifying these triangles is virtually impossible by application-side event handler. For example a poly-line of 3 data points has a joint at the second point. That joint is made with dozens of small triangles, to form a filled circle. And the straight lines have two triangles each. Manipulating this... :shock: We'll, not very comfortable when said nice.

We have put this limitation visible in our demo application's ExampleMultiColorLineEvent example
Coordinates mofifying is supported only when the line width is 1, and line pattern is Solid.
So this an intentional limitation by design.

EDIT:
Remember to set series.MouseHighlight= false, or it will thicken when you mouse over it, the line will be rendered wrong with your handler.
LightningChart Support Team, PT

frank
Posts: 51
Joined: Tue Mar 25, 2014 9:04 am

Re: CustomLinePointColoringAndShaping not working correctly

Post by frank » Fri Aug 29, 2014 7:22 am

Hi Pasi,

so it should work if I set the LineWidth=1 before manipulating and reset it afterwards. But why aren't the lines drawn if I do so, as demonstrated in the sample project? They are just updated when moving the mouse over them or something like that. Or would I have to set/reset the width before calling CustomLinePointColoringAndShaping? Is there an event I could use before and afterwards?

Best regards,
Frank

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: CustomLinePointColoringAndShaping not working correctly

Post by ArctionPasi » Fri Aug 29, 2014 9:10 am

Don't change the line width property in the event. Only modify coordinates and colors.

Code: Select all


This code doesn't flicker: 

namespace WpfApplication2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private readonly double InvalidValue = -Math.Pow(10, 6);//Konstante für ungültige Werte
        private readonly double InvalidValueOvershoot = -Math.Pow(10, 6) + 1;
        private const double NonApprovedValueOffset = -50000;//Ungültige Werte werden mit diesem Offset verschoben, damit beim Zeichnen nicht nachträglich der Status wieder ermittelt werden muss
        private const double NonApprovedValueOvershoot = -20000;
        public MainWindow()
        {
            InitializeComponent();
            InitChart();
        }

        private void InitChart()
        {
            Random r = new Random();
            chart.ChartRenderOptions.MultiCoreProcessing = MultiCoreProcessing.Off;
            chart.ViewXY.XAxes.Add(new Arction.WPF.LightningChartUltimate.Axes.AxisX(chart.ViewXY));
            chart.ViewXY.YAxes.Add(new Arction.WPF.LightningChartUltimate.Axes.AxisY(chart.ViewXY));
            chart.ViewXY.DropOldSeriesData = false;
            chart.AfterRendering += chart_AfterRendering;
            for (int i = 0; i < 5; i++)
            {
                PointLineSeries pls = new PointLineSeries(chart.ViewXY, chart.ViewXY.XAxes[0], chart.ViewXY.YAxes[0]);
                SeriesPoint[] points = new SeriesPoint[100];
                for (int j = 0; j < points.Length; j++)
                {
                    points[j] = new SeriesPoint(j, r.NextDouble());
                }
                pls.LineStyle.Width = 1.0f;
                pls.Points = points;
                pls.MouseHighlight = MouseOverHighlight.None; 
                pls.CustomLinePointColoringAndShaping += CustomLinePointColoringAndShaping;
                chart.ViewXY.PointLineSeries.Add(pls);
            }
        }

        void chart_AfterRendering(LightningChartUltimate chart)
        {
            ChartTools.WriteLog("rendered"); 
        }

        private float _linewidth;
        private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (chart == null || chart.ViewXY == null || chart.ViewXY.PointLineSeries == null)
                return;

            /*
            _linewidth = (float)((int)e.NewValue + 1.0f);

            chart.BeginUpdate(); 
            foreach (PointLineSeries series in chart.ViewXY.PointLineSeries)
            {
                series.LineStyle.Width = (float)((int)e.NewValue + 1.0f);
            }

            chart.EndUpdate();
            */
        }

        private void CustomLinePointColoringAndShaping(PointLineSeriesBase series, ref PointFloat[] coords, ref int[] colors, bool canModifyCoords, bool canModifyColors)
        {
            //series.LineStyle.Width = 1.0f;
            if (!(canModifyColors && canModifyCoords))
            {

                Debug.WriteLine("Modify Colors: " + canModifyColors + " Modify Coords: " + canModifyCoords);

                return;
            }

            var iCount = coords.Length;
            var listOutputCoords = new List<PointFloat>();
            var listOutputColors = new List<int>();
            bool wasLow = true;
            int outputColor = (series.LineStyle.Color.A << 24) | (series.LineStyle.Color.R << 16) | (series.LineStyle.Color.G << 8) | series.LineStyle.Color.B; ;
            for (var i = 0; i < iCount; i++)
            {

                double yValue = 0;
                chart.ViewXY.YAxes[0].CoordToValue(coords[i].Y, out yValue);


                outputColor = (series.LineStyle.Color.A << 24) | (series.LineStyle.Color.R << 16) | (series.LineStyle.Color.G << 8) | series.LineStyle.Color.B; ;
                if (yValue > InvalidValueOvershoot && yValue < NonApprovedValueOvershoot)
                {
                    outputColor = System.Drawing.Color.LightYellow.ToArgb();
                    coords[i].Y = chart.ViewXY.YAxes[0].ValueToCoord(yValue + -NonApprovedValueOffset);
                }

                if (yValue < InvalidValueOvershoot)
                {
                    if (!wasLow && i > 0)
                    {//Vorgänger muss noch einmal transparent gezeichnet werden
                        listOutputColors.Add(System.Drawing.Color.Transparent.ToArgb());
                        listOutputCoords.Add(coords[i - 1]);
                    }
                    listOutputColors.Add(System.Drawing.Color.Transparent.ToArgb());
                    wasLow = true;
                }
                else
                {
                    if (wasLow)//Aktueller Wert muss noch einmal transparent gezeichnet werden
                    {
                        listOutputColors.Add(System.Drawing.Color.Transparent.ToArgb());
                        listOutputCoords.Add(coords[i]);
                    }
                    listOutputColors.Add(outputColor);
                    wasLow = false;
                }

                listOutputCoords.Add(coords[i]);
            }

            coords = listOutputCoords.ToArray();
            colors = listOutputColors.ToArray();
            //series.LineStyle.Width = _linewidth;
        }

    }
}

LightningChart Support Team, PT

frank
Posts: 51
Joined: Tue Mar 25, 2014 9:04 am

Re: CustomLinePointColoringAndShaping not working correctly

Post by frank » Fri Aug 29, 2014 9:54 am

Hi Pasi,

sorry, but I don't see a difference in the code, except that in Slider_ValueChanged the setting of the series.LineStyle.Width is commented out, so that the LineWidth stays 1.

Am I missing something?

Best regards,
Frank

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: CustomLinePointColoringAndShaping not working correctly

Post by ArctionPasi » Fri Aug 29, 2014 10:03 am

In the CustomLinePointColoringAndShaping, the the line width setting is commented out in the beginning and in the end.

And when creating series, I added row
pls.MouseHighlight = MouseOverHighlight.None
LightningChart Support Team, PT

frank
Posts: 51
Joined: Tue Mar 25, 2014 9:04 am

Re: CustomLinePointColoringAndShaping not working correctly

Post by frank » Fri Aug 29, 2014 10:06 am

Yes, I noticed that, too. They aren't needed any more because the LineWidth isn't changed in your example. But I NEED to change the LineWidth in my project!

Is there no way to combine LineWidth>1 and CustomLinePointColoringAndShaping?

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: CustomLinePointColoringAndShaping not working correctly

Post by ArctionPasi » Fri Aug 29, 2014 2:09 pm

I'll check how difficult would it be to add this. Directly I can say, not easy.
LightningChart Support Team, PT

frank
Posts: 51
Joined: Tue Mar 25, 2014 9:04 am

Re: CustomLinePointColoringAndShaping not working correctly

Post by frank » Fri Aug 29, 2014 2:32 pm

Hi Pasi,

thank you very much. This would be helpful.
But if it will become too complicated, I had the idea to use Series.PointStyle.Width and set round shapes :idea:
Perhaps they will be accepting this, as for zoomed-out charts the lines will also appear thicker.
But as I noticed in a short test, Points aren't drawn for overwritten lines in CustomLinePointColoringAndShaping. Is that correct?

Best regards,
Frank

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: CustomLinePointColoringAndShaping not working correctly

Post by ArctionPasi » Sun Aug 31, 2014 8:58 pm

Ok, CustomLinePointColoringAndShaping now supports line widths of > 1 too. This will be a feature of 6.1, available this week. :D
LightningChart Support Team, PT

frank
Posts: 51
Joined: Tue Mar 25, 2014 9:04 am

Re: CustomLinePointColoringAndShaping not working correctly

Post by frank » Mon Sep 01, 2014 6:53 am

:o Thank you very much! This is really good news

Post Reply