Skip to content

Commit

Permalink
update: animation enable. (#283)
Browse files Browse the repository at this point in the history
* update: animation enable.
  • Loading branch information
Koooooo-7 committed Apr 3, 2023
1 parent e070b1e commit 6cd6eeb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
23 changes: 18 additions & 5 deletions charts/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type BaseConfiguration struct {
Colors []string
appendColor []string // append customize color to the Colors(reverse order)

// Animation whether enable the animation, default true
Animation bool `json:"animation" default:"true"`

DataZoomList []opts.DataZoom `json:"datazoom,omitempty"`
VisualMapList []opts.VisualMap `json:"visualmap,omitempty"`

Expand Down Expand Up @@ -111,15 +114,18 @@ func (ba *BaseActions) JSONNotEscapedAction() template.HTML {

func (bc *BaseConfiguration) json() map[string]interface{} {
obj := map[string]interface{}{
"title": bc.Title,
"legend": bc.Legend,
"tooltip": bc.Tooltip,
"series": bc.MultiSeries,
"dataset": bc.Dataset,
"title": bc.Title,
"legend": bc.Legend,
"animation": bc.Animation,
"tooltip": bc.Tooltip,
"series": bc.MultiSeries,
"dataset": bc.Dataset,
}

if bc.AxisPointer != nil {
obj["axisPointer"] = bc.AxisPointer
}

if bc.hasPolar {
obj["polar"] = bc.Polar
obj["angleAxis"] = bc.AngleAxis
Expand Down Expand Up @@ -290,6 +296,13 @@ func WithTitleOpts(opt opts.Title) GlobalOpts {
}
}

// WithAnimation enable or disable the animation.
func WithAnimation() GlobalOpts {
return func(bc *BaseConfiguration) {
bc.Animation = false
}
}

// WithToolboxOpts sets the toolbox.
func WithToolboxOpts(opt opts.Toolbox) GlobalOpts {
return func(bc *BaseConfiguration) {
Expand Down
1 change: 1 addition & 0 deletions charts/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (c *Line) SetXAxis(x interface{}) *Line {
// AddSeries adds the new series.
func (c *Line) AddSeries(name string, data []opts.LineData, options ...SeriesOpts) *Line {
series := SingleSeries{Name: name, Type: types.ChartLine, Data: data}
series.InitSeriesDefaultOpts(c.BaseConfiguration)
series.ConfigureSeriesOpts(options...)
c.MultiSeries = append(c.MultiSeries, series)
return c
Expand Down
14 changes: 13 additions & 1 deletion charts/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type SingleSeries struct {
Sort string `json:"sort,omitempty"`
RenderLabelForZeroData bool `json:"renderLabelForZeroData"`
SelectedMode bool `json:"selectedMode"`
Animation bool `json:"animation"`
Animation bool `json:"animation" default:"true"`
AnimationThreshold int `json:"animationThreshold,omitempty"`
AnimationDuration int `json:"animationDuration,omitempty"`
AnimationEasing string `json:"animationEasing,omitempty"`
Expand Down Expand Up @@ -109,6 +109,12 @@ type SingleSeries struct {

type SeriesOpts func(s *SingleSeries)

func WithSeriesAnimation(enable bool) SeriesOpts {
return func(s *SingleSeries) {
s.Animation = enable
}
}

// WithLabelOpts sets the label.
func WithLabelOpts(opt opts.Label) SeriesOpts {
return func(s *SingleSeries) {
Expand Down Expand Up @@ -465,6 +471,12 @@ func WithMarkPointNameCoordItemOpts(opt ...opts.MarkPointNameCoordItem) SeriesOp
}
}

func (s *SingleSeries) InitSeriesDefaultOpts(c BaseConfiguration) {
opts.SetDefaultValue(s)
// some special inherited options from BaseConfiguration
s.Animation = c.Animation
}

func (s *SingleSeries) ConfigureSeriesOpts(options ...SeriesOpts) {
for _, opt := range options {
opt(s)
Expand Down

0 comments on commit 6cd6eeb

Please sign in to comment.