|
From: <ai...@us...> - 2010-09-11 18:56:28
|
Revision: 11168
http://plplot.svn.sourceforge.net/plplot/?rev=11168&view=rev
Author: airwin
Date: 2010-09-11 18:56:21 +0000 (Sat, 11 Sep 2010)
Log Message:
-----------
Adjust ends of lines of symbols in the legend so they line up roughly
with ends of lines in the legend.
Use line_length specified by user rather than 0.1.
Modified Paths:
--------------
trunk/src/pllegend.c
Modified: trunk/src/pllegend.c
===================================================================
--- trunk/src/pllegend.c 2010-09-11 16:32:28 UTC (rev 11167)
+++ trunk/src/pllegend.c 2010-09-11 18:56:21 UTC (rev 11168)
@@ -23,7 +23,7 @@
#include "plplotP.h"
-PLFLT get_character_height() {
+PLFLT get_character_or_symbol_height(PLINT ifcharacter) {
// Character height in mm
PLFLT default_mm, char_height_mm;
// Normalized viewport limits
@@ -40,7 +40,12 @@
PLFLT wxmin, wxmax, wymin, wymax;
PLFLT world_y;
- plgchr(&default_mm, &char_height_mm);
+ if(ifcharacter) {
+ plgchr(&default_mm, &char_height_mm);
+ } else {
+ default_mm = plsc->symdef;
+ char_height_mm = plsc->symht;
+ }
plgvpd(&vxmin, &vxmax, &vymin, &vymax);
vy = vymax - vymin;
@@ -83,7 +88,7 @@
PLFLT line_y, line_y_world;
PLFLT text_x, text_y, text_x_world, text_y_world;
// Character height (world coordinates)
- PLFLT character_height;
+ PLFLT character_height, character_width, symbol_width;
// y-position of the current legend entry
PLFLT ty;
// Positions of the legend entries
@@ -102,18 +107,31 @@
// World coordinates for legend lines
line_x = x;
line_y = y;
- line_x_end = line_x + 0.1;
+ line_x_end = line_x + line_length;
line_x_world = normalized_to_world_x(line_x);
line_y_world = normalized_to_world_y(line_y);
line_x_end_world = normalized_to_world_x(line_x_end);
+ // Get character height and width in world coordinates
+ character_height = get_character_or_symbol_height(1);
+ character_width = character_height*fabs((xmax-xmin)/(ymax-ymin));
+ // Get symbol width in world coordinates if symbols are plotted to
+ // adjust ends of line of symbols.
+ if( ifline) {
+ symbol_width = 0.;
+ } else {
+ // AWI, no idea why must use 0.5 factor to get ends of symbol lines
+ // to line up approximately correctly with plotted legend lines.
+ // Factor should be unity.
+ symbol_width = 0.5*get_character_or_symbol_height(0)*
+ fabs((xmax-xmin)/(ymax-ymin));
+ }
// Get world-coordinate positions of the start of the legend text
- text_x = line_x_end + 0.01;
+ text_x = line_x_end;
text_y = line_y;
- text_x_world = normalized_to_world_x(text_x);
+ text_x_world = normalized_to_world_x(text_x) + character_width;
text_y_world = normalized_to_world_y(text_y);
- character_height = get_character_height();
// Starting y position for legend entries
ty = text_y_world - character_height;
@@ -123,9 +141,9 @@
plexit( "pllegend: Insufficient memory" );
}
- dxs = (line_x_end_world - line_x_world)/(double) (nsymbols-1);
+ dxs = (line_x_end_world - line_x_world - symbol_width)/(double) (nsymbols-1);
for (j=0; j<nsymbols; j++) {
- xs[j] = line_x_world + dxs*(double) j;
+ xs[j] = line_x_world + 0.5*symbol_width + dxs*(double) j;
ys[j] = ty;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|