Skip to content
This repository has been archived by the owner on Dec 17, 2017. It is now read-only.

Commit

Permalink
Merge pull request #45 from anchor/bugfixes
Browse files Browse the repository at this point in the history
Misc Bugfixes
  • Loading branch information
glasnt committed Sep 8, 2014
2 parents db8583d + cfefe5c commit d9b5d50
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gvb_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-rc2
1.0.0-rc3
37 changes: 34 additions & 3 deletions app/assets/javascripts/graphs/stacked.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ function renderStacked(data) {

min = Number.MAX_VALUE; max = Number.MIN_VALUE;

if (config.renderer == "line") { pad = 1} else {pad = 0}
// Padding - depending on the domain, both scalar and ratio padding are used. So set both.
var scalarPad = 1
var ratioPad = 0.1

if (config.renderer != "line") { scalarPad = 0 }

left_range = [min,max];
right_range = [min,max];
Expand All @@ -76,16 +80,19 @@ function renderStacked(data) {
}
}
if (isRight(n)) {
right_range = [ Math.min(min, right_range[0]) - pad , Math.max(max, right_range[1]) + pad ];
right_range = [ Math.min(min, right_range[0]), Math.max(max, right_range[1])];
} else {
left_range = [ Math.min(min, left_range[0]) - pad, Math.max(max, left_range[1]) + pad ];
left_range = [ Math.min(min, left_range[0]), Math.max(max, left_range[1])];
}
}

if (hasRight()) {
right_range = [right_range[0] - scalarPad, right_range[1] + scalarPad] //Scalar Padding
right_scale = d3.scale.linear().domain(right_range);
}

if (hasLeft()) {
left_range = [left_range[0] - scalarPad, left_range[1] + scalarPad] //Scalar Padding
left_scale = d3.scale.linear().domain(left_range);
}

Expand All @@ -98,6 +105,7 @@ function renderStacked(data) {
} else {
scale = left_scale;
}

