Support mixing orientations.
Cat's Eye Technologies
10 years ago
109 | 109 | * some details about how to depict them on the canvas, mainly |
110 | 110 | * the width and the height which the s-expression will occupy. |
111 | 111 | */ |
112 | this.decorateSexp = function(x, y, sexp) { | |
112 | this.decorateSexp = function(x, y, sexp, parentOrientation) { | |
113 | parentOrientation = !!parentOrientation; // ensure it is a boolean | |
113 | 114 | /* |
114 | 115 | * Determine if we have a Cons cell or an Atom. |
115 | 116 | */ |
150 | 151 | } |
151 | 152 | var len = children.length; |
152 | 153 | |
154 | /* | |
155 | * Determine the orientation of this sexp. | |
156 | */ | |
157 | ||
158 | // STYLE 1: only cond and let* bindings are vertical | |
159 | origSexp.horizontal = true; | |
160 | if (!origSexp.startsWithAtom) { | |
161 | origSexp.horizontal = false; | |
162 | } | |
163 | if (origSexp.startsWithAtom && head.text === 'cond') { | |
164 | origSexp.horizontal = false; | |
165 | } | |
166 | ||
167 | // STYLE 2: orientation is opposite of parent's | |
168 | /* | |
169 | origSexp.horizontal = !parentOrientation; | |
170 | */ | |
171 | ||
172 | // STYLE 3: orientation is random! | |
173 | /* | |
174 | origSexp.horizontal = (Math.random() > 0.5 ? true : false); | |
175 | */ | |
176 | ||
153 | 177 | for (var i = 0; i < len; i++) { |
154 | this.decorateSexp(x, y, children[i]); | |
178 | this.decorateSexp(x, y, children[i], origSexp.horizontal); | |
155 | 179 | } |
156 | 180 | |
157 | 181 | var w = 0; |
158 | 182 | var h = 0; |
159 | ||
160 | origSexp.horizontal = false; | |
161 | 183 | for (var i = 0; i < len; i++) { |
162 | 184 | // alert(i + '...' + w); |
163 | 185 | if (origSexp.horizontal) { |
172 | 194 | } |
173 | 195 | } |
174 | 196 | } |
175 | ||
176 | 197 | if (origSexp.horizontal) { |
177 | 198 | w = w + margin * (len + 1); |
178 | 199 | } else { |