~ubuntu-branches/ubuntu/karmic/kst/karmic

« back to all changes in this revision

Viewing changes to kst/kst/extensions/js/bind_axis.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-06-30 19:11:30 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630191130-acumuar75bz4puty
Tags: 1.2.1-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                                bind_axis.cpp
 
3
                             -------------------
 
4
    begin                : Jan 13 2006
 
5
    copyright            : (C) 2006 The University of Toronto
 
6
    email                :
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#include "bind_axis.h"
 
19
#include "bind_timeinterpretation.h"
 
20
 
 
21
#include <kst.h>
 
22
#include <kstdatacollection.h>
 
23
#include <kstplotlabel.h>
 
24
 
 
25
#include <kdebug.h>
 
26
#include <kjsembed/jsbinding.h>
 
27
 
 
28
KstBindAxis::KstBindAxis(KJS::ExecState *exec, Kst2DPlotPtr d, bool isX)
 
29
: QObject(), KstBinding("Axis", false), _d(d.data()), _xAxis(isX) {
 
30
  KJS::Object o(this);
 
31
  addBindings(exec, o);
 
32
}
 
33
 
 
34
 
 
35
KstBindAxis::KstBindAxis(int id)
 
36
: QObject(), KstBinding("Axis Method", id) {
 
37
}
 
38
 
 
39
 
 
40
KstBindAxis::~KstBindAxis() {
 
41
}
 
42
 
 
43
 
 
44
struct AxisBindings {
 
45
  const char *name;
 
46
  KJS::Value (KstBindAxis::*method)(KJS::ExecState*, const KJS::List&);
 
47
};
 
48
 
 
49
 
 
50
struct AxisProperties {
 
51
  const char *name;
 
52
  void (KstBindAxis::*set)(KJS::ExecState*, const KJS::Value&);
 
53
  KJS::Value (KstBindAxis::*get)(KJS::ExecState*) const;
 
54
};
 
55
 
 
56
 
 
57
static AxisBindings axisBindings[] = {
 
58
  { "scaleAuto", &KstBindAxis::scaleAuto },
 
59
  { "scaleAutoSpikeInsensitive", &KstBindAxis::scaleAutoSpikeInsensitive },
 
60
  { "scaleExpression", &KstBindAxis::scaleExpression },
 
61
  { "scaleRange", &KstBindAxis::scaleRange },
 
62
  { 0L, 0L }
 
63
};
 
64
 
 
65
 
 
66
static AxisProperties axisProperties[] = {
 
67
  { "log", &KstBindAxis::setLog, &KstBindAxis::log },
 
68
  { "suppressed", &KstBindAxis::setSuppressed, &KstBindAxis::suppressed },
 
69
  { "oppositeSuppressed", &KstBindAxis::setOppositeSuppressed, &KstBindAxis::oppositeSuppressed },
 
70
  { "offsetMode", &KstBindAxis::setOffsetMode, &KstBindAxis::offsetMode },
 
71
  { "reversed", &KstBindAxis::setReversed, &KstBindAxis::reversed },
 
72
  { "majorGridLines", &KstBindAxis::setMajorGridLines, &KstBindAxis::majorGridLines },
 
73
  { "minorGridLines", &KstBindAxis::setMinorGridLines, &KstBindAxis::minorGridLines },
 
74
  { "transformation", &KstBindAxis::setTransformation, &KstBindAxis::transformation },
 
75
  { "innerTicks", &KstBindAxis::setInnerTicks, &KstBindAxis::innerTicks },
 
76
  { "outerTicks", &KstBindAxis::setOuterTicks, &KstBindAxis::outerTicks },
 
77
  { "majorGridColor", &KstBindAxis::setMajorGridColor, &KstBindAxis::majorGridColor },
 
78
  { "minorGridColor", &KstBindAxis::setMinorGridColor, &KstBindAxis::minorGridColor },
 
79
  { "minorTickCount", &KstBindAxis::setMinorTickCount, &KstBindAxis::minorTickCount },
 
80
  { "majorTickDensity", &KstBindAxis::setMajorTickDensity, &KstBindAxis::majorTickDensity },
 
81
  { "scaleMode", 0L, &KstBindAxis::scaleMode },
 
82
  { "label", &KstBindAxis::setLabel, &KstBindAxis::label },
 
83
  { "type", 0L, &KstBindAxis::type },
 
84
  { "interpretation", 0L, &KstBindAxis::interpretation },
 
85
  { 0L, 0L, 0L }
 
86
};
 
