Exemple #1
0
    def __add(self, name, attr, value,
              shape="circle",
              word_gap=20,
              word_size_range=None,
              rotate_step=45,
              **kwargs):
        """

        :param name:
            系列名称,用于 tooltip 的显示,legend 的图例筛选。
        :param attr:
            属性名称。
        :param value:
            属性所对应的值。
        :param shape:
            词云图轮廓,有'circle', 'cardioid', 'diamond', 'triangle-forward',
            'triangle', 'pentagon', 'star'可选。
        :param word_gap:
            单词间隔,默认为 20。
        :param word_size_range:
            单词字体大小范围,默认为 [12, 60]。
        :param rotate_step:
            旋转单词角度,默认为 45。
        """
        assert len(attr) == len(value)
        _data = []
        for data in zip(attr, value):
            _name, _value = data
            _data.append({
                "name": _name,
                "value": _value,
                "textStyle": {
                    "normal": {
                        "color": gen_color()
                    }}
            })
        _min, _max = 12, 60
        if word_size_range is not None:
            if len(word_size_range) == 2:
                _min, _max = word_size_range

        _rmin, _rmax = -90, 90
        # 确保设置的形状有效,单词的旋转角度应该设置在 [-90, 90]
        if shape in SHAPES:
            _rmin = _rmax = 0
        else:
            shape = "circle"

        self._option.get('series').append({
            "type": "wordCloud",
            "name": name,
            "shape": shape,
            "rotationRange": [_rmin, _rmax],
            "rotationStep": rotate_step,
            "girdSize": word_gap,
            "sizeRange": [_min, _max],
            "data": _data
        })
        self._config_components(**kwargs)
Exemple #2
0
    def __add(self, name, attr, value,
              shape="circle",
              word_gap=20,
              word_size_range=None,
              rotate_step=45):
        """

        :param name:
            Series name used for displaying in tooltip and filtering with legend,
            or updaing data and configuration with setOption.
        :param attr:
            name of attribute
        :param value:
            value of attribute
        :param shape:
            shape of wordcloud
            It can be 'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star'
        :param word_gap:
            Gap of word
            size of the grid in pixels for marking the availability of the canvas
            the larger the grid size, the bigger the gap between words.
        :param word_size_range:
            Text size range which the value in data will be mapped to.
            Default to have minimum 12px and maximum 60px size.
        :param rotate_step:
            Text rotation range and step in degree. Text will be rotated randomly in range [-90, 90] by rotationStep 45
        """
        assert len(attr) == len(value)
        _data = []
        for data in zip(attr, value):
            _name, _value = data
            _data.append({
                "name": _name,
                "value": _value,
                "textStyle": {
                    "normal": {"color": gen_color()}}
            })
        _min, _max = 12, 60
        if word_size_range is not None:
            if len(word_size_range) == 2:
                _min, _max = word_size_range

        _rmin, _rmax = -90, 90
        # make sure shape valid, need to set ratated range [-90, 90]
        if shape in ("cardioid", "diamond", "triangle-forward", "triangle", "pentagon", "star"):
            _rmin = _rmax = 0
        else:
            shape = "circle"
        self._option.get('series').append({
            "type": "wordCloud",
            "name": name,
            "shape": shape,
            "rotationRange": [_rmin, _rmax],
            "rotationStep": rotate_step,
            "girdSize": word_gap,
            "sizeRange": [_min, _max],
            "data": _data
        })
