| 1218 | } |
| 1219 | |
| 1220 | create_bounding_path(elem, end_points) { |
| 1221 | const values = []; |
| 1222 | const editing_copy = end_points.slice(); |
| 1223 | values.push(end_points[0]); |
| 1224 | editing_copy.splice(0, 1); |
| 1225 | //do union based on which direction you are trying to move in and |
| 1226 | //draw the path |
| 1227 | //best way seems to be horizaontal followed by vertical |
| 1228 | const props = ['x', 'y']; |
| 1229 | let iter = 0; |
| 1230 | let prop = props[iter % 2]; |
| 1231 | let other_prop = props[(iter + 1) % 2]; |
| 1232 | const curr_elem = values[0]; |
| 1233 | let match = curr_elem[prop]; |
| 1234 | let dim = curr_elem[other_prop]; |
| 1235 | let max_iter = 2 * editing_copy.length; |
| 1236 | let final_val = 0; |
| 1237 | while (editing_copy.length > 1 && max_iter > 0) { |
| 1238 | const filtered_array = editing_copy.filter((elem) => { |
| 1239 | return elem[prop] == match; |
| 1240 | }); |
| 1241 | if (filtered_array.length > 0) { |
| 1242 | iter++; |
| 1243 | const min_elem = d3.min(filtered_array, (elem) => { |
| 1244 | return elem[other_prop] as number; |
| 1245 | }); |
| 1246 | const max_elem = d3.max(filtered_array, (elem) => { |
| 1247 | return elem[other_prop] as number; |
| 1248 | }); |
| 1249 | if (min_elem < dim && max_elem > dim) { |
| 1250 | if (prop == 'y') { |
| 1251 | if (this.x_direction == 1) { |
| 1252 | final_val = max_elem; |
| 1253 | } else { |
| 1254 | final_val = min_elem; |
| 1255 | } |
| 1256 | } else { |
| 1257 | // There are elements greater than and lesser than |
| 1258 | // reference value. I am trying to see if there are |
| 1259 | // multiple elements greater or lesser. If there is |
| 1260 | // only one in one of the directions, that is the |
| 1261 | // direction I draw the line in. |
| 1262 | const lesser_arr = filtered_array.filter((elem) => { |
| 1263 | return elem[other_prop] < dim; |
| 1264 | }); |
| 1265 | const greater_arr = filtered_array.filter((elem) => { |
| 1266 | return elem[other_prop] > dim; |
| 1267 | }); |
| 1268 | |
| 1269 | if (lesser_arr.length == 1) { |
| 1270 | final_val = min_elem; |
| 1271 | } else if (greater_arr.length == 1) { |
| 1272 | final_val = max_elem; |
| 1273 | } else { |
| 1274 | final_val = d3.max(lesser_arr, (elem) => { |
| 1275 | return elem[other_prop] as number; |
| 1276 | }); |
| 1277 | } |