-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroadmap.go
143 lines (128 loc) · 3.47 KB
/
roadmap.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package slidesutil
import (
"fmt"
"github.com/grokify/gocharts/v2/data/roadmap"
slides "google.golang.org/api/slides/v1"
)
type SlideCanvasInfo struct {
BoxFgColor *slides.RgbColor
BoxBgColor *slides.RgbColor
BoxHeight float64
BoxMarginBottom float64
Canvas CanvasFloat64
}
func DefaultSlideCanvasInfo() SlideCanvasInfo {
return SlideCanvasInfo{
BoxFgColor: MustParseRgbColorHex("#ffffff"),
BoxBgColor: MustParseRgbColorHex("#4688f1"),
BoxHeight: 25.0,
BoxMarginBottom: 5.0,
Canvas: CanvasFloat64{
MinX: 150.0,
MinY: 70.0,
MaxX: 700.0,
MaxY: 500.0,
},
}
}
type CanvasFloat64 struct {
MinX float64
MinY float64
MaxX float64
MaxY float64
}
func (c64 *CanvasFloat64) ThisX(this, min, max float64) (float64, error) {
if min > max {
return 0.0, fmt.Errorf("min [%v] is larger than max [%v]", min, max)
} else if this < min || this > max {
return 0.0, fmt.Errorf("this [%v] is not within min,max [%v, %v]", this, min, max)
}
diff := max - min
plus := this - min
pct := plus / diff
diffCan := c64.MaxX - c64.MinX
thisPlus := pct * diffCan
thisX := c64.MinX + thisPlus
return thisX, nil
}
type Location struct {
SrcAllMinX int64
SrcAllMaxX int64
SrcAllWdtX int64
SrcBoxMinX int64
SrcBoxMaxX int64
SrcBoxWdtX int64
SrcPctWdtX float64
OutAllMinX float64
OutAllMaxX float64
OutAllWdtX float64
OutBoxMinX float64
OutBoxMaxX float64
OutBoxWdtX float64
BoxOutPctX float64
}
func GoogleSlideDrawRoadmap(pageID string, srcCan roadmap.Canvas, outCan SlideCanvasInfo) ([]*slides.Request, error) {
requests := []*slides.Request{}
err := srcCan.InflateItems()
if err != nil {
return requests, err
}
srcCan.BuildRows()
idx := 0
rowYWatermark := outCan.Canvas.MinY
for _, row := range srcCan.Rows {
for _, el := range row {
// fmtutil.PrintJSON(el)
srcBoxWdtX := el.Max - el.Min
srcAllWdtX := srcCan.MaxX - srcCan.MinX
srcBoxMinX := el.Min
srcBoxMaxX := el.Max
srcPctWdtX := float64(srcBoxWdtX) / float64(srcAllWdtX)
srcAllMinX := srcCan.MinX
outAllWdtX := outCan.Canvas.MaxX - outCan.Canvas.MinX
outBoxWdtX := srcPctWdtX * outAllWdtX
boxOutPctX := float64(srcAllWdtX) / outAllWdtX
outAllMinX := outCan.Canvas.MinX
// fmt.Printf("%v\n", srcBoxMinX-srcAllMinX)
// fmt.Printf("%v\n", el.Min-srcCan.MinX)
outBoxMinX := (float64(srcBoxMinX-srcAllMinX) / boxOutPctX) + outAllMinX
outBoxMaxX := (float64(srcBoxMaxX-srcAllMinX) / boxOutPctX) + outAllMinX
loc := Location{
SrcAllMinX: srcCan.MinX,
SrcAllMaxX: srcCan.MaxX,
SrcAllWdtX: srcCan.MaxX - srcCan.MinX,
SrcBoxMinX: el.Min,
SrcBoxMaxX: el.Max,
SrcBoxWdtX: srcBoxWdtX,
SrcPctWdtX: srcPctWdtX,
OutAllMinX: outCan.Canvas.MinX,
OutAllMaxX: outCan.Canvas.MaxX,
OutAllWdtX: outCan.Canvas.MaxX - outCan.Canvas.MinX,
OutBoxMinX: outBoxMinX,
OutBoxMaxX: outBoxMaxX,
OutBoxWdtX: outBoxWdtX,
BoxOutPctX: boxOutPctX,
}
// fmtutil.PrintJSON(loc)
if loc.OutBoxMaxX > loc.OutAllMaxX {
panic("C")
} else if loc.OutBoxMinX < loc.OutAllMinX {
panic("D")
}
//panic("Z")
elementID := fmt.Sprintf("AutoBox%03d", idx)
requests = append(requests, TextBoxRequestsSimple(
pageID, elementID, el.NameShort, outCan.BoxFgColor, outCan.BoxBgColor,
loc.OutBoxWdtX, outCan.BoxHeight, loc.OutBoxMinX, rowYWatermark)...)
idx++
//break
/*
if i > 3 {
break
}
*/
}
rowYWatermark += outCan.BoxHeight + outCan.BoxMarginBottom
}
return requests, nil
}