dyi 1.2.1 → 1.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.
- data/CHANGES +11 -0
- data/README +2 -3
- data/examples/animation.rb +104 -28
- data/examples/clock.rb +152 -0
- data/examples/data/money.csv +13 -12
- data/examples/external_files/asian_map.png +0 -0
- data/examples/external_files/xslt.xsl +71 -0
- data/examples/letter.rb +125 -0
- data/examples/line_and_bar.rb +32 -19
- data/examples/logo.rb +1 -62
- data/examples/map.rb +30705 -0
- data/examples/panther.rb +1602 -0
- data/examples/pie_chart.rb +27 -20
- data/examples/rainbow.rb +31 -0
- data/examples/simple_animation.rb +28 -0
- data/examples/thumbnail.rb +73 -0
- data/examples/xslt.rb +9 -0
- data/lib/dyi.rb +71 -2
- data/lib/dyi/animation.rb +270 -79
- data/lib/dyi/canvas.rb +10 -1
- data/lib/dyi/chart/line_chart.rb +75 -27
- data/lib/dyi/drawing/color_effect.rb +117 -0
- data/lib/dyi/drawing/pen.rb +6 -2
- data/lib/dyi/element.rb +11 -10
- data/lib/dyi/event.rb +3 -3
- data/lib/dyi/formatter/svg_formatter.rb +113 -25
- data/lib/dyi/shape.rb +2 -0
- data/lib/dyi/shape/base.rb +42 -3
- data/lib/dyi/shape/graphical_template.rb +106 -0
- data/lib/dyi/shape/reused_shape.rb +99 -0
- metadata +14 -3
- data/examples/class_diagram.rb +0 -154
@@ -0,0 +1,99 @@
|
|
1
|
+
# -*- encoding: UTF-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) 2009-2012 Sound-F Co., Ltd. All rights reserved.
|
4
|
+
#
|
5
|
+
# Author:: Mamoru Yuo
|
6
|
+
#
|
7
|
+
# This file is part of DYI.
|
8
|
+
#
|
9
|
+
# DYI is free software: you can redistribute it and/or modify it
|
10
|
+
# under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# DYI is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with DYI. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
|
22
|
+
#
|
23
|
+
module DYI
|
24
|
+
module Shape
|
25
|
+
# Marker object represents a symbol at One or more vertices of the lines.
|
26
|
+
#
|
27
|
+
# Marker provides some pre-defined shapes and a custom marker defined freely.
|
28
|
+
# @since 1.3.0
|
29
|
+
class ReusedShape < Base
|
30
|
+
|
31
|
+
attr_reader :source_element
|
32
|
+
|
33
|
+
# Returns width of the re-used shape.
|
34
|
+
attr_length :width
|
35
|
+
|
36
|
+
# Returns heigth of the re-used shape.
|
37
|
+
attr_length :height
|
38
|
+
|
39
|
+
def initialize(source_element, left_top, options={})
|
40
|
+
@source_element = source_element.to_reused_source
|
41
|
+
width = Length.new_or_nil(options.delete(:width))
|
42
|
+
height = Length.new_or_nil(options.delete(:height))
|
43
|
+
@lt_pt = Coordinate.new(left_top)
|
44
|
+
@lt_pt += Coordinate.new(width, 0) if width && width < Length::ZERO
|
45
|
+
@lt_pt += Coordinate.new(0, height) if height && height < Length::ZERO
|
46
|
+
@width = width && width.abs
|
47
|
+
@height = height && height.abs
|
48
|
+
@attributes = init_attributes(options)
|
49
|
+
source_element.publish_id
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns a x-axis coordinate of the left side of the re-used shape.
|
53
|
+
# @return [Length] the x-axis coordinate of the left side
|
54
|
+
def left
|
55
|
+
@lt_pt.x
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns a x-axis coordinate of the right side of the re-used shape.
|
59
|
+
# @return [Length] the x-axis coordinate of the right side
|
60
|
+
def right
|
61
|
+
width && (@lt_pt.x + width)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns a y-axis coordinate of the top of the re-used shape.
|
65
|
+
# @return [Length] a y-axis coordinate of the top
|
66
|
+
def top
|
67
|
+
@lt_pt.y
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns a y-axis coordinate of the bottom of the re-used shape.
|
71
|
+
# @return [Length] a y-axis coordinate of the bottom
|
72
|
+
def bottom
|
73
|
+
height && (@lt_pt.y + height)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns a coordinate of the center of the re-used shape.
|
77
|
+
# @return [Coordinate] a coordinate of the center
|
78
|
+
def center
|
79
|
+
width && height && (@lt_pt + Coordinate.new(width.quo(2), height.quo(2)))
|
80
|
+
end
|
81
|
+
|
82
|
+
def child_elements
|
83
|
+
source_element.child_elements
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [Boolean] whether the element has a URI reference
|
87
|
+
def has_uri_reference?
|
88
|
+
true
|
89
|
+
end
|
90
|
+
|
91
|
+
# Writes image on io object.
|
92
|
+
# @param [Formatter::Base] formatter an object that defines the image format
|
93
|
+
# @param [IO] io an io to be written
|
94
|
+
def write_as(formatter, io=$>)
|
95
|
+
formatter.write_reused_shape(self, io)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dyi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: 1.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mamoru Yuo
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-06-01 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
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"
|
@@ -25,16 +25,25 @@ files:
|
|
25
25
|
- CHANGES
|
26
26
|
- COPYING
|
27
27
|
- examples/animation.rb
|
28
|
-
- examples/
|
28
|
+
- examples/clock.rb
|
29
29
|
- examples/css.rb
|
30
30
|
- examples/data/03311056.xlsx
|
31
31
|
- examples/data/currency.xlsx
|
32
32
|
- examples/data/money.csv
|
33
|
+
- examples/external_files/asian_map.png
|
34
|
+
- examples/external_files/xslt.xsl
|
35
|
+
- examples/letter.rb
|
33
36
|
- examples/line_and_bar.rb
|
34
37
|
- examples/line_chart.rb
|
35
38
|
- examples/logo.rb
|
39
|
+
- examples/map.rb
|
40
|
+
- examples/panther.rb
|
36
41
|
- examples/pie_chart.rb
|
42
|
+
- examples/rainbow.rb
|
43
|
+
- examples/simple_animation.rb
|
37
44
|
- examples/simple_shapes.rb
|
45
|
+
- examples/thumbnail.rb
|
46
|
+
- examples/xslt.rb
|
38
47
|
- lib/dyi/animation.rb
|
39
48
|
- lib/dyi/canvas.rb
|
40
49
|
- lib/dyi/chart/array_reader.rb
|
@@ -72,8 +81,10 @@ files:
|
|
72
81
|
- lib/dyi/script/simple_script.rb
|
73
82
|
- lib/dyi/script.rb
|
74
83
|
- lib/dyi/shape/base.rb
|
84
|
+
- lib/dyi/shape/graphical_template.rb
|
75
85
|
- lib/dyi/shape/marker.rb
|
76
86
|
- lib/dyi/shape/path.rb
|
87
|
+
- lib/dyi/shape/reused_shape.rb
|
77
88
|
- lib/dyi/shape.rb
|
78
89
|
- lib/dyi/stylesheet.rb
|
79
90
|
- lib/dyi/svg_element.rb
|
data/examples/class_diagram.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
# -*- encoding: UTF-8 -*-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'dyi'
|
5
|
-
|
6
|
-
class ClassBox
|
7
|
-
def initialize class_name
|
8
|
-
@name = class_name
|
9
|
-
@width = @name.length * 12
|
10
|
-
@height = 30
|
11
|
-
@children = []
|
12
|
-
end
|
13
|
-
|
14
|
-
def draw(canvas, pen, top_left_point, horizontal_span = 5)
|
15
|
-
@top_left_point_x = top_left_point[0]
|
16
|
-
@top_left_point_y = top_left_point[1]
|
17
|
-
pen.draw_rectangle(canvas, top_left_point, @width, @height)
|
18
|
-
pen.draw_text(canvas, [@top_left_point_x+@name.length * 2.5, @top_left_point_y+@height*3.0/4.0], @name)
|
19
|
-
|
20
|
-
total_width = 0
|
21
|
-
@children.each do |child|
|
22
|
-
total_width += child.width + horizontal_span
|
23
|
-
end
|
24
|
-
total_width -= horizontal_span
|
25
|
-
|
26
|
-
position_x = @top_left_point_x + @width/2.0 - total_width/2.0
|
27
|
-
@children.each_with_index do |child, i|
|
28
|
-
child.draw(canvas, pen, [position_x, @top_left_point_y+@height+30])
|
29
|
-
pen.draw_arrow(canvas, child.get_top_center, [get_arrowhead_pos_x(i), @top_left_point_y+@height])
|
30
|
-
position_x += child.width + horizontal_span
|
31
|
-
end
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
def extends parent
|
36
|
-
parent.pushChildren self
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
|
-
def pushChildren child
|
41
|
-
@children.push child
|
42
|
-
end
|
43
|
-
|
44
|
-
def width
|
45
|
-
@width
|
46
|
-
end
|
47
|
-
|
48
|
-
def get_top_center
|
49
|
-
[@top_left_point_x + @width/2.0, @top_left_point_y]
|
50
|
-
end
|
51
|
-
|
52
|
-
def get_bottom_center
|
53
|
-
[@top_left_point_x + @width/2.0, @top_left_point_y + @height]
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def get_arrowhead_pos_x index
|
59
|
-
@top_left_point_x+(index+1)*@width/(@children.length+1)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class ArrowPen < DYI::Drawing::Pen
|
64
|
-
def draw_arrow(canvas, start_point, end_point, headsize = 5)
|
65
|
-
start_point = DYI::Coordinate.new(start_point)
|
66
|
-
end_point = DYI::Coordinate.new(end_point)
|
67
|
-
total_length = DYI::Length.new(start_point.distance(end_point))
|
68
|
-
end_point_no_rotate = DYI::Coordinate.new(start_point.x + total_length, start_point.y)
|
69
|
-
|
70
|
-
rotate_value = Math.atan2((end_point.y - start_point.y).to_f, (end_point.x - start_point.x).to_f) * 360.0 / (2*Math::PI)
|
71
|
-
|
72
|
-
draw_line(canvas, start_point, end_point_no_rotate).rotate(rotate_value, start_point)
|
73
|
-
draw_polygon(canvas, end_point_no_rotate){|line|
|
74
|
-
line.line_to([-headsize, -headsize], true)
|
75
|
-
line.line_to([0, 2*headsize], true)
|
76
|
-
line.line_to([headsize, -headsize], true)
|
77
|
-
}.rotate(rotate_value, start_point)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
canvas = DYI::Canvas.new 1300, 1300
|
82
|
-
|
83
|
-
pen = ArrowPen.new
|
84
|
-
dashed_pen = ArrowPen.new(:stroke_dasharray => [3])
|
85
|
-
|
86
|
-
base_class = ClassBox.new('Base')
|
87
|
-
ClassBox.new('Table').extends(base_class)
|
88
|
-
ClassBox.new('PieChart').extends(base_class)
|
89
|
-
ClassBox.new('LineChart').extends(base_class)
|
90
|
-
|
91
|
-
pen.draw_rectangle(canvas, [30,10], 530, 260)
|
92
|
-
pen.draw_text(canvas, [60, 30], 'DYI::Chart')
|
93
|
-
base_class.draw(canvas, pen, [200,30])
|
94
|
-
legend = ClassBox.new('Legend').draw(canvas, pen, [350,30])
|
95
|
-
axis_util = ClassBox.new('AxisUtil').draw(canvas, pen, [450,30])
|
96
|
-
dashed_pen.draw_arrow(canvas, [200,90], legend.get_bottom_center)
|
97
|
-
dashed_pen.draw_arrow(canvas, [310,90], axis_util.get_bottom_center)
|
98
|
-
|
99
|
-
array_reader = ClassBox.new('ArrayReader')
|
100
|
-
ClassBox.new('CsvReader').extends(array_reader)
|
101
|
-
ClassBox.new('ExcelReader').extends(array_reader)
|
102
|
-
|
103
|
-
array_reader.draw(canvas, pen, [200, 170])
|
104
|
-
|
105
|
-
base_class = ClassBox.new('Base')
|
106
|
-
ClassBox.new('EpsFormatter').extends(base_class)
|
107
|
-
xml_formatter = ClassBox.new('XmlFormatter').extends(base_class)
|
108
|
-
ClassBox.new('EmfFormatter').extends(base_class)
|
109
|
-
ClassBox.new('SvgFormatter').extends(xml_formatter)
|
110
|
-
ClassBox.new('XamlFormatter').extends(xml_formatter)
|
111
|
-
|
112
|
-
pen.draw_rectangle(canvas, [30, 300], 480, 230)
|
113
|
-
pen.draw_text(canvas, [230, 320], 'DYI::Formatter')
|
114
|
-
base_class.draw(canvas, pen, [250,330])
|
115
|
-
|
116
|
-
pen_base_class = ClassBox.new('PenBase')
|
117
|
-
brush = ClassBox.new('Brush').extends(pen_base_class)
|
118
|
-
pen_class = ClassBox.new('Pen').extends(pen_base_class)
|
119
|
-
ClassBox.new('CylinderBrush').extends(brush)
|
120
|
-
ClassBox.new('CubicPen').extends(pen_class)
|
121
|
-
|
122
|
-
pen.draw_rectangle(canvas, [540, 300], 400, 230)
|
123
|
-
pen.draw_text(canvas, [730, 320], 'DYI::Drawing')
|
124
|
-
pen_base_class.draw(canvas, pen, [650,330], 90)
|
125
|
-
ClassBox.new('Canvas').draw(canvas, pen, [800,350])
|
126
|
-
|
127
|
-
comparable_class = ClassBox.new('Comparable').draw(canvas, pen, [50, 550])
|
128
|
-
|
129
|
-
pen.draw_rectangle(canvas, [30, 620], 270, 180)
|
130
|
-
pen.draw_text(canvas, [130, 640], 'DYI')
|
131
|
-
ClassBox.new('Length').draw(canvas, pen, [50, 650])
|
132
|
-
ClassBox.new('Coordinate').draw(canvas, pen, [150, 650])
|
133
|
-
ClassBox.new('Color').draw(canvas, pen, [50, 700])
|
134
|
-
ClassBox.new('Font').draw(canvas, pen, [200, 700])
|
135
|
-
ClassBox.new('Painting').draw(canvas, pen, [80, 750])
|
136
|
-
pen.draw_arrow(canvas, [122, 665], [150, 665])
|
137
|
-
dashed_pen.draw_arrow(canvas, [110, 650], comparable_class.get_bottom_center)
|
138
|
-
|
139
|
-
base_class = ClassBox.new('Base')
|
140
|
-
ClassBox.new('Rectangle').extends(base_class)
|
141
|
-
ClassBox.new('Circle').extends(base_class)
|
142
|
-
ClassBox.new('Ellipse').extends(base_class)
|
143
|
-
ClassBox.new('Line').extends(base_class)
|
144
|
-
polyline = ClassBox.new('Polyline').extends(base_class)
|
145
|
-
ClassBox.new('Path').extends(base_class)
|
146
|
-
ClassBox.new('Text').extends(base_class)
|
147
|
-
ClassBox.new('ShapeGroup').extends(base_class)
|
148
|
-
ClassBox.new('Polygon').extends(polyline)
|
149
|
-
|
150
|
-
pen.draw_rectangle(canvas, [310, 600], 770, 200)
|
151
|
-
pen.draw_text(canvas, [730, 620], 'DYI::Shape')
|
152
|
-
base_class.draw(canvas, pen, [650,630])
|
153
|
-
|
154
|
-
canvas.save 'output/class_diagram.svg'
|