forked from react-d3/react-d3-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-d3-basic.js
15339 lines (12828 loc) · 483 KB
/
react-d3-basic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var ReactD3Basic =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PieChart = exports.BarStackHorizontalChart = exports.BarStackChart = exports.AreaStackChart = exports.BarGroupHorizontalChart = exports.BarGroupChart = exports.BarHorizontalChart = exports.BarChart = exports.ScatterPlot = exports.AreaChart = exports.LineChart = undefined;
var _line = __webpack_require__(1);
var _line2 = _interopRequireDefault(_line);
var _area = __webpack_require__(63);
var _area2 = _interopRequireDefault(_area);
var _scatter = __webpack_require__(64);
var _scatter2 = _interopRequireDefault(_scatter);
var _bar = __webpack_require__(65);
var _bar2 = _interopRequireDefault(_bar);
var _bar_horizontal = __webpack_require__(66);
var _bar_horizontal2 = _interopRequireDefault(_bar_horizontal);
var _bar_group = __webpack_require__(67);
var _bar_group2 = _interopRequireDefault(_bar_group);
var _bar_group_horizontal = __webpack_require__(68);
var _bar_group_horizontal2 = _interopRequireDefault(_bar_group_horizontal);
var _area_stack = __webpack_require__(69);
var _area_stack2 = _interopRequireDefault(_area_stack);
var _bar_stack = __webpack_require__(70);
var _bar_stack2 = _interopRequireDefault(_bar_stack);
var _bar_stack_horizontal = __webpack_require__(71);
var _bar_stack_horizontal2 = _interopRequireDefault(_bar_stack_horizontal);
var _pie = __webpack_require__(72);
var _pie2 = _interopRequireDefault(_pie);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.LineChart = _line2.default; // Export high level charts
exports.AreaChart = _area2.default;
exports.ScatterPlot = _scatter2.default;
exports.BarChart = _bar2.default;
exports.BarHorizontalChart = _bar_horizontal2.default;
exports.BarGroupChart = _bar_group2.default;
exports.BarGroupHorizontalChart = _bar_group_horizontal2.default;
exports.AreaStackChart = _area_stack2.default;
exports.BarStackChart = _bar_stack2.default;
exports.BarStackHorizontalChart = _bar_stack_horizontal2.default;
exports.PieChart = _pie2.default;
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = __webpack_require__(2);
var _react2 = _interopRequireDefault(_react);
var _reactD3Core = __webpack_require__(3);
var _reactD3Shape = __webpack_require__(43);
var _commonProps = __webpack_require__(62);
var _commonProps2 = _interopRequireDefault(_commonProps);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var LineChart = function (_Component) {
_inherits(LineChart, _Component);
function LineChart(props) {
_classCallCheck(this, LineChart);
return _possibleConstructorReturn(this, Object.getPrototypeOf(LineChart).call(this, props));
}
_createClass(LineChart, [{
key: 'render',
value: function render() {
var _props = this.props;
var width = _props.width;
var height = _props.height;
var margins = _props.margins;
var data = _props.data;
var chartSeries = _props.chartSeries;
var showXGrid = _props.showXGrid;
var showYGrid = _props.showYGrid;
var showLegend = _props.showLegend;
var categoricalColors = _props.categoricalColors;
var xgrid, ygrid;
if (showXGrid) xgrid = _react2.default.createElement(_reactD3Core.Xgrid, null);
if (showYGrid) ygrid = _react2.default.createElement(_reactD3Core.Ygrid, null);
return _react2.default.createElement(
'div',
null,
showLegend ? _react2.default.createElement(_reactD3Core.Legend, _extends({}, this.props, {
width: width,
margins: margins,
chartSeries: chartSeries,
categoricalColors: categoricalColors
})) : null,
_react2.default.createElement(
_reactD3Shape.Chart,
_extends({}, this.props, {
width: width,
height: height,
data: data,
chartSeries: chartSeries
}),
_react2.default.createElement(_reactD3Shape.Line, {
chartSeries: chartSeries
}),
xgrid,
ygrid,
_react2.default.createElement(_reactD3Core.Xaxis, null),
_react2.default.createElement(_reactD3Core.Yaxis, null),
this.props.children
)
);
}
}]);
return LineChart;
}(_react.Component);
LineChart.defaultProps = _extends({
showScatter: false
}, _commonProps2.default);
LineChart.propTypes = {
width: _react.PropTypes.number.isRequired,
height: _react.PropTypes.number.isRequired,
margins: _react.PropTypes.object.isRequired,
data: _react.PropTypes.array.isRequired,
chartSeries: _react.PropTypes.array.isRequired
};
exports.default = LineChart;
module.exports = exports['default'];
/***/ },
/* 2 */
/***/ function(module, exports) {
module.exports = React;
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _svg = __webpack_require__(4);
Object.defineProperty(exports, 'Svg', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_svg).default;
}
});
var _title = __webpack_require__(15);
Object.defineProperty(exports, 'Title', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_title).default;
}
});
var _chartContainer = __webpack_require__(16);
Object.defineProperty(exports, 'Chart', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_chartContainer).default;
}
});
var _axis = __webpack_require__(33);
Object.defineProperty(exports, 'Axis', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_axis).default;
}
});
var _xaxis = __webpack_require__(35);
Object.defineProperty(exports, 'Xaxis', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_xaxis).default;
}
});
var _yaxis = __webpack_require__(37);
Object.defineProperty(exports, 'Yaxis', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_yaxis).default;
}
});
var _label = __webpack_require__(36);
Object.defineProperty(exports, 'Label', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_label).default;
}
});
var _legend = __webpack_require__(17);
Object.defineProperty(exports, 'Legend', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_legend).default;
}
});
var _grid = __webpack_require__(38);
Object.defineProperty(exports, 'Grid', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_grid).default;
}
});
var _xgrid = __webpack_require__(39);
Object.defineProperty(exports, 'Xgrid', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_xgrid).default;
}
});
var _ygrid = __webpack_require__(40);
Object.defineProperty(exports, 'Ygrid', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_ygrid).default;
}
});
var _scale = __webpack_require__(6);
Object.defineProperty(exports, 'scale', {
enumerable: true,
get: function get() {
return _scale.scale;
}
});
var _xDomain = __webpack_require__(41);
Object.defineProperty(exports, 'xDomainCount', {
enumerable: true,
get: function get() {
return _xDomain.xDomain;
}
});
var _yDomain = __webpack_require__(42);
Object.defineProperty(exports, 'yDomainCount', {
enumerable: true,
get: function get() {
return _yDomain.yDomain;
}
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = __webpack_require__(2);
var _react2 = _interopRequireDefault(_react);
var _commonProps = __webpack_require__(5);
var _commonProps2 = _interopRequireDefault(_commonProps);
var _scale = __webpack_require__(6);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ChartSvg = function (_Component) {
_inherits(ChartSvg, _Component);
function ChartSvg(props) {
_classCallCheck(this, ChartSvg);
return _possibleConstructorReturn(this, Object.getPrototypeOf(ChartSvg).call(this, props));
}
_createClass(ChartSvg, [{
key: 'render',
value: function render() {
var _props = this.props;
var height = _props.height;
var width = _props.width;
var margins = _props.margins;
var svgClassName = _props.svgClassName;
var id = _props.id;
var children = _props.children;
var t = 'translate(' + margins.left + ', ' + margins.top + ')';
return _react2.default.createElement(
'svg',
{
height: height,
width: width,
className: svgClassName,
id: id,
ref: 'svgContainer'
},
_react2.default.createElement(
'g',
{
transform: t
},
children
)
);
}
}]);
return ChartSvg;
}(_react.Component);
ChartSvg.defaultProps = _extends({
svgClassName: 'react-d3-core__container_svg',
onZoom: function onZoom() {},
scaleExtent: [1, 10]
}, _commonProps2.default);
ChartSvg.propTypes = {
id: _react.PropTypes.string,
width: _react.PropTypes.number.isRequired,
height: _react.PropTypes.number.isRequired,
margins: _react.PropTypes.object.isRequired,
svgClassName: _react.PropTypes.string.isRequired
};
exports.default = ChartSvg;
/***/ },
/* 5 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
width: 960,
height: 500,
margins: { top: 80, right: 100, bottom: 80, left: 100 }
};
/***/ },
/* 6 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.scale = scale;
var _d3Scale = __webpack_require__(7);
var _d3Scale2 = _interopRequireDefault(_d3Scale);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function scale(props) {
var type = props.type;
var scale = props.scale;
var func;
if (scale === 'linear') func = _d3Scale2.default.scaleLinear();else if (scale === 'identity') func = _d3Scale2.default.scaleIdentity();else if (scale === 'sqrt') func = _d3Scale2.default.scaleSqrt();else if (scale === 'pow') func = _d3Scale2.default.scalePow();else if (scale === 'log') func = _d3Scale2.default.scaleLog();else if (scale === 'quantize') func = _d3Scale2.default.scaleQuantize();else if (scale === 'quantile') func = _d3Scale2.default.scaleQuantile();else if (scale === 'ordinal') func = _d3Scale2.default.scaleOrdinal();else if (scale === 'band') func = _d3Scale2.default.scaleBand();else if (scale === 'time') func = _d3Scale2.default.scaleTime();else new Error('Please check your axis scale setting. "' + scale + '" scale is invalid. ');
func = _mkScaleSettings(props, func);
return func;
}
function _mkScaleSettings(props, func) {
var type = props.type;
var range = props.range;
var domain = props.domain;
var scale = props.scale;
var bandPaddingInner = props.bandPaddingInner;
var bandPaddingOuter = props.bandPaddingOuter;
if (range) func.range(range);
if (domain) func.domain(domain);
if (scale === 'band') {
func.round(true);
if (bandPaddingInner) func.paddingInner(bandPaddingInner);else func.paddingInner(.1);
if (bandPaddingOuter) func.paddingOuter(bandPaddingOuter);else func.paddingOuter(.1);
}
return func;
}
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
(function (global, factory) {
true ? factory(exports, __webpack_require__(8), __webpack_require__(9), __webpack_require__(10), __webpack_require__(12), __webpack_require__(13), __webpack_require__(14), __webpack_require__(11)) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-array', 'd3-collection', 'd3-interpolate', 'd3-format', 'd3-time', 'd3-time-format', 'd3-color'], factory) :
(factory((global.d3_scale = global.d3_scale || {}),global.d3_array,global.d3_collection,global.d3_interpolate,global.d3_format,global.d3_time,global.d3_time_format,global.d3_color));
}(this, function (exports,d3Array,d3Collection,d3Interpolate,d3Format,d3Time,d3TimeFormat,d3Color) { 'use strict';
var array = Array.prototype;
var map$1 = array.map;
var slice = array.slice;
var implicit = {name: "implicit"};
function ordinal() {
var index = d3Collection.map(),
domain = [],
range = [],
unknown = implicit;
function scale(d) {
var key = d + "", i = index.get(key);
if (!i) {
if (unknown !== implicit) return unknown;
index.set(key, i = domain.push(d));
}
return range[(i - 1) % range.length];
}
scale.domain = function(_) {
if (!arguments.length) return domain.slice();
domain = [], index = d3Collection.map();
var i = -1, n = _.length, d, key;
while (++i < n) if (!index.has(key = (d = _[i]) + "")) index.set(key, domain.push(d));
return scale;
};
scale.range = function(_) {
return arguments.length ? (range = slice.call(_), scale) : range.slice();
};
scale.unknown = function(_) {
return arguments.length ? (unknown = _, scale) : unknown;
};
scale.copy = function() {
return ordinal()
.domain(domain)
.range(range)
.unknown(unknown);
};
return scale;
}
function band() {
var scale = ordinal().unknown(undefined),
domain = scale.domain,
ordinalRange = scale.range,
range = [0, 1],
step,
bandwidth,
round = false,
paddingInner = 0,
paddingOuter = 0,
align = 0.5;
delete scale.unknown;
function rescale() {
var n = domain().length,
reverse = range[1] < range[0],
start = range[reverse - 0],
stop = range[1 - reverse];
step = (stop - start) / Math.max(1, n - paddingInner + paddingOuter * 2);
if (round) step = Math.floor(step);
start += (stop - start - step * (n - paddingInner)) * align;
bandwidth = step * (1 - paddingInner);
if (round) start = Math.round(start), bandwidth = Math.round(bandwidth);
var values = d3Array.range(n).map(function(i) { return start + step * i; });
return ordinalRange(reverse ? values.reverse() : values);
}
scale.domain = function(_) {
return arguments.length ? (domain(_), rescale()) : domain();
};
scale.range = function(_) {
return arguments.length ? (range = [+_[0], +_[1]], rescale()) : range.slice();
};
scale.rangeRound = function(_) {
return range = [+_[0], +_[1]], round = true, rescale();
};
scale.bandwidth = function() {
return bandwidth;
};
scale.step = function() {
return step;
};
scale.round = function(_) {
return arguments.length ? (round = !!_, rescale()) : round;
};
scale.padding = function(_) {
return arguments.length ? (paddingInner = paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
};
scale.paddingInner = function(_) {
return arguments.length ? (paddingInner = Math.max(0, Math.min(1, _)), rescale()) : paddingInner;
};
scale.paddingOuter = function(_) {
return arguments.length ? (paddingOuter = Math.max(0, Math.min(1, _)), rescale()) : paddingOuter;
};
scale.align = function(_) {
return arguments.length ? (align = Math.max(0, Math.min(1, _)), rescale()) : align;
};
scale.copy = function() {
return band()
.domain(domain())
.range(range)
.round(round)
.paddingInner(paddingInner)
.paddingOuter(paddingOuter)
.align(align);
};
return rescale();
}
function pointish(scale) {
var copy = scale.copy;
scale.padding = scale.paddingOuter;
delete scale.paddingInner;
delete scale.paddingOuter;
scale.copy = function() {
return pointish(copy());
};
return scale;
}
function point() {
return pointish(band().paddingInner(1));
}
function constant(x) {
return function() {
return x;
};
}
function number(x) {
return +x;
}
var unit = [0, 1];
function deinterpolate(a, b) {
return (b -= (a = +a))
? function(x) { return (x - a) / b; }
: constant(b);
}
function deinterpolateClamp(deinterpolate) {
return function(a, b) {
var d = deinterpolate(a = +a, b = +b);
return function(x) { return x <= a ? 0 : x >= b ? 1 : d(x); };
};
}
function reinterpolateClamp(reinterpolate) {
return function(a, b) {
var r = reinterpolate(a = +a, b = +b);
return function(t) { return t <= 0 ? a : t >= 1 ? b : r(t); };
};
}
function bimap(domain, range, deinterpolate, reinterpolate) {
var d0 = domain[0], d1 = domain[1], r0 = range[0], r1 = range[1];
if (d1 < d0) d0 = deinterpolate(d1, d0), r0 = reinterpolate(r1, r0);
else d0 = deinterpolate(d0, d1), r0 = reinterpolate(r0, r1);
return function(x) { return r0(d0(x)); };
}
function polymap(domain, range, deinterpolate, reinterpolate) {
var j = Math.min(domain.length, range.length) - 1,
d = new Array(j),
r = new Array(j),
i = -1;
// Reverse descending domains.
if (domain[j] < domain[0]) {
domain = domain.slice().reverse();
range = range.slice().reverse();
}
while (++i < j) {
d[i] = deinterpolate(domain[i], domain[i + 1]);
r[i] = reinterpolate(range[i], range[i + 1]);
}
return function(x) {
var i = d3Array.bisect(domain, x, 1, j) - 1;
return r[i](d[i](x));
};
}
function copy(source, target) {
return target
.domain(source.domain())
.range(source.range())
.interpolate(source.interpolate())
.clamp(source.clamp());
}
// deinterpolate(a, b)(x) takes a domain value x in [a,b] and returns the corresponding parameter t in [0,1].
// reinterpolate(a, b)(t) takes a parameter t in [0,1] and returns the corresponding domain value x in [a,b].
function continuous(deinterpolate$$, reinterpolate) {
var domain = unit,
range = unit,
interpolate = d3Interpolate.interpolate,
clamp = false,
output,
input;
function rescale() {
var map = Math.min(domain.length, range.length) > 2 ? polymap : bimap;
output = map(domain, range, clamp ? deinterpolateClamp(deinterpolate$$) : deinterpolate$$, interpolate);
input = map(range, domain, deinterpolate, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate);
return scale;
}
function scale(x) {
return output(+x);
}
scale.invert = function(y) {
return input(+y);
};
scale.domain = function(_) {
return arguments.length ? (domain = map$1.call(_, number), rescale()) : domain.slice();
};
scale.range = function(_) {
return arguments.length ? (range = slice.call(_), rescale()) : range.slice();
};
scale.rangeRound = function(_) {
return range = slice.call(_), interpolate = d3Interpolate.interpolateRound, rescale();
};
scale.clamp = function(_) {
return arguments.length ? (clamp = !!_, rescale()) : clamp;
};
scale.interpolate = function(_) {
return arguments.length ? (interpolate = _, rescale()) : interpolate;
};
return rescale();
}
function tickFormat(domain, count, specifier) {
var start = domain[0],
stop = domain[domain.length - 1],
step = d3Array.tickStep(start, stop, count == null ? 10 : count),
precision;
specifier = d3Format.formatSpecifier(specifier == null ? ",f" : specifier);
switch (specifier.type) {
case "s": {
var value = Math.max(Math.abs(start), Math.abs(stop));
if (specifier.precision == null && !isNaN(precision = d3Format.precisionPrefix(step, value))) specifier.precision = precision;
return d3Format.formatPrefix(specifier, value);
}
case "":
case "e":
case "g":
case "p":
case "r": {
if (specifier.precision == null && !isNaN(precision = d3Format.precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
break;
}
case "f":
case "%": {
if (specifier.precision == null && !isNaN(precision = d3Format.precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
break;
}
}
return d3Format.format(specifier);
}
function linearish(scale) {
var domain = scale.domain;
scale.ticks = function(count) {
var d = domain();
return d3Array.ticks(d[0], d[d.length - 1], count == null ? 10 : count);
};
scale.tickFormat = function(count, specifier) {
return tickFormat(domain(), count, specifier);
};
scale.nice = function(count) {
var d = domain(),
i = d.length - 1,
n = count == null ? 10 : count,
start = d[0],
stop = d[i],
step = d3Array.tickStep(start, stop, n);
if (step) {
step = d3Array.tickStep(Math.floor(start / step) * step, Math.ceil(stop / step) * step, n);
d[0] = Math.floor(start / step) * step;
d[i] = Math.ceil(stop / step) * step;
domain(d);
}
return scale;
};
return scale;
}
function linear() {
var scale = continuous(deinterpolate, d3Interpolate.interpolateNumber);
scale.copy = function() {
return copy(scale, linear());
};
return linearish(scale);
}
function identity() {
var domain = [0, 1];
function scale(x) {
return +x;
}
scale.invert = scale;
scale.domain = scale.range = function(_) {
return arguments.length ? (domain = map$1.call(_, number), scale) : domain.slice();
};
scale.copy = function() {
return identity().domain(domain);
};
return linearish(scale);
}
function nice(domain, interval) {
domain = domain.slice();
var i0 = 0,
i1 = domain.length - 1,
x0 = domain[i0],
x1 = domain[i1],
t;
if (x1 < x0) {
t = i0, i0 = i1, i1 = t;
t = x0, x0 = x1, x1 = t;
}
domain[i0] = interval.floor(x0);
domain[i1] = interval.ceil(x1);
return domain;
}
function deinterpolate$1(a, b) {
return (b = Math.log(b / a))
? function(x) { return Math.log(x / a) / b; }
: constant(b);
}
function reinterpolate(a, b) {
return a < 0
? function(t) { return -Math.pow(-b, t) * Math.pow(-a, 1 - t); }
: function(t) { return Math.pow(b, t) * Math.pow(a, 1 - t); };
}
function pow10(x) {
return isFinite(x) ? +("1e" + x) : x < 0 ? 0 : x;
}
function powp(base) {
return base === 10 ? pow10
: base === Math.E ? Math.exp
: function(x) { return Math.pow(base, x); };
}
function logp(base) {
return base === Math.E ? Math.log
: base === 10 && Math.log10
|| base === 2 && Math.log2
|| (base = Math.log(base), function(x) { return Math.log(x) / base; });
}
function reflect(f) {
return function(x) {
return -f(-x);
};
}
function log() {
var scale = continuous(deinterpolate$1, reinterpolate).domain([1, 10]),
domain = scale.domain,
base = 10,
logs = logp(10),
pows = powp(10);
function rescale() {
logs = logp(base), pows = powp(base);
if (domain()[0] < 0) logs = reflect(logs), pows = reflect(pows);
return scale;
}
scale.base = function(_) {
return arguments.length ? (base = +_, rescale()) : base;
};
scale.domain = function(_) {
return arguments.length ? (domain(_), rescale()) : domain();
};
scale.ticks = function(count) {
var d = domain(),
u = d[0],
v = d[d.length - 1],
r;
if (r = v < u) i = u, u = v, v = i;
var i = logs(u),
j = logs(v),
p,
k,
t,
n = count == null ? 10 : +count,
z = [];
if (!(base % 1) && j - i < n) {
i = Math.round(i) - 1, j = Math.round(j) + 1;
if (u > 0) for (; i < j; ++i) {
for (k = 1, p = pows(i); k < base; ++k) {
t = p * k;
if (t < u) continue;
if (t > v) break;
z.push(t);
}
} else for (; i < j; ++i) {
for (k = base - 1, p = pows(i); k >= 1; --k) {
t = p * k;
if (t < u) continue;