Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug where hidden variables show up in groups/filters when checkin… #139

Merged
merged 3 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 58 additions & 113 deletions build/webcodebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ function update(codebook) {
return 'custom-' + d.value_col + ' filterCustom';
});
allFilterItem.exit().remove();
allFilterItem.classed('hidden', function (d) {
return codebook.config.hiddenVariables.indexOf(d.value_col) > -1;
});
allFilterItem.sort(function (a, b) {
var aSort = columns.indexOf(a.value_col),
bSort = columns.indexOf(b.value_col);
Expand Down Expand Up @@ -188,7 +191,6 @@ function update(codebook) {
Initialize filters.
\------------------------------------------------------------------------------------------------*/

//export function init(selector, data, vars, settings) {
function init$2(codebook) {
//initialize the wrapper
var selector = codebook.controls.wrap.append('div').attr('class', 'custom-filters'),
Expand Down Expand Up @@ -231,6 +233,9 @@ function update$1(codebook) {
return d.value_col;
});
groupOptions.exit().remove();
groupOptions.classed('hidden', function (d) {
return codebook.config.hiddenVariables.indexOf(d.value_col) > -1;
});
groupOptions.sort(function (a, b) {
return columns.indexOf(a) - columns.indexOf(b);
});
Expand Down Expand Up @@ -1729,7 +1734,6 @@ function makeDetails(d) {
return f != 'values';
});
var statList = statNames.map(function (stat) {
console.log(stat);
return {
key: stat !== 'nMissing' ? stat : 'Missing',
value: d.statistics[stat]
Expand Down Expand Up @@ -2350,9 +2354,40 @@ var data = {

function init$8(codebook) {
codebook.settings.layout(codebook);
for (var funk in codebook.settings.functionality) {
codebook.settings.functionality[funk](codebook);
}
}

function reset(codebook) {
//remove grouping and select 'None' group option
delete codebook.config.group;
codebook.controls.groups.update(codebook);
codebook.controls.wrap.select('.group-select').selectAll('option').property('selected', function (d) {
return d.value_col === 'None';
});

//remove filtering and select all filter options
codebook.data.filtered = codebook.data.raw;
codebook.controls.filters.update(codebook);
codebook.controls.wrap.selectAll('.filterCustom option').property('selected', true);

//redraw data summary, codebook, and listing.
codebook.data.makeSummary(codebook);
codebook.summaryTable.draw(codebook);
codebook.dataListing.init(codebook);
}

function updateSettings(codebook, column) {
var setting = column !== 'Hidden' ? column.toLowerCase() + 's' : 'hiddenVariables',
checkBoxes = codebook.settings.wrap.selectAll('.column-table td.' + column);

//redefine filter array
codebook.config[setting] = checkBoxes.filter(function () {
return d3.select(this).select('input').property('checked');
}).data().map(function (d) {
return column !== 'Hidden' ? { value_col: d.column } : d.column;
});

//reset
reset(codebook);
}

function layout$2(codebook) {
Expand Down Expand Up @@ -2387,15 +2422,23 @@ function layout$2(codebook) {

return columnDatum;
}),
columnTable = codebook.settings.wrap.append('table').classed('column-table', true),
columnTableHeader = columnTable.append('thead').append('tr'),

//define table
columnTable = codebook.settings.wrap.append('table').classed('column-table', true),

//define table headers
columnTableHeader = columnTable.append('thead').append('tr'),
columnTableHeaders = columnTableHeader.selectAll('th').data(columnTableColumns).enter().append('th').attr('class', function (d) {
return d;
}).text(function (d) {
return d;
}),
columnTableRows = columnTable.append('tbody').selectAll('tr').data(columnMetadata).enter().append('tr'),
columnTableCells = columnTableRows.selectAll('td').data(function (d) {

//define table rows
columnTableRows = columnTable.append('tbody').selectAll('tr').data(columnMetadata).enter().append('tr'),

//define table cells
columnTableCells = columnTableRows.selectAll('td').data(function (d) {
return Object.keys(d).map(function (di) {
return { column: d.Column, key: di, value: d[di] };
});
Expand All @@ -2410,122 +2453,24 @@ function layout$2(codebook) {
break;
default:
cell.attr('title', (d.value.checked ? 'Remove' : 'Add') + ' ' + d.column + ' ' + (d.value.checked ? 'from' : 'to') + ' ' + d.key.toLowerCase() + ' list');
cell.append('input').attr('type', d.value.type).property('checked', d.value.checked);
var checkbox = cell.append('input').attr('type', d.value.type).property('checked', d.value.checked);
checkbox.on('change', function () {
return updateSettings(codebook, d.key);
});
}
});

//Add descriptive footnote.
columnTable.select('tbody').append('tr').style('border-bottom', 'none').append('td').attr('colspan', '5').text("This interactive table allows users to modify each column's metadata.");
columnTable.select('tbody').append('tr').style('border-bottom', 'none').append('td').attr('colspan', columnTableColumns.length).html("This interactive table allows users to modify each column's metadata.<br>Updating these settings will reset the codebook and data listing.");
}

function updateGroups(codebook) {
var groupCheckBoxes = codebook.settings.wrap.selectAll('.column-table td.Group');

//Add click functionality to each list item.
groupCheckBoxes.on('change', function () {
var groups = groupCheckBoxes.filter(function () {
return d3.select(this).select('input').property('checked');
}).data().map(function (d) {
return d.column;
});
codebook.config.groups = groups.map(function (d) {
return { value_col: d };
});
codebook.controls.groups.update(codebook);

//Redraw codebook if currently grouped by former group column.
if (codebook.config.group && groups.indexOf(codebook.config.group) === -1) {
delete codebook.config.group;
codebook.data.makeSummary(codebook);
codebook.summaryTable.draw(codebook);
}
});
}

function updateFilters(codebook) {
var filterCheckBoxes = codebook.settings.wrap.selectAll('.column-table td.Filter');

//Add click functionality to each list item.
filterCheckBoxes.on('change', function () {
var filters = filterCheckBoxes.filter(function () {
return d3.select(this).select('input').property('checked');
}).data().map(function (d) {
return d.column;
});

//Add new filters to settings.filters.
filters.forEach(function (filter) {
if (codebook.config.filters.map(function (d) {
return d.value_col;
}).indexOf(filter) === -1) codebook.config.filters.push({ value_col: filter });
});
//Remove old filters from settings.filters.
codebook.config.filters.forEach(function (filter, i) {
if (filters.indexOf(filter.value_col) === -1) codebook.config.filters.splice(i, 1);
});
codebook.controls.filters.update(codebook);

//Update filtered data and redraw codebook.
codebook.data.filtered = codebook.data.makeFiltered(codebook.data.raw, codebook.config.filters);
codebook.data.makeSummary(codebook);
codebook.summaryTable.draw(codebook);
codebook.dataListing.init(codebook);
});
}

function updateHidden(codebook) {
var hiddenCheckBoxes = codebook.settings.wrap.selectAll('.column-table td.Hidden');

//Add click functionality to each list item.
hiddenCheckBoxes.on('change', function () {
codebook.config.hiddenVariables = hiddenCheckBoxes.filter(function () {
return d3.select(this).select('input').property('checked');
}).data().map(function (d) {
return d.column;
});

//update hidden attribute in variable summary data array
codebook.data.summary.forEach(function (d) {
d.hidden = codebook.config.hiddenVariables.indexOf(d.value_col) > -1;
});

//Hide group-by options corresponding to variables specified in settings.hiddenVariables.
codebook.controls.wrap.selectAll('.group-select option').classed('hidden', function (d) {
return codebook.config.hiddenVariables.indexOf(d) > -1;
});

//Hide filters corresponding to variables specified in settings.hiddenVariables.
codebook.controls.wrap.selectAll('.filter-list li.filterCustom').classed('hidden', function (d) {
return codebook.config.hiddenVariables.indexOf(d.value_col) > -1;
});

//update summary text
codebook.summaryTable.updateSummaryText(codebook);

//Hide variable rows corresponding to variables specified in settings.hiddenVariables.
codebook.summaryTable.wrap.selectAll('div.variable-row').classed('hidden', function (d) {
return codebook.config.hiddenVariables.indexOf(d.value_col) > -1;
});

//Redraw data listing because columns corresponding to hidden variables will not be hidden until dataListing.onDraw() is called.
codebook.dataListing.init(codebook);
});
}

var functionality = {
updateGroups: updateGroups,
updateFilters: updateFilters,
updateHidden: updateHidden
};

/*------------------------------------------------------------------------------------------------\
Define settings object.
\------------------------------------------------------------------------------------------------*/

var settings = {
init: init$8,
layout: layout$2,
functionality: functionality
layout: layout$2
};

function createCodebook() {
Expand Down
4 changes: 4 additions & 0 deletions src/codebook/controls/filters/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export function update(codebook) {
return 'custom-' + d.value_col + ' filterCustom';
});
allFilterItem.exit().remove();
allFilterItem.classed(
'hidden',
d => codebook.config.hiddenVariables.indexOf(d.value_col) > -1
);
allFilterItem.sort((a, b) => {
const aSort = columns.indexOf(a.value_col),
bSort = columns.indexOf(b.value_col);
Expand Down
4 changes: 4 additions & 0 deletions src/codebook/controls/groups/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export function update(codebook) {
)
.text(d => d.value_col);
groupOptions.exit().remove();
groupOptions.classed(
'hidden',
d => codebook.config.hiddenVariables.indexOf(d.value_col) > -1
);
groupOptions.sort((a, b) => columns.indexOf(a) - columns.indexOf(b));
groupSelect.on('change', function() {
//display loading indicator
Expand Down
4 changes: 1 addition & 3 deletions src/codebook/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

import { init } from './settings/init';
import { layout } from './settings/layout';
import { functionality } from './settings/functionality';

export const settings = {
init: init,
layout: layout,
functionality: functionality
layout: layout
};
9 changes: 0 additions & 9 deletions src/codebook/settings/functionality.js

This file was deleted.

38 changes: 0 additions & 38 deletions src/codebook/settings/functionality/updateFilters.js

This file was deleted.

28 changes: 0 additions & 28 deletions src/codebook/settings/functionality/updateGroups.js

This file was deleted.

49 changes: 0 additions & 49 deletions src/codebook/settings/functionality/updateHidden.js

This file was deleted.

Loading