<commit_before>var d3 = require('d3');

function min(a, b){ return a < b ? a : b ; }
function max(a, b){ return a > b ? a : b; }    

function Candlestick() {
  var data = null, 
      open = null, 
      high = null, 
      low = null, 
      close = null, 
      width = 1000, 
      height = 800,
      start, end,
      x = d3.scale.linear(),
      y = d3.scale.linear();

  function chart(selection) {
    chart.x = x;
    chart.y = y;

    chart.build.call(this, selection);
  }

  chart.build = function(selection) {

    var plot = selection.selectAll('g.candlestick-chart').data([1]).enter()
      .append('svg:g')
      .attr("class", "candlestick-chart")
      .attr("width", width)
      .attr("height", height);

    var plot = selection.selectAll('g.candlestick-chart');

    var domain = x.domain();
    var length = domain[1] - domain[0];
    var index = data.index;
    var bar_width = 0.5 * (width)/length;

    var range = d3.range(domain[0], domain[1]);
    candles = plot.selectAll("g.candlestick")
      .data(range).exit().remove()

    new_candles = plot.selectAll("g.candlestick")
      .data(range).enter().append("svg:g")
      .attr("class", "candlestick")

    new_candles.append("svg:line")
      .attr("class", "stem");
    new_candles.append("svg:rect");

    candles = plot.selectAll("g.candlestick").data(range);
    candles.attr("transform", function(d) {return "translate("+(x(d)-bar_width/2)+',0)'})

    candles.select('.stem')
      .attr("x1", bar_width / 2)
      .attr("x2", bar_width / 2)		    
      .attr("y1", function(d) { return y(high[d]);})
      .attr("y2", function(d) { return y(low[d]); })
      .attr("stroke", 'black')

    candles.select('rect')
      .attr("x", 0)
            .attr("y", function(d) {return y(max(open[d], close[d]));})		  
      .attr("height", function(d) { return y(min(open[d], close[d]))-y(max(open[d], close[d]));})
      .attr("width", bar_width)
            .attr("fill",function(d) { return open[d] > close[d] ? "red" : "green" ;});
  }

  chart.xview = function(domain) {
    if (!arguments.length) return x.domain();
    x.domain(domain);
    return chart;
  }<commit_msg>made candlestick wick change width with resize<commit_after>var d3 = require('d3');

function min(a, b){ return a < b ? a : b ; }
function max(a, b){ return a > b ? a : b; }    

function Candlestick() {
  var data = null, 
      open = null, 
      high = null, 
      low = null, 
      close = null, 
      width = 1000, 
      height = 800,
      start, end,
      x = d3.scale.linear(),
      y = d3.scale.linear();

  function chart(selection) {
    chart.x = x;
    chart.y = y;

    chart.build.call(this, selection);
  }

  chart.build = function(selection) {

    var plot = selection.selectAll('g.candlestick-chart').data([1]).enter()
      .append('svg:g')
      .attr("class", "candlestick-chart")
      .attr("width", width)
      .attr("height", height);

    var plot = selection.selectAll('g.candlestick-chart');

    var domain = x.domain();
    var length = domain[1] - domain[0];
    var index = data.index;
    var bar_width = 0.5 * (width)/length;

    var range = d3.range(domain[0], domain[1]);
    candles = plot.selectAll("g.candlestick")
      .data(range).exit().remove()

    new_candles = plot.selectAll("g.candlestick")
      .data(range).enter().append("svg:g")
      .attr("class", "candlestick")

    new_candles.append("svg:line")
      .attr("class", "stem");
    new_candles.append("svg:rect");

    candles = plot.selectAll("g.candlestick").data(range);
    candles.attr("transform", function(d) {return "translate("+(x(d)-bar_width/2)+',0)'})

    candles.select('.stem')
      .attr("x1", bar_width / 2)
      .attr("x2", bar_width / 2)		    
      .attr("y1", function(d) { return y(high[d]);})
      .attr("y2", function(d) { return y(low[d]); })
      .attr("stroke", 'black')
      .attr("stroke-width", max(bar_width / 14, 1))

    candles.select('rect')
      .attr("x", 0)
            .attr("y", function(d) {return y(max(open[d], close[d]));})		  
      .attr("height", function(d) { return y(min(open[d], close[d]))-y(max(open[d], close[d]));})
      .attr("width", bar_width)
            .attr("fill",function(d) { return open[d] > close[d] ? "red" : "green" ;});
  }

  chart.xview = function(domain) {
    if (!arguments.length) return x.domain();
    x.domain(domain);
    return chart;
  }
{'fraction_non_alphanumeric': 0.19927289252442626, 'fraction_numerical': 0.013406044080890706, 'mean_word_length': 2.752770673486786, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3903583', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1571, 'n_words': 308}