Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/extensions/styling/StyleRuleEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const evaluateRulesOnDict = (dict, rules, customizations) => {
}
for (const [index, rule] of rules.entries()) {
// Only check customizations that are specified
return evaluateSingleRuleOnDict (dict, rule, index, customizations)
return evaluateSingleRuleOnDict(dict, rule, index, customizations);
}
// If no rules are met, return not found (index=-1)
return -1;
Expand All @@ -81,8 +81,7 @@ export const evaluateSingleRuleOnDict = (dict, rule, ruleIndex, customizations)
}
}
return -1;
}

};

/**
* Evaluates the specified rule set on a node object returned by the Neo4j driver.
Expand Down Expand Up @@ -127,6 +126,20 @@ export const evaluateRules = (entity, customization, defaultValue, rules, entity
return defaultValue;
};

/**
* @param realValue the value found in the real data returned by the query
* @param ruleValue the value specified in the rule.
* @returns whether the condition is met.
*/
const isLooselyEqual = (realValue, ruleValue) => {
// In order to avoid having '5' <> {low: 5, high: 0} OR '5' <> 5
const sensitiveTypes = ['string', 'number', 'object'];
if (sensitiveTypes.includes(typeof realValue) && sensitiveTypes.includes(typeof ruleValue)) {
return realValue == ruleValue;
}
return realValue === ruleValue;
};

/**
* @param realValue the value found in the real data returned by the query
* @param condition the condition, one of [=,!=,<,<=,>,>=,contains].
Expand All @@ -139,10 +152,10 @@ const evaluateCondition = (realValue, condition, ruleValue) => {
return false;
}
if (condition == '=') {
return realValue === ruleValue;
return isLooselyEqual(realValue, ruleValue);
}
if (condition == '!=') {
return realValue !== ruleValue;
return !isLooselyEqual(realValue, ruleValue);
}
if (!isNaN(Number(ruleValue))) {
ruleValue = Number(ruleValue);
Expand Down
Loading