Skip to content

Commit

Permalink
refactor: restructure chart, event and customSVGOptions dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikThePendric committed Oct 21, 2024
1 parent 489ea08 commit 159727c
Show file tree
Hide file tree
Showing 28 changed files with 137 additions and 121 deletions.
63 changes: 0 additions & 63 deletions src/visualizations/config/adapters/dhis_highcharts/chart.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getEvents } from '../events/index.js'
import getType from '../type.js'

const DEFAULT_CHART = {
spacingTop: 20,
style: {
fontFamily: 'Roboto,Helvetica Neue,Helvetica,Arial,sans-serif',
},
}

const DASHBOARD_CHART = {
spacingTop: 0,
spacingRight: 5,
spacingBottom: 2,
spacingLeft: 5,
}

export default function getDefaultChart(layout, el, extraOptions) {
return Object.assign(
{},
getType(layout.type),
{ renderTo: el || layout.el },
DEFAULT_CHART,
extraOptions.dashboard ? DASHBOARD_CHART : undefined,
getEvents(layout.type)
)
}
12 changes: 12 additions & 0 deletions src/visualizations/config/adapters/dhis_highcharts/chart/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { VIS_TYPE_SINGLE_VALUE } from '../../../../../modules/visTypes.js'
import getDefaultChart from './default.js'
import getSingleValueChart from './singleValue.js'