87
 
 
88
 
 
89
KJS::ReferenceList KstBindAxis::propList(KJS::ExecState *exec, bool recursive) {
 
90
  KJS::ReferenceList rc = KstBinding::propList(exec, recursive);
 
91
 
 
92
  for (int i = 0; axisProperties[i].name; ++i) {
 
93
    rc.append(KJS::Reference(this, KJS::Identifier(axisProperties[i].name)));
 
94
  }
 
95
 
 
96
  return rc;
 
97
}
 
98
 
 
99
 
 
100
bool KstBindAxis::hasProperty(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
 
101
  QString prop = propertyName.qstring();
 
102
  for (int i = 0; axisProperties[i].name; ++i) {
 
103
    if (prop == axisProperties[i].name) {
 
104
      return true;
 
105
    }
 
106
  }
 
107
 
 
108
  return KstBinding::hasProperty(exec, propertyName);
 
109
}
 
110
 
 
111
 
 
112
void KstBindAxis::put(KJS::ExecState *exec, const KJS::Identifier& propertyName, const KJS::Value& value, int attr) {
 
113
  QString prop = propertyName.qstring();
 
114
  for (int i = 0; axisProperties[i].name; ++i) {
 
115
    if (prop == axisProperties[i].name) {
 
116
      if (!axisProperties[i].set) {
 
117
        break;
 
118
      }
 
119
      (this->*axisProperties[i].set)(exec, value);
 
120
      return;
 
121
    }
 
122
  }
 
123
 
 
124
  KstBinding::put(exec, propertyName, value, attr);
 
125
}
 
126
 
 
127
 
 
128
KJS::Value KstBindAxis::get(KJS::ExecState *exec, const KJS::Identifier& propertyName) const {
 
129
  QString prop = propertyName.qstring();
 
130
  for (int i = 0; axisProperties[i].name; ++i) {
 
131
    if (prop == axisProperties[i].name) {
 
132
      if (!axisProperties[i].get) {
 
133
        break;
 
134
      }
 
135
      return (this->*axisProperties[i].get)(exec);
 
136
    }
 
137
  }
 
138
  
 
139
  return KstBinding::get(exec, propertyName);
 
140
}
 
141
 
 
142
 
 
143
KJS::Value KstBindAxis::call(KJS::ExecState *exec, KJS::Object& self, const KJS::List& args) {
 
144
  int id = this->id();
 
145
  if (id <= 0) {
 
146
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
147
    exec->setException(eobj);
 
148
    return KJS::Undefined();
 
149
  }
 
150
 
 
151
  KstBindAxis *imp = dynamic_cast<KstBindAxis*>(self.imp());
 
152
  if (!imp) {
 
153
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
154
    exec->setException(eobj);
 
155
    return KJS::Undefined();
 
156
  }
 
157
 
 
158
  return (imp->*axisBindings[id - 1].method)(exec, args);
 
159
}
 
160
 
 
161
 
 
162
void KstBindAxis::addBindings(KJS::ExecState *exec, KJS::Object& obj) {
 
163
  for (int i = 0; axisBindings[i].name != 0L; ++i) {
 
164
    KJS::Object o = KJS::Object(new KstBindAxis(i + 1));
 
165
    obj.put(exec, axisBindings[i].name, o, KJS::Function);
 
166
  }
 
167
}
 
168
 
 
169
 
 
170
KJS::Value KstBindAxis::type(KJS::ExecState *exec) const {
 
171
  Q_UNUSED(exec)
 
172
  return KJS::String(_xAxis ? "X" : "Y");
 
173
}
 
174
 
 
175
 
 
176
KJS::Value KstBindAxis::label(KJS::ExecState *exec) const {
 
177
  if (!_d) {
 
178
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
179
    exec->setException(eobj);
 
180
    return KJS::Undefined();
 
181
  }
 
182
  KstReadLocker rl(_d);
 
183
  if (_xAxis) {
 
184
    return KJS::String(_d->xLabel()->text());
 
185
  } else {
 
186
    return KJS::String(_d->yLabel()->text());
 
187
  }
 
188
}
 
