- # Determine indices of no-NAs days followed by no-NAs tomorrows
- fdays = getNoNA2(data, 1, dateIndexToInteger(index,data)-1)
- # Series + tomorrows in columns, ref_serie first
- centered_series = data$getCenteredSeries(fdays)
-
- # Obtain neighbors (closest for euclidian norm)
- L = length(ref_serie)
- distances = sqrt( colSums( (centered_series - ref_serie)^2 / L ) )
- sorted_distances = sort(distances, index.return=TRUE)
-
- # Compute colors for each neighbor (from darkest to lightest)
- nn = min(limit, length(distances))
- min_dist = min(sorted_distances$x[1:nn])
- max_dist = max(sorted_distances$x[1:nn])
- color_values = floor( 19.5 * (sorted_distances$x[1:nn]-min_dist) / (max_dist-min_dist) ) + 1
- colors = gray.colors(20,0.1,0.9)[color_values] #TODO: 20 == magic number
+ nn <- min(limit, length(weights))
+ sorted_dists = sort(-log(weights), index.return=TRUE)
+ # Compute colors for each neighbor (from darkest to lightest), if weights differ
+ if ( any( weights != weights[1] ) )
+ {
+ min_dist = min(sorted_dists$x[1:nn])
+ max_dist = max(sorted_dists$x[1:nn])
+ color_values = floor(19.5*(sorted_dists$x[1:nn]-min_dist)/(max_dist-min_dist)) + 1
+ colors = gray.colors(20,0.1,0.9)[color_values] #TODO: 20 == magic number
+ }
+ else
+ colors <- rep(colors()[17], length(weights))