Beispiel #1
0
    def sendReport(self):
        if not self.data:
            return

        self.reportData(self.data)
        self.reportSettings("Visualization",
                    [("Symbol shape/size", self.eventAtt),
                     ("Normalized", OWGUI.YesNo[self.normalizeEvent]),
                     ("Label", self.labelAtt),
                     ("Grouping", self.groupAtt),
                     ("Time", self.timeAtt),
                     ("Time scale", self.timeScales[self.timeScale][0] if self.timeScale<len(self.timeScales) else ("Custom, "+self.customTimeRange if self.timeScale>len(self.timeScales) else "Entire range")),
                     ("Time jittering", "%i pixels" % self.jitteringAmounts[self.jitteringAmount] if self.jitteringAmount else "None"),
                     ("Aggregate data within time scale", OWGUI.YesNo[self.wrapTime]),
                     ])

        self.reportSection("Timeline")
        groups, times, canvas = self.groupscanvas, self.timecanvas, self.canvas
        if canvas.width()+groups.width() > 10000:
            self.reportRaw("<p>Figure is too wide for the report.</p>")
            return
            
        if self.eventAtt and self.data.domain[self.eventAtt].varType == orange.VarTypes.Discrete:
            self.reportImage(lambda *x: OWChooseImageSizeDlg(self.legendcanvas).saveImage(*x))

        painter = QPainter()
        buffer = QPixmap(groups.width()+canvas.width(), times.height()+canvas.height())
        painter.begin(buffer)
        painter.setRenderHints(QPainter.Antialiasing | QPainter.TextAntialiasing)
        painter.fillRect(buffer.rect(), QBrush(QColor(255, 255, 255)))
        groups.render(painter, QRectF(0, times.height(), groups.width(), groups.height()))
        times.render(painter, QRectF(groups.width(), 0, times.width(), times.height()))
        canvas.render(painter, QRectF(groups.width(), times.height(), canvas.width(), canvas.height()))
        painter.end()
        self.reportImage(lambda filename: buffer.save(filename, os.path.splitext(filename)[1][1:]))