189
 
 
190
 
 
191
void KstBindAxis::setLabel(KJS::ExecState *exec, const KJS::Value& value) {
 
192
  if (!_d) {
 
193
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
194
    exec->setException(eobj);
 
195
    return;
 
196
  }
 
197
  if (value.type() != KJS::StringType) {
 
198
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
199
    exec->setException(eobj);
 
200
    return;
 
201
  }
 
202
  KstWriteLocker wl(_d);
 
203
  if (_xAxis) {
 
204
    _d->xLabel()->setText(value.toString(exec).qstring());
 
205
  } else {
 
206
    _d->yLabel()->setText(value.toString(exec).qstring());
 
207
  }
 
208
  _d->setDirty();
 
209
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
210
}
 
211
 
 
212
 
 
213
KJS::Value KstBindAxis::transformation(KJS::ExecState *exec) const {
 
214
  if (!_d) {
 
215
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
216
    exec->setException(eobj);
 
217
    return KJS::Undefined();
 
218
  }
 
219
  KstReadLocker rl(_d);
 
220
  if (_xAxis) {
 
221
    return KJS::String(_d->xTransformedExp());
 
222
  } else {
 
223
    return KJS::String(_d->yTransformedExp());
 
224
  }
 
225
}
 
226
 
 
227
 
 
228
void KstBindAxis::setTransformation(KJS::ExecState *exec, const KJS::Value& value) {
 
229
  if (!_d) {
 
230
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
231
    exec->setException(eobj);
 
232
    return;
 
233
  }
 
234
  if (value.type() != KJS::StringType) {
 
235
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
236
    exec->setException(eobj);
 
237
    return;
 
238
  }
 
239
  KstWriteLocker wl(_d);
 
240
  if (_xAxis) {
 
241
    _d->setXTransformedExp(value.toString(exec).qstring());
 
242
  } else {
 
243
    _d->setYTransformedExp(value.toString(exec).qstring());
 
244
  }
 
245
  _d->setDirty();
 
246
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
247
}
 
248
 
 
249
 
 
250
KJS::Value KstBindAxis::log(KJS::ExecState *exec) const {
 
251
  if (!_d) {
 
252
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
253
    exec->setException(eobj);
 
254
    return KJS::Undefined();
 
255
  }
 
256
  KstReadLocker rl(_d);
 
257
  if (_xAxis) {
 
258
    return KJS::Boolean(_d->isXLog());
 
259
  } else {
 
260
    return KJS::Boolean(_d->isYLog());
 
261
  }
 
262
}
 
263
 
 
264
 
 
265
void KstBindAxis::setLog(KJS::ExecState *exec, const KJS::Value& value) {
 
266
  if (!_d) {
 
267
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
268
    exec->setException(eobj);
 
269
    return;
 
270
  }
 
271
  if (value.type() != KJS::BooleanType) {
 
272
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
273
    exec->setException(eobj);
 
274
    return;
 
275
  }
 
276
  KstWriteLocker wl(_d);
 
277
  if (_xAxis) {
 
278
    _d->setLog(value.toBoolean(exec), _d->isYLog());
 
279
  } else {
 
280
    _d->setLog(_d->isXLog(), value.toBoolean(exec));
 
281
  }
 
282
  _d->setDirty();
 
283
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
284
}
 
285
 
 
286
 
 
287
KJS::Value KstBindAxis::majorGridLines(KJS::ExecState *exec) const {
 
288
  if (!_d) {
 
289
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
290
    exec->setException(eobj);
 
291
    return KJS::Undefined();
 
292
  }
 
293
  KstReadLocker rl(_d);
 
294
  if (_xAxis) {
 
295
    return KJS::Boolean(_d->hasXMajorGrid());
 
296
  } else {
 
297
    return KJS::Boolean(_d->hasYMajorGrid());
 
298
  }
 
299
}
 
