Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Enhancement] Image export error handling (#538)

Shan Heabe8e9b8e20d
diff --git a/package.json b/package.json
index 5c9c5b0b1..e2c061479 100644
--- a/package.json
+++ b/package.json
@@ -96,6 +96,7 @@
"lodash.pick": "^4.4.0",
"lodash.throttle": "^4.1.1",
"lodash.uniq": "^4.0.1",
+ "mini-svg-data-uri": "^1.0.3",
"moment": "^2.10.6",
"pbf": "^3.1.0",
"prop-types": "^15.6.0",
diff --git a/src/actions/ui-state-actions.js b/src/actions/ui-state-actions.js
index 6040d108a..1a4ad674a 100644
--- a/src/actions/ui-state-actions.js
+++ b/src/actions/ui-state-actions.js
@@ -165,6 +165,11 @@ export const setExportImageDataUri = createAction(
dataUri => dataUri
);
+export const setExportImageError = createAction(
+ ActionTypes.SET_EXPORT_IMAGE_ERROR,
+ error => error
+);
+
/**
* Delete cached export image
* @memberof uiStateActions
diff --git a/src/components/common/modal.js b/src/components/common/modal.js
index 93b478a53..43edf9b9e 100644
--- a/src/components/common/modal.js
+++ b/src/components/common/modal.js
@@ -71,9 +71,9 @@ const StyledModalFooter = styled.div`
justify-content: flex-end;
padding-top: 24px;
${media.portable`
- padding-top: 24px;
+ padding-top: 24px;
`};
-
+
${media.palm`
padding-top: 16px;
`};
@@ -166,7 +166,7 @@ class ModalDialog extends Component {
style={{
overlay: {
backgroundColor: 'rgba(0, 0, 0, 0.5)',
- zIndex: 10000,
+ zIndex: 1000,
// in case we want to override the modal dialog style
...props.style
}
@@ -206,16 +206,15 @@ class ModalDialog extends Component {
const StyledModal = styled(ModalDialog)`
top: 0;
left: 0;
- z-index: 10000;
transition: ${props => props.theme.transition};
padding-left: 40px;
- padding-right: 40px;
+ padding-right: 40px;
${media.portable`
padding-left: 24px;
- padding-right: 24px;
+ padding-right: 24px;
`};
-
+
${media.palm`
padding-left: 0;
padding-right: 0;
diff --git a/src/components/kepler-gl.js b/src/components/kepler-gl.js
index d51370ab9..83cea38fc 100644
--- a/src/components/kepler-gl.js
+++ b/src/components/kepler-gl.js
@@ -308,8 +308,10 @@ function KeplerGlFactory(
height={height}
exportImageSetting={uiState.exportImage}
mapFields={mapFields}
+ addNotification={uiStateActions.addNotification}
startExportingImage={uiStateActions.startExportingImage}
setExportImageDataUri={uiStateActions.setExportImageDataUri}
+ setExportImageError={uiStateActions.setExportImageError}
/>
}
<BottomWidget
diff --git a/src/components/modal-container.js b/src/components/modal-container.js
index da9bd9ad4..69049d63a 100644
--- a/src/components/modal-container.js
+++ b/src/components/modal-container.js
@@ -301,16 +301,11 @@ export default function ModalContainerFactory(
};
break;
case EXPORT_IMAGE_ID:
- const { ratio, legend, resolution, exporting, imageDataUri } = uiState.exportImage;
template = (
<ExportImageModal
+ {...uiState.exportImage}
width={containerW}
height={containerH}
- legend={legend}
- ratio={ratio}
- resolution={resolution}
- exporting={exporting}
- imageDataUri={imageDataUri}
onChangeRatio={this.props.uiStateActions.setRatio}
onChangeResolution={this.props.uiStateActions.setResolution}
onToggleLegend={this.props.uiStateActions.toggleLegend}
@@ -324,7 +319,7 @@ export default function ModalContainerFactory(
onConfirm: this._onExportImage,
confirmButton: {
large: true,
- disabled: exporting,
+ disabled: uiState.exportImage.exporting,
children: 'Download'
}
};
diff --git a/src/components/modals/export-image-modal.js b/src/components/modals/export-image-modal.js
index 01a8e8360..8053554f6 100644
--- a/src/components/modals/export-image-modal.js
+++ b/src/components/modals/export-image-modal.js
@@ -29,7 +29,10 @@ import {
RESOLUTION_OPTIONS
} from 'constants/default-settings';
-import {StyledModalContent, SelectionButton} from 'components/common/styled-components';
+import {
+ StyledModalContent,
+ SelectionButton
+} from 'components/common/styled-components';
import Switch from 'components/common/switch';
import LoadingSpinner from 'components/common/loading-spinner';
@@ -65,19 +68,22 @@ const PreviewImageSection = styled.div`
justify-content: center;
padding: 30px;
- .dimension, .instruction {
+ .dimension,
+ .instruction {
padding: 8px 0px;
}
.preview-image {
background: #e2e2e2;
border-radius: 4px;
- box-shadow: 0 8px 16px 0 rgba(0,0,0,0.18);
+ box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.18);
width: 100%;
- padding-bottom: ${props => props.ratio === RATIOS.SCREEN ?
- `${100 * props.height/props.width}%`:
- (props.ratio === RATIOS.SIXTEEN_BY_NINE ? '56.25%' : '75%')
- };
+ padding-bottom: ${props =>
+ props.ratio === RATIOS.SCREEN
+ ? `${(100 * props.height) / props.width}%`
+ : props.ratio === RATIOS.SIXTEEN_BY_NINE
+ ? '56.25%'
+ : '75%'};
position: relative;
}
@@ -94,10 +100,16 @@ const PreviewImageSection = styled.div`
left: calc(50% - 25px);
top: calc(50% - 25px);
}
+
+ .preview-image--error {
+ font-size: 12px;
+ padding: 12px;
+ color: ${props => props.theme.errorColor};
+ text-align: center;
+ }
`;
class ExportImageModal extends Component {
-
static propTypes = {
height: PropTypes.number.isRequired,
ratio: PropTypes.string.isRequired,
@@ -116,6 +128,7 @@ class ExportImageModal extends Component {
height,
legend,
ratio,
+ error,
resolution,
width,
exporting,
@@ -127,7 +140,10 @@ class ExportImageModal extends Component {
} = this.props;
const exportImageSize = calculateExportImageSize({
- width, height, ratio, resolution
+ width,
+ height,
+ ratio,
+ resolution
});
return (
@@ -135,9 +151,9 @@ class ExportImageModal extends Component {
<ImageOptionList>
<div className="image-option-section">
<div className="image-option-section-title">Ratio</div>
- Choose the ratio for various usages.
+ Choose the ratio for various usages.
<div className="button-list">
- {RATIO_OPTIONS.map(op =>
+ {RATIO_OPTIONS.map(op => (
<SelectionButton
key={op.id}
selected={ratio === op.id}
@@ -145,43 +161,53 @@ class ExportImageModal extends Component {
>
{op.label}
</SelectionButton>
- )}
+ ))}
</div>
</div>
<div className="image-option-section">
<div className="image-option-section-title">Resolution</div>
High resolution is better for prints.
<div className="button-list">
- {
- RESOLUTION_OPTIONS.map(op =>
- <SelectionButton
- key={op.id}
- selected={resolution === op.id}
- onClick={() => op.available && onChangeResolution({resolution: op.id})}>
- {op.label}
- </SelectionButton>
- )
- }
+ {RESOLUTION_OPTIONS.map(op => (
+ <SelectionButton
+ key={op.id}
+ selected={resolution === op.id}
+ onClick={() =>
+ op.available && onChangeResolution({resolution: op.id})
+ }
+ >
+ {op.label}
+ </SelectionButton>
+ ))}
</div>
</div>
<div className="image-option-section">
<div className="image-option-section-title">Map Legend</div>
- <Switch type="checkbox"
- id="add-map-legend"
- checked={legend}
- label="Add legend on map"
- onChange={onToggleLegend}/>
+ <Switch
+ type="checkbox"
+ id="add-map-legend"
+ checked={legend}
+ label="Add legend on map"
+ onChange={onToggleLegend}
+ />
</div>
</ImageOptionList>
<PreviewImageSection ratio={ratio} width={width} height={height}>
- <div className="dimension">{`${exportImageSize.width} x ${exportImageSize.height}`}</div>
+ <div className="dimension">{`${exportImageSize.width} x ${
+ exportImageSize.height
+ }`}</div>
<div className="preview-image">
- {exporting ?
+ {exporting ? (
<div className="preview-image-spinner">
<LoadingSpinner />
- </div> :
+ </div>
+ ) : error ? (
+ <div className="preview-image--error">
+ <span> {error.message || 'Generate map image failed!'}</span>
+ </div>
+ ) : (
<img className="preview-image-placeholder" src={imageDataUri} />
- }
+ )}
</div>
</PreviewImageSection>
</StyledModalContent>
diff --git a/src/components/notification-panel/notification-item.js b/src/components/notification-panel/notification-item.js
index 460bfcda1..16c274371 100644
--- a/src/components/notification-panel/notification-item.js
+++ b/src/components/notification-panel/notification-item.js
@@ -25,15 +25,16 @@ import {Delete, Info, Warning, Checkmark} from 'components/common/icons';
import ReactMarkdown from 'react-markdown';
const NotificationItemContent = styled.div`
- background-color: ${props => props.theme.notificationColors[props.notification.type] || '#000'};
+ background-color: ${props =>
+ props.theme.notificationColors[props.type] || '#000'};
color: #fff;
display: flex;
flex-direction: row;
- width: ${props => props.theme.notificationPanelItemWidth * (1 + Number(props.isExpanded))}px;
- height: ${props =>
- props.theme.notificationPanelItemHeight * (1 + Number(props.isExpanded))
- }px;
- font-size: 10px;
+ width: ${props =>
+ props.theme.notificationPanelItemWidth * (1 + Number(props.isExpanded))}px;
+ height: ${props =>
+ props.theme.notificationPanelItemHeight * (1 + Number(props.isExpanded))}px;
+ font-size: 11px;
margin-bottom: 1rem;
padding: 1em;
border-radius: 4px;
@@ -49,10 +50,15 @@ const NotificationMessage = styled.div`
flex-grow: 2;
width: ${props => props.theme.notificationPanelItemWidth}px;
margin: 0 1em;
- overflow: ${props => props.isExpanded ? 'auto' : 'hidden'};
- padding-right: ${props => props.isExpanded ? '1em' : 0};
+ overflow: ${props => (props.isExpanded ? 'auto' : 'hidden')};
+ padding-right: ${props => (props.isExpanded ? '1em' : 0)};
+
p {
margin-top: 0;
+ a {
+ color: #fff;
+ text-decoration: underline;
+ }
}
`;
@@ -69,8 +75,15 @@ const icons = {
success: <Checkmark />
};
-export default function NotificationItemFactory()
-{
+const LinkRenderer = props => {
+ return (
+ <a href={props.href} target="_blank" rel="noopener noreferrer">
+ {props.children}
+ </a>
+ );
+};
+
+export default function NotificationItemFactory() {
return class NotificationItem extends Component {
static propTypes = {
notification: PropTypes.shape({
@@ -89,28 +102,36 @@ export default function NotificationItemFactory()
render() {
const {notification, removeNotification} = this.props;
+ const {isExpanded} = this.state;
+
return (
<NotificationItemContent
className="notification-item"
- {...this.props}
- onClick={() => this.setState({isExpanded: !this.state.isExpanded})}
- isExpanded={this.state.isExpanded}>
- <NotificationIcon
- className="notification-item--icon">
+ type={notification.type}
+ isExpanded={isExpanded}
+ onClick={() => this.setState({isExpanded: !isExpanded})}
+ >
+ <NotificationIcon className="notification-item--icon">
{icons[notification.type]}
</NotificationIcon>
<NotificationMessage
className="notification-item--message"
- expanded={this.state.isExpanded}
- theme={this.props.theme}>
- <ReactMarkdown source={notification.message} />
+ isExpanded={isExpanded}
+ theme={this.props.theme}
+ >
+ <ReactMarkdown
+ source={notification.message}
+ renderers={{link: LinkRenderer}}
+ />
</NotificationMessage>
- <div
- className="notification-item--action">
- <DeleteIcon height="10px" onClick={() => removeNotification(notification.id)} />
+ <div className="notification-item--action">
+ <DeleteIcon
+ height="10px"
+ onClick={() => removeNotification(notification.id)}
+ />
</div>
</NotificationItemContent>
);
}
- }
+ };
}
diff --git a/src/components/plot-container.js b/src/components/plot-container.js
index adecb1ff1..6865525f9 100644
--- a/src/components/plot-container.js
+++ b/src/components/plot-container.js
@@ -26,19 +26,22 @@ import styled from 'styled-components';
import {StaticMap} from 'react-map-gl';
import debounce from 'lodash.debounce';
import window from 'global/window';
-
+import {exportImageError} from 'utils/notifications-utils';
import MapContainerFactory from './map-container';
import {calculateExportImageSize, convertToPng} from 'utils/export-image-utils';
import {scaleMapStyleByResolution} from 'utils/map-style-utils/mapbox-gl-style-editor';
+
const propTypes = {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
exportImageSetting: PropTypes.object.isRequired,
+ addNotification: PropTypes.func.isRequired,
mapFields: PropTypes.object.isRequired
};
PlotContainerFactory.deps = [MapContainerFactory];
+// Remove mapbox logo in exported map, because it contains non-ascii characters
const StyledPlotContainer = styled.div`
.mapboxgl-ctrl-bottom-left,
.mapboxgl-ctrl-bottom-right {
@@ -91,7 +94,12 @@ export default function PlotContainerFactory(MapContainer) {
}
};
+ _onRetrievingFinish = (devicePixelRatio) => {
+ window.devicePixelRatio = devicePixelRatio;
+ };
+
_retrieveNewScreenshot = () => {
+
if (this.plottingAreaRef) {
// setting windowDevicePixelRatio to 1
// so that large mapbox base map will load in full
@@ -99,9 +107,16 @@ export default function PlotContainerFactory(MapContainer) {
window.devicePixelRatio = 1;
this.props.startExportingImage();
- convertToPng(this.plottingAreaRef).then(dataUri => {
+ const filter = node => node.className !== 'mapboxgl-control-container';
+
+ convertToPng(this.plottingAreaRef, {filter}).then(dataUri => {
this.props.setExportImageDataUri(dataUri);
- window.devicePixelRatio = savedDevicePixelRatio;
+ this._onRetrievingFinish(savedDevicePixelRatio);
+ })
+ .catch(err => {
+ this.props.setExportImageError(err);
+ this.props.addNotification(exportImageError({err}));
+ this._onRetrievingFinish(savedDevicePixelRatio);
});
}
};
diff --git a/src/constants/action-types.js b/src/constants/action-types.js
index c7f774b1f..81f42834a 100644
--- a/src/constants/action-types.js
+++ b/src/constants/action-types.js
@@ -122,6 +122,7 @@ const ActionTypes = keyMirror({
TOGGLE_LEGEND: null,
START_EXPORTING_IMAGE: null,
SET_EXPORT_IMAGE_DATA_URI: null,
+ SET_EXPORT_IMAGE_ERROR: null,
CLEANUP_EXPORT_IMAGE: null,
// uiState > export data
diff --git a/src/constants/user-feedbacks.js b/src/constants/user-feedbacks.js
index fcfc963bc..3a44d544c 100644
--- a/src/constants/user-feedbacks.js
+++ b/src/constants/user-feedbacks.js
@@ -18,5 +18,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-export const MISSING_MAPBOX_TOKEN = "Mapbox Token not valid. " +
- "[Click here](https://github.com/keplergl/kepler.gl#mapboxapiaccesstoken-string-required)";
+export const MISSING_MAPBOX_TOKEN =
+ 'Mapbox Token not valid. ' +
+ '[Click here](https://github.com/keplergl/kepler.gl#mapboxapiaccesstoken-string-required)';
+
+export const IMAGE_EXPORT_ERRORS = {
+ dataUri: `[kepler.gl] Failed to create image from data uri.
+ Copy the uri in the javascript console when reporting this bug.
+ The uri is the string starts with "data:image/png"`,
+ styleSheet:
+ `[kepler.gl] Failed to fetch stylesheet when exporting image.
+ This probably will not affect the map. It might affect the legend.
+ The stylesheet failed to load is: `
+};
diff --git a/src/constants/user-guides.js b/src/constants/user-guides.js
index 39b2f7740..0e9fcadeb 100644
--- a/src/constants/user-guides.js
+++ b/src/constants/user-guides.js
@@ -21,3 +21,4 @@
export const GITHUB_EXPORT_HTML_MAP = 'https://github.com/keplergl/kepler.gl/blob/master/docs/user-guides/k-save-and-export.md#2save-and-export-current-map';
export const GITHUB_ADD_DATA_TO_MAP = 'https://github.com/keplergl/kepler.gl/blob/master/docs/api-reference/actions/actions.md#adddatatomap';
export const MAPBOX_ACCESS_TOKEN = 'https://docs.mapbox.com/help/how-mapbox-works/access-tokens/';
+export const GITHUB_BUG_REPORT = 'https://github.com/keplergl/kepler.gl/issues/new?template=bug_report.md';
diff --git a/src/deckgl-layers/layer-utils/cluster-utils.js b/src/deckgl-layers/layer-utils/cluster-utils.js
index 1a4bdaf7b..3c6de4439 100644
--- a/src/deckgl-layers/layer-utils/cluster-utils.js
+++ b/src/deckgl-layers/layer-utils/cluster-utils.js
@@ -61,7 +61,6 @@ const getClusterer = memoize(({clusterRadius, geoJSON}) => {
export function clustersAtZoom({bbox, clusterRadius, geoJSON, zoom}) {
const clusterer = getClusterer({clusterRadius, geoJSON});
-
return clusterer.getClusters(bbox, zoom);
}
diff --git a/src/reducers/ui-state-updaters.js b/src/reducers/ui-state-updaters.js
index ebbbfe141..8364dd5b7 100644
--- a/src/reducers/ui-state-updaters.js
+++ b/src/reducers/ui-state-updaters.js
@@ -118,7 +118,8 @@ export const DEFAULT_EXPORT_IMAGE = {
legend: false,
// exporting state
imageDataUri: '',
- exporting: false
+ exporting: false,
+ error: false
};
/**
@@ -389,6 +390,15 @@ export const setExportImageDataUri = (state, {payload: dataUri}) => ({
}
});
+export const setExportImageError = (state, {payload: error}) => ({
+ ...state,
+ exportImage: {
+ ...state.exportImage,
+ exporting: false,
+ error
+ }
+});
+
/**
* Delete cached export image
* @memberof uiStateUpdaters
@@ -401,7 +411,8 @@ export const cleanupExportImage = state => ({
exportImage: {
...state.exportImage,
exporting: false,
- imageDataUri: ''
+ imageDataUri: '',
+ error: false
}
});
diff --git a/src/reducers/ui-state.js b/src/reducers/ui-state.js
index 86ff31596..f4c97b870 100644
--- a/src/reducers/ui-state.js
+++ b/src/reducers/ui-state.js
@@ -41,6 +41,7 @@ const actionHandler = {
[ActionTypes.TOGGLE_LEGEND]: uiStateUpdaters.toggleLegendUpdater,
[ActionTypes.START_EXPORTING_IMAGE]: uiStateUpdaters.startExportingImage,
[ActionTypes.SET_EXPORT_IMAGE_DATA_URI]: uiStateUpdaters.setExportImageDataUri,
+ [ActionTypes.SET_EXPORT_IMAGE_ERROR]: uiStateUpdaters.setExportImageError,
[ActionTypes.CLEANUP_EXPORT_IMAGE]: uiStateUpdaters.cleanupExportImage,
[ActionTypes.SET_EXPORT_SELECTED_DATASET]: uiStateUpdaters.setExportSelectedDatasetUpdater,
diff --git a/src/utils/dom-to-image.js b/src/utils/dom-to-image.js
index e33fe3614..d0547a2af 100644
--- a/src/utils/dom-to-image.js
+++ b/src/utils/dom-to-image.js
@@ -26,6 +26,8 @@
import window from 'global/window';
import document from 'global/document';
import console from 'global/console';
+import svgToMiniDataURI from 'mini-svg-data-uri';
+import {IMAGE_EXPORT_ERRORS} from 'constants/user-feedbacks';
const util = newUtil();
const inliner = newInliner();
@@ -342,16 +344,18 @@ function makeSvgDataUri(node, width, height) {
return Promise.resolve(node)
.then(nd => {
nd.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
- return new window.XMLSerializer().serializeToString(nd);
- })
- .then(util.escapeXhtml)
- .then(xhtml =>
- `<foreignObject x="0" y="0" width="100%" height="100%">${xhtml}</foreignObject>`
- )
- .then(foreignObject =>
- `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">${foreignObject}</svg>`
- )
- .then(svg => `data:image/svg+xml;charset=utf-8,${svg}`);
+ const serializedString = new window.XMLSerializer().serializeToString(nd);
+
+ const xhtml = util.escapeXhtml(serializedString);
+ const foreignObject = `<foreignObject x="0" y="0" width="100%" height="100%">${xhtml}</foreignObject>`;
+ const svgStr = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">${foreignObject}</svg>`;
+
+ // Optimizing SVGs in data URIs
+ // see https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
+ // the best way of encoding SVG in a data: URI is data:image/svg+xml,[actual data].
+ // We don’t need the ;charset=utf-8 parameter because the given SVG is ASCII.
+ return svgToMiniDataURI(svgStr);
+ });
}
function newUtil() {
@@ -376,9 +380,9 @@ function newUtil() {
function mimes() {
/*
- * Only WOFF and EOT mime types for fonts are 'real'
- * see http://www.iana.org/assignments/media-types/media-types.xhtml
- */
+ * Only WOFF and EOT mime types for fonts are 'real'
+ * see http://www.iana.org/assignments/media-types/media-types.xhtml
+ */
const WOFF = 'application/font-woff';
const JPEG = 'image/jpeg';
@@ -470,7 +474,13 @@ function newUtil() {
image.onload = () => {
resolve(image);
};
- image.onerror = reject;
+ image.onerror = (err) => {
+ const message = IMAGE_EXPORT_ERRORS.dataUri;
+ console.log(uri);
+ // error is an Event Object
+ // https://www.w3schools.com/jsref/obj_event.asp
+ reject({event: err, message});
+ };
image.src = uri;
});
}
@@ -527,7 +537,7 @@ function newUtil() {
resolve(placeholder);
} else {
fail(
- `timeout of ${TIMEOUT}ms occured while fetching resource: ${url}`
+ `timeout of ${TIMEOUT}ms occurred while fetching resource: ${url}`
);
}
}
@@ -681,15 +691,20 @@ function newFontFaces() {
return Promise.all(
styleSheets.map(sheet => {
if (sheet.href) {
- return window.fetch(sheet.href, {credentials: 'omit'})
+ // cloudfont doesn't have allow origin header properly set
+ // error response will remain in cache
+ const cache = sheet.href.includes('uber-fonts') ? 'no-cache' : 'default';
+ return window.fetch(sheet.href, {credentials: 'omit', cache})
.then(toText)
.then(setBaseHref(sheet.href))
.then(toStyleSheet)
.catch(err => {
// Handle any error that occurred in any of the previous
- // promises in the chain.
- console.log(err)
- return sheet;
+ // promises in the chain. stylesheet failed to load should not stop
+ // the process, hence result in only a warning, instead of reject
+ console.warn(IMAGE_EXPORT_ERRORS.styleSheet, sheet.href);
+ console.log(err);
+ return;
});
}
return Promise.resolve(sheet);
@@ -754,6 +769,9 @@ function newFontFaces() {
const cssRules = [];
styleSheets.forEach((sheet) => {
// try...catch because browser may not able to enumerate rules for cross-domain sheets
+ if (!sheet) {
+ return;
+ }
let rules;
try {
rules = sheet.rules || sheet.cssRules;
diff --git a/src/utils/export-image-utils.js b/src/utils/export-image-utils.js
index 9403955bf..ab205f68b 100644
--- a/src/utils/export-image-utils.js
+++ b/src/utils/export-image-utils.js
@@ -47,8 +47,8 @@ export function calculateExportImageSize({width, height, ratio, resolution}) {
};
}
-export function convertToPng(sourceElem) {
- return domtoimage.toPng(sourceElem);
+export function convertToPng(sourceElem, options) {
+ return domtoimage.toPng(sourceElem, options);
}
export function dataURItoBlob(dataURI) {
diff --git a/src/utils/notifications-utils.js b/src/utils/notifications-utils.js
index db55a9294..e5e32759e 100644
--- a/src/utils/notifications-utils.js
+++ b/src/utils/notifications-utils.js
@@ -21,10 +21,14 @@
import {generateHashId} from './utils';
import {
- DEFAULT_NOTIFICATION_MESSAGE, DEFAULT_NOTIFICATION_TOPICS,
- DEFAULT_NOTIFICATION_TYPES, DEFAULT_UUID_COUNT
+ DEFAULT_NOTIFICATION_MESSAGE,
+ DEFAULT_NOTIFICATION_TOPICS,
+ DEFAULT_NOTIFICATION_TYPES,
+ DEFAULT_UUID_COUNT
} from 'constants/default-settings';
+import {GITHUB_BUG_REPORT} from 'constants/user-guides';
+
/**
* Creates a notofication
* @param {string} message - Message to display during the notification
@@ -55,13 +59,24 @@ export function createNotification({
* @param options
* @returns {{topic, id, message, type: (null|number)}}
*/
-export const errorNotification = options =>
- ({...createNotification(options), type: DEFAULT_NOTIFICATION_TYPES.error});
+export const errorNotification = options => ({
+ ...createNotification(options),
+ type: DEFAULT_NOTIFICATION_TYPES.error
+});
/**
* Creates a success notification
* @param options
* @returns {{topic, id, message, type: null}}
*/
-export const successNotification = options =>
- ({...createNotification(options), type: DEFAULT_NOTIFICATION_TYPES.success});
+export const successNotification = options => ({
+ ...createNotification(options),
+ type: DEFAULT_NOTIFICATION_TYPES.success
+});
+
+export const exportImageError = options =>
+ errorNotification({
+ ...options,
+ topic: DEFAULT_NOTIFICATION_TOPICS.global,
+ message: `Failed to export image, please take a screenshot of the javascript console, report the with [this link](${GITHUB_BUG_REPORT}) `
+ });