Skip to content

Commit d98d3ae

Browse files
author
Marko Petzold
committed
feat: Update widget-linechart to version 1.6.5; refactor theme handling and improve chart rendering
1 parent 54051f3 commit d98d3ae

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

demo/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
import '../dist/widget-linechart.js'
2929
const data = await fetch('../src/default-data.json').then((res) => res.json())
3030
const themeObject = await fetch('themes/vintage.json').then((res) => res.json())
31+
const theme = { theme_name: 'vintage', theme_object: themeObject }
3132

3233
render(
3334
html`
34-
<widget-linechart-1.6.4 .themeObject="${themeObject}" .inputData=${data}>
35+
<widget-linechart-1.6.5 .theme="${theme}" .inputData=${data}>
3536
web component is not registered. Make sure to use the tag with the correct version
3637
string from the package.json
37-
</widget-linechart-1.6.4>
38+
</widget-linechart-1.6.5>
3839
`,
3940
document.querySelector('#demo')
4041
)

src/widget-linechart.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ import { InputData } from './definition-schema'
3333
import { EChartsOption, ScatterSeriesOption, SeriesOption } from 'echarts'
3434
import { TitleOption } from 'echarts/types/dist/shared'
3535

36+
type Theme = {
37+
theme_name: string
38+
theme_object: any
39+
}
3640
@customElement('widget-linechart-versionplaceholder')
3741
export class WidgetLinechart extends LitElement {
3842
@property({ type: Object })
3943
inputData?: InputData
4044

4145
@property({ type: Object })
42-
themeObject?: any
43-
44-
@property({ type: String })
45-
themeName?: string
46+
theme?: Theme
4647

4748
@state()
4849
private canvasList: Map<
@@ -172,12 +173,8 @@ export class WidgetLinechart extends LitElement {
172173
this.applyData()
173174
}
174175

175-
if (changedProperties.has('themeObject')) {
176-
this.registerTheme(this.themeName, this.themeObject)
177-
}
178-
179-
if (changedProperties.has('themeName')) {
180-
this.registerTheme(this.themeName, this.themeObject)
176+
if (changedProperties.has('theme')) {
177+
this.registerTheme(this.theme)
181178
this.deleteCharts()
182179
this.transformData()
183180
this.applyData()
@@ -200,10 +197,11 @@ export class WidgetLinechart extends LitElement {
200197
}
201198
}
202199

203-
registerTheme(themeName?: string, themeObject?: any) {
204-
if (!themeObject || !themeName) return
200+
registerTheme(theme?: Theme) {
201+
if (!theme || !theme.theme_object || !theme.theme_name) return
205202

206-
echarts.registerTheme(themeName, this.themeObject)
203+
console.log('Registering theme', theme)
204+
echarts.registerTheme(theme.theme_name, theme.theme_object)
207205
}
208206

209207
transformData() {
@@ -363,7 +361,7 @@ export class WidgetLinechart extends LitElement {
363361
newContainer.setAttribute('class', 'sizer')
364362
this.chartContainer.appendChild(newContainer)
365363

366-
const newChart = echarts.init(newContainer, this.themeName)
364+
const newChart = echarts.init(newContainer, this.theme?.theme_name)
367365
const chart = { echart: newChart, series: [] as SeriesOption[], element: newContainer }
368366
this.canvasList.set(label, chart)
369367
//@ts-ignore

0 commit comments

Comments
 (0)