Skip to content

Commit

Permalink
fix: Fix dark/light mode watcher in dashboard charts
Browse files Browse the repository at this point in the history
  • Loading branch information
billyc committed Dec 8, 2021
1 parent 1e6fb21 commit 1291ef7
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 42 deletions.
13 changes: 9 additions & 4 deletions src/charts/area.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import VuePlotly from '@/components/VuePlotly.vue'
import DashboardDataManager from '@/js/DashboardDataManager'
import { FileSystemConfig, UI_FONT } from '@/Globals'
import globalStore from '@/store'
@Component({ components: { VuePlotly } })
export default class VueComponent extends Vue {
@Prop({ required: true }) fileSystemConfig!: FileSystemConfig
Expand All @@ -24,7 +26,7 @@ export default class VueComponent extends Vue {
@Prop({ required: true }) config!: any
@Prop() datamanager!: DashboardDataManager
private globalState = this.$store.state
private globalState = globalStore.state
// dataSet is either x,y or allRows[]
private dataSet: { x?: any[]; y?: any[]; allRows?: any[] } = {}
Expand All @@ -38,9 +40,12 @@ export default class VueComponent extends Vue {
}
@Watch('globalState.isDarkMode') updateTheme() {
this.layout.paper_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff' // #f8f8ff
this.layout.plot_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff'
this.layout.font.color = this.globalState.isDarkMode ? '#cccccc' : '#444444'
const colors = {
paper_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
plot_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
font: { color: this.globalState.isDarkMode ? '#cccccc' : '#444444' },
}
this.layout = Object.assign({}, this.layout, colors)
}
private async loadData() {
Expand Down
21 changes: 12 additions & 9 deletions src/charts/bar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@ export default class VueComponent extends Vue {
}
@Watch('globalState.isDarkMode') updateTheme() {
this.layout.paper_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff' // #f8f8ff
this.layout.plot_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff'
this.layout.font.color = this.globalState.isDarkMode ? '#cccccc' : '#444444'
const colors = {
paper_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
plot_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
font: { color: this.globalState.isDarkMode ? '#cccccc' : '#444444' },
}
this.layout = Object.assign({}, this.layout, colors)
}
private updateLayout() {
this.layout.xaxis.title = this.config.xAxisTitle || ''
this.layout.yaxis.title = this.config.yAxisTitle || ''
this.layout.xaxis.title = this.config.xAxisTitle || this.config.xAxisName || ''
this.layout.yaxis.title = this.config.yAxisTitle || this.config.yAxisName || ''
}
private async handlePlotlyClick(click: any) {
Expand Down Expand Up @@ -187,11 +190,14 @@ export default class VueComponent extends Vue {
var useOwnNames = false
// old configs called it "usedCol" --> now "columns"
const columns = this.config.columns || this.config.usedCol
// old legendname field
if (this.config.legendName) this.config.legendTitles = this.config.legendName
if (this.config.legendTitles !== undefined) {
if (this.config.legendTitles.length === this.config.columns.length) {
if (this.config.legendTitles.length === columns.length) {
useOwnNames = true
}
}
Expand All @@ -208,9 +214,6 @@ export default class VueComponent extends Vue {
}
}
// old configs called it "usedCol" --> now "columns"
const columns = this.config.columns || this.config.usedCol
for (let i = 0; i < columns.length; i++) {
const name = columns[i]
let legendName = ''
Expand Down
19 changes: 13 additions & 6 deletions src/charts/bubble.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import DashboardDataManager from '@/js/DashboardDataManager'
import VuePlotly from '@/components/VuePlotly.vue'
import { FileSystemConfig, UI_FONT } from '@/Globals'
import globalStore from '@/store'
@Component({ components: { VuePlotly } })
export default class VueComponent extends Vue {
Expand All @@ -23,7 +24,7 @@ export default class VueComponent extends Vue {
@Prop({ required: true }) config!: any
@Prop() datamanager!: DashboardDataManager
private globalState = this.$store.state
private globalState = globalStore.state
// dataSet is either x,y or allRows[]
private dataSet: { x?: any[]; y?: any[]; allRows?: any[] } = {}
Expand All @@ -37,9 +38,12 @@ export default class VueComponent extends Vue {
}
@Watch('globalState.isDarkMode') updateTheme() {
this.layout.paper_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff' // #f8f8ff
this.layout.plot_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff'
this.layout.font.color = this.globalState.isDarkMode ? '#cccccc' : '#444444'
const colors = {
paper_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
plot_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
font: { color: this.globalState.isDarkMode ? '#cccccc' : '#444444' },
}
this.layout = Object.assign({}, this.layout, colors)
}
private async loadData() {
Expand All @@ -57,6 +61,9 @@ export default class VueComponent extends Vue {
}
private updateChart() {
this.layout.xaxis.title = this.config.xAxisTitle || this.config.xAxisName || ''
this.layout.yaxis.title = this.config.yAxisTitle || this.config.yAxisName || ''
if (this.config.groupBy) this.updateChartWithGroupBy()
else this.updateChartSimple()
}
Expand Down Expand Up @@ -131,11 +138,11 @@ export default class VueComponent extends Vue {
},
xaxis: {
autorange: true,
title: this.config.xAxisName,
title: '',
},
yaxis: {
autorange: true,
title: this.config.yAxisName,
title: '',
},
legend: {
x: 1,
Expand Down
12 changes: 8 additions & 4 deletions src/charts/heatmap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Vue, Component, Watch, Prop } from 'vue-property-decorator'
import VuePlotly from '@/components/VuePlotly.vue'
import DashboardDataManager from '@/js/DashboardDataManager'
import { FileSystemConfig, UI_FONT } from '@/Globals'
import globalStore from '@/store'
@Component({ components: { VuePlotly } })
export default class VueComponent extends Vue {
Expand All @@ -23,7 +24,7 @@ export default class VueComponent extends Vue {
@Prop({ required: true }) config!: any
@Prop() datamanager!: DashboardDataManager
private globalState = this.$store.state
private globalState = globalStore.state
// dataSet is either x,y or allRows[]
private dataSet: { x?: any[]; y?: any[]; allRows?: any[] } = {}
Expand All @@ -37,9 +38,12 @@ export default class VueComponent extends Vue {
}
@Watch('globalState.isDarkMode') updateTheme() {
this.layout.paper_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff' // #f8f8ff
this.layout.plot_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff'
this.layout.font.color = this.globalState.isDarkMode ? '#cccccc' : '#444444'
const colors = {
paper_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
plot_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
font: { color: this.globalState.isDarkMode ? '#cccccc' : '#444444' },
}
this.layout = Object.assign({}, this.layout, colors)
}
private async loadData() {
Expand Down
20 changes: 14 additions & 6 deletions src/charts/line.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import VuePlotly from '@/components/VuePlotly.vue'
import { FileSystemConfig, UI_FONT } from '@/Globals'
import globalStore from '@/store'
@Component({ components: { VuePlotly } })
export default class VueComponent extends Vue {
@Prop({ required: true }) fileSystemConfig!: FileSystemConfig
Expand All @@ -23,7 +25,7 @@ export default class VueComponent extends Vue {
@Prop({ required: true }) config!: any
@Prop() datamanager!: DashboardDataManager
private globalState = this.$store.state
private globalState = globalStore.state
// dataSet is either x,y or allRows[]
private dataSet: { x?: any[]; y?: any[]; allRows?: any[] } = {}
Expand All @@ -37,9 +39,12 @@ export default class VueComponent extends Vue {
}
@Watch('globalState.isDarkMode') updateTheme() {
this.layout.paper_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff' // #f8f8ff
this.layout.plot_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff'
this.layout.font.color = this.globalState.isDarkMode ? '#cccccc' : '#444444'
const colors = {
paper_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
plot_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
font: { color: this.globalState.isDarkMode ? '#cccccc' : '#444444' },
}
this.layout = Object.assign({}, this.layout, colors)
}
private async loadData() {
Expand All @@ -57,6 +62,9 @@ export default class VueComponent extends Vue {
}
private updateChart() {
this.layout.xaxis.title = this.config.xAxisTitle || this.config.xAxisName || ''
this.layout.yaxis.title = this.config.yAxisTitle || this.config.yAxisName || ''
if (this.config.groupBy) this.updateChartWithGroupBy()
else this.updateChartSimple()
}
Expand Down Expand Up @@ -131,11 +139,11 @@ export default class VueComponent extends Vue {
},
xaxis: {
autorange: true,
title: this.config.xAxisName,
title: '',
},
yaxis: {
autorange: true,
title: this.config.yAxisName,
title: '',
},
legend: {
x: 1,
Expand Down
14 changes: 8 additions & 6 deletions src/charts/pie.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import DashboardDataManager from '@/js/DashboardDataManager'
import VuePlotly from '@/components/VuePlotly.vue'
import { FileSystemConfig, UI_FONT } from '@/Globals'
import globalStore from '@/store'
@Component({ components: { VuePlotly } })
export default class VueComponent extends Vue {
Expand All @@ -23,7 +24,7 @@ export default class VueComponent extends Vue {
@Prop({ required: true }) config!: any
@Prop() datamanager!: DashboardDataManager
private globalState = this.$store.state
private globalState = globalStore.state
private id = 'pie-' + Math.random()
Expand All @@ -38,9 +39,12 @@ export default class VueComponent extends Vue {
}
@Watch('globalState.isDarkMode') updateTheme() {
this.layout.paper_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff' // #f8f8ff
this.layout.plot_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff'
this.layout.font.color = this.globalState.isDarkMode ? '#cccccc' : '#444444'
const colors = {
paper_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
plot_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
font: { color: this.globalState.isDarkMode ? '#cccccc' : '#444444' },
}
this.layout = Object.assign({}, this.layout, colors)
}
private async loadData() {
Expand Down Expand Up @@ -68,10 +72,8 @@ export default class VueComponent extends Vue {
private updateChartSimple() {
const allRows = this.dataSet.allRows || {}
console.log({ allRows })
this.data[0].labels = Object.keys(allRows)
this.data[0].values = Object.values(allRows)
console.log(this.data)
}
private layout: any = {
Expand Down
19 changes: 13 additions & 6 deletions src/charts/scatter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import DashboardDataManager from '@/js/DashboardDataManager'
import VuePlotly from '@/components/VuePlotly.vue'
import { FileSystemConfig, UI_FONT } from '@/Globals'
import globalStore from '@/store'
@Component({ components: { VuePlotly } })
export default class VueComponent extends Vue {
Expand All @@ -23,7 +24,7 @@ export default class VueComponent extends Vue {
@Prop({ required: true }) config!: any
@Prop() datamanager!: DashboardDataManager
private globalState = this.$store.state
private globalState = globalStore.state
// dataSet is either x,y or allRows[]
private dataSet: { x?: any[]; y?: any[]; allRows?: any[] } = {}
Expand All @@ -37,9 +38,12 @@ export default class VueComponent extends Vue {
}
@Watch('globalState.isDarkMode') updateTheme() {
this.layout.paper_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff' // #f8f8ff
this.layout.plot_bgcolor = this.globalState.isDarkMode ? '#282c34' : '#fff'
this.layout.font.color = this.globalState.isDarkMode ? '#cccccc' : '#444444'
const colors = {
paper_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
plot_bgcolor: this.globalState.isDarkMode ? '#282c34' : '#fff',
font: { color: this.globalState.isDarkMode ? '#cccccc' : '#444444' },
}
this.layout = Object.assign({}, this.layout, colors)
}
private async loadData() {
Expand All @@ -57,6 +61,9 @@ export default class VueComponent extends Vue {
}
private updateChart() {
this.layout.xaxis.title = this.config.xAxisTitle || this.config.xAxisName || ''
this.layout.yaxis.title = this.config.yAxisTitle || this.config.yAxisName || ''
if (this.config.groupBy) this.updateChartWithGroupBy()
else this.updateChartSimple()
}
Expand Down Expand Up @@ -136,11 +143,11 @@ export default class VueComponent extends Vue {
},
xaxis: {
autorange: true,
title: this.config.xAxisName,
title: this.config?.xAxisName,
},
yaxis: {
autorange: true,
title: this.config.yAxisName,
title: this.config?.yAxisName,
},
legend: {
x: 1,
Expand Down
6 changes: 5 additions & 1 deletion src/components/VuePlotly.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export default class VueComponent extends Vue {
@Watch('layout')
@Watch('options')
private updatePlot() {
Plotly.react(this.plotlyId, this.data, this.layout, this.options)
try {
Plotly.react(this.plotlyId, this.data, this.layout, this.options)
} catch (e) {
// can error if layout changes before plot is plotted. Ignore.
}
}
}
</script>

0 comments on commit 1291ef7

Please sign in to comment.