;; PointA TopLines - Potions/Scrolls (DRAWCHART.LSP) ;; Bill Kramer April 2003 ;; ;; Chart Drawing Program ;; ;; Data List Format ;; ;; ( ;;chart details ;; ( ;;first row of data ;; ( ;;first cell details ;; (1 . "") ;; (40 . ) ;; (50 . ) ;; ... other group code settings for text ;; ) ;; end first cell ;; ... more cells for row ;; ) ;;end first row ;; ... more rows with cells ;; ) ;;end of chart ;; (setq TestData '( ( ;Row 1 ((1 . "Name") (40 . 0.35) (50 . 0.0)) ((1 . "Office") (40 . 0.35) (50 . 0.0)) ((1 . "IP Off.") (40 . 0.25) (50 . 0.0)) ) ( ;Row 2 ((1 . "Orion") (40 . 0.25) (50 . 0.0)) ((1 . "100") (40 . 0.25) (50 . 0.0)) ((1 . ".253") (40 . 0.25) (50 . 0.0)) ) ( ;Row 3 ((1 . "Lupis") (40 . 0.25) (50 . 0.0)) ((1 . "102") (40 . 0.25) (50 . 0.0)) ((1 . ".252") (40 . 0.25) (50 . 0.0)) ) ( ;Row 4 ((1 . "Weasely") (40 . 0.25) (50 . 0.0)) ((1 . "103") (40 . 0.25) (50 . 0.0)) ((1 . ".251") (40 . 0.25) (50 . 0.0)) ) ( ;Row 5 ((1 . "Zenefero") (40 . 0.25) (50 . 0.0)) ((1 . "105a") (40 . 0.25) (50 . 0.0)) ((1 . ".247") (40 . 0.25) (50 . 0.0)) ) ( ;Row 6 ((1 . "Merlin") (40 . 0.25) (50 . 0.0)) ((1 . "104") (40 . 0.25) (50 . 0.0)) ((1 . ".245") (40 . 0.25) (50 . 0.0)) ) ( ;Row 7 ((1 . "Simpson") (40 . 0.25) (50 . 0.0)) ((1 . "105b") (40 . 0.25) (50 . 0.0)) ((1 . ".249") (40 . 0.25) (50 . 0.0)) ) ( ;Row 8 ((1 . "Harry") (40 . 0.25) (50 . 0.0)) ((1 . "110") (40 . 0.25) (50 . 0.0)) ((1 . ".250") (40 . 0.25) (50 . 0.0)) ) ) CellWidthFactor 1.2 CellHeightFactor 1.5 ) ;; ;;--------------------------------------------------------------------- (defun DrawChart (DataList / ColCount N Width Height TMP Rows) ;; ;; Check that data list is valid ;; (if (null (Verify_Data_List DataList)) (progn ;; ;; Loop through columns of data looking for tallest ;; (setq Height (DetermineColHeight DataList) ;; ;; Loop through rows of data looking for tallest ;; Build nested list of row X Text offset, Y bottom, Y text Rows (DetermineRows DataList) ) ;; ;; Draw the cell details. (Draw_The_Cells DataList Height Rows) ) (print "\nError - input data list is not valid") ) (princ) ) ;;--------------------------------------------------------------------- ;; Figure out which column is the tallest. ;; (defun DetermineColHeight (DataList / N TMP Height) (setq N 0 ;;index of column Height 0.0 ) (repeat (length (car DataList)) ;;Column Count ;; (setq TMP (Col_Total_Size DataList N) ;;Size of column (X, Y) N (1+ N)) ;;index to next column ;; ;;Check height to see if greater, save if so. (if (> (cadr TMP) Height) (setq Height (cadr TMP))) ) ;; Height ;;return the maximum height ) ;;--------------------------------------------------------------------- ;; Figure out where the rows start in Y ;; (defun DetermineRows (DataList / CHgt CWdt Row TMP dY Rows) ;; (setq dY 0.0) ;; ;; Go through each row in the data list ;; (foreach Row DataList ;; ;; Reset maximum sizes found (setq CHgt 0.0 CWdt 0.0) ;; ;; Go through each cell in the row ;; (foreach Cell Row ;; ;; Get cell size as (X, Y) (setq TMP (cell_Size Cell) ) ;; Is this cell larger in Y than saved height? (if (> (cadr TMP) CHgt) (setq CHgt (cadr TMP))) ;; ;; Is this cell wider than saved width? (if (> (car TMP) CWdt) (setq CWdt (car TMP))) ) ;; ;; Add row data found to returning list ;; (setq Rows (cons ;;add to front of list (list ;;nest list to be added contains (if Rows ;;X value of text start for row (caar Rows) ;;get value from first row if known (/ (- CWdt (/ CWdt CellWidthFactor)) 2.0) ;;or calculate it ) (setq dY (- dY CHgt)) ;;Y value of bottom corner (+ dY ;; calculate Y value of text (/ (- CHgt (/ CHgt CellHeightFactor)) 2.0)) ) ;;end list to be added Rows)) ) ;; End of loop, reverse Rows list to match data list order (setq Rows (reverse Rows)) ) ;;--------------------------------------------------------------------- ;; Draw the cell details ;; (defun Draw_The_Cells (DataList Height Rows / N dX ddX dY ddY) ;; (setq N 0 ;;initial column index counter M 0 ;;initial Y index counter dX 0.0 ;;starting X point Height (- Height) ;;ending Y point, below zero ) (repeat (length (car DataList)) ;;column count repeat ;; ;; Get the total size of the column at N (max width, height) (setq TMP (Col_Total_Size DataList N) ddX (+ dX (car TMP)) ;;ending X of column ) ;; ;; Draw line from top left of column to bottom left (add_a_line (list dX 0.0) (list dX Height)) ;; ;; Draw line from top left to top right (add_a_line (list dX 0.0) (list ddX 0.0)) ;; ;; Loop through each column and output text ;; (setq TMP (Get_Column DataList N) ) (foreach CellDetail TMP (setq CSize (cell_size CellDetail) ;;X and Y size of a cell dY (nth M Rows) ;; Y values from rows passed to function TxtPt (list ;;calculate offset text point (+ dX (car dY)) (caddr dY) ) dY (cadr dY) ) ;; ;; Draw line at bottom of cell (add_a_line (list dX dY) (list ddX dY)) ;; ;; Draw the text from bottom right of cell offset (add_a_text TxtPt CellDetail) ;; ;; Next cell Y level index update (setq M (1+ M)) ) ;; ;; Move to next column (setq dX ddX N (1+ N) M 0 ;;reset cell Y index ) ) (add_a_line (list dX 0.0) (list dX Height)) ) ;;--------------------------------------------------------------------- ;; Basic "Add_A" functions for output of graphic entity objects. ;; (defun Add_A_Line (P1 P2) (entmake (list '(0 . "LINE") (cons 10 P1) (cons 11 P2)))) ;; (defun Add_A_Text (P1 Txt) (entmake (append (list (cons 0 "TEXT") (cons 10 P1) ) TXT))) ;; ;;--------------------------------------------------------------------- ;; Col_Total_Size - finds X width and Y length of total column. ;; (defun Col_Total_Size (DataList NN / ColDetails TMP WW HH) (setq ColDetails (Get_Column DataList NN) WW 0.0 HH 0.0) ;; ;; Loop through the cell details for the column ;; (foreach CellDetail ColDetails ;; ;; Get cell size as (X,Y) (setq TMP (Cell_Size CellDetail) HH (+ HH (cadr TMP))) ;;accum Y values ;; (if (> (car TMP) WW) (setq WW (car TMP))) ;;max width ) ;; ;; Return list with Width or largest cell and total Y of columns. (list WW HH) ) ;;--------------------------------------------------------------------- ;; Get Column - Return a nested list containing the cells of a column ;; in the data list at the offset value of NN (zero based). ;; (defun Get_Column (DataList NN) (mapcar '(lambda (X) (nth NN X)) DataList)) ;;--------------------------------------------------------------------- ;; Cell size - given details of the cell, returns list of ;; width (X) and height (Y) ;; (defun Cell_Size (CellDetails / Ans) (setq CellDetails ;;Add group code 10 with zero point (if (assoc 10 CellDetails) (subst '(10 0.0 0.0 0.0) (assoc 10 CellDetails) CellDetails) (cons '(10 0.0 0.0 0.0) CellDetails)) ;; ;; Get text box details for object ;; Ans (textbox CellDetails)) ;; ;; Return list of (X,Y) size times the factors (list (* CellWidthFactor (- (caadr Ans) (caar Ans))) (* CellHeightFactor (- (cadadr Ans) (cadar Ans)))) ) ;;--------------------------------------------------------------------- ;; ;; Reads through the incoming data list and returns nil if all is okay. ;; (defun Verify_data_list (DL / NC Foul) (setq NC (length (car DL))) ;; length of first row (foreach Row DL (if (/= (length Row) NC) (setq Foul Row) ;;row is not proper length ) (foreach Col Row (if (not (apply 'and (mapcar 'listp Col))) (setq Foul (cons "Not a list!" Col)) ;;something is not in list form! ) (if (apply 'or (mapcar '(lambda (X) (/= (type (car X)) (type 1))) Col)) (setq Foul (cons "Not a group code!" Col)) ;;something is not a group code form! ) ) ) Foul )