 class Simulation
 
     constructor: ->
-
-        xm = 0
-        ym = 0.275
-
-        #@p = new Plot(xm, ym)
         @sun = new Sun
         #@h = new Histo
         

    width = 480 - margin.left - margin.right
    height = 480 - margin.top - margin.bottom
    
    constructor: (@xm=0, @ym=0) ->

        super "plot"
        chartArea = @obj
        chartArea.attr("width", width + margin.left + margin.right)
        chartArea.attr("height", height + margin.top + margin.bottom)
        chartArea.attr("class","chart")
        chartArea.attr("id", "chartArea")

        @obj.append("g") # x axis
            .attr("class", "axis")
                .attr("transform", "translate(#{margin.left}, #{margin.top-10})")
            .call(@xAxis) 

        @obj.append("g") # y axis
            .attr("class", "axis")
            .attr("transform","translate(#{margin.left+width+10}, #{margin.top})")
            .call(@yAxis) 

        @plot = @obj.append("g") # Plot area
            .attr("id", "plot")
            .attr("transform", "translate(#{margin.left},#{margin.top})")

        Xm = Trans.x2X(@xm)
        Ym = Trans.y2Y(@ym)

        @marker0 = @marker('black')
        @marker0.attr("cx", Xm)
        @marker0.attr("cy", Ym)

        @l1 = @roofLine(-0.5, -0.5)
        @l1.attr("x2", Xm)
        @l1.attr("y2", Ym)

        @l2 = @roofLine(0.5, 0.5)
        @l2.attr("x2", Xm)
        @l2.attr("y2", Ym)

    roofFn: (x) ->
        xm = Trans.X2x(@marker0.attr('cx'))
        ym = Trans.Y2y(@marker0.attr('cy'))
        #(x<0)*(-0.5+(x+0.5)*(2*ym+1)/(2*xm+1)) + (x>=0)*(ym+(x-xm)*(1-2*ym)/(1-2*xm))
        Trans.fn(x, xm, ym)

    roofLine: (xFixed, yFixed) ->
        @plot.append("line")
            .attr("x1", @xScale xFixed)
            .attr("y1", @yScale yFixed)
            .style("stroke", 'black')
            .style("stroke-width","1")

    marker: (color) ->
        m = @plot.append("circle")
            .attr("r",10)
            .style("fill", color)
            .style("stroke", color)
            .style("stroke-width","1")
            .call(
                d3.behavior
                .drag()

        @element.selectAll("svg").remove()
        @obj = @element.append "svg"
        @initAxes()

    append: (obj) -> @obj.append obj
    
    initAxes: ->
