コード例 #1
0
    def create_plot(self):
        polygon_filter, visible_features_only = self.get_polygon_filter(0)

        config = {'displayModeBar': False, 'staticPlot': True}

        if len(self.plot_settings) == 1:
            plot_factory = PlotFactory(self.plot_settings[0], self, polygon_filter=polygon_filter)
            self.plot_settings[0].properties['visible_features_only'] = visible_features_only
            return plot_factory.build_html(config)

        # to plot many plots in the same figure
        elif len(self.plot_settings) > 1:
            # plot list ready to be called within go.Figure
            pl = []
            plot_factory = PlotFactory(self.plot_settings[0], self, polygon_filter=polygon_filter)

            for current, plot_setting in enumerate(self.plot_settings):
                polygon_filter, visible_features_only = self.get_polygon_filter(current)
                plot_setting.properties['visible_features_only'] = visible_features_only
                factory = PlotFactory(plot_setting, self, polygon_filter=polygon_filter)
                pl.append(factory.trace[0])

            plot_path = plot_factory.build_figures(self.plot_settings[0].plot_type, pl, config=config)
            with open(plot_path, 'r') as myfile:
                return myfile.read()
コード例 #2
0
    def create_plot(self):
        if self.linked_map and self.filter_by_map:
            polygon_filter = FilterRegion(QgsGeometry.fromQPolygonF(self.linked_map.visibleExtentPolygon()),
                                          self.linked_map.crs())
            visible_features_only = True
        elif self.filter_by_atlas and self.layout().reportContext().layer() and self.layout().reportContext().feature().isValid():
            polygon_filter = FilterRegion(self.layout().reportContext().currentGeometry(), self.layout().reportContext().layer().crs())
            visible_features_only = True
        else:
            polygon_filter = None
            visible_features_only = False

        config = {'displayModeBar': False, 'staticPlot': True}

        if len(self.plot_settings) == 1:
            plot_factory = PlotFactory(self.plot_settings[0], self, polygon_filter=polygon_filter)
            self.plot_settings[0].properties['visible_features_only'] = visible_features_only
            return plot_factory.build_html(config)

        # to plot many plots in the same figure
        elif len(self.plot_settings) > 1:
            # plot list ready to be called within go.Figure
            pl = []
            plot_factory = PlotFactory(self.plot_settings[0], self, polygon_filter=polygon_filter)

            for plot_setting in self.plot_settings:
                plot_setting.properties['visible_features_only'] = visible_features_only
                factory = PlotFactory(plot_setting, self, polygon_filter=polygon_filter)
                pl.append(factory.trace[0])

            plot_path = plot_factory.build_figures(self.plot_settings[0].plot_type, pl, config=config)
            with open(plot_path, 'r') as myfile:
                return myfile.read()
コード例 #3
0
    def test_dates(self):  # pylint: disable=too-many-statements
        """
        Test handling of dates
        """
        # default plot settings
        settings = PlotSettings('scatter')

        # no source layer, fixed values must be used
        settings.source_layer_id = ''
        settings.x = [QDate(2020, 1, 1), QDate(2020, 2, 1), QDate(2020, 3, 1)]
        settings.y = [4, 5, 6]
        factory = PlotFactory(settings)

        # Build the HTML/JavaScript for the plot
        plot_html = factory.build_html({})

        # Find the plot specification in the HTML
        match = re.search(r'\[.*\]', plot_html)
        plot_dictionary = json.loads(match.group(0))[0]

        self.assertEqual(plot_dictionary['x'],
                         ["2020-01-01", "2020-02-01", "2020-03-01"])
        self.assertEqual(plot_dictionary['y'], [4, 5, 6])

        settings.x = [
            QDateTime(2020, 1, 1, 11, 21),
            QDateTime(2020, 2, 1, 0, 15),
            QDateTime(2020, 3, 1, 17, 23, 11)
        ]
        settings.y = [4, 5, 6]
        factory = PlotFactory(settings)

        # Build the HTML/JavaScript for the plot
        plot_html = factory.build_html({})

        # Find the plot specification in the HTML
        match = re.search(r'\[.*\]', plot_html)
        plot_dictionary = json.loads(match.group(0))[0]

        self.assertEqual(plot_dictionary['x'], [
            "2020-01-01T11:21:00", "2020-02-01T00:15:00", "2020-03-01T17:23:11"
        ])
        self.assertEqual(plot_dictionary['y'], [4, 5, 6])
コード例 #4
0
    def create_plot(self):
        if self.linked_map and self.filter_by_map:
            polygon_filter = FilterRegion(
                QgsGeometry.fromQPolygonF(
                    self.linked_map.visibleExtentPolygon()),
                self.linked_map.crs())
            self.plot_settings.properties['visible_features_only'] = True
        elif self.filter_by_atlas and self.layout().reportContext().layer(
        ) and self.layout().reportContext().feature().isValid():
            polygon_filter = FilterRegion(
                self.layout().reportContext().currentGeometry(),
                self.layout().reportContext().layer().crs())
            self.plot_settings.properties['visible_features_only'] = True
        else:
            polygon_filter = None
            self.plot_settings.properties['visible_features_only'] = False

        factory = PlotFactory(self.plot_settings,
                              self,
                              polygon_filter=polygon_filter)
        config = {'displayModeBar': False, 'staticPlot': True}
        return factory.build_html(config)
コード例 #5
0
 def create_plot(self):
     factory = PlotFactory(self.plot_settings)
     config = {'displayModeBar': False, 'staticPlot': True}
     return factory.build_html(config)