作者 yangfu

feat: data layout v2

... ... @@ -81,7 +81,7 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
}
for j := yMin; j <= yMax; j++ {
move := 0
position := -1
var c *domain.LayoutCell
for _, cell := range cells {
if cell.Y != j {
continue
... ... @@ -89,19 +89,19 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
if cell.Direction != domain.DirectionRight {
continue
}
move = cell.Length
position = cell.Y
break
}
if move == 0 || position == -1 {
continue
//move = cell.Length
//c = cell
if max(move, cell.Length) != move {
c = cell
}
move = max(move, cell.Length)
//break
}
j = position + 1
ChangeLocation(cells, domain.DirectionRight, position, move)
ChangeLocation(cells, domain.DirectionRight, j, move, c)
}
for i := xMin; i <= xMax; i++ {
move := 0
position := -1
var c *domain.LayoutCell
for _, cell := range cells {
if cell.X != i {
continue
... ... @@ -109,19 +109,19 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
if cell.Direction != domain.DirectionDown {
continue
}
move = cell.Length
position = cell.X
break
}
if move == 0 || position == -1 {
continue
//move = cell.Length
//c = cell
if max(move, cell.Length) != move {
c = cell
}
move = max(move, cell.Length)
//break
}
i = position + 1
ChangeLocation(cells, domain.DirectionDown, position, move)
ChangeLocation(cells, domain.DirectionDown, i, move, c)
}
}
func ChangeLocation(cells []*domain.LayoutCell, direction string, position, move int) {
func ChangeLocation(cells []*domain.LayoutCell, direction string, position, move int, c *domain.LayoutCell) {
// log.Logger.Info("修改定位点")
if move == 0 {
return
... ... @@ -133,7 +133,7 @@ func ChangeLocation(cells []*domain.LayoutCell, direction string, position, move
cell.Y += move - 1
}
case domain.DirectionDown:
if cell.X > position {
if cell.X > position && cell.Y >= c.Y {
cell.X += move - 1
}
}
... ...
... ... @@ -75,7 +75,7 @@ func TestDataLayout(t *testing.T) {
Direction: domain.DirectionNone,
},
// 分组二 右平移10
//分组二 右平移10
{
X: 0,
Y: 10,
... ... @@ -133,7 +133,7 @@ func TestDataLayout(t *testing.T) {
Direction: domain.DirectionNone,
},
},
flag: Location{X: 3, Y: 2},
flag: Location{X: 2, Y: 2},
},
{
title: "正常多字段横排",
... ... @@ -309,6 +309,106 @@ func TestDataLayout(t *testing.T) {
},
flag: Location{X: 2, Y: 1},
},
{
title: "正常多字段横排(长度不一样)+竖排",
cells: []*domain.LayoutCell{
// 分组一
{
X: 0,
Y: 0,
Length: 5,
ImageData: "a",
Direction: domain.DirectionRight,
},
{
X: 0,
Y: 1,
Length: 5,
ImageData: "b",
Direction: domain.DirectionDown,
},
{
X: 1,
Y: 0,
Length: 6,
ImageData: "c",
Direction: domain.DirectionRight,
},
{
X: 2,
Y: 0,
Length: 7,
ImageData: "d",
Direction: domain.DirectionRight,
},
},
flag: Location{X: 2, Y: 1},
},
{
title: "测试用例1",
cells: []*domain.LayoutCell{
// 分组一
{
X: 0,
Y: 0,
Length: 1,
ImageData: "a",
Direction: domain.DirectionNone,
},
{
X: 0,
Y: 1,
Length: 1,
ImageData: "b",
Direction: domain.DirectionNone,
},
{
X: 2,
Y: 2,
Length: 5,
ImageData: "c",
Direction: domain.DirectionRight,
},
},
flag: Location{X: 0, Y: 0},
},
{
title: "测试用例3",
cells: []*domain.LayoutCell{
// 分组一
{
X: 0,
Y: 0,
Length: 5,
ImageData: "a",
Direction: domain.DirectionRight,
},
{
X: 1,
Y: 0,
Length: 5,
ImageData: "b",
Direction: domain.DirectionDown,
},
{
X: 1,
Y: 1,
Length: 5,
ImageData: "c",
Direction: domain.DirectionRight,
},
{
X: 2,
Y: 1,
Length: 5,
ImageData: "d",
Direction: domain.DirectionRight,
},
},
flag: Location{X: 2, Y: 1},
},
}
padding := func(cells []*domain.LayoutCell) {
for _, cell := range cells {
... ... @@ -328,10 +428,53 @@ func TestDataLayout(t *testing.T) {
assert.NoError(t, err)
}
printRes(res)
assert.NotEmptyf(t, res.Data[input.flag.X][input.flag.Y], "单元格有值")
if input.flag.X > 0 && input.flag.Y > 0 {
assert.NotEmptyf(t, res.Data[input.flag.X][input.flag.Y], "单元格有值")
}
}
}
/*
output
2 | 2 | 3 | 3 | 3 | | | | | | | | | 2 | 2 | 3 | 3 | 3 | |
a | | f | | | b | e | | | | | | | a | | f | | | b | e
a | | f | | | b | e | | | | | | | a | | f | | | b | e
c | | d | | | | | | | | | | | c | | d | | | |
a | a | a | a | a | | | | | | | | | | a | a | a | a | a
b | b | b | b | b | | | | | | | | | | b | b | b | b | b
c | c | c | c | c | | | | | | | | | | c | c | c | c | c
d | d | d | d | d | | | | | | | | | | d | d | d | d | d
a | a | a | a | a | | | | | | | | | | a | | | | |
b | b | b | b | b | | | | | | | | | | b | b | b | b | b |
c | | | | | | | | | | | | | | c | | | | | e
d | | | | | | | | | | | | | | d | | | | |
a | a | a | a | a | b
c | c | c | c | c | b
d | d | d | d | d | b
| | | | | b
| | | | | b
a | a | a | a | a | | | b
c | c | c | c | c | c | | b
d | d | d | d | d | d | d | b
| | | | | | | b
| | | | | | | b
a | a | a | a | a | | | | |
b | | | | | c | c | c | c | c
b | | | | | | | | |
b | | | | | | | | |
b | | | | | | | | |
b | | | | | | | | |
| | | | | d | d | d | d | d
*/
func printRes(res *domain.DataTable) {
strBuilder := strings.Builder{}
for i := range res.Data {
... ...