-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: implement single value config via Highcharts adapter
- Loading branch information
1 parent
c7304cf
commit bd8158b
Showing
18 changed files
with
301 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 17 additions & 4 deletions
21
.../adapters/dhis_highcharts/custom/index.js → ...dhis_highcharts/customSVGOptions/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,42 @@ | ||
import { VIS_TYPE_SINGLE_VALUE } from '../../../../../modules/visTypes.js' | ||
import { getSingleValueCustomSVGOptions } from './singleValue/index.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) | ||
console.log('now render SV viz', this) | ||
break | ||
default: | ||
break | ||
} | ||
} | ||
|
||
export function getCustomSVGOptions({ layout }) { | ||
export function getCustomSVGOptions({ | ||
extraConfig, | ||
layout, | ||
extraOptions, | ||
metaData, | ||
series, | ||
}) { | ||
const baseOptions = { | ||
visualizationType: layout.type, | ||
} | ||
switch (layout.type) { | ||
case VIS_TYPE_SINGLE_VALUE: | ||
return { | ||
...baseOptions, | ||
test: 1, | ||
...getSingleValueCustomSVGOptions({ | ||
extraConfig, | ||
layout, | ||
extraOptions, | ||
metaData, | ||
series, | ||
}), | ||
} | ||
default: | ||
return null | ||
break | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ig/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueBackgroundColor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { LEGEND_DISPLAY_STYLE_FILL } from '../../../../../../modules/legends.js' | ||
import { getSingleValueLegendColor } from './getSingleValueLegendColor.js' | ||
|
||
export function getSingleValueBackgroundColor( | ||
legendOptions, | ||
legendSets, | ||
value | ||
) { | ||
const legendColor = getSingleValueLegendColor( | ||
legendOptions, | ||
legendSets, | ||
value | ||
) | ||
return legendColor && legendOptions.style === LEGEND_DISPLAY_STYLE_FILL | ||
? legendColor | ||
: 'transparent' | ||
} |
47 changes: 47 additions & 0 deletions
47
...g/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueCustomSVGOptions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { getSingleValueFormattedValue } from './getSingleValueFormattedValue.js' | ||
|
||
export function getSingleValueCustomSVGOptions({ | ||
extraConfig, | ||
layout, | ||
extraOptions, | ||
metaData, | ||
series, | ||
}) { | ||
const { dashboard, legendSets, fontStyle, noData, legendOptions, icon } = | ||
extraOptions | ||
const value = series[0] | ||
|
||
console.log( | ||
'++++setSingleValueOptions++++', | ||
'\nextraConfig: ', | ||
extraConfig, | ||
'\nlayout: ', | ||
layout, | ||
'\nmetaData: ', | ||
metaData, | ||
'\nseries: ', | ||
series, | ||
'\ndashboard: ', | ||
dashboard, | ||
'\nlegendSets: ', | ||
legendSets, | ||
'\nfontStyle: ', | ||
fontStyle, | ||
'\nnoData: ', | ||
noData, | ||
'\nlegendOptions: ', | ||
legendOptions, | ||
'\nicon: ', | ||
icon, | ||
'\n=============' | ||
) | ||
const customSVGOptions = { | ||
value, | ||
formattedValue: getSingleValueFormattedValue(value, layout, metaData), | ||
icon, | ||
dashboard, | ||
subText: 'Test', | ||
} | ||
console.log('singleValueCustomSvgOptions', customSVGOptions) | ||
return customSVGOptions | ||
} |
23 changes: 23 additions & 0 deletions
23
...fig/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueFormattedValue.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { renderValue } from '../../../../../../modules/renderValue.js' | ||
import { VALUE_TYPE_TEXT } from '../../../../../../modules/valueTypes.js' | ||
|
||
export const INDICATOR_FACTOR_100 = 100 | ||
|
||
export function getSingleValueFormattedValue(value, layout, metaData) { | ||
const valueType = metaData.items[metaData.dimensions.dx[0]].valueType | ||
const indicatorType = | ||
metaData.items[metaData.dimensions.dx[0]].indicatorType | ||
|
||
let formattedValue = renderValue(value, valueType || VALUE_TYPE_TEXT, { | ||
digitGroupSeparator: layout.digitGroupSeparator, | ||
skipRounding: layout.skipRounding, | ||
}) | ||
|
||
// only show the percentage symbol for per cent | ||
// for other factors, show the full text under the value | ||
if (indicatorType?.factor === INDICATOR_FACTOR_100) { | ||
formattedValue += '%' | ||
} | ||
|
||
return formattedValue | ||
} |
8 changes: 8 additions & 0 deletions
8
...config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueLegendColor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getColorByValueFromLegendSet } from '../../../../../../modules/legends.js' | ||
|
||
export function getSingleValueLegendColor(legendOptions, legendSets, value) { | ||
const legendSet = legendOptions && legendSets[0] | ||
return legendSet | ||
? getColorByValueFromLegendSet(legendSet, value) | ||
: undefined | ||
} |
27 changes: 27 additions & 0 deletions
27
...s/config/adapters/dhis_highcharts/customSVGOptions/singleValue/getSingleValueTextColor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { colors } from '@dhis2/ui' | ||
import { LEGEND_DISPLAY_STYLE_TEXT } from '../../../../../../modules/legends.js' | ||
import { getSingleValueLegendColor } from './getSingleValueLegendColor.js' | ||
import { shouldUseContrastColor } from './shouldUseContrastColor.js' | ||
|
||
export function getSingleValueTextColor( | ||
baseColor, | ||
value, | ||
legendOptions, | ||
legendSets | ||
) { | ||
const legendColor = getSingleValueLegendColor( | ||
legendOptions, | ||
legendSets, | ||
value | ||
) | ||
|
||
if (!legendColor) { | ||
return baseColor | ||
} | ||
|
||
if (LEGEND_DISPLAY_STYLE_TEXT) { | ||
return legendColor | ||
} | ||
|
||
return shouldUseContrastColor(legendColor) ? colors.white : baseColor | ||
} |
3 changes: 3 additions & 0 deletions
3
src/visualizations/config/adapters/dhis_highcharts/customSVGOptions/singleValue/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { getSingleValueCustomSVGOptions } from './getSingleValueCustomSVGOptions.js' | ||
export { getSingleValueBackgroundColor } from './getSingleValueBackgroundColor.js' | ||
export { getSingleValueTextColor } from './getSingleValueTextColor.js' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
export default function () { | ||
import { VIS_TYPE_SINGLE_VALUE } from '../../../../modules/visTypes.js' | ||
|
||
export default function (visualizationType) { | ||
return { | ||
style: { | ||
fontSize: '13px', | ||
fontWeight: 'normal', | ||
/* Hide no data label for single value visualizations because | ||
* the data is always missing. */ | ||
opacity: visualizationType === VIS_TYPE_SINGLE_VALUE ? 0 : 1, | ||
}, | ||
} | ||
} |
Oops, something went wrong.