From f2f41ed08f595a4b7654cd4ccfc95b5413d0bdc9 Mon Sep 17 00:00:00 2001 From: Preston Burns Date: Tue, 2 Apr 2019 12:32:32 -0400 Subject: [PATCH] resolve #122 --- build/crfHeatMap.js | 16 +++++++++++++--- package-lock.json | 2 +- package.json | 2 +- scripts/configuration.md | 4 ++-- settings-schema.json | 2 +- src/onInit/summarizeData/calculateStatistics.js | 8 +++++++- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/build/crfHeatMap.js b/build/crfHeatMap.js index d86191e..f388f4d 100644 --- a/build/crfHeatMap.js +++ b/build/crfHeatMap.js @@ -260,9 +260,19 @@ //Define summarized values, either rates or counts. context.initial_config.value_cols.forEach(function(value_col) { - var count = d3.sum(d, function(di) { - return di[value_col.col]; - }); + var count; + if (typeof value_col.denominator === 'undefined') { + count = d3.sum(d, function(di) { + return di[value_col.col]; + }); + } else { + var subset = d.filter(function(row) { + return row[value_col.denominator] === '1'; + }); + count = d3.sum(subset, function(di) { + return di[value_col.col]; + }); + } summary[value_col.col] = crfsNoDenominator .map(function(m) { diff --git a/package-lock.json b/package-lock.json index bc9b9e3..346fd82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "crf-heat-map", - "version": "1.2.1", + "version": "1.2.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 484bf16..fcac2d6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "crf-heat-map", "description": "Heat Map showing database form status at different levels", - "version": "1.2.1", + "version": "1.2.3", "author": "Rho, Inc.", "license": "MIT", "homepage": "https://github.com/rhoinc/crf-heat-map#readme", diff --git a/scripts/configuration.md b/scripts/configuration.md index b2a0f60..4045c77 100644 --- a/scripts/configuration.md +++ b/scripts/configuration.md @@ -3,7 +3,7 @@ The most straightforward way to customize the CRF Heat Map is by using a configu In addition to the standard Webcharts settings several custom settings not available in the base Webcharts library have been added to the CRF Heat Map to facilitate data mapping and other custom functionality. These custom settings are described in detail below and are set in the [rendererSettings.js file](https://github.com/RhoInc/crf-heat-map/blob/master/src/configuration/rendererSettings.js). All defaults can be overwritten by the passed configuration object. # Renderer-specific settings -The sections below describe each crf-heat-map setting as of version 1.2.0. +The sections below describe each crf-heat-map setting as of version 1.2.3. ## settings.site_col `string` @@ -202,7 +202,7 @@ If the number of rows to be drawn exceeds this number when the user checks 'Expa **default:** `10000` # Webcharts settings -The object below contains each Webcharts setting as of version 1.2.0. +The object below contains each Webcharts setting as of version 1.2.3. ``` { return { cols: null, headers: null, // set in rendererSettings applyCSS: true, searchable: false, sortable: false, pagination: false, exportable: true, exports: ['csv', 'xlsx'], dynamicPositioning: false }; } } diff --git a/settings-schema.json b/settings-schema.json index 6fce872..b41e53c 100644 --- a/settings-schema.json +++ b/settings-schema.json @@ -2,7 +2,7 @@ "title": "settings", "description": "JSON schema for the configuration of the CRF Heat Map", "overview": "The most straightforward way to customize the CRF Heat Map is by using a configuration object whose properties describe the behavior and appearance of the table. Since the CRF Heat Map is a Webcharts `table` object, many default Webcharts settings are set in the [webchartsSettings.js file](https://github.com/RhoInc/crf-heat-map/blob/master/src/configuration/webchartsSettings.js) as [described below](#webcharts-settings). Refer to the [Webcharts documentation](https://github.com/RhoInc/Webcharts/wiki/Chart-Configuration) for more details on these settings.\nIn addition to the standard Webcharts settings several custom settings not available in the base Webcharts library have been added to the CRF Heat Map to facilitate data mapping and other custom functionality. These custom settings are described in detail below and are set in the [rendererSettings.js file](https://github.com/RhoInc/crf-heat-map/blob/master/src/configuration/rendererSettings.js). All defaults can be overwritten by the passed configuration object.", - "version": "1.2.0", + "version": "1.2.3", "type": "object", "properties": { "site_col" : { diff --git a/src/onInit/summarizeData/calculateStatistics.js b/src/onInit/summarizeData/calculateStatistics.js index 3a6986d..af0ca54 100644 --- a/src/onInit/summarizeData/calculateStatistics.js +++ b/src/onInit/summarizeData/calculateStatistics.js @@ -41,7 +41,13 @@ export default function calculateStatistics(onInit = true) { //Define summarized values, either rates or counts. context.initial_config.value_cols.forEach(value_col => { - const count = d3.sum(d, di => di[value_col.col]); + var count; + if (typeof value_col.denominator === 'undefined') { + count = d3.sum(d, di => di[value_col.col]); + } else { + var subset = d.filter(row => row[value_col.denominator] === '1'); + count = d3.sum(subset, di => di[value_col.col]); + } summary[value_col.col] = crfsNoDenominator.map(m => m.col).indexOf(value_col.col) > -1 ? summary.nForms