Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

d2-charts-api

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d2-charts-api - npm Package Compare versions

Comparing version 29.0.1 to 31.0.0

css/highcharts-motion.css

5

lib/config/adapters/dhis_highcharts/getCategories.js

@@ -7,4 +7,3 @@ 'use strict';

exports.default = function (store, layout) {
var metaData = store.data.metaData;
exports.default = function (metaData, layout) {
var dimensionName = layout.rows[0].dimension;

@@ -24,4 +23,2 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
;
//# sourceMappingURL=getCategories.js.map

55

lib/config/adapters/dhis_highcharts/index.js

@@ -6,3 +6,3 @@ 'use strict';

});
exports.CHART_TYPE_GAUGE = exports.CHART_TYPE_PIE = undefined;
exports.CHART_TYPE_YEAR_ON_YEAR = exports.CHART_TYPE_GAUGE = exports.CHART_TYPE_PIE = undefined;

@@ -18,34 +18,36 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _layout = getTransformedLayout(layout);
var series = store.generateData({
seriesId: layout.columns[0].dimension,
categoryId: layout.rows[0].dimension
type: _layout.type,
seriesId: _layout.columns[0].dimension,
categoryId: _layout.rows[0].dimension
});
var isStacked = (0, _type.getIsStacked)(layout.type);
var isStacked = (0, _type.getIsStacked)(_layout.type);
var config = {
// type etc
chart: (0, _chart2.default)(layout, el, extraOptions.dashboard),
chart: (0, _chart2.default)(_layout, el, extraOptions.dashboard),
// title
title: (0, _title2.default)(layout, store.data.metaData, extraOptions.dashboard),
title: (0, _title2.default)(_layout, store.data[0].metaData, extraOptions.dashboard),
// subtitle
subtitle: (0, _subtitle2.default)(series, layout, store.data.metaData, extraOptions.dashboard),
subtitle: (0, _subtitle2.default)(series, _layout, store.data[0].metaData, extraOptions.dashboard),
// x-axis
xAxis: (0, _xAxis2.default)(store, layout),
xAxis: (0, _xAxis2.default)(store, _layout),
// y-axis
yAxis: (0, _yAxis2.default)(layout, extraOptions),
yAxis: (0, _yAxis2.default)(_layout, extraOptions),
// series
series: (0, _series2.default)(series.slice(), store, layout, isStacked, extraOptions),
series: (0, _series2.default)(series.slice(), store, _layout, isStacked, extraOptions),
// legend
legend: (0, _legend2.default)(layout, extraOptions.dashboard),
legend: (0, _legend2.default)(_layout, extraOptions.dashboard),
// pane
pane: (0, _pane2.default)(layout.type),
pane: (0, _pane2.default)(_layout.type),

@@ -68,9 +70,9 @@ // no data

// hide empty categories
if (layout.hideEmptyRowItems !== 'NONE') {
config = (0, _getTrimmedConfig2.default)(config, layout.hideEmptyRowItems);
if (_layout.hideEmptyRowItems !== 'NONE') {
config = (0, _getTrimmedConfig2.default)(config, _layout.hideEmptyRowItems);
}
// sorting
if (layout.sortOrder) {
config = (0, _getSortedConfig2.default)(config, layout, isStacked);
if (_layout.sortOrder) {
config = (0, _getSortedConfig2.default)(config, _layout, isStacked);
}

@@ -80,4 +82,4 @@

// trend line on pie and gauge does not make sense
if (layout.type !== CHART_TYPE_GAUGE && layout.type !== CHART_TYPE_PIE && layout.regressionType !== 'NONE') {
config.series = (0, _addTrendLines2.default)(layout.regressionType, config.series, isStacked);
if (!(0, _arrayContains2.default)([CHART_TYPE_GAUGE, CHART_TYPE_PIE], _layout.type) && _layout.regressionType !== 'NONE') {
config.series = (0, _addTrendLines2.default)(_layout.regressionType, config.series, isStacked);
}

@@ -91,2 +93,6 @@

var _arrayContains = require('d2-utilizr/lib/arrayContains');
var _arrayContains2 = _interopRequireDefault(_arrayContains);
var _objectClean = require('d2-utilizr/lib/objectClean');

@@ -148,4 +154,11 @@

var CHART_TYPE_PIE = exports.CHART_TYPE_PIE = 'pie';
var CHART_TYPE_GAUGE = exports.CHART_TYPE_GAUGE = 'gauge';
var CHART_TYPE_PIE = exports.CHART_TYPE_PIE = 'PIE';
var CHART_TYPE_GAUGE = exports.CHART_TYPE_GAUGE = 'GAUGE';
var CHART_TYPE_YEAR_ON_YEAR = exports.CHART_TYPE_YEAR_ON_YEAR = 'YEAR_ON_YEAR';
var getTransformedLayout = function getTransformedLayout(layout) {
return _extends({}, layout, {
type: String(layout.type).toUpperCase()
});
};
//# sourceMappingURL=index.js.map

@@ -16,7 +16,6 @@ 'use strict';

default:
series = getDefault(series, store, layout, isStacked, extraOptions.colors);
series = getDefault(series, store, layout, isStacked, extraOptions);
}
series.forEach(function (seriesObj) {
// animation

@@ -57,3 +56,3 @@ seriesObj.animation = {

function getDefault(series, store, layout, isStacked, colors) {
function getDefault(series, store, layout, isStacked, extraOptions) {
series.forEach(function (seriesObj, index) {

@@ -75,5 +74,5 @@ // show values

// show bar/columm chart as EPI curve (basically remove spacing between bars/columns)
var chartType = (0, _type2.default)(layout.type).type;
var seriesType = (0, _type2.default)(layout.type).type;
if ((chartType === 'column' || chartType === 'bar') && layout.noSpaceBetweenColumns) {
if ((seriesType === 'column' || seriesType === 'bar') && layout.noSpaceBetweenColumns) {
seriesObj.pointPadding = 0;

@@ -84,3 +83,8 @@ seriesObj.groupPadding = 0;

// color
seriesObj.color = getColor(colors, index);
seriesObj.color = getColor(extraOptions.colors, index);
// custom names for series for Year on year chart type
if (extraOptions.yearlySeries) {
seriesObj.name = extraOptions.yearlySeries[index];
}
});

@@ -87,0 +91,0 @@

@@ -13,3 +13,3 @@ 'use strict';

cursor: 'pointer',
data: (0, _getCategories2.default)(store, layout).map(function (category, index) {
data: (0, _getCategories2.default)(store.data[0].metaData, layout).map(function (category, index) {
return {

@@ -16,0 +16,0 @@ name: category,

@@ -41,3 +41,2 @@ 'use strict';

function getText(layout, metaData, dashboard) {
// title

@@ -66,4 +65,2 @@ if ((0, _isString2.default)(layout.title) && layout.title.length) {

}
;
//# sourceMappingURL=title.js.map

@@ -9,5 +9,24 @@ 'use strict';

exports.default = function (type) {
return chartTypeMap.get(type.toLowerCase()) || {
type: type.toLowerCase()
};
switch (type) {
case 'BAR':
case 'STACKED_BAR':
case 'STACKEDBAR':
return { type: 'bar' };
case 'LINE':
case 'YEAR_ON_YEAR':
return { type: 'line' };
case 'AREA':
return { type: 'area' };
case 'PIE':
return { type: 'pie' };
case 'RADAR':
return { type: 'line', polar: true };
case 'GAUGE':
return { type: 'solidgauge' };
case 'COLUMN':
case 'STACKED_COLUMN':
case 'STACKEDCOLUMN':
default:
return { type: 'column' };
}
};

@@ -21,15 +40,7 @@

// Note: IE11 does not support passing the array directly to the constructor
var chartTypeMap = new Map();
var stackedTypes = ['STACKED_COLUMN', 'STACKEDCOLUMN', 'STACKED_BAR', 'STACKEDBAR', 'AREA'];
chartTypeMap.set('radar', { type: 'line', polar: true });
chartTypeMap.set('gauge', { type: 'solidgauge' });
chartTypeMap.set('stackedcolumn', { type: 'column' });
chartTypeMap.set('stackedbar', { type: 'bar' });
var stackedTypes = ['stackedcolumn', 'stackedbar', 'area'];
function getIsStacked(type) {
return (0, _arrayContains2.default)(stackedTypes, type.toLowerCase());
return (0, _arrayContains2.default)(stackedTypes, type);
}
//# sourceMappingURL=type.js.map

@@ -14,2 +14,5 @@ 'use strict';

break;
case _.CHART_TYPE_YEAR_ON_YEAR:
xAxis = (0, _yearOnYear2.default)(store, layout);
break;
default:

@@ -38,2 +41,6 @@ xAxis = getDefault(store, layout);

var _yearOnYear = require('./yearOnYear');
var _yearOnYear2 = _interopRequireDefault(_yearOnYear);
var _ = require('..');

@@ -45,3 +52,3 @@

return (0, _objectClean2.default)({
categories: (0, _getCategories2.default)(store, layout),
categories: (0, _getCategories2.default)(store.data[0].metaData, layout),
title: (0, _getAxisTitle2.default)(layout.domainAxisTitle),

@@ -48,0 +55,0 @@ labels: {

@@ -8,2 +8,6 @@ 'use strict';

var _isArray = require('d2-utilizr/lib/isArray');
var _isArray2 = _interopRequireDefault(_isArray);
require('core-js/fn/array/find-index');

@@ -33,3 +37,4 @@

var store = new _store2.default({ data: data, error: error, warning: warning });
var _data = (0, _isArray2.default)(data) ? data : [data];
var store = new _store2.default({ data: _data, error: error, warning: warning });
var config = new _config2.default({ store: store, layout: layout, el: el, extraOptions: extraOptions, error: error, warning: warning });

@@ -36,0 +41,0 @@

@@ -8,28 +8,44 @@ 'use strict';

exports.default = function (_ref) {
var data = _ref.data,
_ref$seriesId = _ref.seriesId,
seriesId = _ref$seriesId === undefined ? data.headers[0].name : _ref$seriesId,
_ref$categoryId = _ref.categoryId,
categoryId = _ref$categoryId === undefined ? data.headers[1].name : _ref$categoryId;
var type = _ref.type,
data = _ref.data,
seriesId = _ref.seriesId,
categoryId = _ref.categoryId;
var headers = data.headers;
var metaData = data.metaData;
var rows = data.rows;
var headerIdIndexMap = getHeaderIdIndexMap(headers);
var seriesFunction = type === _dhis_highcharts.CHART_TYPE_YEAR_ON_YEAR ? _yearOnYear2.default : getDefault;
var seriesIndex = headerIdIndexMap.get(seriesId);
var categoryIndex = headerIdIndexMap.get(categoryId);
var valueIndex = headerIdIndexMap.get(VALUE_ID);
return data.reduce(function (acc, res) {
seriesId = seriesId || res.headers[0].name;
categoryId = categoryId || res.headers[1].name;
var seriesHeader = headers[seriesIndex];
var categoryHeader = headers[categoryIndex];
var headers = res.headers;
var metaData = res.metaData;
var rows = res.rows;
var headerIdIndexMap = getHeaderIdIndexMap(headers);
var idValueMap = getIdValueMap(rows, seriesHeader, categoryHeader, valueIndex);
var seriesIndex = headerIdIndexMap.get(seriesId);
var categoryIndex = headerIdIndexMap.get(categoryId);
var valueIndex = headerIdIndexMap.get(VALUE_ID);
var seriesIds = metaData.dimensions[seriesId];
var categoryIds = metaData.dimensions[categoryId];
var seriesHeader = headers[seriesIndex];
var categoryHeader = headers[categoryIndex];
return getData(seriesIds, categoryIds, idValueMap, metaData.items);
var idValueMap = getIdValueMap(rows, seriesHeader, categoryHeader, valueIndex);
var seriesIds = metaData.dimensions[seriesId];
var categoryIds = metaData.dimensions[categoryId];
seriesFunction(acc, seriesIds, categoryIds, idValueMap, metaData);
return acc;
}, []);
};
var _yearOnYear = require('./yearOnYear');
var _yearOnYear2 = _interopRequireDefault(_yearOnYear);
var _dhis_highcharts = require('../../../config/adapters/dhis_highcharts');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var VALUE_ID = 'value';

@@ -67,15 +83,9 @@

function getData(seriesIds, categoryIds, idValueMap, metaDataItems) {
var data = [];
var dataItem = void 0;
var value = void 0;
function getDefault(acc, seriesIds, categoryIds, idValueMap, metaData) {
seriesIds.forEach(function (seriesId) {
dataItem = {
name: metaDataItems[seriesId].name,
data: []
};
var serieData = [];
var serieLabel = metaData.items[seriesId].name;
categoryIds.forEach(function (categoryId) {
value = idValueMap.get(seriesId + '-' + categoryId);
var value = idValueMap.get(seriesId + '-' + categoryId);

@@ -85,10 +95,13 @@ // DHIS2-1261: 0 is a valid value

// in that case null is returned as value in the serie for highcharts
dataItem.data.push(value == undefined ? null : parseFloat(value));
serieData.push(value == undefined ? null : parseFloat(value));
});
data.push(dataItem);
acc.push({
name: serieLabel,
data: serieData
});
});
return data;
return acc;
}
//# sourceMappingURL=index.js.map

@@ -32,3 +32,4 @@ 'use strict';

this.generateData = function (_ref2) {
var _ref2$seriesId = _ref2.seriesId,
var type = _ref2.type,
_ref2$seriesId = _ref2.seriesId,
seriesId = _ref2$seriesId === undefined ? seriesId : _ref2$seriesId,

@@ -39,3 +40,6 @@ _ref2$categoryId = _ref2.categoryId,

return _adapter({
data: _validator({ data: data, error: error, warning: warning }),
type: type,
data: data.map(function (d) {
return _validator({ data: d, error: error, warning: warning });
}),
seriesId: seriesId,

@@ -42,0 +46,0 @@ categoryId: categoryId

{
"name": "d2-charts-api",
"version": "29.0.1",
"version": "31.0.0",
"description": "DHIS2 charts api",

@@ -5,0 +5,0 @@ "main": "index.js",

import isArray from 'd2-utilizr/lib/isArray';
export default function (store, layout) {
const metaData = store.data.metaData;
export default function(metaData, layout) {
const dimensionName = layout.rows[0].dimension;
const dimensionIds = isArray(metaData.dimensions[dimensionName]) ? metaData.dimensions[dimensionName] : [];
const dimensionIds = isArray(metaData.dimensions[dimensionName])
? metaData.dimensions[dimensionName]
: [];
return dimensionIds.map(id => metaData.items[id].name);
};
}

@@ -0,1 +1,2 @@

import arrayContains from 'd2-utilizr/lib/arrayContains';
import objectClean from 'd2-utilizr/lib/objectClean';

@@ -16,38 +17,46 @@ import getChart from './chart';

export const CHART_TYPE_PIE = 'pie';
export const CHART_TYPE_GAUGE = 'gauge';
export const CHART_TYPE_PIE = 'PIE';
export const CHART_TYPE_GAUGE = 'GAUGE';
export const CHART_TYPE_YEAR_ON_YEAR = 'YEAR_ON_YEAR';
export default function ({ store, layout, el, extraConfig, extraOptions }) {
const getTransformedLayout = layout => ({
...layout,
type: String(layout.type).toUpperCase(),
});
export default function({ store, layout, el, extraConfig, extraOptions }) {
const _layout = getTransformedLayout(layout);
let series = store.generateData({
seriesId: layout.columns[0].dimension,
categoryId: layout.rows[0].dimension
type: _layout.type,
seriesId: _layout.columns[0].dimension,
categoryId: _layout.rows[0].dimension,
});
const isStacked = getIsStacked(layout.type);
const isStacked = getIsStacked(_layout.type);
let config = {
// type etc
chart: getChart(layout, el, extraOptions.dashboard),
chart: getChart(_layout, el, extraOptions.dashboard),
// title
title: getTitle(layout, store.data.metaData, extraOptions.dashboard),
title: getTitle(_layout, store.data[0].metaData, extraOptions.dashboard),
// subtitle
subtitle: getSubtitle(series, layout, store.data.metaData, extraOptions.dashboard),
subtitle: getSubtitle(series, _layout, store.data[0].metaData, extraOptions.dashboard),
// x-axis
xAxis: getXAxis(store, layout),
xAxis: getXAxis(store, _layout),
// y-axis
yAxis: getYAxis(layout, extraOptions),
yAxis: getYAxis(_layout, extraOptions),
// series
series: getSeries(series.slice(), store, layout, isStacked, extraOptions),
series: getSeries(series.slice(), store, _layout, isStacked, extraOptions),
// legend
legend: getLegend(layout, extraOptions.dashboard),
legend: getLegend(_layout, extraOptions.dashboard),
// pane
pane: getPane(layout.type),
pane: getPane(_layout.type),

@@ -59,3 +68,3 @@ // no data

credits: {
enabled: false
enabled: false,
},

@@ -66,14 +75,14 @@

// disable exporting context menu
enabled: false
}
enabled: false,
},
};
// hide empty categories
if (layout.hideEmptyRowItems !== 'NONE') {
config = getTrimmedConfig(config, layout.hideEmptyRowItems);
if (_layout.hideEmptyRowItems !== 'NONE') {
config = getTrimmedConfig(config, _layout.hideEmptyRowItems);
}
// sorting
if (layout.sortOrder) {
config = getSortedConfig(config, layout, isStacked);
if (_layout.sortOrder) {
config = getSortedConfig(config, _layout, isStacked);
}

@@ -83,4 +92,7 @@

// trend line on pie and gauge does not make sense
if (layout.type !== CHART_TYPE_GAUGE && layout.type !== CHART_TYPE_PIE && layout.regressionType !== 'NONE') {
config.series = addTrendLines(layout.regressionType, config.series, isStacked);
if (
!arrayContains([CHART_TYPE_GAUGE, CHART_TYPE_PIE], _layout.type) &&
_layout.regressionType !== 'NONE'
) {
config.series = addTrendLines(_layout.regressionType, config.series, isStacked);
}

@@ -87,0 +99,0 @@

@@ -9,7 +9,7 @@ import getCumulativeData from './../getCumulativeData';

function getColor(colors, index) {
function getColor(colors, index) {
return colors[index] || getColor(colors, index - colors.length);
}
function getDefault(series, store, layout, isStacked, colors) {
function getDefault(series, store, layout, isStacked, extraOptions) {
series.forEach((seriesObj, index) => {

@@ -19,3 +19,3 @@ // show values

seriesObj.dataLabels = {
enabled: true
enabled: true,
};

@@ -32,5 +32,5 @@ }

// show bar/columm chart as EPI curve (basically remove spacing between bars/columns)
const chartType = getType(layout.type).type;
const seriesType = getType(layout.type).type;
if ((chartType === 'column' || chartType === 'bar') && layout.noSpaceBetweenColumns) {
if ((seriesType === 'column' || seriesType === 'bar') && layout.noSpaceBetweenColumns) {
seriesObj.pointPadding = 0;

@@ -41,3 +41,8 @@ seriesObj.groupPadding = 0;

// color
seriesObj.color = getColor(colors, index);
seriesObj.color = getColor(extraOptions.colors, index);
// custom names for series for Year on year chart type
if (extraOptions.yearlySeries) {
seriesObj.name = extraOptions.yearlySeries[index];
}
});

@@ -53,4 +58,4 @@

export default function (series, store, layout, isStacked, extraOptions) {
switch(layout.type) {
export default function(series, store, layout, isStacked, extraOptions) {
switch (layout.type) {
case CHART_TYPE_PIE:

@@ -63,10 +68,9 @@ series = getPie(series, store, layout, isStacked, extraOptions.colors);

default:
series = getDefault(series, store, layout, isStacked, extraOptions.colors);
series = getDefault(series, store, layout, isStacked, extraOptions);
}
series.forEach(seriesObj => {
// animation
seriesObj.animation = {
duration: DEFAULT_ANIMATION_DURATION
duration: DEFAULT_ANIMATION_DURATION,
};

@@ -73,0 +77,0 @@ });

import getCategories from '../getCategories';
export default function (series, store, layout, isStacked, colors) {
return [{
name: series[0].name,
colorByPoint: true,
allowPointSelect: true,
cursor: 'pointer',
data: getCategories(store, layout).map((category, index) => ({
name: category,
color: colors[index],
y: series[0].data[index],
})),
dataLabels: {
enabled: true,
formatter: function() {
return '<span style="font-weight:normal">' + this.point.name + '</span><br/>' + this.y + '<span style="font-weight:normal"> (' + this.percentage.toFixed(1) + ' %)</span>';
}
}
}];
}
export default function(series, store, layout, isStacked, colors) {
return [
{
name: series[0].name,
colorByPoint: true,
allowPointSelect: true,
cursor: 'pointer',
data: getCategories(store.data[0].metaData, layout).map((category, index) => ({
name: category,
color: colors[index],
y: series[0].data[index],
})),
dataLabels: {
enabled: true,
formatter: function() {
return (
'<span style="font-weight:normal">' +
this.point.name +
'</span><br/>' +
this.y +
'<span style="font-weight:normal"> (' +
this.percentage.toFixed(1) +
' %)</span>'
);
},
},
},
];
}

@@ -15,4 +15,4 @@ import isString from 'd2-utilizr/lib/isString';

color: '#555',
textShadow: '0 0 #999'
}
textShadow: '0 0 #999',
},
};

@@ -27,13 +27,13 @@

fontSize: '12px'
}
fontSize: '12px',
},
};
function getDefault(layout, dashboard, filterTitle) {
function getDefault(layout, dashboard, filterTitle) {
return {
text: dashboard || isString(layout.title) ? filterTitle : undefined
text: dashboard || isString(layout.title) ? filterTitle : undefined,
};
}
export default function (series, layout, metaData, dashboard) {
export default function(series, layout, metaData, dashboard) {
if (layout.hideSubtitle) {

@@ -48,7 +48,6 @@ return null;

subtitle = { text: layout.subtitle };
}
else {
} else {
const filterTitle = getFilterTitle(layout.filters, metaData);
switch(layout.type) {
switch (layout.type) {
case CHART_TYPE_PIE:

@@ -63,8 +62,5 @@ case CHART_TYPE_GAUGE:

return subtitle ? Object.assign(
{},
DEFAULT_SUBTITLE,
dashboard ? DASHBOARD_SUBTITLE : undefined,
subtitle
) : subtitle;
return subtitle
? Object.assign({}, DEFAULT_SUBTITLE, dashboard ? DASHBOARD_SUBTITLE : undefined, subtitle)
: subtitle;
}

@@ -8,4 +8,4 @@ import isString from 'd2-utilizr/lib/isString';

style: {
color: '#111'
}
color: '#111',
},
};

@@ -18,10 +18,9 @@

fontSize: '13px',
fontWeight: 'bold'
}
fontWeight: 'bold',
},
};
function getText(layout, metaData, dashboard) {
function getText(layout, metaData, dashboard) {
// title
if (isString(layout.title) && layout.title.length) {
if (isString(layout.title) && layout.title.length) {
return layout.title;

@@ -36,3 +35,3 @@ }

// filters
if (layout.filters && !dashboard) {
if (layout.filters && !dashboard) {
return getFilterTitle(layout.filters, metaData);

@@ -46,7 +45,7 @@ }

return {
text: layout.hideTitle ? null : getText(layout, metaData, dashboard)
text: layout.hideTitle ? null : getText(layout, metaData, dashboard),
};
}
export default function (layout, metaData, dashboard) {
export default function(layout, metaData, dashboard) {
return Object.assign(

@@ -57,2 +56,2 @@ getTextObject(layout, metaData, dashboard),

);
};
}
import arrayContains from 'd2-utilizr/lib/arrayContains';
// Note: IE11 does not support passing the array directly to the constructor
const chartTypeMap = new Map();
const stackedTypes = ['STACKED_COLUMN', 'STACKEDCOLUMN', 'STACKED_BAR', 'STACKEDBAR', 'AREA'];
chartTypeMap.set('radar', { type: 'line', polar: true });
chartTypeMap.set('gauge', { type: 'solidgauge' });
chartTypeMap.set('stackedcolumn', { type: 'column' });
chartTypeMap.set('stackedbar', { type: 'bar' });
const stackedTypes = ['stackedcolumn', 'stackedbar', 'area'];
export function getIsStacked(type) {
return arrayContains(stackedTypes, type.toLowerCase());
return arrayContains(stackedTypes, type);
}
export default function (type) {
return chartTypeMap.get(type.toLowerCase()) || {
type: type.toLowerCase()
};
export default function(type) {
switch (type) {
case 'BAR':
case 'STACKED_BAR':
case 'STACKEDBAR':
return { type: 'bar' };
case 'LINE':
case 'YEAR_ON_YEAR':
return { type: 'line' };
case 'AREA':
return { type: 'area' };
case 'PIE':
return { type: 'pie' };
case 'RADAR':
return { type: 'line', polar: true };
case 'GAUGE':
return { type: 'solidgauge' };
case 'COLUMN':
case 'STACKED_COLUMN':
case 'STACKEDCOLUMN':
default:
return { type: 'column' };
}
}

@@ -5,7 +5,8 @@ import objectClean from 'd2-utilizr/lib/objectClean';

import getGauge from './gauge';
import { CHART_TYPE_GAUGE } from '..';
import getYearOnYear from './yearOnYear';
import { CHART_TYPE_GAUGE, CHART_TYPE_YEAR_ON_YEAR } from '..';
function getDefault(store, layout) {
return objectClean({
categories: getCategories(store, layout),
categories: getCategories(store.data[0].metaData, layout),
title: getAxisTitle(layout.domainAxisTitle),

@@ -15,15 +16,18 @@ labels: {

color: '#666',
textShadow: '0 0 #ccc'
}
}
textShadow: '0 0 #ccc',
},
},
});
}
export default function (store, layout) {
export default function(store, layout) {
let xAxis;
switch(layout.type) {
switch (layout.type) {
case CHART_TYPE_GAUGE:
xAxis = getGauge();
break;
case CHART_TYPE_YEAR_ON_YEAR:
xAxis = getYearOnYear(store, layout);
break;
default:

@@ -34,2 +38,2 @@ xAxis = getDefault(store, layout);

return xAxis;
}
}

@@ -0,1 +1,2 @@

import isArray from 'd2-utilizr/lib/isArray';
import 'core-js/fn/array/find-index';

@@ -6,12 +7,20 @@

const defaultError = (error) => {
const defaultError = error => {
throw new Error(error);
};
const defaultWarning = (warning) => {
const defaultWarning = warning => {
console.log(warning);
};
function createChart(data, layout, el, extraOptions, error = defaultError, warning = defaultWarning) {
const store = new Store({ data, error, warning });
function createChart(
data,
layout,
el,
extraOptions,
error = defaultError,
warning = defaultWarning
) {
const _data = isArray(data) ? data : [data];
const store = new Store({ data: _data, error, warning });
const config = new Config({ store, layout, el, extraOptions, error, warning });

@@ -22,11 +31,7 @@

config,
chart: config.createChart()
chart: config.createChart(),
};
}
export {
Store,
Config,
createChart
};
export { Store, Config, createChart };

@@ -36,3 +41,3 @@ export default {

Config,
createChart
createChart,
};

@@ -0,7 +1,10 @@

import getYearOnYear from './yearOnYear';
import { CHART_TYPE_YEAR_ON_YEAR } from '../../../config/adapters/dhis_highcharts';
const VALUE_ID = 'value';
function getHeaderIdIndexMap(headers) {
function getHeaderIdIndexMap(headers) {
const map = new Map();
headers.forEach((header, index) => {
headers.forEach((header, index) => {
map.set(header.name, index);

@@ -13,7 +16,7 @@ });

function getPrefixedId(row, header) {
return (header.isPrefix ? (header.name + '_') : '') + row[header.index];
function getPrefixedId(row, header) {
return (header.isPrefix ? header.name + '_' : '') + row[header.index];
}
function getIdValueMap(rows, seriesHeader, categoryHeader, valueIndex) {
function getIdValueMap(rows, seriesHeader, categoryHeader, valueIndex) {
const map = new Map();

@@ -24,3 +27,3 @@

rows.forEach(row => {
rows.forEach(row => {
key = getPrefixedId(row, seriesHeader) + '-' + getPrefixedId(row, categoryHeader);

@@ -35,47 +38,53 @@ value = row[valueIndex];

function getData(seriesIds, categoryIds, idValueMap, metaDataItems) {
const data = [];
let dataItem;
let value;
function getDefault(acc, seriesIds, categoryIds, idValueMap, metaData) {
seriesIds.forEach(seriesId => {
const serieData = [];
const serieLabel = metaData.items[seriesId].name;
seriesIds.forEach(seriesId => {
dataItem = {
name: metaDataItems[seriesId].name,
data: []
};
categoryIds.forEach(categoryId => {
const value = idValueMap.get(`${seriesId}-${categoryId}`);
categoryIds.forEach(categoryId => {
value = idValueMap.get(`${ seriesId }-${ categoryId }`);
// DHIS2-1261: 0 is a valid value
// undefined value means the key was not found within the rows
// in that case null is returned as value in the serie for highcharts
dataItem.data.push((value == undefined) ? null : parseFloat(value));
serieData.push(value == undefined ? null : parseFloat(value));
});
data.push(dataItem);
acc.push({
name: serieLabel,
data: serieData,
});
});
return data;
return acc;
}
export default function ({ data, seriesId = data.headers[0].name, categoryId = data.headers[1].name }) {
const headers = data.headers;
const metaData = data.metaData;
const rows = data.rows;
const headerIdIndexMap = getHeaderIdIndexMap(headers);
export default function({ type, data, seriesId, categoryId }) {
const seriesFunction = type === CHART_TYPE_YEAR_ON_YEAR ? getYearOnYear : getDefault;
const seriesIndex = headerIdIndexMap.get(seriesId);
const categoryIndex = headerIdIndexMap.get(categoryId);
const valueIndex = headerIdIndexMap.get(VALUE_ID);
return data.reduce((acc, res) => {
seriesId = seriesId || res.headers[0].name;
categoryId = categoryId || res.headers[1].name;
const seriesHeader = headers[seriesIndex];
const categoryHeader = headers[categoryIndex];
const headers = res.headers;
const metaData = res.metaData;
const rows = res.rows;
const headerIdIndexMap = getHeaderIdIndexMap(headers);
const idValueMap = getIdValueMap(rows, seriesHeader, categoryHeader, valueIndex);
const seriesIndex = headerIdIndexMap.get(seriesId);
const categoryIndex = headerIdIndexMap.get(categoryId);
const valueIndex = headerIdIndexMap.get(VALUE_ID);
const seriesIds = metaData.dimensions[seriesId];
const categoryIds = metaData.dimensions[categoryId];
const seriesHeader = headers[seriesIndex];
const categoryHeader = headers[categoryIndex];
return getData(seriesIds, categoryIds, idValueMap, metaData.items);
const idValueMap = getIdValueMap(rows, seriesHeader, categoryHeader, valueIndex);
const seriesIds = metaData.dimensions[seriesId];
const categoryIds = metaData.dimensions[categoryId];
seriesFunction(acc, seriesIds, categoryIds, idValueMap, metaData);
return acc;
}, []);
}
import validators from './validators';
import adapters from './adapters';
export default function ({ data, inputFormat = 'dhis', outputFormat = 'highcharts', seriesId, categoryId, error, warning }) {
export default function({
data,
inputFormat = 'dhis',
outputFormat = 'highcharts',
seriesId,
categoryId,
error,
warning,
}) {
let _validator = validators[inputFormat] || validators.noValidation;
let _adapter = adapters[inputFormat + '_' + outputFormat];
if (_validator === validators.noValidation) {
if (_validator === validators.noValidation) {
warning(`Validation not supported for data input format "${inputFormat}"`);
}
if (!_adapter) {
if (!_adapter) {
error(`Data tranformation from "${inputFormat}" to "${outputFormat}" is not supported`);

@@ -18,9 +26,10 @@ }

this.generateData = ({ seriesId = seriesId, categoryId = categoryId }) => {
this.generateData = ({ type, seriesId = seriesId, categoryId = categoryId }) => {
return _adapter({
data: _validator({ data, error, warning }),
type,
data: data.map(d => _validator({ data: d, error, warning })),
seriesId,
categoryId
categoryId,
});
};
}
import dhis from './dhis';
const noValidation = (data) => data;
const noValidation = data => data;

@@ -5,0 +5,0 @@ export default {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc