好吧,我让步了,为你做了修改:)
原始仪表的“扫描角度”和最大仪表值均硬连线为180。如果您尝试更改
max-value
我的版本修复了这个问题,并引入了一个新属性
gauge-sweep
设置仪表覆盖的角度(最高360度)。您还可以设置
最大值
独立(如100)。
代码的主要更改包括以下三个功能:
var getCoordinatesForAngle = function(centerX, centerY, radius, angleInDegrees) {
var angleInRadians = ((angleInDegrees - 90 - gauge.specs.gaugeSweep/2) * Math.PI / 180.0);
return {
x: parseInt(centerX + (radius * Math.cos(angleInRadians))),
y: parseInt(centerY + (radius * Math.sin(angleInRadians)))
};
};
gaugeSweep
价值
// calc background and value arc
// radius as param - diff for circle vs. text path
// Divided into three arcs to ensure accuracy over the largest possible range (360deg)
var getArcPathForAngle = function(startingAngle, endingAngle, radius, maxAngle) {
var startingPt = getCoordinatesForAngle(
gauge.specs.centerX,
gauge.specs.centerY,
radius,
startingAngle);
var midPt1 = getCoordinatesForAngle(
gauge.specs.centerX,
gauge.specs.centerY,
radius,
(startingAngle + endingAngle)/3);
var midPt2 = getCoordinatesForAngle(
gauge.specs.centerX,
gauge.specs.centerY,
radius,
(startingAngle + endingAngle)*2/3);
var endingPt = getCoordinatesForAngle(
gauge.specs.centerX,
gauge.specs.centerY,
radius,
endingAngle);
return ["M", startingPt.x, startingPt.y,
"A", radius, radius, 0, 0, 1, midPt1.x, midPt1.y,
"A", radius, radius, 0, 0, 1, midPt2.x, midPt2.y,
"A", radius, radius, 0, 0, 1, endingPt.x, endingPt.y].join(' ');
};
路径弧(
A
// textPath ticks
function initGradients() {
// use < instead of <= so doesn't show last value, taken care of with fixLastGradientTextValue fn
var offsetStep = (gauge.specs.gradientInterval * 100) / gauge.specs.maxValue;
for (var value = 0, offset = 0; value < gauge.specs.maxValue; value += gauge.specs.gradientInterval, offset += offsetStep) {
gauge.specs.gradients.push({value: value, offset: offset});
}
}
该函数计算仪表的刻度位置。它天生就希望
maxValue
也有一些小的变化
app-main.html
gauge.html
My updated plunkr is here