Skip to content

Commit 1b131d4

Browse files
committed
Merge branch 'master' into add-email-to-users-slz
2 parents b28de25 + 520347b commit 1b131d4

File tree

8 files changed

+379
-324
lines changed

8 files changed

+379
-324
lines changed
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
'use strict';
2+
3+
/* global $:false */
4+
/* global pullf: false */
5+
6+
// TODO remove jQuery dependency
7+
8+
var Plotly = require('../plotly');
9+
var d3 = require('d3');
10+
var isNumeric = require('../isnumeric');
11+
12+
function showSources(td) {
13+
if(td._context && td._context.staticPlot) return;
14+
// show the sources of data in the active tab
15+
var allsources = td.sourcelist;
16+
if(!allsources) {
17+
getSources(td);
18+
return;
19+
}
20+
var container = d3.select(td).select('.js-sourcelinks'),
21+
extsources = allsources.filter(function(v){
22+
return isNumeric(v.ref_fid);
23+
}),
24+
firstsource = extsources[0] || allsources[0];
25+
container.text('');
26+
td.shouldshowsources = false;
27+
// no sources at all? quit
28+
if(!firstsource) return;
29+
30+
// find number of unique internal and external sources
31+
var extobj = {}, plotlyobj = {};
32+
extsources.forEach(function(v){ extobj[v.url] = 1; });
33+
allsources.forEach(function(v){
34+
if(!isNumeric(v.ref_fid)) plotlyobj[v.ref_fid] = 1;
35+
});
36+
37+
var fidparts = String(firstsource.ref_fid).split(':'),
38+
isplot = Plotly.Lib.isPlotDiv(td),
39+
workspace = !isplot || td._context.workspace,
40+
mainlink,
41+
extraslink;
42+
43+
if(isplot) { // svg version for plots
44+
// only sources from the same user? also quit, if we're on a plot
45+
var thisuser = firstsource.fid.split(':')[0];
46+
if(allsources.every(function(v){
47+
return String(v.ref_fid).split(':')[0]===thisuser;
48+
})) {
49+
return;
50+
}
51+
td.shouldshowsources = true;
52+
53+
/**
54+
* in case someone REALLY doesn't want to show sources
55+
* they can hide them...
56+
* but you can always see them by going to the grid
57+
*/
58+
if(td.layout.hidesources) return;
59+
container.append('tspan').text('Source: ');
60+
mainlink = container.append('a').attr({'xlink:xlink:href':'#'});
61+
if(isNumeric(firstsource.ref_fid)) {
62+
mainlink.attr({
63+
'xlink:xlink:show':'new',
64+
'xlink:xlink:href':firstsource.ref_url
65+
});
66+
}
67+
else if(!workspace){
68+
mainlink.attr({
69+
'xlink:xlink:show':'new',
70+
'xlink:xlink:href':'/'+fidparts[1]+'/~'+fidparts[0]
71+
});
72+
}
73+
74+
if(allsources.length>1) {
75+
container.append('tspan').text(' - ');
76+
extraslink = container.append('a')
77+
.attr({'xlink:xlink:href':'#'});
78+
}
79+
}
80+
else { // html version for grids (and scripts?)
81+
if(!container.node()) {
82+
container = d3.select(td).select('.grid-container')
83+
.append('div')
84+
.attr('class', 'grid-sourcelinks js-sourcelinks');
85+
}
86+
container.append('span').text('Source: ');
87+
mainlink = container.append('a').attr({
88+
'href':'#',
89+
'class': 'link--impt'
90+
});
91+
if(isNumeric(firstsource.ref_fid)) {
92+
mainlink.attr({
93+
'target':'_blank',
94+
'href':firstsource.ref_url
95+
});
96+
}
97+
98+
if(allsources.length>1) {
99+
container.append('span').text(' - ');
100+
extraslink = container.append('a')
101+
.attr({href: '#'})
102+
.classed('link--impt', true);
103+
}
104+
}
105+
106+
mainlink.text(firstsource.ref_filename);
107+
108+
function pullSource(){
109+
pullf({fid: firstsource.ref_fid});
110+
return false;
111+
}
112+
113+
function fullSourcing(){
114+
var sourceModal = $('#sourceModal'),
115+
sourceViewer = sourceModal.find('#source-viewer').empty();
116+
117+
sourceViewer.data('jsontree', '')
118+
.jsontree(JSON.stringify(sourceObj),
119+
{terminators: false, collapsibleOuter: false})
120+
.show();
121+
if(workspace) {
122+
sourceModal.find('[data-fid]').click(function(){
123+
sourceModal.modal('hide');
124+
pullf({fid:$(this).attr('data-fid')});
125+
return false;
126+
});
127+
}
128+
else {
129+
sourceModal.find('[data-fid]').each(function(){
130+
fidparts = $(this).attr('data-fid').split(':');
131+
$(this).attr({href:'/~'+fidparts[0]+'/'+fidparts[1]});
132+
});
133+
if(window.self !== window.top) {
134+
// in an iframe: basically fill the frame
135+
sourceModal.css({
136+
left: '10px',
137+
right: '10px',
138+
bottom: '10px',
139+
width: 'auto',
140+
height: 'auto',
141+
margin: 0
142+
});
143+
}
144+
}
145+
sourceModal.modal('show');
146+
147+
sourceModal.find('.close')
148+
.off('click')
149+
.on('click', function(){
150+
sourceModal.modal('hide');
151+
return false;
152+
});
153+
return false;
154+
}
155+
156+
if(!isplot || workspace) mainlink.on('click', pullSource);
157+
158+
if(extraslink) extraslink.text('Full list').on('click', fullSourcing);
159+
160+
function makeSourceObj(container, refByUid) {
161+
if(cnt < 0) {
162+
console.log('infinite loop?');
163+
return container;
164+
}
165+
cnt--;
166+
167+
allsources.forEach(function(src){
168+
if(src.ref_by_uid === refByUid) {
169+
var linkval;
170+
if(isNumeric(src.ref_fid)) {
171+
linkval = '<a href="' + src.ref_url + '" target="_blank">' +
172+
src.ref_filename + '</a>';
173+
}
174+
else {
175+
var refUser = src.ref_fid.split(':')[0],
176+
fn = (refUser !== window.user ? refUser + ': ' : '') +
177+
src.ref_filename;
178+
linkval = '<a href="#" data-fid="' + src.ref_fid + '">'+
179+
fn + '</a>';
180+
}
181+
container[linkval] = makeSourceObj({}, src.uid);
182+
}
183+
});
184+
return container;
185+
}
186+
187+
var cnt = allsources.length,
188+
sourceObj = makeSourceObj({}, null);
189+
}
190+
191+
function getSources(td) {
192+
var extrarefs = (td.ref_fids || []).join(',');
193+
if(!td.fid && !extrarefs) return;
194+
if(!window.PLOTLYENV || !window.PLOTLYENV.DOMAIN_WEBAPP) return;
195+
196+
$.get('/getsources', {fid: td.fid, extrarefs:extrarefs}, function(res) {
197+
td.sourcelist = JSON.parse(res);
198+
if(!Array.isArray(td.sourcelist)) {
199+
console.log('sourcelist error',td.sourcelist);
200+
td.sourcelist = [];
201+
}
202+
showSources(td);
203+
});
204+
}
205+
206+
module.exports = showSources;

