def _show_stream_items()

in tensorwatch/plotly/line_plot.py [0:0]


    def _show_stream_items(self, stream_vis, stream_items):
        """Paint the given stream_items in to visualizer. If visualizer is dirty then return False else True.
        """

        vals = self._extract_vals(stream_items)
        if not len(vals):
            return True # not dirty

        # get trace data
        trace = self.widget.data[stream_vis.trace_index]
        xdata, ydata, zdata, anndata, txtdata, clrdata = list(trace.x), list(trace.y), [], [], [], []
        lows, highs = [], [] # confidence interval

        if self.is_3d:
            zdata = list(trace.z)

        unpacker = lambda a0=None,a1=None,a2=None,a3=None,a4=None,a5=None,a6=None,a7=None,*_:\
            (a0,a1,a2,a3,a4,a5,a6,a7)

        # add each value in trace data
        # each value is of the form:
        # 2D graphs:
        #   y
        #   x [, y [,low, [, high [,annotation [, text [, color]]]]]]
        #   y
        #   x [, y [, z, [,low, [, high [annotation [, text [, color]]]]]
        for val in vals:
            # set defaults
            x, y, z =  len(xdata), None, None
            ann, txt, clr = None, None, None

            # if val turns out to be array-like, extract x,y
            val_l = utils.is_scaler_array(val)
            if val_l >= 0:
                if self.is_3d:
                    x, y, z, low, high, ann, txt, clr = unpacker(*val)
                else:
                    x, y, low, high, ann, txt, clr, _ = unpacker(*val)
            elif isinstance(val, PointData):
                x, y, z, low, high, ann, txt, clr = val.x, val.y, val.z, \
                    val.low, val.high, val.annotation, val.text, val.color
            else:
                y = val

            if ann is not None:
                ann = str(ann)
            if txt is not None:
                txt = str(txt)

            xdata.append(x)
            ydata.append(y)
            zdata.append(z)
            if low is not None:
                lows.append(low)
            if high is not None:
                highs.append(high)
            if txt is not None:
                txtdata.append(txt)
            if clr is not None:
                clrdata.append(clr)
            if ann: #TODO: yref should be y2 for different y axis
                anndata.append(dict(x=x, y=y, xref='x', yref='y', text=ann, showarrow=False))

        self.widget.data[stream_vis.trace_index].x = xdata
        self.widget.data[stream_vis.trace_index].y = ydata   
        if self.is_3d:
            self.widget.data[stream_vis.trace_index].z = zdata

        # add text
        if len(txtdata):
            exisitng = self.widget.data[stream_vis.trace_index].text
            exisitng = list(exisitng) if utils.is_array_like(exisitng) else []
            exisitng += txtdata
            self.widget.data[stream_vis.trace_index].text = exisitng

        # add annotation
        if len(anndata):
            existing = list(self.widget.layout.annotations)
            existing += anndata
            self.widget.layout.annotations = existing

        # add color
        if len(clrdata):
            exisitng = self.widget.data[stream_vis.trace_index].marker.color
            exisitng = list(exisitng) if utils.is_array_like(exisitng) else []
            exisitng += clrdata
            self.widget.data[stream_vis.trace_index].marker.color = exisitng

        return False # dirty