(
visualMapModel: VisualMapModel,
api: ExtensionAPI,
itemSize: number[]
)
| 38 | * @return {string} 'left' or 'right' or 'top' or 'bottom' |
| 39 | */ |
| 40 | export function getItemAlign( |
| 41 | visualMapModel: VisualMapModel, |
| 42 | api: ExtensionAPI, |
| 43 | itemSize: number[] |
| 44 | ): ItemAlign { |
| 45 | const modelOption = visualMapModel.option; |
| 46 | const itemAlign = modelOption.align; |
| 47 | |
| 48 | if (itemAlign != null && itemAlign !== 'auto') { |
| 49 | return itemAlign as ItemAlign; |
| 50 | } |
| 51 | |
| 52 | // Auto decision align. |
| 53 | const ecSize = {width: api.getWidth(), height: api.getHeight()}; |
| 54 | const realIndex = modelOption.orient === 'horizontal' ? 1 : 0; |
| 55 | |
| 56 | const reals = paramsSet[realIndex]; |
| 57 | const fakeValue = [0, null, 10]; |
| 58 | |
| 59 | const layoutInput = {} as Record<ItemAlign, number | string>; |
| 60 | for (let i = 0; i < 3; i++) { |
| 61 | layoutInput[paramsSet[1 - realIndex][i]] = fakeValue[i]; |
| 62 | layoutInput[reals[i]] = i === 2 ? itemSize[0] : modelOption[reals[i]]; |
| 63 | } |
| 64 | |
| 65 | const rParam = ([['x', 'width', 3], ['y', 'height', 0]] as const)[realIndex]; |
| 66 | const rect = getLayoutRect(layoutInput, ecSize, modelOption.padding); |
| 67 | |
| 68 | return reals[ |
| 69 | (rect.margin[rParam[2]] || 0) + rect[rParam[0]] + rect[rParam[1]] * 0.5 |
| 70 | < ecSize[rParam[1]] * 0.5 ? 0 : 1 |
| 71 | ]; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Prepare dataIndex for outside usage, where dataIndex means rawIndex, and |
nothing calls this directly
no test coverage detected
searching dependent graphs…