[Kst] extragear/graphics/kst/kst/extensions/js

George Staikos staikos at kde.org
Mon Jan 16 19:03:00 CET 2006


SVN commit 498951 by staikos:

add the scale modes


 M  +130 -0    bind_axis.cpp  
 M  +35 -0     bind_axis.h  


--- trunk/extragear/graphics/kst/kst/extensions/js/bind_axis.cpp #498950:498951
@@ -53,6 +53,10 @@
 
 
 static AxisBindings axisBindings[] = {
+  { "scaleAuto", &KstBindAxis::scaleAuto },
+  { "scaleAutoSpikeInsensitive", &KstBindAxis::scaleAutoSpikeInsensitive },
+  { "scaleExpression", &KstBindAxis::scaleExpression },
+  { "scaleRange", &KstBindAxis::scaleRange },
   { 0L, 0L }
 };
 
@@ -72,6 +76,7 @@
   { "minorGridColor", &KstBindAxis::setMinorGridColor, &KstBindAxis::minorGridColor },
   { "minorTickCount", &KstBindAxis::setMinorTickCount, &KstBindAxis::minorTickCount },
   { "majorTickDensity", &KstBindAxis::setMajorTickDensity, &KstBindAxis::majorTickDensity },
+  { "scaleMode", 0L, &KstBindAxis::scaleMode },
   { "label", &KstBindAxis::setLabel, &KstBindAxis::label },
   { "type", 0L, &KstBindAxis::type },
   { 0L, 0L, 0L }
@@ -716,4 +721,129 @@
 }
 
 
+KJS::Value KstBindAxis::scaleMode(KJS::ExecState *exec) const {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  KstReadLocker rl(_d);
+  KstScaleModeType i;
+  if (_xAxis) {
+    i = _d->xScaleMode();
+  } else {
+    i = _d->yScaleMode();
+  }
+  return KJS::Number(i);
+}
+
+
+KJS::Value KstBindAxis::scaleAuto(KJS::ExecState *exec, const KJS::List& args) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  if (args.size() != 0) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly zero arguments.");
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  KstWriteLocker rl(_d);
+  if (_xAxis) {
+    _d->setXScaleMode(AUTO);
+  } else {
+    _d->setYScaleMode(AUTO);
+  }
+  return KJS::Undefined();
+}
+
+
+KJS::Value KstBindAxis::scaleAutoSpikeInsensitive(KJS::ExecState *exec, const KJS::List& args) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  if (args.size() != 0) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly zero arguments.");
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  KstWriteLocker rl(_d);
+  if (_xAxis) {
+    _d->setXScaleMode(NOSPIKE);
+  } else {
+    _d->setYScaleMode(NOSPIKE);
+  }
+  return KJS::Undefined();
+}
+
+
+KJS::Value KstBindAxis::scaleExpression(KJS::ExecState *exec, const KJS::List& args) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  if (args.size() != 2) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly two arguments.");
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  if (args[0].type() != KJS::StringType || args[1].type() != KJS::StringType) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  KstWriteLocker rl(_d);
+  if (_xAxis) {
+    _d->setXScaleMode(EXPRESSION);
+    _d->setXExpressions(args[0].toString(exec).qstring(), args[1].toString(exec).qstring());
+  } else {
+    _d->setYScaleMode(EXPRESSION);
+    _d->setYExpressions(args[0].toString(exec).qstring(), args[1].toString(exec).qstring());
+  }
+  return KJS::Undefined();
+}
+
+
+KJS::Value KstBindAxis::scaleRange(KJS::ExecState *exec, const KJS::List& args) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  if (args.size() != 2) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly two arguments.");
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  if (args[0].type() != KJS::NumberType || args[1].type() != KJS::NumberType) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  KstWriteLocker rl(_d);
+  if (_xAxis) {
+    _d->setXScaleMode(FIXED);
+    _d->setXScale(args[0].toNumber(exec), args[1].toNumber(exec));
+  } else {
+    _d->setYScaleMode(FIXED);
+    _d->setYScale(args[0].toNumber(exec), args[1].toNumber(exec));
+  }
+  return KJS::Undefined();
+}
+
+
 // vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/kst/extensions/js/bind_axis.h #498950:498951
@@ -42,6 +42,26 @@
     bool hasProperty(KJS::ExecState *exec, const KJS::Identifier& propertyName) const;
 
     // member functions
+    /* @method scaleAuto
+       @description Sets the scale mode to Auto.
+    */
+    KJS::Value scaleAuto(KJS::ExecState *exec, const KJS::List& args);
+    /* @method scaleAutoSpikeInsensitive
+       @description Sets the scale mode to Auto Spike Insensitive.
+    */
+    KJS::Value scaleAutoSpikeInsensitive(KJS::ExecState *exec, const KJS::List& args);
+    /* @method scaleExpression
+       @description Sets the scale mode to Expression.
+       @arg string minExp The expression for the minimum of the scale.
+       @arg string maxExp The expression for the maximum of the scale.
+    */
+    KJS::Value scaleExpression(KJS::ExecState *exec, const KJS::List& args);
+    /* @method scaleRange
+       @description Sets the scale mode to Fixed and sets the range.
+       @arg string min The value for the minimum of the scale.
+       @arg string max The value for the maximum of the scale.
+    */
+    KJS::Value scaleRange(KJS::ExecState *exec, const KJS::List& args);
 
     // properties
     /* @property boolean log
@@ -132,6 +152,21 @@
      */
     void setMajorTickDensity(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value majorTickDensity(KJS::ExecState *exec) const;
+    /* @property number scaleMode
+       @readonly
+       @description The type of scaling done on the axis.
+                    Value is one of:
+                    <ul>
+                    <li>0 - Auto</li>
+                    <li>1 - All Curves (By Midpoint)</li>
+                    <li>2 - Fixed</li>
+                    <li>3 - Auto Up (Only Scales Upward)</li>
+                    <li>4 - Auto (Spike Insensitive)</li>
+                    <li>5 - Auto (obsolete, same as 0)</li>
+                    <li>6 - Expression Based</li>
+                    </ul>
+     */
+    KJS::Value scaleMode(KJS::ExecState *exec) const;
 
   protected:
     KstBindAxis(int id);


More information about the Kst mailing list