0

I am using coffeescript to render a plot graph. I had previously posted a question about setting up the conditionals; which I believe is now solved. However, the variable curr_visibility, used for one of the conditionals, is causing an issue I think, because it is not defined correctly. The graph plot essentially works like this; a 0 (not visible) or 1 (visible) is assigned to each point on the graph (the points are used to draw a line that is essentially a terrain profile coming from a map using a DEM image). I am attaching a screenshot which illustrates my bug (LV = lastVisibilty and CV = curr_visibility). The variable curr_visibility is inside a for loop. I need to make sure that it is updated after each iteration, but I am just not sure it is set up properly to work inside my fillColor: if conditional statement. the code starts with two empty sets- line = [] and datasets = [] Plot graph showing the bug. The area between LV and CV should be red for No visibility

prev_visibility = data[0].visibility
        for elem, index in data
            curr_visibility = elem.visibility

            point = [
                index
                elem.geometry[2]
            ]

            line.push point
            unless prev_visibility is curr_visibility
                datasets.push line
                line = [point]
                prev_visibility = curr_visibility

        datasets.push line

        line = []
        lastVisibility = data[0].visibility

        newfillColor = if lastVisibilty == 0 && curr_visibility == 0
                "#C90E30"
            else if lastVisibilty == 0 && curr_visibility == 1
                "#439C32"
            else if lastVisibilty == 1 && curr_visibility == 0
                "#C90E30"
            else
                "#439C32"

        for set in datasets
            line.push 
                data: set,
                lines:
                    show: true
                    fill: true
                    opacity: 0.7
                    fillColor: newfillColor

            lastVisibility = 1 - lastVisibility    

1 Answer 1

1

OK, with the help of a coworker, I was able to resolve this issue. First, in the code above, every instance of the variable prev_visibility was removed. It was determined not to be necessary. Second, we determined that index method needed to be utilized to relate to a new variable, next_visibility, that would compare the current visibility value of a point to that of the next for every iteration (I hope I'm explaining this correctly). To do this, we added the following:

line.push point
if (index + 1) < data.length
    next_visibility = data[index + 1].visibility
else
    next_visibility = curr_visibility

unless next_visibility is curr_visibility
    datasets.push line
    line = [point]

Finally, all of the newFillColor stuff was removed and I reverted back to fillColor: if lastVisibility is 0 then "#C90E30" else "439C32"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.