Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d5e3b9

Browse files
committed
Merge pull request plotly#388 from plotly/clean-drawing
remove dependence on internal Plotly in drawing module
2 parents fee3de6 + 4385405 commit 2d5e3b9

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/components/drawing/index.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
1312
var d3 = require('d3');
1413
var isNumeric = require('fast-isnumeric');
1514

15+
var Plots = require('../../plots/plots');
16+
var Color = require('../color');
17+
var Colorscale = require('../colorscale');
18+
var Lib = require('../../lib');
19+
var svgTextUtils = require('../../lib/svg_text_utils');
20+
1621
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
1722
var subTypes = require('../../traces/scatter/subtypes');
1823
var makeBubbleSizeFn = require('../../traces/scatter/make_bubble_size_func');
@@ -32,7 +37,7 @@ drawing.font = function(s, family, size, color) {
3237
}
3338
if(family) s.style('font-family', family);
3439
if(size+1) s.style('font-size', size + 'px');
35-
if(color) s.call(Plotly.Color.fill, color);
40+
if(color) s.call(Color.fill, color);
3641
};
3742

3843
drawing.setPosition = function(s, x, y) { s.attr('x',x).attr('y',y); };
@@ -83,7 +88,7 @@ drawing.lineGroupStyle = function(s, lw, lc, ld) {
8388
dash = ld||line.dash||'';
8489

8590
d3.select(this)
86-
.call(Plotly.Color.stroke,lc||line.color)
91+
.call(Color.stroke,lc||line.color)
8792
.call(drawing.dashLine, dash, lw1);
8893
});
8994
};
@@ -114,7 +119,7 @@ drawing.fillGroupStyle = function(s) {
114119
.each(function(d) {
115120
var shape = d3.select(this);
116121
try {
117-
shape.call(Plotly.Color.fill, d[0].trace.fillcolor);
122+
shape.call(Color.fill, d[0].trace.fillcolor);
118123
}
119124
catch(e) {
120125
console.log(e,s);
@@ -178,7 +183,7 @@ drawing.pointStyle = function(s, trace) {
178183

179184
// only scatter & box plots get marker path and opacity
180185
// bars, histograms don't
181-
if(Plotly.Plots.traceIs(trace, 'symbols')) {
186+
if(Plots.traceIs(trace, 'symbols')) {
182187
var sizeFn = makeBubbleSizeFn(trace);
183188

184189
s.attr('d', function(d) {
@@ -230,29 +235,29 @@ drawing.pointStyle = function(s, trace) {
230235

231236
if('mlc' in d) lineColor = d.mlcc = lineScale(d.mlc);
232237
// weird case: array wasn't long enough to apply to every point
233-
else if(Array.isArray(markerLine.color)) lineColor = Plotly.Color.defaultLine;
238+
else if(Array.isArray(markerLine.color)) lineColor = Color.defaultLine;
234239
else lineColor = markerLine.color;
235240

236241
if('mc' in d) fillColor = d.mcc = markerScale(d.mc);
237-
else if(Array.isArray(marker.color)) fillColor = Plotly.Color.defaultLine;
242+
else if(Array.isArray(marker.color)) fillColor = Color.defaultLine;
238243
else fillColor = marker.color || 'rgba(0,0,0,0)';
239244
}
240245

241246
var p = d3.select(this);
242247
if(d.om) {
243248
// open markers can't have zero linewidth, default to 1px,
244249
// and use fill color as stroke color
245-
p.call(Plotly.Color.stroke, fillColor)
250+
p.call(Color.stroke, fillColor)
246251
.style({
247252
'stroke-width': (lineWidth||1) + 'px',
248253
fill: 'none'
249254
});
250255
}
251256
else {
252257
p.style('stroke-width', lineWidth + 'px')
253-
.call(Plotly.Color.fill, fillColor);
258+
.call(Color.fill, fillColor);
254259
if(lineWidth) {
255-
p.call(Plotly.Color.stroke, lineColor);
260+
p.call(Color.stroke, lineColor);
256261
}
257262
}
258263
});
@@ -262,11 +267,11 @@ drawing.pointStyle = function(s, trace) {
262267
// have a colorscale for it (ie mscl, mcmin, mcmax) - if we do, translate
263268
// all numeric color values according to that scale
264269
drawing.tryColorscale = function(cont, contIn, prefix) {
265-
var colorArray = Plotly.Lib.nestedProperty(cont, prefix + 'color').get(),
266-
scl = Plotly.Lib.nestedProperty(cont, prefix + 'colorscale').get(),
267-
auto = Plotly.Lib.nestedProperty(cont, prefix + 'cauto').get(),
268-
minProp = Plotly.Lib.nestedProperty(cont, prefix + 'cmin'),
269-
maxProp = Plotly.Lib.nestedProperty(cont, prefix + 'cmax'),
270+
var colorArray = Lib.nestedProperty(cont, prefix + 'color').get(),
271+
scl = Lib.nestedProperty(cont, prefix + 'colorscale').get(),
272+
auto = Lib.nestedProperty(cont, prefix + 'cauto').get(),
273+
minProp = Lib.nestedProperty(cont, prefix + 'cmin'),
274+
maxProp = Lib.nestedProperty(cont, prefix + 'cmax'),
270275
min = minProp.get(),
271276
max = maxProp.get();
272277

@@ -287,12 +292,12 @@ drawing.tryColorscale = function(cont, contIn, prefix) {
287292
}
288293
minProp.set(min);
289294
maxProp.set(max);
290-
Plotly.Lib.nestedProperty(contIn, prefix + 'cmin').set(min);
291-
Plotly.Lib.nestedProperty(contIn, prefix + 'cmax').set(max);
295+
Lib.nestedProperty(contIn, prefix + 'cmin').set(min);
296+
Lib.nestedProperty(contIn, prefix + 'cmax').set(max);
292297
}
293-
return Plotly.Colorscale.makeScaleFunction(scl, min, max);
298+
return Colorscale.makeScaleFunction(scl, min, max);
294299
}
295-
else return Plotly.Lib.identity;
300+
else return Lib.identity;
296301
};
297302

298303
// draw text at points
@@ -328,7 +333,7 @@ drawing.textPointStyle = function(s, trace) {
328333
d.tc || trace.textfont.color)
329334
.attr('text-anchor',h)
330335
.text(text)
331-
.call(Plotly.util.convertToTspans);
336+
.call(svgTextUtils.convertToTspans);
332337
var pgroup = d3.select(this.parentNode),
333338
tspans = p.selectAll('tspan.line'),
334339
numLines = ((tspans[0].length||1)-1)*LINEEXPAND+1,
@@ -491,7 +496,7 @@ drawing.bBox = function(node) {
491496
// remeasure the same thing many times
492497
var saveNum = node.attributes['data-bb'];
493498
if(saveNum && saveNum.value) {
494-
return Plotly.Lib.extendFlat({}, savedBBoxes[saveNum.value]);
499+
return Lib.extendFlat({}, savedBBoxes[saveNum.value]);
495500
}
496501

497502
var test3 = d3.select('#js-plotly-tester'),
@@ -534,7 +539,7 @@ drawing.bBox = function(node) {
534539
node.setAttribute('data-bb',savedBBoxes.length);
535540
savedBBoxes.push(bb);
536541

537-
return Plotly.Lib.extendFlat({}, bb);
542+
return Lib.extendFlat({}, bb);
538543
};
539544

540545
/*

0 commit comments

Comments
 (0)