Skip to content

Commit

Permalink
feat: new GridLevelColor
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Dec 9, 2020
1 parent eb3662d commit a793df1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
14 changes: 12 additions & 2 deletions ordinary/ordinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,24 @@ func (variogram *Variogram) Plot(gridMatrices *GridMatrices, width, height int,
} else {
x := float64(width) * (float64(i)*gridMatrices.Width + gridMatrices.Xlim[0] - xlim[0]) / range_[0]
y := float64(height) * (1 - (float64(j)*gridMatrices.Width+gridMatrices.Ylim[0]-ylim[0])/range_[1])
z := (gridMatrices.Data[i][j] - gridMatrices.Zlim[0]) / range_[2]
distance := gridMatrices.Data[i][j] - gridMatrices.Zlim[0]
z := (distance) / range_[2]
if z < 0 {
z = 0.0
} else if z > 1 {
z = 1.0
}

colorIndex := int(math.Floor((float64(len(colors)) - 1) * z))
colorIndex := -1
for index, item := range colors {
if distance >= item.Value[0] && distance <= item.Value[1] {
colorIndex = index
break
}
}
if colorIndex == -1 {
continue
}
color := colors[colorIndex].Color
ctx.DrawRect(math.Round(x-wx/2), math.Round(y-wy/2), wx, wy, color)
}
Expand Down
13 changes: 7 additions & 6 deletions ordinary/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
{Color: NewRGBA(250, 250, 100, 255), Value: [2]float64{5, 10}},
{Color: NewRGBA(252, 207, 81, 255), Value: [2]float64{10, 15}},
{Color: NewRGBA(252, 164, 63, 255), Value: [2]float64{15, 20}},
{Color: NewRGBA(247, 122, 45, 255), Value: [2]float64{20, 25}},
{Color: NewRGBA(242, 77, 31, 255), Value: [2]float64{25, 30}},
{Color: NewRGBA(232, 16, 20, 255), Value: [2]float64{30, 40}},
}
Expand Down Expand Up @@ -72,14 +73,14 @@ type ContourRectangle struct {
YResolution float64 `json:"yResolution"`
}

type Point [2]float64 // [103.614373, 27.00541]
type Point [2]float64 // example [103.614373, 27.00541]

type Ring []Point // [[103.614373, 27.00541],[104.174357, 26.635252],[104.356163, 28.018448],[103.614373, 27.00541]]
type Ring []Point

type PolygonCoordinates []Ring // [[[103.614373, 27.00541],[104.174357, 26.635252],[104.356163, 28.018448],[103.614373, 27.00541]]]
type PolygonCoordinates []Ring

type PolygonGeometry struct {
Type string `json:"type" example:"Polygon"` // Polygon
Type string `json:"type" default:"Polygon"` // Polygon
Coordinates []Ring `json:"coordinates,omitempty"` // coordinates
}

Expand All @@ -89,6 +90,6 @@ func NewRGBA(r, g, b, a uint8) color.RGBA {
}

type GridLevelColor struct {
Value [2]float64 `json:"value" example:"0,5"` // [0, 5]
Color color.RGBA `json:"color"` // {255, 255, 255, 255}
Value [2]float64 `json:"value"` // 值区间 [0, 5]
Color color.RGBA `json:"color"` // RGBA颜色 {255, 255, 255, 255}
}

0 comments on commit a793df1

Please sign in to comment.