2020-11-13 15:20:34 +08:00
|
|
|
// Copyright 2020 Google Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package heatmap
|
|
|
|
|
|
|
|
import (
|
2020-11-18 17:22:49 +08:00
|
|
|
"errors"
|
2020-11-13 15:20:34 +08:00
|
|
|
"github.com/mum4k/termdash/cell"
|
|
|
|
)
|
|
|
|
|
|
|
|
// options.go contains configurable options for HeatMap.
|
|
|
|
|
|
|
|
// Option is used to provide options.
|
|
|
|
type Option interface {
|
|
|
|
// set sets the provided option.
|
|
|
|
set(*options)
|
|
|
|
}
|
|
|
|
|
|
|
|
// options stores the provided options.
|
|
|
|
type options struct {
|
2020-11-18 16:01:09 +08:00
|
|
|
// The default value is 3
|
2020-11-13 15:20:34 +08:00
|
|
|
cellWidth int
|
|
|
|
xLabelCellOpts []cell.Option
|
|
|
|
yLabelCellOpts []cell.Option
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate validates the provided options.
|
|
|
|
func (o *options) validate() error {
|
2020-11-18 17:22:49 +08:00
|
|
|
return errors.New("not implemented")
|
2020-11-13 15:20:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// newOptions returns a new options instance.
|
|
|
|
func newOptions(opts ...Option) *options {
|
|
|
|
opt := &options{
|
|
|
|
cellWidth: 3,
|
|
|
|
}
|
|
|
|
for _, o := range opts {
|
|
|
|
o.set(opt)
|
|
|
|
}
|
|
|
|
return opt
|
|
|
|
}
|
|
|
|
|
|
|
|
// option implements Option.
|
|
|
|
type option func(*options)
|
|
|
|
|
|
|
|
// set implements Option.set.
|
|
|
|
func (o option) set(opts *options) {
|
|
|
|
o(opts)
|
|
|
|
}
|
|
|
|
|
2020-11-23 10:57:07 +08:00
|
|
|
// CellWidth set the width of cells (or grids) in the heat map, not the terminal cell.
|
|
|
|
// The default height of each cell (grid) is 1 and the width is 3.
|
2020-11-19 21:31:59 +08:00
|
|
|
func CellWidth(w int) Option {
|
|
|
|
return option(func(opts *options) {
|
|
|
|
opts.cellWidth = w
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:20:34 +08:00
|
|
|
// XLabelCellOpts set the cell options for the labels on the X axis.
|
|
|
|
func XLabelCellOpts(co ...cell.Option) Option {
|
|
|
|
return option(func(opts *options) {
|
|
|
|
opts.xLabelCellOpts = co
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// YLabelCellOpts set the cell options for the labels on the Y axis.
|
|
|
|
func YLabelCellOpts(co ...cell.Option) Option {
|
|
|
|
return option(func(opts *options) {
|
|
|
|
opts.yLabelCellOpts = co
|
|
|
|
})
|
|
|
|
}
|