Skip to content

Commit 6b191b2

Browse files
committed
Merge master, fix conflicts
2 parents 1773234 + a48f9c0 commit 6b191b2

File tree

11 files changed

+400
-327
lines changed

11 files changed

+400
-327
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/annotations.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,8 @@ annotations.draw = function(gd, index, opt, value) {
771771
// add the arrow
772772
// uses options[arrowwidth,arrowcolor,arrowhead] for styling
773773
var drawArrow = function(dx, dy){
774-
$(gd).find('.annotation-arrow-g[data-index="' + index + '"]')
774+
d3.select(gd)
775+
.selectAll('.annotation-arrow-g[data-index="' + index + '"]')
775776
.remove();
776777
// find where to start the arrow:
777778
// at the border of the textbox, if that border is visible,

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
/* jshint camelcase: false */
4-
53
var Plotly = require('./plotly'),
64
d3 = require('d3'),
75
tinycolor = require('tinycolor2'),
@@ -90,6 +88,7 @@ fx.init = function(gd) {
9088
}
9189
return fullLayout._plots[a].mainplot ? 1 : -1;
9290
});
91+
9392
subplots.forEach(function(subplot) {
9493
var plotinfo = fullLayout._plots[subplot];
9594

@@ -172,21 +171,23 @@ fx.init = function(gd) {
172171
}
173172
});
174173

175-
// in case you mousemove over some hovertext, send it to fx.hover too
174+
// In case you mousemove over some hovertext, send it to fx.hover too
176175
// we do this so that we can put the hover text in front of everything,
177176
// but still be able to interact with everything as if it isn't there
178-
$(fullLayout._hoverlayer.node())
179-
.off('mousemove click')
180-
.on('mousemove',function(evt){
181-
evt.target = fullLayout._lasthover;
182-
fx.hover(gd,evt,fullLayout._hoversubplot);
183-
})
184-
.on('click',function(evt){
185-
evt.target = fullLayout._lasthover;
186-
fx.click(gd,evt);
187-
});
177+
var hoverLayer = fullLayout._hoverlayer.node();
178+
179+
hoverLayer.onmousemove = function(evt) {
180+
evt.target = fullLayout._lasthover;
181+
fx.hover(gd, evt, fullLayout._hoversubplot);
182+
};
183+
184+
hoverLayer.onclick = function(evt) {
185+
evt.target = fullLayout._lasthover;
186+
fx.click(gd, evt);
187+
};
188+
188189
// also delegate mousedowns... TODO: does this actually work?
189-
fullLayout._hoverlayer.node().onmousedown = function(evt){
190+
hoverLayer.onmousedown = function(evt) {
190191
fullLayout._lasthover.onmousedown(evt);
191192
};
192193
};
@@ -552,11 +553,13 @@ function hover(gd, evt, subplot){
552553

553554
if(!hoverChanged(gd, evt, oldhoverdata)) return;
554555

555-
// emit the custom hover handler. Bind this like:
556-
// $(gd).on('hover.plotly',
557-
// function(event,extras){ do something with extras.data });
556+
/* Emit the custom hover handler. Bind this like:
557+
* gd.on('hover.plotly', function(extras) {
558+
* // do something with extras.data
559+
* });
560+
*/
558561
if(oldhoverdata) {
559-
gd.emit('plotly_unhover', {points: oldhoverdata});
562+
gd.emit('plotly_unhover', { points: oldhoverdata });
560563
}
561564
gd.emit('plotly_hover', {
562565
points: gd._hoverdata,

0 commit comments

Comments
 (0)