# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
from __future__ import absolute_import
import random
import json
import logging
logger = logging.getLogger('stepfunctions')
try:
from IPython.core.display import HTML
__IPYTHON_IMPORTED__ = True
except ImportError as e:
logger.warning("IPython failed to import. Visualization features will be impaired or broken.")
__IPYTHON_IMPORTED__ = False
from string import Template
from stepfunctions.workflow.widgets.utils import create_sfn_execution_url
JSLIB_URL = 'https://do0of8uwbahzz.cloudfront.net/sfn'
CSS_URL = 'https://do0of8uwbahzz.cloudfront.net/graph.css'
HTML_TEMPLATE = """
$graph_legend_template
{console_snippet}
"""
EXECUTION_URL_TEMPLATE = """ Inspect in AWS Step Functions """
WORKFLOW_GRAPH_SCRIPT_TEMPLATE = """
require.config({
paths: {
sfn: "$jslib",
}
});
require(['sfn'], function(sfn) {
var element = document.getElementById('$element_id')
var options = {
width: parseFloat(getComputedStyle(element, null).width.replace("px", "")),
height: 600,
layout: '$layout',
resizeHeight: true
};
var definition = $definition;
var elementId = '#$element_id';
var graph = new sfn.StateMachineGraph(definition, elementId, options);
graph.render();
});
"""
EXECUTION_GRAPH_SCRIPT_TEMPLATE = """
require.config({
paths: {
sfn: "$jslib",
}
});
require(['sfn'], function(sfn) {
var element = document.getElementById('$element_id')
var options = {
width: parseFloat(getComputedStyle(element, null).width.replace("px", "")),
height: 1000,
layout: '$layout',
resizeHeight: true
};
var definition = $definition;
var elementId = '#$element_id';
var events = { 'events': $events };
var graph = new sfn.StateMachineExecutionGraph(definition, events, elementId, options);
graph.render();
});
"""
EXECUTION_GRAPH_LEGEND_TEMPLATE = """