var d3 = require('d3');
var fs = require('fs');
var _ = require('underscore');
var default_layout = require('./axes.js').default_layout;

// data
var content = fs.readFileSync('./df.json');
var df = JSON.parse(content);

_.each(df, function(arr, key) {
  if (!_.isArray(arr)) {
    return;
  }
  df[key] = _.last(arr, 1500);
});

var Figure = require('./figure.js');
var Line = require('./line.js');
var CandleStick = require('./candlestick.js');

var df2 = [];
var i = -1;
while (++i < df.high.length) {
  df2.push(df.high[i]+1);
}

var b = Line()
var line = Line().data(df2);
var line2 = Line().data(df.high);
console.log(line.size.toString());
var candle = CandleStick();

var WIDTH = 1400;
var HEIGHT = 800;
var padding = 50;

candle.data(df);

d3.selectAll('body svg').remove();
var svg = d3.select('body').append('svg:svg');
var focus_svg = d3.select('body').append('svg:svg').attr('class', 'focus');

line2.y.range([100, 0]);
line2.x.range([0, WIDTH]);

focus = Figure();
focus.margin(40).width(WIDTH).height(100).index(df.index);
focus(focus_svg);
focus.layer(line2, 'focus');
focus.redraw();

fig = Figure();
fig.margin(40).width(WIDTH).height(HEIGHT).index(df.index);
fig(svg);

var datax = d3.scale.linear().domain([0, df.index.length]).range([0, WIDTH]);
var brush = d3.svg.brush()
    .x(datax);
fig.x.attach(brush);

fig.layer(line, 'line');
fig.layer(line2, 'line2');
fig.layer(candle, 'candle');

fig.redraw();
fig.xchange([300, 400]);

default_layout(fig);

var context_div = focus_svg
  .append("g")
      .attr("class", "x brush")
      .call(brush)
    .selectAll("rect")
      .attr("y", -6)
      .attr("height", 100 + 7);


module.exports = null;

@@ -129,16 +129,36 @@
 _layout;
+%0Arequire('./brush');
 %0A%0A// dat
@@ -551,23 +551,8 @@
 %0A%7D%0A%0A
-var b = Line()%0A
 var 
@@ -614,43 +614,8 @@
 h);%0A
-console.log(line.size.toString());%0A
 var 
@@ -636,16 +636,25 @@
 eStick()
+.data(df)
 ;%0A%0Avar W
@@ -687,44 +687,8 @@
 800;
-%0Avar padding = 50;%0A%0Acandle.data(df);
 %0A%0Ad3
@@ -848,120 +848,78 @@
 );%0A%0A
-line2.y.range(%5B100, 0%5D);%0Aline2.x.range(%5B0, WIDTH%5D);%0A%0Afocus = Figure();%0Afocus.margin(40).width(WIDTH).height(100)
+focus = Figure();%0Afocus%0A  .width(1400)%0A  .height(100)%0A  .margin(40)%0A  
 .ind
@@ -932,16 +932,17 @@
 index);%0A
+%0A
 focus(fo
@@ -984,20 +984,31 @@
 ');%0A
-focus.redraw
+var brush = focus.brush
 ();%0A
@@ -1097,129 +1097,8 @@
 vg);
-%0A%0Avar datax = d3.scale.linear().domain(%5B0, df.index.length%5D).range(%5B0, WIDTH%5D);%0Avar brush = d3.svg.brush()%0A    .x(datax);
 %0Afig
@@ -1202,21 +1202,36 @@
 );%0A%0A
-fig.redraw();
+// default to only first 100
 %0Afig
@@ -1244,14 +1244,12 @@
 ge(%5B
-30
 0, 
-4
+1
 00%5D)
@@ -1277,180 +1277,8 @@
 );%0A%0A
-var context_div = focus_svg%0A  .append(%22g%22)%0A      .attr(%22class%22, %22x brush%22)%0A      .call(brush)%0A    .selectAll(%22rect%22)%0A      .attr(%22y%22, -6)%0A      .attr(%22height%22, 100 + 7);%0A%0A%0A
 modu

clean up test file