33 */
44import React , { PropTypes } from 'react' ;
55
6- import { get , isEmpty , isUndefined , omitBy , defer , set } from 'lodash' ;
6+ import { get , isEmpty , isUndefined , omitBy , defer } from 'lodash' ;
77
88import ColValuesStatistics from './../ColValuesStatistics.js' ;
99import CompleteButton from '../../ui/CompleteButton.jsx' ;
@@ -19,6 +19,7 @@ import {SuggestBoxInputField} from '../../ui/SuggestBoxInputField.jsx';
1919import { FieldGroupCollapsible } from '../../ui/panel/CollapsiblePanel.jsx' ;
2020import { plotParamsShape } from './XYPlot.jsx' ;
2121import { showColSelectPopup , hideColSelectPopup } from './ColSelectView.jsx' ;
22+ import { updateSet } from '../../util/WebUtil.js' ;
2223
2324const DECI_ENABLE_SIZE = 5000 ;
2425
@@ -43,7 +44,7 @@ function parseSuggestboxContent(text) {
4344 if ( text && text . length ) {
4445 // [entireMatch, firstCature, secondCapture] or null
4546 const match = text . match ( / ^ ( .* [ ^ A - Z a - z \d _ ] | ) ( [ A - Z a - z \d _ ] * ) $ / ) ;
46- if ( match && match . length == 3 ) {
47+ if ( match && match . length === 3 ) {
4748 priorContent = match [ 1 ] ;
4849 token = match [ 2 ] ;
4950 }
@@ -159,7 +160,10 @@ export function getColValidator(colValStats) {
159160 * Reducer from field group component,
160161 * clears label, unit, and userSetBoundaries whenever x or y field changes,
161162 * validates min-max-log field relationship
163+ * @param {Object } inFields
164+ * @param {Object } action
162165 * @returns {* } reducer, which clears label and unit whenever x or y field changes
166+ *
163167 */
164168function fldChangeReducer ( inFields , action ) {
165169 if ( ! inFields ) { return { } ; }
@@ -168,19 +172,25 @@ function fldChangeReducer(inFields, action) {
168172 // when field changes, clear the label and unit
169173 fieldKey = get ( action . payload , 'fieldKey' ) ;
170174 if ( fieldKey === 'x.columnOrExpr' ) {
171- set ( inFields , [ 'x.label' , 'value' ] , undefined ) ;
172- set ( inFields , [ 'x.unit' , 'value' ] , undefined ) ;
173- set ( inFields , [ 'xMin' , 'value' ] , undefined ) ;
174- set ( inFields , [ 'xMax' , 'value' ] , undefined ) ;
175+ inFields = updateSet ( inFields , [ 'x.label' , 'value' ] , undefined ) ;
176+ inFields = updateSet ( inFields , [ 'x.unit' , 'value' ] , undefined ) ;
177+ inFields = updateSet ( inFields , [ 'xMin' , 'value' ] , undefined ) ;
178+ inFields = updateSet ( inFields , [ 'xMax' , 'value' ] , undefined ) ;
179+ const currOptions = get ( inFields , [ 'x.options' , 'value' ] ) ;
180+ // do not reset grid selection
181+ inFields = updateSet ( inFields , [ 'x.options' , 'value' ] , getOption ( currOptions , 'grid' ) ) ;
175182 } else if ( fieldKey === 'y.columnOrExpr' ) {
176- set ( inFields , [ 'y.label' , 'value' ] , undefined ) ;
177- set ( inFields , [ 'y.unit' , 'value' ] , undefined ) ;
178- set ( inFields , [ 'yMin' , 'value' ] , undefined ) ;
179- set ( inFields , [ 'yMax' , 'value' ] , undefined ) ;
183+ inFields = updateSet ( inFields , [ 'y.label' , 'value' ] , undefined ) ;
184+ inFields = updateSet ( inFields , [ 'y.unit' , 'value' ] , undefined ) ;
185+ inFields = updateSet ( inFields , [ 'yMin' , 'value' ] , undefined ) ;
186+ inFields = updateSet ( inFields , [ 'yMax' , 'value' ] , undefined ) ;
187+ const currOptions = get ( inFields , [ 'y.options' , 'value' ] ) ;
188+ // do not reset grid selection
189+ inFields = updateSet ( inFields , [ 'y.options' , 'value' ] , getOption ( currOptions , 'grid' ) ) ;
180190 } else if ( fieldKey === 'xyRatio' ) {
181191 if ( get ( inFields , 'nbins.x' ) ) {
182- set ( inFields , [ 'nbins.x' , 'value' ] , undefined ) ;
183- set ( inFields , [ 'nbins.y' , 'value' ] , undefined ) ;
192+ inFields = updateSet ( inFields , [ 'nbins.x' , 'value' ] , undefined ) ;
193+ inFields = updateSet ( inFields , [ 'nbins.y' , 'value' ] , undefined ) ;
184194 }
185195 }
186196 }
@@ -198,13 +208,13 @@ function fldChangeReducer(inFields, action) {
198208 const logVal = Boolean ( options && options . includes ( 'log' ) ) ;
199209 if ( Number . isFinite ( valMin ) ) {
200210 if ( logVal && valMin <= 0 ) {
201- set ( inFields , [ v . min , 'valid' ] , false ) ;
202- set ( inFields , [ v . min , 'message' ] , 'The minimum of a log axis can not be 0 or less' ) ;
211+ inFields = updateSet ( inFields , [ v . min , 'valid' ] , false ) ;
212+ inFields = updateSet ( inFields , [ v . min , 'message' ] , 'The minimum of a log axis can not be 0 or less' ) ;
203213 } else {
204214 const valMax = Number . parseFloat ( get ( inFields , [ v . max , 'value' ] ) ) ;
205215 if ( Number . isFinite ( valMax ) && valMin > valMax ) {
206- set ( inFields , [ fieldKey || v . min , 'valid' ] , false ) ;
207- set ( inFields , [ fieldKey || v . min , 'message' ] , 'Min value greater than max' ) ;
216+ inFields = updateSet ( inFields , [ fieldKey || v . min , 'valid' ] , false ) ;
217+ inFields = updateSet ( inFields , [ fieldKey || v . min , 'message' ] , 'Min value greater than max' ) ;
208218 }
209219 }
210220 }
@@ -218,6 +228,11 @@ function possibleDecimatedTable(colValStats) {
218228 return Boolean ( colValStats . find ( ( el ) => { return el . numpoints > DECI_ENABLE_SIZE ; } ) ) ;
219229}
220230
231+ function getOption ( options , opt ) {
232+ // returns opt if it is included into options
233+ return ( options && ( options . includes ( opt ) || options . includes ( '_all_' ) ) ) ? opt : undefined ;
234+ }
235+
221236
222237export class XYPlotOptions extends React . Component {
223238
0 commit comments