Esempio n. 1
0
File: Vis.py Progetto: smritim/lux
    def to_Altair(self) -> str:
        """
		Generate minimal Altair code to visualize the Vis

		Returns
		-------
		str
			String version of the Altair code. Need to print out the string to apply formatting.
		"""
        from lux.vislib.altair.AltairRenderer import AltairRenderer
        renderer = AltairRenderer(output_type="Altair")
        self.code = renderer.create_vis(self)
        return self.code
Esempio n. 2
0
    def to_altair(self, standalone=False) -> str:
        """
        Generate minimal Altair code to visualize the Vis

        Parameters
        ----------
        standalone : bool, optional
                Flag to determine if outputted code uses user-defined variable names or can be run independently, by default False

        Returns
        -------
        str
                String version of the Altair code. Need to print out the string to apply formatting.
        """
        from lux.vislib.altair.AltairRenderer import AltairRenderer

        renderer = AltairRenderer(output_type="Altair")
        self._code = renderer.create_vis(self, standalone)

        if lux.config.executor.name == "PandasExecutor":
            function_code = "def plot_data(source_df, vis):\n"
            function_code += "\timport altair as alt\n"
            function_code += "\tvisData = create_chart_data(source_df, vis)\n"
        else:
            function_code = "def plot_data(tbl, vis):\n"
            function_code += "\timport altair as alt\n"
            function_code += "\tvisData = create_chart_data(tbl, vis)\n"

        vis_code_lines = self._code.split("\n")
        for i in range(2, len(vis_code_lines) - 1):
            function_code += "\t" + vis_code_lines[i] + "\n"
        function_code += "\treturn chart\n#plot_data(your_df, vis) this creates an Altair plot using your source data and vis specification"
        function_code = function_code.replace("alt.Chart(tbl)",
                                              "alt.Chart(visData)")

        if "mark_circle" in function_code:
            function_code = function_code.replace("plot_data",
                                                  "plot_scatterplot")
        elif "mark_bar" in function_code:
            function_code = function_code.replace("plot_data", "plot_barchart")
        elif "mark_line" in function_code:
            function_code = function_code.replace("plot_data",
                                                  "plot_linechart")
        elif "mark_rect" in function_code:
            function_code = function_code.replace("plot_data", "plot_heatmap")
        return function_code
Esempio n. 3
0
    def to_VegaLite(self, prettyOutput=True) -> Union[dict, str]:
        """
		Generate minimal Vega-Lite code to visualize the Vis

		Returns
		-------
		Union[dict,str]
			String or Dictionary of the VegaLite JSON specification
		"""
        import json
        from lux.vislib.altair.AltairRenderer import AltairRenderer
        renderer = AltairRenderer(output_type="VegaLite")
        self._code = renderer.create_vis(self)
        if (prettyOutput):
            return "** Remove this comment -- Copy Text Below to Vega Editor(vega.github.io/editor) to visualize and edit **\n" + json.dumps(
                self._code, indent=2)
        else:
            return self._code
Esempio n. 4
0
    def to_Altair(self, standalone=False) -> str:
        """
		Generate minimal Altair code to visualize the Vis

		Parameters
		----------
		standalone : bool, optional
			Flag to determine if outputted code uses user-defined variable names or can be run independently, by default False

		Returns
		-------
		str
			String version of the Altair code. Need to print out the string to apply formatting.
		"""
        from lux.vislib.altair.AltairRenderer import AltairRenderer
        renderer = AltairRenderer(output_type="Altair")
        self._code = renderer.create_vis(self, standalone)
        return self._code
Esempio n. 5
0
    def get_Altair_vis_code(self, standalone=False) -> str:
        """
        Returns code specific to the visualization without styling

        Parameters
        ----------
        standalone : bool, optional
                Flag to determine if outputted code uses user-defined variable names or can be run independently, by default False

        Returns
        -------
        str
                String version of the Altair code. Need to print out the string to apply formatting.
        """
        from lux.vislib.altair.AltairRenderer import AltairRenderer

        renderer = AltairRenderer(output_type="Altair")
        self._code = renderer.create_vis(self, standalone)
        return self._code