300
 
 
301
 
 
302
void KstBindAxis::setMajorGridLines(KJS::ExecState *exec, const KJS::Value& value) {
 
303
  if (!_d) {
 
304
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
305
    exec->setException(eobj);
 
306
    return;
 
307
  }
 
308
  if (value.type() != KJS::BooleanType) {
 
309
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
310
    exec->setException(eobj);
 
311
    return;
 
312
  }
 
313
  KstWriteLocker wl(_d);
 
314
  if (_xAxis) {
 
315
    _d->setXGridLines(value.toBoolean(exec), _d->hasXMinorGrid());
 
316
  } else {
 
317
    _d->setYGridLines(value.toBoolean(exec), _d->hasYMinorGrid());
 
318
  }
 
319
  _d->setDirty();
 
320
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
321
}
 
322
 
 
323
 
 
324
KJS::Value KstBindAxis::minorGridLines(KJS::ExecState *exec) const {
 
325
  if (!_d) {
 
326
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
327
    exec->setException(eobj);
 
328
    return KJS::Undefined();
 
329
  }
 
330
  KstReadLocker rl(_d);
 
331
  if (_xAxis) {
 
332
    return KJS::Boolean(_d->hasXMinorGrid());
 
333
  } else {
 
334
    return KJS::Boolean(_d->hasYMinorGrid());
 
335
  }
 
336
}
 
337
 
 
338
 
 
339
void KstBindAxis::setMinorGridLines(KJS::ExecState *exec, const KJS::Value& value) {
 
340
  if (!_d) {
 
341
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
342
    exec->setException(eobj);
 
343
    return;
 
344
  }
 
345
  if (value.type() != KJS::BooleanType) {
 
346
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
347
    exec->setException(eobj);
 
348
    return;
 
349
  }
 
350
  KstWriteLocker wl(_d);
 
351
  if (_xAxis) {
 
352
    _d->setXGridLines(_d->hasXMajorGrid(), value.toBoolean(exec));
 
353
  } else {
 
354
    _d->setYGridLines(_d->hasYMajorGrid(), value.toBoolean(exec));
 
355
  }
 
356
  _d->setDirty();
 
357
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
358
}
 
359
 
 
360
 
 
361
KJS::Value KstBindAxis::reversed(KJS::ExecState *exec) const {
 
362
  if (!_d) {
 
363
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
364
    exec->setException(eobj);
 
365
    return KJS::Undefined();
 
366
  }
 
367
  KstReadLocker rl(_d);
 
368
  if (_xAxis) {
 
369
    return KJS::Boolean(_d->xReversed());
 
370
  } else {
 
371
    return KJS::Boolean(_d->yReversed());
 
372
  }
 
373
}
 
374
 
 
375
 
 
376
void KstBindAxis::setReversed(KJS::ExecState *exec, const KJS::Value& value) {
 
377
  if (!_d) {
 
378
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
379
    exec->setException(eobj);
 
380
    return;
 
381
  }
 
382
  if (value.type() != KJS::BooleanType) {
 
383
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
384
    exec->setException(eobj);
 
385
    return;
 
386
  }
 
387
  KstWriteLocker wl(_d);
 
388
  if (_xAxis) {
 
389
    _d->setXReversed(value.toBoolean(exec));
 
390
  } else {
 
391
    _d->setYReversed(value.toBoolean(exec));
 
392
  }
 
393
  _d->setDirty();
 
394
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
395
}
 
396
 
 
397
 
 
398
KJS::Value KstBindAxis::offsetMode(KJS::ExecState *exec) const {
 
399
  if (!_d) {
 
400
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
401
    exec->setException(eobj);
 
402
    return KJS::Undefined();
 
403
  }
 
404
  KstReadLocker rl(_d);
 
405
  if (_xAxis) {
 
406
    return KJS::Boolean(_d->xOffsetMode());
 
407
  } else {
 
408
    return KJS::Boolean(_d->yOffsetMode());
 
409
  }
 
410
}
 
411
 
 
412
 
 
413
void KstBindAxis::setOffsetMode(KJS::ExecState *exec, const KJS::Value& value) {
 
414
  if (!_d) {
 
415
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
416
    exec->setException(eobj);
 
417
    return;
 
418
  }
 
419
  if (value.type() != KJS::BooleanType) {
 
420
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
421
    exec->setException(eobj);
 
422
    return;
 
423
  }
 
424
  KstWriteLocker wl(_d);
 
425
  if (_xAxis) {
 
426
    _d->setXOffsetMode(value.toBoolean(exec));
 
427
  } else {
 
428
    _d->setYOffsetMode(value.toBoolean(exec));
 
429
  }
 
430
  _d->setDirty();
 
431
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
432
}
 
