| 1 |
{{- define "base_element" -}} |
| 2 |
<div class="container"> |
| 3 |
<div class="item" id="{{ .ChartID }}" style="width:{{ .Initialization.Width }};height:{{ .Initialization.Height }};"></div> |
| 4 |
</div> |
| 5 |
{{- end -}} |
| 6 |
|
| 7 |
{{- define "base_script" -}} |
| 8 |
<script type="text/javascript"> |
| 9 |
"use strict"; |
| 10 |
let goecharts_{{ .ChartID | safeJS }} = echarts.init(document.getElementById('{{ .ChartID | safeJS }}'), "{{ .Theme }}", { renderer: "{{ .Initialization.Renderer }}" }); |
| 11 |
let option_{{ .ChartID | safeJS }} = {{ template "base_option" . }} |
| 12 |
goecharts_{{ .ChartID | safeJS }}.setOption(option_{{ .ChartID | safeJS }}); |
| 13 |
|
| 14 |
{{- range $listener := .EventListeners }} |
| 15 |
{{if .Query }} |
| 16 |
goecharts_{{ $.ChartID | safeJS }}.on({{ $listener.EventName }}, {{ $listener.Query | safeJS }}, {{ injectInstance $listener.Handler "%MY_ECHARTS%" $.ChartID | safeJS }}); |
| 17 |
{{ else }} |
| 18 |
goecharts_{{ $.ChartID | safeJS }}.on({{ $listener.EventName }}, {{ injectInstance $listener.Handler "%MY_ECHARTS%" $.ChartID | safeJS }}) |
| 19 |
{{ end }} |
| 20 |
{{- end }} |
| 21 |
|
| 22 |
{{- range .JSFunctions.Fns }} |
| 23 |
{{ injectInstance . "%MY_ECHARTS%" $.ChartID | safeJS }} |
| 24 |
{{- end }} |
| 25 |
</script> |
| 26 |
{{- end -}} |
| 27 |
|
| 28 |
{{- define "base_option" }} |
| 29 |
{{- .JSONNotEscaped | safeJS }} |
| 30 |
{{- end }}; |
| 31 |
|
| 32 |
{{- define "base" }} |
| 33 |
{{- template "base_element" . }} |
| 34 |
{{- template "base_script" . }} |
| 35 |
{{- end }} |