grapht 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28b0d92ac5111da4102fa9375ed2ff8cd031c36f
4
- data.tar.gz: 92e20cc9d8968b744a9e07764620541f5070fc23
3
+ metadata.gz: 1fe989813b4f6c56f0d18f51aaee1e4bc4f0c45b
4
+ data.tar.gz: 1f756e623419a70df6c1c2fece60324002c7b878
5
5
  SHA512:
6
- metadata.gz: d0c14b3abd8022f504200a9c64a4de95291ec02c57dfa482165868179ab897309e1b37105e2ab2281e780cf7a7b40f18176cbb7698ecd514d470947b776fc4e2
7
- data.tar.gz: abf23e58cacfa00294bc257a3bbf57d9778ec88b8d5cb76b7a47679f7aa8fa2ed195827cc21e93c77c05fa35a62d9f268f0400d40bf5ac4b30270ba572793249
6
+ metadata.gz: 8a7c61bc4e4ce2936fac328cc4f033aee666a1e5e2b18b2b75d70a6a010cd7ac7512053f8ada009b5e2200a48bf80119edc013d921b5f070bac4dd293db35634
7
+ data.tar.gz: 2c77a6970a6841c43fb89f73dee9f21fe83fbddbd38cfe2da835916a6cdf0ddc0d88956fd9846a36a1d5c94142c6d46d480028f4f94942eeb20476ab1ec0fdb1
@@ -7,16 +7,4 @@ rvm:
7
7
  - 2.1.0
8
8
  - 2.1.1
9
9
  - ruby-head
