'Calculates all the elements needed for plotting a dendrogram.
:param (ndarray) X: Matrix of observations as array of arrays
:param (list) colorscale: Color scale for dendrogram tree clusters
:param (function) distfun: Function to compute the pairwise distance
from the observations
:param (function) linkagefun: Function to compute the linkage matrix
from the pairwise distances
:rtype (tuple): Contains all the traces in the following order:
(a) trace_list: List of Plotly trace objects for dendrogram tree
(b) icoord: All X points of the dendrogram tree as array of arrays
with length 4
(c) dcoord: All Y points of the dendrogram tree as array of arrays
with length 4
(d) ordered_labels: leaf labels in the order they are going to
appear on the plot
(e) P[\'leaves\']: left-to-right traversal of the leaves'

def get_dendrogram_traces(self, X, colorscale, distfun, linkagefun):

    d = distfun(X)
    Z = linkagefun(d)
    P = sch.dendrogram(Z, orientation=self.orientation, labels=self.labels, no_plot=True)
    icoord = scp.array(P['icoord'])
    dcoord = scp.array(P['dcoord'])
    ordered_labels = scp.array(P['ivl'])
    color_list = scp.array(P['color_list'])
    colors = self.get_color_dict(colorscale)
    trace_list = []
    for i in range(len(icoord)):
        if (self.orientation in ['top', 'bottom']):
            xs = icoord[i]
        else:
            xs = dcoord[i]
        if (self.orientation in ['top', 'bottom']):
            ys = dcoord[i]
        else:
            ys = icoord[i]
        color_key = color_list[i]
        trace = graph_objs.Scatter(x=np.multiply(self.sign[self.xaxis], xs), y=np.multiply(self.sign[self.yaxis], ys), mode='lines', marker=graph_objs.Marker(color=colors[color_key]))
        try:
            x_index = int(self.xaxis[(-1)])
        except ValueError:
            x_index = ''
        try:
            y_index = int(self.yaxis[(-1)])
        except ValueError:
            y_index = ''
        trace['xaxis'] = ('x' + x_index)
        trace['yaxis'] = ('y' + y_index)
        trace_list.append(trace)
    return (trace_list, icoord, dcoord, ordered_labels, P['leaves'])
