pub fn draw(&mut self, slope: f64, x_center: f64, y_center: f64) {
        // set flip flag
        let flip = if slope < 0.0 { !self.above } else { self.above };

        // compute axis (normalized) coordinates and slope
        write!(
            &mut self.buffer,
            "slope,cx,cy=float({}),float({}),float({})\n\
             if plt.gca().get_xscale() == 'log': cx=np.log10(cx)\n\
             if plt.gca().get_yscale() == 'log': cy=np.log10(cy)\n\
             xc,yc=dataToAxis((cx,cy))\n\
             xa,ya=dataToAxis((cx+1.0,cy+slope))\n\
             m,l=(ya-yc)/(xa-xc),{}\n",
            slope,
            x_center,
            y_center,
            self.length / 2.0,
        )
        .unwrap();

        // set polygon
        if flip {
            self.buffer.push_str(
                "dat=[[pth.Path.MOVETO,(xc-l,yc-m*l)],\
                      [pth.Path.LINETO,(xc-l,yc+m*l)],\
                      [pth.Path.LINETO,(xc+l,yc+m*l)],\
                      [pth.Path.CLOSEPOLY,(None,None)]]\n",
            );
        } else {
            self.buffer.push_str(
                "dat=[[pth.Path.MOVETO,(xc-l,yc-m*l)],\
                      [pth.Path.LINETO,(xc+l,yc-m*l)],\
                      [pth.Path.LINETO,(xc+l,yc+m*l)],\
                      [pth.Path.CLOSEPOLY,(None,None)]]\n",
            );
        }

        // draw
        let tf = self.transform(slope);
        let opt = self.options();
        write!(
            &mut self.buffer,
            "{}cmd,pts=zip(*dat)\n\
             h=pth.Path(pts,cmd)\n\
             p=pat.PathPatch(h{})\n\
             plt.gca().add_patch(p)\n",
            tf, opt,
        )
        .unwrap();

        // skip text
        if self.no_text {
            return;
        }

        // coordinates for labels
        self.buffer.push_str(
            "xm,ym=xc-l,yc-m*l\n\
             xp,yp=xc+l,yc+m*l\n",
        );

        // slope text
        let mut text = String::new();
        if self.text_v == "" {
            if self.precision == 0 {
                write!(&mut text, "{}", f64::abs(slope)).unwrap();
            } else {
                write!(&mut text, "{:.1$}", f64::abs(slope), self.precision).unwrap();
            }
        } else {
            write!(&mut text, "{}", self.text_v).unwrap();
        }

        // draw labels
        let tf_txt = self.transform_text(slope);
        self.buffer.push_str(&tf_txt);
        let (opt_x, opt_y) = self.options_text();
        if flip {
            if slope < 0.0 {
                write!(
                    &mut self.buffer,
                    "plt.text(xc,yp,r'{}',ha='center',va='top'{})\n",
                    self.text_h, opt_x
                )
                .unwrap();
            } else {
                write!(
                    &mut self.buffer,
                    "plt.text(xc,yp,r'{}',ha='center',va='bottom'{})\n",
                    self.text_h, opt_x
                )
                .unwrap();
            }
            write!(
                &mut self.buffer,
                "plt.text(xm,yc,r'{}',ha='right',va='center'{})\n",
                text, opt_y
            )
            .unwrap();
        } else {
            if slope < 0.0 {
                write!(
                    &mut self.buffer,
                    "plt.text(xc,ym,r'{}',ha='center',va='bottom'{})\n",
                    self.text_h, opt_x
                )
                .unwrap();
            } else {
                write!(
                    &mut self.buffer,
                    "plt.text(xc,ym,r'{}',ha='center',va='top'{})\n",
                    self.text_h, opt_x
                )
                .unwrap();
            }
            write!(
                &mut self.buffer,
                "plt.text(xp,yc,r'{}',ha='left',va='center'{})\n",
                text, opt_y
            )
            .unwrap();
        }
    }
