Base class for charts that use React.

Components should be functional, but will require a very thin wrapper class extending this, such that any BaseChart methods called from outside will appropriately affect the component state.

Internally, this class uses mobx to make the config object observable, and creates a React root with the given ReactComponentFunction. Use of MobX was originally intended to be hidden by this abstraction - but if we change to a different state management system, it will have implications for downstream components that expect to react to changes in the config object. Any component that needs to react to changes in the config object should be wrapped in an observer() call.

We may also want to consider a different approach to the React root, i.e. a single root with portals for each chart, in which case it should be handled in this class and should not (hopefully) require child classes/components to change.

Type Parameters

  • T

Hierarchy (View Summary)

Constructors

Properties

__doc__: Document
_tooltip?: HTMLDivElement
ComponentFn: TComponent<T & BaseConfig>
config: T & BaseConfig
contentDiv: HTMLDivElement
contextMenu: ContextMenu
dataStore: DataStore
dialogs: BaseDialog[] = []
div: HTMLElement
extra_legends?: any[]
height: number = 0
isPinned: boolean = false
legend: any
legendIcon: HTMLElement
listeners: Record<string, Listener>
menuSpace: HTMLDivElement
observable: { container: HTMLElement }
popoutIcon: HTMLElement
reactEl: HTMLDivElement
resetButton: HTMLSpanElement | HTMLButtonElement
root?: Root
settingsDialog?: BaseDialog
title: HTMLDivElement
titleBar: HTMLDivElement
unpinIcon?: HTMLElement
useMobx: boolean = true
width: number = 0

Accessors

Methods

  • Adds a listener to the datastore that will be called when an event occurs, passing the event type and any data. There are the following different types of event:-

    • removed - called when the chart has been removed

    Parameters

    • id: string

      a unique id indetifying the listener

    • listener: Listener

      a function that accepts two paramaters, the type of event and the data associated with it

    Returns void

  • Adds a menu icon with tooltip to the title bar

    Parameters

    • icon: string

      the css classs of the icon (space delimited).

    • tooltip: string

      the tooltip text

    • config: { func?: (e: MouseEvent) => void; position?: string; size?: string } = {}

      extra inormation about the icon/tooltip

      • Optionalfunc?: (e: MouseEvent) => void

        a function that is called when the icon is clicked

      • Optionalposition?: string

        the position of the tooltip.

      • Optionalsize?: string

        the size of the tooltip

    Returns HTMLSpanElement

    • the icon
  • Instructs the chart to use a different document. This is only required if you are going to add the chart to a different browser window

    Parameters

    • doc: Document

      the document that the chart will use

    Returns void

  • Parameters

    • column: string
    • OptionalasArray: boolean

    Returns (i: number) => [number, number, number]

  • Parameters

    • svg: any
    • callback: (canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D) => void

    Returns void

  • Returns information about which controls to add to the settings dialog. Subclasses should call this method and then add their own controls e.g.

    getSettings(){
        let settings = super.getSettings();
        return settings.concat([{
          label:"A value"
          type:"slider",
          default_value:this.config.value,
          max:10,
          min:10,
          func:x=>{
              this.config.value=x;
              //update chart
          }
        }]);
    }
    

    wrapping controls with a call to @{link g} will perform type checking todo- specifiy the link to g above properly/ document better

    Returns GuiSpecs

    an array of objects describing tweakable parameters

  • On rare occasions where you need to run a function that depends on mobx state, outside of a React component. This is a convenience method for creating a mobx autorun reaction that will be dispsed when the chart is removed.

    Parameters

    • fn: () => void

      The function to run

    • Optionalopts: IAutorunOptions

      Options for the autorun. According to the docs you can pass an equals option to specify a mobx comparer... but it isn't in IAutorunOptions type, and it doesn't seem to be in the code either.

    Returns void

  • Checks to see if the column is used in the chart If so, the chart will be removed but no callbacks will be involved

    Parameters

    • column: string

    Returns boolean

    true if the chart has been removed

  • adds (or removes) the color legend depending on the chart's config color_legend.display value - assumes chart has a get colorLegend method

    Returns void

  • Sets the size of the graph. If no parameters are supplied then the graph will be resized based on it container. Subclasses should overide this, but call the super method first which will calculate width and height of the content div

    Parameters

    • Optionalx: number

      The new width

    • Optionaly: number

      The new height;

    Returns void