433
 
 
434
 
 
435
KJS::Value KstBindAxis::suppressed(KJS::ExecState *exec) const {
 
436
  if (!_d) {
 
437
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
438
    exec->setException(eobj);
 
439
    return KJS::Undefined();
 
440
  }
 
441
  KstReadLocker rl(_d);
 
442
  if (_xAxis) {
 
443
    return KJS::Boolean(_d->suppressBottom());
 
444
  } else {
 
445
    return KJS::Boolean(_d->suppressLeft());
 
446
  }
 
447
}
 
448
 
 
449
 
 
450
void KstBindAxis::setSuppressed(KJS::ExecState *exec, const KJS::Value& value) {
 
451
  if (!_d) {
 
452
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
453
    exec->setException(eobj);
 
454
    return;
 
455
  }
 
456
  if (value.type() != KJS::BooleanType) {
 
457
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
458
    exec->setException(eobj);
 
459
    return;
 
460
  }
 
461
  KstWriteLocker wl(_d);
 
462
  if (_xAxis) {
 
463
    _d->setSuppressBottom(value.toBoolean(exec));
 
464
  } else {
 
465
    _d->setSuppressLeft(value.toBoolean(exec));
 
466
  }
 
467
  _d->setDirty();
 
468
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
469
}
 
470
 
 
471
 
 
472
KJS::Value KstBindAxis::oppositeSuppressed(KJS::ExecState *exec) const {
 
473
  if (!_d) {
 
474
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
475
    exec->setException(eobj);
 
476
    return KJS::Undefined();
 
477
  }
 
478
  KstReadLocker rl(_d);
 
479
  if (_xAxis) {
 
480
    return KJS::Boolean(_d->suppressTop());
 
481
  } else {
 
482
    return KJS::Boolean(_d->suppressRight());
 
483
  }
 
484
}
 
485
 
 
486
 
 
487
void KstBindAxis::setOppositeSuppressed(KJS::ExecState *exec, const KJS::Value& value) {
 
488
  if (!_d) {
 
489
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
490
    exec->setException(eobj);
 
491
    return;
 
492
  }
 
493
  if (value.type() != KJS::BooleanType) {
 
494
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
495
    exec->setException(eobj);
 
496
    return;
 
497
  }
 
498
  KstWriteLocker wl(_d);
 
499
  if (_xAxis) {
 
500
    _d->setSuppressTop(value.toBoolean(exec));
 
501
  } else {
 
502
    _d->setSuppressRight(value.toBoolean(exec));
 
503
  }
 
504
  _d->setDirty();
 
505
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
506
}
 
507
 
 
508
 
 
509
KJS::Value KstBindAxis::innerTicks(KJS::ExecState *exec) const {
 
510
  if (!_d) {
 
511
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
512
    exec->setException(eobj);
 
513
    return KJS::Undefined();
 
514
  }
 
515
  KstReadLocker rl(_d);
 
516
  if (_xAxis) {
 
517
    return KJS::Boolean(_d->xTicksInPlot());
 
518
  } else {
 
519
    return KJS::Boolean(_d->yTicksInPlot());
 
520
  }
 
521
}
 
522
 
 
523
 
 
524
void KstBindAxis::setInnerTicks(KJS::ExecState *exec, const KJS::Value& value) {
 
525
  if (!_d) {
 
526
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
527
    exec->setException(eobj);
 
528
    return;
 
529
  }
 
530
  if (value.type() != KJS::BooleanType) {
 
531
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
532
    exec->setException(eobj);
 
533
    return;
 
534
  }
 
535
  KstWriteLocker wl(_d);
 
536
  if (_xAxis) {
 
537
    _d->setXTicksInPlot(value.toBoolean(exec));
 
538
  } else {
 
539
    _d->setYTicksInPlot(value.toBoolean(exec));
 
540
  }
 
541
  _d->setDirty();
 
542
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
543
}
 
