[Kst] branches/work/kst/1.6/kst/src/extensions/js

Andrew Walker arwalker at sumusltd.com
Wed Oct 31 20:39:57 CET 2007


SVN commit 731464 by arwalker:

add binding to allow changing of y-axis normalization

 M  +60 -4     bind_histogram.cpp  
 M  +18 -4     bind_histogram.h  
 M  +8 -4      bind_powerspectrum.h  
 M  +4 -8      bindings.txt  


--- branches/work/kst/1.6/kst/src/extensions/js/bind_histogram.cpp #731463:731464
@@ -69,7 +69,7 @@
   unsigned bins = 60;
 
   KstVectorPtr v = extractVector(exec, args[0]);
-  
+
   if (!v) {
     KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
     exec->setException(eobj);
@@ -143,6 +143,7 @@
   { "yVector", 0L, &KstBindHistogram::yVector },
   { "xMin", 0L, &KstBindHistogram::xMin },
   { "xMax", 0L, &KstBindHistogram::xMax },
+  { "normalization", &KstBindHistogram::setNormalization, &KstBindHistogram::normalization },
   { 0L, 0L, 0L }
 };
 
@@ -205,7 +206,7 @@
       return (this->*histogramProperties[i].get)(exec);
     }
   }
-  
+
   return KstBindDataObject::get(exec, propertyName);
 }
 
