ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Controlling tool tips for spline line when no valid data is present
Posted by DC Kelley on Apr-05-2011 04:14
Attachments:
If I have a chart with a spline fitted over some points, and for a period of these points the data is set to "NoValue".  When shown, CD plots the raw data and the spline fit data just fine (see below), but when a mouse is hovered over this data, there is not a tool tip presented for the period when there NoValue is used.  In all the other periods (to either side of the center in this image) the tool top for the spline line works as expected (as it does for all other use of lines).

I realize I can suppress the spline line during the 'no data' periods using the different line patterns you taught in another recent post (setting it to transparent when no line is wanted),

but IF this line is to be shown, how can I create at least some kind of default tool tip ("no data at this point" or some such) to be used?
SavedScreenChart.png

  Re: Controlling tool tips for spline line when no valid data is present
Posted by Peter Kwan on Apr-06-2011 00:43
Hi DC Kelley,

Unluckily, I cannot think of any method that can create tooltips on NoValue positions.

Personally, I would probably use a different line style so that the user can distinguish the NoValue positions from the normal positions.

Another method is to not using NoValue at all. If you do not have NoValue points, then the entire spline will have tooltips. Your data points can be unevenly spaced without using NoValue points (so you can still have a wide gap with no data points). You just need to only pass the (x, y) coordinates of the valid points to ChartDirector to plot the spline.

I am not sure the x-coordinate system you are using. If you are using a label based x-axis (the x-axis is configured using Axis.setLabels), the x-coordinates of a data point is the array index of the labels (0, 1, 2, ....). For example, suppose your original data are y = { 12, 23, 45, Chart::NoValue, 58, 55 }. You may instead use y = { 12, 23, 45, 58, 55 } and x = { 0, 1, 2, 4, 5 }. You may refer to the "Uneven Data Points" sample code for an example.

Regards
Peter Kwan

  Re: Controlling tool tips for spline line when no valid data is present
Posted by DC Kelley on Apr-06-2011 02:55
Attachments:
Regarding the your question about X axis in this app, it reflect the passage time and to us time ALWAYS steps ahead in the moral world at a fixed rate (typically a sec) and never is "missing" and all other data is viewed against this. A side effect of this is I have not been creating X axis data sets for most charts.


Well.....  neither one of those solutions is ideal, so I am not clear on the best choice.

I do like the concept of the the different line styles (and again thanks for demonstrating that in anther prior reply) but in this instance we could have an arbitrary number of data drop outs and it is not clear to me how to extend the fragment of code to handle the general case where an an arbitrary number of changes between the line and "transparent" would be needed.   If I could cope with that, it seems to be the preferred way to go.


The alternative, reworking the data to create a data set with no "NoValue" items present and an X axis array to match, works and does produce the tool tip that started this thread.  I coded that up to test it.

However, as the "LOWESS" algorithm looks at all the data present in its approach (which is of course by design) this has the unintended side effect of causing the line during the drop-out to trend in anticipate of the "future" data once it resumes.  See below.  I dare not use a line like this.  This will be a problem for our needs because it gives rise to questions regarding why the line is "wiggling" in the non-data zone.  Of course you know how the algorithm works, our users do not and tend to presume these lines follow our own internal algorithms (which are predictive in nature so they can not yet use those data points).  In this app it is better to go back the the prior graph (where missing data causes a straight line segment) then use his method.

Unless something like the below can be created for a more general case of use...

   // constrain the line's display color over a limited range
   int lineColor = c->xZoneColor((start + startTrend - overhang), Transparent,
         c->xZoneColor((start + endTrend + overhang),
         0x2200ff, Transparent));
SavedScreenChart.png

  Re: Controlling tool tips for spline line when no valid data is present
Posted by Peter Kwan on Apr-07-2011 00:56
Hi DC Kelley,

1. To use a different line style for the gaps, please use LineLayer.setGapColor. This works for arbitrary number of gaps. (You mentioned above x-zone color at the end of your message. Are you thinking of using x-zone color? For handling data gaps, there is a special API LineLayer.setGapColor that works for arbitrary number of gaps.)

For example:

layer->setGapColor(c->dashLineColor(0x0000ff, Chart::DashLine));

2. Removing the NoValue points should give up an identical chart, even if you use LOWESS. Are you using ArrayMath.lowess2 or ArrayMath.lowess? The ArrayMath.lowess2 allows you to supply an x-coordinate array, so that it can properly take care of the uneven x-coordinates. The Array.lowess assumes all data points must be evenly spaced. From your chart, it seems the LOWESS is computed using Array.lowess as opposed to ArrayMath.lowess2.

Hope this can help.

