types#CoordinateSpaceInitial TypeScript Examples

The following examples show how to use types#CoordinateSpaceInitial. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: editGoodParameter.tsx    From grafana-weathermap-panel with Apache License 2.0 6 votes vote down vote up
editGoodParameter = (
  name: string,
  editCoor: CoordinateSpaceInitial,
  newValue: string,
  widthBackground: number,
  heigthBackground: number
): CoordinateSpaceInitial => {
  if (name.startsWith('positionXMin')) {
    editCoor.coordinate.xMin = limitValueInitialSpace(newValue, 1, widthBackground, heigthBackground);
    //editCoor.coordinate.xMin = newValue;
  } else if (name.startsWith('positionXMax')) {
    editCoor.coordinate.xMax = limitValueInitialSpace(newValue, 2, widthBackground, heigthBackground);
    //editCoor.coordinate.xMax = newValue;
  } else if (name.startsWith('positionYMin')) {
    editCoor.coordinate.yMin = limitValueInitialSpace(newValue, 3, widthBackground, heigthBackground);
    //editCoor.coordinate.yMin = newValue;
  } else if (name.startsWith('positionYMax')) {
    editCoor.coordinate.yMax = limitValueInitialSpace(newValue, 4, widthBackground, heigthBackground);
    //editCoor.coordinate.yMax = newValue;
  }
  return editCoor;
}
Example #2
Source File: coodinateIsInInitialSpace.tsx    From grafana-weathermap-panel with Apache License 2.0 6 votes vote down vote up
coordinateIsInInitialSpace = (x: number, y: number, initial: CoordinateSpaceInitial, baseMap: Background) => {
  //console.log(x + ' ' + y);
  const initialPx: Coord4DInt = pixelToPercent(initial.coordinate, baseMap);
  //console.log(initialPx);
  if (x < initialPx.xMin) {
    //console.log('error');
    return 0;
  }
  if (x > initialPx.xMax) {
    //console.log('error');
    return 0;
  }
  if (y < initialPx.yMin) {
    //console.log('error');
    return 0;
  }
  if (y > initialPx.yMax) {
    //console.log('error');
    return 0;
  }
  //console.log('is ok');
  return 1;
}
Example #3
Source File: coordinateSpaceInitial.tsx    From grafana-weathermap-panel with Apache License 2.0 6 votes vote down vote up
/** change value for switch */
  onChangeSwitchDisplayInitialSpace = () => {
    const newInitialSpace: CoordinateSpaceInitial = this.state.arrayCoor;
    newInitialSpace.displayArea = !newInitialSpace.displayArea;
    this.setState({
      arrayCoor: newInitialSpace,
    });
    this.callBack();
  };
Example #4
Source File: SimplePanel.tsx    From grafana-weathermap-panel with Apache License 2.0 4 votes vote down vote up
/**
   * update button css when mount component
   */
  componentDidMount = async () => {
    // not display Button of Panel if it is in the mode View
    this.checkIfDisplayButton();

    // save background in state
    // this.setState({
    //   currentImage: this.props.options.baseMap.image,
    // });
    if (this.props.options.baseMap.image !== '') {
      this.setState({
        currentImage: this.props.options.baseMap.image,
      });
    }

    // load backgroundSVG
    if (this.props.options.baseMap.modeSVG && this.props.options.baseMap.image !== '') {
      if (this.props.options.baseMap.isUploaded) {
        let width = '';
        let height = '';
        const text = this.props.options.baseMap.image;
        this.setState({ svg: text });
        const result = /id=["']\w*["']/i.exec(text);
        const resultWidth = /width=["']\w*["']/i.exec(text);
        if (resultWidth && resultWidth.length > 0) {
          width = resultWidth[0].split('"')[1];
        }
        const resultHeight = /height=["']\w*["']/i.exec(text);
        if (resultHeight && resultHeight.length > 0) {
          height = resultHeight[0].split('"')[1];
        }
        if (result && result.length > 0) {
          const id: string[] = result[0].split('"');
          if (id.length > 1) {
            const newBaseMap: Background = this.props.options.baseMap;
            newBaseMap.idSVG = id[1];
            newBaseMap.layerImage = this.props.options.baseMap.image;
            newBaseMap.width = parseInt(width || '0', 10).toString() || '';
            newBaseMap.height = parseInt(height || '0', 10).toString() || '';
            this.props.onOptionsChange({
              ...this.props.options,
              baseMap: newBaseMap,
            });
          }
        }
        this.chargeRegion();
      } else {
        fetch(this.props.options.baseMap.image)
          .then((res) => res.text())
          .then((text) => {
            let data: any;
            if (this.props.options.baseMap.image.split(',')[0] === 'base64') {
              data = atob(this.props.options.baseMap.image.split(',')[1]);
            } else {
              data = text;
            }
            this.setState({ svg: data });
            const result = /id=["']\w*["']/i.exec(data);
            if (result && result.length > 0) {
              const id: string[] = result[0].split('"');
              if (id.length > 1) {
                const documentId = document.getElementById(id[1]);
                if (documentId) {
                  const newBaseMap: Background = this.props.options.baseMap;
                  newBaseMap.idSVG = id[1];
                  // newBaseMap.width = documentId.getAttribute('width') || '';
                  // newBaseMap.height = documentId.getAttribute('height') || '';
                  newBaseMap.width = parseInt(documentId.getAttribute('width') || '0', 10).toString() || '';
                  newBaseMap.height = parseInt(documentId.getAttribute('height') || '0', 10).toString() || '';
                  this.props.onOptionsChange({
                    ...this.props.options,
                    baseMap: newBaseMap,
                  });
                }
              }
            }
          })
          .then(() => this.chargeRegion())
          .then(() => {
            const newStr: string = this.editIdString(this.state.svg);
            const background: Background = this.props.options.baseMap;
            background.layerImage = newStr;
            this.props.onOptionsChange({ ...this.props.options, baseMap: background });
          });
      }
    } else {
      this.chargeRegion();
    }

    //Set value initialSpace with width and height of background
    const coordinateSpace: CoordinateSpaceInitial = this.props.options.coordinateSpaceInitial;
    coordinateSpace.coordinate.xMax = this.props.options.baseMap.width || '0';
    coordinateSpace.coordinate.yMax = this.props.options.baseMap.height || '0';
    // if (coordinateSpace.coordinate.xMax === '') {
    //   coordinateSpace.coordinate.xMax = '0';
    // }
    // if (!coordinateSpace.coordinate.yMax) {
    //   coordinateSpace.coordinate.yMax = '0';
    // }
    // this.props.onOptionsChange({
    //   ...this.props.options,
    //   coordinateSpaceInitial: coordinateSpace,
    // });
    this.updateButtonCss();
  };