def get(cls, js_code: str): """ Description: ----------- Get the Javascript Object by its reference. Usage:: JsDate.new("2019-05-03", varName="MyDate") JsDate.get("MyDate") Related Pages: https://www.w3schools.com/jsref/jsref_obj_date.asp Attributes: ---------- :param str js_code: The Javascript object reference. :return: The python Javascript object """ if "-" in js_code: # assume it a valid date return cls(data=None, js_code='new Date("%s")' % js_code, set_var=False) JsUtils.getJsValid(js_code) return cls(data=None, js_code=js_code, set_var=False)
def object(self, varName, value): """ Description: ------------ Attributes: ---------- :param varName: String. The Javascript variable name :param value: Float or Integer. Object passed to the Javascript layer """ JsUtils.getJsValid(varName, fail=True) return JsObjects.JsObjects().new(value, varName=varName, report=self._report)
def object(self, js_code: str, value: float): """ Description: ------------ Transform a Python object to a JavaScript object. Attributes: ---------- :param str js_code: The Javascript variable name. :param float value: Object passed to the Javascript layer. """ JsUtils.getJsValid(js_code, fail=True) return JsObjects.JsObjects().new(value, js_code=js_code, page=self.page)
def list(self, varName, data): """ Description: ------------ Attributes: ---------- :param varName: String. The Javascript variable name :param data: List. Object passed to the Javascript layer """ JsUtils.getJsValid(varName, fail=True) return JsObjects.JsObjects().array(data, varName=varName, setVar=True, report=self._report)
def dataview(self, dataset, var_name: str = None, options: Union[dict, primitives.JsDataModel] = None): """ Description: ----------- A DataView offers a filtered and/or formatted view on a DataSet. One can subscribe to change in a DataView, and easily get filtered or formatted data without having to specify filters and field types all the time. Viz.Js module Related Pages: https://visjs.github.io/vis-data/data/dataview.html Attributes: ---------- :param dataset: :param options: :param var_name: """ vis_obj = VisDataView(self.page, data=dataset.varId, js_code=JsUtils.getJsValid(var_name)) if options is not None: vis_obj.setOptions(options) return vis_obj
def dataset(self, data: Any, js_code: str = None, options: Union[dict, primitives.JsDataModel] = None): """ Description: ----------- One of the starting points of the visualizations of vis.js is that they can deal with dynamic data, and allow manipulation of the data. To enable this, vis.js includes a flexible key/value based DataSet and DataView to handle unstructured JSON data. Related Pages: https://visjs.github.io/vis-data/data/index.html Attributes: ---------- :param Any data: The data to be passed to the JavaScript side. :param str js_code: The variable reference to this object on the JavaScript side. :param dict options: The options to be added to this object. """ vis_obj = VisDataSet(self.page, data=data, js_code=JsUtils.getJsValid(js_code)) if options is not None: vis_obj.setOptions(options) return vis_obj
def crossfilter(self, data=None, js_code: str = None, cross_dimension=None): """ Description: ----------- A crossfilter represents a multi-dimensional dataset. Constructs a new crossfilter. If records is specified, simultaneously adds the specified records. Records can be any array of JavaScript objects or primitives. Related Pages: https://github.com/crossfilter/crossfilter/wiki/API-Reference Attributes: ---------- :param data: :param js_code: :param cross_dimension: """ from epyk.core.js.packages.JsCrossFilter import CrossFilter if data is None: data = "%s.top(Infinity)" % cross_dimension.toStr() if js_code is None: return CrossFilter(page=self.page, data=data, set_var=False) return CrossFilter(page=self.page, js_code=JsUtils.getJsValid(js_code), data=data)
def number(self, js_code: str, value): """ Description: ------------ Transform a Python number to a JavaScript one. Attributes: ---------- :param str js_code: The Javascript variable name. :param value: Float | Integer. Object passed to the Javascript layer. """ JsUtils.getJsValid(js_code, fail=True) return JsObjects.JsObjects().number(value, js_code=js_code, set_var=True, page=self.page)
def list(self, js_code: str, data): """ Description: ------------ Transform a Python object to a JavaScript list. Attributes: ---------- :param str js_code: The Javascript variable name. :param data: List. Object passed to the Javascript layer.W """ JsUtils.getJsValid(js_code, fail=True) return JsObjects.JsObjects().array(data, js_code=js_code, set_var=True, page=self.page)
def get(cls, varName): """ Get the Javascript Object by its reference Example JsDate.new("2019-05-03", varName="MyDate") JsDate.get("MyDate") Documentation https://www.w3schools.com/jsref/jsref_obj_date.asp :param varName: The Javascript object reference :return: The python Javascript object """ if "-" in varName: # assume it a valid date return cls(data=None, varName='new Date("%s")' % varName, setVar=False) JsUtils.getJsValid(varName) return cls(data=None, varName=varName, setVar=False)
def animate(self, name, targ_css_attrs, orig_css_attrs=None, delay=0, duration=1, timing_fnc="ease-in-out", iteration_count="infinite", directions="alternate", fill_mode='forwards'): """ Description: ------------ Use the text-shadow property to create the neon light effect, and then use animation together with keyframes to add the repeatedly glowing effect htmlObj.style.effects.animate("pink", {"color": "blue", "width": "400px"}) Related Pages: https://www.w3schools.com/cssref/css_animatable.asp Attributes: ---------- :param name: String. The animation name :param targ_css_attrs: Dictionary. The different CSS attributes to animate :param orig_css_attrs: Dictionary. The initial state of the attributes to animate :param delay: Integer. The delay in second before starting the animation :param timing_fnc: String. The animation-timing-function property specifies the speed curve of the animation. :param duration: Integer. The animation duration in second :param iteration_count: Integer. The animation count :param directions: String. The animation-direction property specifies whether an animation should be played forwards, backwards or in alternate cycles. :param fill_mode: """ name = JsUtils.getJsValid(name, fail=False) keyframe_name = "animate_%s" % name if self.component is not None: self.component.style.css.animation = "%s %ss %s %ss %s %s %s" % ( keyframe_name, duration, timing_fnc, delay, iteration_count, directions, fill_mode) if orig_css_attrs is None: attrs = {"to": targ_css_attrs} else: attrs = {"from": orig_css_attrs, "to": targ_css_attrs} self.page.body.style.css_class.keyframes(keyframe_name, attrs) return name
def dataset(self, data, var_name=None, options=None): """ Description: ----------- One of the starting points of the visualizations of vis.js is that they can deal with dynamic data, and allow manipulation of the data. To enable this, vis.js includes a flexible key/value based DataSet and DataView to handle unstructured JSON data. Related Pages: https://visjs.github.io/vis-data/data/index.html Attributes: ---------- :param data: :param var_name: :param options: """ vis_obj = VisDataSet(self._src, data=data, varName=JsUtils.getJsValid(var_name)) if options is not None: vis_obj.setOptions(options) return vis_obj
from epyk.core.js import JsUtils print(JsUtils.getJsValid("Test", fail=False)) print(JsUtils.getJsValid("1Test", fail=False)) print(JsUtils.getJsValid("tes-t", fail=False))