diff --git a/pygal/view.py b/pygal/view.py index 408a113..8f96572 100644 --- a/pygal/view.py +++ b/pygal/view.py @@ -381,7 +381,7 @@ class CompleteLogView(object):#combines all of the functionality of the other si self.ylog = ylog self.log_ymax = log10(self.box.ymax) if self.box.ymax > 0 else 0 self.log_ymin = log10(self.box.ymin) if self.box.ymin > 0 else 0 - elif ylog > 0 and ylog != False: + elif ylog > 0: self.ylog = ylog self.log_ymax = log(self.box.ymax, ylog) if self.box.ymax > 0 else 0 self.log_ymin = log(self.box.ymin, ylog) if self.box.ymin > 0 else 0 @@ -389,38 +389,52 @@ class CompleteLogView(object):#combines all of the functionality of the other si self.xlog = xlog self.log_xmax = log10(self.box.xmax) if self.box.xmax > 0 else 0 self.log_xmin = log10(self.box.xmin) if self.box.xmin > 0 else 0 - elif xlog > 0 and xlog is not False: + elif xlog > 0: self.xlog = xlog self.log_xmax = log(self.box.xmax, xlog) if self.box.xmax > 0 else 0 self.log_xmin = log(self.box.xmin, xlog) if self.box.xmin > 0 else 0 self.box.fix(False) - def x_or_y(self, x, y = False): - if y ^ self.vertical: - if self.xlog is False: - return self.width * (x - self.box.xmin) / self.box.width - else if x is None or x <= 0 or self.log_xmax - self.log_xmin == 0: - return 0 - else: - return (self.width * (log(x, self.xlog) - self.log_xmin)/ (self.log_xmax - self.log_xmin)) + def vertical_x(self, x): + if self.xlog is False: + return self.width * (x - self.box.xmin) / self.box.width + else if x is None or x <= 0 or self.log_xmax - self.log_xmin == 0: + return 0 + else if self.xlog == true or self.xlog == 10: + return (self.width * (log10(x) - self.log_xmin) / (self.log_xmax - self.log_xmin)) + else: + return (self.width * (log(x, self.xlog) - self.log_xmin)/ (self.log_xmax - self.log_xmin)) + + def horizontal_x(self, x): + if self.xlog is False: + return (self.height - self.height * (x - self.box.ymin) / self.box.height) + else if x is None or x <= 0 or self.log_xmax - self.log_xmin == 0: + return 0 + else if self.ylog == true or self.ylog == 10: + return self.height - self.height * (log10(x) - self.log_ymin) / (self.log_ymax - self.log_ymin)) + else: + return self.height - self.height * (log(x, self.ylog) - self.log_ymin) / (self.log_ymax - self.log_ymin)) + + def y(self, y): + if self.vertical: + return horizontal_x(y) + else: + return vertical_x(y) + + def x(self, x): + if self.vertical: + return vertical_x(x) else: - if self.xlog is False: - return (self.height - self.height * (x - self.box.ymin) / self.box.height) - else if x is None or x <= 0 or self.log_xmax - self.log_xmin == 0: - return 0 - else: - self.height - self.height * (log(x, self.ylog) - self.log_ymin) / (self.log_ymax - self.log_ymin)) - + return horizontal_x(x) def xlog(self, xlog): - if xlog <= 0: - self.xlog = False + if xlog < 0: return False self.xlog = xlog if self.xlog == true or self.xlog == 10: self.log_xmax = log10(self.box.xmax) if self.box.xmax > 0 else 0 self.log_xmin = log10(self.box.xmin) if self.box.xmin > 0 else 0 - else: + else if xlog != 0: self.log_xmax = log(self.box.xmax, self.xlog) if self.box.xmax > 0 else 0 self.log_xmin = log(self.box.xmin, self.xlog) if self.box.xmin > 0 else 0 return True @@ -455,14 +469,13 @@ class CompleteLogView(object):#combines all of the functionality of the other si self.log_swap() def ylog(self, ylog): - if ylog <= 0: - self.ylog = False + if ylog < 0: return False self.ylog = ylog if self.ylog == true or self.ylog == 10: self.log_ymax = log10(self.box.ymax) if self.box.ymax > 0 else 0 self.log_ymin = log10(self.box.ymin) if self.box.ymin > 0 else 0 - else: + else if ylog != 0: self.log_ymax = log(self.box.ymax, self.ylog) if self.box.ymax > 0 else 0 self.log_ymin = log(self.box.ymin, self.ylog) if self.box.ymin > 0 else 0 return True