Skip to content

Commit

Permalink
Fix documentation images, some minor formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brenan committed May 6, 2021
1 parent 56c85a9 commit f631c5b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{ts,js}]
charset = utf-8
indent_style = space
indent_size = 4
32 changes: 11 additions & 21 deletions docs/docs/query/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ See [expressions](expressions) for context on what expressions are, and [sources

### List Queries

Lists are the simplest view, and simply render a list of pages (or custom fields) which match the query.
Lists are the simplest view, and simply render a list of pages (or custom fields) which match the query.
To obtain a list of pages matching the query, simply use:

```
Expand All @@ -52,9 +52,7 @@ LIST FROM <source>

For example, running `LIST FROM #games/moba or #games/crpg` might show:

<p align="center">
<img width="300" height="150" src="/static/images/game-list.png"/>
</p>
![List Example](/images/game-list.png)

You can render a single computed value in addition to each matching file, by adding an expression after `LIST`:

Expand All @@ -64,9 +62,7 @@ LIST <expression> FROM <source>

For example, running `LIST "File Path: " + file.path FROM "4. Archive"` might show:

<p align="center">
<img width="529" height="98" src="/static/images/file-path-list.png"/>
</p>
![List Example](/images/file-path-list.png)

### Table Queries

Expand All @@ -89,9 +85,7 @@ TABLE time-played AS "Time Played", length as "Length", rating as "Rating" FROM
SORT rating DESC
```

<p align="center">
<img src="/static/images/game.png"/>
</p>
![Table Example](/images/game.png)

### Task Queries

Expand All @@ -103,9 +97,7 @@ TASK from <source>

For example, `TASK FROM "dataview"` might show:

<p align="center">
<img src="/static/images/project-task.png"/>
</p>
![Task Example](/images/project-task.png)

## Data Commands

Expand All @@ -120,12 +112,12 @@ filtering. You can select from any [source](/docs/query/sources), which currentl

- **Tags**: To select from a tag (and all its subtags), use `FROM #tag`.
- **Folders**: To select from a folder (and all its subfolders), use `FROM "folder"`.
- **Links**: You can either select links TO a file, or all links FROM a file.
- To obtain all pages which link TO `[[note]]`, use `FROM [[note]]`.
- **Links**: You can either select links TO a file, or all links FROM a file.
- To obtain all pages which link TO `[[note]]`, use `FROM [[note]]`.
- To obtain all pages which link FROM `[[note]]` (i.e., all the links in that file), use `FROM outgoing([[note]])`.

You can compose these filters in order to get more advanced sources using `and` and `or`.
- For example, `#tag and "folder"` will return all pages in `folder` and with `#tag`.
You can compose these filters in order to get more advanced sources using `and` and `or`.
- For example, `#tag and "folder"` will return all pages in `folder` and with `#tag`.
- `[[Food]] or [[Exercise]]` will give any pages which link to `[[Food]]` OR `[[Exercise]]`.

### WHERE
Expand Down Expand Up @@ -172,7 +164,7 @@ GROUP BY field
GROUP BY (computed_field) AS name
```

In order to make working with the `rows` array easier, Dataview supports field "swizzling". If you want the field `test` from every object in the `rows` array, then `rows.test` will automatically fetch the `test` field from every object in `rows`, yielding a new array.
In order to make working with the `rows` array easier, Dataview supports field "swizzling". If you want the field `test` from every object in the `rows` array, then `rows.test` will automatically fetch the `test` field from every object in `rows`, yielding a new array.
You can then apply aggregation operators like `sum()` over the resulting array.

### FLATTEN
Expand All @@ -191,6 +183,4 @@ table authors from #LiteratureNote
flatten authors
```

<p align="center">
<img width="574" height="393" src="/static/images/flatten-authors.png"/>
</p>
![Flatten Example](/images/flatten-authors.png)
14 changes: 7 additions & 7 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class DataArrayImpl<T> implements DataArray<T> {
]);

private static ARRAY_PROXY: ProxyHandler<DataArrayImpl<any>> = {
get: function(target, prop, reciever) {
get: function (target, prop, reciever) {
if (typeof prop === "symbol") return (target as any)[prop];
else if (typeof prop === "number") return target.values[prop];
else if (!isNaN(parseInt(prop))) return target.values[parseInt(prop)];
Expand Down Expand Up @@ -166,7 +166,7 @@ class DataArrayImpl<T> implements DataArray<T> {
let realComparator = comparator ?? this.defaultComparator;

// Associate each entry with it's index for the key function, and then do a normal sort.
let copy = ([] as any[]).concat(this.array()).map((elem, index) => { return { index: index, value: elem }});
let copy = ([] as any[]).concat(this.array()).map((elem, index) => { return { index: index, value: elem } });
copy.sort((a, b) => {
let aKey = key(a.value, a.index, this.values);
let bKey = key(b.value, b.index, this.values);
Expand All @@ -184,7 +184,7 @@ class DataArrayImpl<T> implements DataArray<T> {
let intermediate = this.sort(key, "asc", comparator);
comparator = comparator ?? this.defaultComparator;

let result: {key: U, rows: DataArray<T> }[] = [];
let result: { key: U, rows: DataArray<T> }[] = [];
let currentRow = [intermediate[0]];
let current = key(intermediate[0], 0, intermediate.values);
for (let index = 1; index < intermediate.length; index++) {
Expand All @@ -208,7 +208,7 @@ class DataArrayImpl<T> implements DataArray<T> {

// For similar reasons to groupBy, do a sort and take the first element of each block.
let intermediate = this
.map((x, index) => { return { key: realKey(x, index, this.values), value: x }})
.map((x, index) => { return { key: realKey(x, index, this.values), value: x } })
.sort(x => x.key, "asc", comparator);
comparator = comparator ?? this.defaultComparator;

Expand Down Expand Up @@ -298,7 +298,7 @@ export class DataviewInlineApi {
public currentFilePath: string;

/**
* The container which holds the output of this view. You can directly append fields to this, if you wish, though
* The container which holds the output of this view. You can directly append fields to this, if you wish, though
* the rendering API is likely to be easier for straight-forward purposes.
*/
public container: HTMLElement;
Expand Down Expand Up @@ -423,10 +423,10 @@ export class DataviewInlineApi {

/** Evaluate a script where 'this' for the script is set to the given context. Allows you to define global variables. */
export function evalInContext(script: string, context: any): any {
return function() { return eval(script); }.call(context);
return function () { return eval(script); }.call(context);
}

/** Make a full API context which a script can be evaluted in. */
export function makeApiContext(index: FullIndex, component: Component, app: App, container: HTMLElement, originFile: string): DataviewInlineApi {
return new DataviewInlineApi(index, component, container, app, originFile);
}
}
4 changes: 2 additions & 2 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function execute(query: Query, index: FullIndex, origin: string): QueryRe
let amount = rootContext.evaluate(operation.amount);
if (typeof amount == 'string') return amount;
if (amount.valueType != 'number') return `LIMIT clauses requires a number - got ${amount.valueType} (value ${amount.value})`;

if (rows.length > amount.value) rows = rows.slice(0, amount.value);
break;
case "where":
Expand Down Expand Up @@ -338,4 +338,4 @@ export function executeTask(query: Query, origin: string, index: FullIndex): Map
}

return realResult;
}
}

0 comments on commit f631c5b

Please sign in to comment.