Skip to content

Commit

Permalink
change title scaling to use a minimum height instead of a minimum scale
Browse files Browse the repository at this point in the history
  • Loading branch information
Skgland committed Jan 20, 2022
1 parent d5ac370 commit 5b9cb2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
27 changes: 13 additions & 14 deletions packages/klighd-core/src/options/render-options-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,23 @@ export class TextSimplificationThreshold implements RangeOption {
}

/**
* The factor by which titles of collapsed regions get scaled by
* in relation to their size at native resolution.
* The minimum size a title should attempt to scale up to
*/
export class TitleScalingFactor implements RangeOption {
static readonly ID: string = 'title-scaling-factor'
static readonly NAME: string = 'Title Scaling Factor'
static readonly DEFAULT: number = 1
readonly id: string = TitleScalingFactor.ID
readonly name: string = TitleScalingFactor.NAME
export class MinimumTitleHeight implements RangeOption {
static readonly ID: string = 'min-title-height'
static readonly NAME: string = 'Minimum Title Height'
static readonly DEFAULT: number = 10
readonly id: string = MinimumTitleHeight.ID
readonly name: string = MinimumTitleHeight.NAME
readonly type: TransformationOptionType = TransformationOptionType.RANGE
readonly values: any[] = []
readonly range = {
first: 0.5,
second: 3
first: 0,
second: 80
}
readonly stepSize = 0.01
readonly initialValue: number = TitleScalingFactor.DEFAULT
currentValue = 1
readonly stepSize = 1
readonly initialValue: number = MinimumTitleHeight.DEFAULT
currentValue = MinimumTitleHeight.DEFAULT
}

/**
Expand Down Expand Up @@ -270,7 +269,7 @@ export class RenderOptionsRegistry extends Registry {
this.register(SimplifySmallText);
this.register(TextSimplificationThreshold);

this.register(TitleScalingFactor);
this.register(MinimumTitleHeight);

this.register(UseMinimumLineWidth);
this.register(MinimumLineWidth);
Expand Down
11 changes: 6 additions & 5 deletions packages/klighd-core/src/views-rendering.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { svg } from 'sprotty'; // eslint-disable-line @typescript-eslint/no-unus
import { Bounds } from 'sprotty-protocol';
import { KGraphData, KNode } from '@kieler/klighd-interactive/lib/constraint-classes';
import { DetailLevel } from './depth-map';
import { PaperShadows, SimplifySmallText, TextSimplificationThreshold, TitleScalingFactor, UseSmartZoom } from './options/render-options-registry';
import { PaperShadows, SimplifySmallText, TextSimplificationThreshold, MinimumTitleHeight, UseSmartZoom } from './options/render-options-registry';
import { SKGraphModelRenderer } from './skgraph-model-renderer';
import {
Arc, HorizontalAlignment, isRendering, KArc, KChildArea, KContainerRendering, KForeground, KHorizontalAlignment, KImage, KPolyline, KRendering, KRenderingLibrary, KRenderingRef, KRoundedBendsPolyline,
Expand Down Expand Up @@ -898,12 +898,11 @@ export function renderKRendering(kRendering: KRendering,
// zoomed in far enough or remember it to be rendered later scaled up and overlayed on top of the parent rendering.
if (applyTitleScaling && boundsAndTransformation.bounds.width && boundsAndTransformation.bounds.height && kRendering.isNodeTitle) {

// Scale to limit of bounding box or max size.
const titleScalingFactorOption = context.renderOptionsRegistry.getValueOrDefault(TitleScalingFactor) as number
const maxScale = titleScalingFactorOption / context.viewport.zoom
const overlayThreshold = context.renderOptionsRegistry.getValueOrDefault(MinimumTitleHeight) as number


// is the rendering at the current zoom level smaller in height than our set threshold (apparently the threshold is minimum height?)
const tooSmall = kRendering.calculatedBounds && kRendering.calculatedBounds.height * context.viewport.zoom <= titleScalingFactorOption * kRendering.calculatedBounds.height
const tooSmall = kRendering.calculatedBounds && kRendering.calculatedBounds.height * context.viewport.zoom <= overlayThreshold
const notFullDetail = providingRegion && providingRegion.detail !== DetailLevel.FullDetails
const multipleChildren = parent.children.length > 1

Expand All @@ -927,6 +926,8 @@ export function renderKRendering(kRendering: KRendering,
const maxScaleX = parentBounds.width / originalWidth
const maxScaleY = parentBounds.height / originalHeight

let maxScale = overlayThreshold / (boundingBox.height * context.viewport.zoom);

// limit the scaling so that it does not exceed the parents size
let scalingFactor = Math.min(maxScaleX, maxScaleY, maxScale)
// Make sure we never scale down.
Expand Down

0 comments on commit 5b9cb2f

Please sign in to comment.