diff --git a/app/assets/javascripts/pb_graph.coffee b/app/assets/javascripts/pb_graph.coffee index 49695d74..aba4a1ca 100644 --- a/app/assets/javascripts/pb_graph.coffee +++ b/app/assets/javascripts/pb_graph.coffee @@ -1,7 +1,14 @@ $ -> - if not gon.run.raw_splits? + if $("#pb-graph").length is 0 return - default_color = $(".timeline").children(".split").first().css("background-color") + + color_styles = [] + for sheet in document.styleSheets + continue if not sheet.cssRules? + for rule in sheet.cssRules + for color in gon.run.colors + if rule.selectorText? and color is rule.selectorText + color_styles.push rule.style["background"] pb_graph_data = ["PB - Gold"] pb_graph_ticks = [] @@ -16,8 +23,8 @@ $ -> data: { columns: [pb_graph_data], type: "bar", - color: (color, d) -> return default_color }, + color: { pattern: color_styles }, axis: { x: { type: "category", diff --git a/app/assets/javascripts/reset_graph.coffee b/app/assets/javascripts/reset_graph.coffee index dfcf71e1..7a1c2018 100644 --- a/app/assets/javascripts/reset_graph.coffee +++ b/app/assets/javascripts/reset_graph.coffee @@ -1,12 +1,14 @@ $ -> - if gon.run.program isnt "livesplit" + if $("#reset-graph").length is 0 or gon.run.program isnt "livesplit" return - colors_obj = {} - $(".timeline").children(".split").each (index) -> - color = $(this).css("background-color") - return if color is "rgba(0, 0, 0, 0)" - colors_obj[$(this).children()[0].innerHTML] = color + color_styles = [] + for sheet in document.styleSheets + continue if not sheet.cssRules? + for rule in sheet.cssRules + for color in gon.run.colors + if rule.selectorText? and color is rule.selectorText + color_styles.push rule.style["background"] reset_counter = gon.run.attempts reset_data = [] @@ -20,8 +22,8 @@ $ -> data: { columns: reset_data, type: "donut", - color: (color, d) -> return if d.id then color else colors_obj[d] }, + color: { pattern: color_styles }, donut: { title: "Resets/Split", label: { format: (v) -> return v } diff --git a/app/assets/javascripts/run_duration_graph.coffee b/app/assets/javascripts/run_duration_graph.coffee index 783b1dfe..0406d99d 100644 --- a/app/assets/javascripts/run_duration_graph.coffee +++ b/app/assets/javascripts/run_duration_graph.coffee @@ -1,8 +1,14 @@ $ -> - if gon.run.program isnt "livesplit" + if $("#run-duration-graph").length is 0 or gon.run.program isnt "livesplit" return - default_color = $(".timeline").children(".split").first().css("background-color") + color_styles = [] + for sheet in document.styleSheets + continue if not sheet.cssRules? + for rule in sheet.cssRules + for color in gon.run.colors + if rule.selectorText? and color is rule.selectorText + color_styles.push rule.style["background"] duration_data = gon.run.history.map((time) -> return time) duration_data.unshift "Run Length" @@ -11,8 +17,8 @@ $ -> title: { text: "Run Duration Over Time" } data: { columns: [duration_data], - color: (color, d) -> return default_color }, + color: { pattern: color_styles }, axis: { x: { type: "category", diff --git a/app/assets/javascripts/segment_history_graph.coffee b/app/assets/javascripts/segment_history_graph.coffee index 82c6a4cf..a09f4a6f 100644 --- a/app/assets/javascripts/segment_history_graph.coffee +++ b/app/assets/javascripts/segment_history_graph.coffee @@ -1,12 +1,14 @@ $ -> - if gon.run.program isnt "livesplit" + if $("#segment-duration-graph").length is 0 or gon.run.program isnt "livesplit" return - colors_obj = {} - $(".timeline").children(".split").each (index) -> - color = $(this).css("background-color") - return if color is "rgba(0, 0, 0, 0)" - colors_obj[$(this).children()[0].innerHTML] = color + color_styles = [] + for sheet in document.styleSheets + continue if not sheet.cssRules? + for rule in sheet.cssRules + for color in gon.run.colors + if rule.selectorText? and color is rule.selectorText + color_styles.push rule.style["background"] seg_histories = [] $.each gon.run.raw_splits, (i, split) -> @@ -17,8 +19,8 @@ $ -> title: { text: "Segment Histories Over Time"}, data: { columns: seg_histories, - color: (color, d) -> return if d.id then colors_obj[d.id] else colors_obj[d] - } + }, + color: { pattern: color_styles }, axis: { x: { type: "category", diff --git a/app/assets/javascripts/segment_mean_graph.coffee b/app/assets/javascripts/segment_mean_graph.coffee index 9e7491aa..3da58390 100644 --- a/app/assets/javascripts/segment_mean_graph.coffee +++ b/app/assets/javascripts/segment_mean_graph.coffee @@ -1,8 +1,16 @@ $ -> - if gon.run.program isnt "livesplit" + if $("#split-history-graph").length is 0 or gon.run.program isnt "livesplit" return - default_color = $(".timeline").children(".split").first().css("background-color") + color_styles = [] + for sheet in document.styleSheets + continue if not sheet.cssRules? + for rule in sheet.cssRules + for color in gon.run.colors + if rule.selectorText? and color is rule.selectorText + color_styles.push rule.style["background"] + + default_color = color_styles[0] split_history_data = ["Mean - Gold"] split_history_ticks = [] @@ -19,8 +27,8 @@ $ -> data: { columns: [split_history_data], type: "bar", - color: (color, d) -> return default_color }, + color: { pattern: color_styles }, axis: { x: { type: "category", diff --git a/app/helpers/runs_helper.rb b/app/helpers/runs_helper.rb index dec808d6..9b99d652 100644 --- a/app/helpers/runs_helper.rb +++ b/app/helpers/runs_helper.rb @@ -1,6 +1,10 @@ module RunsHelper TIMELINE_COLORS = [:blue, :purple, :green, :yellow, :red, :orange] + GRAPH_COLORS = [ + ".blue", ".purple", ".green", ".red", ".orange", + ".light-blue", ".light-purple", ".light-green", ".light-red", ".light-orange" + ] def difference(run_a, run_b) if run_a.nil? || run_b.nil?