wrapper for graphs

This commit is contained in:
stfrigerio 2025-04-13 12:41:56 +02:00
parent 6d6759bda1
commit 84ad5370fb
5 changed files with 69 additions and 5 deletions

View file

@ -19,10 +19,11 @@ import { injectDateNavigatorStyles, removeDateNavigatorStyles } from './src/styl
import { registerHabitCounter } from "./src/webcomponents/HabitCounter/registerHabitCounter"; import { registerHabitCounter } from "./src/webcomponents/HabitCounter/registerHabitCounter";
import { registerBooleanSwitch } from "src/webcomponents/BooleanSwitch/registerBooleanSwitch"; import { registerBooleanSwitch } from "src/webcomponents/BooleanSwitch/registerBooleanSwitch";
import { registerTextInput } from "src/webcomponents/TextInput/registerTextInput"; import { registerTextInput } from "src/webcomponents/TextInput/registerTextInput";
import { registerTimestampUpdaterButton } from "src/webcomponents/TimestampUpdaterButton/registerTimestampUpdaterButton";
import { registerSqlChartRenderer } from "src/webcomponents/SqlChart/registerSqlChart";
import { SQLiteDBSettings, DEFAULT_SETTINGS } from "./src/types"; import { SQLiteDBSettings, DEFAULT_SETTINGS } from "./src/types";
import { pluginState } from "src/pluginState"; import { pluginState } from "src/pluginState";
import { registerTimestampUpdaterButton } from "src/webcomponents/TimestampUpdaterButton/registerTimestampUpdaterButton";
export default class SQLiteDBPlugin extends Plugin { export default class SQLiteDBPlugin extends Plugin {
settings: SQLiteDBSettings; settings: SQLiteDBSettings;
@ -46,6 +47,7 @@ export default class SQLiteDBPlugin extends Plugin {
registerTextInput(el, this.app, this.dbService); registerTextInput(el, this.app, this.dbService);
}); });
registerSqlChartRenderer(this, this.dbService);
registerTimestampUpdaterButton(this); registerTimestampUpdaterButton(this);
//? Codeblocks //? Codeblocks

View file

@ -68,7 +68,7 @@ export function updateDateNavigatorDisplay(
newPeriod: NavigationPeriod newPeriod: NavigationPeriod
): void { ): void {
const displayString = formatPeriodForDisplay(newIsoDate, newPeriod); const displayString = formatPeriodForDisplay(newIsoDate, newPeriod);
if (!elements) { console.error("[DateNavDOM] Cannot update display, elements object is null."); return; } if (!elements) { return; }
// Update Title // Update Title
if (elements.dateDisplay) { if (elements.dateDisplay) {

View file

@ -0,0 +1,62 @@
import { MarkdownPostProcessorContext, Plugin } from 'obsidian';
import { DBService } from '../../DBService'; // Adjust path as needed
import { processSqlChartBlock } from '../../codeblocks/processSqlChartBlock'; // Adjust path as needed
import { replacePlaceholders } from 'src/helpers/replacePlaceholders';
// This function sets up the post-processor
export function registerSqlChartRenderer(plugin: Plugin, dbService: DBService) {
plugin.registerMarkdownPostProcessor(
async (el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
// Find all divs with the class 'sql-chart-render' inside the rendered element 'el'
const chartContainers = el.querySelectorAll<HTMLElement>('div.sql-chart-render');
if (chartContainers.length === 0) {
return; // No charts found in this section
}
// Use Promise.all to process charts potentially in parallel (optional)
// Or a simple loop if preferred: for (const container of chartContainers) { ... }
await Promise.all(Array.from(chartContainers).map(async (container) => {
// Check if already processed (important if post-processor runs multiple times)
if (container.dataset.sqlChartProcessed) {
return;
}
// Mark as processed
container.dataset.sqlChartProcessed = 'true';
const source = container.innerHTML.trim();
const parsedSource = replacePlaceholders(source);
// Clear the original config text before rendering
container.innerHTML = ''; // Clear the container
if (!source) {
container.createEl("p", { text: "Error: SQL Chart configuration block is empty." });
console.warn("Empty sql-chart-render block found", container);
return;
}
// Add a loading indicator (optional)
const loadingEl = container.createEl("p", { text: "Loading chart..." });
try {
// Call your existing core logic directly on the container
await processSqlChartBlock(dbService, parsedSource, container);
// Remove loading indicator if processSqlChartBlock doesn't clear the container itself
loadingEl.remove();
} catch (error: any) {
console.error("Error rendering SQL Chart from div:", error);
// Clear potential loading message or partial render
container.innerHTML = '';
container.createEl("p", { text: "Error rendering SQL Chart:" });
// Display the error message safely
container.createEl("pre", { text: String(error.message || error) });
}
}));
}
);
console.log("SQL Chart Renderer registered.");
}

View file

@ -12,8 +12,6 @@ export function registerTimestampUpdaterButton(plugin: Plugin): void {
plugin.registerMarkdownPostProcessor((element, context: MarkdownPostProcessorContext) => { plugin.registerMarkdownPostProcessor((element, context: MarkdownPostProcessorContext) => {
const { app } = plugin; const { app } = plugin;
console.log(`Timestamp PostProcessor running for section in: ${context.sourcePath}`);
const placeholderElements = element.querySelectorAll('.timestamp-updater-placeholder'); const placeholderElements = element.querySelectorAll('.timestamp-updater-placeholder');
if (placeholderElements.length === 0) { if (placeholderElements.length === 0) {

View file

@ -12,6 +12,7 @@
"isolatedModules": true, "isolatedModules": true,
"strictNullChecks": true, "strictNullChecks": true,
"esModuleInterop": true, "esModuleInterop": true,
"jsx": "react",
"lib": [ "lib": [
"DOM", "DOM",
"ES5", "ES5",
@ -20,6 +21,7 @@
] ]
}, },
"include": [ "include": [
"**/*.ts" "**/*.ts",
"**/*.tsx"
] ]
} }