diff --git a/assets/src/scripts/components/hydrograph/index.js b/assets/src/scripts/components/hydrograph/index.js index cbe78843a32d446981646026d1ef55bfc12793db..63d9290a1a45c60c69950501ebef5e4309e2e7ad 100644 --- a/assets/src/scripts/components/hydrograph/index.js +++ b/assets/src/scripts/components/hydrograph/index.js @@ -287,7 +287,7 @@ const attachToNode = function (node, {siteno} = {}) { })); window.onresize = function() { - store.dispatch(Actions.resizeTimeseriesPlot(node.offsetWidth)); + store.dispatch(Actions.resizeTimeseriesPlot(window.innerWidth, node.offsetWidth)); }; store.dispatch(Actions.retrieveTimeseries(siteno)); }; diff --git a/assets/src/scripts/components/hydrograph/index.spec.js b/assets/src/scripts/components/hydrograph/index.spec.js index ba284f037c5580db918ba67bbe08e3c8d6d1bc3b..19b0533290074db88f73589b99a41aefae64e96d 100644 --- a/assets/src/scripts/components/hydrograph/index.spec.js +++ b/assets/src/scripts/components/hydrograph/index.spec.js @@ -167,6 +167,7 @@ describe('Hydrograph charting module', () => { title: 'My Title', desc: 'My Description', showMedianStatsLabel: false, + windowWidth: 400, width: 400, currentParameterCode: '00060' }); @@ -217,7 +218,7 @@ describe('Hydrograph charting module', () => { }); it('should not have tooltips for the select series table when the screen is large', () => { - store.dispatch(Actions.resizeTimeseriesPlot(800)); + store.dispatch(Actions.resizeUI(800, 800)); expect(selectAll('table .tooltip-table').size()).toBe(0); }); }); diff --git a/assets/src/scripts/components/hydrograph/layout.js b/assets/src/scripts/components/hydrograph/layout.js index 66eac09d74a78f55d393d419ccc1344a81fd9da4..e3a240a714daf20ff8fbe674938498de18e79f6c 100644 --- a/assets/src/scripts/components/hydrograph/layout.js +++ b/assets/src/scripts/components/hydrograph/layout.js @@ -17,20 +17,25 @@ const SPARK_LINE_DIM = { height: 30 } +const SMALL_SCREEN_WIDTH = 481; // size of a small screen as defined in uswds style sheets + /* * @param {Object} state - Redux store * @return {Object} containing width and height properties. */ const layoutSelector = createSelector( (state) => state.width, - (width) => { + (state) => state.windowWidth, + (width, windowWidth) => { return { width: width, - height: width * ASPECT_RATIO + height: width * ASPECT_RATIO, + windowWidth: windowWidth }; } ); -module.exports = {ASPECT_RATIO, ASPECT_RATIO_PERCENT, MARGIN, CIRCLE_RADIUS, layoutSelector, SPARK_LINE_DIM}; +module.exports = {ASPECT_RATIO, ASPECT_RATIO_PERCENT, MARGIN, CIRCLE_RADIUS, layoutSelector, SPARK_LINE_DIM, + SMALL_SCREEN_WIDTH}; diff --git a/assets/src/scripts/components/hydrograph/layout.spec.js b/assets/src/scripts/components/hydrograph/layout.spec.js index 6aea429fcded9c091747e0372db11767b66fd3dc..6e321da0b01896180d1e8a42d788851822fd7035 100644 --- a/assets/src/scripts/components/hydrograph/layout.spec.js +++ b/assets/src/scripts/components/hydrograph/layout.spec.js @@ -3,9 +3,10 @@ const { layoutSelector, ASPECT_RATIO } = require('./layout'); describe('points module', () => { it('Should return the width and height with the predefined ASPECT_RATIO', () => { - let layout = layoutSelector({width: 200}); + let layout = layoutSelector({width: 200, windowWidth: 600}); expect(layout.width).toEqual(200); expect(layout.height).toEqual(200 * ASPECT_RATIO); + expect(layout.windowWidth).toEqual(600); }); }); diff --git a/assets/src/scripts/components/hydrograph/parameters.js b/assets/src/scripts/components/hydrograph/parameters.js index e5179a2e924ad7b686880ce26f67d99d5e50cc20..db054ce3f368fd67990c6f042b8d8c15f3c63460 100644 --- a/assets/src/scripts/components/hydrograph/parameters.js +++ b/assets/src/scripts/components/hydrograph/parameters.js @@ -4,7 +4,7 @@ const { select } = require('d3-selection'); const { Actions } = require('./store'); const { currentDataSelector } = require('./timeseries'); -const { SPARK_LINE_DIM } = require('./layout'); +const { SPARK_LINE_DIM, SMALL_SCREEN_WIDTH } = require('./layout'); const { createXScale, singleSeriesYScale } = require('./scales'); const { dispatch, link } = require('../../lib/redux'); @@ -79,8 +79,7 @@ export const addSparkLine = function(svgSelection, {tsData}) { export const plotSeriesSelectTable = function (elem, {availableTimeseries, layout}) { elem.select('#select-timeseries').remove(); - const smallScreenWidth = 481; // size of a small screen as defined in uswds style sheets - const screenSizeCheck = layout.width <= smallScreenWidth; + const screenSizeCheck = layout.windowWidth <= SMALL_SCREEN_WIDTH; let columnHeaders; if (screenSizeCheck) { diff --git a/assets/src/scripts/components/hydrograph/store.js b/assets/src/scripts/components/hydrograph/store.js index b72eddad4314623b1a06a3f9da68a220f5531960..c12d07bc373b33e8072231fba50a02c47fc62654 100644 --- a/assets/src/scripts/components/hydrograph/store.js +++ b/assets/src/scripts/components/hydrograph/store.js @@ -86,9 +86,10 @@ export const Actions = { compareTime }; }, - resizeTimeseriesPlot(width) { + resizeUI(windowWidth, width) { return { - type: 'RESIZE_TIMESERIES_PLOT', + type: 'RESIZE_UI', + windowWidth, width }; }, @@ -177,9 +178,10 @@ export const timeSeriesReducer = function (state={}, action) { } }; - case 'RESIZE_TIMESERIES_PLOT': + case 'RESIZE_UI': return { ...state, + windowWidth: action.windowWidth, width: action.width }; @@ -216,6 +218,7 @@ export const configureStore = function (initialState) { medianStatistics: false }, currentParameterCode: null, + windowWidth: 1024, width: 800, showMedianStatsLabel: false, tooltipFocusTime: { diff --git a/assets/src/scripts/components/hydrograph/store.spec.js b/assets/src/scripts/components/hydrograph/store.spec.js index f6def64c9048225f145bb029af875eaee8adf7e1..7f87c619c84c355a5d256c60900c9a81ea1c54ac 100644 --- a/assets/src/scripts/components/hydrograph/store.spec.js +++ b/assets/src/scripts/components/hydrograph/store.spec.js @@ -47,8 +47,9 @@ describe('Redux store', () => { }); it('should create an action to resize plot', () => { - expect(Actions.resizeTimeseriesPlot(100)).toEqual({ - type: 'RESIZE_TIMESERIES_PLOT', + expect(Actions.resizeUI(800, 100)).toEqual({ + type: 'RESIZE_UI', + windowWidth: 800, width: 100 }); }); @@ -131,11 +132,13 @@ describe('Redux store', () => { }); }); - it('should handle RESIZE_TIMESERIES_PLOT', () => { + it('should handle RESIZE_UI', () => { expect(timeSeriesReducer({}, { - type: 'RESIZE_TIMESERIES_PLOT', + type: 'RESIZE_UI', + windowWidth: 800, width: 100 })).toEqual({ + windowWidth: 800, width: 100 }); });