10
- - rbx-2
11
- matrix:
12
- include:
13
- - rvm: jruby-18mode
14
- env: JRUBY_OPTS="$JRUBY_OPTS --debug"
15
- - rvm: jruby-19mode
16
- env: JRUBY_OPTS="$JRUBY_OPTS --debug"
17
- - rvm: jruby-head
18
- env: JRUBY_OPTS="$JRUBY_OPTS --debug"
19
- allow_failures:
20
- - rvm: ruby-head
21
- - rvm: jruby-head
22
- fast_finish: true
10
+ - rbx-2
@@ -6,10 +6,13 @@ function(data) {
6
6
  svgHeight = height + margin.top + margin.bottom;
7
7
 
8
8
  var svg = d3.select("body").append("svg")
9
- .style("fill", "none")
9
+ .attr('viewBox', "0 -10 " +svgWidth+ " " +svgHeight+ "")
10
10
  .attr("width", svgWidth)
11
11
  .attr("height", svgHeight)
12
- .attr('viewBox', "0 -10 " +svgWidth+ " " +svgHeight+ "")
12
+ .style("font-family", "Arial")
13
+ .style("font-size", "14px")
14
+ .style("fill", "none")
15
+ .style("background-color", "#ffffff")
13
16
  .append('g')
14
17
  .attr('transform', 'translate(' +margin.left+ ',' +margin.top+ ')')
15
18
  .style("fill", "none");
@@ -50,22 +53,21 @@ function(data) {
50
53
  .data(data)
51
54
  .enter().append('rect')
52
55
  .attr('class', 'bar')
53
- .style('fill', '#428bca')
54
- .attr('opacity', '0.3')
55
56
  .attr('x', 0)
56
57
  .attr('y', function(d) { return y(d.name); })
57
58
  .attr('width', function(d) { return x(d.value); })
58
- .attr('height', y.rangeBand());
59
+ .attr('height', y.rangeBand())
60
+ .style('fill', '#428bca')
61
+ .style('opacity', '0.3')
62
+ ;
59
63
 
60
- svg.selectAll('.text')
61
- .attr('font-family', 'Arial')
62
- .selectAll('label')
64
+ svg.selectAll('label')
63
65
  .attr('fill-opacity', '0.3')
64
66
 
65
67
  var xAxisElement = svg.append('g')
66
68
  .attr('class', 'x axis')
67
- .style("fill", "none")
68
69
  .attr('transform', "translate(0," +height+ ")")
70
+ .style("fill", "none")
69
71
  .call(xAxis);
70
72
 
71
73
  var yAxisElement = svg.append('g')
@@ -75,16 +77,14 @@ function(data) {
75
77
 
76
78
  xAxisElement.selectAll('line')
77
79
  .style('fill', 'none')
78
- .attr('stroke', 'black')
79
- .attr('stroke-width', '1px')
80
- .attr('stroke-opacity', 0.1)
81
- .attr('shape-rendering', 'geometricPrecision');
80
+ .style('stroke', 'black')
81
+ .style('stroke-width', '1px')
82
+ .style('stroke-opacity', 0.1)
83
+ .style('shape-rendering', 'geometricPrecision');
82
84
 
83
85
  xAxisElement.selectAll('text')
84
- .style('fill', '#333333')
85
- .attr('font-family', 'Arial');
86
+ .style('fill', '#333333');
86
87
 
87
88
  yAxisElement.selectAll('text')
88
- .style('fill', '#333333')
89
- .attr('font-family', 'Arial');
89
+ .style('fill', '#333333');
90
90
  }
@@ -6,10 +6,13 @@ function(data) {
6
6
  svgHeight = height + margin.top + margin.bottom;
7
7
 
8
8
  var svg = d3.select("body").append("svg")
9
- .style("fill", "none")
9
+ .attr('viewBox', "0 -10 " +svgWidth+ " " +svgHeight+ "")
10
10
  .attr("width", svgWidth)
11
11
  .attr("height", svgHeight)
12
- .attr('viewBox', "0 -10 " +svgWidth+ " " +svgHeight+ "")
12
+ .style("font-family", "Arial")
13
+ .style("font-size", "14px")
14
+ .style("fill", "none")
15
+ .style("background-color", "#ffffff")
13
16
  .append('g')
14
17
  .attr('transform', 'translate(' +margin.left+ ',' +margin.top+ ')')
15
18
  .style("fill", "none");
@@ -43,17 +46,15 @@ function(data) {
43
46
  .data(data)
44
47
  .enter().append('rect')
45
48
  .attr('class', 'bar')
46
- .style('fill', '#428bca')
47
- .attr('opacity', '0.3')
48
49
  .attr('y', function(d) { return y(d.value); })
49
50
  .attr('x', function(d) { return x(d.name); })
51
+ .attr('width', x.rangeBand())
50
52
  .attr('height', function(d) { return height - y(d.value); })
51
- .attr('width', x.rangeBand());
53
+ .style('fill', '#428bca')
54
+ .style('opacity', '0.3');
52
55
 
53
- svg.selectAll('.text')
54
- .attr('font-family', 'Arial')
55
- .selectAll('label')
56
- .attr('fill-opacity', '0.3')
56
+ svg.selectAll('label')
57
+ .style('fill-opacity', '0.3')
57
58
 
58
59
  var xAxisElement = svg.append('g')
59
60
  .attr('class', 'x axis')
@@ -67,23 +68,21 @@ function(data) {
67
68
 
68
69
  xAxisElement.selectAll('line')
69
70
  .style('fill', 'none')
70
- .attr('stroke', 'black')
71
- .attr('stroke-width', '1px')
72
- .attr('stroke-opacity', 0.1)
73
- .attr('shape-rendering', 'geometricPrecision');
71
+ .style('stroke', 'black')
72
+ .style('stroke-width', '1px')
73
+ .style('stroke-opacity', 0.1)
74
+ .style('shape-rendering', 'geometricPrecision');
74
75
 
75
76
  xAxisElement.selectAll('text')
76
- .style('fill', '#333333')
77
- .attr('font-family', 'Arial');
77
+ .style('fill', '#333333');
78
78
 
79
79
  yAxisElement.selectAll('line')
80
80
  .style('fill', 'none')
81
- .attr('stroke', 'black')
82
- .attr('stroke-width', '1px')
83
- .attr('stroke-opacity', 0.1)
84
- .attr('shape-rendering', 'geometricPrecision');
81
+ .style('stroke', 'black')
82
+ .style('stroke-width', '1px')
83
+ .style('stroke-opacity', 0.1)
84
+ .style('shape-rendering', 'geometricPrecision');
85
85
 
86
86
  yAxisElement.selectAll('text')
87
- .style('fill', '#333333')
88
- .attr('font-family', 'Arial');
87
+ .style('fill', '#333333');
89
88
  }
@@ -6,11 +6,14 @@ function(data) {
6
6
  svgHeight = height + margin.top + margin.bottom,
7
7
  radius = Math.min(width, height) / 2;
8
8
 
9
- var svg = d3.select("body").append("svg")
10
- .style("fill", "none")
9
+ var svg = d3.select("body").append("svg")
10
+ .attr('viewBox', "0 -10 " +svgWidth+ " " +svgHeight+ "")
11
11
  .attr("width", svgWidth)
12
12
  .attr("height", svgHeight)
13
- .attr('viewBox', "0 -10 " +svgWidth+ " " +svgHeight+ "")
13
+ .style("font-family", "Arial")
14
+ .style("font-size", "14px")
15
+ .style("fill", "none")
16
+ .style("background-color", "#ffffff")
14
17
  .append('g')
15
18
  .attr('transform', 'translate(' +(width/2)+ ',' +(height/2)+ ')')
16
19
  .style("fill", "none");
@@ -38,10 +41,9 @@ function(data) {
38
41
 
39
42
  arcElement.append("text")
40
43
  .attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
41
- .attr("dy", ".35em")
44
+ .attr("dy", "5px")
42
45
  .style('fill', '#FFFFFF')
43
- .attr('font-family', 'Arial')
44
- .attr('font-weight', 'bold')
46
+ .style('font-weight', 'bold')
45
47
  .style("text-anchor", "middle")
46
48
  .text(function(d) { return d.data.name; });
47
49
  }
@@ -16,15 +16,17 @@ function(data) {
16
16
  svgHeight = height + margin.top + margin.bottom;
17
17
 
18
18
  var svg = d3.select("body").append("svg")
19
- .style("fill", "none")
20
- .attr("width", svgWidth)
21
- .attr("height", svgHeight)
22
- .attr('viewBox', "0 -10 " +svgWidth+ " " +svgHeight+ "")
19
+ .attr('viewBox', "0 -10 " +svgWidth+ " " +svgHeight+ "")
20
+ .attr("width", svgWidth)
21
+ .attr("height", svgHeight)
22
+ .style("font-family", "Arial")
23
+ .style("font-size", "14px")
24
+ .style("fill", "none")
25
+ .style("background-color", "#ffffff")
23
26
  .append('g')
24
27
  .attr('transform', 'translate(' +margin.left+ ',' +margin.top+ ')')
25
28
  .style("fill", "none");
26
29
 
27
-
28
30
  var x = d3.scale
29
31
  .linear()
30
32
  .range([0, width])
@@ -70,42 +72,39 @@ function(data) {
70
72
 
71
73
  lineElements.append('path')
72
74
  .attr('class', 'line')
73
- .attr('stroke-width', '2px')
74
- .attr('opacity', '0.3')
75
75
  .attr('d', function(d) { return line(d.value) })
76
- .attr('stroke', function(d) { return color(d.key); });
76
+ .style('stroke-width', '2px')
77
+ .style('opacity', '0.3')
78
+ .style('stroke', function(d) { return color(d.key); });
77
79
 
78
80
  lineElements.append('text')
79
81
  .datum(function(d) { return { name: d.key, value: d.value[d.value.length - 1] }; })
80
82
  .attr('transform', function(d) { return "translate(" +x(d.value.x)+ "," +y(d.value.y)+ ")"; })
81
83
  .attr('x', 3)
82
- .attr('dy', '.35em')
84
+ .attr('dy', '5px')
83
85
  .style('fill', '#333333')
84
- .attr('font-family', 'Arial')
85
86
  .text(function(d) { return d.name; });
86
87
 
87
88
  // axis styling
88
89
  xAxisElement.selectAll('line')
89
90
  .style('fill', 'none')
90
- .attr('stroke', 'black')
91
- .attr('stroke-width', '1px')
92
- .attr('stroke-opacity', 0.1)
93
- .attr('shape-rendering', 'geometricPrecision');
91
+ .style('stroke', 'black')
92
+ .style('stroke-width', '1px')
93
+ .style('stroke-opacity', 0.1)
94
+ .style('shape-rendering', 'geometricPrecision');
94
95
 
95
96
  xAxisElement.selectAll('text')
96
- .style('fill', '#333333')
97
- .attr('font-family', 'Arial')
98
- .attr('dy', '20px');
97
+ .attr('dy', '20px')
98
+ .style('fill', '#333333');
99
99
 
100
100
  yAxisElement.selectAll('line')
101
101
  .style('fill', 'none')
102
- .attr('stroke', 'black')
103
- .attr('stroke-width', '1px')
104
- .attr('stroke-opacity', 0.1)
105
- .attr('shape-rendering', 'geometricPrecision');
102
+ .style('stroke', 'black')
103
+ .style('stroke-width', '1px')
104
+ .style('stroke-opacity', 0.1)
105
+ .style('shape-rendering', 'geometricPrecision');
106
106
 
107
107
  yAxisElement.selectAll('text')
108
- .style('fill', '#333333')
109
- .attr('font-family', 'Arial')
110
- .attr('dx', '-10px');
108
+ .attr('dx', '-10px')
109
+ .style('fill', '#333333');
111
110
  }
@@ -5,7 +5,7 @@ module Grapht
5
5
  class Error < StandardError; end
6
6
 
7
7
  CMD = File.join(Grapht::ROOT, 'bin/grapht')
8
- ALLOWED_OPTIONS = %w(-f)
8
+ ALLOWED_OPTIONS = %w(-f -i)
9
9
 
10
10
  def self.exec(type, json_data, options={})
11
11
  options = *options.select { |k,v| ALLOWED_OPTIONS.include? k }.flatten
@@ -1,3 +1,3 @@
1
1
  module Grapht
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -1,45 +1,65 @@
1
1
  page = require('webpage').create()
2
2
  system = require('system')
3
3
  fs = require('fs')
4
+
4
5
  thisFile = system.args[0]
5
6
  graphType = system.args[1]
6
7
  graphFormat = false
7
- scriptPath = fs.absolute(thisFile)
8
- .replace(/[\w\s\-\.]+?\.(js|coffee)$/i, '')
8
+ dependencies = ['d3.min.js', 'json2.js']
9
+
10
+ scriptPath = fs.absolute(thisFile).replace(/[\w\s\-\.]+?\.(js|coffee)$/i, '')
9
11
  vendorPath = "#{scriptPath}../vendor/"
10
12
  defsPath = "#{scriptPath}../lib/graph-definitions/"
11
13
  userDefsPath = system.env['EXT_GRAPHT_DEFINITIONS_HOME']
12
- dependencies = ['d3.min.js', 'json2.js']
13
14
  niceDirPathRX = /\/$|$/
14
15
  naughtyPathRX = /(?:\.{1,2}\/)+/
15
16
 
16
- # -----------------------------------------------------------------------------
17
+
18
+
19
+ #------------------------------------------------------------------------------
17
20
  # Helper Functions
18
- # -----------------------------------------------------------------------------
21
+ #------------------------------------------------------------------------------
19
22
 
20
23
  fns =
21
- # Logs the supplied message, and optional trace to STDERR and exits the process
22
- # with an exit code of 1.
23
- logError: (message, trace) ->
24
+ # Logs the supplied message (and, optionally, the trace) to STDERR; then,
25
+ # exits the process with the supplied code.
26
+ #
27
+ # Return Codes:
28
+ # 0 - Success
29
+ # 1 - Naughty Type Path Error
30
+ # 2 - Graph Defintion Not Found Error
31
+ # 3 - Graph Dependency Load Error
32
+ # 4 - Graph Data Not Found Error
33
+ # 5 - Graph Data Parse Error
34
+ # 99 - Unexpected Error
35
+ #
36
+ logError: (message, code, trace) ->
24
37
  fs.write '/dev/stderr', "<ERROR> #{message}\n"
38
+ fs.write '/dev/stderr', formattedTrace(trace) if trace
39
+ phantom.exit(code || 99)
25
40
 
26
- if trace
27
- traceString = trace.map (t) -> "\t#{t.file}: on line: #{t.line}"
28
- fs.write '/dev/stderr', traceString.join('\n')
29
41
 
30
- phantom.exit(1)
42
+ # Returns a formatted version of the trace object so it can
43
+ # be sent to std out.
44
+ #
45
+ formattedTrace: (trace) ->
46
+ traceString = trace.map (t) -> "\t#{t.file}: on line: #{t.line}"
47
+ traceString.join('\n')
31
48
 
49
+
32
50
  # Scrubs-out any leading '/' characters from the type, and raises an error
33
51
  # if any naughtier path manipulation is detected.
52
+ #
34
53
  sanitizeType: (type) ->
35
54
  if naughtyPathRX.test(type)
36
- @logError "Naughty! There will be no backing out of the definition directory!"
55
+ @logError('Naughty! There will be no backing out of the definition directory!', 1)
37
56
 
38
57
  type.replace(/^\/+/, '')
39
58
 
59
+
40
60
  # Searchs for a valid graph definition in the supplied definition paths. If
41
- # no definition is found, we log an error to STDERR and exit with an exitcode
42
- # of 1.
61
+ # no definition is found, we log an error to STDERR.
62
+ #
43
63
  findDef: (type, defPaths...) ->
44
64
  type = @sanitizeType(type)
45
65
 
@@ -48,20 +68,29 @@ fns =
48
68
  path = "#{dir}#{type}.js"
49
69
  return path if fs.exists(path)
50
70
 
51
- @logError "No graph definition could be found for '#{type}'"
71
+ @logError("No graph definition could be found for '#{type}'", 2)
72
+
73
+
74
+ # Reads in the graph defintion file.
75
+ #
76
+ loadDef: (def) ->
77
+ fs.read(def)
52
78
 
53
- loadDef: (def) -> fs.read(def)
54
79
 
55
80
  # Wraps the supplied graph definition in a function that executes the definition
56
81
  # and returns the resulting content of the document body. This function is intended
57
82
  # to minimize boiler-plate in graph definitions, and reduce the likelihood of user
58
83
  # error.
84
+ #
59
85
  wrapDef: (def) ->
60
86
  "function() {
61
87
  (#{def}).apply(this, arguments);
62
88
  return document.body.innerHTML;
63
89
  }"
64
90
 
91
+ # Returns a hash composed of any optional arguments sent
92
+ # with a command.
93
+ #
65
94
  getOptions: ->
66
95
  optionsIn = system.args[2..]
67
96
  optionsOut = {}
@@ -73,10 +102,25 @@ fns =
73
102
 
74
103
  optionsOut
75
104
 
105
+
106
+ # Returns the value of the format option (nil if not
107
+ # provided)
108
+ #
76
109
  getFormat: ->
77
110
  options = @getOptions()
78
111
  options['-f'] || options['--format']
79
112
 
113
+
114
+ # Returns the value of the include option (nil if not
115
+ # provided)
116
+ #
117
+ getInclude: ->
118
+ options = @getOptions()
119
+ options['-i'] || options['--include']
120
+
121
+
122
+ # Reads in json data for the graph.
123
+ #
80
124
  readDataIn: ->
81
125
  try
82
126
  if (data = fs.read('/dev/stdin')).length
@@ -85,36 +129,59 @@ fns =
85
129
  fns.logError('No graph data was received!')
86
130
 
87
131
  catch err
88
- @logError err
89
-
90
-
91
- # -----------------------------------------------------------------------------
132
+ @logError(err, 4)
133
+
134
+
135
+ # Renders the graph output based on the arguments and
136
+ # options provided.
137
+ #
138
+ renderGraph: ->
139
+ # Load all dependencies.
140
+ dependencies.forEach (dp) ->
141
+ page.injectJs(dp) || fns.logError("Dependency could not be loaded: #{dp}", 3)
142
+
143
+ # Load and evaluate the graph definition within the context of the
144
+ # arguments supplied via STDIN.
145
+ graphData = fns.readDataIn()
146
+ graphDef = fns.wrapDef fns.loadDef fns.findDef(graphType, userDefsPath, defsPath)
147
+ parsedData = try
148
+ JSON.parse(graphData)
149
+ catch err
150
+ fns.logError(err, 5)
151
+
152
+ # Configure page to remove extraneous whitespace that comes out
153
+ # of WebKit.
154
+ #
155
+ # The viewport size eliminates a minimum height of 300px that
156
+ # seems to be enforced. It does so by requiring all drawings to
157
+ # exapnd the viewport to actual size.
158
+ page.viewportSize = { width: 1, height: 1 };
159
+
160
+ # Set the content.
161
+ page.content = content = page.evaluate(graphDef, parsedData)
162
+
163
+ # Write resulting content to stdout.
164
+ if graphFormat = fns.getFormat()
165
+ page.render '/dev/stdout', { format: graphFormat, quality: 100 }
166
+ else
167
+ fs.write '/dev/stdout', "#{content}\n"
168
+
169
+ # Exit with success code
170
+ phantom.exit(0)
171
+
172
+
173
+
174
+ #------------------------------------------------------------------------------
92
175
  # Core Graph Generation Logic
93
- # -----------------------------------------------------------------------------
176
+ #------------------------------------------------------------------------------
94
177
 
95
178
  # Configure the page context.
96
179
  page.libraryPath = vendorPath
97
180
  page.onError = fns.logError
98
181
 
99
- dependencies.forEach (dp) ->
100
- page.injectJs(dp) || fns.logError "could not load #{dp}!"
101
-
102
- # load and evaluate the graph definition within the context of the JSON, supplied
103
- # via STDIN.
104
- graphData = fns.readDataIn()
105
- graphDef = fns.wrapDef fns.loadDef fns.findDef(graphType, userDefsPath, defsPath)
106
- graphFormat = fns.getFormat()
107
- parsedData = try
108
- JSON.parse(graphData)
109
- catch err
110
- fns.logError(err)
111
-
112
- page.content = content = page.evaluate(graphDef, parsedData)
113
-
114
- # Write resulting content to STDOUT and exit.
115
- if graphFormat
116
- page.render '/dev/stdout', { format: graphFormat, quality: 100 }
182
+ # Render the graph to std out. If include option provided, pull that
183
+ # in and render graph via callback.
184
+ if included_file = fns.getInclude()
185
+ page.includeJs(included_file, fns.renderGraph)
117
186
  else
118
- fs.write '/dev/stdout', "#{content}\n"
119
-
120
- phantom.exit()
187
+ fns.renderGraph()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grapht
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Lowrimore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-14 00:00:00.000000000 Z
12
+ date: 2014-09-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -120,4 +120,3 @@ test_files:
120
120
  - spec/lib/grapht/shell_spec.rb
121
121
  - spec/spec_helper.rb
122
122
  - spec/support/rspec-prof.rb
123
- has_rdoc: