Skip to content

Commit 1965632

Browse files
author
maeda-m
committed
Fixed some code review feedback in new layout schema
1 parent a47c2e0 commit 1965632

25 files changed

Lines changed: 222 additions & 211 deletions

src/app/boot.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -442,15 +442,19 @@ thin.init_ = function() {
442442

443443
dialog.addEventListener(goog.ui.Dialog.EventType.SELECT, function(e) {
444444
if (e.isOk()) {
445+
var margin = [];
446+
goog.array.insertAt(margin, pageMarginTop.getValue() || 0, 0);
447+
goog.array.insertAt(margin, pageMarginRight.getValue() || 0, 1);
448+
goog.array.insertAt(margin, pageMarginBottom.getValue() || 0, 2);
449+
goog.array.insertAt(margin, pageMarginLeft.getValue() || 0, 3);
450+
445451
var paperTypeValue = paperTypeSelectbox.getValue();
446-
var formatConfig = {
452+
var report = {
447453
'paper-type': paperTypeValue,
448454
'orientation': pageDirectionSelectbox.getValue(),
449-
'margin-top': pageMarginTop.getValue() || 0,
450-
'margin-bottom': pageMarginBottom.getValue() || 0,
451-
'margin-left': pageMarginLeft.getValue() || 0,
452-
'margin-right': pageMarginRight.getValue() || 0
455+
'margin': margin
453456
};
457+
454458
if (thin.layout.FormatPage.isUserType(paperTypeValue)) {
455459
var userWidth = pageWidthInput.getValue();
456460
var userHeight = pageHeightInput.getValue();
@@ -462,14 +466,13 @@ thin.init_ = function() {
462466
});
463467
return false;
464468
}
465-
formatConfig['width'] = Number(userWidth);
466-
formatConfig['height'] = Number(userHeight);
469+
report['width'] = Number(userWidth);
470+
report['height'] = Number(userHeight);
467471
}
468472
var format = new thin.layout.Format();
469-
format.page = format.setPage({
470-
'title': pageTitleInput.getValue(),
471-
'page': formatConfig
472-
});
473+
format.page = format.setPage(report);
474+
format.page.setTitle(pageTitleInput.getValue());
475+
473476
var workspace = new thin.core.Workspace(format);
474477
tabpane.addPage(new thin.ui.TabPane.TabPage(workspace.getTabName(), workspace));
475478
workspace.setup();
@@ -492,9 +495,9 @@ thin.init_ = function() {
492495

493496
var defaultMargin = thin.layout.FormatPage.DEFAULT_SETTINGS['margin'];
494497
pageMarginTop.setValue(defaultMargin[0]);
495-
pageMarginBottom.setValue(defaultMargin[1]);
496-
pageMarginLeft.setValue(defaultMargin[2]);
497-
pageMarginRight.setValue(defaultMargin[3]);
498+
pageMarginRight.setValue(defaultMargin[1]);
499+
pageMarginBottom.setValue(defaultMargin[2]);
500+
pageMarginLeft.setValue(defaultMargin[3]);
498501

499502
dialog.setVisible(true);
500503
});

src/app/core/abstracttextgroup.js

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,28 @@ thin.core.AbstractTextGroup.prototype.setTextLineHeightRatio = function(ratio) {
142142
};
143143

144144

145+
/**
146+
* @deprecated See: https://github.com/thinreports/thinreports-editor/issues/38
147+
* @param {string|number} spacing
148+
* @return {string}
149+
*/
150+
thin.core.AbstractTextGroup.prototype.convertKerningToDefaultInSince06 = function(spacing) {
151+
if (isNaN(Number(spacing))) {
152+
spacing = thin.core.TextStyle.DEFAULT_KERNING;
153+
}
154+
155+
return spacing;
156+
};
157+
158+
145159
/**
146160
* @param {string} spacing
147161
*/
148162
thin.core.AbstractTextGroup.prototype.setKerning = function(spacing) {
149163
var layout = this.getLayout();
150164
var element = this.getElement();
151165

152-
if (isNaN(Number(spacing))) {
153-
spacing = thin.core.TextStyle.DEFAULT_KERNING;
154-
}
166+
spacing = this.convertKerningToDefaultInSince06(spacing);
155167

156168
if (thin.isExactlyEqual(spacing, thin.core.TextStyle.DEFAULT_KERNING)) {
157169
layout.setElementAttributes(element, {
@@ -382,38 +394,38 @@ thin.core.AbstractTextGroup.prototype.disposeInternal = function() {
382394
/**
383395
* @return {string}
384396
*/
385-
thin.core.AbstractTextGroup.prototype.getTextAnchorToHash = function() {
386-
var textAlignToHash = '';
397+
thin.core.AbstractTextGroup.prototype.getTextAnchorAsJSON = function() {
398+
var textAlignAsJSON = '';
387399
var horizonAlignType = thin.core.TextStyle.HorizonAlignType;
388400

389401
// SVG: start, middle, end
390402
// TLF: left, center, right
391403
switch(this.getTextAnchor()) {
392404
case horizonAlignType.MIDDLE:
393-
textAlignToHash = 'center';
405+
textAlignAsJSON = 'center';
394406
break;
395407
case horizonAlignType.END:
396-
textAlignToHash = 'right';
408+
textAlignAsJSON = 'right';
397409
break;
398410
default:
399-
textAlignToHash = 'left';
411+
textAlignAsJSON = 'left';
400412
break;
401413
}
402414

403-
return textAlignToHash;
415+
return textAlignAsJSON;
404416
};
405417

406418

407419
/**
408-
* @param {string} textAlignToHash
420+
* @param {string} textAlignFromJSON
409421
*/
410-
thin.core.AbstractTextGroup.prototype.setTextAnchorFromHash = function(textAlignToHash) {
422+
thin.core.AbstractTextGroup.prototype.setTextAnchorFromJSON = function(textAlignFromJSON) {
411423
var anchor = '';
412424
var horizonAlignType = thin.core.TextStyle.HorizonAlignType;
413425

414426
// SVG: start, middle, end
415427
// TLF: left, center, right
416-
switch(textAlignToHash) {
428+
switch(textAlignFromJSON) {
417429
case 'center':
418430
anchor = horizonAlignType.MIDDLE;
419431
break;
@@ -432,43 +444,43 @@ thin.core.AbstractTextGroup.prototype.setTextAnchorFromHash = function(textAlign
432444
/**
433445
* @return {string}
434446
*/
435-
thin.core.AbstractTextGroup.prototype.getVerticalAlignToHash = function() {
436-
var verticalAlignToHash = '';
447+
thin.core.AbstractTextGroup.prototype.getVerticalAlignAsJSON = function() {
448+
var verticalAlignAsJSON = '';
437449
var verticalAlignType = thin.core.TextStyle.VerticalAlignType;
438450

439451
// SVG: top, center, bottom
440452
// TLF: top, middle, bottom
441453
switch(this.getVerticalAlign()) {
442454
case verticalAlignType.CENTER:
443-
verticalAlignToHash = 'middle';
455+
verticalAlignAsJSON = 'middle';
444456
break;
445457
case verticalAlignType.BOTTOM:
446-
verticalAlignToHash = verticalAlignType.BOTTOM;
458+
verticalAlignAsJSON = verticalAlignType.BOTTOM;
447459
break;
448460
default:
449-
verticalAlignToHash = verticalAlignType.TOP;
461+
verticalAlignAsJSON = verticalAlignType.TOP;
450462
break;
451463
}
452464

453-
return verticalAlignToHash;
465+
return verticalAlignAsJSON;
454466
};
455467

456468

457469
/**
458-
* @param {string} verticalAlignToHash
470+
* @param {string} verticalAlignFromJSON
459471
*/
460-
thin.core.AbstractTextGroup.prototype.setVerticalAlignFromHash = function(verticalAlignToHash) {
472+
thin.core.AbstractTextGroup.prototype.setVerticalAlignFromJSON = function(verticalAlignFromJSON) {
461473
var valign = '';
462474
var verticalAlignType = thin.core.TextStyle.VerticalAlignType;
463475

464476
// SVG: top, center, bottom
465477
// TLF: top, middle, bottom
466-
switch(verticalAlignToHash) {
478+
switch(verticalAlignFromJSON) {
467479
case 'middle':
468480
valign = verticalAlignType.CENTER;
469481
break;
470482
default:
471-
valign = verticalAlignToHash;
483+
valign = verticalAlignFromJSON;
472484
break;
473485
}
474486

@@ -479,8 +491,8 @@ thin.core.AbstractTextGroup.prototype.setVerticalAlignFromHash = function(vertic
479491
/**
480492
* @return {Object}
481493
*/
482-
thin.core.AbstractTextGroup.prototype.toHash = function() {
483-
var hash = this.toHash_();
494+
thin.core.AbstractTextGroup.prototype.asJSON = function() {
495+
var object = this.asJSON_();
484496

485497
var lineHeight = this.getTextLineHeight();
486498
var lineHeightRatio = this.getTextLineHeightRatio();
@@ -494,21 +506,21 @@ thin.core.AbstractTextGroup.prototype.toHash = function() {
494506
letterSpecing = Number(letterSpecing);
495507
}
496508

497-
goog.object.extend(hash['style'], {
509+
goog.object.extend(object['style'], {
498510
'font-family': [ this.getFontFamily() ],
499511
'font-size': this.getFontSize(),
500-
'color': goog.object.get(hash['style'], 'fill-color'),
501-
'text-align': this.getTextAnchorToHash(),
502-
'vertical-align': this.getVerticalAlignToHash(),
512+
'color': goog.object.get(object['style'], 'fill-color'),
513+
'text-align': this.getTextAnchorAsJSON(),
514+
'vertical-align': this.getVerticalAlignAsJSON(),
503515
'line-height': lineHeight,
504516
'line-height-ratio': lineHeightRatio,
505517
'letter-spacing': letterSpecing
506518
});
507-
goog.object.extend(hash['style'], this.fontStyle_.toHash());
519+
goog.object.extend(object['style'], this.fontStyle_.asJSON());
508520

509-
goog.object.remove(hash['style'], 'fill-color');
521+
goog.object.remove(object['style'], 'fill-color');
510522

511-
return hash;
523+
return object;
512524
};
513525

514526

@@ -530,10 +542,10 @@ thin.core.AbstractTextGroup.prototype.update = function(attrs) {
530542
this.setFillColor(value);
531543
break;
532544
case 'text-align':
533-
this.setTextAnchorFromHash(value);
545+
this.setTextAnchorFromJSON(value);
534546
break;
535547
case 'vertical-align':
536-
this.setVerticalAlignFromHash(value);
548+
this.setVerticalAlignFromJSON(value);
537549
break;
538550
case 'line-height-ratio':
539551
this.setTextLineHeightRatio(value);

src/app/core/ellipseshape.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,23 +335,22 @@ thin.core.EllipseShape.prototype.disposeInternal = function() {
335335
/**
336336
* @return {Object}
337337
*/
338-
thin.core.EllipseShape.prototype.toHash = function() {
339-
var hash = this.toHash_();
338+
thin.core.EllipseShape.prototype.asJSON = function() {
339+
var object = this.asJSON_();
340340

341-
// var radius = this.getRadius();
342-
goog.object.extend(hash, {
341+
goog.object.extend(object, {
343342
'cx': this.cx_,
344343
'cy': this.cy_,
345344
'rx': this.rx_,
346345
'ry': this.ry_
347346
});
348347

349-
goog.object.remove(hash, 'x');
350-
goog.object.remove(hash, 'y');
351-
goog.object.remove(hash, 'width');
352-
goog.object.remove(hash, 'height');
348+
goog.object.remove(object, 'x');
349+
goog.object.remove(object, 'y');
350+
goog.object.remove(object, 'width');
351+
goog.object.remove(object, 'height');
353352

354-
return hash;
353+
return object;
355354
};
356355

357356

src/app/core/fontstyle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ thin.core.FontStyle.prototype.decoration;
7676
/**
7777
* @return {Object}
7878
*/
79-
thin.core.FontStyle.prototype.toHash = function() {
79+
thin.core.FontStyle.prototype.asJSON = function() {
8080
var array = [];
8181

8282
if (this.bold) {

src/app/core/formatstyle/abstractformat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ goog.inherits(thin.core.formatstyles.AbstractFormat, goog.Disposable);
3131
thin.core.formatstyles.AbstractFormat.prototype.inspect = goog.abstractMethod;
3232

3333

34-
thin.core.formatstyles.AbstractFormat.prototype.toHash = goog.abstractMethod;
34+
thin.core.formatstyles.AbstractFormat.prototype.asJSON = goog.abstractMethod;

src/app/core/formatstyle/datetimeformat.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ goog.require('thin.core.formatstyles.AbstractFormat');
2525
*/
2626
thin.core.formatstyles.DatetimeFormat = function(datetimeFormat) {
2727
thin.core.formatstyles.AbstractFormat.call(this);
28-
28+
2929
/**
3030
* @type {string}
3131
* @private
@@ -65,15 +65,15 @@ thin.core.formatstyles.DatetimeFormat.prototype.inspect = function() {
6565
/** @inheritDoc */
6666
thin.core.formatstyles.DatetimeFormat.prototype.disposeInternal = function() {
6767
goog.base(this, 'disposeInternal');
68-
68+
6969
delete this.format_;
7070
};
7171

7272

7373
/**
7474
* @return {Object}
7575
*/
76-
thin.core.formatstyles.DatetimeFormat.prototype.toHash = function() {
76+
thin.core.formatstyles.DatetimeFormat.prototype.asJSON = function() {
7777
return {
7878
'datetime': {
7979
'format': this.getFormat()

src/app/core/formatstyle/numberformat.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ goog.require('thin.core.formatstyles.AbstractFormat');
2727
*/
2828
thin.core.formatstyles.NumberFormat = function(delimiter, precision, enabled) {
2929
thin.core.formatstyles.AbstractFormat.call(this);
30-
30+
3131
var disableDelimiter = thin.core.formatstyles.NumberFormat.DISABLE_DELIMITER;
32-
32+
3333
if (enabled) {
3434
if (thin.isExactlyEqual(delimiter, disableDelimiter)) {
3535
delimiter = thin.core.formatstyles.NumberFormat.DEFAULT_DELIMITER;
@@ -43,14 +43,14 @@ thin.core.formatstyles.NumberFormat = function(delimiter, precision, enabled) {
4343
* @private
4444
*/
4545
this.delimiter_ = delimiter;
46-
46+
4747
/**
4848
* @type {number}
4949
* @private
5050
*/
5151
this.precision_ = precision;
52-
53-
52+
53+
5454
/**
5555
* @type {boolean}
5656
* @private
@@ -122,7 +122,7 @@ thin.core.formatstyles.NumberFormat.prototype.inspect = function() {
122122
/** @inheritDoc */
123123
thin.core.formatstyles.NumberFormat.prototype.disposeInternal = function() {
124124
goog.base(this, 'disposeInternal');
125-
125+
126126
delete this.delimiter_;
127127
delete this.precision_;
128128
};
@@ -131,7 +131,7 @@ thin.core.formatstyles.NumberFormat.prototype.disposeInternal = function() {
131131
/**
132132
* @return {Object}
133133
*/
134-
thin.core.formatstyles.NumberFormat.prototype.toHash = function() {
134+
thin.core.formatstyles.NumberFormat.prototype.asJSON = function() {
135135
return {
136136
'number': {
137137
'delimiter': this.getDelimiter(),

src/app/core/formatstyle/paddingformat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ thin.core.formatstyles.PaddingFormat.prototype.disposeInternal = function() {
146146
/**
147147
* @return {Object}
148148
*/
149-
thin.core.formatstyles.PaddingFormat.prototype.toHash = function() {
149+
thin.core.formatstyles.PaddingFormat.prototype.asJSON = function() {
150150
return {
151151
'padding': {
152152
'length': this.getLength(),

0 commit comments

Comments
 (0)