export default function getChart(layout, el, extraOptions, series) {
switch (layout.type) {
case VIS_TYPE_SINGLE_VALUE:
return getSingleValueChart(layout, el, extraOptions, series)
default:
return getDefaultChart(layout, el, extraOptions)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { getSingleValueBackgroundColor } from '../customSVGOptions/singleValue/getSingleValueBackgroundColor.js'
import getDefaultChart from './default.js'

export default function getSingleValueChart(layout, el, extraOptions, series) {
const chart = {
...getDefaultChart(layout, el, extraOptions),
backgroundColor: getSingleValueBackgroundColor(
layout.legend,
extraOptions.legendSets,
series[0]
),
}

if (extraOptions.dashboard) {
chart.spacingTop = 7
}

return chart
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { VIS_TYPE_SINGLE_VALUE } from '../../../../../modules/visTypes.js'
import { getSingleValueCustomSVGOptions } from './singleValue/index.js'
import { renderSingleValueSVG } from './singleValue/renderer/renderSingleValueSVG.js'
import getSingleValueCustomSVGOptions from './singleValue/index.js'

export function renderCustomSVG(visType) {
switch (visType) {
case VIS_TYPE_SINGLE_VALUE:
renderSingleValueSVG.call(this)
break
default:
break
}
}

export function getCustomSVGOptions({
export default function getCustomSVGOptions({
extraConfig,
layout,
extraOptions,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LEGEND_DISPLAY_STYLE_FILL } from '../../../../../../../modules/legends.js'
import { LEGEND_DISPLAY_STYLE_FILL } from '../../../../../../modules/legends.js'
import { getSingleValueLegendColor } from './getSingleValueLegendColor.js'

export function getSingleValueBackgroundColor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderValue } from '../../../../../../../modules/renderValue.js'
import { VALUE_TYPE_TEXT } from '../../../../../../../modules/valueTypes.js'
import { renderValue } from '../../../../../../modules/renderValue.js'
import { VALUE_TYPE_TEXT } from '../../../../../../modules/valueTypes.js'

export const INDICATOR_FACTOR_100 = 100

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getColorByValueFromLegendSet } from '../../../../../../../modules/legends.js'
import { getColorByValueFromLegendSet } from '../../../../../../modules/legends.js'

export function getSingleValueLegendColor(legendOptions, legendSets, value) {
const legendSet = legendOptions && legendSets[0]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { colors } from '@dhis2/ui'
import { LEGEND_DISPLAY_STYLE_TEXT } from '../../../../../../../modules/legends.js'
import { shouldUseContrastColor } from '../../../../../../util/shouldUseContrastColor.js'
import { LEGEND_DISPLAY_STYLE_TEXT } from '../../../../../../modules/legends.js'
import { shouldUseContrastColor } from '../../../../../util/shouldUseContrastColor.js'
import { getSingleValueLegendColor } from './getSingleValueLegendColor.js'

export function getSingleValueTextColor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { colors } from '@dhis2/ui'
import { LEGEND_DISPLAY_STYLE_FILL } from '../../../../../../../modules/legends.js'
import { shouldUseContrastColor } from '../../../../../../util/shouldUseContrastColor.js'
import { LEGEND_DISPLAY_STYLE_FILL } from '../../../../../../modules/legends.js'
import { shouldUseContrastColor } from '../../../../../util/shouldUseContrastColor.js'
import { getSingleValueLegendColor } from './getSingleValueLegendColor.js'

export function getSingleValueTitleColor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
export { getSingleValueCustomSVGOptions } from './config/getSingleValueCustomSVGOptions.js'
export { getSingleValueBackgroundColor } from './config/getSingleValueBackgroundColor.js'
export { getSingleValueTitleColor } from './config/getSingleValueTitleColor.js'
import { colors } from '@dhis2/ui'
import { getSingleValueFormattedValue } from './getSingleValueFormattedValue.js'
import { getSingleValueSubtext } from './getSingleValueSubtext.js'
import { getSingleValueTextColor } from './getSingleValueTextColor.js'

export default function getSingleValueCustomSVGOptions({
layout,
extraOptions,
metaData,
series,
}) {
const { dashboard, icon } = extraOptions
const value = series[0]
return {
value,
fontColor: getSingleValueTextColor(
colors.grey900,
value,
layout.legend,
extraOptions.legendSets
),
formattedValue: getSingleValueFormattedValue(value, layout, metaData),
icon,
dashboard,
subText: getSingleValueSubtext(metaData),
}
}
23 changes: 23 additions & 0 deletions src/visualizations/config/adapters/dhis_highcharts/events/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import loadCustomSVG from './loadCustomSVG/index.js'

export const getEvents = (visType) => ({
events: {
load: function () {
// Align legend icon with legend text
this.legend.allItems.forEach((item) => {
if (item.legendSymbol) {
item.legendSymbol.attr({
translateY:
-(
(item.legendItem.label.getBBox().height *
0.75) /
4
) +
item.legendSymbol.r / 2,
})
}
})
loadCustomSVG.call(this, visType)
},
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { VIS_TYPE_SINGLE_VALUE } from '../../../../../../modules/visTypes.js'
import loadSingleValueSVG from './singleValue/index.js'

export default function loadCustomSVG(visType) {
switch (visType) {
case VIS_TYPE_SINGLE_VALUE:
loadSingleValueSVG.call(this)
break
default:
break
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getAvailableSpace } from './getAvailableSpace.js'
import { positionElements } from './positionElements.js'
import { DynamicStyles } from './styles.js'

export function renderSingleValueSVG() {
export default function loadSingleValueSVG() {
const { formattedValue, icon, subText, fontColor } =
this.userOptions.customSVGOptions
const dynamicStyles = new DynamicStyles(this.userOptions?.isPdfExport)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { VIS_TYPE_SINGLE_VALUE } from '../../../../modules/visTypes.js'
import { renderSingleValueSVG } from './customSVGOptions/singleValue/renderer/renderSingleValueSVG.js'
import loadSingleValueSVG from './events/loadCustomSVG/singleValue/index.js'

export default function getExporting(visType) {
const exporting = {
Expand All @@ -13,7 +13,7 @@ export default function getExporting(visType) {
chartOptions: {
chart: {
events: {
load: renderSingleValueSVG,
load: loadSingleValueSVG,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/visualizations/config/adapters/dhis_highcharts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
} from '../../../../modules/visTypes.js'
import { defaultMultiAxisTheme1 } from '../../../util/colors/themes.js'
import addTrendLines, { isRegressionIneligible } from './addTrendLines.js'
import getChart from './chart.js'
import { getCustomSVGOptions } from './customSVGOptions/index.js'
import getChart from './chart/index.js'
import getCustomSVGOptions from './customSVGOptions/index.js'
import getExporting from './exporting.js'
import getScatterData from './getScatterData.js'
import getSortedConfig from './getSortedConfig.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import getFilterText from '../../../../util/getFilterText.js'
export { getSingleValueTitleColor as getSingleValueSubtitleColor } from '../customSVGOptions/singleValue/index.js'
export { getSingleValueTitleColor as getSingleValueSubtitleColor } from '../customSVGOptions/singleValue/getSingleValueTitleColor.js'

export default function getSingleValueSubtitle(layout, metaData) {
if (layout.hideSubtitle || 1 === 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import getFilterText from '../../../../util/getFilterText.js'
export { getSingleValueTitleColor } from '../customSVGOptions/singleValue/index.js'
export { getSingleValueTitleColor } from '../customSVGOptions/singleValue/getSingleValueTitleColor.js'

export function getSingleValueTitleText(layout, metaData) {
if (layout.hideTitle) {
Expand Down

0 comments on commit 159727c

Please sign in to comment.