|
1 |
| -import { isFunction, isNumber, isString } from '@antv/util'; |
| 1 | +import { isFunction, isNumber, isString, deepMix } from '@antv/util'; |
2 | 2 | import { Params } from '../../core/adaptor';
|
3 | 3 | import { flow } from '../../utils';
|
4 | 4 | import { tooltip, interaction, animation, theme, scale } from '../../adaptor/common';
|
5 | 5 | import { findGeometry } from '../../utils';
|
| 6 | +import { getQuadrantDefaultConfig } from './util'; |
6 | 7 | import { ScatterOptions } from './types';
|
7 | 8 |
|
8 | 9 | /**
|
@@ -143,12 +144,54 @@ function label(params: Params<ScatterOptions>): Params<ScatterOptions> {
|
143 | 144 | return params;
|
144 | 145 | }
|
145 | 146 |
|
| 147 | +/** |
| 148 | + * 四象限 |
| 149 | + * @param params |
| 150 | + */ |
| 151 | +function quadrant(params: Params<ScatterOptions>): Params<ScatterOptions> { |
| 152 | + const { chart, options } = params; |
| 153 | + const { quadrant } = options; |
| 154 | + |
| 155 | + if (quadrant) { |
| 156 | + const { xBaseline = 0, yBaseline = 0, labels, regionStyle, lineStyle } = quadrant; |
| 157 | + const defaultConfig = getQuadrantDefaultConfig(xBaseline, yBaseline); |
| 158 | + // 仅支持四象限 |
| 159 | + const quadrants = new Array(4).join(',').split(','); |
| 160 | + quadrants.forEach((_: string, index: number) => { |
| 161 | + chart.annotation().region({ |
| 162 | + top: false, |
| 163 | + ...defaultConfig.regionStyle[index].position, |
| 164 | + style: deepMix({}, defaultConfig.regionStyle[index].style, regionStyle?.[index]), |
| 165 | + }); |
| 166 | + chart.annotation().text({ |
| 167 | + top: true, |
| 168 | + ...deepMix({}, defaultConfig.labelStyle[index], labels?.[index]), |
| 169 | + }); |
| 170 | + }); |
| 171 | + // 生成坐标轴 |
| 172 | + chart.annotation().line({ |
| 173 | + top: false, |
| 174 | + start: ['min', yBaseline], |
| 175 | + end: ['max', yBaseline], |
| 176 | + style: deepMix({}, defaultConfig.lineStyle, lineStyle), |
| 177 | + }); |
| 178 | + chart.annotation().line({ |
| 179 | + top: false, |
| 180 | + start: [xBaseline, 'min'], |
| 181 | + end: [xBaseline, 'max'], |
| 182 | + style: deepMix({}, defaultConfig.lineStyle, lineStyle), |
| 183 | + }); |
| 184 | + } |
| 185 | + |
| 186 | + return params; |
| 187 | +} |
| 188 | + |
146 | 189 | /**
|
147 | 190 | * 散点图适配器
|
148 | 191 | * @param chart
|
149 | 192 | * @param options
|
150 | 193 | */
|
151 | 194 | export function adaptor(params: Params<ScatterOptions>) {
|
152 | 195 | // flow 的方式处理所有的配置到 G2 API
|
153 |
| - return flow(field, meta, axis, legend, tooltip, style, label, interaction, animation, theme)(params); |
| 196 | + return flow(field, meta, axis, legend, tooltip, style, label, interaction, quadrant, animation, theme)(params); |
154 | 197 | }
|
0 commit comments