forked from beilinli/cellblender-browser-plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon-display.js
132 lines (112 loc) · 3.48 KB
/
common-display.js
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
/**
* contains functions used by both plot-main.js and histogram.js
* @author Beilin Li
*/
function updateChartDimensions(chart) {
var rightElem = $('#outer-expand');
var rightPos = rightElem.offset().left + rightElem.outerWidth();
var widthPct = 99.0 - 100.0 * rightPos/$(window).width();
$('#chart-container').css({ 'width': widthPct + '%' });
chart.setSize($('#chart').width(), $('#chart').height(), false);
}
function initResizable(chart) {
$('.side-panel').resizable({
handles: 'e',
resize: function(event, ui) {
updateChartDimensions(chart);
}
});
$('#chart-settings').resizable({ handles: 's' });
$('#chart').resizable({
handles: 'se',
resize: function(event, ui) {
chart.setSize($(this).width(), $(this).height(), false);
var marginWidth = 50 - (50.0 * $(this).width() / $('#chart-container').width());
$(this).css({ 'margin-left': marginWidth + '%' });
},
/**
* keeping CSS property percentage based
* to preserve proportionality to the page
*/
stop: function(event, ui) {
var widthPct = 100.0 * $(this).width()/$('#chart-container').width();
var heightPct = 100.0 * $(this).height()/$('#chart-container').height();
$(this).css({ 'width': widthPct + '%',
'height': heightPct + '%' });
}
});
}
function showLabelOptions(labelElem, editElem, offsetX, offsetY) {
console.log(window);
editElem.visible();
var pos = $('#chart').offset();
var x = pos.left + offsetX;
var y = pos.top + offsetY;
editElem.position(x, y);
editElem.children('.label-text')
.val(labelElem.options.title.text);
editElem.children('.label-color')
.val(labelElem.options.title.style.color);
editElem.children('.label-size')
.val(parseInt(labelElem.options.title.style.fontSize));
editElem.children('.label-font')
.val(labelElem.options.title.style.fontFamily);
// axis only
if ((editElem.children('.tick-interval')).length) {
editElem.children('.tick-interval')
.val(labelElem.tickInterval);
}
}
function getLabelElem(chart, eName) {
switch (eName) {
case "edit-title": return chart;
case "edit-x-label": return chart.xAxis[0];
case "edit-y-label": return chart.yAxis[0];
default: alert("error");
}
}
/* user options for changing axis/chart titles
* edit options displayed on label mouseover and
* hidden on cancel/chart/apply click
*/
function initFonts() {
var fontList = ['Times New Roman', 'Arial', 'Helvetica', 'Arial Black', 'Comic Sans MS', 'Lucida Grande', 'Tahoma', 'Geneva', 'Verdana', 'Courier New'];
for (var i = 0; i < fontList.length; i++) {
$('.edit-label .label-font').append($('<option>')
.append(fontList[i])
.attr("name", fontList[i]));
}
}
function applyLabel(chart, parent) {
var labelElem = getLabelElem(chart, parent.attr("id"));
var newStyle = {
color: parent.children('.label-color').val(),
fontSize: parent.children('.label-size').val() + 'px',
fontFamily: parent.children('.label-font').val()
};
labelElem.setTitle({
text: parent.children('.label-text').val(),
style: newStyle
});
if (parent.attr("id") !== "edit-title") {
labelElem.update({
labels: { style: newStyle },
tickInterval: parseFloat(parent.children('.tick-interval').val())
});
}
$('.edit-label').invisible();
}
function initLabelOptions(chart) {
$('.cancel').click(function() {
$('.edit-label').invisible();
});
$('.label-color').spectrum({
showInput: true,
preferredFormat: 'hex'
});
initFonts();
$('.apply-label').click(function() {
console.log($(this).parent());
applyLabel(chart, $(this).parent());
});
}