Regards
Peter Kwan

  Re: Controlling tool tips for spline line when no valid data is present
Posted by DC Kelley on Apr-08-2011 06:44
Attachments:
I believe I am using ArrayMath.lowess2 and passing in an array of the un-even time points, but perhaps I am doing it wrong.  See code below.

The gap color call solves >95% of this issue to my thinking (and do not have top parse over a huge data set with some resolution threshold myself, I can let you can do it :-) ).

I would still like to get lowess2 () the work.  The key code is shown below.  You can see how both lines are plotted ( the lowess2 is the light purple line).

            // Un-even time step method
            double* tempY = NULL;
            double* tempX = NULL;
            j = 0;
            for(i=0; i<howMany; i++) if (pData[i] != NoValue) j++; // count real points present
            tempY = new double[j]; // will hold value set with NO 'no-value' points
            tempX = new double[j]; // will hold un-even time points to match it
            j = 0;
            for(i=0; i<howMany; i++)
            { // fill arrays with the valid data points and time marks only
                if (pData[i] != NoValue)
                {
                    tempY[j] = pData[i]; // the data
                    tempX[j] = i; // record this time in time array
                    j++; // move to next array index
                }
            }
            SplineLayer *theSpine2 = c->addSplineLayer(
                                ArrayMath(DoubleArray(&tempY[0], j)).lowess(
                                          DoubleArray(&tempX[0], j), 0.60),
                                0xff00ff, name + "-ALT-TESTSplineFit");
            theSpine2->setLineWidth(2);
            theSpine2->setXData(start, end-1);
            theSpine2->setGapColor(c->dashLineColor(0x00ffff, Chart::DashLine));
            delete tempY;
            delete tempX;

            /*** Preferred method, as it is somewhat simpler ***/
            SplineLayer *theSpine = c->addSplineLayer(
                                ArrayMath(DoubleArray(pData,howMany)).lowess(),
                                0x0000ff, name + "-SimpleSplineFit");
            theSpine->setLineWidth(3);
            theSpine->setXData(start, end-1);
            theSpine->setGapColor(c->dashLineColor(0x00ffff, Chart::DashLine));
SavedScreenChart.png

  Re: Controlling tool tips for spline line when no valid data is present
Posted by Peter Kwan on Apr-08-2011 16:57
Hi DC Kelley,

The issue is in the line:

          theSpine2->setXData(start, end-1);

The above line means "spread the data points evenly from x=start to x=end - 1". However, your lowess2 points should not be plotted as evenly spaced. Also, we cannot assume that the line starts at "start" and ends at "end - 1" (these two points may not exist and they can be NoValue points and removed from the line).

You may try to modify your code to:

//The actual x-coordinate of the points. It is equal to i only if start = 0 and end = howMany.
tempX[j] = start + i * (end - start) / (double)howMany;

For the layer using lowess2 only, the setXData should be:

//these are the actual x-coordinates of the points
theSpine2->setXData(DoubleArray(tempX, j));

Hope this can help.

Regards
Peter Kwan

  Re: Controlling tool tips for spline line when no valid data is present
Posted by DC Kelley on Apr-09-2011 01:01
Attachments:
I see now, the setXData() call will trump any actual points found in the X axis array, I had thought the reverse would be true but on reflection this make more sense.

I have coded it as you indicated (actually I just went back to the base master array and grabbed the real times from there) and now the line tracks as expected (see below).  Now I more clearly see that what was occurring as the line got "stretched" over the axis bounds due to the above call.

But as this line in fact has no 'NoValue" gaps in it, does the call to
     theSpine->setGapColor(c->dashLineColor(aColor, Chart::DashLine));
still make any sense or have any actual impact?
I am thinking no, and therefore a line WITH the NoValue elements is of value for its ability to control this.

Both lines types nicely drop off the chart if the edge of the chart does not contains valid data, so this good as well.  Call this one closed.
SavedScreenChart.png

  Re: Controlling tool tips for spline line when no valid data is present
Posted by Peter Kwan on Apr-10-2011 18:01
Hi DC Kelley,

The theSpine->setGapColor(c->dashLineColor(aColor, Chart::DashLine)); only has effect if the spline curve has "gaps" in it (has NoValue points). If the NoValue points are removed before passing the data to ChartDirector, then ChartDirector would not know where are the gaps and so the gap color would have no effect.

Note that ChartDirector cannot infer where are the gaps without the NoValue points. For example, suppose your x-coordinates are {0, 1, 1.7, 2.7, 4.3, 7, 8, 8.9}. Although sometimes the points are spaced more widely than the average, it is still hard to know if this means a gap. So NoValue points in the data are needed for ChartDirector to determine the gaps.

Regards
Peter Kwan