File size: 4,191 Bytes
fe66731 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
module.exports = function ( graph ){
var configMenu = {},
checkboxes = [];
configMenu.setup = function (){
var menuEntry = d3.select("#m_modes");
menuEntry.on("mouseover", function (){
var searchMenu = graph.options().searchMenu();
searchMenu.hideSearchEntries();
});
addCheckBox("showZoomSlider", "Zoom controls", "#zoomSliderOption", graph.options().zoomSlider().showSlider, 0);
addLabelWidthSlider("#maxLabelWidthSliderOption", "maxLabelWidth", "Max label width", graph.options().maxLabelWidth);
};
function addLabelWidthSlider( selector, identifier, label, onChangeFunction ){
var sliderContainer,
sliderValueLabel;
sliderContainer = d3.select(selector)
.append("div")
.classed("distanceSliderContainer", true);
var slider = sliderContainer.append("input")
.attr("id", identifier + "Slider")
.attr("type", "range")
.attr("min", 20)
.attr("max", 600)
.attr("value", onChangeFunction())
.attr("step", 10);
sliderContainer.append("label")
.classed("description", true)
.attr("for", identifier + "Slider")
.attr("id", identifier + "DescriptionLabel")
.text(label);
sliderValueLabel = sliderContainer.append("label")
.classed("value", true)
.attr("for", identifier + "Slider")
.attr("id", identifier + "valueLabel")
.text(onChangeFunction());
slider.on("input", function (){
var value = slider.property("value");
onChangeFunction(value);
sliderValueLabel.text(value);
if ( graph.options().dynamicLabelWidth() === true )
graph.animateDynamicLabelWidth();
});
// add wheel event to the slider
slider.on("wheel", function (){
if ( slider.node().disabled === true ) return;
var wheelEvent = d3.event;
var offset;
if ( wheelEvent.deltaY < 0 ) offset = 10;
if ( wheelEvent.deltaY > 0 ) offset = -10;
var oldVal = parseInt(slider.property("value"));
var newSliderValue = oldVal + offset;
if ( newSliderValue !== oldVal ) {
slider.property("value", newSliderValue);
onChangeFunction(newSliderValue);
slider.on("input")(); // << set text and update the graphStyles
}
d3.event.preventDefault();
});
}
function addCheckBox( identifier, modeName, selector, onChangeFunc, updateLvl ){
var configOptionContainer = d3.select(selector)
.append("div")
.classed("checkboxContainer", true);
var configCheckbox = configOptionContainer.append("input")
.classed("moduleCheckbox", true)
.attr("id", identifier + "ConfigCheckbox")
.attr("type", "checkbox")
.property("checked", onChangeFunc());
configCheckbox.on("click", function ( silent ){
var isEnabled = configCheckbox.property("checked");
onChangeFunc(isEnabled);
if ( silent !== true ) {
// updating graph when silent is false or the parameter is not given.
if ( updateLvl === 1 ) {
graph.lazyRefresh();
//graph.redrawWithoutForce
}
if ( updateLvl === 2 ) {
graph.update();
}
if ( updateLvl === 3 ) {
graph.updateDraggerElements();
}
}
});
checkboxes.push(configCheckbox);
configOptionContainer.append("label")
.attr("for", identifier + "ConfigCheckbox")
.text(modeName);
}
configMenu.setCheckBoxValue = function ( identifier, value ){
for ( var i = 0; i < checkboxes.length; i++ ) {
var cbdId = checkboxes[i].attr("id");
if ( cbdId === identifier ) {
checkboxes[i].property("checked", value);
break;
}
}
};
configMenu.getCheckBoxValue = function ( id ){
for ( var i = 0; i < checkboxes.length; i++ ) {
var cbdId = checkboxes[i].attr("id");
if ( cbdId === id ) {
return checkboxes[i].property("checked");
}
}
};
configMenu.updateSettings = function (){
var silent = true;
checkboxes.forEach(function ( checkbox ){
checkbox.on("click")(silent);
});
};
return configMenu;
};
|