Exemple #3
0
    def __add(self, name, attr, value,
              shape="circle",
              word_gap=20,
              word_size_range=None,
              rotate_step=45):
        """

        :param name:
            系列名称,用于 tooltip 的显示,legend 的图例筛选。
        :param attr:
            属性名称。
        :param value:
            属性所对应的值。
        :param shape:
            词云图轮廓,有'circle', 'cardioid', 'diamond', 'triangle-forward',
            'triangle', 'pentagon', 'star'可选。
        :param word_gap:
            单词间隔,默认为 20。
        :param word_size_range:
            单词字体大小范围,默认为 [12, 60]。
        :param rotate_step:
            旋转单词角度,默认为 45。
        """
        assert len(attr) == len(value)
        _data = []
        for data in zip(attr, value):
            _name, _value = data
            _data.append({
                "name": _name,
                "value": _value,
                "textStyle": {
                    "normal": {
                        "color": gen_color()
                    }}
            })
        _min, _max = 12, 60
        if word_size_range is not None:
            if len(word_size_range) == 2:
                _min, _max = word_size_range

        _rmin, _rmax = -90, 90
        # 确保设置的形状有效,单词的旋转角度应该设置在 [-90, 90]
        if shape in SHAPES:
            _rmin = _rmax = 0
        else:
            shape = "circle"

        self._option.get('series').append({
            "type": "wordCloud",
            "name": name,
            "shape": shape,
            "rotationRange": [_rmin, _rmax],
            "rotationStep": rotate_step,
            "girdSize": word_gap,
            "sizeRange": [_min, _max],
            "data": _data
        })
Exemple #4
0
    def __add(self, name, attr, value,
              shape="circle",
              word_gap=20,
              word_size_range=None,
              rotate_step=45):
        """

        :param name:
            图例名称
        :param attr:
            属性名称
        :param value:
            属性所对应的值
        :param shape:
            词云图轮廓,有'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star'可选
        :param word_gap:
            单词间隔
        :param word_size_range:
            单词字体大小范围
        :param rotate_step:
            旋转单词角度,默认为 45 度
        """
        if isinstance(attr, list) and isinstance(value, list):
            assert len(attr) == len(value)
            _data = []
            for data in zip(attr, value):
                _name, _value = data
                _data.append({
                    "name": _name,
                    "value": _value,
                    "textStyle": {
                        "normal": {"color": gen_color()}}
                })
            _min, _max = 12, 60
            if word_size_range is not None:
                if len(word_size_range) == 2:
                    _min, _max = word_size_range
            _rmin, _rmax = -90, 90
            # 确保选择形状时能够生效,需使字体不旋转
            if shape in ("cardioid", "diamond", "triangle-forward", "triangle", "pentagon", "star"):
                _rmin = _rmax = 0
            else:
                shape = "circle"
            self._option.get('series').append({
                "type": "wordCloud",
                "name": name,
                "shape": shape,
                "rotationRange": [_rmin, _rmax],
                "rotationStep": rotate_step,
                "girdSize": word_gap,
                "sizeRange": [_min, _max],
                "data": _data
            })
        else:
            raise TypeError("attr and value must be list")
Exemple #5
0
    def __add(self,
              name,
              attr,
              value,
              shape="circle",
              word_gap=20,
              word_size_range=None,
              rotate_step=45):
        """

        :param name:
            Series name used for displaying in tooltip and filtering with legend,
            or updaing data and configuration with setOption.
        :param attr:
            name of attribute
        :param value:
            value of attribute
        :param shape:
            shape of wordcloud
            It can be 'circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle',
            'pentagon', 'star'
        :param word_gap:
            Gap of word
            size of the grid in pixels for marking the availability of the canvas
            the larger the grid size, the bigger the gap between words.
        :param word_size_range:
            Text size range which the value in data will be mapped to.
            Default to have minimum 12px and maximum 60px size.
        :param rotate_step:
            Text rotation range and step in degree.
            Text will be rotated randomly in range [-90, 90] by rotationStep 45
        """
        assert len(attr) == len(value)
        _data = []
        for data in zip(attr, value):
            _name, _value = data
            _data.append({
                "name": _name,
                "value": _value,
                "textStyle": {
                    "normal": {
                        "color": gen_color()
                    }
                }
            })
        _min, _max = 12, 60
        if word_size_range is not None:
            if len(word_size_range) == 2:
                _min, _max = word_size_range

        _rmin, _rmax = -90, 90
        # make sure shape valid, need to set ratated range [-90, 90]
        if shape in ("cardioid", "diamond", "triangle-forward", "triangle",
                     "pentagon", "star"):
            _rmin = _rmax = 0
        else:
            shape = "circle"
        self._option.get('series').append({
            "type": "wordCloud",
            "name": name,
            "shape": shape,
            "rotationRange": [_rmin, _rmax],
            "rotationStep": rotate_step,
            "girdSize": word_gap,
            "sizeRange": [_min, _max],
            "data": _data
        })