Changeset 8377:4247e84b8d0b in orange
 Timestamp:
 07/06/11 15:58:47 (3 years ago)
 Branch:
 default
 Convert:
 37320b10e09932a04b5fbfed2421cf9742b4b79c
 Location:
 orange/OrangeWidgets
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

orange/OrangeWidgets/OWGraph3D.py
r8375 r8377 285 285 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 286 286 287 for cmd, vao, vao_outlinein self.commands:287 for (cmd, params) in self.commands: 288 288 if cmd == 'scatter': 289 vao, vao_outline, array, labels = params 289 290 glUseProgram(self.color_shader) 290 291 glUniform1i(self.color_shader_face_symbols, self.face_symbols) … … 300 301 glBindVertexArray(0) 301 302 glUseProgram(0) 303 304 if labels != None: 305 for (x,y,z), label in zip(array, labels): 306 self.renderText(x,y,z, '{0:.2}'.format(label), font=self.labels_font) 302 307 303 308 glDisable(GL_BLEND) … … 544 549 if shapes == None: 545 550 shapes = [0 for _ in array] 546 # TODO: what if shapes are not integers?547 551 548 552 max, min = numpy.max(array, axis=0), numpy.min(array, axis=0) … … 553 557 self.normal_size = numpy.max(self.center  self.b_box[1]) / 100. 554 558 559 # TODO: more shapes? For now, wrap other to these ones. 560 different_shapes = [3, 4, 5, 8] 561 555 562 # Generate vertices for shapes and also indices for outlines. 556 563 vertices = [] … … 559 566 for (x,y,z), (r,g,b,a), size, shape in zip(array, colors, sizes, shapes): 560 567 sO2 = size * self.normal_size / 2. 561 n = 4 if shape % 2 == 0 else 4568 n = different_shapes[shape % len(different_shapes)] 562 569 angle_inc = 2.*pi / n 563 570 angle = angle_inc / 2. … … 629 636 self.vaos.append(vao) 630 637 self.vaos.append(vao_outline) 631 self.commands.append(("scatter", vao, vao_outline))638 self.commands.append(("scatter", [vao, vao_outline, array, labels])) 632 639 self.update_axes() 633 640 self.updateGL() 
orange/OrangeWidgets/Prototypes/OWScatterPlot3D.py
r8375 r8377 68 68 callback=self.on_axis_change, 69 69 indent = 10, 70 emptyString = '(Same shape)' 70 emptyString = '(Same shape)', 71 71 ) 72 72 … … 124 124 self.label_attr_cb.clear() 125 125 126 self.discrete_attrs = {} 127 126 128 if self.data is not None: 127 129 self.all_attrs = data.domain.variables + data.domain.getmetas().values() … … 134 136 self.label_attr_cb.addItem('(No labels)') 135 137 icons = OWGUI.getAttributeIcons() 136 for attr in self.axis_candidate_attrs:138 for (i, attr) in enumerate(self.axis_candidate_attrs): 137 139 self.x_attr_cb.addItem(icons[attr.varType], attr.name) 138 140 self.y_attr_cb.addItem(icons[attr.varType], attr.name) … … 141 143 self.size_attr_cb.addItem(icons[attr.varType], attr.name) 142 144 self.label_attr_cb.addItem(icons[attr.varType], attr.name) 145 if attr.varType == orange.VarTypes.Discrete: 146 self.discrete_attrs[len(self.discrete_attrs)+1] = (i, attr) 147 self.shape_attr_cb.addItem(icons[orange.VarTypes.Discrete], attr.name) 143 148 144 149 array, c, w = self.data.toNumpyMA() … … 166 171 167 172 def update_graph(self): 168 if self.data is None: 169 return 170 171 xInd, yInd, zInd = self.getAxesIndices() 172 X, Y, Z, mask = self.getAxisData(xInd, yInd, zInd) 173 174 if self.color_attr > 0: 175 color_attr = self.axis_candidate_attrs[self.color_attr  1] 176 C = self.data_array[:, self.color_attr  1] 177 if color_attr.varType == orange.VarTypes.Discrete: 178 palette = OWColorPalette.ColorPaletteHSV(len(color_attr.values)) 179 colors = [palette[int(value)] for value in C.ravel()] 180 colors = [[c.red()/255., c.green()/255., c.blue()/255., self.alpha_value/255.] for c in colors] 173 if self.data is None: 174 return 175 176 x_ind, y_ind, z_ind = self.get_axes_indices() 177 X, Y, Z, mask = self.get_axis_data(x_ind, y_ind, z_ind) 178 179 if self.color_attr > 0: 180 color_attr = self.axis_candidate_attrs[self.color_attr  1] 181 C = self.data_array[:, self.color_attr  1] 182 if color_attr.varType == orange.VarTypes.Discrete: 183 palette = OWColorPalette.ColorPaletteHSV(len(color_attr.values)) 184 colors = [palette[int(value)] for value in C.ravel()] 185 colors = [[c.red()/255., c.green()/255., c.blue()/255., self.alpha_value/255.] for c in colors] 186 else: 187 palette = OWColorPalette.ColorPaletteBW() 188 maxC, minC = numpy.max(C), numpy.min(C) 189 C = (C  minC) / (maxC  minC) 190 colors = [palette[value] for value in C.ravel()] 191 colors = [[c.red()/255., c.green()/255., c.blue()/255., self.alpha_value/255.] for c in colors] 181 192 else: 182 palette = OWColorPalette.ColorPaletteBW() 183 maxC, minC = numpy.max(C), numpy.min(C) 184 C = (C  minC) / (maxC  minC) 185 colors = [palette[value] for value in C.ravel()] 186 colors = [[c.red()/255., c.green()/255., c.blue()/255., self.alpha_value/255.] for c in colors] 187 else: 188 colors = "b" 189 190 if self.size_attr > 0: 191 size_attr = self.axis_candidate_attrs[self.size_attr  1] 192 S = self.data_array[:, self.size_attr  1] 193 if size_attr.varType == orange.VarTypes.Discrete: 194 sizes = [(v + 1) * len(size_attr.values) / (11  self.symbol_scale) for v in S] 193 colors = 'b' 194 195 if self.size_attr > 0: 196 size_attr = self.axis_candidate_attrs[self.size_attr  1] 197 S = self.data_array[:, self.size_attr  1] 198 if size_attr.varType == orange.VarTypes.Discrete: 199 sizes = [(v + 1) * len(size_attr.values) / (11  self.symbol_scale) for v in S] 200 else: 201 min, max = numpy.min(S), numpy.max(S) 202 sizes = [(v  min) * self.symbol_scale / (maxmin) for v in S] 195 203 else: 196 min, max = numpy.min(S), numpy.max(S) 197 sizes = [(v  min) * self.symbol_scale / (maxmin) for v in S] 198 else: 199 sizes = 1 200 201 self.graph.clear() 202 self.graph.scatter(X, Y, Z, colors, sizes) 203 self.graph.set_x_axis_title(self.axis_candidate_attrs[self.x_attr].name) 204 self.graph.set_x_axis_title(self.axis_candidate_attrs[self.y_attr].name) 205 self.graph.set_x_axis_title(self.axis_candidate_attrs[self.z_attr].name) 206 207 def getAxisData(self, xInd, yInd, zInd): 208 array = self.data_array 209 X, Y, Z = array[:, xInd], array[:, yInd], array[:, zInd] 210 return X, Y, Z, None 211 212 def getAxesIndices(self): 213 return self.x_attr, self.y_attr, self.z_attr 204 sizes = 1 205 206 shapes = None 207 if self.shape_attr > 0: 208 i,shape_attr = self.discrete_attrs[self.shape_attr] 209 if shape_attr.varType == orange.VarTypes.Discrete: 210 # Map discrete attribute to [0...num shapes1] 211 shapes = self.data_array[:, i] 212 num_shapes = 0 213 unique_shapes = {} 214 for shape in shapes: 215 if shape not in unique_shapes: 216 unique_shapes[shape] = num_shapes 217 num_shapes += 1 218 shapes = [unique_shapes[value] for value in shapes] 219 220 labels = None 221 if self.label_attr > 0: 222 label_attr = self.axis_candidate_attrs[self.label_attr  1] 223 labels = self.data_array[:, self.label_attr  1] 224 225 self.graph.clear() 226 self.graph.scatter(X, Y, Z, colors, sizes, shapes, labels) 227 self.graph.set_x_axis_title(self.axis_candidate_attrs[self.x_attr].name) 228 self.graph.set_x_axis_title(self.axis_candidate_attrs[self.y_attr].name) 229 self.graph.set_x_axis_title(self.axis_candidate_attrs[self.z_attr].name) 230 231 def get_axis_data(self, x_ind, y_ind, z_ind): 232 array = self.data_array 233 X, Y, Z = array[:, x_ind], array[:, y_ind], array[:, z_ind] 234 return X, Y, Z, None 235 236 def get_axes_indices(self): 237 return self.x_attr, self.y_attr, self.z_attr 214 238 215 239 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.