Skip to content

Commit

Permalink
fix(getFieldValues): 🐛 Some pretty big bugs that I hadn't noticed... …
Browse files Browse the repository at this point in the history
…I think it works now
  • Loading branch information
SkepticMystic committed Aug 15, 2021
1 parent c1f1f28 commit 6e98456
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Visualisations/ForceDirectedG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const forceDirectedG = (
"link",
d3.forceLink(links).id((d) => d.id)
)
.force("charge", d3.forceManyBody().strength(-6))
.force("charge", d3.forceManyBody().strength(-8))
.force("center", d3.forceCenter(width / 2, height / 2).strength(0.5));

const drag = (simulation: d3.Simulation<any, undefined>) => {
Expand Down
61 changes: 38 additions & 23 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,32 +200,47 @@ export function getFieldValues(
) {
const values: string[] = [];
try {
const rawValues: (string | number | dvLink | Pos | TFile | undefined)[] = [
frontmatterCache?.[field],
].flat(4);

superDebug(settings, `${field} of: ${frontmatterCache?.file?.path}`);
superDebug(settings, { rawValues });

rawValues.forEach((rawItem) => {
if (!rawItem) return;
if (typeof rawItem === "string" || typeof rawItem === "number") {
// Obs cache converts link of form: [[\d+]] to number[][]
const rawItemAsString = rawItem.toString();
const splits = rawItemAsString.match(splitLinksRegex);
if (splits !== null) {
const strs = splits
.map((link) => link.match(dropHeaderOrAlias)[1])
.map((str: string) => str.split("/").last());
} else {
values.push(rawItemAsString.split("/").last());
}
} else if (rawItem.path) {
values.push((rawItem as dvLink).path.split("/").last());
const rawValuesPreFlat = frontmatterCache?.[field];
if (typeof rawValuesPreFlat === "string") {
const splits = rawValuesPreFlat.match(splitLinksRegex);
if (splits !== null) {
const strs = splits.map((link) =>
link.match(dropHeaderOrAlias)[1].split("/").last()
);
values.push(...strs);
}
});
// else {
// Dont't add anything, it's not a link
// }
} else {
const rawValues: (string | number | dvLink | Pos | TFile | undefined)[] =
[rawValuesPreFlat].flat(4);

superDebug(settings, `${field} of: ${frontmatterCache?.file?.path}`);
superDebug(settings, { rawValues });

rawValues.forEach((rawItem) => {
if (!rawItem) return;
if (typeof rawItem === "string" || typeof rawItem === "number") {
// Obs cache converts link of form: [[\d+]] to number[][]
const rawItemAsString = rawItem.toString();
const splits = rawItemAsString.match(splitLinksRegex);
if (splits !== null) {
const strs = splits.map((link) =>
link.match(dropHeaderOrAlias)[1].split("/").last()
);
values.push(...strs);
} else {
values.push(rawItemAsString.split("/").last());
}
} else if (rawItem.path) {
values.push((rawItem as dvLink).path.split("/").last());
}
});
}
return values;
} catch (error) {
console.log(error);
return values;
}
}
Expand Down

0 comments on commit 6e98456

Please sign in to comment.