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");
});

{@link https://www.amcharts.com/docs/v4/reference/adapter_module/#globalAdapter_property More info}.

Sources

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

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

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

Inheritance

Adapter does not extend any other symbol.

Adapter is not extended by any other symbol.

Properties

events
#

Type EventDispatcher < { inserted: object,
  removed: object }
>

Event dispatcher.

object
#

Type Target

Holds an object reference this Adapter is for.

Methods

add(

key: Key,
callback: ( this: C, value: T[""], target: Target, key: Key) => T[""],
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[""]

)

#

Returns T[""]

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

clear()

#

Returns void

Clears all callbacks from this Adapter.

constructor(

c: Target

)

#

Returns Adapter

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

copyFrom(

source: this

)

#

Returns void

Copies all the adapter callbacks from source.

disableKey(

key: Key,
amount: number

)

#

Returns void

Disable applying adapters for a certain key.

Optionally, can set how many applies to skip before automatically re-enabling the applying.

enableKey(

key: Key

)

#

Returns void

Enable applying adapters for a certain key, if it was disabled before by disableKey().

has(

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

)

#

Returns boolean

Checks whether specific adapter is already set.

isEnabled(

key: Key

)

#

Returns boolean

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

keys()

#

Returns Array < string >

Returns all adapter keys which are in this adapter.

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.