-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Group by string value in StringColumn (V4) (#218)
Group by string value in StringColumn (V4)
- Loading branch information
Showing
4 changed files
with
136 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title>LineUp String Grouping Test</title> | ||
|
||
<link href="./LineUpJS.css" rel="stylesheet"> | ||
<link href="./demo.css" rel="stylesheet"> | ||
</head> | ||
|
||
<body> | ||
<script src="https://d3js.org/d3.v4.min.js"></script> | ||
<script src="./LineUpJS.js"></script> | ||
|
||
<script> | ||
window.onload = function () { | ||
const arr = []; | ||
for (let i = 0; i < 5000; ++i) { | ||
arr.push({ | ||
group: Math.floor(Math.random() * 2000).toString() | ||
}); | ||
} | ||
const builder = LineUpJS.builder(arr); | ||
builder | ||
.column(LineUpJS.buildStringColumn('group')); | ||
// and two rankings | ||
const ranking = LineUpJS.buildRanking() | ||
.supportTypes() | ||
.allColumns(); // add all columns | ||
builder | ||
.ranking(ranking); | ||
builder.buildTaggle(document.body); | ||
}; | ||
</script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,65 @@ | ||
import {IDialogContext} from './ADialog'; | ||
import {StringColumn} from '../../model'; | ||
import {cssClass} from '../../styles'; | ||
|
||
import {StringColumn, EStringGroupCriteriaType} from '../../model'; | ||
import {cssClass} from '../../styles/index'; | ||
|
||
/** @internal */ | ||
export default function append(col: StringColumn, node: HTMLElement, dialog: IDialogContext) { | ||
const current = col.getGroupCriteria(); | ||
const isRegex = current.length > 0 && current[0] instanceof RegExp; | ||
const {type, values} = current; | ||
|
||
node.insertAdjacentHTML('beforeend', ` | ||
<label class="${cssClass('checkbox')}"> | ||
<input type="radio" name="regex" value="startsWith" id="${dialog.idPrefix}RW" ${!isRegex ? 'checked' : ''}> | ||
<input type="radio" name="${dialog.idPrefix}groupString" value="${EStringGroupCriteriaType.value}" id="${dialog.idPrefix}VAL" ${type === EStringGroupCriteriaType.value ? 'checked' : ''}> | ||
<span>Use text value</span> | ||
</label> | ||
<label class="${cssClass('checkbox')}"> | ||
<input type="radio" name="${dialog.idPrefix}groupString" value="${EStringGroupCriteriaType.startsWith}" id="${dialog.idPrefix}RW" ${type === EStringGroupCriteriaType.startsWith ? 'checked' : ''}> | ||
<span>Text starts with …</span> | ||
</label> | ||
<label class="${cssClass('checkbox')}"> | ||
<input type="radio" name="regex" value="regex" id="${dialog.idPrefix}RE" ${isRegex ? 'checked' : ''}> | ||
<input type="radio" name="${dialog.idPrefix}groupString" value="${EStringGroupCriteriaType.regex}" id="${dialog.idPrefix}RE" ${type === EStringGroupCriteriaType.regex ? 'checked' : ''}> | ||
<span>Use regular expressions</span> | ||
</label> | ||
<textarea class="${cssClass('textarea')}" required rows="5" placeholder="e.g. Test,a.*" id="${dialog.idPrefix}T">${current.map((d) => typeof d === 'string' ? d : d.source).join('\n')}</textarea> | ||
<button class="${cssClass('dialog-button')}" id="${dialog.idPrefix}A">Apply</button> | ||
<textarea required rows="5" placeholder="e.g. Test,a.*" id="${dialog.idPrefix}T">${values.map((value) => value instanceof RegExp ? value.source : value).join('\n')}</textarea> | ||
<button id="${dialog.idPrefix}A">Apply</button> | ||
`); | ||
|
||
const button = node.querySelector<HTMLButtonElement>(`#${dialog.idPrefix}A`)!; | ||
const isRegexCheck = node.querySelector<HTMLInputElement>(`#${dialog.idPrefix}RE`)!; | ||
const groups = node.querySelector<HTMLTextAreaElement>(`#${dialog.idPrefix}T`)!; | ||
const valueRadioButton = node.querySelector<HTMLInputElement>(`#${dialog.idPrefix}VAL`)!; | ||
const startsWithRadioButton = node.querySelector<HTMLInputElement>(`#${dialog.idPrefix}RW`)!; | ||
const regexRadioButton = node.querySelector<HTMLInputElement>(`#${dialog.idPrefix}RE`)!; | ||
const text = node.querySelector<HTMLTextAreaElement>(`#${dialog.idPrefix}T`)!; | ||
|
||
const showOrHideTextarea = (show: boolean) => { | ||
text.style.display = show ? null : 'none'; | ||
}; | ||
|
||
showOrHideTextarea(type !== EStringGroupCriteriaType.value); | ||
valueRadioButton.onchange = () => showOrHideTextarea(!valueRadioButton.checked); | ||
startsWithRadioButton.onchange = () => showOrHideTextarea(startsWithRadioButton.checked); | ||
regexRadioButton.onchange = () => showOrHideTextarea(regexRadioButton.checked); | ||
|
||
button.onclick = (evt) => { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
const checkedNode = node.querySelector<HTMLInputElement>(`input[name="${dialog.idPrefix}groupString"]:checked`)!; | ||
const newType = <EStringGroupCriteriaType>checkedNode.value; | ||
let items: (string | RegExp)[] = text.value.trim().split('\n').map((d) => d.trim()).filter((d) => d.length > 0); | ||
|
||
let items: (string | RegExp)[] = groups.value.trim().split('\n').map((d) => d.trim()).filter((d) => d.length > 0); | ||
const invalid = items.length === 0; | ||
groups.setCustomValidity(invalid ? 'At least one group is required' : ''); | ||
if (invalid) { | ||
(<any>groups).reportValidity(); // typedoc not uptodate | ||
return; | ||
if (newType !== EStringGroupCriteriaType.value) { | ||
const invalid = items.length === 0; | ||
text.setCustomValidity(invalid ? 'At least one entry is required' : ''); | ||
if (invalid) { | ||
(<any>text).reportValidity(); // typedoc not uptodate | ||
return; | ||
} | ||
} | ||
if (isRegexCheck.checked) { | ||
if (newType === EStringGroupCriteriaType.regex) { | ||
items = items.map((d) => new RegExp(d.toString(), 'gm')); | ||
} | ||
col.setGroupCriteria(items); | ||
col.setGroupCriteria({ | ||
type: newType, | ||
values: items | ||
}); | ||
}; | ||
} |