Beispiel #2
0
    def sendReport(self):
        from PyQt4.QtSvg import QSvgGenerator
        if self.tree:
            self.reportSection("Tree")
            urlfn, filefn = self.getUniqueImageName(ext=".svg")
            svg = QSvgGenerator()
            svg.setFileName(filefn)
            ssize = self.scene.sceneRect().size()
            w, h = ssize.width(), ssize.height()
            fact = 600 / w
            svg.setSize(QSize(600, h * fact))
            painter = QPainter()
            painter.begin(svg)
            self.scene.render(painter)
            painter.end()

            #            buffer = QPixmap(QSize(600, h*fact))
            #            painter.begin(buffer)
            #            painter.fillRect(buffer.rect(), QBrush(QColor(255, 255, 255)))
            #            self.scene.render(painter)
            #            painter.end()
            #            self.reportImage(lambda filename: buffer.save(filename, os.path.splitext(filename)[1][1:]))
            from OWDlgs import OWChooseImageSizeDlg
            self.reportImage(OWChooseImageSizeDlg(self.scene).saveImage)
            self.reportRaw(
                '<!--browsercode<br/>(Click <a href="%s">here</a> to view or download this image in a scalable vector format)-->'
                % urlfn)
 def sendReport(self):
     if self.dataset:
         self.startReport("%s [%s]" %
                          (self.windowTitle(), self.canvas.attr.name))
         self.reportImage(
             lambda *x: OWChooseImageSizeDlg(self.canvas).saveImage(*x))
     else:
         self.startReport(self.windowTitle())
    def saveGraph(self):
        sizeDlg = OWChooseImageSizeDlg(self.dendrogram, parent=self)
        filename = sizeDlg.getFileName(
            "graph",
            "Portable Network Graphics (*.PNG);;"
            "Windows Bitmap (*.BMP);;"
            "Graphics Interchange Format (*.GIF);;"
            "Scalable Vector Graphics (*.SVG)",
            ".png",
        )

        if not filename:
            return

        _, ext = os.path.splitext(filename)
        ext = ext.lower()

        canvases = (self.headerView.scene(), self.dendrogramView.scene(), self.footerView.scene())
        width = max([c.width() for c in canvases])
        height = sum([c.height() for c in canvases])

        size = QSize(width, height)

        if ext == ".svg":
            device = QSvgGenerator()
            device.setTitle("Dendrogram Plot")
            device.setFileName(filename)
            device.setSize(size)
            device.setViewBox(QRect(QPoint(0, 0), size))
        else:
            device = QPixmap(size)
            device.fill(Qt.white)

        painter = QPainter()
        painter.begin(device)
        painter.setRenderHint(QPainter.Antialiasing)

        self.renderDendrogram(painter)
        painter.end()

        if ext != ".svg":
            device.save(filename)
 def sendReport(self):
     self.startReport("%s [%s, %s]" %
                      (self.windowTitle(), self.attrX, self.attrY))
     self.reportSettings(
         "",
         [("X-Attribute", self.attrX),
          ("Y-Attribute", self.attrY), self.attrCondition != "(None)" and
          ("Condition", "%s = '%s'" %
           (self.attrCondition, self.attrConditionValue))])
     self.reportImage(
         lambda *x: OWChooseImageSizeDlg(self.canvas).saveImage(*x))
    def saveGraph(self):
        sizeDlg = OWChooseImageSizeDlg(self.dendrogram, parent=self)
        filename = sizeDlg.getFileName(
            "graph", "Portable Network Graphics (*.PNG);;"
            "Windows Bitmap (*.BMP);;"
            "Graphics Interchange Format (*.GIF);;"
            "Scalable Vector Graphics (*.SVG)", ".png")

        if not filename:
            return

        _, ext = os.path.splitext(filename)
        ext = ext.lower()

        canvases = (self.headerView.scene(), self.dendrogramView.scene(),
                    self.footerView.scene())
        width = max([c.width() for c in canvases])
        height = sum([c.height() for c in canvases])

        size = QSize(width, height)

        if ext == ".svg":
            device = QSvgGenerator()
            device.setTitle("Dendrogram Plot")
            device.setFileName(filename)
            device.setSize(size)
            device.setViewBox(QRect(QPoint(0, 0), size))
        else:
            device = QPixmap(size)
            device.fill(Qt.white)

        painter = QPainter()
        painter.begin(device)
        painter.setRenderHint(QPainter.Antialiasing)

        self.renderDendrogram(painter)
        painter.end()

        if ext != ".svg":
            device.save(filename)
Beispiel #7
0
 def sendReport(self):
     self.reportSettings("Visual settings", [
         ("Background", self.drawModes[self.scene.drawMode] +
          (" - " + self.componentCombo.currentText()
           if self.scene.drawMode == 2 else "")),
         ("Histogram", ["data from training set", "data from input subset"
                        ][self.inputSet] if self.histogram else "none"),
         ("Coloring", "%s for %s" %
          (["pie chart", "majority value", "majority value probability"
            ][self.discHistMode], self.attributeCombo.currentText()))
     ])
     self.reportSection("Plot")
     self.reportImage(OWChooseImageSizeDlg(self.scene).saveImage)
Beispiel #8
0
 def saveToFile(self):
     from OWDlgs import OWChooseImageSizeDlg
     dlg = OWChooseImageSizeDlg(self.graph)
     dlg.exec_()
Beispiel #9
0
 def saveGraph(self):
     sizeDlg = OWChooseImageSizeDlg(self.dendrogram, parent=self)
     sizeDlg.exec_()
 def saveGraph(self, fileName = None):
     from OWDlgs import OWChooseImageSizeDlg
     dlg = OWChooseImageSizeDlg(self.scene, [("Save as Dot Tree File (.dot)", self.saveDot)], parent=self)
     dlg.exec_()
Beispiel #11
0
 def saveToFile(self, extraButtons = []):
     sizeDlg = OWChooseImageSizeDlg(self, extraButtons, parent=self)
     sizeDlg.exec_()
