Adapter

Type class

Adapter allows adding ordered callback functions and associating them with a string-based key. An Adapter user can then easily invoke those callbacks to apply custom functions on its input, output or intermediate values.

Custom code and plugins can add their own callbacks to modify and enhance core functionality.

See the description of add() for an example.

Almost any object in amCharts4 has own adapter, accessible with adapter property.

Any adapters added to it will be applied to that object only.

### Global Adapters If you want to add an adapter which applies to all instances of the same object type, like, for instance all slices in PieSeries, you can use global adapter.

Global adapter is a system-wide instance, accessible via globalAdapter.

am4core.globalAdapter.addAll<am4charts.IPieSeriesAdapters, am4charts.PieSeries, "fill">(am4charts.PieSeries. "fill", (value, target, key) => {
  return am4core.color("#005500");
});
am4core.globalAdapter.addAll(am4charts.PieSeries. "fill", (value, target, key) => {
  return am4core.color("#005500");
});

This link.

Sources

Adapter can be used (imported) via one of the following packages.

// Adapter is available in all of the following modules.
// You only need to import one of them.

/**
 * --------------------------------------------------------
 * Import from: "core.ts"
 * Use like: am4core.Adapter
 * --------------------------------------------------------
 */
import * as am4core from "@amcharts/amcharts4/core";

// Adapter is available in all of the following modules.
// You only need to import one of them.

/**
 * --------------------------------------------------------
 * Include via: <script src="core.js"></script>
 * Access items like: am4core.Adapter
 * --------------------------------------------------------
 */

Inheritance

Adapter does not extend any other symbol.

Adapter is not extended by any other symbol.

Properties

events
#

Type EventDispatcher < object >

Event dispatcher.

object
#

Type Target

Holds an object reference this Adapter is for.

Methods

constructor(

c: Target

)

#

Returns Adapter

Constructor, sets the object referece this Adapter should be used for.

add(

key: Key,
callback: ( this: C, value: T[Key], target: Target, key: Key) => T[Key],
priority: number,
scope?: C

)

#

Returns void

Adds a callback for a specific key.

// Override fill color value and make all slices green
chart.series.template.adapter.add("fill", (value, target, key) => {
  return am4core.color("#005500");
});
// Override fill color value and make all slices green
chart.series.template.adapter.add("fill", function(value, target, key) {
  return am4core.color("#005500");
});
{
  // ...
  "series": [{
    // ...
    "adapter": {
    	// Override fill color value and make all slices green
    	"fill": function(value, target, key) {
    	  return am4core.color("#005500");
    	}
    }
  }]
}

The above will call user-defined function (adapter) whenever fill value is requested from the Pie series, allowing it to override the default using custom code and any fuzzy logic.

There can be any number of adapters set on one property key.

In this case adapters will be applied in daisy-chain fashion. The first adapter in queue will make its transformation. The next one will have the output of the first adapter as a starting value, etc.

The order of the adapters are determined either by the order they were added in, or their priority value.

The heigher the priority, the later in the game adapter will be applied.

apply(

key: Key,
value: T[Key]

)

#

Returns T[Key]

Passes the input value through all the callbacks for the defined key.

clear()

#

Returns void

Clears all callbacks from this Adapter.

copyFrom(

source: this

)

#

Returns void

Copies all the adapter callbacks from source.

has(

key: Key,
callback: ( this: C, value: T[Key], target: Target, key: Key) => T[Key],
priority: number,
scope?: C

)

#

Returns boolean

Checks whether specific adapter is already set.

isEnabled(

key: Key

)

#

Returns boolean

Returns if there are any adapters set for the specific key.

keys()

#

Returns Array < string >

Returns all adapter keys that are currently in effect.

remove(

key: string,
priority?: number

)

#

Returns void

Removes adapter callbacks for the specific key.

If priority is specified, only callbacks for that priority are removed.

@todo Implement

Events

Adapter does not have any events.

Adapters

Adapter does not have any adapters.