-
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: restructure chart, event and customSVGOptions dirs
- Loading branch information
1 parent
1d89e05
commit 3065022
Showing
28 changed files
with
137 additions
and
121 deletions.
There are no files selected for viewing
63 changes: 0 additions & 63 deletions
63
src/visualizations/config/adapters/dhis_highcharts/chart.js
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/visualizations/config/adapters/dhis_highcharts/chart/default.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 { 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
12
src/visualizations/config/adapters/dhis_highcharts/chart/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,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) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/visualizations/config/adapters/dhis_highcharts/chart/singleValue.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,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 | ||
} |
15 changes: 2 additions & 13 deletions
15
src/visualizations/config/adapters/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
27 changes: 0 additions & 27 deletions
27
...ers/dhis_highcharts/customSVGOptions/singleValue/config/getSingleValueCustomSVGOptions.js
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...e/config/getSingleValueBackgroundColor.js → ...gleValue/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
4 changes: 2 additions & 2 deletions
4
...ue/config/getSingleValueFormattedValue.js → ...ngleValue/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
2 changes: 1 addition & 1 deletion
2
...Value/config/getSingleValueLegendColor.js → .../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
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...leValue/config/getSingleValueTextColor.js → ...ns/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
4 changes: 2 additions & 2 deletions
4
...eValue/config/getSingleValueTitleColor.js → ...s/singleValue/getSingleValueTitleColor.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
30 changes: 27 additions & 3 deletions
30
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 |
---|---|---|
@@ -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
23
src/visualizations/config/adapters/dhis_highcharts/events/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,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) | ||
}, | ||
}, | ||
}) |
12 changes: 12 additions & 0 deletions
12
src/visualizations/config/adapters/dhis_highcharts/events/loadCustomSVG/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,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 | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
2 changes: 1 addition & 1 deletion
2
src/visualizations/config/adapters/dhis_highcharts/subtitle/singleValue.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
2 changes: 1 addition & 1 deletion
2
src/visualizations/config/adapters/dhis_highcharts/title/singleValue.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