gavioto / clientsidegchart

Automatically exported from code.google.com/p/clientsidegchart
0 stars 2 forks source link

Feature Request: Inverse axis scale/arbitrary coordinate mapping #5

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In my field (chemical engineering), axis scalings other than normal and 
logarithmic can be useful.  In particular, inverse scaling is common (1/x).  
For a site I implemented last year with GChart 2.6, I made the following 
changes in order to implement this functionality:

    private final int LOG2INVERSE_FORMAT_TYPE = 3;
    private final int MULTINVERSE_FORMAT_TYPE = 4;   // <<<<
    private final int MAPPEDINVERSE_FORMAT_TYPE = 5; // <<<<
    private MappingFunction mappingFunction =        // <<<<
      new MappingFunction(){public double inverse(double input){return input;}};

...

      case LOG2INVERSE_FORMAT_TYPE:
        value = Math.pow(2., value);
        result = numberFormat.format(value);
        break;
      case MULTINVERSE_FORMAT_TYPE:                // <<<<
        value = 1.0/value;                         // <<<<
        result = numberFormat.format(value);       // <<<<
        break;                                     // <<<<
      case MAPPEDINVERSE_FORMAT_TYPE:              // <<<<
        value = mappingFunction.inverse(value);    // <<<<
        result = numberFormat.format(value);       // <<<<
        break;                                     // <<<<
      default:

...

    /**
     * Set the function used for determining a display value from a mapped value.
     * 
     * @param mappingFunction
     */
    public void setAxisMappingFunction(MappingFunction mappingFunction) {
      this.mappingFunction = mappingFunction;
    }

...

        } else if (format.startsWith("=2^")) {
          String transFormat = format.substring("=2^".length());
          numberFormat = NumberFormat.getFormat(transFormat);
          tickLabelFormatType = LOG2INVERSE_FORMAT_TYPE;
        } else if (format.startsWith("=1/")) {                      // <<<<
          String transFormat = format.substring("=1/".length());    // <<<<
          numberFormat = NumberFormat.getFormat(transFormat);       // <<<<
          tickLabelFormatType = MULTINVERSE_FORMAT_TYPE;            // <<<<
        } else if (format.startsWith("=f()")) {                     // <<<<
          String transFormat = format.substring("=f()".length()); // <<<<
          numberFormat = NumberFormat.getFormat(transFormat);     // <<<<
          tickLabelFormatType = MAPPEDINVERSE_FORMAT_TYPE;        // <<<<
        } else {

...

  /**
   * 
   * Provides a simple double function callback for supporting arbitrary
   * functional mappings.
   * 
   */
  public interface MappingFunction {double inverse(double input);}

...

I do not believe either of these features imposes a significant additional 
computational penalty when unused and would love if they could get folded into 
the next library release so I don't have to rely on local hacked versions of 
the library.

Original issue reported on code.google.com by kkroenl...@gmail.com on 8 Jul 2010 at 5:53

GoogleCodeExporter commented 9 years ago
This idea makes a lot of sense to me, too. Thank you for your very clear 
description of how you changed the GChart code to get the different kinds of 
axis transformations (actually, axis label transformations) that you required.

Contributions to GChart must be released under the the Apache 2.0 licence. 
Submitted code can only be included in GChart if its copyright owner has 
released it under Apache 2.0.

Assuming that requirement can be met, and that it tests as well as it looks on 
the page, I can't think of a good reason not to include this improvement in the 
next release.

Original comment by gchartco...@gmail.com on 8 Aug 2010 at 8:50

GoogleCodeExporter commented 9 years ago
The code published above is public domain, and I forfeit any rights I have as 
its author.

I look forward to seeing it incorporated into the next release.

Original comment by kkroenl...@gmail.com on 18 Aug 2010 at 10:11

GoogleCodeExporter commented 9 years ago
Thanks for getting back on the ownership issue. Appreciate your contribution to 
the project.

Original comment by gchartco...@gmail.com on 28 Aug 2010 at 9:00

GoogleCodeExporter commented 9 years ago

Original comment by gchartco...@gmail.com on 29 Aug 2010 at 9:56