Skip to content

Commit

Permalink
feat: add generic mechanism for rendering custom SVGs on chart load e…
Browse files Browse the repository at this point in the history
…vent
  • Loading branch information
HendrikThePendric committed Sep 11, 2024
1 parent be55d7b commit b782cb2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/visualizations/config/adapters/dhis_highcharts/chart.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { renderCustomSVG } from './custom/index.js'
import getType from './type.js'

const DEFAULT_CHART = {
Expand Down Expand Up @@ -31,6 +32,7 @@ const getEvents = () => ({
})
}
})
renderCustomSVG.call(this)
},
},
})
Expand Down
29 changes: 29 additions & 0 deletions src/visualizations/config/adapters/dhis_highcharts/custom/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { VIS_TYPE_SINGLE_VALUE } from '../../../../../modules/visTypes.js'

export function renderCustomSVG() {
const renderer = this.renderer
const options = this.userOptions.customSVGOptions

switch (options.visualizationType) {
case VIS_TYPE_SINGLE_VALUE:
console.log('now render SV viz', renderer, options)
break
default:
break
}
}

export function getCustomSVGOptions({ layout }) {
const baseOptions = {
visualizationType: layout.type,
}
switch (layout.type) {
case VIS_TYPE_SINGLE_VALUE:
return {
...baseOptions,
test: 1,
}
default:
return null
}
}
10 changes: 10 additions & 0 deletions src/visualizations/config/adapters/dhis_highcharts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { defaultMultiAxisTheme1 } from '../../../util/colors/themes.js'
import addTrendLines, { isRegressionIneligible } from './addTrendLines.js'
import getChart from './chart.js'
import { getCustomSVGOptions } from './custom/index.js'
import getScatterData from './getScatterData.js'
import getSortedConfig from './getSortedConfig.js'
import getTrimmedConfig from './getTrimmedConfig.js'
Expand Down Expand Up @@ -231,8 +232,17 @@ export default function ({ store, layout, el, extraConfig, extraOptions }) {
)
}

/* The config object passed to the Highcharts Chart constructor
* can contain arbitrary properties, which are made accessible
* under the Chart instance's `userOptions` member. This means
* that in event callback functions the custom SVG options are
* accessible as `this.userOptions.customSVGOptions` */
config.customSVGOptions = getCustomSVGOptions({ layout })

// force apply extra config
Object.assign(config, extraConfig)

console.log('CONFIG', objectClean(config))

return objectClean(config)
}

0 comments on commit b782cb2

Please sign in to comment.