1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 """Utility functions used by L{InvientCharts} to write its state to
16 the UIDL stream. The state includes properties of L{InvientCharts} such
17 as L{InvientChartsConfig}, L{Series}, L{Point} and various chart events.
18
19 In general, only non-null properties/attributes of a chart are written to
20 the UIDL stream.
21
22 @author: Invient
23 @author: Richard Lincoln
24 """
25
26 from datetime \
27 import datetime
28
29 from muntjac.util \
30 import totalseconds
31
32 from muntjac.addon.invient.invient_charts_config \
33 import AreaConfig, AreaSplineConfig, DateTimeRange, DateTimeValue, \
34 Grid, NumberRange, NumberValue, Tick, BarConfig, CategoryAxis, \
35 ColumnConfig, DateTimeAxis, ImageMarker, LineConfig, \
36 NonLinearSeriesState, NumberAxis, NumberXAxis, NumberYAxis, PieConfig, \
37 PieDataLabel, ScatterConfig, SplineConfig, SymbolMarker, XAxisDataLabel
38
39
62
63
65 """Writes configuration attributes of the chart title.
66
67 @param target
68 @param titleOptions
69 @throws PaintException
70 """
71 target.startTag('title')
72 writeTitleBaseOptions(target, titleOptions)
73 if titleOptions.getMargin() is not None:
74 target.addAttribute('margin', titleOptions.getMargin())
75 target.endTag('title')
76
77
79 """Writes configuration attributes of the chart subtitle. Only those
80 attributes are written who have got non-null values.
81
82 @param target
83 @param subtitleOptions
84 @throws PaintException
85 """
86 target.startTag('subtitle')
87 writeTitleBaseOptions(target, subtitleOptions)
88 target.endTag('subtitle')
89
90
127
128
130 """Writes configuration attributes of the chart legend.
131
132 @param target
133 @param legendOptions
134 @throws PaintException
135 """
136 target.startTag('legend')
137 if legendOptions.getBackgroundColor() is not None:
138 target.addAttribute('backgroundColor',
139 legendOptions.getBackgroundColor().getString())
140 if legendOptions.getBorderColor() is not None:
141 target.addAttribute('borderColor',
142 legendOptions.getBorderColor().getString())
143 if legendOptions.getBorderRadius() is not None:
144 target.addAttribute('borderRadius',
145 legendOptions.getBorderRadius())
146 if legendOptions.getBorderWidth() is not None:
147 target.addAttribute('borderWidth', legendOptions.getBorderWidth())
148 if legendOptions.getEnabled() is not None:
149 target.addAttribute('enabled', legendOptions.getEnabled())
150 if legendOptions.getFloating() is not None:
151 target.addAttribute('floating', legendOptions.getFloating())
152 if legendOptions.getItemHiddenStyle() is not None:
153 target.addAttribute('itemHiddenStyle',
154 legendOptions.getItemHiddenStyle())
155 if legendOptions.getItemHoverStyle() is not None:
156 target.addAttribute('itemHoverStyle',
157 legendOptions.getItemHoverStyle())
158 if legendOptions.getItemStyle() is not None:
159 target.addAttribute('itemStyle', legendOptions.getItemStyle())
160 if legendOptions.getItemWidth() is not None:
161 target.addAttribute('itemWidth', legendOptions.getItemWidth())
162 if legendOptions.getLayout() is not None:
163 target.addAttribute('layout', legendOptions.getLayout().getName())
164 if legendOptions.getLabelFormatterJsFunc() is not None:
165 target.addAttribute('labelFormatter',
166 legendOptions.getLabelFormatterJsFunc())
167 if legendOptions.getMargin() is not None:
168 target.addAttribute('margin', legendOptions.getMargin())
169 if legendOptions.getReversed() is not None:
170 target.addAttribute('reversed', legendOptions.getReversed())
171 if legendOptions.getShadow() is not None:
172 target.addAttribute('shadow', legendOptions.getShadow())
173 if legendOptions.getSymbolPadding() is not None:
174 target.addAttribute('symbolPadding',
175 legendOptions.getSymbolPadding())
176 if legendOptions.getSymbolWidth() is not None:
177 target.addAttribute('symbolWidth', legendOptions.getSymbolWidth())
178 if legendOptions.getWidth() is not None:
179 target.addAttribute('width', legendOptions.getWidth())
180 if legendOptions.getPosition() is not None:
181 if legendOptions.getPosition().getAlign() is not None:
182 target.addAttribute('align',
183 legendOptions.getPosition().getAlign().getName())
184 if legendOptions.getPosition().getVertAlign() is not None:
185 target.addAttribute('verticalAlign',
186 legendOptions.getPosition().getVertAlign().getName())
187 if legendOptions.getPosition().getX() is not None:
188 target.addAttribute('x', legendOptions.getPosition().getX())
189 if legendOptions.getPosition().getY() is not None:
190 target.addAttribute('y', legendOptions.getPosition().getY())
191 target.endTag('legend')
192
193
229
230
232 """Writes configuration attributes of the chart itself.
233
234 @param target
235 @param chartOptions
236 @throws PaintException
237 """
238 target.startTag('chart')
239 if chartOptions.getType() is not None:
240 target.addAttribute('type', chartOptions.getType().getName())
241 if chartOptions.getWidth() is not None:
242 target.addAttribute('width', chartOptions.getWidth())
243 if chartOptions.getHeight() is not None:
244 target.addAttribute('height', chartOptions.getHeight())
245 if chartOptions.getBackgroundColor() is not None:
246 target.addAttribute('backgroundColor',
247 chartOptions.getBackgroundColor().getString())
248 if chartOptions.getBorderColor() is not None:
249 target.addAttribute('borderColor',
250 chartOptions.getBorderColor().getString())
251 if chartOptions.getBorderRadius() is not None:
252 target.addAttribute('borderRadius', chartOptions.getBorderRadius())
253 if chartOptions.getBorderWidth() is not None:
254 target.addAttribute('borderWidth', chartOptions.getBorderWidth())
255 if chartOptions.getIgnoreHiddenSeries() is not None:
256 target.addAttribute('ignoreHiddenSeries',
257 chartOptions.getIgnoreHiddenSeries())
258 if chartOptions.getInverted() is not None:
259 target.addAttribute('inverted', chartOptions.getInverted())
260 if chartOptions.getMargin() is not None:
261 if chartOptions.getMargin().getTop() is not None:
262 target.addAttribute('marginTop',
263 chartOptions.getMargin().getTop())
264 if chartOptions.getMargin().getLeft() is not None:
265 target.addAttribute('marginLeft',
266 chartOptions.getMargin().getLeft())
267 if chartOptions.getMargin().getBottom() is not None:
268 target.addAttribute('marginBottom',
269 chartOptions.getMargin().getBottom())
270 if chartOptions.getMargin().getRight() is not None:
271 target.addAttribute('marginRight',
272 chartOptions.getMargin().getRight())
273 if chartOptions.getSpacing() is not None:
274 if chartOptions.getSpacing().getTop() is not None:
275 target.addAttribute('spacingTop',
276 chartOptions.getSpacing().getTop())
277 if chartOptions.getSpacing().getLeft() is not None:
278 target.addAttribute('spacingLeft',
279 chartOptions.getSpacing().getLeft())
280 if chartOptions.getSpacing().getBottom() is not None:
281 target.addAttribute('spacingBottom',
282 chartOptions.getSpacing().getBottom())
283 if chartOptions.getSpacing().getRight() is not None:
284 target.addAttribute('spacingRight',
285 chartOptions.getSpacing().getRight())
286 if chartOptions.getShowAxes() is not None:
287 target.addAttribute('showAxes', chartOptions.getShowAxes())
288 if chartOptions.getZoomType() is not None:
289 target.addAttribute('zoomType',
290 chartOptions.getZoomType().getName())
291 target.addAttribute('clientZoom', chartOptions.isClientZoom())
292 if chartOptions.getAlignTicks() is not None:
293 target.addAttribute('alignTicks', chartOptions.getAlignTicks())
294 if chartOptions.getAnimation() is not None:
295 target.addAttribute('animation', chartOptions.getAnimation())
296 if chartOptions.getClassName() is not None:
297 target.addAttribute('className', chartOptions.getClassName())
298 if chartOptions.getPlot() is not None:
299 if chartOptions.getPlot().getBackgroundColor() is not None:
300 target.addAttribute('plotBackgroundColor',
301 chartOptions.getPlot().getBackgroundColor().getString())
302 if chartOptions.getPlot().getBorderColor() is not None:
303 target.addAttribute('plotBorderColor',
304 chartOptions.getPlot().getBorderColor().getString())
305 if chartOptions.getPlot().getBackgroundImage() is not None:
306 target.addAttribute('plotBackgroundImage',
307 chartOptions.getPlot().getBackgroundImage())
308 if chartOptions.getPlot().getBorderWidth() is not None:
309 target.addAttribute('plotBorderWidth',
310 chartOptions.getPlot().getBorderWidth())
311 if chartOptions.getPlot().getShadow() is not None:
312 target.addAttribute('plotShadow',
313 chartOptions.getPlot().getShadow())
314 if chartOptions.getReflow() is not None:
315 target.addAttribute('reflow', chartOptions.getReflow())
316 if chartOptions.getShadow() is not None:
317 target.addAttribute('shadow', chartOptions.getShadow())
318 if chartOptions.getStyle() is not None:
319 target.addAttribute('style', chartOptions.getStyle())
320 target.endTag('chart')
321
322
324 """Writes configuration attributes of every series type. The series
325 type can be one of the line, spline, scatter, area, areaspline, bar,
326 column and pie.
327
328 @param target
329 @param seriesOptions
330 @throws PaintException
331 """
332 target.startTag('seriesOptionsPerSeriesType')
333
334 for k, seriesEntryOptions in seriesOptions.iteritems():
335 tagName = k.getName()
336 target.startTag(tagName)
337
338 writeSeriesConfig(target, seriesEntryOptions)
339 target.endTag(tagName)
340 target.endTag('seriesOptionsPerSeriesType')
341
342
344 """Writes configuration attributes of a single series.
345
346 @param target
347 @param series
348 @raise PaintException:
349 """
350
351 if isinstance(series, LineConfig):
352 writeLineOptions(target, series)
353 elif isinstance(series, ScatterConfig):
354 writeScatterOptions(target, series)
355 elif isinstance(series, SplineConfig):
356 writeSplineOptions(target, series)
357 elif isinstance(series, AreaConfig):
358 writeAreaOptions(target, series)
359 elif isinstance(series, AreaSplineConfig):
360 writeAreaSplineOptions(target, series)
361 elif isinstance(series, ColumnConfig):
362 writeColumnOptions(target, series)
363 elif isinstance(series, BarConfig):
364 writeBarOptions(target, series)
365 elif isinstance(series, PieConfig):
366 writePieOptions(target, series)
367 else:
368
369 writeCommonSeriesOptions(target, series)
370
371
373 """Writes configuration attributes common to all types of series.
374
375 @param target
376 @param seriesOptions
377 @throws PaintException
378 """
379 if seriesOptions.getAllowPointSelect() is not None:
380 target.addAttribute('allowPointSelect',
381 seriesOptions.getAllowPointSelect())
382 if seriesOptions.getAnimation() is not None:
383 target.addAttribute('animation',
384 seriesOptions.getAnimation())
385 if seriesOptions.getCursor() is not None:
386 target.addAttribute('cursor', seriesOptions.getCursor())
387 if seriesOptions.getColor() is not None:
388 target.addAttribute('color', seriesOptions.getColor().getString())
389 if seriesOptions.getEnableMouseTracking() is not None:
390 target.addAttribute('enableMouseTracking',
391 seriesOptions.getEnableMouseTracking())
392
393
394
395 if seriesOptions.getShowCheckbox() is not None:
396 target.addAttribute('showCheckbox',
397 seriesOptions.getShowCheckbox())
398 if seriesOptions.getShowInLegend() is not None:
399 target.addAttribute('showInLegend',
400 seriesOptions.getShowInLegend())
401 if seriesOptions.getStacking() is not None:
402 target.addAttribute('stacking',
403 seriesOptions.getStacking().getName())
404 if seriesOptions.getShadow() is not None:
405 target.addAttribute('shadow', seriesOptions.getShadow())
406 if seriesOptions.getVisible() is not None:
407 target.addAttribute('visible', seriesOptions.getVisible())
408
409 writeSeriesDataLabel(target, seriesOptions.getDataLabel())
410
411 writeSeriesState(target, seriesOptions.getHoverState())
412
413
433
434
436 """Writes configuration attributes common to all types of series. It
437 takes care of specific data labels in case of pie.
438
439 @param target
440 @param dataLabel
441 @raise PaintException
442 """
443 target.startTag('dataLabel')
444 if dataLabel is not None:
445 if isinstance(dataLabel, PieDataLabel):
446 writePieDataLabel(target, dataLabel)
447 else:
448 writeDataLabel(target, dataLabel)
449 target.endTag('dataLabel')
450
451
475
476
496
497
499 """Writes configuration attributes of an axis data labels.
500
501 @param target
502 @param dataLabel
503 @raise PaintException
504 """
505 writeDataLabel(target, dataLabel)
506 if dataLabel.getStep() is not None:
507 target.addAttribute('step', dataLabel.getStep())
508
509
511 """Writes configuration attributes of an x-axis data labels.
512
513 @param target
514 @param dataLabel
515 @raise PaintException
516 """
517 target.startTag('label')
518 if dataLabel is not None:
519 writeAxisDataLabel(target, dataLabel)
520 if dataLabel.getStaggerLines() is not None:
521 target.addAttribute('staggerLines',
522 dataLabel.getStaggerLines())
523 target.endTag('label')
524
525
527 """Writes configuration attributes of y-axis data labels.
528
529 @param target
530 @param dataLabel
531 @raise PaintException
532 """
533 target.startTag('label')
534 if dataLabel is not None:
535 writeAxisDataLabel(target, dataLabel)
536 target.endTag('label')
537
538
559
560
578
579
581 """Writes configuration attributes of an image marker
582
583 @param target
584 @param imgMarker
585 @raise PaintException
586 """
587 if imgMarker.getImageURL() is not None:
588 target.addAttribute('symbol', imgMarker.getImageURL())
589
590
613
614
634
635
659
660
662 """Writes configuration attributes of a spline series
663
664 @param target
665 @param splineOptions
666 @raise PaintException
667 """
668 writeBaseLineOptions(target, splineOptions)
669
670
672 """Writes configuration attributes of s scatter series
673
674 @param target
675 @param scatterOptions
676 @raise PaintException
677 """
678 writeBaseLineOptions(target, scatterOptions)
679
680
682 """Writes configuration attributes of a line series
683
684 @param target
685 @param lineOptions
686 @raise PaintException
687 """
688 writeBaseLineOptions(target, lineOptions)
689 if lineOptions.getStep() is not None:
690 target.addAttribute('step', lineOptions.getStep())
691
692
711
712
714 """Writes configuration attributes of an area-spline
715
716 @param target
717 @param areaSplineOptions
718 @raise PaintException
719 """
720 writeAreaOptions(target, areaSplineOptions)
721
722
746
747
781
782
784 """Writes configuration attributes of a bar series
785
786 @param target
787 @param barOptions
788 @raise PaintException
789 """
790 writeBaseBarOptions(target, barOptions)
791
792
794 """Writes configuration attributes of a column series
795
796 @param target
797 @param columnOptions
798 @raise PaintException
799 """
800 writeBaseBarOptions(target, columnOptions)
801
802
803 -def writeSeries(target, chartSeriesType, data, xAxes, yAxes):
804 """Writes data of each series of the chart. It transforms data into
805 a form which is usable by the Muntjac terminal class. It also writes
806 configuration attributes specific to each series, if any.
807
808 @param target
809 @param chartSeriesType
810 @param data
811 @param xAxes
812 @param yAxes
813 @throws PaintException
814 """
815 if data is None:
816 return
817 for series in data:
818 target.startTag('series')
819 if series.getName() is not None and len(series.getName()) > 0:
820 target.addAttribute('name', series.getName())
821 if series.getType() is not None:
822 target.addAttribute('type', series.getType().getName())
823 if series.getStack() is not None and len(series.getStack()) > 0:
824 target.addAttribute('stack', series.getStack())
825 target.addAttribute('xAxis', getXAxisIndex(series.getXAxis(),
826 xAxes))
827 target.addAttribute('yAxis', getYAxisIndex(series.getYAxis(),
828 yAxes))
829 seriesOptionsTagName = chartSeriesType.getName()
830 if series.getType() is not None:
831 seriesOptionsTagName = series.getType().getName()
832 target.startTag(seriesOptionsTagName)
833 if series.getConfig() is not None:
834 writeSeriesConfig(target, series.getConfig())
835 target.endTag(seriesOptionsTagName)
836 target.startTag('points')
837 if series.getPoints() is not None:
838 writePoints(target, series.getPoints())
839 target.endTag('points')
840 target.endTag('series')
841
842
844 """Writes point data (x, y) and its configuration attributes, if any.
845 If a point does not have x and y values then the point is skipped.
846 However, for such points empty tags is created without any attributes
847 or children.
848
849 @param target
850 @param points
851 @throws PaintException
852 """
853 from muntjac.addon.invient.invient_charts import DecimalPoint
854
855 if points is None:
856 return
857 for point in points:
858 target.startTag('point')
859 if (point.getX() is not None) or (point.getY() is not None):
860 if point.getId() is not None and len(point.getId()) > 0:
861 target.addAttribute('id', point.getId())
862 if point.getName() is not None and len(point.getName()) > 0:
863 target.addAttribute('name', point.getName())
864 if point.getX() is not None:
865 if isinstance(point, DecimalPoint):
866 target.addAttribute('x', float(point.getX()))
867 else:
868 target.addAttribute('x', getDate(point.getX(),
869 point.getSeries().isIncludeTime()))
870
871 if point.getY() is not None:
872 target.addAttribute('y', float(point.getY()))
873
874 target.addAttribute('isShift', point.isShift())
875
876
877 if point.getConfig() is not None:
878 if point.getConfig().getSliced() is not None:
879 target.addAttribute('sliced',
880 point.getConfig().getSliced())
881 if point.getConfig().getSelected() is not None:
882 target.addAttribute('selected',
883 point.getConfig().getSelected())
884 if point.getConfig().getColor() is not None:
885 target.addAttribute('color',
886 point.getConfig().getColor().getString())
887 if point.getConfig().getMarker() is not None:
888 writeMarkerOptions(target,
889 point.getConfig().getMarker())
890 target.endTag('point')
891
892
894 """Writes configuration attributes common to all types of axis.
895
896 @param target
897 @param axis
898 @param axes
899 @throws PaintException
900 """
901 if axis.getAlternateGridColor() is not None:
902 target.addAttribute('alternateGridColor',
903 axis.getAlternateGridColor().getString())
904 if axis.getEndOnTick() is not None:
905 target.addAttribute('endOnTick', axis.getEndOnTick())
906 if axis.getGrid() is not None:
907 writeAxisGrid(target, axis.getGrid())
908 if axis.getId() is not None and len(axis.getId()) > 0:
909 target.addAttribute('id', axis.getId())
910 if axis.getLineColor() is not None:
911 target.addAttribute('lineColor', axis.getLineColor().getString())
912 if axis.getLineWidth() is not None:
913 target.addAttribute('lineWidth', axis.getLineWidth())
914 if axis.getLinkedTo() is not None:
915 target.addAttribute('linkedTo',
916 getAxisIndex(axis.getLinkedTo(), axes))
917 if axis.getMaxPadding() is not None:
918 target.addAttribute('maxPadding', axis.getMaxPadding())
919 if axis.getMaxZoom() is not None:
920 target.addAttribute('maxZoom', axis.getMaxZoom())
921 if axis.getMinPadding() is not None:
922 target.addAttribute('minPadding', axis.getMinPadding())
923 if axis.getMinorGrid() is not None:
924 writeAxisMinorGrid(target, axis.getMinorGrid())
925 if axis.getMinorTick() is not None:
926 writeAxisMinorTick(target, axis.getMinorTick())
927 if axis.getOffset() is not None:
928 target.addAttribute('offset', axis.getOffset())
929 if axis.getOpposite() is not None:
930 target.addAttribute('opposite', axis.getOpposite())
931 if axis.getReversed() is not None:
932 target.addAttribute('reversed', axis.getReversed())
933 if axis.getShowFirstLabel() is not None:
934 target.addAttribute('showFirstLabel', axis.getShowFirstLabel())
935 if axis.getShowLastLabel() is not None:
936 target.addAttribute('showLastLabel', axis.getShowLastLabel())
937 if axis.getStartOfWeek() is not None:
938 target.addAttribute('startOfWeek', axis.getStartOfWeek().ordinal())
939 if axis.getStartOnTick() is not None:
940 target.addAttribute('startOnTick', axis.getStartOnTick())
941 if axis.getTick() is not None:
942 writeAxisTick(target, axis.getTick())
943 if axis.getType() is not None:
944 target.addAttribute('type', axis.getType().getName())
945
946
947 writeAxisTitle(target, axis.getTitle())
948
949
950 if isinstance(axis.getLabel(), XAxisDataLabel):
951 writeXAxisDataLabel(target, axis.getLabel())
952 else:
953 writeYAxisDataLabel(target, axis.getLabel())
954
955 if isinstance(axis, NumberAxis):
956 writePlotBands(target, axis.getPlotBands())
957 writePlotLines(target, axis.getPlotLines())
958 elif isinstance(axis, DateTimeAxis):
959 writePlotBands(target, axis.getPlotBands())
960 writePlotLines(target, axis.getPlotLines())
961 elif isinstance(axis, CategoryAxis):
962 writePlotBands(target, axis.getPlotBands())
963 writePlotLines(target, axis.getPlotLines())
964
965
967 """Returns an index of an x-axis in a list of x-axis only if the
968 x-axis exists otherwise null
969
970 @param indexOfXAxis
971 @param xAxes
972 @return: Retrieves Retrieves an index of an x-axis in a list of x-axis
973 only if the x-axis exists otherwise null
974 """
975 return getAxisIndex(indexOfXAxis, xAxes)
976
977
979 """Returns an index of a y-axis in a list of y-axis only if the y-axis
980 exists otherwise null
981
982 @param indexOfYAxis
983 @param yAxes
984 @return: Returns index of a y-axis in a list of y-axis only if the
985 y-axis exists otherwise null
986 """
987 return getAxisIndex(indexOfYAxis, yAxes)
988
989
991 """Returns an index of an axis in a list of axis only if the axis
992 exists otherwise null
993
994 @param indexOfAxis
995 @param axes
996 @return: Returns an index of an axis in a list of axis only if the
997 axis exists otherwise null
998 """
999 if ((indexOfAxis is None) or (axes is None)) or (len(axes) == 0):
1000 return 0
1001
1002 index = 0
1003 for axis in axes:
1004 if axis == indexOfAxis:
1005 return index
1006 index += 1
1007
1008 return None
1009
1010
1034
1035
1064
1065
1067 """Writes from/to value for a plotband. It considers date and number
1068 values separately.
1069
1070 @param target
1071 @param plotBandRange
1072 @throws PaintException
1073 """
1074 target.startTag('rangeValue')
1075 if plotBandRange is not None:
1076 if isinstance(plotBandRange, NumberRange):
1077 target.addAttribute('valueType', 'number')
1078 numberRange = plotBandRange
1079 if numberRange.getFrom() is not None:
1080 target.addAttribute('from', numberRange.getFrom())
1081 if numberRange.getTo() is not None:
1082 target.addAttribute('to', numberRange.getTo())
1083 elif isinstance(plotBandRange, DateTimeRange):
1084 target.addAttribute('valueType', 'date')
1085 dateRange = plotBandRange
1086 target.startTag('from')
1087 if dateRange.getFrom() is not None:
1088 target.addAttribute('year',
1089 getYearFromDate(dateRange.getFrom()))
1090 target.addAttribute('month',
1091 getMonthFromDate(dateRange.getFrom()))
1092 target.addAttribute('day',
1093 getDayFromDate(dateRange.getFrom()))
1094 target.endTag('from')
1095 target.startTag('to')
1096 if dateRange.getTo() is not None:
1097 target.addAttribute('year',
1098 getYearFromDate(dateRange.getTo()))
1099 target.addAttribute('month',
1100 getMonthFromDate(dateRange.getTo()))
1101 target.addAttribute('day',
1102 getDayFromDate(dateRange.getTo()))
1103 target.endTag('to')
1104 target.endTag('rangeValue')
1105
1106
1134
1135
1158
1159
1167
1168
1170 """Writes configuration attributes of an axis. Depending on type of
1171 the argument tick, it either writes attributes for L{MinorTick} or
1172 L{Tick}
1173
1174 @param target
1175 @param tick
1176 @raise PaintException
1177 """
1178 attNameColor = 'minorTickColor'
1179 attNameInterval = 'minorTickInterval'
1180 attNameLength = 'minorTickLength'
1181 attNamePosition = 'minorTickPosition'
1182 attNameWidth = 'minorTickWidth'
1183 if isinstance(tick, Tick):
1184 attNameColor = 'tickColor'
1185 attNameInterval = 'tickInterval'
1186 attNameLength = 'tickLength'
1187 attNamePosition = 'tickPosition'
1188 attNameWidth = 'tickWidth'
1189 if tick.getColor() is not None:
1190 target.addAttribute(attNameColor, tick.getColor().getString())
1191 if tick.getInterval() is not None:
1192 target.addAttribute(attNameInterval, tick.getInterval())
1193 if tick.getLength() is not None:
1194 target.addAttribute(attNameLength, tick.getLength())
1195 if tick.getPosition() is not None:
1196 target.addAttribute(attNamePosition, tick.getPosition().getName())
1197 if tick.getWidth() is not None:
1198 target.addAttribute(attNameWidth, tick.getWidth())
1199
1200
1203
1204
1206 """Writes configuration attributes of an axis. Depending on type of
1207 the argument tick, it either writes attributes for L{MinorGrid} or
1208 L{Grid}
1209
1210 @param target
1211 @param grid
1212 @raise PaintException
1213 """
1214 attNameLineColor = 'minorGridLineColor'
1215 attNameLineWidth = 'minorGridLineWidth'
1216 attNameLineDashStyle = 'minorGridLineDashStyle'
1217 if isinstance(grid, Grid):
1218 attNameLineColor = 'gridLineColor'
1219 attNameLineWidth = 'gridLineWidth'
1220 attNameLineDashStyle = 'gridLineDashStyle'
1221 if grid.getLineColor() is not None:
1222 target.addAttribute(attNameLineColor,
1223 grid.getLineColor().getString())
1224 if grid.getLineWidth() is not None:
1225 target.addAttribute(attNameLineWidth, grid.getLineWidth())
1226 if grid.getLineDashStyle() is not None:
1227 target.addAttribute(attNameLineDashStyle,
1228 grid.getLineDashStyle().getName())
1229
1230
1245
1246
1248 """Iteratively processes each x-axis and writes configuration
1249 attributes of each axis based on type of the axis e.g. L{NumberAxis},
1250 L{DateTimeAxis} and L{CategoryAxis}
1251
1252 @param target
1253 @param axes
1254 @raise PaintException
1255 """
1256 target.startTag('xAxes')
1257 if axes is not None:
1258 for xAxis in axes:
1259 target.startTag('xAxis')
1260 writeBaseAxis(target, xAxis, axes)
1261 if isinstance(xAxis, NumberXAxis):
1262 writeNumberAxis(target, xAxis)
1263 elif isinstance(xAxis, CategoryAxis):
1264 writeCategoryAxis(target, xAxis)
1265 elif isinstance(xAxis, DateTimeAxis):
1266
1267
1268 writeDateTimeAxis(target, xAxis,
1269 isIncludeTime(xAxis,
1270 config.getInvientCharts().getAllSeries()))
1271 target.endTag('xAxis')
1272 target.endTag('xAxes')
1273
1274
1284
1285
1293
1294
1295 -def getDate(dt, isIncludeTime=False):
1296 """Returns milliseconds of the date argument dt. If the argument
1297 isIncludeTime is false then the returned milliseconds does not include
1298 time.
1299 """
1300 if not isIncludeTime:
1301 dt2 = datetime(dt.year, dt.month, dt.day)
1302 dt = dt2
1303 return long(totalseconds(dt - datetime(1970, 1, 1)) * 1e03)
1304
1305
1307 """@param target
1308 @param dateTimeAxis
1309 @raise PaintException
1310 """
1311 if dateTimeAxis.getMax() is not None:
1312 target.addAttribute('max', getDate(dateTimeAxis.getMax(),
1313 isIncludeTime))
1314 if dateTimeAxis.getMin() is not None:
1315 target.addAttribute('min', getDate(dateTimeAxis.getMin(),
1316 isIncludeTime))
1317 if dateTimeAxis.getDateTimeLabelFormat() is not None:
1318 target.startTag('dateTimeLabelFormats')
1319 dateTimeLabelFormat = dateTimeAxis.getDateTimeLabelFormat()
1320 if dateTimeLabelFormat.getSecond() is not None:
1321 target.addAttribute('second',
1322 dateTimeAxis.getDateTimeLabelFormat().getSecond())
1323 if dateTimeLabelFormat.getMinute() is not None:
1324 target.addAttribute('minute',
1325 dateTimeAxis.getDateTimeLabelFormat().getMinute())
1326 if dateTimeLabelFormat.getHour() is not None:
1327 target.addAttribute('hour',
1328 dateTimeAxis.getDateTimeLabelFormat().getHour())
1329 if dateTimeLabelFormat.getDay() is not None:
1330 target.addAttribute('day',
1331 dateTimeAxis.getDateTimeLabelFormat().getDay())
1332 if dateTimeLabelFormat.getWeek() is not None:
1333 target.addAttribute('week',
1334 dateTimeAxis.getDateTimeLabelFormat().getWeek())
1335 if dateTimeLabelFormat.getMonth() is not None:
1336 target.addAttribute('month',
1337 dateTimeAxis.getDateTimeLabelFormat().getMonth())
1338 if dateTimeLabelFormat.getYear() is not None:
1339 target.addAttribute('year',
1340 dateTimeAxis.getDateTimeLabelFormat().getYear())
1341 target.endTag('dateTimeLabelFormats')
1342
1343
1353
1354
1365
1366
1387
1388
1390 """@return: Returns year of the argument date."""
1391 if date is None:
1392 return None
1393 return str(date.year)
1394
1395
1397 """@return: Returns month of the argument date. The returned values
1398 is based on zero-index i.e. for month January, the values
1399 returned is "0"
1400 """
1401 if date is None:
1402 return None
1403 return str(date.month - 1)
1404
1405
1407 if date is None:
1408 return None
1409 return str(date.day)
1410
1411
1413 """Writes information about which series were added, removed or
1414 updated. This information is used by Muntjac terminal class to decide
1415 whether to add a new series or remove/delete an existing series.
1416 Basically, this information helps client to update only a portion of
1417 the chart instead of full chart.
1418 """
1419 for seriesName in seriesCURMap.keys():
1420 seriesCURSet = seriesCURMap.get(seriesName)
1421 if seriesCURSet is not None and len(seriesCURSet) > 0:
1422 for seriesCUR in seriesCURSet:
1423 target.startTag('seriesDataUpdate')
1424 target.addAttribute('seriesName', seriesCUR.getName())
1425 target.addAttribute('operation',
1426 seriesCUR.getType().getName())
1427 target.addAttribute('isReloadPoints',
1428 seriesCUR.isReloadPoints())
1429 target.startTag('pointsAdded')
1430 if len(seriesCUR.getPointsAdded()) > 0:
1431 writePoints(target, seriesCUR.getPointsAdded())
1432 target.endTag('pointsAdded')
1433 target.startTag('pointsRemoved')
1434 if len(seriesCUR.getPointsRemoved()) > 0:
1435 writePoints(target, seriesCUR.getPointsRemoved())
1436 target.endTag('pointsRemoved')
1437 target.endTag('seriesDataUpdate')
1438