Ternary tweaks

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
KevinKillion
Newbie
Newbie
Posts: 11
Joined: Wed Jul 07, 2010 12:00 am

Ternary tweaks

Post by KevinKillion » Thu Jul 29, 2010 6:46 pm

I was delighted to see the new TERNARY series type, and have already made client-dazzling use of it in a project!

But there are a few tweaks needed. Please take this as suggestions from an enthusiastic fan who is astounded by how much is in TChart Pro!

* Axes
-- if a bubble is placed on an edge (because one of the three input values is zero),
the bubble may obscure axes labels. A way is needed to place the labels back further from
the main triangle to avoid this. (Settings for axis position don't seem to have any effect.)

* Weighting colors and palettes
-- Weird bug: I have a ternary series set up to use a rainbow palette. If I just crunch away and add points,
it looks terrific! But there is some time involved in doing the calculations for each point.
If I merely add a "Application.ProcessMessages" line in the loop that creates the points,
this messes up the coloring, and in unpredictable ways!

* Second series: it seems that if a second ternary series is added, that series is either transparent
(despite a transparency setting of zero), or perhaps the appearance is because it's drawn below the grid.

* Series editor:
-- one of the tabs is labeled "Grid 3D", but this is actually the tab that is used to set colors
-- user interface quirk: on that "Grid 3D" tab, simply clicking on the three sub-tabs (Single, Range, Palette)
actually changes the setting.

* VertexTitle
-- it isn't clear why each series should have its own set of three VertexTitles
-- If two or more series do have different VertexTitles, these titles are drawn over each other
-- There may be a problem if the second series has its VertexTitles set to an empty string
(I got some list-index-out-of-bounds errors doing that)
-- Where is the font, color and background color set for VertexTitles?
-- The chart is scaled to fit in available space, but the VertexTitles are ignored in this,
so that they wind up spilling off the left and right edges if they are long.
Possible solutions:
- left adjust the VertexTitle at the lower left, right adjust the one at the lower right
or,
- compensate for VertexTitles when auto-sizing the chart

I was going to add a suggestion that a bubble shape that would be great to have on a ternary chart would be a hexagon, but then I checked and saw that you already had that in there! I'm so impressed at how much thought and innovation went into so much of TChart!

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Ternary tweaks

Post by Yeray » Mon Aug 02, 2010 3:23 pm

Hi Kevin,

Thanks for your comments and suggestions. The TTernarySeries is a quite recent series and we know it needs to improve some aspects.
KevinKillion wrote:* Axes
-- if a bubble is placed on an edge (because one of the three input values is zero),
the bubble may obscure axes labels. A way is needed to place the labels back further from
the main triangle to avoid this. (Settings for axis position don't seem to have any effect.)
I've tried to make an example similar to the example in the Features demo at All fetaures\Welcome !\Axes\Opaque Zones but I've found that the axes are drawn at DrawAllValues so the region isn't yet UnClipped when the Axes try to be drawn, so they are also clipped. I've added it to the wish list to be revised for future releases (TV52015066).

Code: Select all

Uses TeeTernary, Math;

procedure TForm1.SeriesBeforeDraw(Sender: TObject);
Var boundingRect: TRect;
    chartHeight, chartWidth, topBound , midX, tmpWidth, yShift:Integer;
begin
  chartHeight:=Chart1.ChartRect.Bottom-Chart1.ChartRect.Top;
  chartWidth:=Chart1.ChartRect.Right-Chart1.ChartRect.Left;
  if (chartWidth>chartHeight) Then
    boundingRect:=Rect(Chart1.ChartXCenter-(chartHeight div 2),
                       Chart1.ChartRect.Top,
                       Chart1.ChartXCenter+(chartHeight div 2),
                       Chart1.ChartRect.Bottom)
  else
    boundingRect:=Rect(Chart1.ChartRect.Left,
                       Chart1.ChartYCenter-(chartWidth div 2),
                       Chart1.ChartRect.Right,
                       Chart1.ChartYCenter+(chartWidth div 2));

  midX:=Chart1.ChartXCenter;

  tmpWidth:=(boundingRect.Right-boundingRect.Left) div 2;
  topBound:=Round(Tan(DegToRad(60.0))*tmpWidth);
  yShift:=(boundingRect.Bottom-boundingRect.Top-topBound) div 2;

  Chart1.Canvas.ClipPolygon([Point(midX,boundingRect.Bottom-topBound-yShift),
                             Point(boundingRect.Left,boundingRect.Bottom-yShift),
                             Point(boundingRect.Right,boundingRect.Bottom-yShift)], 3);
end;

procedure TForm1.SeriesAfterDraw(Sender: TObject);
begin
  Chart1.Canvas.UnClipRectangle;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;

  with Chart1.AddSeries(TTernarySeries.Create(self)) as TTernarySeries do
  begin
    FillSampleValues(10);

    Pointer.Style:=psCircle;
    Pointer.Transparency:=20;

    TernaryStyle:=tsBubble;
    TernaryLegendStyle:=tlsBubbleWeight;

    BeforeDrawValues:=SeriesBeforeDraw;
    AfterDrawValues:=SeriesAfterDraw;
  end;
end;
KevinKillion wrote:* Weighting colors and palettes
-- Weird bug: I have a ternary series set up to use a rainbow palette. If I just crunch away and add points,
it looks terrific! But there is some time involved in doing the calculations for each point.
If I merely add a "Application.ProcessMessages" line in the loop that creates the points,
this messes up the coloring, and in unpredictable ways!
I'm not sure to understand what are you exactly doing. Could you please arrange a simple example project we can run as-is to reproduce the problem here?
Thanks in advance.
KevinKillion wrote:* Second series: it seems that if a second ternary series is added, that series is either transparent
(despite a transparency setting of zero), or perhaps the appearance is because it's drawn below the grid.
This is probably related to the above (TV52015066).
The axes are drawn just before drawing the values of a TTernarySeries so, if you have two series, the axes will be drawn twice: Axes, Series1, Axes, Series2.
I've added it as another ticket to the wish list so it can be revised for future releases (TV52015067).
KevinKillion wrote:* Series editor:
-- one of the tabs is labeled "Grid 3D", but this is actually the tab that is used to set colors
-- user interface quirk: on that "Grid 3D" tab, simply clicking on the three sub-tabs (Single, Range, Palette)
actually changes the setting.
This happens also with SurfaceSeries, ColorGrid,... I've added to the wish list the possibility to add an "Apply" button so these tabs can be navigated without changing the series until you click on that button (TV52015068)
KevinKillion wrote:* VertexTitle
-- it isn't clear why each series should have its own set of three VertexTitles
-- If two or more series do have different VertexTitles, these titles are drawn over each other
-- There may be a problem if the second series has its VertexTitles set to an empty string
(I got some list-index-out-of-bounds errors doing that)
-- Where is the font, color and background color set for VertexTitles?
-- The chart is scaled to fit in available space, but the VertexTitles are ignored in this,
so that they wind up spilling off the left and right edges if they are long.
Possible solutions:
- left adjust the VertexTitle at the lower left, right adjust the one at the lower right
or,
- compensate for VertexTitles when auto-sizing the chart
I've added it to the wish list too (TV52015069). I think it would be nice if the VertexTitles would be more configurable.
The error of having a second Ternary with an empty VertexTitle would be probably solved with (TV52015067).
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

KevinKillion
Newbie
Newbie
Posts: 11
Joined: Wed Jul 07, 2010 12:00 am

Re: Ternary tweaks

Post by KevinKillion » Tue Aug 17, 2010 3:15 am

Hi, Yeray and others --

I've created a little demo project (with a runnable EXE and all the source code) that illustrates several tweaks needed to TERNARY plots, including:

* obscuring of axis labels
* clipped display of lower two VertexTitles
* Palette seems to cycle over and over, rather than fitting to the range of values
* addition of a second series makes the first series transparent to axis labels and grid (either that or else the labels and grid are now dran after the frst series)
* demonstration of a nasty bug when setting VertexTitles to an empty string
* colors assigned differently if "ProcessMessages" is used between adding points

The attachment feature here won't allow a zip this size, so I've put it on my server at this address:

http://www.shsmedia.com/temp/TernaryTweaks.zip

I'm looking forward to your comments!!!

Kevin

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Ternary tweaks

Post by Yeray » Tue Aug 17, 2010 11:18 am

Hi Kevin,

Thanks for the sample project.
KevinKillion wrote:* obscuring of axis labels
KevinKillion wrote:* addition of a second series makes the first series transparent to axis labels and grid (either that or else the labels and grid are now dran after the frst series)
These two points I think are caused for the particularity of the series and how are drawn the axes for this series. All this will be revised with (TV52015067).
KevinKillion wrote:* demonstration of a nasty bug when setting VertexTitles to an empty string
I've added the description of the problem in the ticket (TV52015069) that will try to improve the VertexTitles.
KevinKillion wrote:* clipped display of lower two VertexTitles
Yes, this is another of the things we'll try to improve in (TV52015069).
KevinKillion wrote:* Palette seems to cycle over and over, rather than fitting to the range of values
Yes, it seems strange to me too. I've added it to the defect list to be revised in future releases (TV52015092).
KevinKillion wrote:* colors assigned differently if "ProcessMessages" is used between adding points
I can't see any difference. I've tried simplifying your example to the following but I can see the same in the two pictures exported:

Code: Select all

uses TeEngine, Chart, TeeSurfa, TeeTernary, TeExport, TeePNG;

procedure TForm1.FormCreate(Sender: TObject);
var Chart1: TChart;
    Series1: TTernarySeries;
    i: Integer;
    a, b, c, distance: longint;
begin
  Chart1:=TChart.Create(self);
  Chart1.Parent:=self;
  Chart1.Height:=500;
  Chart1.Width:=600;

  Chart1.Legend.Visible:=false;
  Chart1.View3D:=false;

  Series1:=TTernarySeries.Create(self);
  Chart1.AddSeries(Series1);

  for i:= 0 to 1 do
  begin
    with Series1 do
    begin
      Clear;
      for a := 0 to 10 do
        for b := 0 to (10 - a) do
          begin
            c := 10 - a - b;
            distance := ABS(a - 3) + ABS(b - 3) + ABS(c - 5);
            AddBubbleXYZWeight(a * 10, b * 10, c * 10, 15, distance);

            if (i=1) then
              Application.ProcessMessages;
          end;

      TernaryStyle:=tsBubble;
      UseColorRange:=False;
      UsePalette:=True;
      PaletteStyle:=psRainbow;
      Pointer.Style:=psHexagon;
    end;

    if i=1 then
      TeeSaveToPNG(Chart1,'C:\tmp\Chart1Msg.png')
    else
      TeeSaveToPNG(Chart1,'C:\tmp\Chart1.png');
  end;
end;
Chart1Msg.png
Chart1Msg.png (9.06 KiB) Viewed 4600 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply