Fixing label support.
This commit is contained in:
parent
a5a5fc051b
commit
5034c7a954
2
docs/assets/js/frappe-charts.min.js
vendored
2
docs/assets/js/frappe-charts.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -319,13 +319,16 @@ function makeVertLine(x, label, y1, y2, options={}) {
|
||||
return line;
|
||||
}
|
||||
|
||||
function makeHoriLine(y, label, x1, x2, options={}) {
|
||||
if(!options.stroke) options.stroke = BASE_LINE_COLOR;
|
||||
if(!options.lineType) options.lineType = '';
|
||||
function makeHoriLine(y, label, x1, x2, options = {}) {
|
||||
if (!options.stroke) options.stroke = BASE_LINE_COLOR;
|
||||
if (!options.lineType) options.lineType = '';
|
||||
if (!options.alignment) options.alignment = 'left';
|
||||
if (options.shortenNumbers) label = shortenLargeNumber(label);
|
||||
|
||||
let className = 'line-horizontal ' + options.className +
|
||||
(options.lineType === "dashed" ? "dashed": "");
|
||||
let className =
|
||||
'line-horizontal ' +
|
||||
options.className +
|
||||
(options.lineType === 'dashed' ? 'dashed' : '');
|
||||
|
||||
let l = createSVG('line', {
|
||||
className: className,
|
||||
@ -339,12 +342,12 @@ function makeHoriLine(y, label, x1, x2, options={}) {
|
||||
});
|
||||
|
||||
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,
|
||||
dy: (FONT_SIZE / 2 - 2) + 'px',
|
||||
dy: FONT_SIZE / 2 - 2 + 'px',
|
||||
'font-size': FONT_SIZE + 'px',
|
||||
'text-anchor': x1 < x2 ? 'end' : 'start',
|
||||
innerHTML: label+""
|
||||
innerHTML: label + ''
|
||||
});
|
||||
|
||||
let line = createSVG('g', {
|
||||
@ -352,8 +355,8 @@ function makeHoriLine(y, label, x1, x2, options={}) {
|
||||
'stroke-opacity': 1
|
||||
});
|
||||
|
||||
if(text === 0 || text === '0') {
|
||||
line.style.stroke = "rgba(27, 31, 35, 0.6)";
|
||||
if (text === 0 || text === '0') {
|
||||
line.style.stroke = 'rgba(27, 31, 35, 0.6)';
|
||||
}
|
||||
|
||||
line.appendChild(l);
|
||||
@ -386,32 +389,33 @@ export function generateAxisLabel(options) {
|
||||
return labelSvg;
|
||||
}
|
||||
|
||||
export function yLine(y, label, width, options={}) {
|
||||
export function yLine(y, label, width, options = {}) {
|
||||
if (!isValidNumber(y)) y = 0;
|
||||
|
||||
if(!options.pos) options.pos = 'left';
|
||||
if(!options.offset) options.offset = 0;
|
||||
if(!options.mode) options.mode = 'span';
|
||||
if(!options.stroke) options.stroke = BASE_LINE_COLOR;
|
||||
if(!options.className) options.className = '';
|
||||
if (!options.pos) options.pos = 'left';
|
||||
if (!options.offset) options.offset = 0;
|
||||
if (!options.mode) options.mode = 'span';
|
||||
if (!options.stroke) options.stroke = BASE_LINE_COLOR;
|
||||
if (!options.className) options.className = '';
|
||||
|
||||
let x1 = -1 * AXIS_TICK_LENGTH;
|
||||
let x2 = options.mode === 'span' ? width + AXIS_TICK_LENGTH : 0;
|
||||
|
||||
if(options.mode === 'tick' && options.pos === 'right') {
|
||||
if (options.mode === 'tick' && options.pos === 'right') {
|
||||
x1 = width + AXIS_TICK_LENGTH;
|
||||
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;
|
||||
x2 += options.offset;
|
||||
x1 += offset;
|
||||
x2 += offset;
|
||||
|
||||
return makeHoriLine(y, label, x1, x2, {
|
||||
stroke: options.stroke,
|
||||
className: options.className,
|
||||
lineType: options.lineType,
|
||||
alignment: options.pos,
|
||||
shortenNumbers: options.shortenNumbers
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user