Skip to content

Commit 4091c89

Browse files
committed
Revert "RS-20085: Only set rhtmlwidget-status to ready once images have loaded (#133)"
This reverts commit 91e17e7.
1 parent 91e17e7 commit 4091c89

15 files changed

Lines changed: 46 additions & 53 deletions

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: rhtmlPictographs
22
Type: Package
33
Title: Create Pictograph html widgets
4-
Version: 1.0.9
4+
Version: 1.0.8
55
Author: Displayr <opensource@displayr.com>
66
Maintainer: Displayr <opensource@displayr.com>
77
Description: An R HTMLWidget that can generate single image graphics, mutli

inst/htmlwidgets/rhtmlPictographs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/htmlwidgets/rhtmlPictographs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

theSrc/scripts/BaseCell.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ class BaseCell {
128128
}
129129

130130
draw () {
131-
return Promise.resolve()
132-
.then(() => this._draw())
133-
.then(() => this._generateDynamicCss())
131+
this._draw()
132+
this._generateDynamicCss()
134133
}
135134

136135
setCss (cssLocation, cssAttr, cssValue) {

theSrc/scripts/GraphicCell.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -538,31 +538,38 @@ class GraphicCell extends BaseCell {
538538
throw error // NB This is thrown because displayr wants the error too
539539
}
540540

541-
const imageRenderPromises = []
541+
let baseImageCompletePromise = Promise.resolve()
542542
if (this.config.baseImage != null) {
543543
const baseImageConfig = this.config.baseImage
544544
const imageFactory = this.imageFactory
545+
const baseImageRenderPromises = []
545546
enteringLeafNodes.each(function (dataAttributes) {
546547
const d3Node = d3.select(this)
547-
imageRenderPromises.push(
548+
baseImageRenderPromises.push(
548549
imageFactory.addBaseImageTo(d3Node, baseImageConfig, imageWidth, imageHeight, dataAttributes)
549550
)
550551
})
552+
baseImageCompletePromise = Promise.all(baseImageRenderPromises).catch(imageErrorHandler)
551553
}
552554

555+
// TODO this should be tied to base image promise unconditioanlly (ie. swap lines below)
556+
// let variableImageCompletePromise = baseImageCompletePromise
557+
let variableImageCompletePromise = Promise.resolve()
553558
if (this.config.variableImage != null) {
554559
const variableImageConfig = this.config.variableImage
555560
const imageFactory = this.imageFactory
556-
enteringLeafNodes.each(function (dataAttributes) {
557-
const d3Node = d3.select(this)
558-
imageRenderPromises.push(
559-
imageFactory.addVarImageTo(d3Node, variableImageConfig, imageWidth, imageHeight, dataAttributes)
560-
)
561+
variableImageCompletePromise = baseImageCompletePromise.then(function () {
562+
const variableImageRenderPromises = []
563+
enteringLeafNodes.each(function (dataAttributes) {
564+
const d3Node = d3.select(this)
565+
variableImageRenderPromises.push(
566+
imageFactory.addVarImageTo(d3Node, variableImageConfig, imageWidth, imageHeight, dataAttributes)
567+
)
568+
})
569+
return Promise.all(variableImageRenderPromises).catch(imageErrorHandler)
561570
})
562571
}
563572

564-
const variableImageCompletePromise = Promise.all(imageRenderPromises).catch(imageErrorHandler)
565-
566573
return variableImageCompletePromise.then(() => {
567574
if (this.config.tooltip) {
568575
enteringLeafNodes.append('svg:title')

theSrc/scripts/ImageFactory.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,12 @@ class ImageFactory {
220220
return null
221221
}
222222
})
223-
.then((clipId) => imageInstance.appendToSvg(clipId))
223+
.then((clipId) => {
224+
const imageHandle = imageInstance.appendToSvg()
225+
if (clipId) {
226+
imageHandle.attr('clip-path', `url(#${clipId})`)
227+
}
228+
})
224229
}
225230

226231
calculateAspectRatio (config) {

theSrc/scripts/Pictograph.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Pictograph {
1414
constructor (el) {
1515
this.rootElement = _.has(el, 'length') ? el[0] : el
1616
d3.select(this.rootElement).attr(`rhtmlwidget-status`, 'loading')
17+
d3.select(this.rootElement).attr(`rhtmlPictographs-status`, 'loading') // to be removed once regression testing code checks for rhtmlwidget-status
1718
const actualDimensions = this.getContainerDimensions()
1819
log.info('Pictograph() called. Container dimensions:', actualDimensions, 'element:', el)
1920

@@ -41,6 +42,7 @@ class Pictograph {
4142
if (error.type === InsufficientContainerSizeError.type) {
4243
console.log(error.message)
4344
d3.select(this.rootElement).attr(`rhtmlwidget-status`, 'ready')
45+
d3.select(this.rootElement).attr(`rhtmlPictographs-status`, 'ready') // to be removed once regression testing code checks for rhtmlwidget-status
4446
} else {
4547
console.error(`error in pictograph draw: ${error.message}`)
4648
console.error(error.stack)
@@ -77,6 +79,7 @@ class Pictograph {
7779
if (error.type === InsufficientContainerSizeError.type) {
7880
console.log(error.message)
7981
d3.select(this.rootElement).attr(`rhtmlwidget-status`, 'ready')
82+
d3.select(this.rootElement).attr(`rhtmlPictographs-status`, 'ready') // to be removed once regression testing code checks for rhtmlwidget-status
8083
} else {
8184
console.error(`error in pictograph resize: ${error.message}`)
8285
console.error(error.stack)
@@ -494,8 +497,6 @@ class Pictograph {
494497
.attr('class', 'table-cell')
495498
.attr('transform', d => `translate(${d.x},${d.y})`)
496499

497-
const cellDrawingPromises = []
498-
499500
enteringCells.each(function (d) {
500501
const instance = d.instance
501502
log.debug(`rendering entering cell`, instance)
@@ -507,11 +508,11 @@ class Pictograph {
507508
instance.setWidth(d.width)
508509
instance.setHeight(d.height)
509510
instance.setDynamicMargins(d.dynamicMargins)
510-
511-
cellDrawingPromises.push(instance.draw())
511+
instance.draw()
512512
})
513513

514-
Promise.all(cellDrawingPromises).then(() => d3.select(this.rootElement).attr(`rhtmlwidget-status`, 'ready'))
514+
d3.select(this.rootElement).attr(`rhtmlwidget-status`, 'ready')
515+
d3.select(this.rootElement).attr(`rhtmlPictographs-status`, 'ready') // to be removed once regression testing code checks for rhtmlwidget-status
515516
}
516517

517518
// TODO Duplicated code from graphicCell

theSrc/scripts/imageTypes/base.imagetype.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ class BaseImageType {
6464
get baseShapeHiding () {
6565
return (this.config.baseShapeScale != null) ? this.config.baseShapeScale : 1
6666
}
67-
68-
addClipId (clipId) {
69-
if (clipId) {
70-
this.imageHandle.attr('clip-path', `url(#${clipId})`)
71-
}
72-
}
7367
}
7468

7569
module.exports = BaseImageType

theSrc/scripts/imageTypes/circle.imagetype.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CircleType extends BaseImageType {
1616
return Promise.resolve(1)
1717
}
1818

19-
appendToSvg (clipId) {
19+
appendToSvg () {
2020
this.imageHandle = this.d3Node.append('svg:circle')
2121
.classed('circle', true)
2222
.attr('cx', this.containerWidth / 2)
@@ -25,9 +25,7 @@ class CircleType extends BaseImageType {
2525
.style('fill', this.color)
2626
.style('opacity', this.opacity)
2727

28-
this.addClipId(clipId)
29-
30-
return Promise.resolve()
28+
return this.imageHandle
3129
}
3230
}
3331

theSrc/scripts/imageTypes/ellipse.imagetype.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class EllipseType extends BaseImageType {
99
return Promise.resolve(null)
1010
}
1111

12-
appendToSvg (clipId) {
12+
appendToSvg () {
1313
this.imageHandle = this.d3Node.append('svg:ellipse')
1414
.classed('ellipse', true)
1515
.attr('cx', this.containerWidth / 2)
@@ -19,9 +19,7 @@ class EllipseType extends BaseImageType {
1919
.style('fill', this.color)
2020
.style('opacity', this.opacity)
2121

22-
this.addClipId(clipId)
23-
24-
return Promise.resolve()
22+
return this.imageHandle
2523
}
2624
}
2725

0 commit comments

Comments
 (0)