简介
plugins.tool.mapper 将图中的某一通道通过 @antv/scale 的某种变换后,映射到 @antv/g2/src/component/legend 提供的图例上,并且在图例的交互中可以对图上元素进行筛选。
安装
在 HTML 中引用文件:
<script src="https://unpkg.com/@antv/g6/build/plugin.tool.mapper.js"></script>
在 npm 中引用:
import '@antv/g6/build/plugin.tool.mapper';
参数
| 参数 | 说明 | 类型 | 默认值 | ||
|---|---|---|---|---|---|
| itemType | 映射对象类型,’node’ / ‘edge’。 | string | null | ||
| dim | 映射对象的维度,该维度存在与原始数据当中。e.g. ‘class’, ‘weight’。 | string | null | ||
| range | 映射后的值域。e.g. [0, 1], [‘#BAE7FF’, ‘#1890FF’, ‘#0050B3’]。 | array | [0, 1] | ||
| channel | 视觉通道。e.g. ‘size’, ‘color’。 | string | null | ||
| otherCfg | legend 和 scale 的配置项。legendCfg 为 null 时不显示图例。 | array | |||
| legendCfg | legendTitle | 图例的标题。 | string | ||
| lengedLayout | 图例的布局方式。’horizontal’ / ‘vertical’。 | string | ‘horizontal’ | ||
| legendWidth | 图例的宽。 | number | 150 或 15 | ||
| legendHeight | 图例的高。 | number | 15 或150 | ||
| formatter | 图例中数字到文字的转换。默认显示原始数值。 | funcion | null | ||
| scaleCfg | type | 被映射数值的变换形式。’Linear’ / ‘Log’ / ‘Pow’。 | string | ‘Linear’ |
使用
实例化插件对象:
const Mapper = G6.Plugins['tool.mapper'];const nodeColorMapper = new Mapper('node', 'class', 'color', ['#BAE7FF', '#0050B3'], {legendCfg: {layout: 'vertical',legendWidth: 200}});const nodeSizeMapper = new Mapper('node', 'weight', 'size', [10, 50], {legendCfg: {layout: 'horizontal',formatter: function(num) {return num + ' apples'}},scaleCfg: {type: 'log'}});const edgeSizeMapper = new Mapper('edge', 'weight', 'size', [2, 20], {legendCfg: null // no legend});
在实例化 Graph 时作为插件插入:
const graph = new G6.Graph({container: 'mountNode',plugins: [ nodeColorMapper, nodeSizeMapper, edgeSizeMapper ]});
