Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(render): support render snippets of chart #428

Merged
merged 11 commits into from
May 20, 2024
Merged

Conversation

Koooooo-7
Copy link
Member

@Koooooo-7 Koooooo-7 commented May 20, 2024

Description

Please share your ideas and awesome changes to let us know more :)

As per to the contribution and discussion in #410 .
Do the refine:

  • Only support the RenderSnippets in chart.
  • Refactor templates.
  • Add BaseRender to make the interface implementation easier.
  • Support extract options individually.
  • Support multi render calls and update the before function re-trigger issues.

Example:

// create a new bar instance
	bar := charts.NewBar()
	// set some global options like Title/Legend/ToolTip or anything else
	bar.SetGlobalOptions(charts.WithTitleOpts(opts.Title{
		Title:    "My first bar chart generated by go-echarts",
		Subtitle: "It's extremely easy to use, right?",
	}))

	// Put data into instance
	bar.SetXAxis([]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}).
		AddSeries("Category A", generateBarItems()).
		AddSeries("Category B", generateBarItems())

	chartSnippet := bar.RenderSnippet()

	tmpl := "{{.Element  }} {{.Script}} {{.Option}}"
	t := template.New("snippet")
	t, err := t.Parse(tmpl)
	if err != nil {
		panic(err)
	}

	data := struct {
		Element template.HTML
		Script  template.HTML
		Option  template.HTML
	}{
		Element: template.HTML(chartSnippet.Element),
		Script:  template.HTML(chartSnippet.Script),
		Option:  template.HTML(chartSnippet.Option),
	}

	err = t.Execute(os.Stdout, data)
	if err != nil {
		panic(err)
	}

close #406

Type of change

  • Bug fix (Non-breaking change which fixes an issue)
  • New feature (Non-breaking change which adds functionality)
  • Breaking change (Would cause existing functionality to not work as expected)
  • Docs
  • Others

@Koooooo-7 Koooooo-7 merged commit faa30f0 into master May 20, 2024
5 checks passed
@Koooooo-7 Koooooo-7 deleted the pr-410-todo branch May 20, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[proposal] provide export api for echarts options.
2 participants