Skip to content

Legend with continuous gradient #57

@filonico

Description

@filonico

Hello! Thank you for the very useful tool! I was plotting bootstrap data on my phylogenetic tree as points on nodes color-coded with a continuous gradient. Here is the code to produce this:

static Gradient gradient = new Gradient(
new List<TreeViewer.GradientStop>()
{
    new TreeViewer.GradientStop(0, Colour.FromRgba(0.996078431372549d, 0.2901960784313726d, 0.28627450980392155d, 1d)),
    new TreeViewer.GradientStop(0.5, Colour.FromRgba(0.996078431372549d, 0.8431372549019608d, 0.4d, 1d)),
    new TreeViewer.GradientStop(1, Colour.FromRgba(0d, 0.6235294117647059d, 0.7176470588235294d, 1d))
});

public static Colour? Format(object attribute)
{
    if (attribute is double attributeValue &&
    !double.IsNaN(attributeValue))
    {
        double position = (attributeValue - 0) / 100;
        position = Math.Max(Math.Min(position, 1), 0);
        return gradient.GetColour(position);
    }
    else
    {
        return null;
    }
}

On the manual, you show how to create a legend using binned categories, and that works fine. Though, I was wondering if you know of any way in which I can create an actual gradient also in the legend. Something like this:

Image

Thank you very much for helping!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions