ruby_pptx 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +98 -0
- data/README.md +94 -4
- data/lib/ruby_pptx/action.rb +12 -4
- data/lib/ruby_pptx/autoshape_spec.rb +6 -2
- data/lib/ruby_pptx/builder.rb +3 -1
- data/lib/ruby_pptx/chart/categories.rb +45 -15
- data/lib/ruby_pptx/chart/chart.rb +168 -31
- data/lib/ruby_pptx/chart/combo.rb +19 -4
- data/lib/ruby_pptx/chart/data.rb +45 -15
- data/lib/ruby_pptx/chart/format.rb +229 -76
- data/lib/ruby_pptx/chart/workbook_writer.rb +9 -3
- data/lib/ruby_pptx/chart/xml_writer.rb +54 -18
- data/lib/ruby_pptx/chart/xy_data.rb +68 -22
- data/lib/ruby_pptx/dml/color.rb +27 -9
- data/lib/ruby_pptx/dml/effect.rb +6 -2
- data/lib/ruby_pptx/dml/fill.rb +42 -14
- data/lib/ruby_pptx/element_proxy.rb +12 -4
- data/lib/ruby_pptx/enum/base.rb +30 -10
- data/lib/ruby_pptx/enum/prog_id.rb +3 -1
- data/lib/ruby_pptx/geometry.rb +32 -10
- data/lib/ruby_pptx/image.rb +27 -9
- data/lib/ruby_pptx/length.rb +94 -27
- data/lib/ruby_pptx/media.rb +12 -4
- data/lib/ruby_pptx/numeric_lengths.rb +34 -9
- data/lib/ruby_pptx/opc/oxml.rb +7 -5
- data/lib/ruby_pptx/opc/pack_uri.rb +15 -5
- data/lib/ruby_pptx/opc/package.rb +97 -31
- data/lib/ruby_pptx/opc/serialized.rb +15 -5
- data/lib/ruby_pptx/oxml/backend.rb +585 -0
- data/lib/ruby_pptx/oxml/chart.rb +112 -42
- data/lib/ruby_pptx/oxml/content_model.rb +6 -2
- data/lib/ruby_pptx/oxml/dml/color.rb +6 -2
- data/lib/ruby_pptx/oxml/dml/fill.rb +6 -2
- data/lib/ruby_pptx/oxml/element.rb +138 -101
- data/lib/ruby_pptx/oxml/ns.rb +7 -7
- data/lib/ruby_pptx/oxml/presentation.rb +9 -3
- data/lib/ruby_pptx/oxml/section.rb +3 -1
- data/lib/ruby_pptx/oxml/shapes/autoshape.rb +39 -13
- data/lib/ruby_pptx/oxml/shapes/groupshape.rb +15 -7
- data/lib/ruby_pptx/oxml/shapes/other.rb +47 -16
- data/lib/ruby_pptx/oxml/shapes/shared.rb +96 -30
- data/lib/ruby_pptx/oxml/simple_types.rb +169 -52
- data/lib/ruby_pptx/oxml/slide.rb +25 -8
- data/lib/ruby_pptx/oxml/table.rb +39 -13
- data/lib/ruby_pptx/oxml/text.rb +122 -16
- data/lib/ruby_pptx/oxml/theme.rb +13 -4
- data/lib/ruby_pptx/package.rb +9 -3
- data/lib/ruby_pptx/parts/chart.rb +6 -2
- data/lib/ruby_pptx/parts/image.rb +12 -4
- data/lib/ruby_pptx/parts/media.rb +3 -1
- data/lib/ruby_pptx/parts/presentation.rb +15 -5
- data/lib/ruby_pptx/parts/slide.rb +33 -11
- data/lib/ruby_pptx/parts/theme.rb +3 -1
- data/lib/ruby_pptx/pattern_matching.rb +6 -2
- data/lib/ruby_pptx/presentation.rb +24 -8
- data/lib/ruby_pptx/section.rb +30 -10
- data/lib/ruby_pptx/shapes/adjustments.rb +9 -3
- data/lib/ruby_pptx/shapes/authoring.rb +3 -1
- data/lib/ruby_pptx/shapes/base.rb +74 -24
- data/lib/ruby_pptx/shapes/freeform.rb +36 -12
- data/lib/ruby_pptx/shapes/placeholder.rb +44 -15
- data/lib/ruby_pptx/shapes/shape.rb +91 -30
- data/lib/ruby_pptx/shapes/shape_tree.rb +235 -121
- data/lib/ruby_pptx/slide.rb +137 -46
- data/lib/ruby_pptx/table.rb +105 -35
- data/lib/ruby_pptx/text/font_metrics.rb +30 -9
- data/lib/ruby_pptx/text/list_style.rb +88 -0
- data/lib/ruby_pptx/text/text.rb +241 -59
- data/lib/ruby_pptx/theme.rb +30 -10
- data/lib/ruby_pptx/version.rb +1 -1
- data/lib/ruby_pptx.rb +9 -1
- metadata +24 -2
|
@@ -31,10 +31,14 @@ module Pptx
|
|
|
31
31
|
# python-pptx's PlotTypeInspector does.
|
|
32
32
|
#
|
|
33
33
|
# @return [Pptx::Enum::Member] a member of XL_CHART_TYPE
|
|
34
|
-
def chart_type
|
|
34
|
+
def chart_type
|
|
35
|
+
ChartTypeInspector.chart_type(plot_area.plot_elements.first)
|
|
36
|
+
end
|
|
35
37
|
|
|
36
38
|
# The chart style number, 1 to 48, or nil when none is set.
|
|
37
|
-
def chart_style
|
|
39
|
+
def chart_style
|
|
40
|
+
@element.style&.val
|
|
41
|
+
end
|
|
38
42
|
|
|
39
43
|
def chart_style=(value)
|
|
40
44
|
@element.remove_style
|
|
@@ -42,7 +46,9 @@ module Pptx
|
|
|
42
46
|
end
|
|
43
47
|
|
|
44
48
|
# The default font for all text in the chart, created on first use.
|
|
45
|
-
def font
|
|
49
|
+
def font
|
|
50
|
+
@font ||= Font.new(@element.defRPr)
|
|
51
|
+
end
|
|
46
52
|
|
|
47
53
|
# Every series in the chart: plot by plot, and within a plot in the order
|
|
48
54
|
# it draws them.
|
|
@@ -55,9 +61,22 @@ module Pptx
|
|
|
55
61
|
# Replace this chart's categories and series with those in +chart_data+.
|
|
56
62
|
#
|
|
57
63
|
# Series-level formatting is left alone. If there are more series than
|
|
58
|
-
# before, the extra ones are cloned from the last series
|
|
59
|
-
#
|
|
60
|
-
#
|
|
64
|
+
# before, the extra ones are cloned from the last series so they inherit
|
|
65
|
+
# its formatting; if fewer, the surplus is removed from the end.
|
|
66
|
+
#
|
|
67
|
+
# The new series are matched to the existing ones in document order, plot
|
|
68
|
+
# by plot. On a chart with more than one plot (a combo chart) the series
|
|
69
|
+
# count must therefore stay the same: adding or dropping series would
|
|
70
|
+
# silently move series between plots or remove a plot with its axis and
|
|
71
|
+
# formatting, so it raises {Pptx::Error} instead.
|
|
72
|
+
#
|
|
73
|
+
# A category chart (bar, line, pie, area, ...) takes {ChartData}; a
|
|
74
|
+
# scatter chart takes {XyChartData} and a bubble chart {BubbleChartData}.
|
|
75
|
+
# Passing the wrong kind raises {Pptx::Error} rather than writing a
|
|
76
|
+
# series PowerPoint cannot read.
|
|
77
|
+
#
|
|
78
|
+
# @raise [Pptx::Error] for a data kind the chart cannot hold, or a series
|
|
79
|
+
# count change on a multi-plot chart
|
|
61
80
|
def replace_data(chart_data)
|
|
62
81
|
SeriesRewriter.new(chart_data).rewrite(@element)
|
|
63
82
|
part.workbook.replace_with(chart_data.xlsx_blob)
|
|
@@ -65,7 +84,9 @@ module Pptx
|
|
|
65
84
|
end
|
|
66
85
|
|
|
67
86
|
# Whether a legend is drawn.
|
|
68
|
-
def legend?
|
|
87
|
+
def legend?
|
|
88
|
+
!chart_element.legend.nil?
|
|
89
|
+
end
|
|
69
90
|
|
|
70
91
|
def legend=(value)
|
|
71
92
|
value ? chart_element.get_or_add_legend : chart_element.remove_legend
|
|
@@ -78,7 +99,9 @@ module Pptx
|
|
|
78
99
|
element.nil? ? nil : (@legend ||= ChartLegend.new(element))
|
|
79
100
|
end
|
|
80
101
|
|
|
81
|
-
def title?
|
|
102
|
+
def title?
|
|
103
|
+
!chart_element.title.nil?
|
|
104
|
+
end
|
|
82
105
|
|
|
83
106
|
# @return [ChartTitle, nil]
|
|
84
107
|
def title
|
|
@@ -105,7 +128,9 @@ module Pptx
|
|
|
105
128
|
#
|
|
106
129
|
# Nearly every chart has exactly one; a combo chart has several, which is
|
|
107
130
|
# why this is a collection rather than a property of the chart.
|
|
108
|
-
def plots
|
|
131
|
+
def plots
|
|
132
|
+
plot_area.plot_elements.map { |element| ChartPlot.new(element, self) }
|
|
133
|
+
end
|
|
109
134
|
|
|
110
135
|
# The horizontal axis: a category or date axis, or, on an XY or bubble
|
|
111
136
|
# chart, the first value axis. nil for a chart with no axes, such as a pie.
|
|
@@ -129,7 +154,9 @@ module Pptx
|
|
|
129
154
|
ValueAxis.new(axes[axes.size > 1 ? 1 : 0])
|
|
130
155
|
end
|
|
131
156
|
|
|
132
|
-
def value_axes
|
|
157
|
+
def value_axes
|
|
158
|
+
plot_area.value_axes.map { |element| ValueAxis.new(element) }
|
|
159
|
+
end
|
|
133
160
|
|
|
134
161
|
# The category labels cached in the chart XML.
|
|
135
162
|
def categories
|
|
@@ -139,13 +166,19 @@ module Pptx
|
|
|
139
166
|
first.xpath("./c:cat//c:pt/c:v").map(&:text)
|
|
140
167
|
end
|
|
141
168
|
|
|
142
|
-
def inspect
|
|
169
|
+
def inspect
|
|
170
|
+
"#<Pptx::Chart #{chart_type.name} series=#{series.size}>"
|
|
171
|
+
end
|
|
143
172
|
|
|
144
173
|
private
|
|
145
174
|
|
|
146
|
-
def chart_element
|
|
175
|
+
def chart_element
|
|
176
|
+
@element.chart
|
|
177
|
+
end
|
|
147
178
|
|
|
148
|
-
def plot_area
|
|
179
|
+
def plot_area
|
|
180
|
+
chart_element.plotArea
|
|
181
|
+
end
|
|
149
182
|
end
|
|
150
183
|
|
|
151
184
|
# Works out the full chart type from a plot element, after python-pptx's
|
|
@@ -200,11 +233,17 @@ module Pptx
|
|
|
200
233
|
rule.call(plot)
|
|
201
234
|
end
|
|
202
235
|
|
|
203
|
-
def line_markers?(plot)
|
|
236
|
+
def line_markers?(plot)
|
|
237
|
+
plot.xpath('c:ser/c:marker/c:symbol[@val="none"]').empty?
|
|
238
|
+
end
|
|
204
239
|
|
|
205
|
-
def exploded?(plot)
|
|
240
|
+
def exploded?(plot)
|
|
241
|
+
!plot.xpath("./c:ser/c:explosion").empty?
|
|
242
|
+
end
|
|
206
243
|
|
|
207
|
-
def first_symbol(plot)
|
|
244
|
+
def first_symbol(plot)
|
|
245
|
+
plot.xpath("c:ser/c:marker/c:symbol").first&.get("val")
|
|
246
|
+
end
|
|
208
247
|
|
|
209
248
|
def bubble(plot)
|
|
210
249
|
bubble3d = plot.xpath("c:ser/c:bubble3D").first
|
|
@@ -260,17 +299,27 @@ module Pptx
|
|
|
260
299
|
end
|
|
261
300
|
|
|
262
301
|
# The fill and outline of this series.
|
|
263
|
-
def format
|
|
302
|
+
def format
|
|
303
|
+
@format ||= ChartFormat.new(@element)
|
|
304
|
+
end
|
|
264
305
|
|
|
265
306
|
# The series' chart-wide index.
|
|
266
|
-
def index
|
|
307
|
+
def index
|
|
308
|
+
@element.idx.val
|
|
309
|
+
end
|
|
267
310
|
|
|
268
|
-
def name
|
|
311
|
+
def name
|
|
312
|
+
@element.xpath("./c:tx//c:pt/c:v").first&.text.to_s
|
|
313
|
+
end
|
|
269
314
|
|
|
270
315
|
# Cached values, with nil where the chart records a gap.
|
|
271
|
-
def values
|
|
316
|
+
def values
|
|
317
|
+
cached(@element.val)
|
|
318
|
+
end
|
|
272
319
|
|
|
273
|
-
def inspect
|
|
320
|
+
def inspect
|
|
321
|
+
"#<#{self.class.name} #{name.inspect}>"
|
|
322
|
+
end
|
|
274
323
|
|
|
275
324
|
private
|
|
276
325
|
|
|
@@ -286,15 +335,21 @@ module Pptx
|
|
|
286
335
|
# Data labels and per-point formatting, for series plotted by category.
|
|
287
336
|
module CategorySeriesFeatures
|
|
288
337
|
# This series' own data labels, created on first use.
|
|
289
|
-
def data_labels
|
|
338
|
+
def data_labels
|
|
339
|
+
@data_labels ||= ChartDataLabels.new(@element.get_or_add_dLbls)
|
|
340
|
+
end
|
|
290
341
|
|
|
291
342
|
# The points of this series, one per category.
|
|
292
|
-
def points
|
|
343
|
+
def points
|
|
344
|
+
ChartPoints.new(@element, @element.cat_ptCount_val)
|
|
345
|
+
end
|
|
293
346
|
end
|
|
294
347
|
|
|
295
348
|
# Markers, for the kinds of series that draw them.
|
|
296
349
|
module MarkerFeatures
|
|
297
|
-
def marker
|
|
350
|
+
def marker
|
|
351
|
+
@marker ||= Marker.new(@element)
|
|
352
|
+
end
|
|
298
353
|
end
|
|
299
354
|
|
|
300
355
|
class AreaSeriesView < ChartSeriesView
|
|
@@ -310,7 +365,9 @@ module Pptx
|
|
|
310
365
|
|
|
311
366
|
# Whether a negative bar is drawn in inverted colours. An absent
|
|
312
367
|
# `c:invertIfNegative` reads as true, the schema default.
|
|
313
|
-
def invert_if_negative?
|
|
368
|
+
def invert_if_negative?
|
|
369
|
+
@element.invertIfNegative.nil? || @element.invertIfNegative.val
|
|
370
|
+
end
|
|
314
371
|
|
|
315
372
|
def invert_if_negative=(value)
|
|
316
373
|
@element.get_or_add_invertIfNegative.val = value ? true : false
|
|
@@ -323,7 +380,9 @@ module Pptx
|
|
|
323
380
|
|
|
324
381
|
# Whether the line is drawn as a smooth curve. An absent `c:smooth` reads
|
|
325
382
|
# as true, the schema default.
|
|
326
|
-
def smooth?
|
|
383
|
+
def smooth?
|
|
384
|
+
@element.smooth.nil? || @element.smooth.val
|
|
385
|
+
end
|
|
327
386
|
|
|
328
387
|
def smooth=(value)
|
|
329
388
|
@element.get_or_add_smooth.val = value ? true : false
|
|
@@ -339,9 +398,13 @@ module Pptx
|
|
|
339
398
|
class XySeriesView < ChartSeriesView
|
|
340
399
|
include MarkerFeatures
|
|
341
400
|
|
|
342
|
-
def values
|
|
401
|
+
def values
|
|
402
|
+
cached(@element.yVal)
|
|
403
|
+
end
|
|
343
404
|
|
|
344
|
-
def points
|
|
405
|
+
def points
|
|
406
|
+
ChartPoints.new(@element, [@element.xVal_ptCount_val, @element.yVal_ptCount_val].min)
|
|
407
|
+
end
|
|
345
408
|
end
|
|
346
409
|
|
|
347
410
|
class BubbleSeriesView < XySeriesView
|
|
@@ -361,17 +424,62 @@ module Pptx
|
|
|
361
424
|
# A date category's cached serial depends on the chart's date system.
|
|
362
425
|
@date_1904 = chart_space.date1904&.val || false
|
|
363
426
|
plot_area = chart_space.chart.plotArea
|
|
427
|
+
check_data_kind(plot_area)
|
|
364
428
|
adjust_series_count(plot_area, @chart_data.series.size)
|
|
365
429
|
plot_area.series_elements.zip(@chart_data.series) do |ser, series_data|
|
|
366
|
-
rewrite_series(ser, series_data)
|
|
430
|
+
xy? ? rewrite_xy_series(ser, series_data) : rewrite_series(ser, series_data)
|
|
367
431
|
end
|
|
368
432
|
self
|
|
369
433
|
end
|
|
370
434
|
|
|
371
435
|
private
|
|
372
436
|
|
|
437
|
+
def xy?
|
|
438
|
+
@chart_data.is_a?(XyChartData)
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def bubble?
|
|
442
|
+
@chart_data.is_a?(BubbleChartData)
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
# Scatter and bubble series carry c:xVal/c:yVal(/c:bubbleSize) where a
|
|
446
|
+
# category series carries c:cat/c:val; writing one kind of data into the
|
|
447
|
+
# other kind of series leaves a c:ser PowerPoint reports as corrupt.
|
|
448
|
+
def check_data_kind(plot_area)
|
|
449
|
+
kinds = plot_area.plot_elements.map { |plot| plot_kind(plot) }.uniq
|
|
450
|
+
expected = if bubble? then :bubble
|
|
451
|
+
elsif xy? then :scatter
|
|
452
|
+
else :category
|
|
453
|
+
end
|
|
454
|
+
return if kinds.empty? || kinds == [expected]
|
|
455
|
+
|
|
456
|
+
raise Error, "cannot replace the data of a #{kinds.join("/")} chart with " \
|
|
457
|
+
"#{@chart_data.class.name}; use #{data_class_for(kinds.first)}"
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
def plot_kind(plot)
|
|
461
|
+
case plot.nsptag
|
|
462
|
+
when "c:scatterChart" then :scatter
|
|
463
|
+
when "c:bubbleChart" then :bubble
|
|
464
|
+
else :category
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
def data_class_for(kind)
|
|
469
|
+
{ scatter: "Pptx::XyChartData", bubble: "Pptx::BubbleChartData",
|
|
470
|
+
category: "Pptx::ChartData" }.fetch(kind)
|
|
471
|
+
end
|
|
472
|
+
|
|
373
473
|
def adjust_series_count(plot_area, wanted)
|
|
374
474
|
difference = wanted - plot_area.series_elements.size
|
|
475
|
+
plots = plot_area.plot_elements.size
|
|
476
|
+
if difference.nonzero? && plots > 1
|
|
477
|
+
raise Error, "cannot change the series count of a chart with #{plots} plots " \
|
|
478
|
+
"(#{plot_area.series_elements.size} series, #{wanted} given); " \
|
|
479
|
+
"series map to plots in document order, so adding or removing them " \
|
|
480
|
+
"would move series between plots or drop a plot"
|
|
481
|
+
end
|
|
482
|
+
|
|
375
483
|
if difference.positive?
|
|
376
484
|
clone_series(plot_area, difference)
|
|
377
485
|
elsif difference.negative?
|
|
@@ -387,10 +495,10 @@ module Pptx
|
|
|
387
495
|
|
|
388
496
|
next_index = plot_area.series_elements.size
|
|
389
497
|
count.times do |offset|
|
|
390
|
-
copy = last.parent.
|
|
498
|
+
copy = last.parent.import(last)
|
|
391
499
|
copy.get_or_add_idx.val = next_index + offset
|
|
392
500
|
copy.get_or_add_order.val = next_index + offset
|
|
393
|
-
last.
|
|
501
|
+
last.add_next_sibling(copy)
|
|
394
502
|
last = copy
|
|
395
503
|
end
|
|
396
504
|
end
|
|
@@ -413,6 +521,18 @@ module Pptx
|
|
|
413
521
|
ser.insert_cat(ser.build_from_xml(cat))
|
|
414
522
|
ser.insert_val(ser.build_from_xml(val))
|
|
415
523
|
end
|
|
524
|
+
|
|
525
|
+
def rewrite_xy_series(ser, series_data)
|
|
526
|
+
ser.remove_tx
|
|
527
|
+
ser.remove_xVal
|
|
528
|
+
ser.remove_yVal
|
|
529
|
+
ser.remove_bubbleSize
|
|
530
|
+
fragments = SeriesFragments.new(@chart_data, series_data).xy_fragments
|
|
531
|
+
ser.insert_tx(ser.build_from_xml(fragments[:tx]))
|
|
532
|
+
ser.insert_xVal(ser.build_from_xml(fragments[:x_val]))
|
|
533
|
+
ser.insert_yVal(ser.build_from_xml(fragments[:y_val]))
|
|
534
|
+
ser.insert_bubbleSize(ser.build_from_xml(fragments[:bubble_size])) if fragments[:bubble_size]
|
|
535
|
+
end
|
|
416
536
|
end
|
|
417
537
|
|
|
418
538
|
# Builds the `c:tx`, `c:cat` and `c:val` of one series as standalone XML.
|
|
@@ -432,6 +552,23 @@ module Pptx
|
|
|
432
552
|
[namespaced(tx_xml(@series)), namespaced(cat_xml(@series)), namespaced(val_xml(@series))]
|
|
433
553
|
end
|
|
434
554
|
|
|
555
|
+
# The tx, xVal, yVal and (for a bubble series) bubbleSize of a scatter or
|
|
556
|
+
# bubble series, written exactly as XyBase writes them for a new chart.
|
|
557
|
+
#
|
|
558
|
+
# @return [Hash{Symbol => String}]
|
|
559
|
+
def xy_fragments
|
|
560
|
+
fragments = {
|
|
561
|
+
tx: tx_xml(@series),
|
|
562
|
+
x_val: num_ref_xml("c:xVal", @series.x_values_ref, @series.x_values, @series.number_format),
|
|
563
|
+
y_val: num_ref_xml("c:yVal", @series.y_values_ref, @series.y_values, @series.number_format)
|
|
564
|
+
}
|
|
565
|
+
if @series.respond_to?(:bubble_sizes)
|
|
566
|
+
fragments[:bubble_size] = num_ref_xml("c:bubbleSize", @series.bubble_sizes_ref,
|
|
567
|
+
@series.bubble_sizes, @series.number_format)
|
|
568
|
+
end
|
|
569
|
+
fragments.transform_values { |fragment| namespaced(fragment) }
|
|
570
|
+
end
|
|
571
|
+
|
|
435
572
|
private
|
|
436
573
|
|
|
437
574
|
# The fragments are written for a document that already declares the chart
|
|
@@ -62,7 +62,9 @@ module Pptx
|
|
|
62
62
|
self
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
def secondary_axis?
|
|
65
|
+
def secondary_axis?
|
|
66
|
+
@specs.any?(&:secondary_axis)
|
|
67
|
+
end
|
|
66
68
|
|
|
67
69
|
private
|
|
68
70
|
|
|
@@ -122,7 +124,9 @@ module Pptx
|
|
|
122
124
|
|
|
123
125
|
private
|
|
124
126
|
|
|
125
|
-
def plot_elements
|
|
127
|
+
def plot_elements
|
|
128
|
+
@builder.specs.map { |spec| plot_element(spec) }.join
|
|
129
|
+
end
|
|
126
130
|
|
|
127
131
|
def plot_element(spec)
|
|
128
132
|
family = ChartXmlWriter.family_of(spec.chart_type)
|
|
@@ -133,7 +137,7 @@ module Pptx
|
|
|
133
137
|
<<~XML
|
|
134
138
|
<#{plot_tag(family)}>
|
|
135
139
|
#{indent(body, 2).chomp}
|
|
136
|
-
#{indent(spec.series.map { |s|
|
|
140
|
+
#{indent(spec.series.map { |s| plot_series_xml(family, s) }.join, 2).chomp}
|
|
137
141
|
#{indent(plot_tail(family, spec), 2).chomp}
|
|
138
142
|
<c:axId val="#{cat_ax}"/>
|
|
139
143
|
<c:axId val="#{value_ax}"/>
|
|
@@ -141,7 +145,18 @@ module Pptx
|
|
|
141
145
|
XML
|
|
142
146
|
end
|
|
143
147
|
|
|
144
|
-
|
|
148
|
+
# PowerPoint draws a line series with no c:smooth of its own as a smoothed
|
|
149
|
+
# curve, whatever the plot-level c:smooth says, so each line series turns
|
|
150
|
+
# it off explicitly -- as LineChartWriter does for a plain line chart.
|
|
151
|
+
def plot_series_xml(family, series)
|
|
152
|
+
return series_xml(series) unless family == :line
|
|
153
|
+
|
|
154
|
+
series_xml(series, extra_after_val: %(<c:smooth val="0"/>\n))
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def plot_tag(family)
|
|
158
|
+
{ bar: "c:barChart", line: "c:lineChart", area: "c:areaChart" }[family]
|
|
159
|
+
end
|
|
145
160
|
|
|
146
161
|
def bar_plot_body(spec)
|
|
147
162
|
direction = ChartXmlWriter::BarChartWriter::BAR_TYPES.include?(spec.chart_type.name) ? "bar" : "col"
|
data/lib/ruby_pptx/chart/data.rb
CHANGED
|
@@ -50,17 +50,25 @@ module Pptx
|
|
|
50
50
|
series
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
def each(&)
|
|
53
|
+
def each(&)
|
|
54
|
+
@series.each(&)
|
|
55
|
+
end
|
|
54
56
|
|
|
55
|
-
def size
|
|
57
|
+
def size
|
|
58
|
+
@series.size
|
|
59
|
+
end
|
|
56
60
|
|
|
57
61
|
# The number of categories plotted: the leaves, when they are grouped.
|
|
58
|
-
def category_count
|
|
62
|
+
def category_count
|
|
63
|
+
@categories.leaf_count
|
|
64
|
+
end
|
|
59
65
|
|
|
60
66
|
# True when the categories are numbers or dates, which makes the category
|
|
61
67
|
# cache numeric rather than textual. Decided by the first category, as
|
|
62
68
|
# python-pptx decides it.
|
|
63
|
-
def numeric_categories?
|
|
69
|
+
def numeric_categories?
|
|
70
|
+
@categories.numeric?
|
|
71
|
+
end
|
|
64
72
|
|
|
65
73
|
# @api private
|
|
66
74
|
# The category block: one column per level, one row per leaf.
|
|
@@ -72,7 +80,9 @@ module Pptx
|
|
|
72
80
|
end
|
|
73
81
|
|
|
74
82
|
# @api private
|
|
75
|
-
def series_name_ref(series)
|
|
83
|
+
def series_name_ref(series)
|
|
84
|
+
"#{WORKSHEET_NAME}!$#{column_letter(series)}$1"
|
|
85
|
+
end
|
|
76
86
|
|
|
77
87
|
# @api private
|
|
78
88
|
# As long as the series itself, which python-pptx also measures by the
|
|
@@ -85,7 +95,9 @@ module Pptx
|
|
|
85
95
|
|
|
86
96
|
# @api private
|
|
87
97
|
# The Excel column letter for a series: after the category columns.
|
|
88
|
-
def column_letter(series)
|
|
98
|
+
def column_letter(series)
|
|
99
|
+
ChartData.column_reference(1 + @categories.depth + series.index)
|
|
100
|
+
end
|
|
89
101
|
|
|
90
102
|
# Excel's bijective base-26 column names: 1 => "A", 27 => "AA".
|
|
91
103
|
def self.column_reference(column_number)
|
|
@@ -102,9 +114,13 @@ module Pptx
|
|
|
102
114
|
|
|
103
115
|
# @api private
|
|
104
116
|
# Bytes of the embedded Excel workbook holding this data.
|
|
105
|
-
def xlsx_blob
|
|
117
|
+
def xlsx_blob
|
|
118
|
+
ChartWorkbookWriter.new(self).blob
|
|
119
|
+
end
|
|
106
120
|
|
|
107
|
-
def inspect
|
|
121
|
+
def inspect
|
|
122
|
+
"#<Pptx::ChartData categories=#{category_count} series=#{size}>"
|
|
123
|
+
end
|
|
108
124
|
end
|
|
109
125
|
|
|
110
126
|
# One series of a chart: a name and one value per category.
|
|
@@ -121,9 +137,13 @@ module Pptx
|
|
|
121
137
|
@number_format = number_format
|
|
122
138
|
end
|
|
123
139
|
|
|
124
|
-
def each(&)
|
|
140
|
+
def each(&)
|
|
141
|
+
@values.each(&)
|
|
142
|
+
end
|
|
125
143
|
|
|
126
|
-
def size
|
|
144
|
+
def size
|
|
145
|
+
@values.size
|
|
146
|
+
end
|
|
127
147
|
|
|
128
148
|
# Append one value, for building a series up point by point.
|
|
129
149
|
#
|
|
@@ -134,14 +154,24 @@ module Pptx
|
|
|
134
154
|
self
|
|
135
155
|
end
|
|
136
156
|
|
|
137
|
-
def categories
|
|
157
|
+
def categories
|
|
158
|
+
@chart_data.categories
|
|
159
|
+
end
|
|
138
160
|
|
|
139
|
-
def name_ref
|
|
161
|
+
def name_ref
|
|
162
|
+
@chart_data.series_name_ref(self)
|
|
163
|
+
end
|
|
140
164
|
|
|
141
|
-
def values_ref
|
|
165
|
+
def values_ref
|
|
166
|
+
@chart_data.series_values_ref(self)
|
|
167
|
+
end
|
|
142
168
|
|
|
143
|
-
def categories_ref
|
|
169
|
+
def categories_ref
|
|
170
|
+
@chart_data.categories_ref
|
|
171
|
+
end
|
|
144
172
|
|
|
145
|
-
def inspect
|
|
173
|
+
def inspect
|
|
174
|
+
"#<Pptx::ChartSeries #{@name.inspect} #{size} values>"
|
|
175
|
+
end
|
|
146
176
|
end
|
|
147
177
|
end
|