Skip to content

Commit

Permalink
- ADD: Added initial version of balloon chart.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-raubach committed Dec 3, 2024
1 parent b8b1016 commit 0bade96
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 6 deletions.
161 changes: 161 additions & 0 deletions src/components/charts/BalloonChart.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<template>
<div v-if="plotData && plotData.length > 0">
<BaseChart :id="id" :width="() => 1280" :height="() => height" chartType="plotly" :filename="baseFilename" v-on:resize="update" :supportsPngDownload="true" :supportsSvgDownload="true" v-on:force-redraw="update">
<div slot="chart" ref="chart" />
</BaseChart>
</div>
</template>

<script>
import { mapGetters } from 'vuex'
import BaseChart from '@/components/charts/BaseChart'
import { uuidv4 } from '@/mixins/util'
const Plotly = require('plotly.js/lib/core')
// Only register the chart types we're actually using to reduce the final bundle size
Plotly.register([
require('plotly.js/lib/scatter')
])
export default {
props: {
plotData: {
type: Array,
default: () => []
},
stats: {
type: Array,
default: () => []
},
baseFilename: {
type: String,
default: 'balloon-chart'
}
},
data: function () {
const id = 'chart-' + uuidv4()
return {
id: id,
isUpdating: false,
height: 600
}
},
computed: {
...mapGetters([
'storeDarkMode'
])
},
watch: {
plotData: {
deep: true,
handler: function () {
this.update()
}
},
stats: function () {
this.update()
}
},
components: {
BaseChart
},
methods: {
update: function () {
if (this.isUpdating) {
return
}
this.isUpdating = true
this.$nextTick(() => {
if (!this.plotData || this.plotData.length < 1) {
return
}
const div = this.$refs.chart
try {
// Plotly.purge(div)
} catch (e) {
// Nothing
}
const data = []
this.height = Math.max(500, this.plotData.length * 175)
if (this.stats && this.stats.length > 0) {
this.stats.forEach(st => {
data.push({
y: st.values.map(_ => st.displayName),
x: st.dims,
mode: 'markers',
name: st.displayName,
marker: {
size: st.values,
color: st.values.map(_ => st.color),
opacity: st.values.map(_ => 1)
}
})
})
}
this.plotData.forEach(pd => {
data.push({
y: pd.values.map(_ => pd.displayName),
x: pd.dims,
mode: 'markers',
customdata: pd.customdata,
name: pd.displayName,
marker: {
size: pd.values,
color: pd.values.map(_ => pd.color),
opacity: pd.values.map(_ => 1)
},
hovertemplate: '%{y}<br>%{customdata}'
})
})
const layout = {
paper_bgcolor: 'transparent',
plot_bgcolor: 'transparent',
height: this.height,
showlegend: data.length > 1,
xaxis: {
title: { text: null, font: { color: this.storeDarkMode ? 'white' : 'black' } },
tickfont: { color: this.storeDarkMode ? 'white' : 'black' }
},
yaxis: {
title: { text: null, font: { color: this.storeDarkMode ? 'white' : 'black' } },
tickfont: { color: this.storeDarkMode ? 'white' : 'black' }
},
legend: {
bgcolor: 'rgba(0,0,0,0)',
orientation: 'h',
font: { color: this.storeDarkMode ? 'white' : 'black' },
x: 0,
y: 1.1
}
}
const config = {
modeBarButtonsToRemove: ['toImage'],
displayModeBar: true,
responsive: true,
displaylogo: false
}
Plotly.react(div, data, layout, config)
this.isUpdating = false
})
}
},
mounted: function () {
this.update()
}
}
</script>