/// Draws an icon of line slope
Draws an icon of line slope
Draws an icon of line slope
pub fn draw(&mut self, slope: f64, x_center: f64, y_center: f64) {
        // set flip flag
        let flip = if slope < 0.0 { !self.above } else { self.above };
        // compute axis (normalized) coordinates and slope
        write!(
            &mut self.buffer,
            "slope,cx,cy=float({}),float({}),float({})\n\
             if plt.gca().get_xscale() == 'log': cx=np.log10(cx)\n\
             if plt.gca().get_yscale() == 'log': cy=np.log10(cy)\n\
             xc,yc=dataToAxis((cx,cy))\n\
             xa,ya=dataToAxis((cx+1.0,cy+slope))\n\
             m,l=(ya-yc)/(xa-xc),{}\n",
            slope,
            x_center,
            y_center,
            self.length / 2.0,
        )
        .unwrap();
        // set polygon
        if flip {
            self.buffer.push_str(
                "dat=[[pth.Path.MOVETO,(xc-l,yc-m*l)],\
                      [pth.Path.LINETO,(xc-l,yc+m*l)],\
                      [pth.Path.LINETO,(xc+l,yc+m*l)],\
                      [pth.Path.CLOSEPOLY,(None,None)]]\n",
            );
        } else {
            self.buffer.push_str(
                "dat=[[pth.Path.MOVETO,(xc-l,yc-m*l)],\
                      [pth.Path.LINETO,(xc+l,yc-m*l)],\
                      [pth.Path.LINETO,(xc+l,yc+m*l)],\
                      [pth.Path.CLOSEPOLY,(None,None)]]\n",
            );
        }
        // draw
        let tf = self.transform(slope);
        let opt = self.options();
        write!(
            &mut self.buffer,
            "{}cmd,pts=zip(*dat)\n\
             h=pth.Path(pts,cmd)\n\
             p=pat.PathPatch(h{})\n\
             plt.gca().add_patch(p)\n",
            tf, opt,
        )
        .unwrap();
        // skip text
        if self.no_text {
            return;
        }
        // coordinates for labels
        self.buffer.push_str(
            "xm,ym=xc-l,yc-m*l\n\
             xp,yp=xc+l,yc+m*l\n",
        );
        // slope text
        let mut text = String::new();
        if self.text_v == "" {
            if self.precision == 0 {
                write!(&mut text, "{}", f64::abs(slope)).unwrap();
            } else {
                write!(&mut text, "{:.1$}", f64::abs(slope), self.precision).unwrap();
            }
        } else {
            write!(&mut text, "{}", self.text_v).unwrap();
        }
        // draw labels
        let tf_txt = self.transform_text(slope);
        self.buffer.push_str(&tf_txt);
        let (opt_x, opt_y) = self.options_text();
        if flip {
            if slope < 0.0 {
                write!(
                    &mut self.buffer,
                    "plt.text(xc,yp,r'{}',ha='center',va='top'{})\n",
                    self.text_h, opt_x
                )
                .unwrap();
            } else {
                write!(
                    &mut self.buffer,
                    "plt.text(xc,yp,r'{}',ha='center',va='bottom'{})\n",
                    self.text_h, opt_x
                )
                .unwrap();
            }
            write!(
                &mut self.buffer,
                "plt.text(xm,yc,r'{}',ha='right',va='center'{})\n",
                text, opt_y
            )
            .unwrap();
        } else {
            if slope < 0.0 {
                write!(
                    &mut self.buffer,
                    "plt.text(xc,ym,r'{}',ha='center',va='bottom'{})\n",
                    self.text_h, opt_x
                )
                .unwrap();
            } else {
                write!(
                    &mut self.buffer,
                    "plt.text(xc,ym,r'{}',ha='center',va='top'{})\n",
                    self.text_h, opt_x
                )
                .unwrap();
            }
            write!(
                &mut self.buffer,
                "plt.text(xp,yc,r'{}',ha='left',va='center'{})\n",
                text, opt_y
            )
            .unwrap();
        }
    }
pub fn draw ( & mut self , slope : f64 , x_center : f64 , y_center : f64 ) { // set flip flag let flip = if slope < 0.0 { ! self . above } else { self . above } ; // compute axis (normalized) coordinates and slope write ! ( mut self buffer " \n \
 \n \
 \n \
 \n \
 \n \
 \n " slope x_center y_center self length 2.0 ) . unwrap ( ) ; // set polygon if flip { self . buffer . push_str ( " \
 \
 \
 \n " , ) ; } else { self . buffer . push_str ( " \
 \
 \
 \n " , ) ; } // draw let tf = self . transform ( slope ) ; let opt = self . options ( ) ; write ! ( mut self buffer " \n \
 \n \
 \n \
 \n " tf opt ) . unwrap ( ) ; // skip text if self . no_text { return ; } // coordinates for labels self . buffer . push_str ( " \n \
 \n " , ) ; // slope text let mut text = String :: new ( ) ; if self . text_v == " " { if self . precision == 0 { write ! ( mut text " " f64 abs ( slope ) ) . unwrap ( ) ; } else { write ! ( mut text " " f64 abs ( slope ) self precision ) . unwrap ( ) ; } } else { write ! ( mut text " " self text_v ) . unwrap ( ) ; } // draw labels let tf_txt = self . transform_text ( slope ) ; self . buffer . push_str ( & tf_txt ) ; let ( opt_x , opt_y ) = self . options_text ( ) ; if flip { if slope < 0.0 { write ! ( mut self buffer " \n " self text_h opt_x ) . unwrap ( ) ; } else { write ! ( mut self buffer " \n " self text_h opt_x ) . unwrap ( ) ; } write ! ( mut self buffer " \n " text opt_y ) . unwrap ( ) ; } else { if slope < 0.0 { write ! ( mut self buffer " \n " self text_h opt_x ) . unwrap ( ) ; } else { write ! ( mut self buffer " \n " self text_h opt_x ) . unwrap ( ) ; } write ! ( mut self buffer " \n " text opt_y ) . unwrap ( ) ; } }
Draws an icon of line slope
Draws an icon of line slope
&mut self
slope
f64
x_center
f64
y_center
f64
&mut self
slope
f64
x_center
f64
y_center
f64