d2-charts-api
Advanced tools
Comparing version 32.0.7 to 32.0.8
@@ -1,50 +0,54 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.default = function (series, store, layout, isStacked, extraOptions) { | ||
switch (layout.type) { | ||
case _type.CHART_TYPE_PIE: | ||
series = (0, _pie2.default)(series, store, layout, isStacked, extraOptions.colors); | ||
break; | ||
case _type.CHART_TYPE_GAUGE: | ||
series = (0, _gauge2.default)(series, extraOptions.dashboard); | ||
break; | ||
default: | ||
series = getDefault(series, layout, isStacked, extraOptions); | ||
} | ||
switch (layout.type) { | ||
case _type.CHART_TYPE_PIE: | ||
series = (0, _pie2.default)(series, store, layout, isStacked, extraOptions.colors); | ||
break; | ||
case _type.CHART_TYPE_GAUGE: | ||
series = (0, _gauge2.default)(series, extraOptions.dashboard); | ||
break; | ||
default: | ||
series = getDefault(series, layout, isStacked, extraOptions); | ||
} | ||
series.forEach(function (seriesObj) { | ||
// animation | ||
seriesObj.animation = { | ||
duration: getAnimation(extraOptions.animation, DEFAULT_ANIMATION_DURATION) | ||
}; | ||
}); | ||
series.forEach(function (seriesObj) { | ||
// animation | ||
seriesObj.animation = { | ||
duration: getAnimation(extraOptions.animation, DEFAULT_ANIMATION_DURATION) | ||
}; | ||
}); | ||
return series; | ||
return series; | ||
}; | ||
var _getCumulativeData = require('./../getCumulativeData'); | ||
var _arrayContains = require("d2-utilizr/lib/arrayContains"); | ||
var _arrayContains2 = _interopRequireDefault(_arrayContains); | ||
var _getCumulativeData = require("./../getCumulativeData"); | ||
var _getCumulativeData2 = _interopRequireDefault(_getCumulativeData); | ||
var _pie = require('./pie'); | ||
var _pie = require("./pie"); | ||
var _pie2 = _interopRequireDefault(_pie); | ||
var _gauge = require('./gauge'); | ||
var _gauge = require("./gauge"); | ||
var _gauge2 = _interopRequireDefault(_gauge); | ||
var _type = require('../type'); | ||
var _type = require("../type"); | ||
var _type2 = _interopRequireDefault(_type); | ||
var _seriesItems = require('../seriesItems'); | ||
var _seriesItems = require("../seriesItems"); | ||
var _gradientColorGenerator = require('../../../../util/colors/gradientColorGenerator'); | ||
var _gradientColorGenerator = require("../../../../util/colors/gradientColorGenerator"); | ||
var _layout = require('../layout'); | ||
var _layout = require("../layout"); | ||
@@ -55,6 +59,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var HIGHCHARTS_TYPE_COLUMN = 'column'; | ||
var HIGHCHARTS_TYPE_BAR = 'bar'; | ||
var HIGHCHARTS_TYPE_PERCENT = 'percent'; | ||
var HIGHCHARTS_TYPE_NORMAL = 'normal'; | ||
var HIGHCHARTS_TYPE_COLUMN = "column"; | ||
var HIGHCHARTS_TYPE_BAR = "bar"; | ||
var HIGHCHARTS_TYPE_PERCENT = "percent"; | ||
var HIGHCHARTS_TYPE_NORMAL = "normal"; | ||
@@ -64,88 +68,88 @@ var epiCurveTypes = [HIGHCHARTS_TYPE_COLUMN, HIGHCHARTS_TYPE_BAR]; | ||
function getAnimation(option, fallback) { | ||
return typeof option === 'number' ? option : fallback; | ||
return typeof option === "number" ? option : fallback; | ||
} | ||
function getColor(colors, index) { | ||
return colors[index] || getColor(colors, index - colors.length); | ||
return colors[index] || getColor(colors, index - colors.length); | ||
} | ||
function getIdColorMap(series, layout, extraOptions) { | ||
if ((0, _layout.shouldHaveDualAxis)(layout)) { | ||
var axisIdsMap = (0, _seriesItems.getAxisIdsMap)(layout.seriesItems, series); | ||
var theme = extraOptions.multiAxisTheme; | ||
if ((0, _layout.shouldHaveDualAxis)(layout)) { | ||
var axisIdsMap = (0, _seriesItems.getAxisIdsMap)(layout.seriesItems, series); | ||
var theme = extraOptions.multiAxisTheme; | ||
var colorsByAxis = Object.keys(axisIdsMap).reduce(function (map, axis) { | ||
var numberOfIds = axisIdsMap[axis].length; | ||
map[axis] = (0, _gradientColorGenerator.generateColors)(theme[axis].startColor, theme[axis].endColor, numberOfIds, true); | ||
return map; | ||
}, {}); | ||
var colorsByAxis = Object.keys(axisIdsMap).reduce(function (map, axis) { | ||
var numberOfIds = axisIdsMap[axis].length; | ||
map[axis] = (0, _gradientColorGenerator.generateColors)(theme[axis].startColor, theme[axis].endColor, numberOfIds, true); | ||
return map; | ||
}, {}); | ||
return Object.keys(colorsByAxis).reduce(function (map, axis) { | ||
var colors = colorsByAxis[axis]; | ||
var ids = axisIdsMap[axis]; | ||
return Object.keys(colorsByAxis).reduce(function (map, axis) { | ||
var colors = colorsByAxis[axis]; | ||
var ids = axisIdsMap[axis]; | ||
ids.forEach(function (id, index) { | ||
map[id] = colors[index]; | ||
}); | ||
ids.forEach(function (id, index) { | ||
map[id] = colors[index]; | ||
}); | ||
return map; | ||
}, {}); | ||
} else { | ||
var colors = extraOptions.colors; | ||
return map; | ||
}, {}); | ||
} else { | ||
var colors = extraOptions.colors; | ||
return series.reduce(function (map, s, index) { | ||
map[s.id] = getColor(colors, index); | ||
return map; | ||
}, {}); | ||
} | ||
return series.reduce(function (map, s, index) { | ||
map[s.id] = getColor(colors, index); | ||
return map; | ||
}, {}); | ||
} | ||
} | ||
function getDefault(series, layout, isStacked, extraOptions) { | ||
var fullIdAxisMap = (0, _seriesItems.getFullIdAxisMap)(layout.seriesItems, series); | ||
var idColorMap = getIdColorMap(series, layout, extraOptions); | ||
var fullIdAxisMap = (0, _seriesItems.getFullIdAxisMap)(layout.seriesItems, series); | ||
var idColorMap = getIdColorMap(series, layout, extraOptions); | ||
series.forEach(function (seriesObj, index) { | ||
// show values | ||
if (layout.showValues || layout.showData) { | ||
seriesObj.dataLabels = { | ||
enabled: true | ||
}; | ||
} | ||
series.forEach(function (seriesObj, index) { | ||
// show values | ||
if (layout.showValues || layout.showData) { | ||
seriesObj.dataLabels = { | ||
enabled: true | ||
}; | ||
} | ||
// stacked | ||
if (isStacked) { | ||
// DHIS2-1060: stacked charts can optionally be shown as 100% stacked charts | ||
seriesObj.stacking = layout.percentStackedValues === true ? HIGHCHARTS_TYPE_PERCENT : HIGHCHARTS_TYPE_NORMAL; | ||
} | ||
// stacked | ||
if (isStacked) { | ||
// DHIS2-1060: stacked charts can optionally be shown as 100% stacked charts | ||
seriesObj.stacking = layout.percentStackedValues === true ? HIGHCHARTS_TYPE_PERCENT : HIGHCHARTS_TYPE_NORMAL; | ||
} | ||
// DHIS2-2101 | ||
// show bar/column chart as EPI curve (basically remove spacing between bars/columns) | ||
if (layout.noSpaceBetweenColumns) { | ||
var seriesType = (0, _type2.default)(layout.type).type; | ||
// DHIS2-2101 | ||
// show bar/column chart as EPI curve (basically remove spacing between bars/columns) | ||
if (layout.noSpaceBetweenColumns) { | ||
var seriesType = (0, _type2.default)(layout.type).type; | ||
if (arrayContains(epiCurveTypes, seriesType)) { | ||
seriesObj.pointPadding = 0; | ||
seriesObj.groupPadding = 0; | ||
} | ||
} | ||
if ((0, _arrayContains2.default)(epiCurveTypes, seriesType)) { | ||
seriesObj.pointPadding = 0; | ||
seriesObj.groupPadding = 0; | ||
} | ||
} | ||
// color | ||
seriesObj.color = (0, _type.isYearOverYear)(layout.type) ? extraOptions.colors[index] : idColorMap[seriesObj.id]; | ||
// color | ||
seriesObj.color = (0, _type.isYearOverYear)(layout.type) ? extraOptions.colors[index] : idColorMap[seriesObj.id]; | ||
// axis number | ||
seriesObj.yAxis = (0, _type.isDualAxis)(layout.type) ? fullIdAxisMap[seriesObj.id] : 0; | ||
// axis number | ||
seriesObj.yAxis = (0, _type.isDualAxis)(layout.type) ? fullIdAxisMap[seriesObj.id] : 0; | ||
// custom names for "year over year" series | ||
if (extraOptions.yearlySeries) { | ||
seriesObj.name = extraOptions.yearlySeries[index]; | ||
} | ||
}); | ||
// DHIS2-701: use cumulative values | ||
if (layout.cumulativeValues === true) { | ||
series = (0, _getCumulativeData2.default)(series); | ||
// custom names for "year over year" series | ||
if (extraOptions.yearlySeries) { | ||
seriesObj.name = extraOptions.yearlySeries[index]; | ||
} | ||
}); | ||
return series; | ||
// DHIS2-701: use cumulative values | ||
if (layout.cumulativeValues === true) { | ||
series = (0, _getCumulativeData2.default)(series); | ||
} | ||
return series; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "d2-charts-api", | ||
"version": "32.0.7", | ||
"version": "32.0.8", | ||
"description": "DHIS2 charts api", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,16 +0,18 @@ | ||
import getCumulativeData from './../getCumulativeData'; | ||
import getPie from './pie'; | ||
import getGauge from './gauge'; | ||
import getType, { isDualAxis, isYearOverYear } from '../type'; | ||
import { CHART_TYPE_PIE, CHART_TYPE_GAUGE } from '../type'; | ||
import { getFullIdAxisMap, getAxisIdsMap } from '../seriesItems'; | ||
import { generateColors } from '../../../../util/colors/gradientColorGenerator'; | ||
import { shouldHaveDualAxis } from '../layout'; | ||
import arrayContains from "d2-utilizr/lib/arrayContains"; | ||
import getCumulativeData from "./../getCumulativeData"; | ||
import getPie from "./pie"; | ||
import getGauge from "./gauge"; | ||
import getType, { isDualAxis, isYearOverYear } from "../type"; | ||
import { CHART_TYPE_PIE, CHART_TYPE_GAUGE } from "../type"; | ||
import { getFullIdAxisMap, getAxisIdsMap } from "../seriesItems"; | ||
import { generateColors } from "../../../../util/colors/gradientColorGenerator"; | ||
import { shouldHaveDualAxis } from "../layout"; | ||
const DEFAULT_ANIMATION_DURATION = 200; | ||
const HIGHCHARTS_TYPE_COLUMN = 'column'; | ||
const HIGHCHARTS_TYPE_BAR = 'bar'; | ||
const HIGHCHARTS_TYPE_PERCENT = 'percent'; | ||
const HIGHCHARTS_TYPE_NORMAL = 'normal'; | ||
const HIGHCHARTS_TYPE_COLUMN = "column"; | ||
const HIGHCHARTS_TYPE_BAR = "bar"; | ||
const HIGHCHARTS_TYPE_PERCENT = "percent"; | ||
const HIGHCHARTS_TYPE_NORMAL = "normal"; | ||
@@ -20,112 +22,119 @@ const epiCurveTypes = [HIGHCHARTS_TYPE_COLUMN, HIGHCHARTS_TYPE_BAR]; | ||
function getAnimation(option, fallback) { | ||
return typeof option === 'number' ? option : fallback; | ||
return typeof option === "number" ? option : fallback; | ||
} | ||
function getColor(colors, index) { | ||
return colors[index] || getColor(colors, index - colors.length); | ||
return colors[index] || getColor(colors, index - colors.length); | ||
} | ||
function getIdColorMap(series, layout, extraOptions) { | ||
if (shouldHaveDualAxis(layout)) { | ||
const axisIdsMap = getAxisIdsMap(layout.seriesItems, series); | ||
const theme = extraOptions.multiAxisTheme; | ||
if (shouldHaveDualAxis(layout)) { | ||
const axisIdsMap = getAxisIdsMap(layout.seriesItems, series); | ||
const theme = extraOptions.multiAxisTheme; | ||
const colorsByAxis = Object.keys(axisIdsMap).reduce((map, axis) => { | ||
const numberOfIds = axisIdsMap[axis].length; | ||
map[axis] = generateColors(theme[axis].startColor, theme[axis].endColor, numberOfIds, true); | ||
return map; | ||
}, {}); | ||
const colorsByAxis = Object.keys(axisIdsMap).reduce((map, axis) => { | ||
const numberOfIds = axisIdsMap[axis].length; | ||
map[axis] = generateColors( | ||
theme[axis].startColor, | ||
theme[axis].endColor, | ||
numberOfIds, | ||
true | ||
); | ||
return map; | ||
}, {}); | ||
return Object.keys(colorsByAxis).reduce((map, axis) => { | ||
const colors = colorsByAxis[axis]; | ||
const ids = axisIdsMap[axis]; | ||
return Object.keys(colorsByAxis).reduce((map, axis) => { | ||
const colors = colorsByAxis[axis]; | ||
const ids = axisIdsMap[axis]; | ||
ids.forEach((id, index) => { | ||
map[id] = colors[index]; | ||
}); | ||
ids.forEach((id, index) => { | ||
map[id] = colors[index]; | ||
}); | ||
return map; | ||
}, {}); | ||
} | ||
else { | ||
const colors = extraOptions.colors; | ||
return map; | ||
}, {}); | ||
} else { | ||
const colors = extraOptions.colors; | ||
return series.reduce((map, s, index) => { | ||
map[s.id] = getColor(colors, index); | ||
return map; | ||
}, {}); | ||
} | ||
return series.reduce((map, s, index) => { | ||
map[s.id] = getColor(colors, index); | ||
return map; | ||
}, {}); | ||
} | ||
} | ||
function getDefault(series, layout, isStacked, extraOptions) { | ||
const fullIdAxisMap = getFullIdAxisMap(layout.seriesItems, series); | ||
const idColorMap = getIdColorMap(series, layout, extraOptions); | ||
const fullIdAxisMap = getFullIdAxisMap(layout.seriesItems, series); | ||
const idColorMap = getIdColorMap(series, layout, extraOptions); | ||
series.forEach((seriesObj, index) => { | ||
// show values | ||
if (layout.showValues || layout.showData) { | ||
seriesObj.dataLabels = { | ||
enabled: true, | ||
}; | ||
} | ||
series.forEach((seriesObj, index) => { | ||
// show values | ||
if (layout.showValues || layout.showData) { | ||
seriesObj.dataLabels = { | ||
enabled: true | ||
}; | ||
} | ||
// stacked | ||
if (isStacked) { | ||
// DHIS2-1060: stacked charts can optionally be shown as 100% stacked charts | ||
seriesObj.stacking = layout.percentStackedValues === true ? HIGHCHARTS_TYPE_PERCENT : HIGHCHARTS_TYPE_NORMAL; | ||
} | ||
// stacked | ||
if (isStacked) { | ||
// DHIS2-1060: stacked charts can optionally be shown as 100% stacked charts | ||
seriesObj.stacking = | ||
layout.percentStackedValues === true | ||
? HIGHCHARTS_TYPE_PERCENT | ||
: HIGHCHARTS_TYPE_NORMAL; | ||
} | ||
// DHIS2-2101 | ||
// show bar/column chart as EPI curve (basically remove spacing between bars/columns) | ||
if (layout.noSpaceBetweenColumns) { | ||
const seriesType = getType(layout.type).type; | ||
// DHIS2-2101 | ||
// show bar/column chart as EPI curve (basically remove spacing between bars/columns) | ||
if (layout.noSpaceBetweenColumns) { | ||
const seriesType = getType(layout.type).type; | ||
if (arrayContains(epiCurveTypes, seriesType)) { | ||
seriesObj.pointPadding = 0; | ||
seriesObj.groupPadding = 0; | ||
} | ||
} | ||
if (arrayContains(epiCurveTypes, seriesType)) { | ||
seriesObj.pointPadding = 0; | ||
seriesObj.groupPadding = 0; | ||
} | ||
} | ||
// color | ||
seriesObj.color = isYearOverYear(layout.type) ? | ||
extraOptions.colors[index] : | ||
idColorMap[seriesObj.id]; | ||
// color | ||
seriesObj.color = isYearOverYear(layout.type) | ||
? extraOptions.colors[index] | ||
: idColorMap[seriesObj.id]; | ||
// axis number | ||
seriesObj.yAxis = isDualAxis(layout.type) ? fullIdAxisMap[seriesObj.id] : 0; | ||
// axis number | ||
seriesObj.yAxis = isDualAxis(layout.type) ? fullIdAxisMap[seriesObj.id] : 0; | ||
// custom names for "year over year" series | ||
if (extraOptions.yearlySeries) { | ||
seriesObj.name = extraOptions.yearlySeries[index]; | ||
} | ||
}); | ||
// DHIS2-701: use cumulative values | ||
if (layout.cumulativeValues === true) { | ||
series = getCumulativeData(series); | ||
// custom names for "year over year" series | ||
if (extraOptions.yearlySeries) { | ||
seriesObj.name = extraOptions.yearlySeries[index]; | ||
} | ||
}); | ||
return series; | ||
// DHIS2-701: use cumulative values | ||
if (layout.cumulativeValues === true) { | ||
series = getCumulativeData(series); | ||
} | ||
return series; | ||
} | ||
export default function(series, store, layout, isStacked, extraOptions) { | ||
switch (layout.type) { | ||
case CHART_TYPE_PIE: | ||
series = getPie(series, store, layout, isStacked, extraOptions.colors); | ||
break; | ||
case CHART_TYPE_GAUGE: | ||
series = getGauge(series, extraOptions.dashboard); | ||
break; | ||
default: | ||
series = getDefault(series, layout, isStacked, extraOptions); | ||
} | ||
switch (layout.type) { | ||
case CHART_TYPE_PIE: | ||
series = getPie(series, store, layout, isStacked, extraOptions.colors); | ||
break; | ||
case CHART_TYPE_GAUGE: | ||
series = getGauge(series, extraOptions.dashboard); | ||
break; | ||
default: | ||
series = getDefault(series, layout, isStacked, extraOptions); | ||
} | ||
series.forEach(seriesObj => { | ||
// animation | ||
seriesObj.animation = { | ||
duration: getAnimation(extraOptions.animation, DEFAULT_ANIMATION_DURATION), | ||
}; | ||
}); | ||
series.forEach(seriesObj => { | ||
// animation | ||
seriesObj.animation = { | ||
duration: getAnimation(extraOptions.animation, DEFAULT_ANIMATION_DURATION) | ||
}; | ||
}); | ||
return series; | ||
return series; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3953
273467
143