Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@

'use strict';

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

var Plots = require('../../plots/plots');
var Color = require('../color');
var Colorscale = require('../colorscale');
var Lib = require('../../lib');
var svgTextUtils = require('../../lib/svg_text_utils');

var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
var subTypes = require('../../traces/scatter/subtypes');
var makeBubbleSizeFn = require('../../traces/scatter/make_bubble_size_func');
Expand All @@ -32,7 +37,7 @@ drawing.font = function(s, family, size, color) {
}
if(family) s.style('font-family', family);
if(size+1) s.style('font-size', size + 'px');
if(color) s.call(Plotly.Color.fill, color);
if(color) s.call(Color.fill, color);
};

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

d3.select(this)
.call(Plotly.Color.stroke,lc||line.color)
.call(Color.stroke,lc||line.color)
.call(drawing.dashLine, dash, lw1);
});
};
Expand Down Expand Up @@ -114,7 +119,7 @@ drawing.fillGroupStyle = function(s) {
.each(function(d) {
var shape = d3.select(this);
try {
shape.call(Plotly.Color.fill, d[0].trace.fillcolor);
shape.call(Color.fill, d[0].trace.fillcolor);
}
catch(e) {
console.log(e,s);
Expand Down Expand Up @@ -178,7 +183,7 @@ drawing.pointStyle = function(s, trace) {

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

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

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

if('mc' in d) fillColor = d.mcc = markerScale(d.mc);
else if(Array.isArray(marker.color)) fillColor = Plotly.Color.defaultLine;
else if(Array.isArray(marker.color)) fillColor = Color.defaultLine;
else fillColor = marker.color || 'rgba(0,0,0,0)';
}

var p = d3.select(this);
if(d.om) {
// open markers can't have zero linewidth, default to 1px,
// and use fill color as stroke color
p.call(Plotly.Color.stroke, fillColor)
p.call(Color.stroke, fillColor)
.style({
'stroke-width': (lineWidth||1) + 'px',
fill: 'none'
});
}
else {
p.style('stroke-width', lineWidth + 'px')
.call(Plotly.Color.fill, fillColor);
.call(Color.fill, fillColor);
if(lineWidth) {
p.call(Plotly.Color.stroke, lineColor);
p.call(Color.stroke, lineColor);
}
}
});
Expand All @@ -262,11 +267,11 @@ drawing.pointStyle = function(s, trace) {
// have a colorscale for it (ie mscl, mcmin, mcmax) - if we do, translate
// all numeric color values according to that scale
drawing.tryColorscale = function(cont, contIn, prefix) {
var colorArray = Plotly.Lib.nestedProperty(cont, prefix + 'color').get(),
scl = Plotly.Lib.nestedProperty(cont, prefix + 'colorscale').get(),
auto = Plotly.Lib.nestedProperty(cont, prefix + 'cauto').get(),
minProp = Plotly.Lib.nestedProperty(cont, prefix + 'cmin'),
maxProp = Plotly.Lib.nestedProperty(cont, prefix + 'cmax'),
var colorArray = Lib.nestedProperty(cont, prefix + 'color').get(),
scl = Lib.nestedProperty(cont, prefix + 'colorscale').get(),
auto = Lib.nestedProperty(cont, prefix + 'cauto').get(),
minProp = Lib.nestedProperty(cont, prefix + 'cmin'),
maxProp = Lib.nestedProperty(cont, prefix + 'cmax'),
min = minProp.get(),
max = maxProp.get();

Expand All @@ -287,12 +292,12 @@ drawing.tryColorscale = function(cont, contIn, prefix) {
}
minProp.set(min);
maxProp.set(max);
Plotly.Lib.nestedProperty(contIn, prefix + 'cmin').set(min);
Plotly.Lib.nestedProperty(contIn, prefix + 'cmax').set(max);
Lib.nestedProperty(contIn, prefix + 'cmin').set(min);
Lib.nestedProperty(contIn, prefix + 'cmax').set(max);
}
return Plotly.Colorscale.makeScaleFunction(scl, min, max);
return Colorscale.makeScaleFunction(scl, min, max);
}
else return Plotly.Lib.identity;
else return Lib.identity;
};

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

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

return Plotly.Lib.extendFlat({}, bb);
return Lib.extendFlat({}, bb);
};

/*
Expand Down