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

George Staikos staikos at kde.org
Sat Jan 14 20:15:45 CET 2006


SVN commit 498130 by staikos:

add inner/outer ticks and grid color bindings


 M  +131 -0    bind_axis.cpp  
 M  +20 -0     bind_axis.h  


--- trunk/extragear/graphics/kst/kst/extensions/js/bind_axis.cpp #498129:498130
@@ -21,6 +21,7 @@
 #include <kstplotlabel.h>
 
 #include <kdebug.h>
+#include <kjsembed/jsbinding.h>
 
 KstBindAxis::KstBindAxis(KJS::ExecState *exec, Kst2DPlotPtr d, bool isX)
 : KstBinding("Axis", false), _d(d.data()), _xAxis(isX) {
@@ -65,6 +66,10 @@
   { "majorGridLines", &KstBindAxis::setMajorGridLines, &KstBindAxis::majorGridLines },
   { "minorGridLines", &KstBindAxis::setMinorGridLines, &KstBindAxis::minorGridLines },
   { "transformation", &KstBindAxis::setTransformation, &KstBindAxis::transformation },
+  { "innerTicks", &KstBindAxis::setInnerTicks, &KstBindAxis::innerTicks },
+  { "outerTicks", &KstBindAxis::setOuterTicks, &KstBindAxis::outerTicks },
+  { "majorGridColor", &KstBindAxis::setMajorGridColor, &KstBindAxis::majorGridColor },
+  { "minorGridColor", &KstBindAxis::setMinorGridColor, &KstBindAxis::minorGridColor },
   { "label", &KstBindAxis::setLabel, &KstBindAxis::label },
   { "type", 0L, &KstBindAxis::type },
   { 0L, 0L, 0L }
@@ -473,4 +478,130 @@
 }
 
 
+KJS::Value KstBindAxis::innerTicks(KJS::ExecState *exec) const {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  KstReadLocker rl(_d);
+  if (_xAxis) {
+    return KJS::Boolean(_d->xTicksInPlot());
+  } else {
+    return KJS::Boolean(_d->yTicksInPlot());
+  }
+}
+
+
+void KstBindAxis::setInnerTicks(KJS::ExecState *exec, const KJS::Value& value) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return;
+  }
+  if (value.type() != KJS::BooleanType) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return;
+  }
+  KstWriteLocker wl(_d);
+  if (_xAxis) {
+    _d->setXTicksInPlot(value.toBoolean(exec));
+  } else {
+    _d->setYTicksInPlot(value.toBoolean(exec));
+  }
+}
+
+
+KJS::Value KstBindAxis::outerTicks(KJS::ExecState *exec) const {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  KstReadLocker rl(_d);
+  if (_xAxis) {
+    return KJS::Boolean(_d->xTicksOutPlot());
+  } else {
+    return KJS::Boolean(_d->yTicksOutPlot());
+  }
+}
+
+
+void KstBindAxis::setOuterTicks(KJS::ExecState *exec, const KJS::Value& value) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return;
+  }
+  if (value.type() != KJS::BooleanType) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return;
+  }
+  KstWriteLocker wl(_d);
+  if (_xAxis) {
+    _d->setXTicksOutPlot(value.toBoolean(exec));
+  } else {
+    _d->setYTicksOutPlot(value.toBoolean(exec));
+  }
+}
+
+
+KJS::Value KstBindAxis::majorGridColor(KJS::ExecState *exec) const {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  KstReadLocker rl(_d);
+  return KJSEmbed::convertToValue(exec, _d->majorGridColor());
+}
+
+
+void KstBindAxis::setMajorGridColor(KJS::ExecState *exec, const KJS::Value& value) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return;
+  }
+  QVariant cv = KJSEmbed::convertToVariant(exec, value);
+  if (!cv.canCast(QVariant::Color)) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return;
+  }
+  KstWriteLocker rl(_d);
+  _d->setGridLinesColor(cv.toColor(), _d->minorGridColor(), false, _d->defaultMinorGridColor());
+}
+
+
+KJS::Value KstBindAxis::minorGridColor(KJS::ExecState *exec) const {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  KstReadLocker rl(_d);
+  return KJSEmbed::convertToValue(exec, _d->minorGridColor());
+}
+
+
+void KstBindAxis::setMinorGridColor(KJS::ExecState *exec, const KJS::Value& value) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return;
+  }
+  QVariant cv = KJSEmbed::convertToVariant(exec, value);
+  if (!cv.canCast(QVariant::Color)) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return;
+  }
+  KstWriteLocker rl(_d);
+  _d->setGridLinesColor(_d->majorGridColor(), cv.toColor(), _d->defaultMajorGridColor(), false);
+}
+
+
 // vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/kst/extensions/js/bind_axis.h #498129:498130
@@ -84,6 +84,16 @@
     */
     void setTransformation(KJS::ExecState *exec, const KJS::Value& value);
     KJS::Value transformation(KJS::ExecState *exec) const;
+    /* @property boolean innerTicks
+       @description True if tick marks are displayed inside the plot.
+    */
+    void setInnerTicks(KJS::ExecState *exec, const KJS::Value& value);
+    KJS::Value innerTicks(KJS::ExecState *exec) const;
+    /* @property boolean outerTicks
+       @description True if tick marks are displayed outside the plot.
+    */
+    void setOuterTicks(KJS::ExecState *exec, const KJS::Value& value);
+    KJS::Value outerTicks(KJS::ExecState *exec) const;
     /* @property string label
        @description The label for this axis.
     */
@@ -94,6 +104,16 @@
        @description The type of axis - X or Y presently.
     */
     KJS::Value type(KJS::ExecState *exec) const;
+    /* @property string majorGridColor
+       @description The color for the major grid lines.
+     */
+    void setMajorGridColor(KJS::ExecState *exec, const KJS::Value& value);
+    KJS::Value majorGridColor(KJS::ExecState *exec) const;
+    /* @property string minorGridColor
+       @description The color for the minor grid lines.
+     */
+    void setMinorGridColor(KJS::ExecState *exec, const KJS::Value& value);
+    KJS::Value minorGridColor(KJS::ExecState *exec) const;
 
   protected:
     KstBindAxis(int id);


More information about the Kst mailing list