9
"github.com/Arafatk/glot"
10
"github.com/RB-PRO/ssa/pkg/oss"
11
"github.com/xuri/excelize/v2"
12
"gonum.org/v1/gonum/mat"
19
// "png"+OpSystemFilder+
21
func MakeGraph(n int, dt float64, pointsX []float64, filename string) error {
25
plot, _ := glot.NewPlot(dimensions, persist, debug)
26
fct := func(x float64) float64 { return (oss.F(x, n)) }
27
groupName := "Исходная функция"
29
for i := range pointsX {
33
plot.AddFunc2d(groupName, style, pointsX, fct)
34
plot.SavePlot(filename)
38
// "png" + oss.OpSystemFilder + filename + ".png"
39
func MakeGraphOfArray(vals []float64, Path, FileName string) error {
43
plot, _ := glot.NewPlot(dimensions, persist, debug)
44
fct := func(x float64) float64 { return (vals[int(x)]) }
46
x := make([]float64, len(vals))
47
for i := 0; i < len(vals); i++ {
50
plot.AddFunc2d(FileName, style, x, fct)
51
plot.SavePlot(Path + FileName)
55
// Построить график по координатам X и Y. Источник - float64[]
57
// "png" + oss.OpSystemFilder + filename + ".png"
58
func MakeGraphYX_float64(x, y []float64, Path, FileName string) error {
60
return errors.New("MakeGraphYX_float64: Length different for " + FileName)
65
plot, ErrorPloting := glot.NewPlot(dimensions, persist, debug)
66
if ErrorPloting != nil {
70
ErrorPointGroup := plot.AddPointGroup(FileName, "lines", [][]float64{y, x})
71
if ErrorPointGroup != nil {
72
return ErrorPointGroup
75
ErrorSave := plot.SavePlot(Path + FileName)
82
// Построить график по координатам X и Y. Источник - mat.VecDense
83
func MakeGraphYX_VecDense(x, y1, y2 mat.VecDense, f1, Path, f2 string) error {
84
x_arr := oss.VecDense_in_float64(x)
85
y1_arr := oss.VecDense_in_float64(y1)
86
y2_arr := oss.VecDense_in_float64(y2)
87
if len(x_arr) != len(y1_arr) {
88
return errors.New("Length y1 of different for " + f1)
90
if len(x_arr) != len(y2_arr) {
91
return errors.New("Length y2 of different for " + f2)
97
plot, _ := glot.NewPlot(dimensions, persist, debug)
98
plot.AddPointGroup(f1, "lines", [][]float64{x_arr, y1_arr})
99
plot.AddPointGroup(f2, "lines", [][]float64{x_arr, y2_arr})
101
plot.SavePlot(Path + f2 + ".png")
105
// Создать в Excel пригодную матрицу цветов
107
// "files" + oss.OpSystemFilder + filename + ".xlsx"
108
func Imagesc(C mat.Dense, Path, FileName string) {
109
r1 := color{r: 0, g: 255, b: 255}
110
r2 := color{r: 255, g: 255, b: 0}
112
min_val := oss.MinDense(C)
113
max_val := oss.MaxDense(C)
114
delta := max_val - min_val
117
file_graph := excelize.NewFile()
118
file_graph.NewSheet("main")
119
file_graph.DeleteSheet("Sheet1")
121
//err := file_graph.SetSheetProps("main", opts*SheetPropsOptions)
124
file_graph.SetColWidth("main", oss.GetColumnName(1), oss.GetColumnName(c), 5)
125
for i := 0; i < r; i++ {
126
file_graph.SetRowHeight("main", i, 35)
127
for j := 0; j < c; j++ {
128
k := uint8(math.Round((C.At(i, j) - min_val) / delta * 100.0))
129
colorOutput := colorSet(r1, r2, k)
131
r := fmt.Sprintf("%x", colorOutput.r)
132
g := fmt.Sprintf("%x", colorOutput.g)
133
b := fmt.Sprintf("%x", colorOutput.b)
135
style, err := file_graph.NewStyle(`{"fill":{"type":"pattern","color":["#` + r + g + b + `"],"pattern":1}}`)
139
cell := oss.GetColumnName(j+1) + strconv.Itoa(i+1)
140
file_graph.SetCellStyle("main", cell, cell, style)
143
if err := file_graph.SetRowVisible("main", r, true); err != nil {
146
if err := file_graph.SetColVisible("main", "A:"+oss.GetColumnName(c), true); err != nil {
149
// "files" + oss.OpSystemFilder + filename + ".xlsx"
150
if err := file_graph.SaveAs(Path + FileName); err != nil {
156
// Узнать цвет градиента. k=[0;100]
157
func colorSet(r1, r2 color, k uint8) color {
158
return color{r: r1.r*(1-k) + r2.r*k, g: r1.g*(1-k) + r2.g*k, b: r1.b*(1-k) + r2.b*k}