544
 
 
545
 
 
546
KJS::Value KstBindAxis::outerTicks(KJS::ExecState *exec) const {
 
547
  if (!_d) {
 
548
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
549
    exec->setException(eobj);
 
550
    return KJS::Undefined();
 
551
  }
 
552
  KstReadLocker rl(_d);
 
553
  if (_xAxis) {
 
554
    return KJS::Boolean(_d->xTicksOutPlot());
 
555
  } else {
 
556
    return KJS::Boolean(_d->yTicksOutPlot());
 
557
  }
 
558
}
 
559
 
 
560
 
 
561
void KstBindAxis::setOuterTicks(KJS::ExecState *exec, const KJS::Value& value) {
 
562
  if (!_d) {
 
563
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
564
    exec->setException(eobj);
 
565
    return;
 
566
  }
 
567
  if (value.type() != KJS::BooleanType) {
 
568
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
569
    exec->setException(eobj);
 
570
    return;
 
571
  }
 
572
  KstWriteLocker wl(_d);
 
573
  if (_xAxis) {
 
574
    _d->setXTicksOutPlot(value.toBoolean(exec));
 
575
  } else {
 
576
    _d->setYTicksOutPlot(value.toBoolean(exec));
 
577
  }
 
578
  _d->setDirty();
 
579
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
580
}
 
581
 
 
582
 
 
583
KJS::Value KstBindAxis::majorGridColor(KJS::ExecState *exec) const {
 
584
  if (!_d) {
 
585
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
586
    exec->setException(eobj);
 
587
    return KJS::Undefined();
 
588
  }
 
589
  KstReadLocker rl(_d);
 
590
  return KJSEmbed::convertToValue(exec, _d->majorGridColor());
 
591
}
 
592
 
 
593
 
 
594
void KstBindAxis::setMajorGridColor(KJS::ExecState *exec, const KJS::Value& value) {
 
595
  if (!_d) {
 
596
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
597
    exec->setException(eobj);
 
598
    return;
 
599
  }
 
600
  QVariant cv = KJSEmbed::convertToVariant(exec, value);
 
601
  if (!cv.canCast(QVariant::Color)) {
 
602
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
603
    exec->setException(eobj);
 
604
    return;
 
605
  }
 
606
  KstWriteLocker rl(_d);
 
607
  _d->setGridLinesColor(cv.toColor(), _d->minorGridColor(), false, _d->defaultMinorGridColor());
 
608
  _d->setDirty();
 
609
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
610
}
 
611
 
 
612
 
 
613
KJS::Value KstBindAxis::minorGridColor(KJS::ExecState *exec) const {
 
614
  if (!_d) {
 
615
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
616
    exec->setException(eobj);
 
617
    return KJS::Undefined();
 
618
  }
 
619
  KstReadLocker rl(_d);
 
620
  return KJSEmbed::convertToValue(exec, _d->minorGridColor());
 
621
}
 
622
 
 
623
 
 
624
void KstBindAxis::setMinorGridColor(KJS::ExecState *exec, const KJS::Value& value) {
 
625
  if (!_d) {
 
626
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
627
    exec->setException(eobj);
 
628
    return;
 
629
  }
 
630
  QVariant cv = KJSEmbed::convertToVariant(exec, value);
 
631
  if (!cv.canCast(QVariant::Color)) {
 
632
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
633
    exec->setException(eobj);
 
634
    return;
 
635
  }
 
636
  KstWriteLocker rl(_d);
 
637
  _d->setGridLinesColor(_d->majorGridColor(), cv.toColor(), _d->defaultMajorGridColor(), false);
 
638
  _d->setDirty();
 
639
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
640
}
 
641
 
 
642
 
 
643
KJS::Value KstBindAxis::interpretation(KJS::ExecState *exec) const {
 
644
  return KJS::Object(new KstBindTimeInterpretation(exec, const_cast<KstBindAxis*>(this))); // yuck
 
645
}
 
