Skip to content

Commit b6fdd0c

Browse files
committed
[fix] regarding [Bug]: Plot not showing #2
1 parent 057700e commit b6fdd0c

6 files changed

Lines changed: 625 additions & 47 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: yarn install
2727

2828
- name: Run version-bump
29-
run: node version-bump.mjs
29+
run: node version-bump.mjs ${{ github.event.release.tag_name }}
3030

3131
- name: Commit and push changes
3232
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
yarn-error.log
33
dist/
4+
copy.bat

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
"license": "MIT",
88
"private": true,
99
"scripts": {
10-
"build": "rimraf dist && mkdir dist && cp manifest.json dist/manifest.json && webpack"
10+
"build": "rimraf dist && make-dir dist && cpy manifest.json dist && webpack"
1111
},
1212
"devDependencies": {
13+
"cpy-cli": "^4.1.0",
14+
"make-dir-cli": "^3.0.0",
1315
"rimraf": "^3.0.2",
1416
"sass": "^1.51.0",
1517
"sass-loader": "^12.6.0",

src/main.ts

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,50 @@ export default class ObsidianFunctionPlot extends Plugin {
2727
}
2828

2929
async functionPlotHandler(source: string, el: HTMLElement, _ctx: MarkdownPostProcessorContext): Promise<void> {
30-
// styles
31-
el.classList.add('functionplot')
32-
// parse yaml for bounds and functions to plot
33-
const header = (source.match(/-{3,}([^]+)-{3,}/) || [null, null])[1]
34-
console.log(header)
35-
const functions = (header ? source.substring(header.length) : source)
36-
.split('\n')
37-
.map(line => line.trim())
38-
.filter(line => line.length > 0)
39-
40-
const config: HeaderOptions = Object.assign(
41-
{},
42-
DEFAULT_HEADER_OPTIONS,
43-
parseYaml(header || '')
44-
)
30+
try {
31+
// styles
32+
el.classList.add('functionplot')
33+
// parse yaml for bounds and functions to plot
34+
35+
const header = (source.match(/-{3}[^]+-{3}/) || [null])[0]
36+
const functions = (header ? source.substring(header.length) : source)
37+
.split('\n')
38+
.map(line => line.trim())
39+
.filter(line => line.length > 0)
40+
41+
const config: HeaderOptions = Object.assign(
42+
{},
43+
DEFAULT_HEADER_OPTIONS,
44+
parseYaml(header.match(/-{3,}([^]+?)-{3,}/)[1] || '')
45+
)
4546

46-
// prepare options for call to FunctionPlotya
47-
const fPlotOptions: FunctionPlotOptions = {
48-
target: el as unknown as string, // weird workaround
49-
title: config.title,
50-
grid: config.grid,
51-
disableZoom: config.disableZoom,
52-
xAxis: {
53-
domain: [config.bounds[0], config.bounds[1]],
54-
label: config.xLabel
55-
},
56-
yAxis: {
57-
domain: [config.bounds[2], config.bounds[3]],
58-
label: config.yLabel
59-
},
60-
data: functions.map(line => { return { "fn": line.split('=')[1].trim() } })
47+
// prepare options for call to FunctionPlotya
48+
const fPlotOptions: FunctionPlotOptions = {
49+
target: el as unknown as string, // weird workaround
50+
title: config.title,
51+
grid: config.grid,
52+
disableZoom: config.disableZoom,
53+
xAxis: {
54+
domain: [config.bounds[0], config.bounds[1]],
55+
label: config.xLabel
56+
},
57+
yAxis: {
58+
domain: [config.bounds[2], config.bounds[3]],
59+
label: config.yLabel
60+
},
61+
data: functions.map(line => { return { "fn": line.split('=')[1].trim() } })
62+
}
63+
// render
64+
functionPlot(fPlotOptions)
65+
// make text listen to stylesheet
66+
el.querySelectorAll('text').forEach(el => el.setAttribute('fill', 'currentColor'))
67+
} catch (e) {
68+
el.innerHTML = `
69+
<div style="border-radius:1em;background:black;opacity:0.5">
70+
<p style="opacity:1;font-size:0.7em;padding:1em">
71+
${e}\n\n${source}
72+
</p>
73+
</div>`
6174
}
62-
// render
63-
functionPlot(fPlotOptions)
64-
// make text listen to stylesheet
65-
el.querySelectorAll('text').forEach(el => el.setAttribute('fill', 'currentColor'))
6675
}
6776
}

version-bump.mjs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { readFileSync, writeFileSync } from "fs";
22

3-
const { version } = JSON.parse(readFileSync("package.json", "utf8"));
3+
const version = process.argv[2];
44

5-
// read minAppVersion from manifest.json and bump version to target version
5+
// read files
6+
let package_ = JSON.parse(readFileSync("package.json", "utf8"));
67
let manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
7-
const { minAppVersion } = manifest;
8-
manifest.version = version;
9-
writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));
10-
11-
// update versions.json with target version and minAppVersion from manifest.json
128
let versions = JSON.parse(readFileSync("versions.json", "utf8"));
9+
10+
// index minAppVersion
1311
versions[version] = minAppVersion;
12+
13+
// update versions
14+
package_.version = version;
15+
manifest.version = version;
16+
17+
writeFileSync("package.json", JSON.stringify(package_, null, "\t"));
18+
writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));
1419
writeFileSync("versions.json", JSON.stringify(versions, null, "\t"));

0 commit comments

Comments
 (0)