app/assets/javascripts/plasticine/line.coffee in plasticine-1.2.3 vs app/assets/javascripts/plasticine/line.coffee in plasticine-1.2.4

- old
+ new

@@ -1,17 +1,16 @@ class @PlasticineLine constructor: (@holder) -> @holder = $('.plasticine-line') + @holder.on('resize', (e) => @resizeX()) PlasticineHelpers.setLocale() - #@drawTooltip() @xScale = d3.scaleBand() @setXScaleRange() + @yScale = d3.scaleLinear().range([@holder.height(), @holder.data('lines-top-padding')]) - @yScale = d3.scaleLinear().range([@holder.height(),50]) - @setXAxis() @setYAxis() @legend = d3.select("##{@holder.attr('id')}").append('ul').attr('class', 'legend') @svg = d3.select("##{@holder.attr('id')}").append('svg').style('width', @holderWidth()).style('height', @holder.height()).append('g') @@ -50,17 +49,17 @@ stackedDataset[j]["y#{i+1}"] = d.y stack = d3.stack().keys(stackedKeys) series = stack(stackedDataset); - @chartPath = d3.area().curve(d3.curveCardinal) + @chartPath = d3.area().curve(d3.curveMonotoneX) .x( (d,i) => @xScale(stackedDataset[i].x) ) .y0( (d) => @yScale(d[0]) ) .y1( (d) => @yScale(d[1]) ) else series = data['lines'] - @chartPath = d3.line().curve(d3.curveCardinal) + @chartPath = d3.line().curve(d3.curveMonotoneX) .x( (d) => @xScale(d.x)) .y( (d) => @yScale(d.y)) @lines = @svg.append('g').attr('class', "elements #{@chartLayout}").selectAll('.element').data(series) @refreshLines() @@ -69,10 +68,12 @@ @drawLegend(data) d3.select(window).on("resize." + @holder.attr("id"), () => @resizeX()) refreshLines: () -> + self = this + $('g.element').remove() element = @lines.enter().append('g').attr('class', "element") element.append("path") .attr('class', 'line') @@ -82,10 +83,11 @@ drawLegend: (data) -> data['lines'].forEach (line) => @legend.append('li').html('<span></span>' + line.label) + drawXAxis: () -> height = @holder.height() @svg.append('g').attr('class', 'x axis') .attr('transform', 'translate(0,' + height + ')') .call @xAxis @@ -124,19 +126,17 @@ setXAxis: () -> @xAxis = d3.axisBottom(@xScale) @xAxis.tickSize -@holder.height() - switch @xAxisFormat - when 'date' then @xAxis.tickFormat(d3.timeFormat('%b')) - when 'day' then @xAxis.tickFormat(d3.timeFormat('%e-%m')) - when 'quarter' then @xAxis.tickFormat (d) => PlasticineHelpers.toQuarter(d, @quarterStartMonth) - when 'year' then @xAxis.tickFormat (d) => PlasticineHelpers.toYear(d, @quarterStartMonth) - when 'money' then @xAxis.tickFormat (d) => PlasticineHelpers.toPrice(d) - when 'numeric' then @xAxis.tickFormat (d) => PlasticineHelpers.toNumeric(d) + setXAxis: () -> + @xAxis = d3.axisBottom(@xScale) + @xAxis.tickSize -@holder.height() + PlasticineHelpers.setAxisFormat @xAxis, @xAxisFormat + setXScaleRange: () -> linesMargin = @holder.data('lines-margin') linesLeftPadding = @holder.data('lines-left-padding') linesRightPadding = @holder.data('lines-right-padding') width = @holderWidth() @@ -147,10 +147,6 @@ setYAxis: () -> @yAxis = d3.axisLeft(@yScale) @yAxis.tickSize -@holderWidth() @yAxis.ticks @yAxisTickCount - switch @yAxisFormat - when 'date' then @yAxis.tickFormat(d3.timeFormat('%b')) - when 'day' then @yAxis.tickFormat(d3.timeFormat('%e-%m')) - when 'money' then @yAxis.tickFormat (d) => PlasticineHelpers.toPrice(d) - when 'numeric' then @yAxis.tickFormat (d) => PlasticineHelpers.toNumeric(d) + PlasticineHelpers.setAxisFormat @yAxis, @yAxisFormat