646
 
 
647
 
 
648
KJS::Value KstBindAxis::minorTickCount(KJS::ExecState *exec) const {
 
649
  if (!_d) {
 
650
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
651
    exec->setException(eobj);
 
652
    return KJS::Undefined();
 
653
  }
 
654
  KstReadLocker rl(_d);
 
655
  if (_xAxis) {
 
656
    return KJS::Number(_d->xMinorTicks());
 
657
  } else {
 
658
    return KJS::Number(_d->yMinorTicks());
 
659
  }
 
660
}
 
661
 
 
662
 
 
663
void KstBindAxis::setMinorTickCount(KJS::ExecState *exec, const KJS::Value& value) {
 
664
  if (!_d) {
 
665
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
666
    exec->setException(eobj);
 
667
    return;
 
668
  }
 
669
  if (value.type() != KJS::NumberType) {
 
670
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
671
    exec->setException(eobj);
 
672
    return;
 
673
  }
 
674
 
 
675
  KstWriteLocker rl(_d);
 
676
  if (_xAxis) {
 
677
    _d->setXMinorTicks(value.toInt32(exec));
 
678
  } else {
 
679
    _d->setYMinorTicks(value.toInt32(exec));
 
680
  }
 
681
  _d->setDirty();
 
682
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
683
}
 
684
 
 
685
 
 
686
KJS::Value KstBindAxis::majorTickDensity(KJS::ExecState *exec) const {
 
687
  if (!_d) {
 
688
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
689
    exec->setException(eobj);
 
690
    return KJS::Undefined();
 
691
  }
 
692
  KstReadLocker rl(_d);
 
693
  int i = 0;
 
694
  if (_xAxis) {
 
695
    i = _d->xMajorTicks();
 
696
  } else {
 
697
    i = _d->yMajorTicks();
 
698
  }
 
699
  switch (i) {
 
700
    case 2:
 
701
      i = 0;
 
702
      break;
 
703
    case 10:
 
704
      i = 2;
 
705
      break;
 
706
    case 15:
 
707
      i = 3;
 
708
      break;
 
709
    case 5:
 
710
    default:
 
711
      i = 1;
 
712
      break;
 
713
  }
 
714
 
 
715
  return KJS::Number(i);
 
716
}
 
717
 
 
718
 
 
719
void KstBindAxis::setMajorTickDensity(KJS::ExecState *exec, const KJS::Value& value) {
 
720
  if (!_d) {
 
721
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
722
    exec->setException(eobj);
 
723
    return;
 
724
  }
 
725
  if (value.type() != KJS::NumberType) {
 
726
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
727
    exec->setException(eobj);
 
728
    return;
 
729
  }
 
730
 
 
731
  int i = value.toInt32(exec);
 
732
  switch (i) {
 
733
    case 0:
 
734
        i = 2;
 
735
      break;
 
736
    case 1:
 
737
        i = 5;
 
738
      break;
 
739
    case 2:
 
740
        i = 10;
 
741
      break;
 
742
    case 3:
 
743
        i = 15;
 
744
      break;
 
745
    default:
 
746
      KJS::Object eobj = KJS::Error::create(exec, KJS::RangeError);
 
747
      exec->setException(eobj);
 
748
      return;
 
749
  }
 
750
 
 
751
  KstWriteLocker rl(_d);
 
752
  if (_xAxis) {
 
753
    _d->setXMajorTicks(value.toInt32(exec));
 
754
  } else {
 
755
    _d->setYMajorTicks(value.toInt32(exec));
 
756
  }
 
757
  _d->setDirty();
 
758
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
759
}
 
760
 
 
761
 
 
762
KJS::Value KstBindAxis::scaleMode(KJS::ExecState *exec) const {
 
763
  if (!_d) {
 
764
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
765
    exec->setException(eobj);
 
766
    return KJS::Undefined();
 
767
  }
 
768
  KstReadLocker rl(_d);
 
769
  KstScaleModeType i;
 
770
  if (_xAxis) {
 
771
    i = _d->xScaleMode();
 
772
  } else {
 
773
    i = _d->yScaleMode();
 
774
  }
 
775
  _d->setDirty();
 
776
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
777
  return KJS::Number(i);
 
778
}
 
