-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlayout.go
94 lines (82 loc) · 2.22 KB
/
layout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package washeet
import (
"math"
)
func newLayoutData(originX, originY, maxX, maxY float64) *layoutData {
if maxX <= originX || maxY <= originY {
return nil
}
return &layoutData{
startColumn: int64(0),
startRow: int64(0),
endColumn: int64(0),
endRow: int64(0),
colStartXCoords: make([]float64, 0, 1+int(math.Ceil((maxX-originX+1)/constDefaultCellWidth))),
rowStartYCoords: make([]float64, 0, 1+int(math.Ceil((maxY-originY+1)/constDefaultCellHeight))),
layoutFromStartCol: true,
layoutFromStartRow: true,
}
}
func (sheet *Sheet) computeLayout(layout *layoutData, col, row int64, changeSheetStartCol, changeSheetStartRow bool) {
if sheet == nil {
return
}
// Recompute startColumn/startRow/endColumn/endRow colStartXCoords/rowStartYCoords
layout.layoutFromStartCol = changeSheetStartCol
layout.layoutFromStartRow = changeSheetStartRow
if col >= 0 {
if changeSheetStartCol {
layout.startColumn = col
} else {
layout.endColumn = col
}
}
if row >= 0 {
if changeSheetStartRow {
layout.startRow = row
} else {
layout.endRow = row
}
}
// Start of actual top left cell to be drawn after accounting
// for the row/col-headers
minX, minY := sheet.origX+constDefaultCellWidth, sheet.origY+constDefaultCellHeight
if layout.layoutFromStartCol {
layout.endColumn, layout.colStartXCoords = computeCellsCoordsRefStart(
minX,
sheet.maxX,
layout.startColumn,
sheet.dataSource.GetColumnWidth,
constDefaultCellWidth,
layout.colStartXCoords,
)
} else {
layout.startColumn, layout.endColumn, layout.colStartXCoords = computeCellsCoordsRefEnd(
minX,
sheet.maxX,
layout.endColumn,
sheet.dataSource.GetColumnWidth,
constDefaultCellWidth,
layout.colStartXCoords,
)
}
if layout.layoutFromStartRow {
layout.endRow, layout.rowStartYCoords = computeCellsCoordsRefStart(
minY,
sheet.maxY,
layout.startRow,
sheet.dataSource.GetRowHeight,
constDefaultCellHeight,
layout.rowStartYCoords,
)
} else {
layout.startRow, layout.endRow, layout.rowStartYCoords = computeCellsCoordsRefEnd(
minY,
sheet.maxY,
layout.endRow,
sheet.dataSource.GetRowHeight,
constDefaultCellHeight,
layout.rowStartYCoords,
)
}
}