Custom tool to hide legend

I am trying to make a custom tool to add to plots that will show or hide the plot legend when clicked. Is there a property I can set in the doit function in the tool implementation code to turn legend on or off?

Here is the class I want to implement:

class LegendTool(Tool):

implementation = “”"

import * as p from “core/properties”

import {ActionTool, ActionToolView} from “models/tools/actions/action_tool”

export class LegendToolView extends ActionToolView

doit: () ->

code to show/hide legend

export class LegendTool extends ActionTool

default_view: LegendToolView

type: “LegendTool”

tool_name: “Show Legend”

icon: “bk-tool-icon-tap-select”

“”"

Thank you for any help you can provide,

Clinton

Hi,

You can try something like “@plot_view.select_one(Legend).visible = false”. You’ll have to require “Legend” from “models/annotations/legend”.

Regards,

Eugene

···

On Thursday, November 30, 2017 at 5:58:46 AM UTC+7, Clinton Miller wrote:

I am trying to make a custom tool to add to plots that will show or hide the plot legend when clicked. Is there a property I can set in the doit function in the tool implementation code to turn legend on or off?

Here is the class I want to implement:

class LegendTool(Tool):

implementation = “”"

import * as p from “core/properties”

import {ActionTool, ActionToolView} from “models/tools/actions/action_tool”

export class LegendToolView extends ActionToolView

doit: () ->

code to show/hide legend

export class LegendTool extends ActionTool

default_view: LegendToolView

type: “LegendTool”

tool_name: “Show Legend”

icon: “bk-tool-icon-tap-select”

“”"

Thank you for any help you can provide,

Clinton

Awesome, thank you. I have it working now.

···

On Thursday, November 30, 2017 at 2:18:51 PM UTC-5, Eugene Pakhomov wrote:

Hi,

You can try something like “@plot_view.select_one(Legend).visible = false”. You’ll have to require “Legend” from “models/annotations/legend”.

Regards,

Eugene

On Thursday, November 30, 2017 at 5:58:46 AM UTC+7, Clinton Miller wrote:

I am trying to make a custom tool to add to plots that will show or hide the plot legend when clicked. Is there a property I can set in the doit function in the tool implementation code to turn legend on or off?

Here is the class I want to implement:

class LegendTool(Tool):

implementation = “”"

import * as p from “core/properties”

import {ActionTool, ActionToolView} from “models/tools/actions/action_tool”

export class LegendToolView extends ActionToolView

doit: () ->

code to show/hide legend

export class LegendTool extends ActionTool

default_view: LegendToolView

type: “LegendTool”

tool_name: “Show Legend”

icon: “bk-tool-icon-tap-select”

“”"

Thank you for any help you can provide,

Clinton

FYI this would be a great tool to have built-in Bokeh.

Jacques

···

On Thursday, November 30, 2017 at 12:23:01 PM UTC-8, Clinton Miller wrote:

Awesome, thank you. I have it working now.

On Thursday, November 30, 2017 at 2:18:51 PM UTC-5, Eugene Pakhomov wrote:

Hi,

You can try something like “@plot_view.select_one(Legend).visible = false”. You’ll have to require “Legend” from “models/annotations/legend”.

Regards,

Eugene

On Thursday, November 30, 2017 at 5:58:46 AM UTC+7, Clinton Miller wrote:

I am trying to make a custom tool to add to plots that will show or hide the plot legend when clicked. Is there a property I can set in the doit function in the tool implementation code to turn legend on or off?

Here is the class I want to implement:

class LegendTool(Tool):

implementation = “”"

import * as p from “core/properties”

import {ActionTool, ActionToolView} from “models/tools/actions/action_tool”

export class LegendToolView extends ActionToolView

doit: () ->

code to show/hide legend

export class LegendTool extends ActionTool

default_view: LegendToolView

type: “LegendTool”

tool_name: “Show Legend”

icon: “bk-tool-icon-tap-select”

“”"

Thank you for any help you can provide,

Clinton