@@ -261,6 +262,7 @@
 
 KJS::Value KstBindHistogram::realTimeAutoBin(KJS::ExecState *exec) const {
   Q_UNUSED(exec)
+
   KstHistogramPtr d = makeHistogram(_d);
   if (d) {
     KstReadLocker rl(d);
@@ -270,6 +272,62 @@
 }
 
 
+void KstBindHistogram::setNormalization(KJS::ExecState *exec, const KJS::Value& value) {
+  if (value.type() != KJS::NumberType) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return;
+  }
+  KstHistogramPtr d = makeHistogram(_d);
+  if (d) {
+    KstWriteLocker wl(d);
+    switch (value.toInt32(exec)) {
+      case KST_HS_NUMBER:
+        d->setIsNormNum();
+        d->setDirty();
+        break;
+      case KST_HS_PERCENT:
+        d->setIsNormPercent();
+        d->setDirty();
+        break;
+      case KST_HS_FRACTION:
+        d->setIsNormFraction();
+        d->setDirty();
+        break;
+      case KST_HS_MAX_ONE:
+        d->setIsNormOne();
+        d->setDirty();
+        break;
+      default:
+        KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+        exec->setException(eobj);
+        return;
+    }
+  }
+}
+
+
+KJS::Value KstBindHistogram::normalization(KJS::ExecState *exec) const {
+ Q_UNUSED(exec)
+
+  KstHistogramPtr d = makeHistogram(_d);
+  if (d) {
+    KstReadLocker rl(d);
+
+    if (d->isNormNum()) {
+      return KJS::Number(KST_HS_NUMBER);
+    } else if (d->isNormPercent()) {
+      return KJS::Number(KST_HS_PERCENT);
+    } else if (d->isNormFraction()) {
+      return KJS::Number(KST_HS_FRACTION);
+    } else if (d->isNormOne()) {
+      return KJS::Number(KST_HS_MAX_ONE);
+    }
+  }
+  return KJS::Number(-1);
+}
+
+
 void KstBindHistogram::setBins(KJS::ExecState *exec, const KJS::Value& value) {
   unsigned i = 0;
   if (value.type() != KJS::NumberType || !value.toUInt32(i)) {
@@ -398,7 +456,5 @@
   return KJS::Number(0);
 }
 
-
 #undef makeHistogram
 
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/extensions/js/bind_histogram.h #731463:731464
@@ -51,13 +51,12 @@
     KJS::ReferenceList propList(KJS::ExecState *exec, bool recursive = true);
     bool hasProperty(KJS::ExecState *exec, const KJS::Identifier& propertyName) const;
 
-    // member functions
-    
     /* @method setVector
        @arg Vector vector The vector for the histogram to operate on.
        @description Sets the input vector for the histogram.
     */
     KJS::Value setVector(KJS::ExecState *exec, const KJS::List& args);
+
     /* @method setRange
        @arg number from The starting X value.
        @arg number to The ending X value.
@@ -70,26 +69,43 @@
     */
     void setRealTimeAutoBin(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value realTimeAutoBin(KJS::ExecState *exec) const;
+
+    /* @property number normalization
+       @description Set the y-axis normalization.
+                    <ul>
+                    <li>0 - Number in bin</li>
+                    <li>1 - Percent in bin</li>
+                    <li>2 - Fraction in bin</li>
+                    <li>3 - Peak bin = 1.0</li>
+                    </ul>
+    */
+    void setNormalization(KJS::ExecState *exec, const KJS::Value& value);
+    KJS::Value normalization(KJS::ExecState *exec) const;
+
     /* @property number bins
        @description The number of bins for the histogram.
     */
     void setBins(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value bins(KJS::ExecState *exec) const;
+
     /* @property number xMin
        @readonly
        @description The minimum X value for the histogram.
     */
     KJS::Value xMin(KJS::ExecState *exec) const;
+
     /* @property number xMax
        @readonly
        @description The maximum X value for the histogram.
     */
     KJS::Value xMax(KJS::ExecState *exec) const;
+
     /* @property Vector xVector
        @readonly
        @description The X-axis vector generated by the histogram.
     */
     KJS::Value xVector(KJS::ExecState *exec) const;
+
     /* @property Vector yVector
        @readonly
        @description The Y-axis vector generated by the histogram.
@@ -102,7 +118,5 @@
     static KstBindDataObject *bindFactory(KJS::ExecState *exec, KstDataObjectPtr obj);
 };
 
-
 #endif
 
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/extensions/js/bind_powerspectrum.h #731463:731464
@@ -55,49 +55,55 @@
     KJS::ReferenceList propList(KJS::ExecState *exec, bool recursive = true);
     bool hasProperty(KJS::ExecState *exec, const KJS::Identifier& propertyName) const;
 
-    // member functions
-
     /* @property number length
        @description Contains the base 2 logarithm of the length of the power
                     spectrum.  Should be an integer &gt;= 4.
     */
     void setLength(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value length(KJS::ExecState *exec) const;
+
     /* @property boolean removeMean
        @description True if the mean should be removed before performing the
                     transform.
     */
     void setRemoveMean(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value removeMean(KJS::ExecState *exec) const;
+
     /* @property number average
     */
     void setAverage(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value average(KJS::ExecState *exec) const;
+
     /* @property boolean apodize
        @description If true, sharp discontinuities are removed.
     */
     void setApodize(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value apodize(KJS::ExecState *exec) const;
+
     /* @property number frequency
        @description Contains the sampling rate of the power spectrum.
     */
     void setFrequency(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value frequency(KJS::ExecState *exec) const;
+
     /* @property Vector xVector
        @readonly
        @description The X-axis vector for the power spectrum.
     */
     KJS::Value xVector(KJS::ExecState *exec) const;
+
     /* @property Vector yVector
        @readonly
        @description The Y-axi vector for the power spectrum.
     */
     KJS::Value yVector(KJS::ExecState *exec) const;
+
     /* @property string vUnits
        @description A string containing the units for the vector.
     */
     void setVUnits(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value vUnits(KJS::ExecState *exec) const;
+
     /* @property string rUnits
        @description A string containing the units for the rate.
     */
@@ -110,7 +116,5 @@
     static KstBindDataObject *bindFactory(KJS::ExecState *exec, KstDataObjectPtr obj);
 };
 
-
 #endif
 
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/extensions/js/bindings.txt #731463:731464
@@ -2,7 +2,7 @@
 Classes to be bound or created in JS:
 
 Kst		General Kst object (static global) - effectively "document"
-Debug		DONE (.log property unfinished)
+Debug		DONE
 Vector		DONE
 DataVector	DONE
 Scalar		DONE
@@ -19,8 +19,8 @@
 Fit
 Filter
 Plugin		DONE (needs work)
-Histogram	DONE (issue with the type of histogram remains)
-Curve		DONE (maybe still do some minX etc stuff)
+Histogram	DONE 
+Curve		DONE 
 Image		Name?
 Plot		DONE (needs many more functions/properties)
 Window		DONE (needs more functions/properties)
@@ -35,12 +35,8 @@
 -> Line		DONE
 -> Label	DONE
 -> Arrow	DONE
--> Polygon
--> ViewObjectGroup
--> ViewCurve       (Bezier, etc)
--> HTML            (Embedded KHTML)
+-> Group
 
-
 KstUIMerge
 	- Global object used to load XMLUI files for merging.
 	KstJSUIBuilder loadGUI(string filename);


More information about the Kst mailing list