1 ;;; xwem-diagram.el --- Diagrams drawing for XWEM.
3 ;; Copyright (C) 2004,2005 by XWEM Org.
5 ;; Author: Zajcev Evgeny <zevlg@yandex.ru>
6 ;; Created: Sat Mar 6 17:09:58 MSK 2004
8 ;; X-CVS: $Id: xwem-diagram.el,v 1.6 2005-04-04 19:54:11 lg Exp $
10 ;; This file is part of XWEM.
12 ;; XWEM is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; XWEM is distributed in the hope that it will be useful, but WITHOUT
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
20 ;; License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 ;;; Synched up with: Not in FSF
31 ;; Diagrams drawer, supports:
33 ;; * Plain bar digrams.
35 ;; * Plain sectors diagrams.
36 ;; * 3D sectors diagrams.
38 ;; * Many gnuplot like datasets drawing.
47 (defun xwem-diag-dot-distance (dot1 dot2)
48 "Return distance betwean DOT1 and DOT2."
49 (let ((w (abs (- (X-Point-x dot1) (X-Point-x dot2))))
50 (h (abs (- (X-Point-y dot1) (X-Point-y dot2)))))
52 (sqrt (+ (* h h) (* w h)))))
54 (defun xwem-diag-dot-betwean-p (x-or-y dot dot1 dot2)
55 "Return non-nil if X-OR-Y of DOT betwean DOT1 and DOT2.
56 X-OR-Y can be 'x or 'y."
58 (or (and (>= (X-Point-x dot) (X-Point-x dot1))
59 (<= (X-Point-x dot) (X-Point-x dot2)))
60 (and (<= (X-Point-x dot) (X-Point-x dot1))
61 (>= (X-Point-x dot) (X-Point-x dot2))))
63 (or (and (>= (X-Point-y dot) (X-Point-y dot1))
64 (<= (X-Point-y dot) (X-Point-y dot2)))
65 (and (<= (X-Point-y dot) (X-Point-y dot1))
66 (>= (X-Point-y dot) (X-Point-y dot2))))))
68 (defun xwem-diag-dot-< (x-or-y dot dot1)
69 "Return non-nil if X-OR-Y of DOT is < DOT1."
71 (< (X-Point-x dot) (X-Point-x dot1))
72 (< (X-Point-y dot) (X-Point-y dot1))))
74 (defun xwem-diag-dot-<= (x-or-y dot dot1)
75 "Return non-nil if X-OR-Y of DOT is <= DOT1."
77 (<= (X-Point-x dot) (X-Point-x dot1))
78 (<= (X-Point-y dot) (X-Point-y dot1))))
80 (defun xwem-diag-dot-> (x-or-y dot dot1)
81 "Return non-nil if X-OR-Y of DOT is > DOT1."
83 (> (X-Point-x dot) (X-Point-x dot1))
84 (> (X-Point-y dot) (X-Point-y dot1))))
86 (defun xwem-diag-dot->= (x-or-y dot dot1)
87 "Return non-nil if X-OR-Y of DOT is >= DOT1."
89 (>= (X-Point-x dot) (X-Point-x dot1))
90 (>= (X-Point-y dot) (X-Point-y dot1))))
92 (defun xwem-diag-calc-arc-dot-at (cnt-dot w h a)
93 "Calculte dot position."
94 (let* ((ra (/ (* a pi) 180))
99 (cons (round (+ (X-Point-x cnt-dot) rx))
100 (round (+ (X-Point-y cnt-dot) (- ry))))))
102 (defun xwem-diag-draw-rect (d gc dot1 dot2 dot3 dot4 &optional fill-gc)
103 "Draw parallelogram with vertexes at DOT1 DOT2 DOT3 and DOT4."
104 (when (X-Gc-p fill-gc)
105 (XFillPoly (X-Drawable-dpy d) d fill-gc (list dot1 dot2 dot3 dot4)))
107 (XDrawLines (X-Drawable-dpy d) d gc (list dot1 dot2 dot3 dot4 dot1)))
109 (defun xwem-diag-calc-sector-dots (x y w h a1 a2)
110 (let* ((mcnt (cons (+ x (/ w 2))
112 (d1 (xwem-diag-calc-arc-dot-at mcnt (/ w 2) (/ h 2) a1))
113 (d2 (xwem-diag-calc-arc-dot-at mcnt (/ w 2) (/ h 2) (+ a2 a1))))
116 (defun xwem-diag-draw-sector (d gc x y w h a1 a2 &optional fill-gc)
117 "Draw sector, return new dots."
118 (let ((dots (xwem-diag-calc-sector-dots x y w h a1 a2)))
120 (when (X-Gc-p fill-gc)
121 (XFillArc (X-Drawable-dpy d) d fill-gc x y w h a1 a2))
123 (XDrawLines (X-Drawable-dpy d) d gc dots)
124 (XDrawArc (X-Drawable-dpy d) d gc x y w h a1 a2)
127 (defun xwem-diag-calc-butt-center (ds1 ds2)
129 (let* ((h1 (- (X-Point-x (nth 2 ds1))
130 (X-Point-x (nth 1 ds1))))
131 (h2 (- (X-Point-x (nth 0 ds1))
132 (X-Point-x (nth 1 ds1))))
133 (l (* (/ (float h1) h2)
134 (- (X-Point-y (nth 1 ds2))
135 (X-Point-y (nth 0 ds2)))))
136 (L (+ (- (X-Point-y (nth 2 ds1))
137 (X-Point-y (nth 1 ds2)))
139 (a (- (X-Point-y (nth 1 ds2))
140 (X-Point-y (nth 1 ds1))))
142 (T (xwem-diag-dot-distance
143 (nth 1 ds2) (cons (X-Point-x (nth 2 ds1))
144 (+ (X-Point-y (nth 1 ds2))
146 (tt (/ (* T a) (+ L a)))
151 (cons (truncate (+ (X-Point-x (nth 1 ds2))
153 (truncate (+ (X-Point-y (nth 1 ds2))
156 (defun xwem-diag-draw-3d-sector (d gc x y w h a1 a2 sector-width &optional fill-gc)
158 (let ((ds1 (xwem-diag-calc-sector-dots x y w h a1 a2))
159 (ds2 (xwem-diag-calc-sector-dots x (+ y sector-width) w h a1 a2))
160 d0-adds1 d0-adds2 d2-adds1 d2-adds2
164 center-visible dot0-visible dot2-visible
165 cd0-visible cd2-visible)
169 (setq a1 (+ a1 360)))
171 (setq a1 (- a1 360)))
173 (setq a2 (- a2 360)))
175 (when (or (and (<= a1 180)
179 (setq d0-adds1 (cons (- (X-Point-x (nth 1 ds1)) (/ w 2))
180 (X-Point-y (nth 1 ds1))))
181 (setq d0-adds2 (cons (- (X-Point-x (nth 1 ds2)) (/ w 2))
182 (X-Point-y (nth 1 ds2))))
187 (setq buta2 (- a2 (- buta1 a1))))
190 (setq d0-buta2 (- (+ a1 a2) 270 270)))
193 (when (> (+ (or buta1 a1) (or buta2 a2)) 360)
194 (setq d2-adds1 (cons (+ (X-Point-x (nth 1 ds1)) (/ w 2))
195 (X-Point-y (nth 1 ds1))))
196 (setq d2-adds2 (cons (+ (X-Point-x (nth 1 ds2)) (/ w 2))
197 (X-Point-y (nth 1 ds2))))
198 (if (or (and (xwem-diag-dot-> 'y (nth 0 ds1) (nth 1 ds1))
199 (xwem-diag-dot-> 'y (nth 2 ds1) (nth 1 ds1)))
200 (and d0-buta1 d0-buta2))
202 (setq d0-buta1 (or d0-buta1 buta1))
203 (setq d0-buta2 (or d0-buta2 buta2))
204 (setq d2-buta1 (or buta1 a1))
205 (setq d2-buta2 (- 360 d2-buta1))
209 (setq buta1 (or buta1 a1))
210 (setq buta2 (- 360 buta1))
213 ;; Setup visibilities
214 (unless (and (xwem-diag-dot-< 'x (nth 0 ds1) (nth 1 ds1))
215 (xwem-diag-dot-< 'y (nth 0 ds1) (nth 1 ds1)))
216 (setq dot0-visible t))
218 (unless (and (xwem-diag-dot-> 'x (nth 2 ds1) (nth 1 ds1))
219 (xwem-diag-dot-< 'y (nth 2 ds1) (nth 1 ds1)))
220 (setq dot2-visible t))
222 (when (or (and (xwem-diag-dot->= 'x (nth 0 ds1) (nth 1 ds1))
223 (xwem-diag-dot-<= 'y (nth 0 ds1) (nth 1 ds1))
224 (not (and (xwem-diag-dot->= 'x (nth 2 ds1) (nth 1 ds1))
225 (or (xwem-diag-dot->= 'y (nth 2 ds1) (nth 1 ds1))
226 (xwem-diag-dot->= 'y (nth 2 ds1) (nth 0 ds1))))))
227 (and (xwem-diag-dot->= 'x (nth 0 ds1) (nth 1 ds1))
228 (xwem-diag-dot->= 'y (nth 0 ds1) (nth 1 ds1))
229 (not (and (xwem-diag-dot->= 'y (nth 2 ds1) (nth 0 ds1))
230 (xwem-diag-dot->= 'x (nth 2 ds1) (nth 1 ds1))
231 (xwem-diag-dot->= 'y (nth 2 ds1) (nth 1 ds1)))))
232 (and (xwem-diag-dot-<= 'x (nth 0 ds1) (nth 1 ds1))
233 (xwem-diag-dot-<= 'y (nth 0 ds1) (nth 1 ds1))
234 (xwem-diag-dot-<= 'x (nth 2 ds1) (nth 1 ds1))
235 (or (xwem-diag-dot->= 'y (nth 2 ds1) (nth 1 ds1))
236 (xwem-diag-dot->= 'y (nth 2 ds1) (nth 0 ds1))))
237 (and (xwem-diag-dot-<= 'x (nth 0 ds1) (nth 1 ds1))
238 (xwem-diag-dot->= 'y (nth 0 ds1) (nth 1 ds1))
239 (xwem-diag-dot-<= 'x (nth 2 ds1) (nth 1 ds1))
240 (and (xwem-diag-dot->= 'y (nth 2 ds1) (nth 1 ds1))
241 (xwem-diag-dot->= 'y (nth 2 ds1) (nth 0 ds1)))))
242 (setq center-visible t)
245 (unless (and (xwem-diag-dot-> 'y (nth 2 ds2) (nth 1 ds2))
246 (xwem-diag-dot-betwean-p 'x (nth 2 ds2) (nth 1 ds2) (nth 0 ds2)))
247 (setq cd0-visible t)))
250 (unless (and (xwem-diag-dot-> 'y (nth 0 ds2) (nth 1 ds2))
251 (xwem-diag-dot-betwean-p 'x (nth 0 ds2) (nth 1 ds2) (nth 2 ds2)))
252 (setq cd2-visible t)))
256 (if (and buta1 buta2)
259 (XFillArc (X-Drawable-dpy d) d fill-gc x (+ y sector-width) w h buta1 buta2))
260 (XDrawArc (X-Drawable-dpy d) d gc x (+ y sector-width) w h buta1 buta2))
262 (if (or (and d0-buta1 d0-buta2)
263 (and d2-buta1 d2-buta2))
265 (when (and d0-buta1 d0-buta2)
267 (XFillArc (X-Drawable-dpy d) d fill-gc x (+ y sector-width) w h d0-buta1 d0-buta2))
268 (XDrawArc (X-Drawable-dpy d) d gc x (+ y sector-width) w h d0-buta1 d0-buta2))
269 (when (and d2-buta1 d2-buta2)
271 (XFillArc (X-Drawable-dpy d) d fill-gc x (+ y sector-width) w h d2-buta1 d2-buta2))
272 (XDrawArc (X-Drawable-dpy d) d gc x (+ y sector-width) w h d2-buta1 d2-buta2)))
274 (when (and (xwem-diag-dot->= 'y (nth 0 ds1) (nth 1 ds1))
275 (xwem-diag-dot->= 'y (nth 2 ds1) (nth 1 ds1)))
277 (XFillArc (X-Drawable-dpy d) d fill-gc x (+ y sector-width) w h a1 a2))
278 (XDrawArc (X-Drawable-dpy d) d gc x (+ y sector-width) w h a1 a2))))
283 (XFillArc (X-Drawable-dpy d) d fill-gc x y w h a1 a2)
285 (xwem-diag-draw-rect d fill-gc
286 (nth 2 ds2) (nth 2 ds1)
287 (nth 1 ds1) (nth 1 ds2)
289 (xwem-diag-draw-rect d fill-gc
290 (nth 0 ds2) (nth 0 ds1)
291 (nth 1 ds1) (nth 1 ds2)
294 (when (and d0-adds1 d0-adds2)
295 (XFillPoly (X-Drawable-dpy d) d fill-gc
296 (list d0-adds1 d0-adds2 (nth 1 ds2) (nth 1 ds1)
299 (when (and d2-adds1 d2-adds2)
300 (XFillPoly (X-Drawable-dpy d) d fill-gc
301 (list d2-adds1 d2-adds2 (nth 1 ds2) (nth 1 ds1)
306 (XDrawLines (X-Drawable-dpy d) d gc ds1)
307 (XDrawArc (X-Drawable-dpy d) d gc x y w h a1 a2)
309 (xwem-diag-draw-sector d gc x y w h a1 a2 fill-gc) ; sector always visible
313 (XDrawLines (X-Drawable-dpy d) d gc (list (nth 1 ds1) (nth 1 ds2))))
315 (XDrawLines (X-Drawable-dpy d) d gc (list (nth 1 ds2) (nth 0 ds2))))
317 (XDrawLines (X-Drawable-dpy d) d gc (list (nth 1 ds2) (nth 2 ds2))))
319 (XDrawLines (X-Drawable-dpy d) d gc (list (nth 0 ds1) (nth 0 ds2))))
321 (XDrawLines (X-Drawable-dpy d) d gc (list (nth 2 ds1) (nth 2 ds2))))
322 (when (and d0-adds1 d0-adds2)
323 (XDrawLines (X-Drawable-dpy d) d gc (list d0-adds1 d0-adds2)))
324 (when (and d2-adds1 d2-adds2)
325 (XDrawLines (X-Drawable-dpy d) d gc (list d2-adds1 d2-adds2)))
328 (defun xwem-diag-draw-bar (d gc x y w h &optional fill-gc)
330 (xwem-diag-draw-rect d gc
331 (cons x y) (cons (+ x w) y)
332 (cons (+ x w) (+ y h)) (cons x (+ y h))
335 (defun xwem-diag-draw-3d-bar (d gc x y w h bar-width &optional fill-gc)
337 (let* ((d1 (cons x y))
338 (d2 (cons (+ x w) y))
339 (d3 (cons (+ x w) (+ y h)))
340 (d4 (cons x (+ y h)))
341 (x-off (/ bar-width 2))
342 (y-off (/ bar-width 2))
343 (dd1 (cons (+ x-off (car d1)) (- (cdr d1) y-off)))
344 (dd2 (cons (+ x-off (car d2)) (- (cdr d2) y-off)))
345 (dd3 (cons (+ x-off (car d3)) (- (cdr d3) y-off))))
348 (XFillPoly (X-Drawable-dpy d) d fill-gc
349 (list d1 dd1 dd2 dd3 d3 d4 d1)))
351 (XDrawLines (X-Drawable-dpy d) d gc
352 (list d1 dd1 dd2 dd3 d3 d4 d1 d2 d3 d2 dd2))
355 (defun xwem-diag-draw-percentage (type spec d edge-gc x y width height
356 &optional sector-width label-factor
357 label-font override-gc)
358 "Draw percentage sector of TYPE.
359 TYPE is one of 'plain or '3d.
360 SPEC specifies percentage to display, it is an array in form
361 \[percents sector-label fill-color center-offset x-offset y-offset\]
362 perecnts - is number betwean 0 and 100.
363 sector-label - either string or t, t mean show percentage.
364 fill-color - nil or color to fill sector.
365 center-offset - sector's offset from center using bisector vector.
366 x-offset - sector's x offset.
367 y-offset - sector's y offest.
369 EDGE-GC used to draw sector edges.
370 X, Y, WIDTH and HEIGHT specifies sector geometry coordinate inside
372 Optionally SECTOR-WIDTH may be specified (only for '3d TYPE).
373 LABEL-FACTOR is float number used, when calculating label placement.
374 LABEL-FONT is font used to draw label, default is font of EDGE-GC."
375 (let ((xdpy (X-Drawable-dpy d))
376 (temp-fill-face (make-face 'temp-fill-face))
381 ; (when (> (apply '+ (mapcar (lambda (el) (aref el 0)) spec)) 100)
382 ; (error "XWEM Invalid spec" spec))
385 (lambda (sel angbeg angle)
386 (xwem-set-face-foreground temp-fill-face (aref sel 2))
390 (when (not (zerop (aref sel 3)))
391 (let ((ra (/ (* pi (+ angbeg (/ angle 2))) 180)))
392 (setq xint-off (round (* (aref sel 3) (cos ra))))
393 (setq yint-off (- (round (* (aref sel 3) (sin ra)))))))
396 (xwem-diag-draw-sector
397 d edge-gc (+ x xint-off (aref sel 4))
398 (+ y yint-off (aref sel 5)) width height
400 (or override-gc (xwem-face-get-gc temp-fill-face)))
401 (xwem-diag-draw-3d-sector
402 d edge-gc (+ x xint-off (aref sel 4))
403 (+ y yint-off (aref sel 5)) width height
404 angbeg angle (or sector-width 10)
405 (or override-gc (xwem-face-get-gc temp-fill-face))))
409 (let* ((k (or label-factor 0.8))
412 (nx (+ (aref sel 4) x xint-off (/ (- width nw) 2)))
413 (ny (+ (aref sel 5) y yint-off (/ (- height nh) 2)))
414 (cd (xwem-diag-calc-sector-dots nx ny nw nh angbeg (/ angle 2)))
416 (text (if (stringp (aref sel 1)) (aref sel 1) (format "%d%%" (aref sel 0)))))
417 (XDrawString xdpy d gc
418 (- (X-Point-x (nth 2 cd))
419 (/ (X-Text-width xdpy (X-Gc-font gc) text) 2))
420 (+ (/ (X-Text-height xdpy (X-Gc-font gc) text) 2)
421 (X-Point-y (nth 2 cd)))
424 ;; Sort SPEC by percentage
425 (setq spec (sort spec (lambda (el1 el2) (> (aref el1 0) (aref el2 0)))))
427 ;; Special cases, when first sector is too big or too small
428 (when (> (aref (car spec) 0) 75)
429 (setq start-angle (* 360.0 (/ (- (aref (car spec) 0) 100) 100.0))))
430 (when (< (aref (car spec) 0) 25)
431 (setq start-angle (* 360.0 (/ (- 25 (aref (car spec) 0)) 100.0))))
433 (setq angle-begin start-angle)
435 (while (and spec (< (+ (* 100 (/ angle-begin 360.0))
438 (setq curang (* 360.0 (/ (aref (car spec) 0) 100.0)))
439 (funcall draw-sector (car spec) angle-begin curang)
440 (setq angle-begin (+ angle-begin curang))
441 (setq spec (cdr spec)))
443 ;; Draw little sectors
444 (setq angle-begin start-angle)
446 (setq curang (* 360.0 (/ (aref sss 0) 100.0)))
447 (setq angle-begin (- angle-begin curang))
448 (funcall draw-sector sss angle-begin curang))
451 (defun xwem-diag-plot-coordinates (d gc x y w h x-step y-step &rest params)
452 "Draw coordinates system."
453 (let ((notch-len (or (plist-get params :notch-len) 4))
454 (with-grid-p (plist-get params :with-grid))
455 (grid-dash-even (or (plist-get params :grid-dash-even) 1))
456 (grid-dash-odd (or (plist-get params :grid-dash-odd 3)))
457 (with-labels-p (plist-get params :with-labels))
458 (labels-offset (or (plist-get params :labels-offest) 4))
459 (labels-gc (or (plist-get params :labels-gc) gc))
460 (center-x (or (plist-get params :center-x) 0))
461 (center-y (or (plist-get params :center-y) 0))
462 (scale-x (or (plist-get params :scale-x) x-step))
463 (scale-y (or (plist-get params :scale-y) y-step))
465 (xdpy (X-Drawable-dpy d))
466 x-notches y-notches noff sls)
468 (setq noff (% center-x x-step))
470 (setq x-notches (cons (cons (cons (+ x noff)
472 (cons (+ x noff) (- y center-y notch-len)))
474 (setq noff (+ noff x-step)))
476 (setq noff (% center-y y-step))
478 (setq y-notches (cons (cons (cons (+ x center-x)
480 (cons (+ x center-x notch-len) (- y noff)))
482 (setq noff (+ noff y-step)))
486 (setq sls (X-Gc-line-style gc))
487 (setf (X-Gc-line-style gc) X-LineOnOffDash)
489 (XSetDashes xdpy gc 0 (list grid-dash-even grid-dash-odd
490 grid-dash-even grid-dash-odd))
494 (XDrawSegments xdpy d gc
496 (cons (cons x (X-Point-y (car s)))
497 (cons (+ x w) (X-Point-y (cdr s)))))
499 (XDrawSegments xdpy d gc
501 (cons (cons (X-Point-x (car s)) (- y h))
502 (cons (X-Point-x (car s)) y)))
505 (setf (X-Gc-line-style gc) sls)
506 (XChangeGC xdpy gc)))
510 (let* ((txt (int-to-string (/ (* scale-x (- (X-Point-x (car s)) x center-x)) x-step)))
511 (tw (X-Text-width xdpy (X-Gc-font labels-gc) txt))
512 (th (X-Text-height xdpy (X-Gc-font labels-gc) txt)))
514 (XDrawString xdpy d labels-gc (- (X-Point-x (car s)) (/ tw 2))
515 (+ y th labels-offset) txt)))
518 (let* ((txt (int-to-string (/ (* scale-y (- y (X-Point-y (car s)) center-y)) y-step)))
519 (tw (X-Text-width xdpy (X-Gc-font labels-gc) txt))
520 (th (X-Text-height xdpy (X-Gc-font labels-gc) txt)))
522 (XDrawString xdpy d labels-gc (- x tw labels-offset)
523 (+ (X-Point-y (car s)) (/ th 2)) txt)))
527 (XDrawSegments xdpy d gc (nconc (list (cons (cons x (- y center-y)) (cons (+ x w) (- y center-y)))
528 (cons (cons (+ x center-x) y) (cons (+ x center-x) (- y h))))
529 x-notches y-notches))
532 (defun xwem-diag-plot-points (point-type d gc dots &optional point-size)
533 "Draw points of TYPE."
537 (let ((xdpy (X-Drawable-dpy d)))
538 (cond ((eq point-type 0)
541 (make-X-Arc :x (- (X-Point-x d) point-size)
542 :y (- (X-Point-y d) point-size)
543 :width (+ point-size point-size)
544 :height (+ point-size point-size)
547 (XDrawPoints xdpy d gc dots))
550 (XDrawSegments xdpy d gc
553 (list (cons (cons (- (X-Point-x d) point-size)
555 (cons (+ (X-Point-x d) point-size)
557 (cons (cons (X-Point-x d)
558 (- (X-Point-y d) point-size))
560 (+ (X-Point-y d) point-size)))))
564 (XDrawSegments xdpy d gc
567 (list (cons (cons (- (X-Point-x d) point-size)
568 (- (X-Point-y d) point-size))
569 (cons (+ (X-Point-x d) point-size)
570 (+ (X-Point-y d) point-size)))
571 (cons (cons (- (X-Point-x d) point-size)
572 (+ (X-Point-y d) point-size))
573 (cons (+ (X-Point-x d) point-size)
574 (- (X-Point-y d) point-size)))))
578 (defun xwem-diag-plot-dots (type d gc x y dots &optional point-type point-size)
579 "Draw dots in cartesian coordinate system which has 0 at X Y."
580 ;; Adjust dots, according to X Y
581 (setq dots (mapcar (lambda (dot)
582 (cons (+ x (X-Point-x dot))
583 (- y (X-Point-y dot))))
586 ;; Default point/line types
590 (let ((xdpy (X-Drawable-dpy d)))
591 (cond ((eq type 'points)
592 (xwem-diag-plot-points point-type d gc dots point-size))
595 (XDrawLines xdpy d gc dots))
597 ((eq type 'linespoints)
598 (xwem-diag-plot-points point-type d gc dots point-size)
599 (XDrawLines xdpy d gc dots))
602 (XDrawSegments xdpy d gc
604 (cons (cons (X-Point-x d) y) d))
608 (XDrawPoints xdpy d gc dots))
611 (XDrawLines xdpy d gc
612 (apply 'nconc (mapcar* (lambda (d dn)
614 (list d (cons (X-Point-x dn) (X-Point-y d)))
616 dots (nconc (cdr dots) (list nil))))))
619 (XDrawLines xdpy d gc
620 (apply 'nconc (mapcar* (lambda (d dn)
622 (list d (cons (X-Point-x d) (X-Point-y dn)))
624 dots (nconc (cdr dots) (list nil))))))
635 (defun xwem-diag-read-data-file (file &optional using x-scale y-scale)
636 "Read data FILE and return list of dots lists.
637 USING is cons cell that specifies which columns to use.
638 X-SCALE is x coordinates scalling.
639 Y-SCALE is y coordinates scalling."
641 (setq using (cons 1 2)))
645 (insert-file-contents file)
646 (goto-char (point-min))
648 (cond ((looking-at "^#"))
650 ((looking-at "^[ \t]*$")
651 ;; dots set delimiter
652 (setq dlist (cons cdots dlist))
656 (let ((sc (split-string (buffer-substring (point-at-bol) (point-at-eol)) "[ \t]+")))
657 (setq sc (delete "" sc))
658 (setq cdots (cons (cons (* (or x-scale 1) (string-to-int (nth (1- (car using)) sc)))
659 (* (or y-scale 1) (string-to-int (nth (1- (cdr using)) sc))))
664 ;; Add last cdots, if any
666 (setq dlist (cons cdots dlist)))
672 ; (mapc (lambda (dots)
673 ; (xwem-diag-plot-dots 'lines (xwem-frame-xwin (nth 3 xwem-frames-list)) (xwem-face-get-gc 'green)
675 ; (xwem-diag-read-data-file "/usr/local/share/doc/gnuplot/world.dat" nil 3 4))
677 ; (xwem-diag-plot-dots 'points (xwem-frame-xwin (nth 3 xwem-frames-list)) (xwem-face-get-gc 'red)
678 ; 600 600 (car (xwem-diag-read-data-file "/usr/local/share/doc/gnuplot/world.cor" nil 3 4)) 1 3)
680 ; (xwem-diag-plot-coordinates (xwem-frame-xwin (nth 3 xwem-frames-list)) (xwem-face-get-gc 'blue)
681 ; 60 1000 1200 800 50 50
682 ; :center-x 600 :center-y 400 :with-grid t :grid-dash-even 1 :grid-dash-odd 4
683 ; :with-labels t :labels-gc (xwem-face-get-gc 'bold))
687 (provide 'xwem-diagram)
689 ;;; xwem-diagram.el ends here