Skip to content
Merged
3 changes: 3 additions & 0 deletions R/getSettingValue.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ getSettingValue <- function(key,settings){
#If there are more keys and the value is a list, iterate
if(typeof(value)=="list"){
value<-getSettingValue(key[2:length(key)],value)
#If position is provided and the value is a vector
}else if(is.numeric(key[[2]]) & length(value)>=key[[2]] & length(key)==2){
value<-value[[key[[2]]]]
}else{
#If there are more keys, but the value is not a list, return NULL
value<-NULL
Expand Down
10 changes: 5 additions & 5 deletions R/trimData.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@


trimData <- function(data, settings, chart="edish"){

## Remove columns not in settings ##
col_names <- colnames(data)

allKeys <- getSettingsMetadata(charts=chart, filter_expr = .data$column_mapping, cols = c("text_key","setting_type"))
dataKeys <- allKeys %>% filter(.data$setting_type !="vector") %>% pull(.data$text_key) %>% textKeysToList()

# Add items in vectors to list individually
dataVectorKeys <- allKeys %>% filter(.data$setting_type =="vector") %>% pull(.data$text_key) %>% textKeysToList()
for(key in dataVectorKeys){
Expand All @@ -42,9 +42,9 @@ trimData <- function(data, settings, chart="edish"){
}
}
}

settings_values <- map(dataKeys, function(x) {return(getSettingValue(x, settings))})

common_cols <- intersect(col_names,settings_values)

data_subset <- select(data, unlist(common_cols))
Expand Down
8 changes: 4 additions & 4 deletions inst/htmlwidgets/eDISH.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ dependencies:
src: htmlwidgets/lib/d3-3.5.17
script: d3.v3.min.js
- name: webcharts
version: 1.11.3
src: htmlwidgets/lib/webcharts-1.11.3
version: 1.11.5
src: htmlwidgets/lib/webcharts-1.11.5
script: webcharts.js
stylesheet: webcharts.css
- name: safety-eDish
version: 0.16.3
src: htmlwidgets/lib/safety-eDISH-0.16.3
version: 0.16.7
src: htmlwidgets/lib/safety-eDISH-0.16.7
script: safetyedish.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@

//make sure filters is an Array
if (!(settings.filters instanceof Array)) {
settings.filters = [];
settings.filters = typeof settings.filters == 'string' ? [settings.filters] : [];
}

//Define default details.
Expand Down Expand Up @@ -445,6 +445,11 @@
});
}

//parse details to array if needed
if (!(settings.details instanceof Array)) {
settings.details = typeof settings.details == 'string' ? [settings.details] : [];
}

