Analyzing the dynamics of the photospheric magnetic field of the Sun is one of the most important problems in Solar Physics. Different estimates of the complexity of magnetograms of the Sun Active Regions (AR) are used to predict the time and the strength of the solar flares, but the quality of the forecasts are still insufficient. A magnetogram is a highly variable discrete image with a very large number of local extrema. We use an idea of extraction of stable critical points within a framework of the scale-space theory. Two sequential convolutions of the image with the same Gaussian kernel and calculating the difference between the produced images allow to get a stable estimation of the Laplacian of the image. A critical graph is constructed using maxima and minima of the Laplacian. Dynamics of critical graphs can be used for diagnostics of dynamical regimes of ARs. The so-called spectral gap is proposed to be used as a numerical descriptor. This is the difference between the two largest eigenvalues of the discrete Laplacian of the graph constructed on critical networks. We investigated several ARs and found that there was a sudden increase in the spectral gap values one or two days before the flares.