779
 
 
780
 
 
781
KJS::Value KstBindAxis::scaleAuto(KJS::ExecState *exec, const KJS::List& args) {
 
782
  if (!_d) {
 
783
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
784
    exec->setException(eobj);
 
785
    return KJS::Undefined();
 
786
  }
 
787
 
 
788
  if (args.size() != 0) {
 
789
    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly zero arguments.");
 
790
    exec->setException(eobj);
 
791
    return KJS::Undefined();
 
792
  }
 
793
 
 
794
  KstWriteLocker rl(_d);
 
795
  if (_xAxis) {
 
796
    _d->setXScaleMode(AUTO);
 
797
  } else {
 
798
    _d->setYScaleMode(AUTO);
 
799
  }
 
800
  _d->setDirty();
 
801
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
802
  return KJS::Undefined();
 
803
}
 
804
 
 
805
 
 
806
KJS::Value KstBindAxis::scaleAutoSpikeInsensitive(KJS::ExecState *exec, const KJS::List& args) {
 
807
  if (!_d) {
 
808
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
809
    exec->setException(eobj);
 
810
    return KJS::Undefined();
 
811
  }
 
812
 
 
813
  if (args.size() != 0) {
 
814
    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly zero arguments.");
 
815
    exec->setException(eobj);
 
816
    return KJS::Undefined();
 
817
  }
 
818
 
 
819
  KstWriteLocker rl(_d);
 
820
  if (_xAxis) {
 
821
    _d->setXScaleMode(NOSPIKE);
 
822
  } else {
 
823
    _d->setYScaleMode(NOSPIKE);
 
824
  }
 
825
  _d->setDirty();
 
826
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
827
  return KJS::Undefined();
 
828
}
 
829
 
 
830
 
 
831
KJS::Value KstBindAxis::scaleExpression(KJS::ExecState *exec, const KJS::List& args) {
 
832
  if (!_d) {
 
833
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
834
    exec->setException(eobj);
 
835
    return KJS::Undefined();
 
836
  }
 
837
 
 
838
  if (args.size() != 2) {
 
839
    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly two arguments.");
 
840
    exec->setException(eobj);
 
841
    return KJS::Undefined();
 
842
  }
 
843
 
 
844
  if (args[0].type() != KJS::StringType || args[1].type() != KJS::StringType) {
 
845
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
846
    exec->setException(eobj);
 
847
    return KJS::Undefined();
 
848
  }
 
849
 
 
850
  KstWriteLocker rl(_d);
 
851
  if (_xAxis) {
 
852
    _d->setXScaleMode(EXPRESSION);
 
853
    _d->setXExpressions(args[0].toString(exec).qstring(), args[1].toString(exec).qstring());
 
854
  } else {
 
855
    _d->setYScaleMode(EXPRESSION);
 
856
    _d->setYExpressions(args[0].toString(exec).qstring(), args[1].toString(exec).qstring());
 
857
  }
 
858
  _d->setDirty();
 
859
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
860
  return KJS::Undefined();
 
861
}
 
862
 
 
863
 
 
864
KJS::Value KstBindAxis::scaleRange(KJS::ExecState *exec, const KJS::List& args) {
 
865
  if (!_d) {
 
866
    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
 
867
    exec->setException(eobj);
 
868
    return KJS::Undefined();
 
869
  }
 
870
 
 
871
  if (args.size() != 2) {
 
872
    KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires exactly two arguments.");
 
873
    exec->setException(eobj);
 
874
    return KJS::Undefined();
 
875
  }
 
876
 
 
877
  if (args[0].type() != KJS::NumberType || args[1].type() != KJS::NumberType) {
 
878
    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
 
879
    exec->setException(eobj);
 
880
    return KJS::Undefined();
 
881
  }
 
882
 
 
883
  KstWriteLocker rl(_d);
 
884
  if (_xAxis) {
 
885
    _d->setXScaleMode(FIXED);
 
886
    _d->setXScale(args[0].toNumber(exec), args[1].toNumber(exec));
 
887
  } else {
 
888
    _d->setYScaleMode(FIXED);
 
889
    _d->setYScale(args[0].toNumber(exec), args[1].toNumber(exec));
 
890
  }
 
891
  _d->setDirty();
 
892
  KstApp::inst()->paintAll(KstPainter::P_PAINT);
 
893
  return KJS::Undefined();
 
894
}
 
895
 
 
896
 
 
897
// vim: ts=2 sw=2 et