mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-09-18 17:55:14 +00:00
Center on last step in proof tree
This commit is contained in:
parent
78bb732541
commit
db48c7ffa0
@ -129,8 +129,18 @@ class MathjaxProofTree extends MathjaxAdapter {
|
||||
}
|
||||
}
|
||||
// limit start zoom
|
||||
svg.viewBox.baseVal.width = Math.min(100000, svg.viewBox.baseVal.width);
|
||||
svg.viewBox.baseVal.width = Math.min(50000, svg.viewBox.baseVal.width);
|
||||
svg.viewBox.baseVal.width = Math.max(20000, svg.viewBox.baseVal.width);
|
||||
// center on first visible element
|
||||
const finalConclusion = svg
|
||||
.querySelector<SVGGraphicsElement>("#typicalc-prooftree > g[semantics='bspr_inferenceRule:down']")!
|
||||
.children[1]! as SVGGraphicsElement;
|
||||
const conclusionBBox = finalConclusion.getBBox();
|
||||
const mainGroupElement = svg.children[1]! as SVGGraphicsElement;
|
||||
const currentX = conclusionBBox.x + conclusionBBox.width / 2;
|
||||
const desiredX = svg.viewBox.baseVal.width / 2;
|
||||
mainGroupElement.setAttribute("transform",
|
||||
mainGroupElement.getAttribute("transform") + " translate(" + (desiredX - currentX) + " 0)");
|
||||
|
||||
// MathJax layout of bussproofs is sometimes wrong:
|
||||
// https://github.com/mathjax/MathJax/issues/2270
|
||||
@ -238,10 +248,18 @@ class MathjaxProofTree extends MathjaxAdapter {
|
||||
}
|
||||
console.timeEnd('stepCalculation');
|
||||
|
||||
const thisShadowRoot = this.shadowRoot!;
|
||||
|
||||
// should not be used on empty SVGs
|
||||
// svg-pan-zoom should not be used on empty SVGs
|
||||
if (nodeIterator.length >= 3) {
|
||||
// a timeout is required, otherwise the proof tree is moved around
|
||||
setTimeout(() => {
|
||||
this.setupPanZoom(this.shadowRoot!, svg);
|
||||
}, 100);
|
||||
}
|
||||
this.steps = steps;
|
||||
this.showStep(0);
|
||||
}
|
||||
|
||||
private setupPanZoom(thisShadowRoot: ShadowRoot, svg: SVGElement) {
|
||||
window.svgPanZoomFun(svg, {
|
||||
fit: false,
|
||||
controlIconsEnabled: true,
|
||||
@ -340,6 +358,7 @@ class MathjaxProofTree extends MathjaxAdapter {
|
||||
matrix.e = 0;
|
||||
matrix.f = 0;
|
||||
|
||||
// this listener destroys tooltips if the mouse is moved away from the relevant element
|
||||
svg.addEventListener("mousemove", (e) => {
|
||||
if (!this.hoveringOnElement || this.panningSvg) {
|
||||
return;
|
||||
@ -354,9 +373,6 @@ class MathjaxProofTree extends MathjaxAdapter {
|
||||
}
|
||||
});
|
||||
}
|
||||
this.steps = steps;
|
||||
this.showStep(0);
|
||||
}
|
||||
|
||||
protected calculateSteps(extraData: any): void {
|
||||
const data = typeof extraData === "string" ? JSON.parse(extraData) : [];
|
||||
|
Loading…
Reference in New Issue
Block a user