Skip to content
Snippets Groups Projects
Commit c3ae507e authored by Williams, Darius Shamar's avatar Williams, Darius Shamar
Browse files

Cleaning up code, adding comments

parent ad832837
No related branches found
No related tags found
1 merge request!421Wdfn 768 - Convert the legend component to vue
<template>
<div class="graph-controls-container">
<GraphControls />
</div>
</template>
<script>
import GraphControls from './vue-components/graph-controls.vue';
export default {
name: 'GraphControlsApp',
components: {
GraphControls
}
};
</script>
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<script> <script>
import GraphBrush from './vue-components/graph-brush.vue'; import GraphBrush from './vue-components/graph-brush.vue';
import CursorSlider from './vue-components/cursor-slider.vue'; import CursorSlider from './vue-components/cursor-slider.vue';
import HydrographLegend from './vue-components/legend.vue'; import HydrographLegend from './vue-components/hydrograph-legend.vue';
import GraphControls from './vue-components/graph-controls.vue'; import GraphControls from './vue-components/graph-controls.vue';
import {useState} from 'redux-connect-vue'; import {useState} from 'redux-connect-vue';
......
import {mount} from '@vue/test-utils'; import {mount} from '@vue/test-utils';
import {bindActionCreators} from 'redux';
import ReduxConnectVue from 'redux-connect-vue';
import {createStructuredSelector} from 'reselect';
import config from 'ui/config'; import config from 'ui/config';
import * as utils from 'ui/utils'; import * as utils from 'ui/utils';
import {format} from 'd3-format';
import {configureStore} from 'ml/store'; import {configureStore} from 'ml/store';
import {TEST_PRIMARY_IV_DATA, TEST_GW_LEVELS} from '../mock-hydrograph-state'; import {TEST_PRIMARY_IV_DATA, TEST_GW_LEVELS} from '../mock-hydrograph-state';
import HydrographLegend from './legend.vue'; import HydrographLegend from './hydrograph-legend.vue';
import {getMainLayout} from '../selectors/layout';
import {getLegendMarkerRows} from '../selectors/legend-data'; import {getLegendMarkerRows} from '../selectors/legend-data';
import {getLegendMarkers as getDVLegendMarkerRows} from '../../daily-value-hydrograph/selectors/legend-data'; import {getLegendMarkers as getDVLegendMarkerRows} from '../../daily-value-hydrograph/selectors/legend-data';
...@@ -124,21 +119,19 @@ describe('monitoring-location/components/hydrograph/legend module', () => { ...@@ -124,21 +119,19 @@ describe('monitoring-location/components/hydrograph/legend module', () => {
store = configureStore(TEST_STATE); store = configureStore(TEST_STATE);
wrapper = mount(HydrographLegend, { wrapper = mount(HydrographLegend, {
global: {
plugins: [
[ReduxConnectVue, {
store,
mapDispatchToPropsFactory: (actionCreators) => (dispatch) => bindActionCreators(actionCreators, dispatch),
mapStateToPropsFactory: createStructuredSelector
}]
]
},
props: { props: {
legendMarkerRows: getLegendMarkerRows(TEST_STATE), legendMarkerRows: getLegendMarkerRows(TEST_STATE),
layout: getMainLayout.resultFunc(200, 600, { layout: {
tickValues: [5, 10, 15], "width": 992,
tickFormat: format('d') "height": 496,
}) "windowWidth": 1041,
"margin": {
"bottom": 5,
"top": 25,
"left": 55,
"right": 25
}
}
} }
}); });
}); });
...@@ -149,21 +142,19 @@ describe('monitoring-location/components/hydrograph/legend module', () => { ...@@ -149,21 +142,19 @@ describe('monitoring-location/components/hydrograph/legend module', () => {
it('Should have the correct number of legend markers when working for the DV graph', async() => { it('Should have the correct number of legend markers when working for the DV graph', async() => {
wrapper = mount(HydrographLegend, { wrapper = mount(HydrographLegend, {
global: {
plugins: [
[ReduxConnectVue, {
store: configureStore(DV_TEST_STATE),
mapDispatchToPropsFactory: (actionCreators) => (dispatch) => bindActionCreators(actionCreators, dispatch),
mapStateToPropsFactory: createStructuredSelector
}]
]
},
props: { props: {
legendMarkerRows: getDVLegendMarkerRows(DV_TEST_STATE), legendMarkerRows: getDVLegendMarkerRows(DV_TEST_STATE),
layout: getMainLayout.resultFunc(200, 600, { layout: {
tickValues: [5, 10, 15], "width": 992,
tickFormat: format('d') "height": 496,
}) "windowWidth": 1041,
"margin": {
"bottom": 5,
"top": 25,
"left": 55,
"right": 25
}
}
} }
}); });
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
...@@ -172,15 +163,6 @@ describe('monitoring-location/components/hydrograph/legend module', () => { ...@@ -172,15 +163,6 @@ describe('monitoring-location/components/hydrograph/legend module', () => {
it('If no markers are provided legend-svg will contain no groups', async() => { it('If no markers are provided legend-svg will contain no groups', async() => {
wrapper = mount(HydrographLegend, { wrapper = mount(HydrographLegend, {
global: {
plugins: [
[ReduxConnectVue, {
store,
mapDispatchToPropsFactory: (actionCreators) => (dispatch) => bindActionCreators(actionCreators, dispatch),
mapStateToPropsFactory: createStructuredSelector
}]
]
},
props: { props: {
legendMarkerRows: [], legendMarkerRows: [],
layout: {} layout: {}
......
...@@ -24,6 +24,10 @@ import {select} from 'd3-selection'; ...@@ -24,6 +24,10 @@ import {select} from 'd3-selection';
import {mediaQuery} from 'ui/utils'; import {mediaQuery} from 'ui/utils';
import config from 'ui/config'; import config from 'ui/config';
/*
* @vue-prop {Array of Arrays} legendMarkerRows - array of rows to be displayed. Each array contains objects with the text to be displayed.
* @vue-prop {Object} layout - Object with the properties: height, margin (object with bottom, top, left, and right), width, and window width
*/
export default { export default {
name: 'HydrographLegend', name: 'HydrographLegend',
props: { props: {
...@@ -65,15 +69,8 @@ export default { ...@@ -65,15 +69,8 @@ export default {
let lastMarker; let lastMarker;
const getNewXPosition = function(markerGroup, lastXPosition) { const getNewXPosition = function(markerGroup, lastXPosition) {
// Long story short, firefox is unable to get the bounding box if //This try/catch allows unit tests to run. The JSDOM browser
// the svg element isn't actually taking up space and visible. Folks on the //can throw an error when calling getBBox
// internet seem to have gotten around this by setting `visibility:hidden`
// to hide things, but that would still mean the elements will take up space.
// which we don't want. So, here's some error handling for getBBox failures.
// This handling ends up not creating the legend, but that's okay because the
// graph is being shown anyway. A more detailed discussion of this can be found at:
// https://bugzilla.mozilla.org/show_bug.cgi?id=612118 and
// https://stackoverflow.com/questions/28282295/getbbox-of-svg-when-hidden.
try { try {
const markerGroupBBox = markerGroup.node().getBBox(); const markerGroupBBox = markerGroup.node().getBBox();
return markerGroupBBox.x + markerGroupBBox.width + MARKER_GROUP_X_OFFSET; return markerGroupBBox.x + markerGroupBBox.width + MARKER_GROUP_X_OFFSET;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment