Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more gchart update

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@1486 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information...
commit b8dc2acc460bc513154eea670628d461701a30d5 1 parent 99b4d3d
lkcl authored
View
53 examples/gcharttestapp/GChartExample04.py
@@ -0,0 +1,53 @@
+import math
+
+from pyjamas.chart.GChart import GChart
+from pyjamas.chart import GChartUtil
+
+# GWT 1.4's Math class does not include JDK's
+# Math.log10--so emulate it.
+def log10(x):
+ return math.log(x)/math.log(10.0)
+
+"""*
+* Defines a traditional "semi-log" chart by using custom
+* ticks on the y axis, in conjunction with log-transformed
+* y data.
+"""
+class GChartExample04(GChart):
+ def __init__(self):
+ GChart.__init__(self, 300, 450)
+ self.setChartTitle("<h2>2<sup>x</sup> vs x</h2>")
+ self.addCurve()
+ self.getCurve().getSymbol().setHovertextTemplate(
+ GChartUtil.formatAsHovertext("${y}=2^${x}"))
+ self.getCurve().setLegendLabel("<b>2<sup>x</sup></b>")
+ self.getCurve().getSymbol().setBackgroundColor("red")
+ self.getCurve().getSymbol().setBorderColor("black")
+ self.getCurve().getSymbol().setWidth(9)
+ self.getCurve().getSymbol().setHeight(9)
+
+ # add (log10-transformed) powers of 2 from 1/4 to 8
+ for i in range(-2, 4):
+ self.getCurve().addPoint(i,log10(math.pow(2,i)))
+
+ # GChart's "=10^" NumberFormat prefix inverts the log10
+ # transform
+ self.getYAxis().setTickLabelFormat("=10^#.##")
+ # add conventional log-scaled ticks from .1 to 10
+ self.getYAxis().addTick(log10(0.1))
+ x = 0.1
+ while x < 10:
+ for y in range(2, 11):
+ self.getYAxis().addTick(log10(x*y))
+ x *= 10
+
+ self.getXAxis().setAxisLabel("<b>x</b>")
+ self.getXAxis().setHasGridlines(True)
+ self.getXAxis().setTickCount(6)
+
+ self.getYAxis().setAxisLabel("<b>2<sup>x</sup></b>")
+ self.getYAxis().setHasGridlines(True)
+
+
+
+
View
5 examples/gcharttestapp/GChartTestApp.py
@@ -13,6 +13,7 @@
from GChartExample01 import GChartExample01
from GChartExample02 import GChartExample02
from GChartExample03 import GChartExample03
+from GChartExample04 import GChartExample04
"""*
*
@@ -130,9 +131,9 @@ def onModuleLoad():
# addChart(GChartExample01a(0))
# addChart(GChartExample01b())
# addChart(GChartExample01c())
- addChart(GChartExample02())
+ #addChart(GChartExample02())
#addChart(GChartExample03())
- # addChart(GChartExample04())
+ addChart(GChartExample04())
# addChart(GChartExample04a())
# addChart(GChartExample04b())
# addChart(GChartExample05())
View
9 library/__safari__/pyjamas/Window.py
@@ -0,0 +1,9 @@
+def getDocumentRoot():
+ # Safari does not implement $doc.compatMode.
+ # Use a CSS test to determine rendering mode.
+ JS("""
+ var elem = $doc.createElement('div');
+ elem.style.cssText = "width:0px;width:1";
+ return parseInt(elem.style.width) != 1 ? $doc.documentElement :
+ $doc.body;
+ """)
View
11 library/pyjamas/Window.py
@@ -56,6 +56,17 @@ def getClientWidth():
except:
return doc().body.clientWidth;
+def getScrollLeft():
+ return getDocumentRoot().scrollLeft;
+
+def getScrollTop():
+ return getDocumentRoot().scrollTop;
+
+def getDocumentRoot():
+ if doc().compatMode == 'CSS1Compat':
+ return doc().documentElement
+ return doc().body
+
def setLocation(url):
w = wnd()
w.location = url
View
6 library/pyjamas/chart/Axis.py
@@ -1546,7 +1546,7 @@ def setTickLabelFormat(self, format):
self.chartDecorationsChanged = True
if format.startswith("=(Date)"):
- transFormat = format.find("=(Date)".length())
+ transFormat = format[len("=(Date)"):]
if transFormat.equals(""):
# so "=(Date)" works
self.dateFormat = DateTimeFormat.getShortDateTimeFormat()
@@ -1557,12 +1557,12 @@ def setTickLabelFormat(self, format):
self.tickLabelFormatType = DATE_FORMAT_TYPE
elif format.startswith("=10^"):
- transFormat = format.find("=10^".length())
+ transFormat = format[len("=10^"):]
self.numberFormat = NumberFormat.getFormat(transFormat)
self.tickLabelFormatType = LOG10INVERSE_FORMAT_TYPE
elif format.startswith("=2^"):
- transFormat = format.find("=2^".length())
+ transFormat = format[len("=2^"):]
self.numberFormat = NumberFormat.getFormat(transFormat)
self.tickLabelFormatType = LOG2INVERSE_FORMAT_TYPE
View
32 library/pyjamas/chart/GChartWidgets.py
@@ -1201,7 +1201,8 @@ def setClientX(self, clientX, isClick):
if (GChart.NAI == clientX):
self.xMouse = GChart.NAI
else:
- self.xMouse = (Window.getScrollLeft() + clientX - getAbsoluteLeft())
+ self.xMouse = (Window.getScrollLeft() + clientX -
+ self.getAbsoluteLeft())
def getClientY(self):
return self.clientY
@@ -1218,7 +1219,8 @@ def setClientY(self, clientY, isClick):
if (GChart.NAI == clientY):
self.yMouse = GChart.NAI
else:
- self.yMouse = (Window.getScrollTop() + clientY - getAbsoluteTop())
+ self.yMouse = (Window.getScrollTop() + clientY -
+ self.getAbsoluteTop())
"""
@@ -1908,16 +1910,16 @@ def takesUsCompletelyOutsideChart(self, event):
result = False
elif self.isGeometricallyContainedIn(self.getElement(),
- event.getClientX(),
- event.getClientY()):
+ DOM.eventGetClientX(event),
+ DOM.eventGetClientY(event)):
result = False
else:
hoverElement = self.getOpenedHoverElement()
if None != hoverElement:
if self.isGeometricallyContainedIn(hoverElement,
- event.getClientX(),
- event.getClientY()):
+ DOM.eventGetClientX(event),
+ DOM.eventGetClientY(event)):
result = False
@@ -2067,10 +2069,11 @@ def onBrowserEvent(self, event):
"""
if self.chart.getHoverTouchingEnabled() or isClick:
- self.setClientX(event.getClientX(), isClick)
- self.setClientY(event.getClientY(), isClick)
- if not self.isUpdateNeeded() and self.touchObjectAtMousePosition(isClick):
- self.assembleChart()
+ self.setClientX(DOM.eventGetClientX(event), isClick)
+ self.setClientY(DOM.eventGetClientY(event), isClick)
+ if (not self.chart.isUpdateNeeded() and
+ self.touchObjectAtMousePosition(isClick)):
+ self.chart.assembleChart()
@@ -2081,8 +2084,9 @@ def onBrowserEvent(self, event):
# " event.getTarget()=" + event.getTarget())
self.setClientX(GChart.NAI, False); # mouse not over chart,
self.setClientY(GChart.NAI, False); # so position is undefined
- if not self.isUpdateNeeded() and self.touchObjectAtMousePosition():
- self.assembleChart()
+ if (not self.chart.isUpdateNeeded() and
+ self.touchObjectAtMousePosition()):
+ self.chart.assembleChart()
@@ -2094,8 +2098,8 @@ def onBrowserEvent(self, event):
def isValidated(self):
result = True
i = 0
- while result and i < curves.size():
- result = curves.get(i).isValidated()
+ while result and i < len(self.chart.curves):
+ result = self.chart.curves[i].isValidated()
i += 1
return result
View
16 library/pyjamas/chart/SymbolType.py
@@ -607,16 +607,16 @@ def getEdgeOppositeVertically(self, pp, symbol, y, onY2):
nextYPx = Double.NaN
height = symbol.getHeight(pp, onY2)
- symHeight = getAdjustedHeight(height, yPx,
- prevYPx, nextYPx, yMinPx, yMaxPx, yMidPx)
+ symHeight = self.getAdjustedHeight(height, yPx,
+ prevYPx, nextYPx, yMinPx, yMaxPx, yMidPx)
if (Double.isNaN(symHeight)):
return Double.NaN
- yTop = getUpperLeftY(height, yPx,
- prevYPx, nextYPx,
- yMinPx, yMaxPx, yMidPx,
- pp.getYMousePlotArea())
+ yTop = self.getUpperLeftY(height, yPx,
+ prevYPx, nextYPx,
+ yMinPx, yMaxPx, yMidPx,
+ pp.getYMousePlotArea())
if (Double.isNaN(yTop)):
return Double.NaN
@@ -700,13 +700,13 @@ def isIntersecting13(self, pp, symbol, prevX, x, nextX, prevY, y,
nextYPx = pp.yToPixel(nextY, onY2)
height = symbol.getHeight(pp, onY2)
- symHeight = getAdjustedHeight(height, yPx,
+ symHeight = self.getAdjustedHeight(height, yPx,
prevYPx, nextYPx, yMinPx, yMaxPx, yMidPx)
if (Double.isNaN(symHeight)):
return False
- yTop = getUpperLeftY(height, yPx,
+ yTop = self.getUpperLeftY(height, yPx,
prevYPx, nextYPx,
yMinPx, yMaxPx, yMidPx,
pp.getYMousePlotArea())
Please sign in to comment.
Something went wrong with that request. Please try again.