Skip to content

Commit 3684240

Browse files
committed
extracted out the model making
1 parent 6dfd319 commit 3684240

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

src/traces/parcoords/parcoords.js

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ var lineLayerMaker = require('./lines');
1212
var Lib = require('../../lib');
1313
var d3 = require('d3');
1414

15+
var overdrag = 40;
16+
var legendWidth = 80;
17+
1518
function keyFun(d) {return d.key;}
1619

1720
function repeat(d) {return [d];}
@@ -67,6 +70,55 @@ function domainToUnitScale(values) {
6770
return d3.scale.linear().domain(extent);
6871
}
6972

73+
function model(layout, d) {
74+
75+
var data = d.dimensions;
76+
77+
var canvasPixelRatio = d.lines.pixelratio;
78+
var lines = Lib.extendDeep(d.lines, {
79+
color: d.line.color.map(domainToUnitScale(d.line.color)),
80+
canvasOverdrag: overdrag * canvasPixelRatio
81+
});
82+
83+
var layoutWidth = layout.width * (d.domain.x[1] - d.domain.x[0]);
84+
var layoutHeight = layout.height * (d.domain.y[1] - d.domain.y[0]);
85+
86+
var padding = d.padding || 80;
87+
var translateX = (d.domain.x[0] || 0) * layout.width;
88+
var translateY = (d.domain.y[0] || 0) * layout.height;
89+
var width = layoutWidth - 2 * padding - legendWidth; // leavig room for the colorbar
90+
var height = layoutHeight - 2 * padding;
91+
92+
var canvasWidth = width * canvasPixelRatio + 2 * lines.canvasOverdrag;
93+
var canvasHeight = height * canvasPixelRatio;
94+
95+
var resizeHeight = d.filterbar.handleheight;
96+
var brushVisibleWidth = d.filterbar.width;
97+
var brushCaptureWidth = d.filterbar.capturewidth || Math.min(32, brushVisibleWidth + 16);
98+
99+
return [
100+
{
101+
key: Math.random(),
102+
dimensions: data,
103+
tickDistance: d.tickdistance,
104+
unitToColor: d.unitToColor,
105+
lines: lines,
106+
translateX: translateX,
107+
translateY: translateY,
108+
padding: padding,
109+
canvasWidth: canvasWidth,
110+
canvasHeight: canvasHeight,
111+
width: width,
112+
height: height,
113+
brushVisibleWidth: brushVisibleWidth,
114+
brushCaptureWidth: brushCaptureWidth,
115+
resizeHeight: resizeHeight,
116+
canvasPixelRatio: canvasPixelRatio,
117+
filterBar: d.filterbar
118+
}
119+
];
120+
}
121+
70122
function viewModel(model) {
71123

72124
var lines = model.lines;
@@ -128,58 +180,6 @@ function styleExtentTexts(selection) {
128180

129181
module.exports = function(root, styledData, layout, callbacks) {
130182

131-
var overdrag = 40;
132-
var legendWidth = 80;
133-
134-
function model(d) {
135-
136-
var data = d.dimensions;
137-
138-
var canvasPixelRatio = d.lines.pixelratio;
139-
var lines = Lib.extendDeep(d.lines, {
140-
color: d.line.color.map(domainToUnitScale(d.line.color)),
141-
canvasOverdrag: overdrag * canvasPixelRatio
142-
});
143-
144-
var layoutWidth = layout.width * (d.domain.x[1] - d.domain.x[0]);
145-
var layoutHeight = layout.height * (d.domain.y[1] - d.domain.y[0]);
146-
147-
var padding = d.padding || 80;
148-
var translateX = (d.domain.x[0] || 0) * layout.width;
149-
var translateY = (d.domain.y[0] || 0) * layout.height;
150-
var width = layoutWidth - 2 * padding - legendWidth; // leavig room for the colorbar
151-
var height = layoutHeight - 2 * padding;
152-
153-
var canvasWidth = width * canvasPixelRatio + 2 * lines.canvasOverdrag;
154-
var canvasHeight = height * canvasPixelRatio;
155-
156-
var resizeHeight = d.filterbar.handleheight;
157-
var brushVisibleWidth = d.filterbar.width;
158-
var brushCaptureWidth = d.filterbar.capturewidth || Math.min(32, brushVisibleWidth + 16);
159-
160-
return [
161-
{
162-
key: Math.random(),
163-
dimensions: data,
164-
tickDistance: d.tickdistance,
165-
unitToColor: d.unitToColor,
166-
lines: lines,
167-
translateX: translateX,
168-
translateY: translateY,
169-
padding: padding,
170-
canvasWidth: canvasWidth,
171-
canvasHeight: canvasHeight,
172-
width: width,
173-
height: height,
174-
brushVisibleWidth: brushVisibleWidth,
175-
brushCaptureWidth: brushCaptureWidth,
176-
resizeHeight: resizeHeight,
177-
canvasPixelRatio: canvasPixelRatio,
178-
filterBar: d.filterbar
179-
}
180-
];
181-
}
182-
183183
function enterSvgDefs(root) {
184184
var defs = root.selectAll('defs')
185185
.data(repeat, keyFun);
@@ -215,7 +215,7 @@ module.exports = function(root, styledData, layout, callbacks) {
215215
}
216216

217217
var parcoordsModel = d3.select(root).selectAll('.parcoordsModel')
218-
.data(model(styledData), keyFun);
218+
.data(model(layout, styledData), keyFun);
219219

220220
parcoordsModel.enter()
221221
.append('div')

0 commit comments

Comments
 (0)