Skip to content

Commit

Permalink
add summary rows from unique values
Browse files Browse the repository at this point in the history
  • Loading branch information
LeosPrograms committed May 14, 2024
1 parent 3be5e57 commit 5716035
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
3 changes: 2 additions & 1 deletion ui/src/CellEdit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
slTypes[ColumnType.Email] = "email"
slTypes[ColumnType.Date] = "date"
slTypes[ColumnType.URL] = "text"
slTypes[ColumnType.Currency] = "currency"
let value
</script>
Expand Down Expand Up @@ -115,7 +116,7 @@
}}
type={slTypes[type]}
style="width:{width}px"
value={value}
value={value}
on:sl-input={(e)=>{
value = e.target.value
}}
Expand Down
13 changes: 2 additions & 11 deletions ui/src/Queries.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,17 @@ const queryStore = writable(initialQuery);
function changeQuery(newQuery) {
currentQuery[activeHashB64] = newQuery
console.log("new query", newQuery)
queriedData[activeHashB64] = []
$state.rows.forEach((row) => {
if (newQuery.length === 0) {
queriedData[activeHashB64].push(row.id)
} else {
console.log("jjk")
// for key and value in row.cells
let subbedQuery = newQuery
// console.log("subbedQuery", subbedQuery)
Object.keys(row.cells).forEach((cellId) => {
console.log("cellId", cellId)
let value: any = '"' + row.cells[cellId]?.value + '"'
console.log($state.columnDefs.find((col) => col.id === cellId)?.type)
if ($state.columnDefs.find((col) => col.id === cellId)?.type === 1) {
const tempValue = parseInt(row.cells[cellId]?.value)
if (!isNaN(tempValue)) {
Expand All @@ -62,18 +56,15 @@ function changeQuery(newQuery) {
}
subbedQuery = subbedQuery.replace(new RegExp(cellId, 'g'), value);
console.log("subbedQuery", subbedQuery, value, cellId)
subbedQuery = subbedQuery.replace(new RegExp('contains', 'g'), 'includes');
})
console.log("subbedQuery", subbedQuery)
if (eval(subbedQuery)) {
// console.log("subbedQuery", subbedQuery)
if (subbedQuery && eval(subbedQuery)) {
queriedData[activeHashB64].push(row.id)
}
}
})
console.log("queried data", queriedData[activeHashB64])
}
// Function to handle query changes
Expand Down
18 changes: 9 additions & 9 deletions ui/src/SummaryRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
{@const sum = Object.values(querriedData).reduce((acc, row) => {
const cell = row.cells[def.id];
if (cell && cell.value) {
return acc + Number(cell.value);
return acc + Number(cell.value.replace(/[^0-9-.]/g, ''));
}
return acc;
}, 0)}
Expand All @@ -76,7 +76,7 @@
{@const sum = Object.values(querriedData).reduce((acc, row) => {
const cell = row.cells[def.id];
if (cell && cell.value) {
return acc + Number(cell.value);
return acc + Number(cell.value.replace(/[^0-9-.]/g, ''));
}
return acc;
}, 0)}
Expand All @@ -94,7 +94,7 @@
}
} else {
console.log(Math.max(acc, Number(cell.value)))
return Math.max(acc, Number(cell.value));
return Math.max(acc, Number(cell.value.replace(/[^0-9-.]/g, '')));
}
}
return acc;
Expand All @@ -114,7 +114,7 @@
return Math.min(acc, dateNumber);
}
}
return Math.min(acc, Number(cell.value));
return Math.min(acc, Number(cell.value.replace(/[^0-9-.]/g, '')));
}
return acc;
},
Expand All @@ -126,7 +126,7 @@
{@const values = Object.values(querriedData).map(row => {
const cell = row.cells[def.id];
if (cell && cell.value) {
return Number(cell.value);
return Number(cell.value.replace(/[^0-9-.]/g, ''));
}
}).sort((a, b) => a - b).filter(value => value !== undefined)}

Expand All @@ -135,7 +135,7 @@
{@const values = Object.values(querriedData).map(row => {
const cell = row.cells[def.id];
if (cell && cell.value) {
return Number(cell.value);
return Number(cell.value.replace(/[^0-9-.]/g, ''));
}
}).filter(value => value !== undefined)}
{@const counts = values.reduce((acc, value) => {
Expand All @@ -152,15 +152,15 @@
{@const values = Object.values(querriedData).map(row => {
const cell = row.cells[def.id];
if (cell && cell.value) {
return Number(cell.value);
return Number(cell.value.replace(/[^0-9-.]/g, ''));
}
}).sort((a, b) => a - b).filter(value => value !== undefined)}
{values[values.length - 1] - values[0]}
{:else if sumType == SumType.StDeviation}
{@const values = Object.values(querriedData).map(row => {
const cell = row.cells[def.id];
if (cell && cell.value) {
return Number(cell.value);
return Number(cell.value.replace(/[^0-9-.]/g, ''));
}
}).filter(value => value !== undefined)}
{@const mean = values.reduce((acc, value) => acc + value, 0) / values.length}
Expand All @@ -184,7 +184,7 @@
{#if !embedded}
<div style="float: right; color: #baa480; margin: 2px;">
{SumType[sumType]}
{#if def.type == ColumnType.Number}
{#if def.type == ColumnType.Number || def.type == ColumnType.Currency}
<select
style="width: 15px;"
bind:value={sumType}
Expand Down
36 changes: 36 additions & 0 deletions ui/src/TablePane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
$: showEditHeader = false;
$: editHeaderIndex = null;
$: dataView = false;
$: addUniqueSummaryFromColumn = null;
function setFilterOption(newOption) {
filterOption = newOption;
Expand Down Expand Up @@ -542,6 +543,41 @@
<h3>{query.label}</h3>
</div>
{/each}
<!-- allow adding a new summary row for each label from a label row -->
Summary by unique value:
<select
on:change={(e)=>{
addUniqueSummaryFromColumn = e.target.value
}}
>
<option></option>
{#each $state.columnDefs as def}
<option value={def.id}>{def.name}</option>
{/each}
</select>
{#if addUniqueSummaryFromColumn}
{@const columnValues = $state.rows.map(row=>row.cells[addUniqueSummaryFromColumn]?.value)}
{#each Array.from(new Set(columnValues)) as value}
<div class="modal-body" style="display:flex; margin: 10px 0">
<button
class="add-summary-row-button"
on:click={()=>{
// add summary row to board
let summaryDefs = {}
$state.columnDefs.forEach(def=> {
// if (def.type) {
// summaryDefs[def.id] = def.type
// }
summaryDefs[def.id] = 0
})
activeBoard.requestChanges([{ type: "add-summary-row", summaryRow: {id: uuidv1(), query: `${addUniqueSummaryFromColumn} == ${JSON.stringify(value)}`, queryLabel: `${value}`, summaryDefs: summaryDefs}}]);
}}>
<SvgIcon icon=faPlus size=10 style="height:20px;"/>
</button>&nbsp;
<h3>{$state.columnDefs.find(def=>def.id == addUniqueSummaryFromColumn).name} = {value}</h3>
</div>
{/each}
{/if}
<!-- <button on:click={()=>{newSummaryRowModal = false}}>Done</button> -->
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions ui/src/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum ColumnType {
String,
Number,
Date,
Currency,
Email,
URL,
Label,
Expand Down

0 comments on commit 5716035

Please sign in to comment.