shelly/plotlyjs/static/plotlyjs/src/graph_interact.js

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -114,35 +114,30 @@ fx.init = function(gd) {
114114
// mousemove events for all data hover effects
115115
var maindrag = dragBox(gd, plotinfo, 0, 0,
116116
xa._length, ya._length,'ns','ew');
117-
$(maindrag)
118-
.mousemove(function(evt){
119-
fx.hover(gd,evt,subplot);
120-
fullLayout._lasthover = maindrag;
121-
fullLayout._hoversubplot = subplot;
122-
})
123-
.mouseout(function(evt) {
124-
/*
125-
* IMPORTANT: `fx.unhover(gd, evt)` has been commented out below
126-
* because in some browsers a 'mouseout' event is fired on clicks
127-
* on the maindrag container before reaching the 'click' handler.
128-
*
129-
* This results in a call to `fx.unhover` before `fx.click` where
130-
* `unhover` sets `gd._hoverdata` to `undefined` causing the call
131-
* to `fx.click` to return early.
132-
*
133-
* Note that the 'mouseout' handler is called only when the mouse
134-
* cursor gets lost. Most 'unhover' calls happen from 'mousemove';
135-
* these are not affected by the change below.
136-
*
137-
* Browsers where this behavior has been noticed:
138-
* - Chrome 46.0.2490.71
139-
* - Firefox 41.0.2
140-
* - IE 9, 10, 11
141-
*/
142-
// fx.unhover(gd, evt);
143-
return;
144-
})
145-
.click(function(evt){ fx.click(gd,evt); });
117+
118+
maindrag.onmousemove = function(evt) {
119+
fx.hover(gd, evt, subplot);
120+
fullLayout._lasthover = maindrag;
121+
fullLayout._hoversubplot = subplot;
122+
};
123+
124+
/*
125+
* IMPORTANT:
126+
* We must check for the presence of the drag cover here.
127+
* If we don't, a 'mouseout' event is triggered on the
128+
* maindrag before each 'click' event, which has the effect
129+
* of clearing the hoverdata; thus, cancelling the click event.
130+
*/
131+
maindrag.onmouseout = function(evt) {
132+
if(gd._dragging) return;
133+
134+
fx.unhover(gd, evt);
135+
};
136+
137+
maindrag.onclick = function(evt) {
138+
fx.click(gd, evt);
139+
};
140+
146141
// corner draggers
147142
dragBox(gd, plotinfo, -DRAGGERSIZE, -DRAGGERSIZE,
148143
DRAGGERSIZE, DRAGGERSIZE, 'n', 'w');

0 commit comments

Comments
 (0)