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

Message ListMessage List     Post MessagePost Message

  Problem with tracking and dot line
Posted by davide on Jul-04-2018 23:55
Attachments:
Hi Peter,

I have a problem using tracking and dot line or dash line. Basically when the LineLayer is a continuous line I have no problem, the track line works well, I have the right color and the value is displayed in the right way on the trackaxis. When I switch to a Dot Line the color looks like it can't be recognized by the code(now I post also the code), and the value is displayed using Dot as well as the line and the color is white(but in debug I see -131072 even worst).
This is the function I use for the Tracking, it's not all the code but I hope it's enough, if it's not let me know!


for(int i = 0; i < c->getLayerCount(); ++i)
            {
                Layer *layer = c->getLayerByZ(i);

                // The data array index of the x-value
                int xIndex = layer->getXIndexOf(xValue);

                // Iterate through all the data sets in the layer
                for(int j = 0; j < layer->getDataSetCount(); ++j)
                {
                    DataSet *dataSet = layer->getDataSetByZ(j);

                    // The positional value, axis binding, pixel coordinate and color of the data point.
                    double dataPoint = dataSet->getPosition(xIndex);
                    Axis *yAxis = dataSet->getUseYAxis();
                    int yCoor = c->getYCoor(dataPoint, yAxis);
                    int color = dataSet->getDataColor();

                    // Draw the axis label only for visible data points of named data sets
                    if ((dataPoint != Chart::NoValue) && (color != (int)Chart::Transparent) && (yCoor >=
                        plotArea->getTopY()) && (yCoor <= plotArea->getBottomY()))
                    {
                        int xPos = yAxis->getX() + ((yAxis->getAlignment() == Chart::Left) ? -4 : 4);
                        d->hline(xCoor, xPos, yCoor + c->getAbsOffsetY(), d->dashLineColor(color, 0x0101));
                        d->circle(xCoor, yCoor + c->getAbsOffsetY(), GRANDEZZA_PALLINO_GRAFICI, GRANDEZZA_PALLINO_GRAFICI, color, color);

                        ostringstream label;
                        label << "<*font,bgColor=000000*> " << c->formatValue(dataSet->getValue(xIndex), "{value|P4}") << " <*font*>";
                        t = d->text(label.str().c_str(), "arialbd.ttf", 8);

                        // Draw the label on the right side of the dot if the mouse is on the left side the
                        // chart, and vice versa. This ensures the label will not go outside the chart image.
                        if (xCoor <= (plotArea->getLeftX() + plotArea->getRightX()) / 2)
                        {
                            t->draw(xCoor + OFFSET_SIDE_LABELS, /*yCoor*/yCoorLabel + c->getAbsOffsetY(), color, Chart::Left);
                        }
                        else
                        {
                            t->draw(xCoor - OFFSET_SIDE_LABELS, /*yCoor*/yCoorLabel + c->getAbsOffsetY(), color, Chart::Right);
                        }
                        yCoorLabel -= height;
                        t->destroy();
                    }
                }
            }

Maybe watching at the image you will understand better. Is there a way to get the right color and the right layout (not Dot) for the value I display when tracking?

Thanks in advance!
problem.PNG
Noproblem.PNG

  Re: Problem with tracking and dot line
Posted by Peter Kwan on Jul-05-2018 22:58
Hi Davide,

There are two issues in using the "dynamic color" (such as the dash line color) for drawing other things:

(a) If you use a dash line color to draw a non-line (such as to draw text), the effect is not predictable and usually is not good.

(b) A "dynamic color" is created by a chart object, such as by using BaseChart::dashLineColor for a dash line color. The returned integer "color" is actually a "handle" to the dynamic color, and the handle is only valid for the chart that creates the color. So a dynamic color created using the chart A can only be used for the objects in chart A, and not in a different chart B.


For your case, the code structure seems to suggest that the DrawArea "d" is not the DrawArea for the XYChart "c". (It is probably the DrawArea for a different MultiChart object.) So the dynamic color would not work in "d".

In general, a dynamic color can be dynamic in various ways (it can be a dash line color, pattern color, zone color, gradients, etc), and they may not be suitable to draw text.


For your case, the obvious method is to restrict the data color to a solid ARGB color. If you must use dynamic colors, you would need to specify two colors - one for the line, and one for the track cursor text. The ChartDirector API does not have a built-in property for the track line text color, so you would need to keep a lookup table to map the "chart index and the dynamic color" to the "text color".

Regards
Peter Kwan

  Re: Problem with tracking and dot line
Posted by davide on Jul-05-2018 23:34
Thanks for the reply Peter.

I understand the problem of "dynamic color" but I have some other questions about it.


b) If I understood correctly, a "dynamic color" si not just a color, it contains some different properties. But there must be a way to extract the color from that int, since the line is displayed using the correct color: it means that CD knows which bit(for example) identifies the color of the line.

1)Alternatively, since I have the yAxis that refers to that dot line that has the same color I need, is there a way to extract the color from it?
Or maybe from the title of the yAxis? there is a function yAxis->setColors() but I didn't see a function yAxis->getColors() or something similar.
It would be very helpful, maybe for the next CD release :)

Regards
Davide Salvetti

  Re: Problem with tracking and dot line
Posted by Peter Kwan on Jul-07-2018 00:43
Hi davide,

A dynamic color be a dash line color or a 10 x 10 pattern color or a gradient color, etc..
An integer does not have sufficient number of bits to hold all the information. In ChartDirector, the integer is actually a "handle" to a table which holds the type and parameters for the dynamic color, in which the table is in the chart object for which the dynamic color is defined. That's why a dynamic color only works for the chart which defines the color.

For a "dash line color", there seems to be a "correct color" for text. However, in all other cases, there is no "correct color" (consider the 10 x 10 pattern with 100 colors or a graident with 4 color stops, there one no obvious "correct color"? ). So internally there is no API to get the "correct color".

For getting the colors, unluckily, ChartDirector does not have too many getter methods, particularly for information that are provided externally. For the axis colors, they are provided by your code to ChartDirector, so your code should already know all the colors. It just needs to keep track of the colors. In one common implementation, the code will have a "property bag" that contains all the configurable parameters of your chart. The chart is configured based on the "property bag". If the configuration parameters are needed later, they too can be retrieved from the "property bag".

Regards
Peter Kwan