Skip to content
This repository was archived by the owner on Nov 2, 2021. It is now read-only.

Commit 8ee575b

Browse files
committed
3.0.0-8
1 parent c2c7afb commit 8ee575b

File tree

5 files changed

+155
-171
lines changed

5 files changed

+155
-171
lines changed

dist/d3kit-es.js

Lines changed: 76 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ var AbstractChart = function () {
10641064

10651065
var mergedOptions = deepExtend.apply(undefined, [{}, AbstractChart.DEFAULT_OPTIONS].concat(options));
10661066

1067-
this.state = {
1067+
this._state = {
10681068
width: mergedOptions.initialWidth,
10691069
height: mergedOptions.initialHeight,
10701070
innerWidth: 0,
@@ -1075,70 +1075,72 @@ var AbstractChart = function () {
10751075
};
10761076

10771077
this.container = select(selector);
1078+
// Enforce line-height = 0 to fix issue with height resizing
1079+
// https://github.com/twitter/d3kit/issues/13
1080+
this.container.style('line-height', 0);
10781081

10791082
var customEvents = this.constructor.getCustomEventNames();
10801083
this.setupDispatcher(customEvents);
10811084

1082-
this.dispatchData = debounce(this.dispatchData.bind(this), 1);
1083-
this.dispatchOptions = debounce(this.dispatchOptions.bind(this), 1);
1084-
this.dispatchResize = debounce(this.dispatchResize.bind(this), 1);
1085-
1086-
this.updateDimension = debounce(this.updateDimension.bind(this), 1);
1085+
this._dispatchData = debounce(this._dispatchData.bind(this), 1);
1086+
this._dispatchOptions = debounce(this._dispatchOptions.bind(this), 1);
1087+
this._dispatchResize = debounce(this._dispatchResize.bind(this), 1);
1088+
this._updateDimension = debounce(this._updateDimension.bind(this), 1);
10871089
}
10881090

10891091
createClass(AbstractChart, [{
10901092
key: 'setupDispatcher',
10911093
value: function setupDispatcher() {
10921094
var customEventNames = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
10931095

1094-
this.customEventNames = customEventNames;
1095-
this.eventNames = AbstractChart.DEFAULT_EVENTS.concat(customEventNames);
1096-
this.dispatcher = dispatch.apply(this, this.eventNames);
1096+
this._customEventNames = customEventNames;
1097+
this._eventNames = AbstractChart.DEFAULT_EVENTS.concat(customEventNames);
1098+
this.dispatcher = dispatch.apply(this, this._eventNames);
10971099
}
10981100
}, {
10991101
key: 'getCustomEventNames',
11001102
value: function getCustomEventNames() {
1101-
return this.customEventNames;
1103+
return this._customEventNames;
11021104
}
11031105
}, {
11041106
key: 'getInnerWidth',
11051107
value: function getInnerWidth() {
1106-
return this.state.innerWidth;
1108+
return this._state.innerWidth;
11071109
}
11081110
}, {
11091111
key: 'getInnerHeight',
11101112
value: function getInnerHeight() {
1111-
return this.state.innerHeight;
1113+
return this._state.innerHeight;
11121114
}
11131115
}, {
11141116
key: 'width',
11151117
value: function width() {
1116-
if (arguments.length === 0) return this.state.width;
1118+
if (arguments.length === 0) return this._state.width;
11171119
var newValue = Math.floor(+(arguments.length <= 0 ? undefined : arguments[0]));
1118-
if (newValue !== this.state.width) {
1119-
this.state.width = newValue;
1120-
this.updateDimension();
1121-
this.dispatchResize();
1120+
if (newValue !== this._state.width) {
1121+
this._state.width = newValue;
1122+
this._updateDimension();
1123+
this._dispatchResize();
11221124
}
11231125
return this;
11241126
}
11251127
}, {
11261128
key: 'height',
11271129
value: function height() {
1128-
if (arguments.length === 0) return this.state.height;
1130+
if (arguments.length === 0) return this._state.height;
11291131
var newValue = Math.floor(+(arguments.length <= 0 ? undefined : arguments[0]));
1130-
if (newValue !== this.state.height) {
1131-
this.state.height = newValue;
1132-
this.updateDimension();
1133-
this.dispatchResize();
1132+
if (newValue !== this._state.height) {
1133+
this._state.height = newValue;
1134+
this._updateDimension();
1135+
this._dispatchResize();
11341136
}
11351137
return this;
11361138
}
11371139
}, {
11381140
key: 'dimension',
11391141
value: function dimension() {
11401142
if (arguments.length === 0) {
1141-
return [this.state.width, this.state.height];
1143+
return [this._state.width, this._state.height];
11421144
}
11431145

11441146
var _ref = arguments.length <= 0 ? undefined : arguments[0];
@@ -1158,42 +1160,42 @@ var AbstractChart = function () {
11581160
args[_key2] = arguments[_key2];
11591161
}
11601162

1161-
if (args.length === 0) return this.state.data;
1163+
if (args.length === 0) return this._state.data;
11621164
var newData = args[0];
11631165

1164-
this.state.data = newData;
1165-
this.dispatchData();
1166+
this._state.data = newData;
1167+
this._dispatchData();
11661168
return this;
11671169
}
11681170
}, {
11691171
key: 'margin',
11701172
value: function margin() {
1171-
if (arguments.length === 0) return this.state.options.margin;
1172-
var oldMargin = this.state.options.margin;
1173-
var newMargin = extend({}, this.state.options.margin, arguments.length <= 0 ? undefined : arguments[0]);
1173+
if (arguments.length === 0) return this._state.options.margin;
1174+
var oldMargin = this._state.options.margin;
1175+
var newMargin = extend({}, this._state.options.margin, arguments.length <= 0 ? undefined : arguments[0]);
11741176
var changed = Object.keys(oldMargin).some(function (field) {
11751177
return oldMargin[field] !== newMargin[field];
11761178
});
11771179
if (changed) {
1178-
this.state.options.margin = newMargin;
1179-
this.updateDimension();
1180-
this.dispatchResize();
1180+
this._state.options.margin = newMargin;
1181+
this._updateDimension();
1182+
this._dispatchResize();
11811183
}
11821184
return this;
11831185
}
11841186
}, {
11851187
key: 'offset',
11861188
value: function offset() {
1187-
if (arguments.length === 0) return this.state.options.offset;
1188-
var oldOffset = this.state.options.offset;
1189-
var newOffset = extend({}, this.state.offset, arguments.length <= 0 ? undefined : arguments[0]);
1189+
if (arguments.length === 0) return this._state.options.offset;
1190+
var oldOffset = this._state.options.offset;
1191+
var newOffset = extend({}, this._state.offset, arguments.length <= 0 ? undefined : arguments[0]);
11901192
var changed = Object.keys(oldOffset).some(function (field) {
11911193
return oldOffset[field] !== newOffset[field];
11921194
});
11931195
if (changed) {
1194-
this.state.options.offset = newOffset;
1195-
this.updateDimension();
1196-
this.dispatchResize();
1196+
this._state.options.offset = newOffset;
1197+
this._updateDimension();
1198+
this._dispatchResize();
11971199
}
11981200
return this;
11991201
}
@@ -1204,7 +1206,7 @@ var AbstractChart = function () {
12041206
args[_key3] = arguments[_key3];
12051207
}
12061208

1207-
if (args.length === 0) return this.state.options;
1209+
if (args.length === 0) return this._state.options;
12081210
var newOptions = args[0];
12091211

12101212
if (newOptions.margin) {
@@ -1213,46 +1215,46 @@ var AbstractChart = function () {
12131215
if (newOptions.offset) {
12141216
this.offset(newOptions.offset);
12151217
}
1216-
this.state.options = deepExtend(this.state.options, newOptions);
1217-
this.dispatchOptions();
1218+
this._state.options = deepExtend(this._state.options, newOptions);
1219+
this._dispatchOptions();
12181220
return this;
12191221
}
12201222
}, {
1221-
key: 'updateDimension',
1222-
value: function updateDimension() {
1223-
var _state = this.state;
1223+
key: '_updateDimension',
1224+
value: function _updateDimension() {
1225+
var _state = this._state;
12241226
var width = _state.width;
12251227
var height = _state.height;
1226-
var margin = this.state.options.margin;
1228+
var margin = this._state.options.margin;
12271229
var top = margin.top;
12281230
var right = margin.right;
12291231
var bottom = margin.bottom;
12301232
var left = margin.left;
12311233

12321234

1233-
this.state.innerWidth = width - left - right;
1234-
this.state.innerHeight = height - top - bottom;
1235+
this._state.innerWidth = width - left - right;
1236+
this._state.innerHeight = height - top - bottom;
12351237

12361238
return this;
12371239
}
12381240
}, {
12391241
key: 'updateDimensionNow',
12401242
value: function updateDimensionNow() {
1241-
this.updateDimension();
1242-
this.updateDimension.flush();
1243+
this._updateDimension();
1244+
this._updateDimension.flush();
12431245
return this;
12441246
}
12451247
}, {
12461248
key: 'hasData',
12471249
value: function hasData() {
1248-
var data = this.state.data;
1250+
var data = this._state.data;
12491251

12501252
return data !== null && data !== undefined;
12511253
}
12521254
}, {
12531255
key: 'hasNonZeroArea',
12541256
value: function hasNonZeroArea() {
1255-
var _state2 = this.state;
1257+
var _state2 = this._state;
12561258
var innerWidth = _state2.innerWidth;
12571259
var innerHeight = _state2.innerHeight;
12581260

@@ -1266,13 +1268,13 @@ var AbstractChart = function () {
12661268
var watchOptions = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
12671269

12681270
if (fitOptions) {
1269-
this.state.fitOptions = fitOptions;
1271+
this._state.fitOptions = fitOptions;
12701272
}
12711273

12721274
// Fit once
12731275
var fitter = new Fitter(fitOptions);
12741276

1275-
var _fitter$fit = fitter.fit(this.getBoundElement(), this.container.node());
1277+
var _fitter$fit = fitter.fit(this.dimension(), this.container.node());
12761278

12771279
var changed = _fitter$fit.changed;
12781280
var dimension = _fitter$fit.dimension;
@@ -1288,7 +1290,7 @@ var AbstractChart = function () {
12881290
if (this.fitWatcher) {
12891291
this.fitWatcher.destroy();
12901292
}
1291-
this.fitWatcher = new FitWatcher(this.getBoundElement(), this.container.node(), this.state.fitOptions, isObject(watchOptions) ? watchOptions : null).on('change', function (dim) {
1293+
this.fitWatcher = new FitWatcher(this.dimension(), this.container.node(), this._state.fitOptions, isObject(watchOptions) ? watchOptions : null).on('change', function (dim) {
12921294
return _this.dimension([dim.width, dim.height]);
12931295
}).start();
12941296
}
@@ -1305,21 +1307,21 @@ var AbstractChart = function () {
13051307
return this;
13061308
}
13071309
}, {
1308-
key: 'dispatchData',
1309-
value: function dispatchData() {
1310-
this.dispatcher.call('data', this, this.state.data);
1310+
key: '_dispatchData',
1311+
value: function _dispatchData() {
1312+
this.dispatcher.call('data', this, this._state.data);
13111313
return this;
13121314
}
13131315
}, {
1314-
key: 'dispatchOptions',
1315-
value: function dispatchOptions() {
1316-
this.dispatcher.call('options', this, this.state.options);
1316+
key: '_dispatchOptions',
1317+
value: function _dispatchOptions() {
1318+
this.dispatcher.call('options', this, this._state.options);
13171319
return this;
13181320
}
13191321
}, {
1320-
key: 'dispatchResize',
1321-
value: function dispatchResize() {
1322-
var _state3 = this.state;
1322+
key: '_dispatchResize',
1323+
value: function _dispatchResize() {
1324+
var _state3 = this._state;
13231325
var width = _state3.width;
13241326
var height = _state3.height;
13251327
var innerWidth = _state3.innerWidth;
@@ -1345,7 +1347,7 @@ var AbstractChart = function () {
13451347
value: function destroy() {
13461348
var _this2 = this;
13471349

1348-
this.eventNames.forEach(function (name) {
1350+
this._eventNames.forEach(function (name) {
13491351
_this2.off(name);
13501352
});
13511353
this.stopFitWatcher();
@@ -1397,11 +1399,6 @@ var CanvasChart = function (_AbstractChart) {
13971399
}
13981400

13991401
createClass(CanvasChart, [{
1400-
key: 'getBoundElement',
1401-
value: function getBoundElement() {
1402-
return this.canvas.node();
1403-
}
1404-
}, {
14051402
key: 'getContext2d',
14061403
value: function getContext2d() {
14071404
var _options = this.options();
@@ -1430,14 +1427,14 @@ var CanvasChart = function (_AbstractChart) {
14301427
return this;
14311428
}
14321429
}, {
1433-
key: 'updateDimension',
1434-
value: function updateDimension() {
1435-
get(Object.getPrototypeOf(CanvasChart.prototype), 'updateDimension', this).call(this);
1430+
key: '_updateDimension',
1431+
value: function _updateDimension() {
1432+
get(Object.getPrototypeOf(CanvasChart.prototype), '_updateDimension', this).call(this);
14361433

1437-
var _state = this.state;
1434+
var _state = this._state;
14381435
var width = _state.width;
14391436
var height = _state.height;
1440-
var pixelRatio = this.state.options.pixelRatio;
1437+
var pixelRatio = this._state.options.pixelRatio;
14411438

14421439

14431440
this.canvas.style('width', width).style('height', height).attr('width', width * pixelRatio).attr('height', height * pixelRatio);
@@ -1571,19 +1568,14 @@ var SvgChart = function (_AbstractChart) {
15711568
}
15721569

15731570
createClass(SvgChart, [{
1574-
key: 'getBoundElement',
1575-
value: function getBoundElement() {
1576-
return this.svg.node();
1577-
}
1578-
}, {
1579-
key: 'updateDimension',
1580-
value: function updateDimension() {
1581-
get(Object.getPrototypeOf(SvgChart.prototype), 'updateDimension', this).call(this);
1571+
key: '_updateDimension',
1572+
value: function _updateDimension() {
1573+
get(Object.getPrototypeOf(SvgChart.prototype), '_updateDimension', this).call(this);
15821574

1583-
var _state = this.state;
1575+
var _state = this._state;
15841576
var width = _state.width;
15851577
var height = _state.height;
1586-
var _state$options = this.state.options;
1578+
var _state$options = this._state.options;
15871579
var offset = _state$options.offset;
15881580
var margin = _state$options.margin;
15891581
var top = margin.top;

0 commit comments

Comments
 (0)