<style>
</style>
8 changes: 4 additions & 4 deletions src/components/charts/TimelineChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export default {
if (this.selectedGermplasm.length > 0) {
this.selectedGermplasm.forEach((gp, i) => {
const germplasmData = this.traitData.filter(td => td.trialRow === gp.row && td.trialColumn === gp.column && td.germplasmName === gp.germplasm)
const germplasmData = this.traitData.filter(td => td.trialsetupId === gp.trialsetupId)
const treatments = [...new Set(germplasmData.map(td => td.treatment))]
treatments.forEach(t => {
Expand Down Expand Up @@ -345,7 +345,7 @@ export default {
this.selectedGermplasm.splice(index, 1)
},
onGermplasmSelected: function (newGermplasm) {
const index = this.selectedGermplasm.findIndex(sg => sg.row === newGermplasm.row && sg.column === newGermplasm.column && sg.germplasm === newGermplasm.germplasm)
const index = this.selectedGermplasm.findIndex(sg => sg.trialsetupId === newGermplasm.trialsetupId)
if (index === -1) {
this.selectedGermplasm.push(newGermplasm)
Expand Down Expand Up @@ -382,8 +382,8 @@ export default {
yaxis: {
gridcolor: this.storeDarkMode ? 'rgba(1.0, 1.0, 1.0, 0.1)' : 'rgba(0.0, 0.0, 0.0, 0.1)',
title: { text: this.$t('chartAxisTitleValue'), font: { color: this.storeDarkMode ? 'white' : 'black' } },
tickfont: { color: this.storeDarkMode ? 'white' : 'black' },
range: this.traitStats ? [this.traitStats.min - (this.traitStats.max - this.traitStats.min) * 0.05, this.traitStats.max + (this.traitStats.max - this.traitStats.min) * 0.05] : null
tickfont: { color: this.storeDarkMode ? 'white' : 'black' }
// range: this.traitStats ? [this.traitStats.min - (this.traitStats.max - this.traitStats.min) * 0.05, this.traitStats.max + (this.traitStats.max - this.traitStats.min) * 0.05] : null
},
hovermode: 'x',
shapes: [{
Expand Down
5 changes: 4 additions & 1 deletion src/components/export/TraitRadarChartSelection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<b-col class="mb-3" :cols="radarCols.cols" :md="radarCols.md" :lg="radarCols.lg" v-for="(data, index) in radarChartDataArray" :key="`radar-chart-data-${index}`">
<h3 v-if="individualCharts">{{ data[0].displayName }}</h3>
<RadarChart :baseFilename="`radar-chart-${datasetIds.join(',')}`" :plotData="data" :stats="plotDataStats" @rotated="e => updateRotation(index, e)" :ref="`radar-chart-${index}`" />
<BalloonChart :baseFilename="`balloon-chart-${datasetIds.join(',')}`" :plotData="data" :stats="plotDataStats" :ref="`radar-chart-${index}`" />
</b-col>
</template>
</b-row>
Expand All @@ -45,6 +46,7 @@
<script>
import MdiIcon from '@/components/icons/MdiIcon'
import RadarChart from '@/components/charts/RadarChart'
import BalloonChart from '@/components/charts/BalloonChart'
import SearchableSelect from '@/components/util/SearchableSelect'
import TrialGermplasmLookup from '@/components/util/TrialGermplasmLookup'
import { apiPostTraitDatasetStats, apiPostTrialsDataTable } from '@/mixins/api/trait'
Expand Down Expand Up @@ -266,7 +268,8 @@ export default {
MdiIcon,
SearchableSelect,
TrialGermplasmLookup,
RadarChart
RadarChart,
BalloonChart
},
methods: {
updateRotation: function (indexToSkip, rotation) {
Expand Down
1 change: 1 addition & 0 deletions src/components/structure/SidebarComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export default {
{
href: { name: Pages.projects },
title: this.$t('menuProjects'),
identifiers: ['projects'],
badge: {
text: (this.storeSelectedProjects && this.storeSelectedProjects.length > 0) ? `${this.storeSelectedProjects.length}/${this.getBadgeCount(this.badgeCounts, 'projects')}` : this.getBadgeCount(this.badgeCounts, 'projects'),
class: 'vsm--badge vsm--badge_default'
Expand Down
2 changes: 2 additions & 0 deletions src/components/util/TrialGermplasmLookup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default {
germplasm: item.germplasmName,
rep: item.rep || 'N/A',
row: item.trialRow || 'N/A',
treatment: item.treatment || 'N/A',
column: item.trialColumn || 'N/A',
block: item.block || 'N/A'
})
Expand All @@ -87,6 +88,7 @@ export default {
germplasm: germplasm.germplasmName,
rep: germplasm.rep,
row: germplasm.trialRow,
treatment: germplasm.treatment || 'N/A',
column: germplasm.trialColumn,
block: germplasm.block || 'N/A'
})
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/i18n/en_GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"dropdownUserSettingsGermplasmUnifier": "Germplasm unifier",
"dropdownUserSettingsGerminateSettings": "Germinate settings",
"dropdownUserSettingsGetToken": "Get access token",
"dropdownLabelGermplasmSearch": "{germplasm}, Rep: {rep}, Block: {block}, Row: {row}, Column: {column}",
"dropdownLabelGermplasmSearch": "{germplasm}, Rep: {rep}, Block: {block}, Treatment: {treatment}, Row: {row}, Column: {column}",
"dublinCoreContributor": "Contributor",
"dublinCoreCoverage": "Coverage",
"dublinCoreCreator": "Creator",
Expand Down

0 comments on commit 0bade96

Please sign in to comment.