Beispiel #12
0
 def saveGraph(self, fileName=None):
     from OWDlgs import OWChooseImageSizeDlg
     dlg = OWChooseImageSizeDlg(
         self.scene, [("Save as Dot Tree File (.dot)", self.saveDot)],
         parent=self)
     dlg.exec_()
Beispiel #13
0
 def saveToFileDirect(self, fileName, size = None):
     sizeDlg = OWChooseImageSizeDlg(self)
     sizeDlg.saveImage(fileName, size)
 def saveToFileCanvas(self):
     sizeDlg = OWChooseImageSizeDlg(self.canvas, parent=self)
     sizeDlg.exec_()
Beispiel #15
0
 def saveGraph(self):
     sizeDlg = OWChooseImageSizeDlg(self.scene)
     sizeDlg.exec_()
Beispiel #16
0
 def saveScene(self):
     from OWDlgs import OWChooseImageSizeDlg
     sizeDlg = OWChooseImageSizeDlg(self.scene, parent=self)
     sizeDlg.exec_()
Beispiel #17
0
 def saveToFileCanvas(self):
     sizeDlg = OWChooseImageSizeDlg(self.canvas, parent=self)
     sizeDlg.exec_()
Beispiel #18
0
 def saveToFile(self, extraButtons=[]):
     sizeDlg = OWChooseImageSizeDlg(self, extraButtons, parent=self)
     sizeDlg.exec_()
 def saveToFile(self):
     from OWDlgs import OWChooseImageSizeDlg
     dlg = OWChooseImageSizeDlg(self.graph)
     dlg.exec_()
Beispiel #20
0
 def saveScene(self):
     from OWDlgs import OWChooseImageSizeDlg
     sizeDlg = OWChooseImageSizeDlg(self.scene, parent=self)
     sizeDlg.exec_()
Beispiel #21
0
 def sendReport(self):
     self.startReport("%s" % (self.windowTitle()))
     self.reportImage(
         lambda *x: OWChooseImageSizeDlg(self.canvas).saveImage(*x))
Beispiel #22
0
 def saveToFileDirect(self, fileName, size=None):
     sizeDlg = OWChooseImageSizeDlg(self)
     sizeDlg.saveImage(fileName, size)
