Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rule based styling cell colouring feature #938

Closed
Show file tree
Hide file tree
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
rule based styling cell colouring feature
  • Loading branch information
LiamEdwardsLamarche committed Aug 8, 2024
commit 97b743ffa4ba81b660a3838ed9d44b88f0fc8f98
11 changes: 10 additions & 1 deletion src/chart/table/TableChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DataGrid, GridColumnVisibilityModel } from '@mui/x-data-grid';
import { ChartProps } from '../Chart';
import {
evaluateRulesOnDict,
evaluateSingleRuleOnDict,
generateClassDefinitionsBasedOnRules,
useStyleRules,
} from '../../extensions/styling/StyleRuleEvaluator';
Expand Down Expand Up @@ -253,7 +254,15 @@ export const NeoTableChart = (props: ChartProps) => {
getCellClassName: (params) => {
return ['cell color', 'cell text color']
.map((e) => {
return `rule${evaluateRulesOnDict({ [params.field]: params.value }, styleRules, [e])}`;
for (const [index, rule] of styleRules.entries()) {
if (rule.targetField) {
if (rule.targetField === params.field) {
return `rule${evaluateSingleRuleOnDict({ [rule.field]: params.row[rule.field] }, rule, index, [e])}`;
}
} else {
return `rule${evaluateSingleRuleOnDict({ [params.field]: params.value }, rule, index, [e])}`;
}
}
})
.join(' ');
},
Expand Down
29 changes: 29 additions & 0 deletions src/extensions/styling/StyleRuleCreationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,35 @@ export const NeoCustomReportStyleModal = ({
}}
fluid
/>
<Autocomplete
className='n-align-middle n-inline-block n-w-5/12 n-pr-1'
disableClearable={true}
id={`autocomplete-label-type${index}`}
size='small'
noOptionsText='*Specify an exact field name'
options={createFieldVariableSuggestions().filter((e) =>
e.toLowerCase().includes(rule.targetField)
)}
value={rule.targetField ? rule.targetField : (rule.field ? rule.field : '')}
inputValue={rule.targetField ? rule.targetField : (rule.field ? rule.field : '')}
popupIcon={<></>}
style={{ minWidth: 125, visibility: rule.customization.includes("cell") ? 'visible' : 'hidden', display: rule.customization.includes("cell") ? '' : 'none' }}
onInputChange={(event, value) => {
updateRuleField(index, 'targetField', value);
}}
onChange={(event, newValue) => {
updateRuleField(index, 'targetField', newValue);
}}
renderInput={(params) => (
<TextField
{...params}
placeholder='Target field name...'
InputLabelProps={{ shrink: true }}
style={{ padding: '6px 0 7px' }}
size={'small'}
/>
)}
/>
<TextInput
className='n-align-middle n-inline-block n-w-1/12 n-pr-1'
style={{ minWidth: 30 }}
Expand Down
24 changes: 14 additions & 10 deletions src/extensions/styling/StyleRuleEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,25 @@ export const evaluateRulesOnDict = (dict, rules, customizations) => {
}
for (const [index, rule] of rules.entries()) {
// Only check customizations that are specified
if (customizations.includes(rule.customization)) {
// if the row contains the specified field...
if (dict[rule.field] !== undefined && dict[rule.field] !== null) {
const realValue = dict[rule.field].low ? dict[rule.field].low : dict[rule.field];
const ruleValue = rule.value;
if (evaluateCondition(realValue, rule.condition, ruleValue)) {
return index;
}
}
}
return evaluateSingleRuleOnDict(dict, rule, index, customizations);
}
// If no rules are met, return not found (index=-1)
return -1;
};

export const evaluateSingleRuleOnDict = (dict, rule, ruleIndex, customizations) => {
if (customizations.includes(rule.customization)) {
// if the row contains the specified field...
if (dict[rule.field] !== undefined && dict[rule.field] !== null) {
const realValue = dict[rule.field].low ? dict[rule.field].low : dict[rule.field];
const ruleValue = rule.value;
if (evaluateCondition(realValue, rule.condition, ruleValue)) {
return ruleIndex;
}
}
}
}

/**
* Evaluates the specified rule set on a node object returned by the Neo4j driver.
* @param node - the node representation returned by the Neo4j driver.
Expand Down
Loading