home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / borland / ib / setups / intrabld / data.z / CHART.CC < prev    next >
Text File  |  1996-12-11  |  5KB  |  145 lines

  1. /****************************************************************************\
  2. *                                                                            *
  3. * Chart.cc  --  Custom Charting Controls                                     *
  4. *                                                                            *
  5. * Chart.cc contains a custom ActiveX chart control and a custom JavaApplet   *
  6. * chart control. These controls both have an Init() method that is used to   *
  7. * identify the fields that are used for the label and the data and the       *
  8. * rowset where data is located. See the Java.jfm and the ActiveX.jfm for     *
  9. * examples of using these controls.                                          *
  10. *                                                                            *
  11. * Dependencies:  http://java.sun.com/applets/applets/BarChart/chart.class    *
  12. *                                                                            *
  13. * Updated 11/09/96 by IntraBuilder Samples Group                             *
  14. * $Revision:   1.0  $                                                        *
  15. *                                                                            *
  16. * Copyright (c) 1996, Borland International, Inc. All rights reserved.       *
  17. \****************************************************************************/
  18. class ActiveXChartQuery(FormObj) extends ActiveX(FormObj) custom {
  19.    with (this) {
  20.       height = 10;
  21.       width = 62;
  22.       classId = "clsid:FC25B780-75BE-11CF-8B01-444553540000";
  23.       params["ChartType"] = "8";
  24.    }
  25.  
  26.    function Init(keyField, valueField, rowset)
  27.    {
  28.       this.keyField = keyField;
  29.       this.valueField = valueField;
  30.       this.rowset = rowset;
  31.    }
  32.  
  33.    function onServerLoad()
  34.    {
  35.       var rowCount = 0;
  36.       var rowNames = "";
  37.       var data = this.rowset;
  38.       data.first();
  39.       while (!data.endOfSet) {
  40.           
  41.           
  42.          this.params["data[" + rowCount + "]"] = "" + data.fields[this.valueField].value;
  43.  
  44.          var name = data.fields[this.keyField].value;
  45.          while ((pos = name.indexOf(" ")) > 0)
  46.             name = name.substring(0,pos) + "_" + name.substring(pos+1,name.length);
  47.          if (name.length == 0)
  48.             name = "Other";
  49.           
  50.          rowNames += (name + " ");
  51.          rowCount++
  52.           
  53.          data.next();
  54.       }
  55.       this.params["Rows"] = "" + rowCount;
  56.       this.params["RowNames"] = rowNames;
  57.        
  58.    }
  59.  
  60.  
  61. }
  62.  
  63. class JavaChartQuery(FormObj) extends JavaApplet(FormObj) custom {
  64.    with (this) {
  65.       height = 24;
  66.       width = 90;
  67.       code = "Chart.class";
  68.       codeBase = "http://java.sun.com/applets/applets/BarChart/";
  69.       params["orientation"] = "horizontal";
  70.    }
  71.  
  72.    function Init(keyField, valueField, rowset)
  73.    {
  74.       this.keyField = keyField;
  75.       this.valueField = valueField;
  76.       this.rowset = rowset;
  77.       this.colors = {"pink","red","orange","yellow","green","cyan","blue","magenta","white"}
  78.    }
  79.  
  80.    function onServerLoad()
  81.    {
  82.       var rowCount = 0,
  83.           largest = 0,
  84.           magnitude = 0;
  85.  
  86.       var data = this.rowset;
  87.       data.first();
  88.       while (!data.endOfSet) {
  89.          rowCount++
  90.          var name = data.fields[this.keyField].value;
  91.          var sumTotal = data.fields[this.valueField].value;
  92.          if (name.length == 0)
  93.             name = "Other";
  94.  
  95.          this.params["c" + rowCount]            = sumTotal;
  96.          this.params["c" + rowCount + "_label"] = name;
  97.          this.params["c" + rowCount + "_style"] = "solid";
  98.          this.params["c" + rowCount + "_color"] = this.colors[rowCount%this.colors.length]
  99.          largest = (sumTotal > largest ? sumTotal : largest);
  100.  
  101.          data.next();
  102.       }
  103.       this.params["columns"] = "" + parseInt(rowCount);
  104.       //
  105.       // calculate the magnitude of largest value
  106.       //
  107.       while (largest > 400) {
  108.          magnitude++;
  109.          largest /= 10;
  110.       }
  111.       // set the title to show the scale
  112.       this.params["title"] = "Each unit represents 1" + new StringEx().replicate("0",magnitude);
  113.       //
  114.       // recalculate the values based on magnitude or largest value
  115.       //
  116.       magnitude = Math.pow(10,magnitude);
  117.       for (var i = 1; i<=rowCount; i++) {
  118.          this.params["c" + i] = "" + parseInt(this.params["c"+i]/magnitude);
  119.       }
  120.       //
  121.       // Set the scale param to make maximum use of this area
  122.       if (largest <= 45)
  123.          this.params["scale"] = "10";
  124.       else if (largest <= 50)
  125.          this.params["scale"] = "9";
  126.       else if (largest <= 55)
  127.          this.params["scale"] = "8";
  128.       else if (largest <= 65)
  129.          this.params["scale"] = "7";
  130.       else if (largest <= 70)
  131.          this.params["scale"] = "6";
  132.       else if (largest <= 85)
  133.          this.params["scale"] = "5";
  134.       else if (largest <= 105)
  135.          this.params["scale"] = "4";
  136.       else if (largest <= 140)
  137.          this.params["scale"] = "3";
  138.       else if (largest <= 210)
  139.          this.params["scale"] = "2";
  140.       else
  141.          this.params["scale"] = "1";
  142.    }
  143. }
  144.  
  145.