series.push({
color: colours[n],
data: data[n].data,
Expand All @@ -109,6 +117,29 @@ function renderStacked(data) {
// Finally, make the chart
config.interpolate = "monotone";


//Ratio Padding - defaults from rickshaw.js
padY = 0.02
padX = 0

if (hasRight() && hasLeft() ) {
d = [Math.min(left_scale.domain()[0], right_scale.domain()[0]),
Math.max(left_scale.domain()[1], right_scale.domain()[1])]
} else if (hasRight()) {
d = right_scale.domain()
} else {
d = left_scale.domain()
}

if (d[0] >= -2 && d[1] <= 2) { // -1 -> 1, plus scalar padding
padY = ratioPadding
}

padArray = {top: padY, right: padX, bottom: padY, left: padX}

config.padding = padArray

// ...
if (flag == "xkcd") {
config.interpolate = "xkcd";
}
Expand Down
26 changes: 14 additions & 12 deletions app/controllers/graphs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@ def index
# Get all the metrics, and build up a javascript blob with their useful bits
new_metrics = que_qs(:metric)
gon.metrics = []

@metrics = new_metrics.map{|m| Metric.new(m)}

new_metrics.each_with_index{|mstr, i|
g = {}
g[:id] = @metrics[i].id
g[:feed] = @metrics[i].feed
g[:live] = @metrics[i].live?
g[:sourceURL] = @metrics[i].get_metric_url start, stop, step
g[:removeURL] = rem_qs(:metric, mstr)

@metrics = []

new_metrics.each do |metric|
m = Metric.new(metric)
@metrics << m

g = {}
g[:id] = m.id
g[:feed] = m.feed
g[:live] = m.live?
g[:sourceURL] = m.get_metric_url start, stop, step
g[:removeURL] = rem_qs(:metric, metric)
# g[:counter] = true if m.counter? ##TODO Incorporate vaultaire based metadata

gon.metrics << g
}
end

@gon = gon

Expand Down
11 changes: 11 additions & 0 deletions lib/errorstore.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Errorstore < Store
def get_metric _,_,_,_
raise Store::Error, "Invalid origin: '#{@origin_id}' not defined in settings"
end
def get_metric_url _,_,_,_
""
end
def get_metric_list
[]
end
end
8 changes: 7 additions & 1 deletion lib/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'net/http'
require 'uri'
require 'ostruct'
# Library filers file
module Helpers

Expand All @@ -25,7 +26,12 @@ def is_up? uri=@base_url

# Given an origin ID, find the key/value in the settings file and return it, plus the search key
def origin_settings ostr
Settings.origins.find{|o,k| o.to_s == ostr.to_s}
settings = Settings.origins.find{|o,k| o.to_s == ostr.to_s}
unless settings
# Use a Error store, default Source if no settings found
return [ostr,OpenStruct.new({store: "Errorstore", source: "Source"})]
end
settings
end

# Take a string of SEP, KVP, and DELIM ops and split it into a nice hash
Expand Down
17 changes: 11 additions & 6 deletions lib/vaultaire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ def initialize origin, settings
# Sieste can be used to query for a metric's metadata based on it's origin and metric_id alone
def metadata metric_id
r = get_json("#{@base_url}/simple/search?origin=#{@origin_id}&address=#{metric_id}").first
return machiavelli_encode(r)
return machiavelli_encode(r) if r
return metric_id
end

# Split the metadata into nice pieces and make a HTML table.
def metadata_table metric
# TODO function assumes origin within metadatastring, formats out weird without it
ret = URI.decode(metric).strip
sep = [[SEP,"</td></tr><tr><td>"],[KVP,"</td><td> - "],[DELIM,"</td></tr><tr><td>"]]
sep.each {|a| ret.gsub!(a[0],a[1])}
'<table style="text-align: left"><tr><td colspan=2>'+ret+'</table>'
t = URI.decode(metric).strip.split(DELIM).map{|a| a.split(KVP)}

table = ""
t.each {|a|
table += "<tr><td>"+a[0]+"</td><td> = "+a[1]+"</td></tr>"
}

header = "<tr><td>#{@origin_id}</td><td> - #{self.class.name}</td></tr>"
return "<table style='text-align: left'>#{header}#{table}</table>"
end

# Convert a string into a uri-transferable sieste metric
Expand Down
27 changes: 19 additions & 8 deletions vendor/assets/javascripts/select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ the specific language governing permissions and limitations under the Apache Lic
dest.attr("class", replacements.join(" "));
}

// Extended to match multiple terms, delimited by space
// Extended to match multiple terms, delimited by space
function markMatch(text, term, markup, escapeMarkup) {
var text_ = stripDiacritics(text.toUpperCase())
var term_ = stripDiacritics(term.toUpperCase())
Expand All @@ -376,19 +376,19 @@ the specific language governing permissions and limitations under the Apache Lic

var start = 0
$.each(terms, function(i, t) {
var x = text_.substring(start, text_.length).indexOf(t) + start
index.push([x, t.length]);
start = x+t.length

var hits = indiciesOf(text_,t);
$.each(hits, function(i, x) { index.push([x, t.length]) })
})

if (index.length === 0) {
markup.push(escapeMarkup(text));
return;
}

index = index.sort(function(a,b){return a-b});

var point = 0
$.each(index, function(i, pair) {
$.each(index, function(y, pair) {
var i = pair[0];
var len = pair[1];
markup.push(escapeMarkup(text.substring(point, i)));
Expand All @@ -401,6 +401,17 @@ the specific language governing permissions and limitations under the Apache Lic
markup.push(escapeMarkup(text.substring(point, text_.length)));
}

function indiciesOf(text, search) {
var start = 0;
var index, indices = []
while ((index = text.indexOf(search, start)) > -1) {
indices.push(index);
start = index + search.length;
}
return indices;
}


function defaultEscapeMarkup(markup) {
var replace_map = {
'\\': '&#92;',
Expand Down Expand Up @@ -3328,8 +3339,8 @@ the specific language governing permissions and limitations under the Apache Lic
formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " or more character" + (n == 1? "" : "s"); },
formatInputTooLong: function (input, max) { var n = input.length - max; return "Please delete " + n + " character" + (n == 1? "" : "s"); },
formatSelectionTooBig: function (limit) { return "You can only select " + limit + " item" + (limit == 1 ? "" : "s"); },
formatLoadMore: function (pageNumber) { return "."; },
formatSearching: function () { return "Searching"; },
formatLoadMore: function (pageNumber) { return "_"; },
formatSearching: function () { return "Searching..."; },
formatDropdownHeader: function () { return undefined; },
formatDropdownFooter: function () { return undefined; },
allowSelectAllNone: false,
Expand Down
1 change: 1 addition & 0 deletions vendor/assets/stylesheets/select2.css
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ disabled look for disabled choices in the results dropdown

.select2-more-results {
background: #f4f4f4;
color: #ffffff;
display: list-item;
}

Expand Down

0 comments on commit d9b5d50

Please sign in to comment.