Beispiel #23
0
    def __init__(self, parent=None, signalManager=None):
        #        self.callbackDeposit = [] # deposit for OWGUI callback function
        OWWidget.__init__(self,
                          parent,
                          signalManager,
                          'Distance Map',
                          wantGraph=True)

        self.inputs = [("Distance Matrix", orange.SymMatrix, self.setMatrix)]
        self.outputs = [("Examples", ExampleTable),
                        ("Attribute List", orange.VarList)]

        self.clicked = False
        self.offsetX = 5
        self.offsetY = 5
        self.imageWidth = 0
        self.imageHeight = 0
        self.distanceImage = None
        self.legendImage = None
        self.colorSettings = None
        self.selectedSchemaIndex = 0

        self.palette = None

        self.shiftPressed = False

        #set default settings
        self.CellWidth = 15
        self.CellHeight = 15
        self.Merge = 1
        self.savedMerge = self.Merge
        self.Gamma = 1
        self.Grid = 1
        self.savedGrid = 1
        self.CutLow = 0
        self.CutHigh = 0
        self.CutEnabled = 0
        self.Sort = 0
        self.SquareCells = 0
        self.ShowLegend = 1
        self.ShowLabels = 1
        self.ShowBalloon = 1
        self.ShowItemsInBalloon = 1
        self.SendOnRelease = 1

        self.loadSettings()

        self.maxHSize = 30
        self.maxVSize = 30
        self.sorting = [("No sorting", self.sortNone),
                        ("Adjacent distance", self.sortAdjDist),
                        ("Random order", self.sortRandom),
                        ("Clustering", self.sortClustering),
                        ("Clustering with ordered leafs",
                         self.sortClusteringOrdered)]

        self.matrix = self.order = None
        self.rootCluster = None

        # GUI definition
        self.tabs = OWGUI.tabWidget(self.controlArea)

        # SETTINGS TAB
        tab = OWGUI.createTabPage(self.tabs, "Settings")
        box = OWGUI.widgetBox(tab, "Cell Size (Pixels)")
        OWGUI.qwtHSlider(box,
                         self,
                         "CellWidth",
                         label='Width: ',
                         labelWidth=38,
                         minValue=1,
                         maxValue=self.maxHSize,
                         step=1,
                         precision=0,
                         callback=[
                             lambda f="CellWidth", t="CellHeight": self.
                             adjustCellSize(f, t), self.drawDistanceMap,
                             self.manageGrid
                         ])
        OWGUI.qwtHSlider(box,
                         self,
                         "CellHeight",
                         label='Height: ',
                         labelWidth=38,
                         minValue=1,
                         maxValue=self.maxVSize,
                         step=1,
                         precision=0,
                         callback=[
                             lambda f="CellHeight", t="CellWidth": self.
                             adjustCellSize(f, t), self.drawDistanceMap,
                             self.manageGrid
                         ])
        OWGUI.checkBox(box,
                       self,
                       "SquareCells",
                       "Cells as squares",
                       callback=[self.setSquares, self.drawDistanceMap])
        self.gridChkBox = OWGUI.checkBox(
            box,
            self,
            "Grid",
            "Show grid",
            callback=self.createDistanceMap,
            disabled=lambda: min(self.CellWidth, self.CellHeight
                                 ) <= c_smallcell)

        OWGUI.separator(tab)
        OWGUI.qwtHSlider(tab,
                         self,
                         "Merge",
                         box="Merge",
                         label='Elements:',
                         labelWidth=50,
                         minValue=1,
                         maxValue=100,
                         step=1,
                         callback=self.createDistanceMap,
                         ticks=0)

        OWGUI.separator(tab)
        self.labelCombo = OWGUI.comboBox(
            tab,
            self,
            "Sort",
            box="Sort",
            items=[x[0] for x in self.sorting],
            tooltip="Sorting method for items in distance matrix.",
            callback=self.sortItems)
        OWGUI.rubber(tab)

        ##        self.tabs.insertTab(tab, "Settings")

        # FILTER TAB
        tab = OWGUI.createTabPage(self.tabs, "Colors")
        box = OWGUI.widgetBox(tab, "Color settings", addSpace=True)
        OWGUI.widgetLabel(box, "Gamma")
        OWGUI.qwtHSlider(box,
                         self,
                         "Gamma",
                         minValue=0.1,
                         maxValue=1,
                         step=0.1,
                         maxWidth=100,
                         callback=self.drawDistanceMap)

        OWGUI.separator(box)

        OWGUI.checkBox(box,
                       self,
                       'CutEnabled',
                       "Enable thresholds",
                       callback=self.setCutEnabled)
        self.sliderCutLow = OWGUI.qwtHSlider(box,
                                             self,
                                             'CutLow',
                                             label='Low:',
                                             labelWidth=33,
                                             minValue=-100,
                                             maxValue=0,
                                             step=0.1,
                                             precision=1,
                                             ticks=0,
                                             maxWidth=80,
                                             callback=self.drawDistanceMap)
        self.sliderCutHigh = OWGUI.qwtHSlider(box,
                                              self,
                                              'CutHigh',
                                              label='High:',
                                              labelWidth=33,
                                              minValue=0,
                                              maxValue=100,
                                              step=0.1,
                                              precision=1,
                                              ticks=0,
                                              maxWidth=80,
                                              callback=self.drawDistanceMap)
        if not self.CutEnabled:
            self.sliderCutLow.box.setDisabled(1)
            self.sliderCutHigh.box.setDisabled(1)

