Fixing label support.

This commit is contained in:
Kaleb White 2021-11-12 19:02:04 -08:00
parent a5a5fc051b
commit 5034c7a954
3 changed files with 62 additions and 58 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -322,10 +322,13 @@ function makeVertLine(x, label, y1, y2, options={}) {
function makeHoriLine(y, label, x1, x2, options = {}) { function makeHoriLine(y, label, x1, x2, options = {}) {
if (!options.stroke) options.stroke = BASE_LINE_COLOR; if (!options.stroke) options.stroke = BASE_LINE_COLOR;
if (!options.lineType) options.lineType = ''; if (!options.lineType) options.lineType = '';
if (!options.alignment) options.alignment = 'left';
if (options.shortenNumbers) label = shortenLargeNumber(label); if (options.shortenNumbers) label = shortenLargeNumber(label);
let className = 'line-horizontal ' + options.className + let className =
(options.lineType === "dashed" ? "dashed": ""); 'line-horizontal ' +
options.className +
(options.lineType === 'dashed' ? 'dashed' : '');
let l = createSVG('line', { let l = createSVG('line', {
className: className, className: className,
@ -339,12 +342,12 @@ function makeHoriLine(y, label, x1, x2, options={}) {
}); });
let text = createSVG('text', { let text = createSVG('text', {
x: x1 < x2 ? x1 - LABEL_MARGIN : x1 + LABEL_MARGIN, x: options.alignment === 'left' ? x1 - LABEL_MARGIN : x2 + LABEL_MARGIN * 4,
y: 0, y: 0,
dy: (FONT_SIZE / 2 - 2) + 'px', dy: FONT_SIZE / 2 - 2 + 'px',
'font-size': FONT_SIZE + 'px', 'font-size': FONT_SIZE + 'px',
'text-anchor': x1 < x2 ? 'end' : 'start', 'text-anchor': x1 < x2 ? 'end' : 'start',
innerHTML: label+"" innerHTML: label + ''
}); });
let line = createSVG('g', { let line = createSVG('g', {
@ -353,7 +356,7 @@ function makeHoriLine(y, label, x1, x2, options={}) {
}); });
if (text === 0 || text === '0') { if (text === 0 || text === '0') {
line.style.stroke = "rgba(27, 31, 35, 0.6)"; line.style.stroke = 'rgba(27, 31, 35, 0.6)';
} }
line.appendChild(l); line.appendChild(l);
@ -403,15 +406,16 @@ export function yLine(y, label, width, options={}) {
x2 = width; x2 = width;
} }
// let offset = options.pos === 'left' ? -1 * options.offset : options.offset; let offset = options.pos === 'left' ? -1 * options.offset : options.offset;
x1 += options.offset; x1 += offset;
x2 += options.offset; x2 += offset;
return makeHoriLine(y, label, x1, x2, { return makeHoriLine(y, label, x1, x2, {
stroke: options.stroke, stroke: options.stroke,
className: options.className, className: options.className,
lineType: options.lineType, lineType: options.lineType,
alignment: options.pos,
shortenNumbers: options.shortenNumbers shortenNumbers: options.shortenNumbers
}); });
} }