Skip to content

Commit

Permalink
Add select modifier to select columns/rows of a table
Browse files Browse the repository at this point in the history
  • Loading branch information
phibr0 committed Mar 26, 2022
1 parent 633d386 commit 771e33b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docusaurus/docs/Chart from Table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
beginAtZero: true
```
````
4. Choose the column or row oriented layout using the `layout` key. Options are `rows` or `columns`.
4. Choose the column or row oriented layout using the `layout` attribute. Options are `rows` or `columns`.
5. (Optional) Select the Columns or Rows with the `select` attribute. E.g. to only show Row `Data2` add `select: [Data2]`

## Replace Table with Chart

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-charts",
"name": "Obsidian Charts",
"version": "3.4.6",
"version": "3.4.7",
"minAppVersion": "0.12.7",
"description": "This Plugin lets you create Charts within Obsidian",
"author": "phibr0",
Expand Down
11 changes: 10 additions & 1 deletion src/chartFromTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ beginAtZero: true
editor.replaceSelection(chart);
}

export function generateTableData(table: string, layout: 'columns' | 'rows') {
export function generateTableData(table: string, layout: 'columns' | 'rows', selected?: string[]) {
let fields: any;
try {
fields = Extractor.extractObject(table, layout, false);
Expand All @@ -33,5 +33,14 @@ export function generateTableData(table: string, layout: 'columns' | 'rows') {
data: Object.values(fields[key]) as string[]
}
});

if(selected) {
dataFields.filter((v) => {
if(!selected.contains(v.dataTitle)) {
dataFields.remove(v)
}
});
}

return {labels, dataFields};
}
2 changes: 1 addition & 1 deletion src/chartRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class ChartRenderChild extends MarkdownRenderChild {
const tableString = (await this.renderer.plugin.app.vault.cachedRead(this.data.file ? linkDest : this.renderer.plugin.app.vault.getAbstractFileByPath(this.ownPath) as TFile)).substring(pos.start.offset, pos.end.offset);
let tableData;
try {
tableData = generateTableData(tableString, this.data.layout ?? 'columns');
tableData = generateTableData(tableString, this.data.layout ?? 'columns', this.data.select);
} catch (error) {
throw "There is no table at that id and/or file"
}
Expand Down

0 comments on commit 771e33b

Please sign in to comment.