Skip to content

Commit

Permalink
Merge pull request #20 from Kitware/fix-proxy-property-handling
Browse files Browse the repository at this point in the history
Fix proxy property handling
  • Loading branch information
jourdain committed Feb 25, 2016
2 parents 74cfdd0 + 64f27df commit d831920
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 26 deletions.
26 changes: 13 additions & 13 deletions dist/ParaViewWeb.js

Large diffs are not rendered by default.

30 changes: 28 additions & 2 deletions src/Common/Misc/ConvertProxyProperty/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function extractLayout(ui) {
return ui.size.toString();
}

if(ui.widget === 'list-1') {
return '1';
}

if(ui.size === 6) {
if(ui.name.toLowerCase().indexOf('bound')) {
return '3x2';
Expand All @@ -25,6 +29,13 @@ function extractLayout(ui) {
return 'NO_LAYOUT';
}

function extractType(ui) {
if(ui.type === 'proxy') {
return 'string';
}
return ui.type;
}

function extractDomain(ui) {
if(ui.values) {
if(Array.isArray(ui.values)) {
Expand All @@ -34,11 +45,18 @@ function extractDomain(ui) {
});
return domain;
}
if(ui.type === 'proxy') {
const domain = {};
for(const key in ui.values) {
domain[key] = key;
}
return domain;
}
return ui.values;
}

if(ui.range) {
console.log('FIXME: build domain using range');
return { range: ui.range };
}

return {};
Expand All @@ -50,10 +68,17 @@ export function proxyPropToProp(property, ui) {
console.log('No propType for', ui);
}

const depList = ui.depends ? ui.depends.split(':') : null;
const depStatus = depList ? Boolean(Number(depList.pop())) : true;
const depValue = depList ? depList.pop() : null;
const depId = depList ? depList.join(':') : null;
const searchString = [ ui.name, ui.doc ].concat(property.value).join(' ').toLowerCase();

return {
show(ctx) {
if(depId && ctx.properties[depId] !== undefined) {
return (ctx.properties[depId][0] === depValue) ? depStatus : !depStatus;
}
if(ctx.filter && ctx.filter.length) {
const queries = ctx.filter.toLowerCase().split(' ');
let match = true;
Expand All @@ -72,14 +97,15 @@ export function proxyPropToProp(property, ui) {
help: ui.doc,
noEmpty: true,
layout: extractLayout(ui),
type: ui.type,
type: extractType(ui),
domain: extractDomain(ui),
componentLabels: [],
size: ui.size,
},
data: {
id: [property.id, property.name].join(':'),
value: [].concat(property.value),
size: ui.size,
},
}
}
Expand Down
19 changes: 10 additions & 9 deletions src/React/Properties/CellProperty/InputCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,21 @@ export default React.createClass({

if (validate[this.props.type](newVal)) {
let propVal = convert[this.props.type](newVal);
if (this.props.type === 'integer' || this.props.type === 'int' ||
this.props.type === 'double' || this.props.type === 'dbl') {
propVal = this.clamp(propVal);
}
propVal = this.applyDomains(this.props.idx, propVal);
this.props.onChange(this.props.idx, propVal);
}
},

clamp(val) {
if (this.props.domain.hasOwnProperty('min')) {
val = Math.max(this.props.domain.min, val);
applyDomains(idx, val) {
if(!this.props.domain) {
return val;
}
if (this.props.domain.hasOwnProperty('max')) {
val = Math.min(this.props.domain.max, val);

// Handle range
if (this.props.domain.hasOwnProperty('range')) {
const { min, max } = this.props.domain.range[idx];
val = (min !== undefined) ? Math.max(min, val) : val;
val = (max !== undefined) ? Math.min(max, val) : val;
}
return val;
},
Expand Down
8 changes: 6 additions & 2 deletions src/React/Widgets/ProxyPropertyGroupWidget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ export default React.createClass({

valueChange(change) {
const changeSet = this.state.changeSet;
changeSet[change.id] = change.value;
changeSet[change.id] = (change.size === 1 && Array.isArray(change.value)) ? change.value[0] : change.value;
this.setState({changeSet});
if(this.props.onChange) {
this.props.onChange(changeSet);
}
},

render() {
const ctx = { advanced: this.props.advanced, filter: this.props.filter };
const properties = {};
const ctx = { advanced: this.props.advanced, filter: this.props.filter, properties };
const changeSetCount = Object.keys(this.state.changeSet).length;
this.state.properties.forEach(p => {
properties[p.data.id] = p.data.value;
});

return (
<div className={ style.container }>
Expand Down

0 comments on commit d831920

Please sign in to comment.