Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 50 additions & 38 deletions src/plugins/plugin.filler.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,46 +63,54 @@ function decodeFill(line, index, count) {
let target = parseFloat(fill);

if (isFinite(target) && Math.floor(target) === target) {
if (fill[0] === '-' || fill[0] === '+') {
target = index + target;
}
return decodeTargetIndex(fill[0], index, target, count);
}

if (target === index || target < 0 || target >= count) {
return false;
}
return ['origin', 'start', 'end', 'stack', 'shape'].indexOf(fill) >= 0 && fill;
}

return target;
function decodeTargetIndex(firstCh, index, target, count) {
if (firstCh === '-' || firstCh === '+') {
target = index + target;
}

return ['origin', 'start', 'end', 'stack', 'shape'].indexOf(fill) >= 0 && fill;
if (target === index || target < 0 || target >= count) {
return false;
}

return target;
}

function computeLinearBoundary(source) {
const {scale = {}, fill} = source;
let target = null;
let horizontal;
const pixel = getTargetPixel(fill, scale);

if (fill === 'start') {
target = scale.bottom;
} else if (fill === 'end') {
target = scale.top;
} else if (isObject(fill)) {
target = scale.getPixelForValue(fill.value);
} else if (scale.getBasePixel) {
target = scale.getBasePixel();
}
if (isFinite(pixel)) {
const horizontal = scale.isHorizontal();

if (isFinite(target)) {
horizontal = scale.isHorizontal();
return {
x: horizontal ? target : null,
y: horizontal ? null : target
x: horizontal ? pixel : null,
y: horizontal ? null : pixel
};
}

return null;
}

function getTargetPixel(fill, scale) {
let pixel = null;
if (fill === 'start') {
pixel = scale.bottom;
} else if (fill === 'end') {
pixel = scale.top;
} else if (isObject(fill)) {
pixel = scale.getPixelForValue(fill.value);
} else if (scale.getBasePixel) {
pixel = scale.getBasePixel();
}
return pixel;
}

// TODO: use elements.ArcElement instead
class simpleArc {
constructor(opts) {
Expand Down Expand Up @@ -133,36 +141,40 @@ function computeCircularBoundary(source) {
const {scale, fill} = source;
const options = scale.options;
const length = scale.getLabels().length;
const target = [];
const start = options.reverse ? scale.max : scale.min;
const end = options.reverse ? scale.min : scale.max;
let i, center, value;

if (fill === 'start') {
value = start;
} else if (fill === 'end') {
value = end;
} else if (isObject(fill)) {
value = fill.value;
} else {
value = scale.getBaseValue();
}
const value = getTargetValue(fill, scale, start);
const target = [];

if (options.grid.circular) {
center = scale.getPointPositionForValue(0, start);
const center = scale.getPointPositionForValue(0, start);
return new simpleArc({
x: center.x,
y: center.y,
radius: scale.getDistanceFromCenterForValue(value)
});
}

for (i = 0; i < length; ++i) {
for (let i = 0; i < length; ++i) {
target.push(scale.getPointPositionForValue(i, value));
}
return target;
}

function getTargetValue(fill, scale, startValue) {
let value;

if (fill === 'start') {
value = startValue;
} else if (fill === 'end') {
value = scale.options.reverse ? scale.min : scale.max;
} else if (isObject(fill)) {
value = fill.value;
} else {
value = scale.getBaseValue();
}
return value;
}

function computeBoundary(source) {
const scale = source.scale || {};

Expand Down