1
This commit is contained in:
Alex Yatskov 2015-06-28 12:14:38 +09:00
parent b2b5dd0eba
commit d0931fdea0

View File

@ -113,7 +113,7 @@
cursor: 'crosshair', cursor: 'crosshair',
stroke: _borderColor, stroke: _borderColor,
fill: _fillColorBg fill: _fillColorBg
}).click(clicked); }).click(indicatorClick);
// density // density
_elements.density = _canvas.rect( _elements.density = _canvas.rect(
@ -145,6 +145,17 @@
'text-anchor': 'middle' 'text-anchor': 'middle'
}); });
// bracketBg
_elements.bracketBg = _canvas.rect(
_width - _bracketSize,
0,
_bracketSize,
_height - _panelSize
).attr({
fill: _bracketColorBg,
cursor: 'ns-resize'
}).click(bracketClick);
// indiciator // indiciator
updateIndicator(_data.value); updateIndicator(_data.value);
@ -206,15 +217,15 @@
).attr({ ).attr({
cursor: 'crosshair', cursor: 'crosshair',
fill: fill fill: fill
}).click(clicked); }).click(indicatorClick);
} }
} }
function updateBracket() { function updateBracket() {
var visibility = _data.bracket.min <= _data.bracket.max ? 'visible' : 'hidden'; var visibility = _data.bracket.min <= _data.bracket.max ? 'visible' : 'hidden';
var yMin = valueToIndicator(_data.bracket.min); var yMin = valueToBracket(_data.bracket.min);
var yMax = valueToIndicator(_data.bracket.max); var yMax = valueToBracket(_data.bracket.max);
var ySize = yMax - yMin; var ySize = yMax - yMin;
var xMin = _width - _bracketSize; var xMin = _width - _bracketSize;
@ -226,18 +237,6 @@
'v' + ySize * 0.95 + 'v' + ySize * 0.95 +
'Q' + xMax + ' ' + yMax + ',' + xMin + ' ' + yMax; 'Q' + xMax + ' ' + yMax + ',' + xMin + ' ' + yMax;
if (!_.has(_elements, 'bracketBg')) {
_elements.bracketBg = _canvas.rect(
_width - _bracketSize,
0,
_bracketSize,
_height - _panelSize
).attr({
fill: _bracketColorBg,
cursor: 'ns-resize'
});
}
if (_.has(_elements, 'bracketPath')) { if (_.has(_elements, 'bracketPath')) {
_elements.bracketPath.attr({ _elements.bracketPath.attr({
visibility: visibility, visibility: visibility,
@ -252,7 +251,7 @@
stroke: _bracketColorFg, stroke: _bracketColorFg,
cursor: 'ns-resize', cursor: 'ns-resize',
'stroke-dasharray': '5, 1' 'stroke-dasharray': '5, 1'
}); }).click(bracketClick);
} }
if (_.has(_elements, 'bracketMin')) { if (_.has(_elements, 'bracketMin')) {
@ -371,21 +370,46 @@
return new Range(valueToIndicator(0.0), valueToIndicator(value)); return new Range(valueToIndicator(0.0), valueToIndicator(value));
} }
function valueToIndicator(scalar) { function valueToControl(control, scalar) {
var box = _elements.indicatorBg.getBBox(); var box = control.getBBox();
var offset = _range.offset(scalar); var offset = _range.offset(scalar);
return box.y + box.height * (1.0 - offset); return box.y + box.height * (1.0 - offset);
} }
function indicatorToValue(scalar) { function controlToValue(control, scalar) {
var box = _elements.indicatorBg.getBBox(); var box = control.getBBox();
var range = new Range(box.y, box.y + box.height); var range = new Range(box.y, box.y + box.height);
return -_range.project(range.offset(scalar)); return -_range.project(range.offset(scalar));
} }
function clicked(event, x, y) { function valueToIndicator(scalar) {
return valueToControl(_elements.indicatorBg, scalar);
}
function indicatorToValue(scalar) {
return controlToValue(_elements.indicatorBg, scalar);
}
function valueToBracket(scalar) {
return valueToControl(_elements.bracketBg, scalar);
}
function bracketToValue(scalar) {
return controlToValue(_elements.bracketBg, scalar);
}
function indicatorClick(event, x, y) {
var rect = _canvas.node.getBoundingClientRect(); var rect = _canvas.node.getBoundingClientRect();
updateValue(indicatorToValue(y - rect.top)); var val = indicatorToValue(y - rect.top);
updateValue(val);
}
function bracketClick(event, x, y) {
var mid = (_data.bracket.min + _data.bracket.max) / 2;
var rect = _canvas.node.getBoundingClientRect();
var val = bracketToValue(y - rect.top);
alert('Clicked');
} }
this.update = function(data, scale) { this.update = function(data, scale) {