dyi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +20 -0
- data/examples/class_diagram.rb +5 -2
- data/examples/line_and_bar.rb +5 -4
- data/examples/line_chart.rb +6 -5
- data/examples/logo.rb +3 -1
- data/examples/pie_chart.rb +6 -5
- data/examples/simple_shapes.rb +5 -2
- data/lib/dyi.rb +2 -1
- data/lib/dyi/chart/pie_chart.rb +3 -3
- data/lib/dyi/formatter/base.rb +1 -1
- data/lib/dyi/formatter/eps_formatter.rb +1 -0
- data/lib/dyi/formatter/svg_reader.rb +66 -32
- data/lib/dyi/formatter/xaml_formatter.rb +1 -1
- data/lib/dyi/painting.rb +1 -1
- data/lib/dyi/shape.rb +6 -3
- metadata +5 -4
data/CHANGES
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
= DYI Changelog
|
2
|
+
|
3
|
+
== Version 0.0.2 / 2011-09-05
|
4
|
+
|
5
|
+
* Minor Enhancements
|
6
|
+
* Modify header comments of output file.
|
7
|
+
|
8
|
+
* Bug Fixes
|
9
|
+
* A path is not drawn correctly.
|
10
|
+
* Miter length is not set corrently.
|
11
|
+
|
12
|
+
== Version 0.0.1 / 2011-07-15
|
13
|
+
|
14
|
+
* Bug Fixes
|
15
|
+
* Clipping is not possible for a shape object.
|
16
|
+
* A path is not drawn correctly.
|
17
|
+
|
18
|
+
== Version 0.0.0 / 2011-06-30
|
19
|
+
|
20
|
+
* First public release
|
data/examples/class_diagram.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dyi'
|
2
5
|
|
3
6
|
class ClassBox
|
4
7
|
def initialize class_name
|
@@ -148,4 +151,4 @@ pen.draw_rectangle(canvas, [310, 600], 770, 200)
|
|
148
151
|
pen.draw_text(canvas, [730, 620], 'DYI::Shape')
|
149
152
|
base_class.draw(canvas, pen, [650,630])
|
150
153
|
|
151
|
-
canvas.save 'output/
|
154
|
+
canvas.save 'output/class_diagram.svg'
|
data/examples/line_and_bar.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# -*- encoding: UTF-8 -*-
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dyi'
|
4
5
|
|
5
6
|
chart = DYI::Chart::LineChart.new 800,500,
|
6
7
|
:use_y_second_axises => [true, nil],
|
@@ -21,6 +22,6 @@ chart = DYI::Chart::LineChart.new 800,500,
|
|
21
22
|
reader = DYI::Chart::CsvReader.read('data/money.csv', :data_types => [:number, :number, :string], :title_column=>0, :column_skip => 1)
|
22
23
|
chart.load_data reader
|
23
24
|
|
24
|
-
chart.save 'output/
|
25
|
-
chart.save 'output/
|
26
|
-
chart.save 'output/
|
25
|
+
chart.save 'output/line_and_bar.svg'
|
26
|
+
chart.save 'output/line_and_bar.eps', :eps
|
27
|
+
chart.save 'output/line_and_bar.emf', :emf if defined? IRONRUBY_VERSION
|
data/examples/line_chart.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# -*- encoding: UTF-8 -*-
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dyi'
|
4
5
|
|
5
6
|
gr = DYI::Drawing::ColorEffect::LinearGradient.new([0,0],[0,1])
|
6
7
|
gr.add_color(0, '#8FD3F5')
|
@@ -24,7 +25,7 @@ chart = DYI::Chart::LineChart.new 720,300,
|
|
24
25
|
reader = DYI::Chart::ExcelReader.read('data/03311056.xlsx', :sheet => 'Sheet2', :title_column=>1, :column_skip=>2, :title_row=>1, :row_skip=>2)
|
25
26
|
chart.load_data reader
|
26
27
|
|
27
|
-
chart.save 'output/
|
28
|
-
chart.save 'output/
|
29
|
-
chart.save 'output/
|
30
|
-
chart.save 'output/
|
28
|
+
chart.save 'output/line_chart.svg'
|
29
|
+
chart.save 'output/line_chart.xaml', :xaml
|
30
|
+
chart.save 'output/line_chart.eps', :eps
|
31
|
+
chart.save 'output/line_chart.emf', :emf if defined? IRONRUBY_VERSION
|
data/examples/logo.rb
CHANGED
data/examples/pie_chart.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# -*- encoding: UTF-8 -*-
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dyi'
|
4
5
|
|
5
6
|
chart = DYI::Chart::PieChart.new 400,500,
|
6
7
|
:data_label_format => "{name}\n{percent}",
|
@@ -13,7 +14,7 @@ chart = DYI::Chart::PieChart.new 400,500,
|
|
13
14
|
reader = DYI::Chart::ExcelReader.read('data/currency.xlsx', :title_column=>0, :column_skip=>1)
|
14
15
|
chart.load_data reader
|
15
16
|
|
16
|
-
chart.save 'output/
|
17
|
-
chart.save 'output/
|
18
|
-
chart.save 'output/
|
19
|
-
chart.save 'output/
|
17
|
+
chart.save 'output/pie_chart.svg'
|
18
|
+
chart.save 'output/pie_chart.xaml', :xaml
|
19
|
+
chart.save 'output/pie_chart.eps', :eps
|
20
|
+
chart.save 'output/pie_chart.emf', :emf if defined? IRONRUBY_VERSION
|
data/examples/simple_shapes.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'dyi'
|
2
5
|
|
3
6
|
canvas = DYI::Drawing::Canvas.new(500, 500)
|
4
7
|
|
@@ -12,4 +15,4 @@ brush.draw_circle(canvas, center_point, 20)
|
|
12
15
|
pen = DYI::Drawing::Pen.new(:color => '#CCFFCC', :width => 5)
|
13
16
|
pen.draw_line(canvas, [150,70], [80,140])
|
14
17
|
|
15
|
-
canvas.save 'output/
|
18
|
+
canvas.save 'output/simple_shape.svg'
|
data/lib/dyi.rb
CHANGED
data/lib/dyi/chart/pie_chart.rb
CHANGED
@@ -75,7 +75,7 @@ module DYI #:nodoc:
|
|
75
75
|
if represent_3d?
|
76
76
|
brush = Drawing::ColumnBrush.new(back_translate_value.merge(chart_stroke_color ? {:stroke_width => chart_stroke_width, :stroke => chart_stroke_color} : {}))
|
77
77
|
else
|
78
|
-
brush = Drawing::Brush.new(chart_stroke_color ? {:stroke_width => chart_stroke_width, :stroke => chart_stroke_color, :stroke_miterlimit => chart_stroke_width
|
78
|
+
brush = Drawing::Brush.new(chart_stroke_color ? {:stroke_width => chart_stroke_width, :stroke => chart_stroke_color, :stroke_miterlimit => chart_stroke_width} : {})
|
79
79
|
end
|
80
80
|
@chart_canvas = Shape::ShapeGroup.draw_on(@canvas)
|
81
81
|
@data_label_canvas = Shape::ShapeGroup.draw_on(@canvas)
|
@@ -129,11 +129,11 @@ module DYI #:nodoc:
|
|
129
129
|
legend_point = Coordinate.new(
|
130
130
|
chart_radius_x * (data_label_position + (dr || 0)) * Math.cos(((accumulation * 2.0 + value) / total_value - 0.5) * Math::PI),
|
131
131
|
chart_radius_y * (data_label_position + (dr || 0)) * Math.sin(((accumulation * 2.0 + value) / total_value - 0.5) * Math::PI))
|
132
|
-
Drawing::Pen.black_pen(:font =>
|
132
|
+
Drawing::Pen.black_pen(:font => data_label_font).draw_text(
|
133
133
|
@data_label_canvas,
|
134
134
|
center_point + legend_point,
|
135
135
|
data_label_format.gsub(/\{name\}/, name).gsub(/\{value\}/, value.to_s).gsub(/\{percent\}/, '%.1f%' % (ratio * 100.0).to_s),
|
136
|
-
:text_anchor => 'middle'
|
136
|
+
:text_anchor => 'middle')
|
137
137
|
end if hide_data_label_ratio < ratio
|
138
138
|
end
|
139
139
|
end
|
data/lib/dyi/formatter/base.rb
CHANGED
@@ -29,6 +29,7 @@ module DYI #:nodoc:
|
|
29
29
|
def header_comment
|
30
30
|
<<-EOS
|
31
31
|
%!PS-Adobe-3.0 EPSF-3.0
|
32
|
+
%%Creator: DYI #{DYI::VERSION} (#{DYI::URL})
|
32
33
|
%%CreationDate: #{Time.now.strftime('%a %b %d %H:%M:%S %Y')}
|
33
34
|
%%BoundingBox: 0 0 #{@canvas.real_width.to_f('pt').ceil} #{@canvas.real_height.to_f('pt').ceil}
|
34
35
|
%%EndComments
|
@@ -19,6 +19,7 @@
|
|
19
19
|
# You should have received a copy of the GNU General Public License
|
20
20
|
# along with DYI. If not, see <http://www.gnu.org/licenses/>.
|
21
21
|
|
22
|
+
require 'enumerator'
|
22
23
|
require 'rexml/document'
|
23
24
|
|
24
25
|
module DYI #:nodoc:
|
@@ -70,42 +71,75 @@ module DYI #:nodoc:
|
|
70
71
|
|
71
72
|
def create_path(element)
|
72
73
|
color = DYI::Color.new(element.attributes['fill']) if element.attributes['fill'] != 'none'
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
74
|
+
paths = element.attributes['d'].scan(/([MmZzLlHhVvCcSsQqTtAa])\s*([+-]?(?:\d+\.?\d*|\.\d+)(?:\s*,?\s*[+-]?(?:\d+\.?\d*|\.\d+))*)?/)
|
75
|
+
enumerator = paths.each
|
76
|
+
path_element = enumerator.next
|
77
|
+
if path_element.first.upcase == 'M'
|
78
|
+
lengths = path_element[1].scan(/[+-]?(?:\d+\.?\d*|\.\d+)/).map{|n| DYI::Length.new(n)}
|
79
|
+
return if lengths.count % 2 == 1
|
80
|
+
points = lengths.each_slice(2).map{|x, y| DYI::Coordinate.new(x, y)}
|
81
|
+
path_data = DYI::Shape::Path::PathData.new(*points)
|
82
|
+
loop do
|
83
|
+
path_element = enumerator.next
|
84
|
+
case path_element.first
|
85
|
+
when 'M', 'm', 'L', 'l', 'C', 'c', 'S', 's', 'Q', 'q', 'T', 't'
|
86
|
+
lengths = path_element[1].scan(/[+-]?(?:\d+\.?\d*|\.\d+)/).map{|n| DYI::Length.new(n)}
|
87
|
+
return unless lengths.size % 2 == 0
|
88
|
+
command_type = case path_element.first
|
89
|
+
when 'M' then :move_to
|
90
|
+
when 'm' then :rmove_to
|
91
|
+
when 'L' then :line_to
|
92
|
+
when 'l' then :rline_to
|
93
|
+
when 'C' then :curve_to
|
94
|
+
when 'c' then :rcurve_to
|
95
|
+
when 'S' then :shorthand_curve_to
|
96
|
+
when 's' then :rshorthand_curve_to
|
97
|
+
when 'Q' then :quadratic_curve_to
|
98
|
+
when 'q' then :rquadratic_curve_to
|
99
|
+
when 'T' then :shorthand_quadratic_curve_to
|
100
|
+
when 't' then :rshorthand_quadratic_curve_to
|
101
|
+
end
|
102
|
+
points = lengths.each_slice(2).map{|x, y| DYI::Coordinate.new(x, y)}
|
103
|
+
path_data.push_command(command_type, *points)
|
104
|
+
when 'Z', 'z'
|
105
|
+
path_data.push_command(:close_path, *lengths)
|
106
|
+
when 'H', 'h', 'V', 'v'
|
107
|
+
lengths = path_element[1].scan(/[+-]?(?:\d+\.?\d*|\.\d+)/).map{|n| DYI::Length.new(n)}
|
108
|
+
command_type = case path_element.first
|
109
|
+
when 'H' then :horizontal_lineto_to
|
110
|
+
when 'h' then :rhorizontal_lineto_to
|
111
|
+
when 'V' then :vertical_lineto_to
|
112
|
+
when 'v' then :rvertical_lineto_to
|
113
|
+
end
|
114
|
+
path_data.push_command(command_type, *lengths)
|
115
|
+
when 'A', 'a'
|
116
|
+
params = []
|
117
|
+
enumerator = path_element[1].scan(/[+-]?(?:\d+\.?\d*|\.\d+)/).each
|
118
|
+
return unless enumerator.count % 7 == 0
|
119
|
+
loop do
|
120
|
+
rx = enumerator.next
|
121
|
+
ry = enumerator.next
|
122
|
+
rotation = enumerator.next
|
123
|
+
is_large_arc = enumerator.next
|
124
|
+
is_clockwise = enumerator.next
|
125
|
+
cx = enumerator.next
|
126
|
+
cy = enumerator.next
|
127
|
+
params << DYI::Length.new(rx) << DYI::Length.new(ry)
|
128
|
+
params << rotation.to_f
|
129
|
+
[is_large_arc, is_clockwise].each do |flg|
|
130
|
+
case flg
|
131
|
+
when '0' then params << false
|
132
|
+
when '1' then params << true
|
133
|
+
else return
|
134
|
+
end
|
135
|
+
end
|
136
|
+
params << Coordinate.new(cx, cy)
|
84
137
|
end
|
85
|
-
|
86
|
-
path.line_to(coors)
|
87
|
-
when 'l'
|
88
|
-
path.line_to(coors, true)
|
89
|
-
when 'H'
|
90
|
-
p 'H'
|
91
|
-
path.line_to([coors.first, path.current_point.y])
|
92
|
-
when 'h'
|
93
|
-
path.line_to([coors.first, 0], true)
|
94
|
-
when 'V'
|
95
|
-
p 'V'
|
96
|
-
path.line_to([path.current_point.x, coors.first])
|
97
|
-
when 'v'
|
98
|
-
path.line_to([0, coors.first], true)
|
99
|
-
when 'C'
|
100
|
-
path.curve_to([coors[0..1], coors[2..3], coors[4..5]])
|
101
|
-
when 'c'
|
102
|
-
path.curve_to([coors[0..1], coors[2..3], coors[4..5]], true)
|
103
|
-
when 'z'
|
104
|
-
path.close_path
|
138
|
+
path_data.push_command(path_element.first == 'A' ? :arc_to : :rarc_to, *params)
|
105
139
|
end
|
106
140
|
end
|
107
141
|
end
|
108
|
-
|
142
|
+
DYI::Shape::Path.new(path_data, :painting => {:fill => color})
|
109
143
|
end
|
110
144
|
end
|
111
145
|
end
|
@@ -286,7 +286,7 @@ module DYI #:nodoc:
|
|
286
286
|
if linejoin = STROKE_LINE_JOIN[painting.stroke_linejoin]
|
287
287
|
attr[:StrokeLineJoin] = linejoin
|
288
288
|
end
|
289
|
-
attr[:
|
289
|
+
attr[:StrokeMiterLimit] = painting.stroke_miterlimit if painting.stroke_miterlimit
|
290
290
|
if painting.stroke_width
|
291
291
|
attr[:StrokeThickness] = painting.stroke_width.to_user_unit
|
292
292
|
end
|
data/lib/dyi/painting.rb
CHANGED
@@ -134,7 +134,7 @@ module DYI #:nodoc:
|
|
134
134
|
end
|
135
135
|
|
136
136
|
def stroke_miterlimit=(miterlimit)
|
137
|
-
@stroke_miterlimit = miterlimit.nil? ? nil : miterlimit.to_f
|
137
|
+
@stroke_miterlimit = miterlimit.nil? ? nil : [miterlimit.to_f, 1].max
|
138
138
|
end
|
139
139
|
|
140
140
|
def stroke_dasharray=(array)
|
data/lib/dyi/shape.rb
CHANGED
@@ -391,7 +391,10 @@ module DYI #:nodoc:
|
|
391
391
|
attr_painting :painting
|
392
392
|
|
393
393
|
def initialize(start_point, options={})
|
394
|
-
@path_data =
|
394
|
+
@path_data = case start_point
|
395
|
+
when PathData then start_point
|
396
|
+
else PathData.new(start_point)
|
397
|
+
end
|
395
398
|
@attributes = init_attributes(options)
|
396
399
|
end
|
397
400
|
|
@@ -946,7 +949,7 @@ module DYI #:nodoc:
|
|
946
949
|
end
|
947
950
|
|
948
951
|
def to_compatible_commands(preceding_command)
|
949
|
-
LineCommand.new(relative?, preceding_command,
|
952
|
+
LineCommand.new(relative?, preceding_command, @point)
|
950
953
|
end
|
951
954
|
|
952
955
|
def to_concise_syntax_fragments
|
@@ -964,7 +967,7 @@ module DYI #:nodoc:
|
|
964
967
|
end
|
965
968
|
|
966
969
|
def to_compatible_commands(preceding_command)
|
967
|
-
LineCommand.new(relative?, preceding_command,
|
970
|
+
LineCommand.new(relative?, preceding_command, @point)
|
968
971
|
end
|
969
972
|
|
970
973
|
def to_concise_syntax_fragments
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dyi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yuo
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-09-05 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: " DYI is a 2D graphics library, very rich and expressive.\n DYI have been optimized for SVG format, but it is also possible\n to output other format; for example, EPS.\n"
|
@@ -27,6 +27,7 @@ extensions: []
|
|
27
27
|
extra_rdoc_files: []
|
28
28
|
|
29
29
|
files:
|
30
|
+
- CHANGES
|
30
31
|
- COPYING
|
31
32
|
- examples/class_diagram.rb
|
32
33
|
- examples/data/03311056.xlsx
|