Skip to content

Commit

Permalink
Update date range from metadata on load
Browse files Browse the repository at this point in the history
  • Loading branch information
trvrb committed Mar 19, 2017
1 parent c70f8f6 commit ed745b9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
35 changes: 34 additions & 1 deletion src/actions/loadData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,40 @@ import { updateColorScale, updateNodeColors } from "./colors";
import { dataURLStem } from "../util/globals";
import * as types from "./types";

/* request metadata */
const updateDateRange = function () {
return function (dispatch, getState) {
const { controls, metadata } = getState();
/* bail if all required params aren't (yet) available! */
if (!(metadata.loadStatus === 2)) {
return null;
}
if (metadata.metadata.date_range) {
if (metadata.metadata.date_range.date_min) {
dispatch({
type: types.CHANGE_ABSOLUTE_DATE_MIN,
data: metadata.metadata.date_range.date_min
});
dispatch({
type: types.CHANGE_DATE_MIN,
data: metadata.metadata.date_range.date_min
});
}
if (metadata.metadata.date_range.date_max) {
dispatch({
type: types.CHANGE_ABSOLUTE_DATE_MAX,
data: metadata.metadata.date_range.date_max
});
dispatch({
type: types.CHANGE_DATE_MAX,
data: metadata.metadata.date_range.date_max
});
}
}

};
};

/* request metadata */
const requestMetadata = () => {
return {
type: types.REQUEST_METADATA
Expand Down Expand Up @@ -42,6 +74,7 @@ const populateMetadataStore = (queryParams) => {
dispatch(receiveMetadata(json));
dispatch(updateColorScale());
dispatch(updateNodeColors());
dispatch(updateDateRange());
},
(err) => dispatch(metadataFetchError(err))
);
Expand Down
4 changes: 3 additions & 1 deletion src/components/controls/date-range-inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class DateRangeInputs extends React.Component {
const selectedMinNumDate = calendarToNumeric(selectedMin);
const selectedMaxNumDate = calendarToNumeric(selectedMax);

const minDistance = (absoluteMaxNumDate - absoluteMinNumDate) / 10.0;

return (
<div>
<div style={{width: controlsWidth}}>
Expand All @@ -161,7 +163,7 @@ class DateRangeInputs extends React.Component {
/* debounce the onChange event, but ensure the final one goes through */
onChange={this.updateFromSlider.bind(this, true)}
onAfterChange={this.updateFromSlider.bind(this, false)}
minDistance={0.5} // minDistance is in years
minDistance={minDistance}
pearling
withBars/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/util/getColorScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const genericScale = (cmin, cmax) => {
const range = cmax - cmin;
const tmpColorScale = d3.scale.linear()
.domain(genericDomain.map((d) => offset + d * range))
.range(colors[10]);
.range(colors[9]);
return tmpColorScale;
};

Expand Down

0 comments on commit ed745b9

Please sign in to comment.