Skip to content

Commit 2686c8b

Browse files
committed
Merge branch 'master' into add-users-lookup
2 parents e3ff575 + 520347b commit 2686c8b

37 files changed

+2753
-626
lines changed

shelly/plotlyjs/static/plotlyjs/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@
1616
"d3": "3.3.5",
1717
"delaunay-triangulate": "^1.1.6",
1818
"es6-promise": "^3.0.2",
19+
"gl-error2d": "^1.0.0",
1920
"gl-error3d": "^1.0.0",
21+
"gl-line2d": "^1.2.1",
2022
"gl-line3d": "^1.0.1",
2123
"gl-mat4": "^1.1.2",
2224
"gl-mesh3d": "^1.0.4",
25+
"gl-plot2d": "^1.1.6",
2326
"gl-plot3d": "^1.3.0",
27+
"gl-scatter2d": "^1.0.5",
28+
"gl-scatter2d-fancy": "^1.1.1",
2429
"gl-scatter3d": "^1.0.4",
30+
"gl-select-box": "^1.0.1",
31+
"gl-spikes2d": "^1.0.1",
2532
"gl-surface3d": "^1.0.6",
2633
"mouse-change": "^1.1.1",
2734
"mouse-wheel": "^1.0.2",
@@ -30,6 +37,7 @@
3037
"ndarray-homography": "^1.0.0",
3138
"ndarray-ops": "^1.2.2",
3239
"right-now": "^1.0.0",
40+
"robust-orientation": "^1.1.3",
3341
"superscript-text": "^1.0.0",
3442
"through2": "^2.0.0",
3543
"tinycolor2": "1.1.2",
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;

0 commit comments

Comments
 (0)