##        self.colorPalette = ColorPalette(box, self, "",
##                         additionalColors =["Cell outline", "Selected cells"],
##                         callback = self.setColor)
##        box.layout().addWidget(self.colorPalette)
        box = OWGUI.widgetBox(box, "Colors", orientation="horizontal")
        self.colorCombo = OWColorPalette.PaletteSelectorComboBox(self)
        try:
            self.colorCombo.setPalettes("palette", self.createColorDialog())
        except Exception as ex:
            print(
                ex,
                "Error loading saved color palettes!\nCreating new default palette!",
                file=sys.stderr)
            self.colorSettings = None
            self.colorCombo.setPalettes("palette", self.createColorDialog())
        self.colorCombo.setCurrentIndex(self.selectedSchemaIndex)
        self.connect(self.colorCombo, SIGNAL("activated(int)"), self.setColor)
        box.layout().addWidget(self.colorCombo, 2)
        OWGUI.button(box,
                     self,
                     "Edit colors",
                     callback=self.openColorDialog,
                     debuggingEnabled=0)
        OWGUI.rubber(tab)

        self.setColor(self.selectedSchemaIndex)

        ##        self.tabs.insertTab(tab, "Colors")

        # INFO TAB
        tab = OWGUI.createTabPage(self.tabs, "Info")
        box = OWGUI.widgetBox(tab, "Annotation && Legends")
        OWGUI.checkBox(box,
                       self,
                       'ShowLegend',
                       'Show legend',
                       callback=self.drawDistanceMap)
        OWGUI.checkBox(box,
                       self,
                       'ShowLabels',
                       'Show labels',
                       callback=self.drawDistanceMap)

        box = OWGUI.widgetBox(tab, "Balloon")
        OWGUI.checkBox(box, self, 'ShowBalloon', "Show balloon")
        OWGUI.checkBox(box, self, 'ShowItemsInBalloon', "Display item names")

        box = OWGUI.widgetBox(tab, "Select")
        box2 = OWGUI.widgetBox(box, orientation="horizontal")
        self.box2 = box2
        self.buttonUndo = OWToolbars.createButton(box2,
                                                  'Undo',
                                                  self.actionUndo,
                                                  QIcon(OWToolbars.dlg_undo),
                                                  toggle=0)
        self.buttonRemoveAllSelections = OWToolbars.createButton(
            box2,
            'Remove all selections',
            self.actionRemoveAllSelections,
            QIcon(OWToolbars.dlg_clear),
            toggle=0)

        self.buttonSendSelections = OWToolbars.createButton(
            box2,
            'Send selections',
            self.sendOutput,
            QIcon(OWToolbars.dlg_send),
            toggle=0)
        OWGUI.checkBox(box, self, 'SendOnRelease', "Send after mouse release")
        OWGUI.rubber(tab)
        ##        self.tabs.insertTab(tab, "Info")

        self.resize(700, 400)

        self.scene = EventfulGraphicsScene(self)
        self.sceneView = EventfulGraphicsView(self.scene, self.mainArea, self)
        self.mainArea.layout().addWidget(self.sceneView)

        #construct selector
        self.selector = QGraphicsRectItem(0, 0, self.CellWidth,
                                          self.CellHeight, None, self.scene)
        ##        color = self.colorPalette.getCurrentColorSchema().getAdditionalColors()["Cell outline"]
        color = self.cellOutlineColor
        self.selector.setPen(QPen(self.qrgbToQColor(color), v_sel_width))
        self.selector.setZValue(20)

        ##        self.bubble = BubbleInfo(self.scene)
        self.selection = SelectionManager()

        self.selectionLines = []
        self.annotationText = []
        self.clusterItems = []
        self.selectionRects = []

        self.legendText1 = QGraphicsSimpleTextItem(None, self.scene)
        self.legendText2 = QGraphicsSimpleTextItem(None, self.scene)

        self.errorText = QGraphicsSimpleTextItem("Bitmap is too large.", None,
                                                 self.scene)
        self.errorText.setPos(10, 10)

        #        OWGUI.button(self.controlArea, self, "&Save Graph", lambda:OWChooseImageSizeDlg(self.scene).exec_(), debuggingEnabled = 0)
        self.connect(
            self.graphButton, SIGNAL("clicked()"),
            lambda: OWChooseImageSizeDlg(self.scene, parent=self).exec_())