ekylibre-cartography 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -0
- data/Rakefile +10 -0
- data/app/assets/javascripts/cartography.coffee +535 -0
- data/app/assets/javascripts/cartography/base.coffee +11 -0
- data/app/assets/javascripts/cartography/controls.coffee +463 -0
- data/app/assets/javascripts/cartography/events.coffee +36 -0
- data/app/assets/javascripts/cartography/layers.coffee +127 -0
- data/app/assets/javascripts/cartography/layers/simple.coffee +37 -0
- data/app/assets/javascripts/cartography/leaflet/controls.coffee +420 -0
- data/app/assets/javascripts/cartography/leaflet/handlers.coffee +461 -0
- data/app/assets/javascripts/cartography/leaflet/i18n.coffee +31 -0
- data/app/assets/javascripts/cartography/leaflet/layers.coffee +60 -0
- data/app/assets/javascripts/cartography/leaflet/toolbars.coffee +450 -0
- data/app/assets/javascripts/cartography/patches.js +8 -0
- data/app/assets/javascripts/cartography/util.coffee +18 -0
- data/app/assets/javascripts/main.js +18 -0
- data/app/assets/stylesheets/cartography.css +86 -0
- data/app/helpers/cartography_helper.rb +55 -0
- data/lib/cartography.rb +1 -0
- data/lib/cartography/engine.rb +11 -0
- data/lib/cartography/version.rb +3 -0
- data/vendor/assets/components/d3-array/dist/d3-array.js +590 -0
- data/vendor/assets/components/d3-array/dist/d3-array.min.js +2 -0
- data/vendor/assets/components/geojson-equality/dist/geojson-equality.js +295 -0
- data/vendor/assets/components/geojson-equality/dist/geojson-equality.js.map +21 -0
- data/vendor/assets/components/geojson-equality/dist/geojson-equality.min.js +1 -0
- data/vendor/assets/components/leaflet-controlpanel/dist/leaflet.controlpanel.css +29 -0
- data/vendor/assets/components/leaflet-controlpanel/dist/leaflet.controlpanel.js +269 -0
- data/vendor/assets/components/leaflet-draw-cut/dist/leaflet.draw.cut.css +1 -0
- data/vendor/assets/components/leaflet-draw-cut/dist/leaflet.draw.cut.js +8 -0
- data/vendor/assets/components/leaflet-draw-merge/dist/leaflet.draw.merge.css +0 -0
- data/vendor/assets/components/leaflet-draw-merge/dist/leaflet.draw.merge.js +48026 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw-src.css +326 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw-src.js +4653 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw-src.map +1 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw.css +10 -0
- data/vendor/assets/components/leaflet-draw/dist/leaflet.draw.js +10 -0
- data/vendor/assets/components/leaflet-geographicutil/dist/leaflet.geographicutil.js +3220 -0
- data/vendor/assets/components/leaflet-reactive_measure/dist/reactive_measure.css +30 -0
- data/vendor/assets/components/leaflet-reactive_measure/dist/reactive_measure.js +3764 -0
- data/vendor/assets/components/leaflet/dist/leaflet-src.js +13609 -0
- data/vendor/assets/components/leaflet/dist/leaflet-src.js.map +1 -0
- data/vendor/assets/components/leaflet/dist/leaflet-src.map +1 -0
- data/vendor/assets/components/leaflet/dist/leaflet.css +632 -0
- data/vendor/assets/components/leaflet/dist/leaflet.js +5 -0
- data/vendor/assets/components/leaflet/dist/leaflet.js.map +1 -0
- data/vendor/assets/components/martinez-polygon-clipping/dist/martinez.min.js +9 -0
- data/vendor/assets/components/martinez-polygon-clipping/dist/martinez.umd.js +1716 -0
- data/vendor/assets/components/martinez-polygon-clipping/dist/martinez.umd.js.map +1 -0
- data/vendor/assets/components/polygon-clipping/dist/polygon-clipping.js +279 -0
- data/vendor/assets/components/polygon-clipping/dist/polygon-clipping.min.js +1 -0
- data/vendor/assets/components/rtree/dist/rtree.js +911 -0
- data/vendor/assets/components/rtree/dist/rtree.min.js +1 -0
- data/vendor/assets/components/splaytree/dist/splay.es6.js +765 -0
- data/vendor/assets/components/splaytree/dist/splay.es6.js.map +1 -0
- data/vendor/assets/components/splaytree/dist/splay.js +797 -0
- data/vendor/assets/components/splaytree/dist/splay.js.map +1 -0
- metadata +156 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
((C, $, _) ->
|
2
|
+
"use strict"
|
3
|
+
|
4
|
+
class C.Util
|
5
|
+
|
6
|
+
#Leaflet inspiration, but provides object deep merging
|
7
|
+
@extend: (dest, src) ->
|
8
|
+
_.merge(dest, src)
|
9
|
+
|
10
|
+
@setOptions = (obj, options) ->
|
11
|
+
if !obj.hasOwnProperty 'options'
|
12
|
+
obj.options = if obj.options then L.Util.create(obj.options) else {}
|
13
|
+
@extend obj.options, options
|
14
|
+
|
15
|
+
C.extend = C.Util.extend
|
16
|
+
C.setOptions = C.Util.setOptions
|
17
|
+
|
18
|
+
)(window.Cartography = window.Cartography || {}, jQuery, _)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
//= require lodash/lodash.js
|
2
|
+
//= require pure-uuid/uuid.js
|
3
|
+
//= require leaflet/dist/leaflet-src.js
|
4
|
+
//= require leaflet-draw/dist/leaflet.draw-src.js
|
5
|
+
//= require leaflet-providers/leaflet-providers.js
|
6
|
+
//= require rtree/dist/rtree.js
|
7
|
+
|
8
|
+
//= require cartography/leaflet/i18n.coffee
|
9
|
+
//= require leaflet-layerindex/leaflet.layerindex.js
|
10
|
+
//= require leaflet-snap/leaflet.snap.js
|
11
|
+
//= require leaflet-geometryutil/src/leaflet.geometryutil.js
|
12
|
+
//= require leaflet-reactive_measure/dist/reactive_measure.js
|
13
|
+
|
14
|
+
//= require leaflet-draw-cut/dist/leaflet.draw.cut.js
|
15
|
+
// require leaflet-draw-merge/dist/leaflet.draw.merge.js
|
16
|
+
//= require leaflet-controlpanel/dist/leaflet.controlpanel.js
|
17
|
+
|
18
|
+
//= require_tree .
|
@@ -0,0 +1,86 @@
|
|
1
|
+
/*
|
2
|
+
*= require leaflet/dist/leaflet.css
|
3
|
+
*= require leaflet-draw/dist/leaflet.draw.css
|
4
|
+
*= require leaflet-reactive_measure/dist/reactive_measure.css
|
5
|
+
*= require leaflet-controlpanel/dist/leaflet.controlpanel.css
|
6
|
+
*/
|
7
|
+
.leaflet-div-icon, .leaflet-mouse-marker{
|
8
|
+
/*background: #fff;*/
|
9
|
+
border: 1px solid rgb(44,83,158);
|
10
|
+
border-radius: 50%;
|
11
|
+
background: rgb(255,255,255); /* Old browsers */
|
12
|
+
background: -moz-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%, rgba(246,246,246,1) 47%, rgba(237,237,237,1) 100%); /* FF3.6-15 */
|
13
|
+
background: -webkit-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%,rgba(246,246,246,1) 47%,rgba(237,237,237,1) 100%); /* Chrome10-25,Safari5.1-6 */
|
14
|
+
background: radial-gradient(ellipse at center, rgba(255,255,255,1) 0%,rgba(246,246,246,1) 47%,rgba(237,237,237,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
|
15
|
+
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ededed',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
|
16
|
+
|
17
|
+
margin-left: -8px !important;
|
18
|
+
margin-top: -8px !important;
|
19
|
+
width: 16px !important;
|
20
|
+
height: 16px !important;
|
21
|
+
box-sizing: border-box;
|
22
|
+
}
|
23
|
+
|
24
|
+
.leaflet-draw-guide-dash {
|
25
|
+
border-radius: 50%;
|
26
|
+
opacity: 1;
|
27
|
+
z-index: 1000;
|
28
|
+
}
|
29
|
+
|
30
|
+
.marker-origin {
|
31
|
+
animation: beat 1s infinite linear;
|
32
|
+
transform-origin: center;
|
33
|
+
}
|
34
|
+
|
35
|
+
@keyframes beat{
|
36
|
+
0% {
|
37
|
+
border-width: 1px;
|
38
|
+
}
|
39
|
+
50% {
|
40
|
+
border-width: 3px;
|
41
|
+
}
|
42
|
+
100% {
|
43
|
+
border-width: 1px;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
.leaflet-control-controlPanel-title {
|
50
|
+
color: black;
|
51
|
+
font-weight: bold;
|
52
|
+
font-size: small;
|
53
|
+
border-bottom: 1px solid rgba(0,0,0,0.2);
|
54
|
+
text-align: center;
|
55
|
+
}
|
56
|
+
|
57
|
+
.legend{
|
58
|
+
border: 1px solid black;
|
59
|
+
width: 20px;
|
60
|
+
height: 10px;
|
61
|
+
display: inline-block;
|
62
|
+
}
|
63
|
+
|
64
|
+
.legend-area {
|
65
|
+
display: inline-block;
|
66
|
+
margin-left: 10px;
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
.leaflet-control-controlPanel-properties {
|
71
|
+
padding: 1%;
|
72
|
+
width: 98%;
|
73
|
+
}
|
74
|
+
|
75
|
+
.property-title {
|
76
|
+
color: grey;
|
77
|
+
font-weight: bold;
|
78
|
+
font-size: larger;
|
79
|
+
}
|
80
|
+
.animated-helper {
|
81
|
+
width: 100%;
|
82
|
+
}
|
83
|
+
|
84
|
+
.surface-row {
|
85
|
+
text-align: middle;
|
86
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Cartography
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
def initialize(config = {})
|
5
|
+
@config = config
|
6
|
+
# @categories_colors = @config.delete(:categories_colors)
|
7
|
+
# @config[:backgrounds] = MapLayer.available_backgrounds.collect(&:to_json_object)
|
8
|
+
# @config[:overlays] = MapLayer.available_overlays.collect(&:to_json_object)
|
9
|
+
# @config[:async_url] = @config.delete(:async_url)
|
10
|
+
end
|
11
|
+
|
12
|
+
def layer(name, serie, options = {})
|
13
|
+
unless options[:label]
|
14
|
+
options[:label] = name.is_a?(String) ? name : name.tl(default: "attributes.#{name}".to_sym)
|
15
|
+
end
|
16
|
+
name = name.to_s.parameterize.tr('-', '_') unless name.is_a?(Symbol)
|
17
|
+
|
18
|
+
@config[:layers] ||= []
|
19
|
+
@config[:layers] << { reference: name.to_s.camelcase(:lower) }.merge(options.merge(name: name, serie: serie.to_s.camelcase(:lower)))
|
20
|
+
end
|
21
|
+
|
22
|
+
def simple(name, serie, options = {})
|
23
|
+
layer(name, serie, options.merge(type: :simple))
|
24
|
+
end
|
25
|
+
|
26
|
+
# Add a serie of geo data
|
27
|
+
def serie(name, feature_collection)
|
28
|
+
@config[:series] ||= {}.with_indifferent_access
|
29
|
+
@config[:series][name] = feature_collection
|
30
|
+
# data.compact.collect do |item|
|
31
|
+
# next unless item[:shape]
|
32
|
+
# item
|
33
|
+
# # .merge(shape: Charta.new_geometry(item[:shape]).transform(:WGS84).to_json_object)
|
34
|
+
# # .merge(item[:popup] ? { popup: compile_visualization_popup(item[:popup], item) } : {})
|
35
|
+
# end.compact
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_json(options = {})
|
39
|
+
@config.jsonize_keys.to_json
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module CartographyHelper
|
45
|
+
def configure_cartography(options = {})
|
46
|
+
# config = Cartography::Configuration.new({ categories_colors: theme_colors }.merge(options))
|
47
|
+
config = Cartography::Configuration.new(options)
|
48
|
+
yield config
|
49
|
+
config
|
50
|
+
end
|
51
|
+
def cartography( options = {}, html_options = {}, &block)
|
52
|
+
config = configure_cartography(options, &block)
|
53
|
+
content_tag(:div, nil, html_options.deep_merge(data: { cartography: config.to_json }))
|
54
|
+
end
|
55
|
+
end
|
data/lib/cartography.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'cartography/engine'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Cartography
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
initializer 'cartography.assets.precompile' do |app|
|
4
|
+
app.config.assets.precompile += %w[cartography.scss cartography.js]
|
5
|
+
end
|
6
|
+
|
7
|
+
initializer :i18n do |app|
|
8
|
+
app.config.i18n.load_path += Dir[Cartography::Engine.root.join('config', 'locales', '*.yml')]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,590 @@
|
|
1
|
+
// https://d3js.org/d3-array/ v1.2.4 Copyright 2018 Mike Bostock
|
2
|
+
(function (global, factory) {
|
3
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
4
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
5
|
+
(factory((global.d3 = global.d3 || {})));
|
6
|
+
}(this, (function (exports) { 'use strict';
|
7
|
+
|
8
|
+
function ascending(a, b) {
|
9
|
+
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
10
|
+
}
|
11
|
+
|
12
|
+
function bisector(compare) {
|
13
|
+
if (compare.length === 1) compare = ascendingComparator(compare);
|
14
|
+
return {
|
15
|
+
left: function(a, x, lo, hi) {
|
16
|
+
if (lo == null) lo = 0;
|
17
|
+
if (hi == null) hi = a.length;
|
18
|
+
while (lo < hi) {
|
19
|
+
var mid = lo + hi >>> 1;
|
20
|
+
if (compare(a[mid], x) < 0) lo = mid + 1;
|
21
|
+
else hi = mid;
|
22
|
+
}
|
23
|
+
return lo;
|
24
|
+
},
|
25
|
+
right: function(a, x, lo, hi) {
|
26
|
+
if (lo == null) lo = 0;
|
27
|
+
if (hi == null) hi = a.length;
|
28
|
+
while (lo < hi) {
|
29
|
+
var mid = lo + hi >>> 1;
|
30
|
+
if (compare(a[mid], x) > 0) hi = mid;
|
31
|
+
else lo = mid + 1;
|
32
|
+
}
|
33
|
+
return lo;
|
34
|
+
}
|
35
|
+
};
|
36
|
+
}
|
37
|
+
|
38
|
+
function ascendingComparator(f) {
|
39
|
+
return function(d, x) {
|
40
|
+
return ascending(f(d), x);
|
41
|
+
};
|
42
|
+
}
|
43
|
+
|
44
|
+
var ascendingBisect = bisector(ascending);
|
45
|
+
var bisectRight = ascendingBisect.right;
|
46
|
+
var bisectLeft = ascendingBisect.left;
|
47
|
+
|
48
|
+
function pairs(array, f) {
|
49
|
+
if (f == null) f = pair;
|
50
|
+
var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
|
51
|
+
while (i < n) pairs[i] = f(p, p = array[++i]);
|
52
|
+
return pairs;
|
53
|
+
}
|
54
|
+
|
55
|
+
function pair(a, b) {
|
56
|
+
return [a, b];
|
57
|
+
}
|
58
|
+
|
59
|
+
function cross(values0, values1, reduce) {
|
60
|
+
var n0 = values0.length,
|
61
|
+
n1 = values1.length,
|
62
|
+
values = new Array(n0 * n1),
|
63
|
+
i0,
|
64
|
+
i1,
|
65
|
+
i,
|
66
|
+
value0;
|
67
|
+
|
68
|
+
if (reduce == null) reduce = pair;
|
69
|
+
|
70
|
+
for (i0 = i = 0; i0 < n0; ++i0) {
|
71
|
+
for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
|
72
|
+
values[i] = reduce(value0, values1[i1]);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
return values;
|
77
|
+
}
|
78
|
+
|
79
|
+
function descending(a, b) {
|
80
|
+
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
|
81
|
+
}
|
82
|
+
|
83
|
+
function number(x) {
|
84
|
+
return x === null ? NaN : +x;
|
85
|
+
}
|
86
|
+
|
87
|
+
function variance(values, valueof) {
|
88
|
+
var n = values.length,
|
89
|
+
m = 0,
|
90
|
+
i = -1,
|
91
|
+
mean = 0,
|
92
|
+
value,
|
93
|
+
delta,
|
94
|
+
sum = 0;
|
95
|
+
|
96
|
+
if (valueof == null) {
|
97
|
+
while (++i < n) {
|
98
|
+
if (!isNaN(value = number(values[i]))) {
|
99
|
+
delta = value - mean;
|
100
|
+
mean += delta / ++m;
|
101
|
+
sum += delta * (value - mean);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
else {
|
107
|
+
while (++i < n) {
|
108
|
+
if (!isNaN(value = number(valueof(values[i], i, values)))) {
|
109
|
+
delta = value - mean;
|
110
|
+
mean += delta / ++m;
|
111
|
+
sum += delta * (value - mean);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
if (m > 1) return sum / (m - 1);
|
117
|
+
}
|
118
|
+
|
119
|
+
function deviation(array, f) {
|
120
|
+
var v = variance(array, f);
|
121
|
+
return v ? Math.sqrt(v) : v;
|
122
|
+
}
|
123
|
+
|
124
|
+
function extent(values, valueof) {
|
125
|
+
var n = values.length,
|
126
|
+
i = -1,
|
127
|
+
value,
|
128
|
+
min,
|
129
|
+
max;
|
130
|
+
|
131
|
+
if (valueof == null) {
|
132
|
+
while (++i < n) { // Find the first comparable value.
|
133
|
+
if ((value = values[i]) != null && value >= value) {
|
134
|
+
min = max = value;
|
135
|
+
while (++i < n) { // Compare the remaining values.
|
136
|
+
if ((value = values[i]) != null) {
|
137
|
+
if (min > value) min = value;
|
138
|
+
if (max < value) max = value;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
else {
|
146
|
+
while (++i < n) { // Find the first comparable value.
|
147
|
+
if ((value = valueof(values[i], i, values)) != null && value >= value) {
|
148
|
+
min = max = value;
|
149
|
+
while (++i < n) { // Compare the remaining values.
|
150
|
+
if ((value = valueof(values[i], i, values)) != null) {
|
151
|
+
if (min > value) min = value;
|
152
|
+
if (max < value) max = value;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
return [min, max];
|
160
|
+
}
|
161
|
+
|
162
|
+
var array = Array.prototype;
|
163
|
+
|
164
|
+
var slice = array.slice;
|
165
|
+
var map = array.map;
|
166
|
+
|
167
|
+
function constant(x) {
|
168
|
+
return function() {
|
169
|
+
return x;
|
170
|
+
};
|
171
|
+
}
|
172
|
+
|
173
|
+
function identity(x) {
|
174
|
+
return x;
|
175
|
+
}
|
176
|
+
|
177
|
+
function range(start, stop, step) {
|
178
|
+
start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
|
179
|
+
|
180
|
+
var i = -1,
|
181
|
+
n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
|
182
|
+
range = new Array(n);
|
183
|
+
|
184
|
+
while (++i < n) {
|
185
|
+
range[i] = start + i * step;
|
186
|
+
}
|
187
|
+
|
188
|
+
return range;
|
189
|
+
}
|
190
|
+
|
191
|
+
var e10 = Math.sqrt(50),
|
192
|
+
e5 = Math.sqrt(10),
|
193
|
+
e2 = Math.sqrt(2);
|
194
|
+
|
195
|
+
function ticks(start, stop, count) {
|
196
|
+
var reverse,
|
197
|
+
i = -1,
|
198
|
+
n,
|
199
|
+
ticks,
|
200
|
+
step;
|
201
|
+
|
202
|
+
stop = +stop, start = +start, count = +count;
|
203
|
+
if (start === stop && count > 0) return [start];
|
204
|
+
if (reverse = stop < start) n = start, start = stop, stop = n;
|
205
|
+
if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
|
206
|
+
|
207
|
+
if (step > 0) {
|
208
|
+
start = Math.ceil(start / step);
|
209
|
+
stop = Math.floor(stop / step);
|
210
|
+
ticks = new Array(n = Math.ceil(stop - start + 1));
|
211
|
+
while (++i < n) ticks[i] = (start + i) * step;
|
212
|
+
} else {
|
213
|
+
start = Math.floor(start * step);
|
214
|
+
stop = Math.ceil(stop * step);
|
215
|
+
ticks = new Array(n = Math.ceil(start - stop + 1));
|
216
|
+
while (++i < n) ticks[i] = (start - i) / step;
|
217
|
+
}
|
218
|
+
|
219
|
+
if (reverse) ticks.reverse();
|
220
|
+
|
221
|
+
return ticks;
|
222
|
+
}
|
223
|
+
|
224
|
+
function tickIncrement(start, stop, count) {
|
225
|
+
var step = (stop - start) / Math.max(0, count),
|
226
|
+
power = Math.floor(Math.log(step) / Math.LN10),
|
227
|
+
error = step / Math.pow(10, power);
|
228
|
+
return power >= 0
|
229
|
+
? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
|
230
|
+
: -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
|
231
|
+
}
|
232
|
+
|
233
|
+
function tickStep(start, stop, count) {
|
234
|
+
var step0 = Math.abs(stop - start) / Math.max(0, count),
|
235
|
+
step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
|
236
|
+
error = step0 / step1;
|
237
|
+
if (error >= e10) step1 *= 10;
|
238
|
+
else if (error >= e5) step1 *= 5;
|
239
|
+
else if (error >= e2) step1 *= 2;
|
240
|
+
return stop < start ? -step1 : step1;
|
241
|
+
}
|
242
|
+
|
243
|
+
function sturges(values) {
|
244
|
+
return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
|
245
|
+
}
|
246
|
+
|
247
|
+
function histogram() {
|
248
|
+
var value = identity,
|
249
|
+
domain = extent,
|
250
|
+
threshold = sturges;
|
251
|
+
|
252
|
+
function histogram(data) {
|
253
|
+
var i,
|
254
|
+
n = data.length,
|
255
|
+
x,
|
256
|
+
values = new Array(n);
|
257
|
+
|
258
|
+
for (i = 0; i < n; ++i) {
|
259
|
+
values[i] = value(data[i], i, data);
|
260
|
+
}
|
261
|
+
|
262
|
+
var xz = domain(values),
|
263
|
+
x0 = xz[0],
|
264
|
+
x1 = xz[1],
|
265
|
+
tz = threshold(values, x0, x1);
|
266
|
+
|
267
|
+
// Convert number of thresholds into uniform thresholds.
|
268
|
+
if (!Array.isArray(tz)) {
|
269
|
+
tz = tickStep(x0, x1, tz);
|
270
|
+
tz = range(Math.ceil(x0 / tz) * tz, x1, tz); // exclusive
|
271
|
+
}
|
272
|
+
|
273
|
+
// Remove any thresholds outside the domain.
|
274
|
+
var m = tz.length;
|
275
|
+
while (tz[0] <= x0) tz.shift(), --m;
|
276
|
+
while (tz[m - 1] > x1) tz.pop(), --m;
|
277
|
+
|
278
|
+
var bins = new Array(m + 1),
|
279
|
+
bin;
|
280
|
+
|
281
|
+
// Initialize bins.
|
282
|
+
for (i = 0; i <= m; ++i) {
|
283
|
+
bin = bins[i] = [];
|
284
|
+
bin.x0 = i > 0 ? tz[i - 1] : x0;
|
285
|
+
bin.x1 = i < m ? tz[i] : x1;
|
286
|
+
}
|
287
|
+
|
288
|
+
// Assign data to bins by value, ignoring any outside the domain.
|
289
|
+
for (i = 0; i < n; ++i) {
|
290
|
+
x = values[i];
|
291
|
+
if (x0 <= x && x <= x1) {
|
292
|
+
bins[bisectRight(tz, x, 0, m)].push(data[i]);
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
return bins;
|
297
|
+
}
|
298
|
+
|
299
|
+
histogram.value = function(_) {
|
300
|
+
return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
|
301
|
+
};
|
302
|
+
|
303
|
+
histogram.domain = function(_) {
|
304
|
+
return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
|
305
|
+
};
|
306
|
+
|
307
|
+
histogram.thresholds = function(_) {
|
308
|
+
return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
|
309
|
+
};
|
310
|
+
|
311
|
+
return histogram;
|
312
|
+
}
|
313
|
+
|
314
|
+
function quantile(values, p, valueof) {
|
315
|
+
if (valueof == null) valueof = number;
|
316
|
+
if (!(n = values.length)) return;
|
317
|
+
if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
|
318
|
+
if (p >= 1) return +valueof(values[n - 1], n - 1, values);
|
319
|
+
var n,
|
320
|
+
i = (n - 1) * p,
|
321
|
+
i0 = Math.floor(i),
|
322
|
+
value0 = +valueof(values[i0], i0, values),
|
323
|
+
value1 = +valueof(values[i0 + 1], i0 + 1, values);
|
324
|
+
return value0 + (value1 - value0) * (i - i0);
|
325
|
+
}
|
326
|
+
|
327
|
+
function freedmanDiaconis(values, min, max) {
|
328
|
+
values = map.call(values, number).sort(ascending);
|
329
|
+
return Math.ceil((max - min) / (2 * (quantile(values, 0.75) - quantile(values, 0.25)) * Math.pow(values.length, -1 / 3)));
|
330
|
+
}
|
331
|
+
|
332
|
+
function scott(values, min, max) {
|
333
|
+
return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
|
334
|
+
}
|
335
|
+
|
336
|
+
function max(values, valueof) {
|
337
|
+
var n = values.length,
|
338
|
+
i = -1,
|
339
|
+
value,
|
340
|
+
max;
|
341
|
+
|
342
|
+
if (valueof == null) {
|
343
|
+
while (++i < n) { // Find the first comparable value.
|
344
|
+
if ((value = values[i]) != null && value >= value) {
|
345
|
+
max = value;
|
346
|
+
while (++i < n) { // Compare the remaining values.
|
347
|
+
if ((value = values[i]) != null && value > max) {
|
348
|
+
max = value;
|
349
|
+
}
|
350
|
+
}
|
351
|
+
}
|
352
|
+
}
|
353
|
+
}
|
354
|
+
|
355
|
+
else {
|
356
|
+
while (++i < n) { // Find the first comparable value.
|
357
|
+
if ((value = valueof(values[i], i, values)) != null && value >= value) {
|
358
|
+
max = value;
|
359
|
+
while (++i < n) { // Compare the remaining values.
|
360
|
+
if ((value = valueof(values[i], i, values)) != null && value > max) {
|
361
|
+
max = value;
|
362
|
+
}
|
363
|
+
}
|
364
|
+
}
|
365
|
+
}
|
366
|
+
}
|
367
|
+
|
368
|
+
return max;
|
369
|
+
}
|
370
|
+
|
371
|
+
function mean(values, valueof) {
|
372
|
+
var n = values.length,
|
373
|
+
m = n,
|
374
|
+
i = -1,
|
375
|
+
value,
|
376
|
+
sum = 0;
|
377
|
+
|
378
|
+
if (valueof == null) {
|
379
|
+
while (++i < n) {
|
380
|
+
if (!isNaN(value = number(values[i]))) sum += value;
|
381
|
+
else --m;
|
382
|
+
}
|
383
|
+
}
|
384
|
+
|
385
|
+
else {
|
386
|
+
while (++i < n) {
|
387
|
+
if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
|
388
|
+
else --m;
|
389
|
+
}
|
390
|
+
}
|
391
|
+
|
392
|
+
if (m) return sum / m;
|
393
|
+
}
|
394
|
+
|
395
|
+
function median(values, valueof) {
|
396
|
+
var n = values.length,
|
397
|
+
i = -1,
|
398
|
+
value,
|
399
|
+
numbers = [];
|
400
|
+
|
401
|
+
if (valueof == null) {
|
402
|
+
while (++i < n) {
|
403
|
+
if (!isNaN(value = number(values[i]))) {
|
404
|
+
numbers.push(value);
|
405
|
+
}
|
406
|
+
}
|
407
|
+
}
|
408
|
+
|
409
|
+
else {
|
410
|
+
while (++i < n) {
|
411
|
+
if (!isNaN(value = number(valueof(values[i], i, values)))) {
|
412
|
+
numbers.push(value);
|
413
|
+
}
|
414
|
+
}
|
415
|
+
}
|
416
|
+
|
417
|
+
return quantile(numbers.sort(ascending), 0.5);
|
418
|
+
}
|
419
|
+
|
420
|
+
function merge(arrays) {
|
421
|
+
var n = arrays.length,
|
422
|
+
m,
|
423
|
+
i = -1,
|
424
|
+
j = 0,
|
425
|
+
merged,
|
426
|
+
array;
|
427
|
+
|
428
|
+
while (++i < n) j += arrays[i].length;
|
429
|
+
merged = new Array(j);
|
430
|
+
|
431
|
+
while (--n >= 0) {
|
432
|
+
array = arrays[n];
|
433
|
+
m = array.length;
|
434
|
+
while (--m >= 0) {
|
435
|
+
merged[--j] = array[m];
|
436
|
+
}
|
437
|
+
}
|
438
|
+
|
439
|
+
return merged;
|
440
|
+
}
|
441
|
+
|
442
|
+
function min(values, valueof) {
|
443
|
+
var n = values.length,
|
444
|
+
i = -1,
|
445
|
+
value,
|
446
|
+
min;
|
447
|
+
|
448
|
+
if (valueof == null) {
|
449
|
+
while (++i < n) { // Find the first comparable value.
|
450
|
+
if ((value = values[i]) != null && value >= value) {
|
451
|
+
min = value;
|
452
|
+
while (++i < n) { // Compare the remaining values.
|
453
|
+
if ((value = values[i]) != null && min > value) {
|
454
|
+
min = value;
|
455
|
+
}
|
456
|
+
}
|
457
|
+
}
|
458
|
+
}
|
459
|
+
}
|
460
|
+
|
461
|
+
else {
|
462
|
+
while (++i < n) { // Find the first comparable value.
|
463
|
+
if ((value = valueof(values[i], i, values)) != null && value >= value) {
|
464
|
+
min = value;
|
465
|
+
while (++i < n) { // Compare the remaining values.
|
466
|
+
if ((value = valueof(values[i], i, values)) != null && min > value) {
|
467
|
+
min = value;
|
468
|
+
}
|
469
|
+
}
|
470
|
+
}
|
471
|
+
}
|
472
|
+
}
|
473
|
+
|
474
|
+
return min;
|
475
|
+
}
|
476
|
+
|
477
|
+
function permute(array, indexes) {
|
478
|
+
var i = indexes.length, permutes = new Array(i);
|
479
|
+
while (i--) permutes[i] = array[indexes[i]];
|
480
|
+
return permutes;
|
481
|
+
}
|
482
|
+
|
483
|
+
function scan(values, compare) {
|
484
|
+
if (!(n = values.length)) return;
|
485
|
+
var n,
|
486
|
+
i = 0,
|
487
|
+
j = 0,
|
488
|
+
xi,
|
489
|
+
xj = values[j];
|
490
|
+
|
491
|
+
if (compare == null) compare = ascending;
|
492
|
+
|
493
|
+
while (++i < n) {
|
494
|
+
if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
|
495
|
+
xj = xi, j = i;
|
496
|
+
}
|
497
|
+
}
|
498
|
+
|
499
|
+
if (compare(xj, xj) === 0) return j;
|
500
|
+
}
|
501
|
+
|
502
|
+
function shuffle(array, i0, i1) {
|
503
|
+
var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
|
504
|
+
t,
|
505
|
+
i;
|
506
|
+
|
507
|
+
while (m) {
|
508
|
+
i = Math.random() * m-- | 0;
|
509
|
+
t = array[m + i0];
|
510
|
+
array[m + i0] = array[i + i0];
|
511
|
+
array[i + i0] = t;
|
512
|
+
}
|
513
|
+
|
514
|
+
return array;
|
515
|
+
}
|
516
|
+
|
517
|
+
function sum(values, valueof) {
|
518
|
+
var n = values.length,
|
519
|
+
i = -1,
|
520
|
+
value,
|
521
|
+
sum = 0;
|
522
|
+
|
523
|
+
if (valueof == null) {
|
524
|
+
while (++i < n) {
|
525
|
+
if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
|
526
|
+
}
|
527
|
+
}
|
528
|
+
|
529
|
+
else {
|
530
|
+
while (++i < n) {
|
531
|
+
if (value = +valueof(values[i], i, values)) sum += value;
|
532
|
+
}
|
533
|
+
}
|
534
|
+
|
535
|
+
return sum;
|
536
|
+
}
|
537
|
+
|
538
|
+
function transpose(matrix) {
|
539
|
+
if (!(n = matrix.length)) return [];
|
540
|
+
for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
|
541
|
+
for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
|
542
|
+
row[j] = matrix[j][i];
|
543
|
+
}
|
544
|
+
}
|
545
|
+
return transpose;
|
546
|
+
}
|
547
|
+
|
548
|
+
function length(d) {
|
549
|
+
return d.length;
|
550
|
+
}
|
551
|
+
|
552
|
+
function zip() {
|
553
|
+
return transpose(arguments);
|
554
|
+
}
|
555
|
+
|
556
|
+
exports.bisect = bisectRight;
|
557
|
+
exports.bisectRight = bisectRight;
|
558
|
+
exports.bisectLeft = bisectLeft;
|
559
|
+
exports.ascending = ascending;
|
560
|
+
exports.bisector = bisector;
|
561
|
+
exports.cross = cross;
|
562
|
+
exports.descending = descending;
|
563
|
+
exports.deviation = deviation;
|
564
|
+
exports.extent = extent;
|
565
|
+
exports.histogram = histogram;
|
566
|
+
exports.thresholdFreedmanDiaconis = freedmanDiaconis;
|
567
|
+
exports.thresholdScott = scott;
|
568
|
+
exports.thresholdSturges = sturges;
|
569
|
+
exports.max = max;
|
570
|
+
exports.mean = mean;
|
571
|
+
exports.median = median;
|
572
|
+
exports.merge = merge;
|
573
|
+
exports.min = min;
|
574
|
+
exports.pairs = pairs;
|
575
|
+
exports.permute = permute;
|
576
|
+
exports.quantile = quantile;
|
577
|
+
exports.range = range;
|
578
|
+
exports.scan = scan;
|
579
|
+
exports.shuffle = shuffle;
|
580
|
+
exports.sum = sum;
|
581
|
+
exports.ticks = ticks;
|
582
|
+
exports.tickIncrement = tickIncrement;
|
583
|
+
exports.tickStep = tickStep;
|
584
|
+
exports.transpose = transpose;
|
585
|
+
exports.variance = variance;
|
586
|
+
exports.zip = zip;
|
587
|
+
|
588
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
589
|
+
|
590
|
+
})));
|