Skip to content

Commit

Permalink
~ improved documentation(references #4)
Browse files Browse the repository at this point in the history
~ improved error handling(references #4)
  • Loading branch information
joethei committed Feb 22, 2022
1 parent 8839cec commit df29055
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 22 deletions.
103 changes: 98 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,60 @@ You can configure your cloud using a [YAML](https://learnxinyminutes.com/docs/ya

Displays all tags that fit your selection.

### Examples

#### Show all tags in the entire vault

~~~markdown
```tagcloud
```
~~~

#### Show all tags in the current file

~~~markdown
```tagcloud
source: file
```
~~~

#### Show all tags from a folder/file.
> ⚠️ Requires Dataview
~~~markdown
```tagcloud
source: query
query: Folder/File
```
~~~

#### Show all tags that show up together with our tag.
> ⚠️ Requires Dataview
~~~markdown
```tagcloud
source: query
query: '#yourTag'
```
~~~

#### Show all tags from notes that link to note.
> ⚠️ Requires Dataview
~~~markdown
```tagcloud
source: query
query: '[[Other note]]'
```
~~~


### Options

| **Name** | **Description** | **Possible Values** |
|----------|----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
| query | Requires [Dataview](https://github.com/blacksmithgu/obsidian-dataview), requires `source` to be set to `query` | A valid [Dataview Source](https://blacksmithgu.github.io/obsidian-dataview/query/sources/) |
All other options from [here](#general-options) still apply

## Word Cloud

Expand All @@ -33,15 +82,33 @@ Displays all tags that fit your selection.
a wordcloud displays all words in your vault/note.


> ⚠ Word distribution will only be calculated when loading a vault and by running the `Recalculate Word Distribution` command.
>
> This is because the calculation is computationally expensive and takes some time.[^performance]
### Examples

#### Show all words in the entire vault

~~~markdown
```wordcloud
```
~~~

#### Show all words in the current file

~~~markdown
```wordcloud
source: file
```
~~~

### Options

| **Name** | **Description** | **Possible Values** | **Default** |
|-----------|-----------------------------------------------------------------------------------------------------------------|---------------------|-------------|
| stopwords | Remove all [stopwords](https://www.opinosis-analytics.com/knowledge-base/stop-words-explained/) from the result | `true`/ `false` | `true` |

> ⚠ Word distribution will only be calculated when loading a vault and by running the `Recalculate Word Distribution` command.
>
> This is because the calculation is computationally expensive and takes some time.[^performance]
All other options from [here](#general-options) still apply

## Link Cloud
![](https://i.joethei.space/Obsidian_438TsZQC1w.png)
Expand All @@ -50,11 +117,37 @@ A link cloud displays all links in your vault.

This cloud can only be generated vault wide.

### Examples

#### Show all links

~~~markdown
```linkcloud
```
~~~

#### Show all links to existing files

~~~markdown
```linkcloud
type: resolved
```
~~~

#### Show all links to non-existing files

~~~markdown
```linkcloud
type: unresolved
```
~~~

### Options

| **Name** | **Description** | **Possible Values** | **Default** |
|----------|-----------------------------|----------------------------------|-------------|
| type | Which type of links to show | `resolved`, `unresolved`, `both` | `resolved` |
The following options also apply.


## General Options
Expand All @@ -67,7 +160,7 @@ The following options are supported for all clouds.
| weight | factor by wich the size of a word is multiplied | any positive integer | `2` |
| shrinkToFit | Adjust word weight to make it fit | `true`/`false` | `true` |
| minCount | Minumum number of occurances | any positive integer | `0` |
| maxDepth | Only show the X most used elements(if two elements have the same number of occurrences only one will be counted) | any positive integer (increasing this number may result in the cloud not showing, as only so many elements can be rendered) | `50` |
| maxDepth | Only show the X most used elements(if two elements have the same number of occurrences only one will be counted) | any positive integer (increasing this number may result in the cloud not showing, as only so many elements can be rendered) | `25` |
| background | Background color | a hexadecimal RGB value | background color from the chosen theme |
| width | Width of canvas | in pixels (the `px` is omitted) | line width |
| height | Height of canvas | in pixels (the `px` is omitted) | `width / 2` |
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": "tag-word-cloud",
"name": "Tag & Word Cloud",
"version": "1.3.0",
"version": "1.3.1",
"minAppVersion": "0.12.0",
"description": "Show a cloud of your tags/words in a note",
"author": "Johannes Theiner",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-tag-cloud",
"version": "1.3.0",
"version": "1.3.1",
"description": "Show a cloud of your tags/words in a note",
"main": "main.js",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/linkcloud.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {MarkdownPostProcessorContext} from "obsidian";
import TagCloudPlugin from "./main";
import WordCloud from "wordcloud";

export class LinkCloud {
plugin: TagCloudPlugin;
Expand All @@ -24,6 +25,11 @@ export class LinkCloud {

public processor = async(source: string, el: HTMLElement, _: MarkdownPostProcessorContext) : Promise<void> => {
el.createEl('p').setText("generating link cloud");

if(!WordCloud.isSupported) {
el.createEl("p", {cls: "cloud-error", text: "Your device is not supported"});
}

const options = this.plugin.parseCodeblockOptions(source);

if (options === undefined) {
Expand Down
22 changes: 9 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,13 @@ export default class TagCloudPlugin extends Plugin {
parseCodeblockOptions(source: string): CodeblockOptions | undefined {
const yaml = source ? parseYaml(source) : {};

const previewBlock = getComputedStyle(
document.querySelector(
'.markdown-preview-view.is-readable-line-width .markdown-preview-sizer'
));
if (previewBlock === undefined) {
logger.error("Preview block is undefined");
return undefined;
}
let max_width = 0;

const max_width = document.querySelectorAll(
'.markdown-preview-view.is-readable-line-width .markdown-preview-sizer, .cm-content'
)[0].clientWidth;
document.querySelectorAll('.markdown-preview-view.is-readable-line-width .markdown-preview-sizer, .cm-content').forEach(el => {
if(el.clientWidth !== 0) {
max_width = el.clientWidth;
}
});


let width = yaml.width ? yaml.width : max_width;
Expand Down Expand Up @@ -113,7 +108,7 @@ export default class TagCloudPlugin extends Plugin {
minCount: yaml.minCount ? yaml.minCount : 0,
type: yaml.type ? yaml.type : 'resolved',
shrinkToFit: yaml.shrinkToFit ? yaml.shrinkToFit : true,
maxDepth: yaml.maxDepth ? yaml.maxDepth : 50,
maxDepth: yaml.maxDepth ? yaml.maxDepth : 25,
}
}

Expand Down Expand Up @@ -267,7 +262,8 @@ export default class TagCloudPlugin extends Plugin {
if (checking) return !this.calculatingWordDistribution;

(async () => {
await this.calculateWordDistribution()
await this.calculateWordDistribution();
new Notice("calculated word distribution");
})();
},
})
Expand Down
5 changes: 5 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import TagCloudPlugin from "./main";
import {PluginSettingTab, Setting} from "obsidian";
import WordCloud from "wordcloud";

export interface WordsCache {
withStopwords: Record<string, number>;
Expand Down Expand Up @@ -35,6 +36,10 @@ export class TagCloudPluginSettingsTab extends PluginSettingTab{

containerEl.empty();

if(!WordCloud.isSupported) {
containerEl.createEl("p", {cls: "cloud-error", text: "Your device is not supported"});
}

containerEl.createEl('h1', {text: 'Tag & Word Cloud Settings'});

new Setting(containerEl)
Expand Down
16 changes: 15 additions & 1 deletion src/tagcloud.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {getAllTags, MarkdownPostProcessorContext} from "obsidian";
import {getAPI} from "obsidian-dataview";
import TagCloudPlugin, {logger} from "./main";
import WordCloud from "wordcloud";

export class TagCloud {
plugin: TagCloudPlugin;
Expand All @@ -11,6 +12,11 @@ export class TagCloud {

public processor = async(source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) : Promise<void> => {
el.createEl('p').setText("generating tag cloud");

if(!WordCloud.isSupported) {
el.createEl("p", {cls: "cloud-error", text: "Your device is not supported"});
}

const options = this.plugin.parseCodeblockOptions(source);

if (options === undefined) {
Expand Down Expand Up @@ -47,7 +53,15 @@ export class TagCloud {

let pages: any; // eslint-disable-line @typescript-eslint/no-explicit-any
try {
pages = dataviewAPI.pages(options.query, ctx.sourcePath);
let query = options.query;
if(!query) {
el.createEl('p', {cls: "cloud-error"}).setText("query option is required");
return;
}
if(!query.match(/[\[#]/)) {
query = '"' + options.query + '"';
}
pages = dataviewAPI.pages(query, ctx.sourcePath);
} catch (error: any) { // eslint-disable-line @typescript-eslint/no-explicit-any
el.createEl('p', {cls: "cloud-error"}).setText(error.toString());
logger.error(error);
Expand Down
5 changes: 5 additions & 0 deletions src/wordcloud.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import TagCloudPlugin from "./main";
import {MarkdownPostProcessorContext, TFile} from "obsidian";
import {convertToMap, getWords, recordToArray, removeStopwords} from "./functions";
import WordCloud from "wordcloud";

export class Wordcloud {
plugin: TagCloudPlugin;
Expand All @@ -12,6 +13,10 @@ export class Wordcloud {
public processor = async(source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) : Promise<void> => {
el.createEl('p').setText("generating word cloud");

if(!WordCloud.isSupported) {
el.createEl("p", {cls: "cloud-error", text: "Your device is not supported"});
}

const options = this.plugin.parseCodeblockOptions(source);

if (options === undefined) {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"1.1.1": "0.12.0",
"1.1.2": "0.12.0",
"1.2.0": "0.12.0",
"1.3.0": "0.12.0"
"1.3.0": "0.12.0",
"1.3.1": "0.12.0"
}

0 comments on commit df29055

Please sign in to comment.