コード例 #1
0
    def _renderSvgBasedViz(self, pdfRenderer, view, props, mode):
        # set the fetch option output_mode to 'json_cols'
        #  this will cause the data returned by getFeed to be
        #  pre-populated into the columnar form that the charting code wants
        # set the fetch option time_format to '%FT%T.%Q%:z'
        #  this is the only time format that is accepted by charting
        # set the show_metadata flag to true for chart mode only
        #  this will populate the metadata for each field, which certain chart types need to render correctly
        if mode == "chart":
            view.getSearchJobObj().setFetchOptions(output_mode="json_cols", time_format="%FT%T.%Q%:z", show_metadata="true")
        elif mode == "single":
            view.getSearchJobObj().setFetchOptions(output_mode="json_cols", time_format="%FT%T.%Q%:z", count=1000)
        else:
            view.getSearchJobObj().setFetchOptions(output_mode="json_cols", time_format="%FT%T.%Q%:z")
        feedCount = DEFAULT_FEED_COUNT
        if 'data.count' in props:
            feedCount = props['data.count']

        feed = view.getSearchJobFeed(feedCount=feedCount)
        logger.debug("_renderSvgBasedViz> feed: " + str(feed) + ", " + str(type(feed)))
        
        if feed is None or len(feed.strip()) == 0:
            logger.warning("_renderSvgBasedViz> feed: " + str(feed) + ", " + str(type(feed)))

            pdfRenderer.renderText("No results found.")
            return

        feed = json.loads(feed)

        # extract columns and fields from the search results
        data = feed['columns']
        fields = feed['fields']

        if len(data) == 0:
            pdfRenderer.renderText("No results found.")
            return

        # set up the SVG viz object
        svgBasedViz = None
        if mode == "chart":
            # SPL-118166 - remove 'None' values from the '_time' column.
            if len(fields) and fields[0].get('name') == '_time':
                data[0] = filter(None, data[0])
            svgBasedViz = pc.Chart(data, fields, props, self._locale, server_zoneinfo=self._server_zoneinfo)
        elif mode == "map":
            svgBasedViz = pc.Map(data, fields, props, self._locale, server_zoneinfo=self._server_zoneinfo)
        elif mode == "single":
            svgBasedViz = pc.Single(data, fields, props, self._locale, server_zoneinfo=self._server_zoneinfo)

        # build the SVG viz 
        buildSuccess = svgBasedViz.build()
        if buildSuccess:
            svgString = svgBasedViz.getSvg()
            pdfRenderer.renderSvgString(svgString, title=None)
        else:
            logger.error("SVG based viz building error")
コード例 #2
0
    def _renderSvgBasedViz(
        self,
        pdfRenderer,
        view,
        props,
        mode,
    ):

        # set the fetch option output_mode to 'json_cols'
        #  this will cause the data returned by getFeed to be
        #  pre-populated into the columnar form that the charting code wants
        # set the fetch option time_format to '%FT%T.%Q%:z'
        #  this is the only time format that is accepted by charting
        # set the show_metadata flag to true for chart mode only
        #  this will populate the metadata for each field, which certain chart types need to render correctly

        if mode == 'chart':
            view.getSearchJobObj().setFetchOptions(output_mode='json_cols',
                                                   time_format='%FT%T.%Q%:z',
                                                   show_metadata='true')
        elif mode == 'single':
            view.getSearchJobObj().setFetchOptions(output_mode='json_cols',
                                                   time_format='%FT%T.%Q%:z',
                                                   count=1000)
        else:
            view.getSearchJobObj().setFetchOptions(output_mode='json_cols',
                                                   time_format='%FT%T.%Q%:z')
        feedCount = DEFAULT_FEED_COUNT
        if 'data.count' in props:
            feedCount = props['data.count']

        feed = view.getSearchJobFeed(feedCount=feedCount)
        logger.debug('_renderSvgBasedViz> feed: ' + str(feed) + ', ' +
                     str(type(feed)))

        if feed is None or len(feed.strip()) == 0:
            logger.warning('_renderSvgBasedViz> feed: ' + str(feed) + ', ' +
                           str(type(feed)))

            pdfRenderer.renderText('No results found.')
            return

        feed = json.loads(feed)

        # extract columns and fields from the search results

        data = feed['columns']
        fields = feed['fields']

        if len(data) == 0:
            pdfRenderer.renderText('No results found.')
            return

        # set up the SVG viz object

        svgBasedViz = None
        if mode == 'chart':
            svgBasedViz = pc.Chart(data, fields, props, self._locale)
        elif mode == 'map':
            svgBasedViz = pc.Map(data, fields, props, self._locale)
        elif mode == 'single':
            svgBasedViz = pc.Single(data, fields, props, self._locale)

        # build the SVG viz

        buildSuccess = svgBasedViz.build()
        if buildSuccess:
            svgString = svgBasedViz.getSvg()
            pdfRenderer.renderSvgString(svgString, title=None)
        else:
            logger.error('SVG based viz building error')