def draw_selected(self, dc): dc = wx.GCDC(dc) if len(self.selected_path_ids) > 0: paths = [] for id in self.selected_path_ids: item = self.data[id] path = [] for i in range(len(item) - 1): x0, x1 = i + 1, i + 2 y0, y1 = item[i], item[i + 1] seg = ((x0, y0), (x1, y1)) path.append(self.seg_dict[seg]) paths.append(path) DrawLines(dc, paths, edge_color=wx.Color(200, 200, 200), edge_thickness=2) key = id for key in self.data.keys(): item = self.data[key] t = len(item) if key in self.selected_path_ids: for i in range(t): if self.time_gstar_p[key][i] > 0.05: continue try: neighbors = self.time_neighbors[str(i)] except: neighbors = self.time_neighbors[i] if len(neighbors) == 0: continue if self.time_gstar_z[key][i] >= 0: color = wx.RED else: color = wx.BLUE path = [] for n_id in neighbors: j = int(n_id) if j > i: x0, x1 = j, j + 1 else: x0, x1 = j + 1, j + 2 y0, y1 = item[x0 - 1], item[x1 - 1] seg = ((x0, y0), (x1, y1)) path.append(self.seg_dict[seg]) DrawLines(dc, [path], edge_color=color, edge_thickness=2)
def plot_data(self,dc): y_ticks = self.yAxisScale.GetNiceTicks() # draw verticle time lines at background dc.SetFont(wx.Font(10,wx.NORMAL,wx.NORMAL,wx.NORMAL)) j = 0 for i in range(self.x_min, self.x_max+1): vtl_start_x, vtl_start_y = self.transform_coord_pt(i, y_ticks[0]) vtl_end_x, vtl_end_y = self.transform_coord_pt(i, y_ticks[-1]) dc.DrawLine(vtl_start_x, vtl_start_y, vtl_end_x, self.margin_top) lbl = "%s-%s"%(self.interval_labels[j][0],self.interval_labels[j][1]) j += 1 lbl_w,lbl_h = dc.GetTextExtent(lbl) #dc.DrawText(lbl, vtl_end_x - lbl_w/2.0, vtl_start_y+8) dc.DrawRotatedText(lbl, vtl_start_x - lbl_w/1.414, vtl_start_y+lbl_w/1.414+4,45) x_label = "Time Interval" x_lbl_w, x_lbl_h = dc.GetTextExtent(x_label) center_x = max(self.margin_left + self.ax_width/2.0 - x_lbl_w/2.0, self.margin_left) dc.DrawText(x_label, center_x, self.bufferHeight - x_lbl_h - 8) # plots data pen = wx.BLACK_PEN pen.SetStyle(wx.SOLID) dc.SetPen(pen) paths = [] self.local_paths = [] self.seg_dict = {} for key in self.data.keys(): item = self.data[key] path = [] local_path = [] for i in range(len(item)-1): x0, x1 = i +1, i+2 y0, y1 = item[i], item[i+1] seg = ((x0,y0),(x1,y1)) if seg in self.seg_dict: path.append(self.seg_dict[seg]) else: x0,y0 = seg[0] x1,y1 = seg[1] x0,y0 = self.transform_coord_pt(x0,y0) x1,y1 = self.transform_coord_pt(x1,y1) path.append((x0,y0,x1,y1)) self.seg_dict[seg] = (x0,y0,x1,y1) local_path.append(seg) paths.append(path) self.local_paths.append([local_path,min(item),max(item)]) """ DrawLines(dc,paths, data_group=self.id_group, fill_color_group=self.color_group, edge_thickness=2, opaque=255) """ DrawLines(dc, paths)
def draw_selected(self,dc): dc = wx.GCDC(dc) if len(self.selected_path_ids) > 0: for id in self.selected_path_ids: item = self.data[id] path = [] for i in range(len(item)-1): x0, x1 = i +1, i+2 y0, y1 = item[i], item[i+1] seg = ((x0,y0),(x1,y1)) path.append(self.seg_dict[seg]) DrawLines(dc,[path], edge_color=wx.RED,edge_thickness=2)
def draw_selected(self, dc): """ """ dc = wx.GCDC(dc) if len(self.selected_path_ids) > 0: paths = [] for id in self.selected_path_ids: item = self.data[id] path = [] for i in range(len(item) - 1): x0, x1 = i + 1, i + 2 y0, y1 = item[i], item[i + 1] seg = ((x0, y0), (x1, y1)) path.append(self.seg_dict[seg]) paths.append(path) DrawLines(dc, paths, edge_color=wx.Color(200, 200, 200), edge_thickness=2) key = id for key in self.data.keys(): item = self.data[key] t = len(item) ml = self.localMorans[key] sigFlag = ml[2] clusterFlag = ml[3] if key not in self.selected_path_ids: continue dc.SetPen(wx.BLACK_PEN) for i in range(t): if str(i) not in self.timeNeighbors: self.ShowMsgBox("Time weights not valid.") return try: neighbors = self.timeNeighbors[str(i)] except: neighbors = self.timeNeighbors[i] if sigFlag[i] == 0: continue cluster = clusterFlag[i] if cluster == 0: color = stars.LISA_NOT_SIG_COLOR elif cluster == 1: color = stars.LISA_HH_COLOR elif cluster == 2: color = stars.LISA_LL_COLOR elif cluster == 3: color = stars.LISA_LH_COLOR elif cluster == 4: color = stars.LISA_HL_COLOR elif cluster == 5: color = stars.LISA_OBSOLETE_COLOR path = [] for n_id in neighbors: j = int(n_id) if j > i: x0, x1 = j, j + 1 else: x0, x1 = j + 1, j + 2 y0, y1 = item[x0 - 1], item[x1 - 1] seg = ((x0, y0), (x1, y1)) path.append(self.seg_dict[seg]) DrawLines(dc, [path], edge_color=color, edge_thickness=2) # draw with line mark if self.selected_line != None: vline = self.verticle_lines[self.selected_line] try: neighbors = self.timeNeighbors[str(self.selected_line)] except: neighbors = self.timeNeighbors[self.selected_line] left_neigh = None right_neigh = None for n_id in neighbors: j = int(n_id) if left_neigh == None or j < left_neigh: left_neigh = j if right_neigh == None or j > right_neigh: right_neigh = j if right_neigh < self.selected_line: right_neigh = self.selected_line if left_neigh > self.selected_line: left_neigh = self.selected_line if left_neigh == None or right_neigh == None: return left_x = self.verticle_lines[left_neigh][0] right_x = self.verticle_lines[right_neigh][0] height = self.verticle_lines[left_neigh][ 1] - self.verticle_lines[left_neigh][3] dc.SetPen(wx.TRANSPARENT_PEN) dc.SetBrush(wx.Brush(wx.Color(245, 245, 245))) dc.DrawRectangle(left_x - 10, vline[3], right_x - left_x + 20, height) dc.SetPen(wx.BLACK_PEN) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.DrawRectangle(left_x, vline[3], right_x - left_x, height) dc.SetBrush(wx.BLACK_BRUSH) dc.SetPen(wx.Pen(wx.Color(250, 250, 250))) for j in range(left_neigh + 1, right_neigh): ln = self.verticle_lines[j] dc.DrawLine(ln[0], ln[1], ln[2], ln[3]) dc.SetBrush(wx.BLACK_BRUSH) dc.SetPen(wx.Pen(wx.Color(255, 255, 0), 5)) dc.DrawLine(vline[0], vline[1], vline[2], vline[3]) dc.SetPen(wx.BLACK_PEN) for key in self.data.keys(): if key not in self.selected_path_ids: continue item = self.data[key] t = len(item) ml = self.localMorans[key] sigFlag = ml[2] clusterFlag = ml[3] dc.SetPen(wx.BLACK_PEN) for i in range(t): if i != self.selected_line: continue try: neighbors = self.timeNeighbors[str(i)] except: neighbors = self.timeNeighbors[i] #if sigFlag[i] == 0: # continue cluster = clusterFlag[i] if cluster == 0: color = wx.Color(220, 220, 220) #stars.LISA_NOT_SIG_COLOR elif cluster == 1: color = stars.LISA_HH_COLOR elif cluster == 2: color = stars.LISA_LL_COLOR elif cluster == 3: color = stars.LISA_LH_COLOR elif cluster == 4: color = stars.LISA_HL_COLOR elif cluster == 5: color = stars.LISA_OBSOLETE_COLOR path = [] for n_id in neighbors: j = int(n_id) if j > i: x0, x1 = j, j + 1 else: x0, x1 = j + 1, j + 2 y0, y1 = item[x0 - 1], item[x1 - 1] seg = ((x0, y0), (x1, y1)) path.append(self.seg_dict[seg]) DrawLines(dc, [path], edge_color=color, edge_thickness=2)
def plot_data(self, dc): y_ticks = self.yAxisScale.GetNiceTicks() # draw verticle time lines at background dc.SetFont( wx.Font(self.font_size_y_axis, wx.ROMAN, wx.NORMAL, wx.NORMAL)) if os.name == 'posix': dc.SetFont( wx.Font(self.font_size_y_axis + 2, wx.ROMAN, wx.NORMAL, wx.NORMAL)) self.line_marker = [] self.verticle_lines = [] for i in range(self.x_min, self.x_max + 1): if i == self.x_min or i == self.x_max: dc.SetPen(wx.BLACK_PEN) else: dc.SetPen(wx.Pen(wx.Color(200, 200, 200))) vtl_start_x, vtl_start_y = self.transform_coord_pt(i, y_ticks[0]) vtl_end_x, vtl_end_y = self.transform_coord_pt(i, y_ticks[-1]) dc.DrawLine(vtl_start_x, vtl_start_y, vtl_end_x, self.margin_top) self.verticle_lines.append( (vtl_start_x, vtl_start_y, vtl_end_x, self.margin_top)) # draw triangle line marker x, y = vtl_end_x, vtl_end_y - 3 mark_w = 5 x1, y1 = vtl_end_x - mark_w, y x2, y2 = vtl_end_x + mark_w, y x3, y3 = vtl_end_x + mark_w, y - mark_w * 2 x4, y4 = vtl_end_x - mark_w, y - mark_w * 2 self.line_marker.append([(x1, y1), (x3, y3)]) dc.SetPen(wx.TRANSPARENT_PEN) dc.SetBrush(wx.RED_BRUSH) dc.DrawPolygon([(x, y), (x3, y3), (x4, y4), (x, y)]) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetPen(wx.BLACK_PEN) lbl = "%s-%s" % (self.interval_labels[i - 1][0], self.interval_labels[i - 1][1]) lbl_w, lbl_h = dc.GetTextExtent(lbl) #dc.DrawText(lbl, vtl_end_x - lbl_w/2.0, vtl_start_y+8) dc.DrawRotatedText(lbl, vtl_start_x - lbl_w / 1.414, vtl_start_y + lbl_w / 1.414 + 4, 45) x_label = "Time Interval" x_lbl_w, x_lbl_h = dc.GetTextExtent(x_label) center_x = max(self.margin_left + self.ax_width / 2.0 - x_lbl_w / 2.0, self.margin_left) dc.DrawText(x_label, center_x, self.bufferHeight - x_lbl_h - 38) # draw legend dc.SetFont( wx.Font(stars.LISA_SPACE_LEGEND_FONT_SIZE, wx.ROMAN, wx.NORMAL, wx.NORMAL)) if os.name == 'posix': dc.SetFont( wx.Font(stars.LISA_SPACE_LEGEND_FONT_SIZE + 2, wx.ROMAN, wx.NORMAL, wx.NORMAL)) dc.SetPen(wx.BLACK_PEN) y = self.bufferHeight - 14 x = 1 colors = [ wx.Color(180, 180, 180), stars.LISA_HH_COLOR, stars.LISA_LL_COLOR, stars.LISA_LH_COLOR, stars.LISA_HL_COLOR, stars.LISA_OBSOLETE_COLOR ] labels = [ "Not significant", "High-High", "Low-Low", "Low-High", "High-Low", "Neighborless" ] for i in range(len(colors)): clr = colors[i] lbl = labels[i] dc.SetBrush(wx.Brush(clr)) dc.DrawRectangle(x, y, 12, 12) x += 12 + 1 dc.DrawText(lbl, x, y) lbl_w, lbl_h = dc.GetTextExtent(lbl) x += lbl_w + 2 x += 2 dc.SetBrush(wx.RED_BRUSH) dc.DrawPolygon([(x, y), (x + 12, y), (x + 6, y + 12), (x, y)]) x += 14 dc.DrawText("Click to show Core+Neighbors", x, y) # plots data paths = [] self.local_paths = [] self.seg_dict = {} for key in self.data.keys(): item = self.data[key] path = [] local_path = [] for i in range(len(item) - 1): x0, x1 = i + 1, i + 2 y0, y1 = item[i], item[i + 1] seg = ((x0, y0), (x1, y1)) if seg in self.seg_dict: path.append(self.seg_dict[seg]) else: x0, y0 = seg[0] x1, y1 = seg[1] x0, y0 = self.transform_coord_pt(x0, y0) x1, y1 = self.transform_coord_pt(x1, y1) path.append((x0, y0, x1, y1)) self.seg_dict[seg] = (x0, y0, x1, y1) local_path.append(seg) paths.append(path) self.local_paths.append([local_path, min(item), max(item)]) DrawLines(dc, paths, edge_thickness=1, edge_color=wx.Color(240, 240, 240)) # draw initial highlights if len(self.highlight_ids) > 0: self.selected_path_ids = self.highlight_ids self.draw_selected(dc)
def draw_selected(self, dc): dc = wx.GCDC(dc) if len(self.selected_path_ids) > 0: paths = [] for id in self.selected_path_ids: item = self.data[id] path = [] for i in range(len(item) - 1): x0, x1 = i + 1, i + 2 y0, y1 = item[i], item[i + 1] seg = ((x0, y0), (x1, y1)) path.append(self.seg_dict[seg]) paths.append(path) DrawLines(dc, paths, edge_color=wx.Color(200, 200, 200), edge_thickness=2) key = id for key in self.data.keys(): item = self.data[key] t = len(item) if key in self.selected_path_ids: for i in range(t): if self.time_gstar_p[key][i] > 0.05: continue try: neighbors = self.time_neighbors[str(i)] except: neighbors = self.time_neighbors[i] if len(neighbors) == 0: continue if self.time_gstar_z[key][i] >= 0: color = wx.RED else: color = wx.BLUE path = [] for n_id in neighbors: j = int(n_id) if j > i: x0, x1 = j, j + 1 else: x0, x1 = j + 1, j + 2 y0, y1 = item[x0 - 1], item[x1 - 1] seg = ((x0, y0), (x1, y1)) path.append(self.seg_dict[seg]) DrawLines(dc, [path], edge_color=color, edge_thickness=2) # draw with line mark if self.selected_line != None: vline = self.verticle_lines[self.selected_line] try: neighbors = self.time_neighbors[str(self.selected_line)] except: neighbors = self.time_neighbors[self.selected_line] left_neigh = None right_neigh = None for n_id in neighbors: j = int(n_id) if left_neigh == None or j < left_neigh: left_neigh = j if right_neigh == None or j > right_neigh: right_neigh = j if right_neigh < self.selected_line: right_neigh = self.selected_line if left_neigh > self.selected_line: left_neigh = self.selected_line left_x = self.verticle_lines[left_neigh][0] right_x = self.verticle_lines[right_neigh][0] height = self.verticle_lines[left_neigh][ 1] - self.verticle_lines[left_neigh][3] dc.SetPen(wx.TRANSPARENT_PEN) dc.SetBrush(wx.Brush(wx.Color(245, 245, 245))) dc.DrawRectangle(left_x - 10, vline[3], right_x - left_x + 20, height) dc.SetPen(wx.BLACK_PEN) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.DrawRectangle(left_x, vline[3], right_x - left_x, height) dc.SetBrush(wx.BLACK_BRUSH) dc.SetPen(wx.Pen(wx.Color(250, 250, 250))) for j in range(left_neigh + 1, right_neigh): ln = self.verticle_lines[j] dc.DrawLine(ln[0], ln[1], ln[2], ln[3]) dc.SetBrush(wx.BLACK_BRUSH) dc.SetPen(wx.Pen(wx.Color(255, 255, 0), 5)) dc.DrawLine(vline[0], vline[1], vline[2], vline[3]) dc.SetPen(wx.BLACK_PEN) for key in self.data.keys(): item = self.data[key] t = len(item) dc.SetPen(wx.BLACK_PEN) if key not in self.selected_path_ids: continue for i in range(t): if i != self.selected_line: continue try: neighbors = self.time_neighbors[str(i)] except: neighbors = self.time_neighbors[i] if self.time_gstar_z[key][i] >= 0: color = wx.RED else: color = wx.BLUE path = [] for n_id in neighbors: j = int(n_id) if j > i: x0, x1 = j, j + 1 else: x0, x1 = j + 1, j + 2 y0, y1 = item[x0 - 1], item[x1 - 1] seg = ((x0, y0), (x1, y1)) path.append(self.seg_dict[seg]) DrawLines(dc, [path], edge_color=color, edge_thickness=2)
def plot_data(self, dc): y_ticks = self.yAxisScale.GetNiceTicks() # draw verticle time lines at background dc.SetFont( wx.Font(self.font_size_y_axis, wx.NORMAL, wx.NORMAL, wx.NORMAL)) if os.name == 'posix': dc.SetFont( wx.Font(self.font_size_y_axis + 2, wx.NORMAL, wx.NORMAL, wx.NORMAL)) for i in range(self.x_min, self.x_max + 1): if i == self.x_min or i == self.x_max: dc.SetPen(wx.BLACK_PEN) else: dc.SetPen(wx.Pen(wx.Color(200, 200, 200))) vtl_start_x, vtl_start_y = self.transform_coord_pt(i, y_ticks[0]) vtl_end_x, vtl_end_y = self.transform_coord_pt(i, y_ticks[-1]) dc.DrawLine(vtl_start_x, vtl_start_y, vtl_end_x, self.margin_top) lbl = 't' + str(i) lbl_w, lbl_h = dc.GetTextExtent(lbl) dc.DrawText(lbl, vtl_end_x - lbl_w / 2.0, vtl_start_y + 8) # draw legend dc.SetFont( wx.Font(stars.LISA_SPACE_LEGEND_FONT_SIZE, wx.NORMAL, wx.NORMAL, wx.NORMAL)) if os.name == 'posix': dc.SetFont( wx.Font(stars.LISA_SPACE_LEGEND_FONT_SIZE + 2, wx.NORMAL, wx.NORMAL, wx.NORMAL)) dc.SetPen(wx.BLACK_PEN) y = self.bufferHeight - 18 x = 6 colors = [ wx.Color(180, 180, 180), stars.LISA_HH_COLOR, stars.LISA_LL_COLOR ] labels = ["Not significant", "High-High", "Low-Low"] for i in range(len(colors)): clr = colors[i] lbl = labels[i] dc.SetBrush(wx.Brush(clr)) dc.DrawRectangle(x, y, 12, 12) x += 12 + 1 dc.DrawText(lbl, x, y) lbl_w, lbl_h = dc.GetTextExtent(lbl) x += lbl_w + 2 # plots data paths = [] self.local_paths = [] self.seg_dict = {} for key in self.data.keys(): item = self.data[key] path = [] local_path = [] for i in range(len(item) - 1): x0, x1 = i + 1, i + 2 y0, y1 = item[i], item[i + 1] seg = ((x0, y0), (x1, y1)) if seg in self.seg_dict: path.append(self.seg_dict[seg]) else: x0, y0 = seg[0] x1, y1 = seg[1] x0, y0 = self.transform_coord_pt(x0, y0) x1, y1 = self.transform_coord_pt(x1, y1) path.append((x0, y0, x1, y1)) self.seg_dict[seg] = (x0, y0, x1, y1) local_path.append(seg) paths.append(path) self.local_paths.append([local_path, min(item), max(item)]) DrawLines(dc, paths, edge_thickness=1, edge_color=wx.Color(240, 240, 240)) # draw initial highlights if len(self.highlight_ids) > 0: self.selected_path_ids = self.highlight_ids self.draw_selected(dc)
def draw_selected(self, dc): dc = wx.GCDC(dc) if len(self.selected_path_ids) > 0: paths = [] for id in self.selected_path_ids: item = self.data[id] path = [] for i in range(len(item) - 1): x0, x1 = i + 1, i + 2 y0, y1 = item[i], item[i + 1] seg = ((x0, y0), (x1, y1)) path.append(self.seg_dict[seg]) paths.append(path) DrawLines(dc, paths, edge_color=wx.Color(200, 200, 200), edge_thickness=2) key = id for key in self.data.keys(): item = self.data[key] t = len(item) ml = self.localMorans[key] sigFlag = ml[2] clusterFlag = ml[3] if key not in self.selected_path_ids: continue dc.SetPen(wx.BLACK_PEN) for i in range(t): if str(i) not in self.timeNeighbors: self.ShowMsgBox("Time weights not valid.") return try: neighbors = self.timeNeighbors[str(i)] except: neighbors = self.timeNeighbors[i] if sigFlag[i] == 0: continue cluster = clusterFlag[i] if cluster == 0: color = stars.LISA_NOT_SIG_COLOR elif cluster == 1: color = stars.LISA_HH_COLOR elif cluster == 2: color = stars.LISA_LL_COLOR elif cluster == 3: color = stars.LISA_LH_COLOR elif cluster == 4: color = stars.LISA_HL_COLOR elif cluster == 5: color = stars.LISA_OBSOLETE_COLOR path = [] for n_id in neighbors: j = int(n_id) if j > i: x0, x1 = j, j + 1 else: x0, x1 = j + 1, j + 2 y0, y1 = item[x0 - 1], item[x1 - 1] seg = ((x0, y0), (x1, y1)) path.append(self.seg_dict[seg]) DrawLines(dc, [path], edge_color=color, edge_thickness=2)