//If [settings.details] is not specified:
if (!settings.details) settings.details = defaultDetails;
else {
Expand Down Expand Up @@ -473,15 +478,29 @@

// If settings.analysisFlag is null
if (!settings.analysisFlag) settings.analysisFlag = { value_col: null, values: [] };

if (!settings.analysisFlag.value_col) settings.analysisFlag.value_col = null;
if (!(settings.analysisFlag.values instanceof Array)) {
settings.analysisFlag.values =
typeof settings.analysisFlag.values == 'string'
? [settings.analysisFlag.values]
: [];
}
//if it is null, set settings.baseline.value_col to settings.studyday_col.
if (!settings.baseline) settings.baseline = { value_col: null, values: [] };
if (settings.baseline.values.length == 0) settings.baseline.values = [0];
if (!settings.baseline.value_col) settings.baseline.value_col = settings.studyday_col;
if (!(settings.baseline.values instanceof Array)) {
settings.baseline.values =
typeof settings.baseline.values == 'string' ? [settings.baseline.values] : [];
}

//parse x_ and y_options to array if needed
if (typeof settings.x_options == 'string') settings.x_options = [settings.x_options];
if (typeof settings.y_options == 'string') settings.y_options = [settings.y_options];
if (!(settings.x_options instanceof Array)) {
settings.x_options = typeof settings.x_options == 'string' ? [settings.x_options] : [];
}

if (!(settings.y_options instanceof Array)) {
settings.y_options = typeof settings.y_options == 'string' ? [settings.y_options] : [];
}

// track initial Cutpoint (lets us detect when cutpoint should change)
settings.cuts.x = settings.x.column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@

//Define default details.
var defaultDetails = [{ value_col: settings.id_col, label: 'Subject Identifier' }];

if (!(settings.filters instanceof Array)) {
settings.filters = typeof settings.filters == 'string' ? [settings.filters] : [];
}

if (settings.filters)
settings.filters.forEach(function(filter) {
return defaultDetails.push({
Expand All @@ -219,6 +224,11 @@
label: 'Upper Limit of Normal'
});

//If [settings.details] is not an array:
if (!(settings.details instanceof Array)) {
settings.details = typeof settings.details == 'string' ? [settings.details] : [];
}

//If [settings.details] is not specified:
if (!settings.details) settings.details = defaultDetails;
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
: (global.webCharts = factory(global.d3));
})(typeof self !== 'undefined' ? self : this, function(d3) {
'use strict';
var version = '1.11.3';
var version = '1.11.5';

function init(data) {
var _this = this;
Expand Down Expand Up @@ -518,7 +518,7 @@
if (this.filters.length) {
this.filters.forEach(function(filter) {
_this.filtered_data = _this.filtered_data.filter(function(d) {
return filter.val === 'All'
return filter.all === true && filter.index === 0
? d
: filter.val instanceof Array
? filter.val.indexOf(d[filter.col]) > -1
Expand Down Expand Up @@ -1092,7 +1092,7 @@
if (this.filters.length) {
this.filters.forEach(function(e) {
filtered = filtered.filter(function(d) {
return e.val === 'All'
return e.all === true && e.index === 0
? d
: e.val instanceof Array
? e.val.indexOf(d[e.col]) > -1
Expand Down Expand Up @@ -1831,6 +1831,7 @@
function drawBars(marks) {
var _this = this;

var chart = this;
var rawData = this.raw_data;
var config = this.config;

Expand Down Expand Up @@ -1896,7 +1897,7 @@
.attr('class', function(d) {
return 'wc-data-mark bar ' + d.key;
})
.style('clip-path', 'url(#' + this.id + ')')
.style('clip-path', 'url(#' + chart.id + ')')
.attr('y', this.y(0))
.attr('height', 0)
.append('title');
Expand Down Expand Up @@ -2029,7 +2030,7 @@
.attr('class', function(d) {
return 'wc-data-mark bar ' + d.key;
})
.style('clip-path', 'url(#' + this.id + ')')
.style('clip-path', 'url(#' + chart.id + ')')
.attr('x', this.x(0))
.attr('width', 0)
.append('title');
Expand Down Expand Up @@ -2157,7 +2158,7 @@
.attr('class', function(d) {
return 'wc-data-mark bar ' + d.key;
})
.style('clip-path', 'url(#' + this.id + ')')
.style('clip-path', 'url(#' + chart.id + ')')
.attr('y', this.y(0))
.attr('height', 0)
.append('title');
Expand Down Expand Up @@ -2267,7 +2268,7 @@
.attr('class', function(d) {
return 'wc-data-mark bar ' + d.key;
})
.style('clip-path', 'url(#' + this.id + ')')
.style('clip-path', 'url(#' + chart.id + ')')
.attr('x', this.x(0))
.attr('width', 0)
.append('title');
Expand Down Expand Up @@ -2362,6 +2363,7 @@
function drawLines(marks) {
var _this = this;

var chart = this;
var config = this.config;
var line = d3.svg
.line()
Expand Down Expand Up @@ -2409,6 +2411,7 @@
var linePaths = line_grps
.select('path')
.attr('class', 'wc-data-mark')
.style('clip-path', 'url(#' + chart.id + ')')
.datum(function(d) {
return d.values;
})
Expand Down Expand Up @@ -2458,6 +2461,7 @@
function drawPoints(marks) {
var _this = this;

var chart = this;
var config = this.config;

var point_supergroups = this.svg.selectAll('.point-supergroup').data(marks, function(d, i) {
Expand Down Expand Up @@ -2496,6 +2500,7 @@
//static attributes
points
.select('circle')
.style('clip-path', 'url(#' + chart.id + ')')
.attr(
'fill-opacity',
config.fill_opacity || config.fill_opacity === 0 ? config.fill_opacity : 0.6
Expand Down Expand Up @@ -2568,6 +2573,7 @@
function drawText(marks) {
var _this = this;

var chart = this;
var config = this.config;

var textSupergroups = this.svg.selectAll('.text-supergroup').data(marks, function(d, i) {
Expand Down Expand Up @@ -2610,7 +2616,7 @@
texts.each(attachMarks);

// parse text like tooltips
texts.select('text').text(function(d) {
texts.select('text').style('clip-path', 'url(#' + chart.id + ')').text(function(d) {
var tt = d.mark.text || '';
var xformat = config.x.summary === 'percent'
? d3.format('0%')
Expand Down Expand Up @@ -3061,13 +3067,16 @@
}

function makeSubsetterControl(control, control_wrap) {
var targets = this.targets;
var targets = this.targets; // associated charts and tables.

//dropdown selection
var changer = control_wrap
.append('select')
.attr('class', 'changer')
.classed('changer', true)
.attr('multiple', control.multiple ? true : null)
.datum(control);

//dropdown option data
var option_data = control.values
? control.values
: d3
Expand All @@ -3080,17 +3089,24 @@
return f;
})
)
.values();
option_data.sort(naturalSorter);
.values()
.sort(naturalSorter); // only sort when values are derived

//initial dropdown option
control.start = control.start ? control.start : control.loose ? option_data[0] : null;

//conditionally add All option
if (!control.multiple && !control.start) {
option_data.unshift('All');
control.all = true;
} else {
control.all = false;
}

//what does loose mean?
control.loose = !control.loose && control.start ? true : control.loose;

//dropdown options selection
var options = changer
.selectAll('option')
.data(option_data)
Expand All @@ -3103,6 +3119,7 @@
return d === control.start;
});

//define filter object for each associated target
targets.forEach(function(e) {
var match = e.filters
.slice()
Expand All @@ -3113,16 +3130,20 @@
if (match > -1) {
e.filters[match] = {
col: control.value_col,
val: control.start ? control.start : 'All',
val: control.start ? control.start : !control.multiple ? 'All' : option_data,
index: 0,
choices: option_data,
loose: control.loose
loose: control.loose,
all: control.all
};
} else {
e.filters.push({
col: control.value_col,
val: control.start ? control.start : 'All',
val: control.start ? control.start : !control.multiple ? 'All' : option_data,
index: 0,
choices: option_data,
loose: control.loose
loose: control.loose,
all: control.all
});
}
});
Expand All @@ -3139,6 +3160,7 @@
}
}

//add event listener to control
changer.on('change', function(d) {
if (control.multiple) {
var values = options
Expand All @@ -3152,8 +3174,10 @@
var new_filter = {
col: control.value_col,
val: values,
index: null, // could specify an array of indices but seems like a waste of resources give it doesn't inform anything without an overall 'All'
choices: option_data,
loose: control.loose
loose: control.loose,
all: control.all
};
targets.forEach(function(e) {
setSubsetter(e, new_filter);
Expand All @@ -3165,11 +3189,14 @@
});
} else {
var value = d3.select(this).select('option:checked').property('text');
var index = d3.select(this).select('option:checked').property('index');
var _new_filter = {
col: control.value_col,
val: value,
index: index,
choices: option_data,
loose: control.loose
loose: control.loose,
all: control.all
};
targets.forEach(function(e) {
setSubsetter(e, _new_filter);
Expand Down Expand Up @@ -3273,7 +3300,8 @@
this.filters &&
this.filters.some(function(filter) {
return (
(typeof filter.val === 'string' && filter.val !== 'All') ||
(typeof filter.val === 'string' &&
!(filter.all === true && filter.index === 0)) ||
(Array.isArray(filter.val) && filter.val.length < filter.choices.length)
);
})
Expand All @@ -3282,7 +3310,8 @@
this.filters
.filter(function(filter) {
return (
(typeof filter.val === 'string' && filter.val !== 'All') ||
(typeof filter.val === 'string' &&
!(filter.all === true && filter.index === 0)) ||
(Array.isArray(filter.val) && filter.val.length < filter.choices.length)
);
})
Expand Down
Loading